chat-engine
Version:
1 lines • 253 kB
JSON
{"errors":[],"warnings":[],"version":"3.12.0","hash":"608089a5a231dae9e4a0","publicPath":"","assetsByChunkName":{"main":"chat-engine.js"},"assets":[{"name":"chat-engine.js","size":310873,"chunks":[0],"chunkNames":["main"],"emitted":true},{"name":"stats.json","size":0,"chunks":[],"chunkNames":[]}],"filteredAssets":0,"entrypoints":{"main":{"chunks":[0],"assets":["chat-engine.js"]}},"chunks":[{"id":0,"rendered":true,"initial":true,"entry":true,"extraAsync":false,"size":300172,"names":["main"],"files":["chat-engine.js"],"hash":"e9cd30d4ef5856407423","parents":[],"modules":[{"id":1,"identifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/modules/emitter.js","name":"./src/modules/emitter.js","index":63,"index2":61,"size":9595,"cacheable":true,"built":true,"optional":false,"prefetched":false,"chunks":[0],"assets":[],"issuer":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/components/user.js","issuerId":26,"issuerName":"./src/components/user.js","profile":{"factory":169,"building":81,"dependencies":3},"failed":false,"errors":0,"warnings":0,"reasons":[{"moduleId":26,"moduleIdentifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/components/user.js","module":"./src/components/user.js","moduleName":"./src/components/user.js","type":"cjs require","userRequest":"../modules/emitter","loc":"11:14-43"},{"moduleId":51,"moduleIdentifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/components/chat.js","module":"./src/components/chat.js","moduleName":"./src/components/chat.js","type":"cjs require","userRequest":"../modules/emitter","loc":"14:14-43"},{"moduleId":70,"moduleIdentifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/components/event.js","module":"./src/components/event.js","moduleName":"./src/components/event.js","type":"cjs require","userRequest":"../modules/emitter","loc":"11:14-43"},{"moduleId":71,"moduleIdentifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/components/search.js","module":"./src/components/search.js","moduleName":"./src/components/search.js","type":"cjs require","userRequest":"../modules/emitter","loc":"9:14-43"},{"moduleId":100,"moduleIdentifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/components/session.js","module":"./src/components/session.js","moduleName":"./src/components/session.js","type":"cjs require","userRequest":"../modules/emitter","loc":"11:14-43"}],"usedExports":true,"providedExports":null,"optimizationBailout":[],"depth":3,"source":"'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar waterfall = require('async/waterfall');\nvar RootEmitter = require('./root_emitter');\n\nvar augmentSender = require('../plugins/augment/sender');\n/**\n An ChatEngine generic emitter that supports plugins and duplicates\n events on the root emitter.\n @class Emitter\n @extends RootEmitter\n */\n\nvar Emitter = function (_RootEmitter) {\n _inherits(Emitter, _RootEmitter);\n\n function Emitter(chatEngine) {\n _classCallCheck(this, Emitter);\n\n var _this = _possibleConstructorReturn(this, (Emitter.__proto__ || Object.getPrototypeOf(Emitter)).call(this));\n\n _this.chatEngine = chatEngine;\n\n _this.name = 'Emitter';\n\n /**\n Stores a list of plugins bound to this object\n @private\n */\n _this.plugins = [];\n\n /**\n Stores in memory keys and values\n @private\n */\n _this._dataset = {};\n\n _this.plugin(augmentSender(chatEngine));\n\n /**\n Emit events locally.\n @private\n @param {String} event The event payload object\n */\n _this._emit = function (event) {\n var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n\n\n // all events are forwarded to ChatEngine object\n // so you can globally bind to events with ChatEngine.on()\n _this.chatEngine._emit(event, data, _this);\n\n // emit the event from the object that created it\n _this.emitter.emit(event, data);\n\n return _this;\n };\n\n /**\n * Listen for a specific event and fire a callback when it's emitted. Supports wildcard matching.\n * @method\n * @param {String} event The event name\n * @param {Function} cb The function to run when the event is emitted\n * @example\n *\n * // Get notified whenever someone joins the room\n * object.on('event', (payload) => {\n * console.log('event was fired').\n * })\n *\n * // Get notified of event.a and event.b\n * object.on('event.*', (payload) => {\n * console.log('event.a or event.b was fired').;\n * })\n */\n _this.on = function (event, cb) {\n\n // call the private _on property\n _this._on(event, cb);\n\n return _this;\n };\n\n return _this;\n }\n\n // add an object as a subobject under a namespace\n /**\n * @private\n */\n\n\n _createClass(Emitter, [{\n key: 'addChild',\n value: function addChild(childName, childOb) {\n // assign the new child object as a property of parent under the\n // given namespace\n this[childName] = childOb;\n\n // assign a data set for the namespace if it doesn't exist\n if (!this._dataset[childName]) {\n this._dataset[childName] = {};\n }\n\n // the new object can use ```this.parent``` to access\n // the root class\n childOb.parent = this;\n\n // bind get() and set() to the data set\n childOb.get = this.get.bind(this._dataset[childName]);\n childOb.set = this.set.bind(this._dataset[childName]);\n }\n }, {\n key: 'get',\n value: function get(key) {\n return this[key];\n }\n }, {\n key: 'set',\n value: function set(key, value) {\n if (this[key] && !value) {\n delete this[key];\n } else {\n this[key] = value;\n }\n }\n\n /**\n Binds a plugin to this object\n @param {Object} module The plugin module\n @tutorial using\n */\n\n }, {\n key: 'plugin',\n value: function plugin(module) {\n\n // add this plugin to a list of plugins for this object\n this.plugins.push(module);\n\n // see if there are plugins to attach to this class\n if (module.extends && module.extends[this.name]) {\n // attach the plugins to this class\n // under their namespace\n this.addChild(module.namespace, new module.extends[this.name]());\n\n this[module.namespace].ChatEngine = this.chatEngine;\n\n // if the plugin has a special construct function\n // run it\n if (this[module.namespace].construct) {\n this[module.namespace].construct();\n }\n }\n\n return this;\n }\n\n /**\n * @private\n */\n\n }, {\n key: 'bindProtoPlugins',\n value: function bindProtoPlugins() {\n var _this2 = this;\n\n if (this.chatEngine.protoPlugins[this.name]) {\n\n this.chatEngine.protoPlugins[this.name].forEach(function (module) {\n _this2.plugin(module);\n });\n }\n }\n\n /**\n Broadcasts an event locally to all listeners.\n @private\n @param {String} event The event name\n @param {Object} payload The event payload object\n */\n\n }, {\n key: 'trigger',\n value: function trigger(event) {\n var _this3 = this;\n\n var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var done = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {};\n\n\n // let plugins modify the event\n this.runPluginQueue('on', event, function (next) {\n next(null, payload);\n }, function (reject, pluginResponse) {\n\n if (reject) {\n done(reject);\n } else {\n\n // emit this event to any listener\n _this3._emit(event, pluginResponse);\n done(null, event, pluginResponse);\n }\n });\n }\n\n /**\n Load plugins and attach a queue of functions to execute before and\n after events are trigger or received.\n @private\n @param {String} location Where in the middleeware the event should run (emit, trigger)\n @param {String} event The event name\n @param {String} first The first function to run before the plugins have run\n @param {String} last The last function to run after the plugins have run\n */\n\n }, {\n key: 'runPluginQueue',\n value: function runPluginQueue(location, event, first, last) {\n\n // this assembles a queue of functions to run as middleware\n // event is a triggered event key\n var pluginQueue = [];\n\n // the first function is always required\n pluginQueue.push(first);\n\n // look through the configured plugins\n this.plugins.forEach(function (pluginItem) {\n\n // if they have defined a function to run specifically\n // for this event\n if (pluginItem.middleware && pluginItem.middleware[location]) {\n\n if (pluginItem.middleware[location][event]) {\n // add the function to the queue\n pluginQueue.push(pluginItem.middleware[location][event]);\n }\n\n if (pluginItem.middleware[location]['*']) {\n // add the function to the queue\n pluginQueue.push(pluginItem.middleware[location]['*']);\n }\n }\n });\n\n // waterfall runs the functions in assigned order\n // waiting for one to complete before moving to the next\n // when it's done, the ```last``` parameter is called\n waterfall(pluginQueue, last);\n }\n\n /**\n * @private\n */\n\n }, {\n key: 'onConstructed',\n value: function onConstructed() {\n\n this.bindProtoPlugins();\n this.trigger(['$', 'created', this.name.toLowerCase()].join('.'));\n }\n }]);\n\n return Emitter;\n}(RootEmitter);\n\nmodule.exports = Emitter;"},{"id":13,"identifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/modules/root_emitter.js","name":"./src/modules/root_emitter.js","index":31,"index2":30,"size":4062,"cacheable":true,"built":true,"optional":false,"prefetched":false,"chunks":[0],"assets":[],"issuer":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/bootstrap.js","issuerId":28,"issuerName":"./src/bootstrap.js","profile":{"factory":9,"building":74},"failed":false,"errors":0,"warnings":0,"reasons":[{"moduleId":1,"moduleIdentifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/modules/emitter.js","module":"./src/modules/emitter.js","moduleName":"./src/modules/emitter.js","type":"cjs require","userRequest":"./root_emitter","loc":"12:18-43"},{"moduleId":28,"moduleIdentifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/bootstrap.js","module":"./src/bootstrap.js","moduleName":"./src/bootstrap.js","type":"cjs require","userRequest":"./modules/root_emitter","loc":"7:18-51"}],"usedExports":true,"providedExports":null,"optimizationBailout":[],"depth":2,"source":"'use strict';\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n// Allows us to create and bind to events. Everything in ChatEngine is an event\n// emitter\nvar EventEmitter2 = require('eventemitter2').EventEmitter2;\n\n/**\n* The {@link ChatEngine} object is a RootEmitter. Configures an event emitter that other ChatEngine objects inherit. Adds shortcut methods for\n* ```this.on()```, ```this.emit()```, etc.\n* @class RootEmitter\n*/\n\nvar RootEmitter = function RootEmitter() {\n var _this = this;\n\n _classCallCheck(this, RootEmitter);\n\n /**\n * @private\n */\n this.events = {};\n\n /**\n Handy property to identify what this class is.\n @type String\n @private\n */\n this.name = 'RootEmitter';\n\n /**\n Create a new EventEmitter2 object for this class.\n @private\n */\n this.emitter = new EventEmitter2({\n wildcard: true,\n newListener: true,\n maxListeners: 50,\n verboseMemoryLeak: true\n });\n\n // we bind to make sure wildcards work\n // https://github.com/asyncly/EventEmitter2/issues/186\n\n /**\n Private emit method that broadcasts the event to listeners on this page.\n @private\n @param {String} event The event name\n @param {Object} the event payload\n */\n this._emit = this.emitter.emit.bind(this.emitter);\n\n /**\n Listen for a specific event and fire a callback when it's emitted. This is reserved in case ```this.on``` is overwritten.\n @private\n @param {String} event The event name\n @param {Function} callback The function to run when the event is emitted\n */\n\n this._on = this.emitter.on.bind(this.emitter);\n\n /**\n * Listen for a specific event and fire a callback when it's emitted. Supports wildcard matching.\n * @method\n * @param {String} event The event name\n * @param {Function} cb The function to run when the event is emitted\n * @example\n *\n * // Get notified whenever someone joins the room\n * object.on('event', (payload) => {\n * console.log('event was fired').\n * })\n *\n * // Get notified of event.a and event.b\n * object.on('event.*', (payload) => {\n * console.log('event.a or event.b was fired').;\n * })\n */\n this.on = function (event, callback) {\n\n // emit the event from the object that created it\n _this.emitter.on(event, callback);\n\n return _this;\n };\n\n /**\n * Stop a callback from listening to an event.\n * @method\n * @param {String} event The event name\n * @example\n * let callback = function(payload;) {\n * console.log('something happend!');\n * };\n * object.on('event', callback);\n * // ...\n * object.off('event', callback);\n */\n this.off = function (event, callback) {\n\n // emit the event from the object that created it\n _this.emitter.off(event, callback);\n\n return _this;\n };\n\n /**\n * Listen for any event on this object and fire a callback when it's emitted\n * @method\n * @param {Function} callback The function to run when any event is emitted. First parameter is the event name and second is the payload.\n * @example\n * object.onAny((event, payload) => {\n * console.log('All events trigger this.');\n * });\n */\n this.onAny = function (event, callback) {\n\n // emit the event from the object that created it\n _this.emitter.onAny(event, callback);\n\n return _this;\n };\n\n /**\n * Listen for an event and only fire the callback a single time\n * @method\n * @param {String} event The event name\n * @param {Function} callback The function to run once\n * @example\n * object.once('message', => (event, payload) {\n * console.log('This is only fired once!');\n * });\n */\n this.once = function (event, callback) {\n\n // emit the event from the object that created it\n _this.emitter.once(event, callback);\n\n return _this;\n };\n};\n\nmodule.exports = RootEmitter;"},{"id":25,"identifier":"/Users/craigb/deploy/chat-engine/node_modules/webpack/buildin/module.js","name":"(webpack)/buildin/module.js","index":81,"index2":70,"size":517,"cacheable":true,"built":true,"optional":false,"prefetched":false,"chunks":[0],"assets":[],"issuer":"/Users/craigb/deploy/chat-engine/node_modules/lodash/isBuffer.js","issuerId":82,"issuerName":"./node_modules/lodash/isBuffer.js","profile":{"factory":13,"building":6},"failed":false,"errors":0,"warnings":0,"reasons":[{"moduleId":82,"moduleIdentifier":"/Users/craigb/deploy/chat-engine/node_modules/lodash/isBuffer.js","module":"./node_modules/lodash/isBuffer.js","moduleName":"./node_modules/lodash/isBuffer.js","type":"cjs require","userRequest":"module","loc":"1:0-41"},{"moduleId":88,"moduleIdentifier":"/Users/craigb/deploy/chat-engine/node_modules/lodash/_nodeUtil.js","module":"./node_modules/lodash/_nodeUtil.js","moduleName":"./node_modules/lodash/_nodeUtil.js","type":"cjs require","userRequest":"module","loc":"1:0-41"}],"usedExports":true,"providedExports":null,"optimizationBailout":[],"depth":11,"source":"module.exports = function(module) {\r\n\tif(!module.webpackPolyfill) {\r\n\t\tmodule.deprecate = function() {};\r\n\t\tmodule.paths = [];\r\n\t\t// module.parent = undefined by default\r\n\t\tif(!module.children) module.children = [];\r\n\t\tObject.defineProperty(module, \"loaded\", {\r\n\t\t\tenumerable: true,\r\n\t\t\tget: function() {\r\n\t\t\t\treturn module.l;\r\n\t\t\t}\r\n\t\t});\r\n\t\tObject.defineProperty(module, \"id\", {\r\n\t\t\tenumerable: true,\r\n\t\t\tget: function() {\r\n\t\t\t\treturn module.i;\r\n\t\t\t}\r\n\t\t});\r\n\t\tmodule.webpackPolyfill = 1;\r\n\t}\r\n\treturn module;\r\n};\r\n"},{"id":26,"identifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/components/user.js","name":"./src/components/user.js","index":99,"index2":96,"size":6752,"cacheable":true,"built":true,"optional":false,"prefetched":false,"chunks":[0],"assets":[],"issuer":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/bootstrap.js","issuerId":28,"issuerName":"./src/bootstrap.js","profile":{"factory":10,"building":130},"failed":false,"errors":0,"warnings":0,"reasons":[{"moduleId":28,"moduleIdentifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/bootstrap.js","module":"./src/bootstrap.js","moduleName":"./src/bootstrap.js","type":"cjs require","userRequest":"./components/user","loc":"10:11-39"},{"moduleId":99,"moduleIdentifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/components/me.js","module":"./src/components/me.js","moduleName":"./src/components/me.js","type":"cjs require","userRequest":"./user","loc":"13:11-28"}],"usedExports":true,"providedExports":null,"optimizationBailout":[],"depth":2,"source":"'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar Emitter = require('../modules/emitter');\n\n/**\nThis is our User class which represents a connected client. User's are automatically created and managed by {@link Chat}s, but you can also instantiate them yourself.\nIf a User has been created but has never been authenticated, you will recieve 403s when connecting to their feed or direct Chats.\n@class User\n@extends Emitter\n@extends RootEmitter\n@param {User#uuid} uuid A unique identifier for this user.\n@param {User#state} state The {@link User}'s state object synchronized between all clients of the chat.\n */\n\nvar User = function (_Emitter) {\n _inherits(User, _Emitter);\n\n function User(chatEngine, uuid) {\n var _ret;\n\n var state = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n\n _classCallCheck(this, User);\n\n var _this = _possibleConstructorReturn(this, (User.__proto__ || Object.getPrototypeOf(User)).call(this));\n\n _this.chatEngine = chatEngine;\n\n _this.name = 'User';\n\n /**\n The User's unique identifier, usually a device uuid. This helps ChatEngine identify the user between events. This is public id exposed to the network.\n Check out [the wikipedia page on UUIDs](https://en.wikipedia.org/wiki/Universally_unique_identifier).\n @readonly\n @type String\n */\n _this.uuid = uuid.toString();\n\n /**\n * Gets the user state. See {@link Me#update} for how to assign state values.\n * @return {Object} Returns a generic JSON object containing state information.\n * @example\n *\n * // State\n * let state = user.state;\n */\n _this.state = state;\n\n _this._stateSet = false;\n\n /**\n * Feed is a Chat that only streams things a User does, like\n * 'startTyping' or 'idle' events for example. Anybody can subscribe\n * to a User's feed, but only the User can publish to it. Users will\n * not be able to converse in this channel.\n *\n * @type Chat\n * @example\n * // me\n * me.feed.emit('update', 'I may be away from my computer right now');\n *\n * // another instance\n * them.feed.connect();\n * them.feed.on('update', (payload) => {})\n */\n\n // grants for these chats are done on auth. Even though they're marked private, they are locked down via the server\n _this.feed = new _this.chatEngine.Chat([chatEngine.global.channel, 'user', uuid, 'read.', 'feed'].join('#'), false, _this.constructor.name === 'Me', {}, 'system');\n\n /**\n * Direct is a private channel that anybody can publish to but only\n * the user can subscribe to. Great for pushing notifications or\n * inviting to other chats. Users will not be able to communicate\n * with one another inside of this chat. Check out the\n * {@link Chat#invite} method for private chats utilizing\n * {@link User#direct}.\n *\n * @type Chat\n * @example\n * // me\n * me.direct.on('private-message', (payload) -> {\n * console.log(payload.sender.uuid, 'sent your a direct message');\n * });\n *\n * // another instance\n * them.direct.connect();\n * them.direct.emit('private-message', {secret: 42});\n */\n _this.direct = new _this.chatEngine.Chat([chatEngine.global.channel, 'user', uuid, 'write.', 'direct'].join('#'), false, _this.constructor.name === 'Me', {}, 'system');\n\n // if the user does not exist at all and we get enough\n // information to build the user\n if (!chatEngine.users[uuid]) {\n chatEngine.users[uuid] = _this;\n }\n\n if (Object.keys(state).length) {\n // update this user's state in it's created context\n _this.assign(state);\n }\n\n return _ret = _this, _possibleConstructorReturn(_this, _ret);\n }\n\n /**\n this is only called from network updates\n @private\n */\n\n\n _createClass(User, [{\n key: 'assign',\n value: function assign(state) {\n\n var oldState = this.state || {};\n this.state = Object.assign(oldState, state);\n\n this._stateSet = true;\n }\n\n /**\n * @private\n * @param {Object} state The new state for the user\n */\n\n }, {\n key: 'update',\n value: function update(state) {\n this.assign(state);\n }\n\n /**\n Get stored user state from remote server.\n @private\n */\n\n }, {\n key: '_getStoredState',\n value: function _getStoredState(callback) {\n var _this2 = this;\n\n if (!this._stateSet) {\n\n this.chatEngine.request('get', 'user_state', {\n user: this.uuid\n }).then(function (res) {\n\n _this2.assign(res.data);\n callback(_this2.state);\n }).catch(function (err) {\n _this2.chatEngine.throwError(_this2, 'trigger', 'getState', err);\n });\n } else {\n callback(this.state);\n }\n }\n }]);\n\n return User;\n}(Emitter);\n\nmodule.exports = User;"},{"id":27,"identifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/index.js","name":"./src/index.js","index":0,"index2":100,"size":2628,"cacheable":true,"built":true,"optional":false,"prefetched":false,"chunks":[0],"assets":[],"issuer":null,"issuerId":null,"issuerName":null,"profile":{"factory":18,"building":193},"failed":false,"errors":0,"warnings":0,"reasons":[],"usedExports":true,"providedExports":null,"optimizationBailout":[],"depth":0,"source":"'use strict';\n\nvar init = require('./bootstrap');\n\n/**\nGlobal object used to create an instance of {@link ChatEngine}.\n\n@alias ChatEngineCore\n@param pnConfig {Object} ChatEngine is based off PubNub. Supply your PubNub configuration parameters here. See the getting started tutorial and [the PubNub docs](https://www.pubnub.com/docs/web-javascript/api-reference-configuration).\n@param ceConfig {Object} A list of ChatEngine specific configuration options.\n@param [ceConfig.globalChannel=chat-engine] {String} The root channel. See {@link ChatEngine.global}\n@param [ceConfig.enableSync] {Boolean} Synchronizes chats between instances with the same {@link Me#uuid}. See {@link Me#sync}.\n@param [ceConfig.enableMeta] {Boolean} Persists {@link Chat#meta} on the server. See {@link Chat#update}.\n@param [ceConfig.throwErrors=true] {Boolean} Throws errors in JS console.\n@param [ceConfig.endpoint='https://pubsub.pubnub.com/v1/blocks/sub-key/YOUR_SUB_KEY/chat-engine-server'] {String} The root URL of the server used to manage permissions for private channels. Set by default to match the PubNub functions deployed to your account. See {@tutorial privacy} for more.\n@param [ceConfig.debug] {Boolean} Logs all ChatEngine events to the console This should not be enabled in production.\n@param [ceConfig.profile] {Boolean} Sums event counts and outputs a table to the console every few seconds.\n@return {ChatEngine} Returns an instance of {@link ChatEngine}\n@example\nChatEngine = ChatEngineCore.create({\n publishKey: 'YOUR_PUB_KEY',\n subscribeKey: 'YOUR_SUB_KEY'\n});\n*/\n\nvar create = function create(pnConfig) {\n var ceConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n\n\n if (ceConfig.globalChannel) {\n ceConfig.globalChannel = ceConfig.globalChannel.toString();\n } else {\n ceConfig.globalChannel = 'chat-engine';\n }\n\n if (typeof ceConfig.throwErrors === 'undefined') {\n ceConfig.throwErrors = true;\n }\n\n if (typeof ceConfig.enableSync === 'undefined') {\n ceConfig.enableSync = false;\n }\n\n if (typeof ceConfig.enableMeta === 'undefined') {\n ceConfig.enableMeta = false;\n }\n\n ceConfig.endpoint = ceConfig.endpoint || 'https://pubsub.pubnub.com/v1/blocks/sub-key/' + pnConfig.subscribeKey + '/chat-engine-server';\n\n pnConfig.heartbeatInterval = pnConfig.heartbeatInterval || 0;\n\n // return an instance of ChatEngine\n return init(ceConfig, pnConfig);\n};\n\n// export the ChatEngine api\nvar ChatEngineCore = {\n plugin: {},\n create: create\n};\n\nmodule.exports = ChatEngineCore;\n\nmodule.exports.ChatEngineCore = ChatEngineCore;"},{"id":28,"identifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/bootstrap.js","name":"./src/bootstrap.js","index":1,"index2":99,"size":19556,"cacheable":true,"built":true,"optional":false,"prefetched":false,"chunks":[0],"assets":[],"issuer":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/index.js","issuerId":27,"issuerName":"./src/index.js","profile":{"factory":2,"building":132},"failed":false,"errors":0,"warnings":0,"reasons":[{"moduleId":27,"moduleIdentifier":"/Users/craigb/deploy/chat-engine/node_modules/babel-loader/lib/index.js??ref--1!/Users/craigb/deploy/chat-engine/src/index.js","module":"./src/index.js","moduleName":"./src/index.js","type":"cjs require","userRequest":"./bootstrap","loc":"3:11-33"}],"usedExports":true,"providedExports":null,"optimizationBailout":[],"depth":1,"source":"'use strict';\n\nvar axios = require('axios');\nvar PubNub = require('pubnub');\nvar pack = require('../package.json');\n\nvar RootEmitter = require('./modules/root_emitter');\nvar Chat = require('./components/chat');\nvar Me = require('./components/me');\nvar User = require('./components/user');\nvar waterfall = require('async/waterfall');\n\n/**\n@class ChatEngine\n@extends RootEmitter\n@return {ChatEngine} Returns an instance of {@link ChatEngine}\n*/\nmodule.exports = function () {\n var ceConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n var pnConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n\n\n // Create the root ChatEngine object\n var ChatEngine = new RootEmitter();\n\n ChatEngine.ceConfig = ceConfig;\n ChatEngine.pnConfig = pnConfig;\n\n /**\n * A map of all known {@link User}s in this instance of ChatEngine.\n * @type {Object}\n * @memberof ChatEngine\n */\n ChatEngine.users = {};\n\n /**\n * A map of all known {@link Chat}s in this instance of ChatEngine.\n * @memberof ChatEngine\n * @type {Object}\n */\n ChatEngine.chats = {};\n\n /**\n * A global {@link Chat} that all {@link User}s join when they connect to ChatEngine. Useful for announcements, alerts, and global events.\n * @member {Chat} global\n * @memberof ChatEngine\n */\n ChatEngine.global = false;\n\n /**\n * This instance of ChatEngine represented as a special {@link User} know as {@link Me}.\n * @member {Me} me\n * @memberof ChatEngine\n */\n ChatEngine.me = false;\n\n /**\n * An instance of PubNub, the networking infrastructure that powers the realtime communication between {@link User}s in {@link Chats}.\n * @member {Object} pubnub\n * @memberof ChatEngine\n */\n ChatEngine.pubnub = false;\n\n /**\n * Indicates if ChatEngine has fired the {@link ChatEngine#$\".\"ready} event.\n * @member {Object} ready\n * @memberof ChatEngine\n */\n ChatEngine.ready = false;\n\n /**\n * The package.json for ChatEngine. Used mainly for detecting package version.\n * @type {Object}\n */\n ChatEngine.package = pack;\n\n ChatEngine.throwError = function (self, cb, key, ceError) {\n var payload = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};\n\n\n if (ceConfig.throwErrors) {\n // throw ceError;\n console.error(payload);\n throw ceError;\n }\n\n payload.ceError = ceError.toString();\n\n self[cb](['$', 'error', key].join('.'), payload);\n };\n\n if (ceConfig.debug) {\n\n ChatEngine.onAny(function (event, payload) {\n console.info('debug:', event, payload);\n });\n }\n\n if (ceConfig.profile) {\n\n var countObject = {};\n\n ChatEngine.onAny(function (event) {\n countObject['event: ' + event] = countObject[event] || 0;\n countObject['event: ' + event] += 1;\n });\n\n setInterval(function () {\n\n countObject.chats = Object.keys(ChatEngine.chats).length;\n countObject.users = Object.keys(ChatEngine.users).length;\n\n console.table(countObject);\n }, 3000);\n }\n\n ChatEngine.protoPlugins = {};\n\n /**\n * Bind a plugin to all future instances of a Class.\n * @method ChatEngine#proto\n * @param {String} className The string representation of a class to bind to\n * @param {Class} plugin The plugin function.\n */\n ChatEngine.proto = function (className, plugin) {\n ChatEngine.protoPlugins[className] = ChatEngine.protoPlugins[className] || [];\n ChatEngine.protoPlugins[className].push(plugin);\n };\n\n /**\n * @private\n */\n ChatEngine.request = function (method, route) {\n var inputBody = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n var inputParams = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};\n\n\n var body = {\n uuid: ChatEngine.pnConfig.uuid,\n global: ceConfig.globalChannel,\n authKey: ChatEngine.pnConfig.authKey\n };\n\n var params = {\n route: route\n };\n\n body = Object.assign(body, inputBody);\n params = Object.assign(params, inputParams);\n\n if (method === 'get' || method === 'delete') {\n params = Object.assign(params, body);\n return axios[method](ceConfig.endpoint, { params: params });\n } else {\n return axios[method](ceConfig.endpoint, body, { params: params });\n }\n };\n\n /**\n * Parse a channel name into chat object parts\n * @private\n */\n ChatEngine.parseChannel = function (channel) {\n\n var info = channel.split('#');\n\n return {\n global: info[0],\n type: info[1],\n private: info[2] === 'private.'\n };\n };\n\n /**\n * Get the internal channel name of supplied string\n * @private\n */\n ChatEngine.augmentChannel = function () {\n var original = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Date().getTime();\n var isPrivate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;\n\n\n var channel = original.toString();\n\n // public.* has PubNub permissions for everyone to read and write\n // private.* is totally locked down and users must be granted access one by one\n var chanPrivString = 'public.';\n\n if (isPrivate) {\n chanPrivString = 'private.';\n }\n\n if (channel.indexOf(ChatEngine.ceConfig.globalChannel) === -1) {\n channel = [ChatEngine.ceConfig.globalChannel, 'chat', chanPrivString, channel].join('#');\n }\n\n return channel;\n };\n\n /**\n * Initial communication with the server. Server grants permissions to\n * talk in chats, etc.\n * @private\n */\n ChatEngine.handshake = function (complete) {\n\n waterfall([function (next) {\n ChatEngine.request('post', 'bootstrap').then(function () {\n next(null);\n }).catch(next);\n }, function (next) {\n ChatEngine.request('post', 'user_read').then(function () {\n next(null);\n }).catch(next);\n }, function (next) {\n ChatEngine.request('post', 'user_write').then(function () {\n next(null);\n }).catch(next);\n }, function (next) {\n ChatEngine.request('post', 'group').then(function () {\n next();\n }).catch(next);\n }], function (error) {\n\n if (error) {\n ChatEngine.throwError(ChatEngine, '_emit', 'auth', new Error('There was a problem logging into the auth server (' + ceConfig.endpoint + ').' + error && error.response && error.response.data), { error: error });\n } else {\n complete();\n }\n });\n };\n\n /**\n * Listen to PubNub events and forward them into ChatEngine system.\n * @private\n */\n ChatEngine.listenToPubNub = function () {\n\n ChatEngine.pubnub.addListener({\n message: function message(m) {\n\n // assign the message timetoken as a property of the payload\n m.message.timetoken = m.timetoken;\n\n if (ChatEngine.chats[m.channel]) {\n ChatEngine.chats[m.channel].trigger(m.message.event, m.message);\n }\n },\n presence: function presence(payload) {\n\n if (ChatEngine.chats[payload.channel]) {\n ChatEngine.chats[payload.channel].onPresence(payload);\n }\n },\n status: function status(statusEvent) {\n\n /**\n * SDK detected that network is online.\n * @event ChatEngine#$\".\"network\".\"up\".\"online\n */\n\n /**\n * SDK detected that network is down.\n * @event ChatEngine#$\".\"network\".\"down\".\"offline\n */\n\n /**\n * A subscribe event experienced an exception when running.\n * @event ChatEngine#$\".\"network\".\"down\".\"issue\n */\n\n /**\n * SDK was able to reconnect to pubnub.\n * @event ChatEngine#$\".\"network\".\"up\".\"reconnected\n */\n\n /**\n * SDK subscribed with a new mix of channels.\n * @event ChatEngine#$\".\"network\".\"up\".\"connected\n */\n\n /**\n * JSON parsing crashed.\n * @event ChatEngine#$\".\"network\".\"down\".\"malformed\n */\n\n /**\n * Server rejected the request.\n * @event ChatEngine#$\".\"network\".\"down\".\"badrequest\n */\n\n /**\n * If using decryption strategies and the decryption fails.\n * @event ChatEngine#$\".\"network\".\"down\".\"decryption\n */\n\n /**\n * Request timed out.\n * @event ChatEngine#$\".\"network\".\"down\".\"timeout\n */\n\n /**\n * PAM permission failure.\n * @event ChatEngine#$\".\"network\".\"down\".\"denied\n */\n\n // map the pubnub events into ChatEngine events\n var categories = {\n PNNetworkUpCategory: 'up.online',\n PNNetworkDownCategory: 'down.offline',\n PNNetworkIssuesCategory: 'down.issue',\n PNReconnectedCategory: 'up.reconnected',\n PNConnectedCategory: 'up.connected',\n PNAccessDeniedCategory: 'down.denied',\n PNMalformedResponseCategory: 'down.malformed',\n PNBadRequestCategory: 'down.badrequest',\n PNDecryptionErrorCategory: 'down.decryption',\n PNTimeoutCategory: 'down.timeout'\n };\n\n var eventName = ['$', 'network', categories[statusEvent.category] || 'other'].join('.');\n\n ChatEngine._emit(eventName, statusEvent);\n }\n });\n };\n\n /**\n * Subscribe to PubNub and begin receiving events.\n * @private\n */\n ChatEngine.subscribeToPubNub = function () {\n\n var chanGroups = [ceConfig.globalChannel + '#' + ChatEngine.me.uuid + '#rooms', ceConfig.globalChannel + '#' + ChatEngine.me.uuid + '#system', ceConfig.globalChannel + '#' + ChatEngine.me.uuid + '#custom'];\n\n ChatEngine.pubnub.subscribe({\n channelGroups: chanGroups,\n withPresence: true\n });\n };\n\n /**\n * Initialize ChatEngine modules on first time boot.\n * @private\n */\n ChatEngine.firstConnect = function (state) {\n\n ChatEngine.pubnub = new PubNub(ChatEngine.pnConfig);\n\n // create a new chat to use as global chat\n // we don't do auth on this one because it's assumed to be done with the /auth request below\n ChatEngine.global = new ChatEngine.Chat(ceConfig.globalChannel, false, true, {}, 'system');\n\n ChatEngine.global.once('$.connected', function () {\n\n // build the current user\n ChatEngine.me = new Me(ChatEngine, ChatEngine.pnConfig.uuid);\n\n /**\n * Fired when a {@link Me} has been created within ChatEngine.\n * @event ChatEngine#$\".\"created\".\"me\n * @example\n * ChatEngine.on('$.created.me', (data, me) => {\n * console.log('Me was created', me);\n * });\n */\n ChatEngine.me.onConstructed();\n\n if (ChatEngine.ceConfig.enableSync) {\n ChatEngine.me.session.subscribe();\n }\n\n ChatEngine.me.update(state, function () {\n\n /**\n * Fired when ChatEngine is connected to the internet and ready to go!\n * @event ChatEngine#$\".\"ready\n * @example\n * ChatEngine.on('$.ready', (data) => {\n * let me = data.me;\n * })\n */\n ChatEngine._emit('$.ready', {\n me: ChatEngine.me\n });\n\n ChatEngine.ready = true;\n\n ChatEngine.listenToPubNub();\n ChatEngine.subscribeToPubNub();\n\n ChatEngine.global.getUserUpdates();\n\n if (ChatEngine.ceConfig.enableSync) {\n ChatEngine.me.session.restore();\n }\n });\n });\n };\n\n /**\n * Disconnect from all {@link Chat}s and mark them as asleep.\n * @method ChatEngine#disconnect\n * @example\n *\n * // create a new chat\n * let chat = new ChatEngine.Chat(new Date().getTime());\n *\n * // disconnect from ChatEngine\n * ChatEngine.disconnect();\n *\n * // every individual chat will be disconnected\n * chat.on('$.disconnected', () => {\n * done();\n * });\n *\n * // Changing User:\n * ChatEngine.disconnect()\n * ChatEngine = new ChatEngine({}, {});\n * ChatEngine.connect()\n */\n ChatEngine.disconnect = function () {\n\n // Unsubscribe from all PubNub chats\n ChatEngine.pubnub.unsubscribeAll();\n\n // for every chat in ChatEngine.chats, signal disconnected\n Object.keys(ChatEngine.chats).forEach(function (key) {\n ChatEngine.chats[key].sleep();\n });\n };\n\n /**\n * Performs authentication with server and restores connection\n * to all sleeping chats.\n * @method ChatEngine#reconnect\n * @example\n *\n * // create a new chat\n * let chat = new ChatEngine.Chat(new Date().getTime());\n *\n * // disconnect from ChatEngine\n * ChatEngine.disconnect();\n *\n * // reconnect sometime later\n * ChatEngine.reconnect();\n *\n */\n ChatEngine.reconnect = function () {\n\n // do the whole auth flow with the new authKey\n ChatEngine.handshake(function () {\n // for every chat in ChatEngine.chats, call .connect()\n Object.keys(ChatEngine.chats).forEach(function (key) {\n ChatEngine.chats[key].wake();\n });\n\n ChatEngine.subscribeToPubNub();\n });\n };\n\n /**\n @private\n */\n ChatEngine.setAuth = function () {\n var authKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : PubNub.generateUUID();\n\n\n ChatEngine.pnConfig.authKey = authKey;\n ChatEngine.pubnub.setAuthKey(authKey);\n };\n\n /**\n * Disconnects, changes authentication token, performs handshake with server\n * and reconnects with new auth key. Used for extending logged in sessions\n * for active users.\n * @method ChatEngine#reauthorize\n * @example\n * // early\n * ChatEngine.connect(...);\n *\n * ChatEngine.once('$.connected', () => {\n * // first connection established\n * });\n *\n * // some time passes, session token expires\n * ChatEngine.reauthorize(authKey);\n *\n * // we are connected again\n * ChatEngine.once('$.connected', () => {\n * // we are connected again\n * });\n */\n ChatEngine.reauthorize = function () {\n var authKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : PubNub.generateUUID();\n\n\n ChatEngine.global.once('$.disconnected', function () {\n\n ChatEngine.setAuth(authKey);\n ChatEngine.reconnect();\n });\n\n ChatEngine.disconnect();\n };\n\n /**\n * Connect to realtime service and create instance of {@link Me}\n * @method ChatEngine#connect\n * @param {String} uuid A unique string for {@link Me}. It can be a device id, username, user id, email, etc. Must be alphanumeric.\n * @param {Object} [state={}] An object containing information about this client ({@link Me}). This JSON object is sent to all other clients on the network, so no passwords!\n * @param {String} [authKey] A authentication secret. Will be sent to authentication backend for validation. This is usually an access token. See {@tutorial auth} for more.\n * @fires $\".\"connected\n */\n ChatEngine.connect = function (uuid) {\n var state = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var authKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : PubNub.generateUUID();\n\n\n // this creates a user known as Me and\n // connects to the global chatroom\n ChatEngine.pnConfig.uuid = uuid;\n ChatEngine.pnConfig.authKey = authKey;\n\n ChatEngine.handshake(function () {\n ChatEngine.firstConnect(state);\n });\n };\n\n ChatEngine.destroy = function () {\n\n Object.keys(ChatEngine.cha