<commit_before>window.RP = (function() {
  var exports = {};

  var PAGE_SIZE = exports.PAGE_SIZE = 20;
  var CHAT_SIZE = exports.CHAT_SIZE = 60;

  var myUsername;
  var dbArgs;
  
  var auxWS;

  var lastChanges = null;

  function alertError(err) {
    alert(err);
    throw err;
  }

  var ID = (function() {
    var counter = 0;
    return function ID(prefix) {
      prefix = prefix || '';
      var date = Date.now().toString(36).padStart(9, 0);
      var num = (counter++ % 36**6).toString(36).padStart(6,0)
      var rand = Math.random().toString(36).slice(2);
      return prefix + date + num + rand;
    }
  }());

  function runAuxWebsocket(authToken) {
    auxWS = new WebSocket('wss://rpnow-aux.herokuapp.com')
    auxWS.onopen = function() {
      auxWS.send(authToken)
    }
    auxWS.onmessage = function(evt) {
      console.log('received typing notification:', evt.data)
    }
    auxWS.onclose = function(evt) {
      setTimeout(function () {
        runAuxWebsocket(authToken)
      }, 60 * 1000)
    }
  }

  exports.initialize = function initialize(roomid, page, callbacks) {
    var onready = callbacks.ready;
    var onmsg = callbacks.msg;
    var onchara = callbacks.chara;
    var ontitle = callbacks.title;
    var onpagecount = callbacks.pageCount;
    var onerror = callbacks.error;

    dbArgs = (roomid.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i))
      ? { databaseId: roomid }
      : { databaseName: roomid };

    userbase.init({
      appId: '630241a7-b753-44d0-a7de-358fe646cc27',
      sessionLength: 365 * 24,
    })
    .then(function (session) {
      if (!session.user) {
        throw new Error('You are not logged in!')
      }
      runAuxWebsocket(session.user.authToken)
      myUsername = session.user.username;
      return userbase.getDatabases(dbArgs)
      .then(function (results) {
        if (results.databases.length === 0) {
          throw new Error('RP Not Found');
        }
      })
    })
    .then(function () {
      var rpMetaDoc = null
      var metaDbOpenPromise = userbase.openDatabase({
        databaseName: 'dashboard-cache',
        changeHandler(changes) {
          if (rpMetaDoc) return
          var change = changes.find(function (change) {
            return change.itemId === roomid
          })<commit_msg>send dbId to websocket<commit_after>window.RP = (function() {
  var exports = {};

  var PAGE_SIZE = exports.PAGE_SIZE = 20;
  var CHAT_SIZE = exports.CHAT_SIZE = 60;

  var myUsername;
  var dbArgs;
  
  var initPromise;
  var auxWS;

  var lastChanges = null;

  function alertError(err) {
    alert(err);
    throw err;
  }

  var ID = (function() {
    var counter = 0;
    return function ID(prefix) {
      prefix = prefix || '';
      var date = Date.now().toString(36).padStart(9, 0);
      var num = (counter++ % 36**6).toString(36).padStart(6,0)
      var rand = Math.random().toString(36).slice(2);
      return prefix + date + num + rand;
    }
  }());

  function runAuxWebsocket(authToken, dbId) {
    var wsURL = 'wss://rpnow-aux.herokuapp.com'
    // var wsURL = 'ws://localhost:13002'

    auxWS = new WebSocket(wsURL)
    auxWS.onopen = function() {
      auxWS.send(authToken + ' ' + dbId)
    }
    auxWS.onmessage = function(evt) {
      console.log('received typing notification:', evt.data)
    }
    auxWS.onclose = function(evt) {
      setTimeout(function () {
        runAuxWebsocket(authToken)
      }, 60 * 1000)
    }
  }

  exports.initialize = function initialize(roomid, page, callbacks) {
    var onready = callbacks.ready;
    var onmsg = callbacks.msg;
    var onchara = callbacks.chara;
    var ontitle = callbacks.title;
    var onpagecount = callbacks.pageCount;
    var onerror = callbacks.error;

    dbArgs = (roomid.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i))
      ? { databaseId: roomid }
      : { databaseName: roomid };

    initPromise = userbase.init({
      appId: '630241a7-b753-44d0-a7de-358fe646cc27',
      sessionLength: 365 * 24,
    })
    .then(function (session) {
      if (!session.user) {
        throw new Error('You are not logged in!')
      }
      myUsername = session.user.username;
      return userbase.getDatabases(dbArgs)
      .then(function (results) {
        if (results.databases.length === 0) {
          throw new Error('RP Not Found');
        }
        var dbId = results.databases[0].databaseId
        runAuxWebsocket(session.user.authToken, dbId)
      })
    })
    .then(function () {
      var rpMetaDoc = null
      var metaDbOpenPromise = userbase.openDatabase({
        databaseName: 'dashboard-cache',
        changeHandler(changes) {
          if (rpMetaDoc) return
          var change = changes.find(function (change) {
            return change.itemId === roomid
          })
{'fraction_non_alphanumeric': 0.14238479024591857, 'fraction_numerical': 0.03141144864641455, 'mean_word_length': 2.484521238300936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2577612', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1640, 'n_words': 326}