From 3a2680cb51f38091a75a4118c8f52a064546db47 Mon Sep 17 00:00:00 2001 From: James Lees Date: Wed, 25 Sep 2019 17:11:12 +0100 Subject: [PATCH 1/4] update changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd6fb7140..cdd09be88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 5.0.2 (2019-09-25) + +[FIXED] Utilise new API for @react-native-community/netinfo suppressing +deprecation warnings + +[CHANGED] output an ES6 module from typescript to allow webpack to optimise the +bundle more effectively (thanks to @stof for this change) + +[CHANGED] Use prettier to format source + ## 5.0.1 (2019-09-02) [FIXED] We no longer include an unnecessary Buffer polyfill in bundles From 2ac2c77d468c80851273ee5cb36b68661464e0eb Mon Sep 17 00:00:00 2001 From: James Lees Date: Wed, 25 Sep 2019 17:11:26 +0100 Subject: [PATCH 2/4] 5.0.2 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1e4c83435..e55344515 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "pusher-js", - "version": "5.0.1", + "version": "5.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 36813d851..093c4ee4d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pusher-js", - "version": "5.0.1", + "version": "5.0.2", "description": "Pusher Channels JavaScript library for browsers, React Native, NodeJS and web workers", "main": "dist/node/pusher.js", "browser": "dist/web/pusher.js", From 9096e904891a585032cea526f6df31de8809f11a Mon Sep 17 00:00:00 2001 From: James Lees Date: Wed, 25 Sep 2019 17:13:59 +0100 Subject: [PATCH 3/4] add built bundles --- dist/node/pusher.js | 17483 ++++++++++++++--------------- dist/react-native/pusher.js | 4 +- dist/web/pusher.js | 9923 ++++++++-------- dist/web/pusher.min.js | 4 +- dist/worker/pusher.worker.js | 9002 +++++++-------- dist/worker/pusher.worker.min.js | 4 +- 6 files changed, 17598 insertions(+), 18822 deletions(-) diff --git a/dist/node/pusher.js b/dist/node/pusher.js index e97a09022..6bfc3c324 100644 --- a/dist/node/pusher.js +++ b/dist/node/pusher.js @@ -1,5 +1,5 @@ /*! - * Pusher JavaScript Library v5.0.1 + * Pusher JavaScript Library v5.0.2 * https://pusher.com/ * * Copyright 2017, Pusher @@ -90,502 +90,96 @@ module.exports = /******/ /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 32); +/******/ return __webpack_require__(__webpack_require__.s = 20); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ +/***/ (function(module, exports) { + +module.exports = require("util"); + +/***/ }), +/* 1 */ /***/ (function(module, exports, __webpack_require__) { -"use strict"; +/* eslint-disable node/no-deprecated-api */ +var buffer = __webpack_require__(21) +var Buffer = buffer.Buffer -exports.__esModule = true; -var base64_1 = __webpack_require__(34); -var util_1 = __webpack_require__(3); -function extend(target) { - var sources = []; - for (var _i = 1; _i < arguments.length; _i++) { - sources[_i - 1] = arguments[_i]; - } - for (var i = 0; i < sources.length; i++) { - var extensions = sources[i]; - for (var property in extensions) { - if (extensions[property] && extensions[property].constructor && - extensions[property].constructor === Object) { - target[property] = extend(target[property] || {}, extensions[property]); - } - else { - target[property] = extensions[property]; - } - } - } - return target; -} -exports.extend = extend; -function stringify() { - var m = ["Pusher"]; - for (var i = 0; i < arguments.length; i++) { - if (typeof arguments[i] === "string") { - m.push(arguments[i]); - } - else { - m.push(safeJSONStringify(arguments[i])); - } - } - return m.join(" : "); -} -exports.stringify = stringify; -function arrayIndexOf(array, item) { - var nativeIndexOf = Array.prototype.indexOf; - if (array === null) { - return -1; - } - if (nativeIndexOf && array.indexOf === nativeIndexOf) { - return array.indexOf(item); - } - for (var i = 0, l = array.length; i < l; i++) { - if (array[i] === item) { - return i; - } - } - return -1; -} -exports.arrayIndexOf = arrayIndexOf; -function objectApply(object, f) { - for (var key in object) { - if (Object.prototype.hasOwnProperty.call(object, key)) { - f(object[key], key, object); - } - } -} -exports.objectApply = objectApply; -function keys(object) { - var keys = []; - objectApply(object, function (_, key) { - keys.push(key); - }); - return keys; -} -exports.keys = keys; -function values(object) { - var values = []; - objectApply(object, function (value) { - values.push(value); - }); - return values; -} -exports.values = values; -function apply(array, f, context) { - for (var i = 0; i < array.length; i++) { - f.call(context || global, array[i], i, array); - } -} -exports.apply = apply; -function map(array, f) { - var result = []; - for (var i = 0; i < array.length; i++) { - result.push(f(array[i], i, array, result)); - } - return result; -} -exports.map = map; -function mapObject(object, f) { - var result = {}; - objectApply(object, function (value, key) { - result[key] = f(value); - }); - return result; -} -exports.mapObject = mapObject; -function filter(array, test) { - test = test || function (value) { return !!value; }; - var result = []; - for (var i = 0; i < array.length; i++) { - if (test(array[i], i, array, result)) { - result.push(array[i]); - } - } - return result; +// alternative to using Object.keys for old browsers +function copyProps (src, dst) { + for (var key in src) { + dst[key] = src[key] + } } -exports.filter = filter; -function filterObject(object, test) { - var result = {}; - objectApply(object, function (value, key) { - if ((test && test(value, key, object, result)) || Boolean(value)) { - result[key] = value; - } - }); - return result; +if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { + module.exports = buffer +} else { + // Copy properties from require('buffer') + copyProps(buffer, exports) + exports.Buffer = SafeBuffer } -exports.filterObject = filterObject; -function flatten(object) { - var result = []; - objectApply(object, function (value, key) { - result.push([key, value]); - }); - return result; + +function SafeBuffer (arg, encodingOrOffset, length) { + return Buffer(arg, encodingOrOffset, length) } -exports.flatten = flatten; -function any(array, test) { - for (var i = 0; i < array.length; i++) { - if (test(array[i], i, array)) { - return true; - } - } - return false; + +// Copy static methods from Buffer +copyProps(Buffer, SafeBuffer) + +SafeBuffer.from = function (arg, encodingOrOffset, length) { + if (typeof arg === 'number') { + throw new TypeError('Argument must not be a number') + } + return Buffer(arg, encodingOrOffset, length) } -exports.any = any; -function all(array, test) { - for (var i = 0; i < array.length; i++) { - if (!test(array[i], i, array)) { - return false; - } + +SafeBuffer.alloc = function (size, fill, encoding) { + if (typeof size !== 'number') { + throw new TypeError('Argument must be a number') + } + var buf = Buffer(size) + if (fill !== undefined) { + if (typeof encoding === 'string') { + buf.fill(fill, encoding) + } else { + buf.fill(fill) } - return true; -} -exports.all = all; -function encodeParamsObject(data) { - return mapObject(data, function (value) { - if (typeof value === "object") { - value = safeJSONStringify(value); - } - return encodeURIComponent(base64_1["default"](value.toString())); - }); -} -exports.encodeParamsObject = encodeParamsObject; -function buildQueryString(data) { - var params = filterObject(data, function (value) { - return value !== undefined; - }); - var query = map(flatten(encodeParamsObject(params)), util_1["default"].method("join", "=")).join("&"); - return query; + } else { + buf.fill(0) + } + return buf } -exports.buildQueryString = buildQueryString; -function decycleObject(object) { - var objects = [], paths = []; - return (function derez(value, path) { - var i, name, nu; - switch (typeof value) { - case 'object': - if (!value) { - return null; - } - for (i = 0; i < objects.length; i += 1) { - if (objects[i] === value) { - return { $ref: paths[i] }; - } - } - objects.push(value); - paths.push(path); - if (Object.prototype.toString.apply(value) === '[object Array]') { - nu = []; - for (i = 0; i < value.length; i += 1) { - nu[i] = derez(value[i], path + '[' + i + ']'); - } - } - else { - nu = {}; - for (name in value) { - if (Object.prototype.hasOwnProperty.call(value, name)) { - nu[name] = derez(value[name], path + '[' + JSON.stringify(name) + ']'); - } - } - } - return nu; - case 'number': - case 'string': - case 'boolean': - return value; - } - }(object, '$')); + +SafeBuffer.allocUnsafe = function (size) { + if (typeof size !== 'number') { + throw new TypeError('Argument must be a number') + } + return Buffer(size) } -exports.decycleObject = decycleObject; -function safeJSONStringify(source) { - try { - return JSON.stringify(source); - } - catch (e) { - return JSON.stringify(decycleObject(source)); - } + +SafeBuffer.allocUnsafeSlow = function (size) { + if (typeof size !== 'number') { + throw new TypeError('Argument must be a number') + } + return buffer.SlowBuffer(size) } -exports.safeJSONStringify = safeJSONStringify; /***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var runtime_1 = __webpack_require__(33); -var faye_websocket_1 = __webpack_require__(68); -var xmlhttprequest_1 = __webpack_require__(90); -var net_info_1 = __webpack_require__(95); -var xhr_auth_1 = __webpack_require__(96); -var xhr_timeline_1 = __webpack_require__(97); -var getDefaultStrategy = runtime_1["default"].getDefaultStrategy, Transports = runtime_1["default"].Transports, setup = runtime_1["default"].setup, getProtocol = runtime_1["default"].getProtocol, isXHRSupported = runtime_1["default"].isXHRSupported, getLocalStorage = runtime_1["default"].getLocalStorage, createXHR = runtime_1["default"].createXHR, createWebSocket = runtime_1["default"].createWebSocket, addUnloadListener = runtime_1["default"].addUnloadListener, removeUnloadListener = runtime_1["default"].removeUnloadListener, transportConnectionInitializer = runtime_1["default"].transportConnectionInitializer, createSocketRequest = runtime_1["default"].createSocketRequest, HTTPFactory = runtime_1["default"].HTTPFactory; -var NodeJS = { - getDefaultStrategy: getDefaultStrategy, - Transports: Transports, - setup: setup, - getProtocol: getProtocol, - isXHRSupported: isXHRSupported, - createSocketRequest: createSocketRequest, - getLocalStorage: getLocalStorage, - createXHR: createXHR, - createWebSocket: createWebSocket, - addUnloadListener: addUnloadListener, - removeUnloadListener: removeUnloadListener, - transportConnectionInitializer: transportConnectionInitializer, - HTTPFactory: HTTPFactory, - TimelineTransport: xhr_timeline_1["default"], - getAuthorizers: function () { - return { ajax: xhr_auth_1["default"] }; - }, - getWebSocketAPI: function () { - return faye_websocket_1.Client; - }, - getXHRAPI: function () { - return xmlhttprequest_1.XMLHttpRequest; - }, - getNetwork: function () { - return net_info_1.Network; - } -}; -exports["default"] = NodeJS; - - -/***/ }), -/* 2 */ -/***/ (function(module, exports) { - -module.exports = require("util"); - -/***/ }), -/* 3 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var timers_1 = __webpack_require__(8); -var Util = { - now: function () { - if (Date.now) { - return Date.now(); - } - else { - return new Date().valueOf(); - } - }, - defer: function (callback) { - return new timers_1.OneOffTimer(0, callback); - }, - method: function (name) { - var args = []; - for (var _i = 1; _i < arguments.length; _i++) { - args[_i - 1] = arguments[_i]; - } - var boundArguments = Array.prototype.slice.call(arguments, 1); - return function (object) { - return object[name].apply(object, boundArguments.concat(arguments)); - }; - } -}; -exports["default"] = Util; - - -/***/ }), -/* 4 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var collections_1 = __webpack_require__(0); -var pusher_1 = __webpack_require__(22); -var Logger = { - debug: function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - if (!pusher_1["default"].log) { - return; - } - pusher_1["default"].log(collections_1.stringify.apply(this, arguments)); - }, - warn: function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - var message = collections_1.stringify.apply(this, arguments); - if (pusher_1["default"].log) { - pusher_1["default"].log(message); - } - else if (global.console) { - if (global.console.warn) { - global.console.warn(message); - } - else if (global.console.log) { - global.console.log(message); - } - } - } -}; -exports["default"] = Logger; - - -/***/ }), -/* 5 */ -/***/ (function(module, exports, __webpack_require__) { - -/* eslint-disable node/no-deprecated-api */ -var buffer = __webpack_require__(69) -var Buffer = buffer.Buffer - -// alternative to using Object.keys for old browsers -function copyProps (src, dst) { - for (var key in src) { - dst[key] = src[key] - } -} -if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { - module.exports = buffer -} else { - // Copy properties from require('buffer') - copyProps(buffer, exports) - exports.Buffer = SafeBuffer -} - -function SafeBuffer (arg, encodingOrOffset, length) { - return Buffer(arg, encodingOrOffset, length) -} - -// Copy static methods from Buffer -copyProps(Buffer, SafeBuffer) - -SafeBuffer.from = function (arg, encodingOrOffset, length) { - if (typeof arg === 'number') { - throw new TypeError('Argument must not be a number') - } - return Buffer(arg, encodingOrOffset, length) -} - -SafeBuffer.alloc = function (size, fill, encoding) { - if (typeof size !== 'number') { - throw new TypeError('Argument must be a number') - } - var buf = Buffer(size) - if (fill !== undefined) { - if (typeof encoding === 'string') { - buf.fill(fill, encoding) - } else { - buf.fill(fill) - } - } else { - buf.fill(0) - } - return buf -} - -SafeBuffer.allocUnsafe = function (size) { - if (typeof size !== 'number') { - throw new TypeError('Argument must be a number') - } - return Buffer(size) -} - -SafeBuffer.allocUnsafeSlow = function (size) { - if (typeof size !== 'number') { - throw new TypeError('Argument must be a number') - } - return buffer.SlowBuffer(size) -} - - -/***/ }), -/* 6 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Collections = __webpack_require__(0); -var callback_registry_1 = __webpack_require__(40); -var Dispatcher = (function () { - function Dispatcher(failThrough) { - this.callbacks = new callback_registry_1["default"](); - this.global_callbacks = []; - this.failThrough = failThrough; - } - Dispatcher.prototype.bind = function (eventName, callback, context) { - this.callbacks.add(eventName, callback, context); - return this; - }; - Dispatcher.prototype.bind_global = function (callback) { - this.global_callbacks.push(callback); - return this; - }; - Dispatcher.prototype.unbind = function (eventName, callback, context) { - this.callbacks.remove(eventName, callback, context); - return this; - }; - Dispatcher.prototype.unbind_global = function (callback) { - if (!callback) { - this.global_callbacks = []; - return this; - } - this.global_callbacks = Collections.filter(this.global_callbacks || [], function (c) { return c !== callback; }); - return this; - }; - Dispatcher.prototype.unbind_all = function () { - this.unbind(); - this.unbind_global(); - return this; - }; - Dispatcher.prototype.emit = function (eventName, data, metadata) { - for (var i = 0; i < this.global_callbacks.length; i++) { - this.global_callbacks[i](eventName, data); - } - var callbacks = this.callbacks.get(eventName); - var args = []; - if (metadata) { - args.push(data, metadata); - } - else if (data) { - args.push(data); - } - if (callbacks && callbacks.length > 0) { - for (var i = 0; i < callbacks.length; i++) { - callbacks[i].fn.apply(callbacks[i].context || global, args); - } - } - else if (this.failThrough) { - this.failThrough(eventName, data); - } - return this; - }; - return Dispatcher; -}()); -exports["default"] = Dispatcher; - - -/***/ }), -/* 7 */ +/* 2 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -var Buffer = __webpack_require__(5).Buffer, - Emitter = __webpack_require__(70).EventEmitter, - util = __webpack_require__(2), - streams = __webpack_require__(71), - Headers = __webpack_require__(19), - Reader = __webpack_require__(72); +var Buffer = __webpack_require__(1).Buffer, + Emitter = __webpack_require__(22).EventEmitter, + util = __webpack_require__(0), + streams = __webpack_require__(23), + Headers = __webpack_require__(10), + Reader = __webpack_require__(24); var Base = function(request, url, options) { Emitter.call(this); @@ -774,4236 +368,957 @@ module.exports = Base; /***/ }), -/* 8 */ +/* 3 */ /***/ (function(module, exports, __webpack_require__) { -"use strict"; +(function(nacl) { +'use strict'; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var abstract_timer_1 = __webpack_require__(35); -function clearTimeout(timer) { - global.clearTimeout(timer); -} -function clearInterval(timer) { - global.clearInterval(timer); -} -var OneOffTimer = (function (_super) { - __extends(OneOffTimer, _super); - function OneOffTimer(delay, callback) { - return _super.call(this, setTimeout, clearTimeout, delay, function (timer) { - callback(); - return null; - }) || this; - } - return OneOffTimer; -}(abstract_timer_1["default"])); -exports.OneOffTimer = OneOffTimer; -var PeriodicTimer = (function (_super) { - __extends(PeriodicTimer, _super); - function PeriodicTimer(delay, callback) { - return _super.call(this, setInterval, clearInterval, delay, function (timer) { - callback(); - return timer; - }) || this; - } - return PeriodicTimer; -}(abstract_timer_1["default"])); -exports.PeriodicTimer = PeriodicTimer; +// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. +// Public domain. +// +// Implementation derived from TweetNaCl version 20140427. +// See for details: http://tweetnacl.cr.yp.to/ +var gf = function(init) { + var i, r = new Float64Array(16); + if (init) for (i = 0; i < init.length; i++) r[i] = init[i]; + return r; +}; -/***/ }), -/* 9 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var assistant_to_the_transport_manager_1 = __webpack_require__(43); -var handshake_1 = __webpack_require__(44); -var pusher_authorizer_1 = __webpack_require__(46); -var timeline_sender_1 = __webpack_require__(47); -var presence_channel_1 = __webpack_require__(48); -var private_channel_1 = __webpack_require__(18); -var encrypted_channel_1 = __webpack_require__(50); -var channel_1 = __webpack_require__(24); -var connection_manager_1 = __webpack_require__(53); -var channels_1 = __webpack_require__(54); -var Factory = { - createChannels: function () { - return new channels_1["default"](); - }, - createConnectionManager: function (key, options) { - return new connection_manager_1["default"](key, options); - }, - createChannel: function (name, pusher) { - return new channel_1["default"](name, pusher); - }, - createPrivateChannel: function (name, pusher) { - return new private_channel_1["default"](name, pusher); - }, - createPresenceChannel: function (name, pusher) { - return new presence_channel_1["default"](name, pusher); - }, - createEncryptedChannel: function (name, pusher) { - return new encrypted_channel_1["default"](name, pusher); - }, - createTimelineSender: function (timeline, options) { - return new timeline_sender_1["default"](timeline, options); - }, - createAuthorizer: function (channel, options) { - if (options.authorizer) { - return options.authorizer(channel, options); - } - return new pusher_authorizer_1["default"](channel, options); - }, - createHandshake: function (transport, callback) { - return new handshake_1["default"](transport, callback); - }, - createAssistantToTheTransportManager: function (manager, transport, options) { - return new assistant_to_the_transport_manager_1["default"](manager, transport, options); - } -}; -exports["default"] = Factory; +// Pluggable, initialized in high-level API below. +var randombytes = function(/* x, n */) { throw new Error('no PRNG'); }; +var _0 = new Uint8Array(16); +var _9 = new Uint8Array(32); _9[0] = 9; -/***/ }), -/* 10 */ -/***/ (function(module, exports, __webpack_require__) { +var gf0 = gf(), + gf1 = gf([1]), + _121665 = gf([0xdb41, 1]), + D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]), + D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]), + X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]), + Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]), + I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]); -"use strict"; +function ts64(x, i, h, l) { + x[i] = (h >> 24) & 0xff; + x[i+1] = (h >> 16) & 0xff; + x[i+2] = (h >> 8) & 0xff; + x[i+3] = h & 0xff; + x[i+4] = (l >> 24) & 0xff; + x[i+5] = (l >> 16) & 0xff; + x[i+6] = (l >> 8) & 0xff; + x[i+7] = l & 0xff; +} -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var BadEventName = (function (_super) { - __extends(BadEventName, _super); - function BadEventName(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return BadEventName; -}(Error)); -exports.BadEventName = BadEventName; -var RequestTimedOut = (function (_super) { - __extends(RequestTimedOut, _super); - function RequestTimedOut(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return RequestTimedOut; -}(Error)); -exports.RequestTimedOut = RequestTimedOut; -var TransportPriorityTooLow = (function (_super) { - __extends(TransportPriorityTooLow, _super); - function TransportPriorityTooLow(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return TransportPriorityTooLow; -}(Error)); -exports.TransportPriorityTooLow = TransportPriorityTooLow; -var TransportClosed = (function (_super) { - __extends(TransportClosed, _super); - function TransportClosed(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return TransportClosed; -}(Error)); -exports.TransportClosed = TransportClosed; -var UnsupportedFeature = (function (_super) { - __extends(UnsupportedFeature, _super); - function UnsupportedFeature(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return UnsupportedFeature; -}(Error)); -exports.UnsupportedFeature = UnsupportedFeature; -var UnsupportedTransport = (function (_super) { - __extends(UnsupportedTransport, _super); - function UnsupportedTransport(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return UnsupportedTransport; -}(Error)); -exports.UnsupportedTransport = UnsupportedTransport; -var UnsupportedStrategy = (function (_super) { - __extends(UnsupportedStrategy, _super); - function UnsupportedStrategy(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return UnsupportedStrategy; -}(Error)); -exports.UnsupportedStrategy = UnsupportedStrategy; +function vn(x, xi, y, yi, n) { + var i,d = 0; + for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i]; + return (1 & ((d - 1) >>> 8)) - 1; +} +function crypto_verify_16(x, xi, y, yi) { + return vn(x,xi,y,yi,16); +} -/***/ }), -/* 11 */ -/***/ (function(module, exports) { +function crypto_verify_32(x, xi, y, yi) { + return vn(x,xi,y,yi,32); +} -module.exports = require("crypto"); +function core_salsa20(o, p, k, c) { + var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, + j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, + j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, + j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, + j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, + j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, + j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, + j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, + j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, + j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, + j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, + j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, + j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, + j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, + j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, + j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; -/***/ }), -/* 12 */ -/***/ (function(module, exports, __webpack_require__) { + var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, + x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, + x15 = j15, u; -"use strict"; + for (var i = 0; i < 20; i += 2) { + u = x0 + x12 | 0; + x4 ^= u<<7 | u>>>(32-7); + u = x4 + x0 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x4 | 0; + x12 ^= u<<13 | u>>>(32-13); + u = x12 + x8 | 0; + x0 ^= u<<18 | u>>>(32-18); -exports.__esModule = true; -var urlStore = { - baseUrl: "https://pusher.com", - urls: { - authenticationEndpoint: { - path: "/docs/authenticating_users", - }, - javascriptQuickStart: { - path: "/docs/javascript_quick_start" - }, - triggeringClientEvents: { - path: "/docs/client_api_guide/client_events#trigger-events" - } - } -}; -var buildLogSuffix = function (key) { - var urlPrefix = "See:"; - var urlObj = urlStore.urls[key]; - if (!urlObj) - return ""; - var url; - if (urlObj.fullUrl) { - url = urlObj.fullUrl; - } - else if (urlObj.path) { - url = urlStore.baseUrl + urlObj.path; - } - if (!url) - return ""; - return urlPrefix + " " + url; -}; -exports["default"] = { buildLogSuffix: buildLogSuffix }; + u = x5 + x1 | 0; + x9 ^= u<<7 | u>>>(32-7); + u = x9 + x5 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x9 | 0; + x1 ^= u<<13 | u>>>(32-13); + u = x1 + x13 | 0; + x5 ^= u<<18 | u>>>(32-18); + u = x10 + x6 | 0; + x14 ^= u<<7 | u>>>(32-7); + u = x14 + x10 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x14 | 0; + x6 ^= u<<13 | u>>>(32-13); + u = x6 + x2 | 0; + x10 ^= u<<18 | u>>>(32-18); -/***/ }), -/* 13 */ -/***/ (function(module, exports, __webpack_require__) { + u = x15 + x11 | 0; + x3 ^= u<<7 | u>>>(32-7); + u = x3 + x15 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x3 | 0; + x11 ^= u<<13 | u>>>(32-13); + u = x11 + x7 | 0; + x15 ^= u<<18 | u>>>(32-18); -"use strict"; + u = x0 + x3 | 0; + x1 ^= u<<7 | u>>>(32-7); + u = x1 + x0 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x1 | 0; + x3 ^= u<<13 | u>>>(32-13); + u = x3 + x2 | 0; + x0 ^= u<<18 | u>>>(32-18); + u = x5 + x4 | 0; + x6 ^= u<<7 | u>>>(32-7); + u = x6 + x5 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x6 | 0; + x4 ^= u<<13 | u>>>(32-13); + u = x4 + x7 | 0; + x5 ^= u<<18 | u>>>(32-18); -// Protocol references: -// -// * http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75 -// * http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76 -// * http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17 + u = x10 + x9 | 0; + x11 ^= u<<7 | u>>>(32-7); + u = x11 + x10 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x11 | 0; + x9 ^= u<<13 | u>>>(32-13); + u = x9 + x8 | 0; + x10 ^= u<<18 | u>>>(32-18); -var Base = __webpack_require__(7), - Client = __webpack_require__(73), - Server = __webpack_require__(84); + u = x15 + x14 | 0; + x12 ^= u<<7 | u>>>(32-7); + u = x12 + x15 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x12 | 0; + x14 ^= u<<13 | u>>>(32-13); + u = x14 + x13 | 0; + x15 ^= u<<18 | u>>>(32-18); + } + x0 = x0 + j0 | 0; + x1 = x1 + j1 | 0; + x2 = x2 + j2 | 0; + x3 = x3 + j3 | 0; + x4 = x4 + j4 | 0; + x5 = x5 + j5 | 0; + x6 = x6 + j6 | 0; + x7 = x7 + j7 | 0; + x8 = x8 + j8 | 0; + x9 = x9 + j9 | 0; + x10 = x10 + j10 | 0; + x11 = x11 + j11 | 0; + x12 = x12 + j12 | 0; + x13 = x13 + j13 | 0; + x14 = x14 + j14 | 0; + x15 = x15 + j15 | 0; -var Driver = { - client: function(url, options) { - options = options || {}; - if (options.masking === undefined) options.masking = true; - return new Client(url, options); - }, + o[ 0] = x0 >>> 0 & 0xff; + o[ 1] = x0 >>> 8 & 0xff; + o[ 2] = x0 >>> 16 & 0xff; + o[ 3] = x0 >>> 24 & 0xff; - server: function(options) { - options = options || {}; - if (options.requireMasking === undefined) options.requireMasking = true; - return new Server(options); - }, + o[ 4] = x1 >>> 0 & 0xff; + o[ 5] = x1 >>> 8 & 0xff; + o[ 6] = x1 >>> 16 & 0xff; + o[ 7] = x1 >>> 24 & 0xff; - http: function() { - return Server.http.apply(Server, arguments); - }, + o[ 8] = x2 >>> 0 & 0xff; + o[ 9] = x2 >>> 8 & 0xff; + o[10] = x2 >>> 16 & 0xff; + o[11] = x2 >>> 24 & 0xff; - isSecureRequest: function(request) { - return Server.isSecureRequest(request); - }, + o[12] = x3 >>> 0 & 0xff; + o[13] = x3 >>> 8 & 0xff; + o[14] = x3 >>> 16 & 0xff; + o[15] = x3 >>> 24 & 0xff; - isWebSocket: function(request) { - return Base.isWebSocket(request); - }, + o[16] = x4 >>> 0 & 0xff; + o[17] = x4 >>> 8 & 0xff; + o[18] = x4 >>> 16 & 0xff; + o[19] = x4 >>> 24 & 0xff; - validateOptions: function(options, validKeys) { - Base.validateOptions(options, validKeys); - } -}; + o[20] = x5 >>> 0 & 0xff; + o[21] = x5 >>> 8 & 0xff; + o[22] = x5 >>> 16 & 0xff; + o[23] = x5 >>> 24 & 0xff; -module.exports = Driver; + o[24] = x6 >>> 0 & 0xff; + o[25] = x6 >>> 8 & 0xff; + o[26] = x6 >>> 16 & 0xff; + o[27] = x6 >>> 24 & 0xff; + o[28] = x7 >>> 0 & 0xff; + o[29] = x7 >>> 8 & 0xff; + o[30] = x7 >>> 16 & 0xff; + o[31] = x7 >>> 24 & 0xff; -/***/ }), -/* 14 */ -/***/ (function(module, exports) { + o[32] = x8 >>> 0 & 0xff; + o[33] = x8 >>> 8 & 0xff; + o[34] = x8 >>> 16 & 0xff; + o[35] = x8 >>> 24 & 0xff; -module.exports = require("stream"); + o[36] = x9 >>> 0 & 0xff; + o[37] = x9 >>> 8 & 0xff; + o[38] = x9 >>> 16 & 0xff; + o[39] = x9 >>> 24 & 0xff; -/***/ }), -/* 15 */ -/***/ (function(module, exports) { + o[40] = x10 >>> 0 & 0xff; + o[41] = x10 >>> 8 & 0xff; + o[42] = x10 >>> 16 & 0xff; + o[43] = x10 >>> 24 & 0xff; -module.exports = require("url"); + o[44] = x11 >>> 0 & 0xff; + o[45] = x11 >>> 8 & 0xff; + o[46] = x11 >>> 16 & 0xff; + o[47] = x11 >>> 24 & 0xff; -/***/ }), -/* 16 */ -/***/ (function(module, exports) { + o[48] = x12 >>> 0 & 0xff; + o[49] = x12 >>> 8 & 0xff; + o[50] = x12 >>> 16 & 0xff; + o[51] = x12 >>> 24 & 0xff; -var Event = function(eventType, options) { - this.type = eventType; - for (var key in options) - this[key] = options[key]; -}; + o[52] = x13 >>> 0 & 0xff; + o[53] = x13 >>> 8 & 0xff; + o[54] = x13 >>> 16 & 0xff; + o[55] = x13 >>> 24 & 0xff; -Event.prototype.initEvent = function(eventType, canBubble, cancelable) { - this.type = eventType; - this.bubbles = canBubble; - this.cancelable = cancelable; -}; + o[56] = x14 >>> 0 & 0xff; + o[57] = x14 >>> 8 & 0xff; + o[58] = x14 >>> 16 & 0xff; + o[59] = x14 >>> 24 & 0xff; -Event.prototype.stopPropagation = function() {}; -Event.prototype.preventDefault = function() {}; + o[60] = x15 >>> 0 & 0xff; + o[61] = x15 >>> 8 & 0xff; + o[62] = x15 >>> 16 & 0xff; + o[63] = x15 >>> 24 & 0xff; +} -Event.CAPTURING_PHASE = 1; -Event.AT_TARGET = 2; -Event.BUBBLING_PHASE = 3; +function core_hsalsa20(o,p,k,c) { + var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, + j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, + j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, + j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, + j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, + j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, + j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, + j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, + j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, + j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, + j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, + j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, + j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, + j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, + j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, + j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; -module.exports = Event; + var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, + x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, + x15 = j15, u; + for (var i = 0; i < 20; i += 2) { + u = x0 + x12 | 0; + x4 ^= u<<7 | u>>>(32-7); + u = x4 + x0 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x4 | 0; + x12 ^= u<<13 | u>>>(32-13); + u = x12 + x8 | 0; + x0 ^= u<<18 | u>>>(32-18); -/***/ }), -/* 17 */ -/***/ (function(module, exports, __webpack_require__) { + u = x5 + x1 | 0; + x9 ^= u<<7 | u>>>(32-7); + u = x9 + x5 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x9 | 0; + x1 ^= u<<13 | u>>>(32-13); + u = x1 + x13 | 0; + x5 ^= u<<18 | u>>>(32-18); -"use strict"; + u = x10 + x6 | 0; + x14 ^= u<<7 | u>>>(32-7); + u = x14 + x10 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x14 | 0; + x6 ^= u<<13 | u>>>(32-13); + u = x6 + x2 | 0; + x10 ^= u<<18 | u>>>(32-18); -exports.__esModule = true; -var Defaults = { - VERSION: "5.0.1", - PROTOCOL: 7, - host: 'ws.pusherapp.com', - ws_port: 80, - wss_port: 443, - ws_path: '', - sockjs_host: 'sockjs.pusher.com', - sockjs_http_port: 80, - sockjs_https_port: 443, - sockjs_path: "/pusher", - stats_host: 'stats.pusher.com', - channel_auth_endpoint: '/pusher/auth', - channel_auth_transport: 'ajax', - activity_timeout: 120000, - pong_timeout: 30000, - unavailable_timeout: 10000, - cdn_http: "http://js.pusher.com", - cdn_https: "https://js.pusher.com", - dependency_suffix: "" -}; -exports["default"] = Defaults; + u = x15 + x11 | 0; + x3 ^= u<<7 | u>>>(32-7); + u = x3 + x15 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x3 | 0; + x11 ^= u<<13 | u>>>(32-13); + u = x11 + x7 | 0; + x15 ^= u<<18 | u>>>(32-18); + u = x0 + x3 | 0; + x1 ^= u<<7 | u>>>(32-7); + u = x1 + x0 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x1 | 0; + x3 ^= u<<13 | u>>>(32-13); + u = x3 + x2 | 0; + x0 ^= u<<18 | u>>>(32-18); -/***/ }), -/* 18 */ -/***/ (function(module, exports, __webpack_require__) { + u = x5 + x4 | 0; + x6 ^= u<<7 | u>>>(32-7); + u = x6 + x5 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x6 | 0; + x4 ^= u<<13 | u>>>(32-13); + u = x4 + x7 | 0; + x5 ^= u<<18 | u>>>(32-18); -"use strict"; + u = x10 + x9 | 0; + x11 ^= u<<7 | u>>>(32-7); + u = x11 + x10 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x11 | 0; + x9 ^= u<<13 | u>>>(32-13); + u = x9 + x8 | 0; + x10 ^= u<<18 | u>>>(32-18); -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var factory_1 = __webpack_require__(9); -var channel_1 = __webpack_require__(24); -var PrivateChannel = (function (_super) { - __extends(PrivateChannel, _super); - function PrivateChannel() { - return _super !== null && _super.apply(this, arguments) || this; - } - PrivateChannel.prototype.authorize = function (socketId, callback) { - var authorizer = factory_1["default"].createAuthorizer(this, this.pusher.config); - return authorizer.authorize(socketId, callback); - }; - return PrivateChannel; -}(channel_1["default"])); -exports["default"] = PrivateChannel; + u = x15 + x14 | 0; + x12 ^= u<<7 | u>>>(32-7); + u = x12 + x15 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x12 | 0; + x14 ^= u<<13 | u>>>(32-13); + u = x14 + x13 | 0; + x15 ^= u<<18 | u>>>(32-18); + } + o[ 0] = x0 >>> 0 & 0xff; + o[ 1] = x0 >>> 8 & 0xff; + o[ 2] = x0 >>> 16 & 0xff; + o[ 3] = x0 >>> 24 & 0xff; -/***/ }), -/* 19 */ -/***/ (function(module, exports, __webpack_require__) { + o[ 4] = x5 >>> 0 & 0xff; + o[ 5] = x5 >>> 8 & 0xff; + o[ 6] = x5 >>> 16 & 0xff; + o[ 7] = x5 >>> 24 & 0xff; -"use strict"; + o[ 8] = x10 >>> 0 & 0xff; + o[ 9] = x10 >>> 8 & 0xff; + o[10] = x10 >>> 16 & 0xff; + o[11] = x10 >>> 24 & 0xff; + o[12] = x15 >>> 0 & 0xff; + o[13] = x15 >>> 8 & 0xff; + o[14] = x15 >>> 16 & 0xff; + o[15] = x15 >>> 24 & 0xff; -var Headers = function() { - this.clear(); -}; + o[16] = x6 >>> 0 & 0xff; + o[17] = x6 >>> 8 & 0xff; + o[18] = x6 >>> 16 & 0xff; + o[19] = x6 >>> 24 & 0xff; -Headers.prototype.ALLOWED_DUPLICATES = ['set-cookie', 'set-cookie2', 'warning', 'www-authenticate']; + o[20] = x7 >>> 0 & 0xff; + o[21] = x7 >>> 8 & 0xff; + o[22] = x7 >>> 16 & 0xff; + o[23] = x7 >>> 24 & 0xff; -Headers.prototype.clear = function() { - this._sent = {}; - this._lines = []; -}; + o[24] = x8 >>> 0 & 0xff; + o[25] = x8 >>> 8 & 0xff; + o[26] = x8 >>> 16 & 0xff; + o[27] = x8 >>> 24 & 0xff; -Headers.prototype.set = function(name, value) { - if (value === undefined) return; + o[28] = x9 >>> 0 & 0xff; + o[29] = x9 >>> 8 & 0xff; + o[30] = x9 >>> 16 & 0xff; + o[31] = x9 >>> 24 & 0xff; +} - name = this._strip(name); - value = this._strip(value); +function crypto_core_salsa20(out,inp,k,c) { + core_salsa20(out,inp,k,c); +} - var key = name.toLowerCase(); - if (!this._sent.hasOwnProperty(key) || this.ALLOWED_DUPLICATES.indexOf(key) >= 0) { - this._sent[key] = true; - this._lines.push(name + ': ' + value + '\r\n'); - } -}; +function crypto_core_hsalsa20(out,inp,k,c) { + core_hsalsa20(out,inp,k,c); +} -Headers.prototype.toString = function() { - return this._lines.join(''); -}; +var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]); + // "expand 32-byte k" -Headers.prototype._strip = function(string) { - return string.toString().replace(/^ */, '').replace(/ *$/, ''); -}; +function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) { + var z = new Uint8Array(16), x = new Uint8Array(64); + var u, i; + for (i = 0; i < 16; i++) z[i] = 0; + for (i = 0; i < 8; i++) z[i] = n[i]; + while (b >= 64) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i]; + u = 1; + for (i = 8; i < 16; i++) { + u = u + (z[i] & 0xff) | 0; + z[i] = u & 0xff; + u >>>= 8; + } + b -= 64; + cpos += 64; + mpos += 64; + } + if (b > 0) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i]; + } + return 0; +} -module.exports = Headers; +function crypto_stream_salsa20(c,cpos,b,n,k) { + var z = new Uint8Array(16), x = new Uint8Array(64); + var u, i; + for (i = 0; i < 16; i++) z[i] = 0; + for (i = 0; i < 8; i++) z[i] = n[i]; + while (b >= 64) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < 64; i++) c[cpos+i] = x[i]; + u = 1; + for (i = 8; i < 16; i++) { + u = u + (z[i] & 0xff) | 0; + z[i] = u & 0xff; + u >>>= 8; + } + b -= 64; + cpos += 64; + } + if (b > 0) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < b; i++) c[cpos+i] = x[i]; + } + return 0; +} +function crypto_stream(c,cpos,d,n,k) { + var s = new Uint8Array(32); + crypto_core_hsalsa20(s,n,k,sigma); + var sn = new Uint8Array(8); + for (var i = 0; i < 8; i++) sn[i] = n[i+16]; + return crypto_stream_salsa20(c,cpos,d,sn,s); +} -/***/ }), -/* 20 */ -/***/ (function(module, exports, __webpack_require__) { +function crypto_stream_xor(c,cpos,m,mpos,d,n,k) { + var s = new Uint8Array(32); + crypto_core_hsalsa20(s,n,k,sigma); + var sn = new Uint8Array(8); + for (var i = 0; i < 8; i++) sn[i] = n[i+16]; + return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s); +} -"use strict"; +/* +* Port of Andrew Moon's Poly1305-donna-16. Public domain. +* https://github.com/floodyberry/poly1305-donna +*/ +var poly1305 = function(key) { + this.buffer = new Uint8Array(16); + this.r = new Uint16Array(10); + this.h = new Uint16Array(10); + this.pad = new Uint16Array(8); + this.leftover = 0; + this.fin = 0; -var NodeHTTPParser = __webpack_require__(74).HTTPParser, - Buffer = __webpack_require__(5).Buffer; + var t0, t1, t2, t3, t4, t5, t6, t7; -var TYPES = { - request: NodeHTTPParser.REQUEST || 'request', - response: NodeHTTPParser.RESPONSE || 'response' -}; + t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff; + t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff; + t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03; + t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff; + t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff; + this.r[5] = ((t4 >>> 1)) & 0x1ffe; + t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff; + t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81; + t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff; + this.r[9] = ((t7 >>> 5)) & 0x007f; -var HttpParser = function(type) { - this._type = type; - this._parser = new NodeHTTPParser(TYPES[type]); - this._complete = false; - this.headers = {}; + this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8; + this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8; + this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8; + this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8; + this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8; + this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8; + this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8; + this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8; +}; - var current = null, - self = this; +poly1305.prototype.blocks = function(m, mpos, bytes) { + var hibit = this.fin ? 0 : (1 << 11); + var t0, t1, t2, t3, t4, t5, t6, t7, c; + var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9; - this._parser.onHeaderField = function(b, start, length) { - current = b.toString('utf8', start, start + length).toLowerCase(); - }; + var h0 = this.h[0], + h1 = this.h[1], + h2 = this.h[2], + h3 = this.h[3], + h4 = this.h[4], + h5 = this.h[5], + h6 = this.h[6], + h7 = this.h[7], + h8 = this.h[8], + h9 = this.h[9]; - this._parser.onHeaderValue = function(b, start, length) { - var value = b.toString('utf8', start, start + length); + var r0 = this.r[0], + r1 = this.r[1], + r2 = this.r[2], + r3 = this.r[3], + r4 = this.r[4], + r5 = this.r[5], + r6 = this.r[6], + r7 = this.r[7], + r8 = this.r[8], + r9 = this.r[9]; - if (self.headers.hasOwnProperty(current)) - self.headers[current] += ', ' + value; - else - self.headers[current] = value; - }; + while (bytes >= 16) { + t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff; + t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff; + t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff; + t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff; + t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff; + h5 += ((t4 >>> 1)) & 0x1fff; + t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff; + t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff; + t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff; + h9 += ((t7 >>> 5)) | hibit; - this._parser.onHeadersComplete = this._parser[NodeHTTPParser.kOnHeadersComplete] = - function(majorVersion, minorVersion, headers, method, pathname, statusCode) { - var info = arguments[0]; + c = 0; - if (typeof info === 'object') { - method = info.method; - pathname = info.url; - statusCode = info.statusCode; - headers = info.headers; - } + d0 = c; + d0 += h0 * r0; + d0 += h1 * (5 * r9); + d0 += h2 * (5 * r8); + d0 += h3 * (5 * r7); + d0 += h4 * (5 * r6); + c = (d0 >>> 13); d0 &= 0x1fff; + d0 += h5 * (5 * r5); + d0 += h6 * (5 * r4); + d0 += h7 * (5 * r3); + d0 += h8 * (5 * r2); + d0 += h9 * (5 * r1); + c += (d0 >>> 13); d0 &= 0x1fff; - self.method = (typeof method === 'number') ? HttpParser.METHODS[method] : method; - self.statusCode = statusCode; - self.url = pathname; + d1 = c; + d1 += h0 * r1; + d1 += h1 * r0; + d1 += h2 * (5 * r9); + d1 += h3 * (5 * r8); + d1 += h4 * (5 * r7); + c = (d1 >>> 13); d1 &= 0x1fff; + d1 += h5 * (5 * r6); + d1 += h6 * (5 * r5); + d1 += h7 * (5 * r4); + d1 += h8 * (5 * r3); + d1 += h9 * (5 * r2); + c += (d1 >>> 13); d1 &= 0x1fff; - if (!headers) return; + d2 = c; + d2 += h0 * r2; + d2 += h1 * r1; + d2 += h2 * r0; + d2 += h3 * (5 * r9); + d2 += h4 * (5 * r8); + c = (d2 >>> 13); d2 &= 0x1fff; + d2 += h5 * (5 * r7); + d2 += h6 * (5 * r6); + d2 += h7 * (5 * r5); + d2 += h8 * (5 * r4); + d2 += h9 * (5 * r3); + c += (d2 >>> 13); d2 &= 0x1fff; - for (var i = 0, n = headers.length, key, value; i < n; i += 2) { - key = headers[i].toLowerCase(); - value = headers[i+1]; - if (self.headers.hasOwnProperty(key)) - self.headers[key] += ', ' + value; - else - self.headers[key] = value; - } + d3 = c; + d3 += h0 * r3; + d3 += h1 * r2; + d3 += h2 * r1; + d3 += h3 * r0; + d3 += h4 * (5 * r9); + c = (d3 >>> 13); d3 &= 0x1fff; + d3 += h5 * (5 * r8); + d3 += h6 * (5 * r7); + d3 += h7 * (5 * r6); + d3 += h8 * (5 * r5); + d3 += h9 * (5 * r4); + c += (d3 >>> 13); d3 &= 0x1fff; - self._complete = true; - }; -}; + d4 = c; + d4 += h0 * r4; + d4 += h1 * r3; + d4 += h2 * r2; + d4 += h3 * r1; + d4 += h4 * r0; + c = (d4 >>> 13); d4 &= 0x1fff; + d4 += h5 * (5 * r9); + d4 += h6 * (5 * r8); + d4 += h7 * (5 * r7); + d4 += h8 * (5 * r6); + d4 += h9 * (5 * r5); + c += (d4 >>> 13); d4 &= 0x1fff; -HttpParser.METHODS = { - 0: 'DELETE', - 1: 'GET', - 2: 'HEAD', - 3: 'POST', - 4: 'PUT', - 5: 'CONNECT', - 6: 'OPTIONS', - 7: 'TRACE', - 8: 'COPY', - 9: 'LOCK', - 10: 'MKCOL', - 11: 'MOVE', - 12: 'PROPFIND', - 13: 'PROPPATCH', - 14: 'SEARCH', - 15: 'UNLOCK', - 16: 'BIND', - 17: 'REBIND', - 18: 'UNBIND', - 19: 'ACL', - 20: 'REPORT', - 21: 'MKACTIVITY', - 22: 'CHECKOUT', - 23: 'MERGE', - 24: 'M-SEARCH', - 25: 'NOTIFY', - 26: 'SUBSCRIBE', - 27: 'UNSUBSCRIBE', - 28: 'PATCH', - 29: 'PURGE', - 30: 'MKCALENDAR', - 31: 'LINK', - 32: 'UNLINK' -}; + d5 = c; + d5 += h0 * r5; + d5 += h1 * r4; + d5 += h2 * r3; + d5 += h3 * r2; + d5 += h4 * r1; + c = (d5 >>> 13); d5 &= 0x1fff; + d5 += h5 * r0; + d5 += h6 * (5 * r9); + d5 += h7 * (5 * r8); + d5 += h8 * (5 * r7); + d5 += h9 * (5 * r6); + c += (d5 >>> 13); d5 &= 0x1fff; -var VERSION = (process.version || '') - .match(/[0-9]+/g) - .map(function(n) { return parseInt(n, 10) }); + d6 = c; + d6 += h0 * r6; + d6 += h1 * r5; + d6 += h2 * r4; + d6 += h3 * r3; + d6 += h4 * r2; + c = (d6 >>> 13); d6 &= 0x1fff; + d6 += h5 * r1; + d6 += h6 * r0; + d6 += h7 * (5 * r9); + d6 += h8 * (5 * r8); + d6 += h9 * (5 * r7); + c += (d6 >>> 13); d6 &= 0x1fff; -if (VERSION[0] === 0 && VERSION[1] === 12) { - HttpParser.METHODS[16] = 'REPORT'; - HttpParser.METHODS[17] = 'MKACTIVITY'; - HttpParser.METHODS[18] = 'CHECKOUT'; - HttpParser.METHODS[19] = 'MERGE'; - HttpParser.METHODS[20] = 'M-SEARCH'; - HttpParser.METHODS[21] = 'NOTIFY'; - HttpParser.METHODS[22] = 'SUBSCRIBE'; - HttpParser.METHODS[23] = 'UNSUBSCRIBE'; - HttpParser.METHODS[24] = 'PATCH'; - HttpParser.METHODS[25] = 'PURGE'; -} + d7 = c; + d7 += h0 * r7; + d7 += h1 * r6; + d7 += h2 * r5; + d7 += h3 * r4; + d7 += h4 * r3; + c = (d7 >>> 13); d7 &= 0x1fff; + d7 += h5 * r2; + d7 += h6 * r1; + d7 += h7 * r0; + d7 += h8 * (5 * r9); + d7 += h9 * (5 * r8); + c += (d7 >>> 13); d7 &= 0x1fff; -HttpParser.prototype.isComplete = function() { - return this._complete; -}; + d8 = c; + d8 += h0 * r8; + d8 += h1 * r7; + d8 += h2 * r6; + d8 += h3 * r5; + d8 += h4 * r4; + c = (d8 >>> 13); d8 &= 0x1fff; + d8 += h5 * r3; + d8 += h6 * r2; + d8 += h7 * r1; + d8 += h8 * r0; + d8 += h9 * (5 * r9); + c += (d8 >>> 13); d8 &= 0x1fff; -HttpParser.prototype.parse = function(chunk) { - var consumed = this._parser.execute(chunk, 0, chunk.length); + d9 = c; + d9 += h0 * r9; + d9 += h1 * r8; + d9 += h2 * r7; + d9 += h3 * r6; + d9 += h4 * r5; + c = (d9 >>> 13); d9 &= 0x1fff; + d9 += h5 * r4; + d9 += h6 * r3; + d9 += h7 * r2; + d9 += h8 * r1; + d9 += h9 * r0; + c += (d9 >>> 13); d9 &= 0x1fff; - if (typeof consumed !== 'number') { - this.error = consumed; - this._complete = true; - return; - } + c = (((c << 2) + c)) | 0; + c = (c + d0) | 0; + d0 = c & 0x1fff; + c = (c >>> 13); + d1 += c; - if (this._complete) - this.body = (consumed < chunk.length) - ? chunk.slice(consumed) - : Buffer.alloc(0); + h0 = d0; + h1 = d1; + h2 = d2; + h3 = d3; + h4 = d4; + h5 = d5; + h6 = d6; + h7 = d7; + h8 = d8; + h9 = d9; + + mpos += 16; + bytes -= 16; + } + this.h[0] = h0; + this.h[1] = h1; + this.h[2] = h2; + this.h[3] = h3; + this.h[4] = h4; + this.h[5] = h5; + this.h[6] = h6; + this.h[7] = h7; + this.h[8] = h8; + this.h[9] = h9; }; -module.exports = HttpParser; +poly1305.prototype.finish = function(mac, macpos) { + var g = new Uint16Array(10); + var c, mask, f, i; + if (this.leftover) { + i = this.leftover; + this.buffer[i++] = 1; + for (; i < 16; i++) this.buffer[i] = 0; + this.fin = 1; + this.blocks(this.buffer, 0, 16); + } -/***/ }), -/* 21 */ -/***/ (function(module, exports, __webpack_require__) { - -var Stream = __webpack_require__(14).Stream, - util = __webpack_require__(2), - driver = __webpack_require__(13), - EventTarget = __webpack_require__(30), - Event = __webpack_require__(16); - -var API = function(options) { - options = options || {}; - driver.validateOptions(options, ['headers', 'extensions', 'maxLength', 'ping', 'proxy', 'tls', 'ca']); - - this.readable = this.writable = true; - - var headers = options.headers; - if (headers) { - for (var name in headers) this._driver.setHeader(name, headers[name]); + c = this.h[1] >>> 13; + this.h[1] &= 0x1fff; + for (i = 2; i < 10; i++) { + this.h[i] += c; + c = this.h[i] >>> 13; + this.h[i] &= 0x1fff; } + this.h[0] += (c * 5); + c = this.h[0] >>> 13; + this.h[0] &= 0x1fff; + this.h[1] += c; + c = this.h[1] >>> 13; + this.h[1] &= 0x1fff; + this.h[2] += c; - var extensions = options.extensions; - if (extensions) { - [].concat(extensions).forEach(this._driver.addExtension, this._driver); + g[0] = this.h[0] + 5; + c = g[0] >>> 13; + g[0] &= 0x1fff; + for (i = 1; i < 10; i++) { + g[i] = this.h[i] + c; + c = g[i] >>> 13; + g[i] &= 0x1fff; } + g[9] -= (1 << 13); - this._ping = options.ping; - this._pingId = 0; - this.readyState = API.CONNECTING; - this.bufferedAmount = 0; - this.protocol = ''; - this.url = this._driver.url; - this.version = this._driver.version; + mask = (c ^ 1) - 1; + for (i = 0; i < 10; i++) g[i] &= mask; + mask = ~mask; + for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]; - var self = this; + this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff; + this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff; + this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff; + this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff; + this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff; + this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff; + this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff; + this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff; - this._driver.on('open', function(e) { self._open() }); - this._driver.on('message', function(e) { self._receiveMessage(e.data) }); - this._driver.on('close', function(e) { self._beginClose(e.reason, e.code) }); + f = this.h[0] + this.pad[0]; + this.h[0] = f & 0xffff; + for (i = 1; i < 8; i++) { + f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0; + this.h[i] = f & 0xffff; + } - this._driver.on('error', function(error) { - self._emitError(error.message); - }); - this.on('error', function() {}); + mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff; + mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff; + mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff; + mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff; + mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff; + mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff; + mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff; + mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff; + mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff; + mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff; + mac[macpos+10] = (this.h[5] >>> 0) & 0xff; + mac[macpos+11] = (this.h[5] >>> 8) & 0xff; + mac[macpos+12] = (this.h[6] >>> 0) & 0xff; + mac[macpos+13] = (this.h[6] >>> 8) & 0xff; + mac[macpos+14] = (this.h[7] >>> 0) & 0xff; + mac[macpos+15] = (this.h[7] >>> 8) & 0xff; +}; - this._driver.messages.on('drain', function() { - self.emit('drain'); - }); +poly1305.prototype.update = function(m, mpos, bytes) { + var i, want; - if (this._ping) - this._pingTimer = setInterval(function() { - self._pingId += 1; - self.ping(self._pingId.toString()); - }, this._ping * 1000); + if (this.leftover) { + want = (16 - this.leftover); + if (want > bytes) + want = bytes; + for (i = 0; i < want; i++) + this.buffer[this.leftover + i] = m[mpos+i]; + bytes -= want; + mpos += want; + this.leftover += want; + if (this.leftover < 16) + return; + this.blocks(this.buffer, 0, 16); + this.leftover = 0; + } - this._configureStream(); + if (bytes >= 16) { + want = bytes - (bytes % 16); + this.blocks(m, mpos, want); + mpos += want; + bytes -= want; + } - if (!this._proxy) { - this._stream.pipe(this._driver.io); - this._driver.io.pipe(this._stream); + if (bytes) { + for (i = 0; i < bytes; i++) + this.buffer[this.leftover + i] = m[mpos+i]; + this.leftover += bytes; } }; -util.inherits(API, Stream); -API.CONNECTING = 0; -API.OPEN = 1; -API.CLOSING = 2; -API.CLOSED = 3; +function crypto_onetimeauth(out, outpos, m, mpos, n, k) { + var s = new poly1305(k); + s.update(m, mpos, n); + s.finish(out, outpos); + return 0; +} -var instance = { - write: function(data) { - return this.send(data); - }, +function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) { + var x = new Uint8Array(16); + crypto_onetimeauth(x,0,m,mpos,n,k); + return crypto_verify_16(h,hpos,x,0); +} - end: function(data) { - if (data !== undefined) this.send(data); - this.close(); - }, +function crypto_secretbox(c,m,d,n,k) { + var i; + if (d < 32) return -1; + crypto_stream_xor(c,0,m,0,d,n,k); + crypto_onetimeauth(c, 16, c, 32, d - 32, c); + for (i = 0; i < 16; i++) c[i] = 0; + return 0; +} - pause: function() { - return this._driver.messages.pause(); - }, +function crypto_secretbox_open(m,c,d,n,k) { + var i; + var x = new Uint8Array(32); + if (d < 32) return -1; + crypto_stream(x,0,32,n,k); + if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1; + crypto_stream_xor(m,0,c,0,d,n,k); + for (i = 0; i < 32; i++) m[i] = 0; + return 0; +} - resume: function() { - return this._driver.messages.resume(); - }, +function set25519(r, a) { + var i; + for (i = 0; i < 16; i++) r[i] = a[i]|0; +} - send: function(data) { - if (this.readyState > API.OPEN) return false; - if (!(data instanceof Buffer)) data = String(data); - return this._driver.messages.write(data); - }, +function car25519(o) { + var i, v, c = 1; + for (i = 0; i < 16; i++) { + v = o[i] + c + 65535; + c = Math.floor(v / 65536); + o[i] = v - c * 65536; + } + o[0] += c-1 + 37 * (c-1); +} - ping: function(message, callback) { - if (this.readyState > API.OPEN) return false; - return this._driver.ping(message, callback); - }, +function sel25519(p, q, b) { + var t, c = ~(b-1); + for (var i = 0; i < 16; i++) { + t = c & (p[i] ^ q[i]); + p[i] ^= t; + q[i] ^= t; + } +} - close: function() { - if (this.readyState !== API.CLOSED) this.readyState = API.CLOSING; - this._driver.close(); - }, +function pack25519(o, n) { + var i, j, b; + var m = gf(), t = gf(); + for (i = 0; i < 16; i++) t[i] = n[i]; + car25519(t); + car25519(t); + car25519(t); + for (j = 0; j < 2; j++) { + m[0] = t[0] - 0xffed; + for (i = 1; i < 15; i++) { + m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1); + m[i-1] &= 0xffff; + } + m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1); + b = (m[15]>>16) & 1; + m[14] &= 0xffff; + sel25519(t, m, 1-b); + } + for (i = 0; i < 16; i++) { + o[2*i] = t[i] & 0xff; + o[2*i+1] = t[i]>>8; + } +} - _configureStream: function() { - var self = this; +function neq25519(a, b) { + var c = new Uint8Array(32), d = new Uint8Array(32); + pack25519(c, a); + pack25519(d, b); + return crypto_verify_32(c, 0, d, 0); +} - this._stream.setTimeout(0); - this._stream.setNoDelay(true); +function par25519(a) { + var d = new Uint8Array(32); + pack25519(d, a); + return d[0] & 1; +} - ['close', 'end'].forEach(function(event) { - this._stream.on(event, function() { self._finalizeClose() }); - }, this); +function unpack25519(o, n) { + var i; + for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8); + o[15] &= 0x7fff; +} - this._stream.on('error', function(error) { - self._emitError('Network error: ' + self.url + ': ' + error.message); - self._finalizeClose(); - }); - }, - - _open: function() { - if (this.readyState !== API.CONNECTING) return; - - this.readyState = API.OPEN; - this.protocol = this._driver.protocol || ''; - - var event = new Event('open'); - event.initEvent('open', false, false); - this.dispatchEvent(event); - }, - - _receiveMessage: function(data) { - if (this.readyState > API.OPEN) return false; - - if (this.readable) this.emit('data', data); - - var event = new Event('message', {data: data}); - event.initEvent('message', false, false); - this.dispatchEvent(event); - }, - - _emitError: function(message) { - if (this.readyState >= API.CLOSING) return; - - var event = new Event('error', {message: message}); - event.initEvent('error', false, false); - this.dispatchEvent(event); - }, - - _beginClose: function(reason, code) { - if (this.readyState === API.CLOSED) return; - this.readyState = API.CLOSING; - - if (this._stream) { - this._stream.end(); - if (!this._stream.readable) this._finalizeClose(); - } - this._closeParams = [reason, code]; - }, - - _finalizeClose: function() { - if (this.readyState === API.CLOSED) return; - this.readyState = API.CLOSED; - - if (this._pingTimer) clearInterval(this._pingTimer); - if (this._stream) this._stream.end(); - - if (this.readable) this.emit('end'); - this.readable = this.writable = false; - - var reason = this._closeParams ? this._closeParams[0] : '', - code = this._closeParams ? this._closeParams[1] : 1006; - - var event = new Event('close', {code: code, reason: reason}); - event.initEvent('close', false, false); - this.dispatchEvent(event); - } -}; - -for (var method in instance) API.prototype[method] = instance[method]; -for (var key in EventTarget) API.prototype[key] = EventTarget[key]; - -module.exports = API; - - -/***/ }), -/* 22 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var Collections = __webpack_require__(0); -var dispatcher_1 = __webpack_require__(6); -var timeline_1 = __webpack_require__(98); -var level_1 = __webpack_require__(31); -var strategy_builder_1 = __webpack_require__(99); -var timers_1 = __webpack_require__(8); -var defaults_1 = __webpack_require__(17); -var DefaultConfig = __webpack_require__(101); -var logger_1 = __webpack_require__(4); -var factory_1 = __webpack_require__(9); -var url_store_1 = __webpack_require__(12); -var Pusher = (function () { - function Pusher(app_key, options) { - var _this = this; - checkAppKey(app_key); - options = options || {}; - if (!options.cluster && !(options.wsHost || options.httpHost)) { - var suffix = url_store_1["default"].buildLogSuffix("javascriptQuickStart"); - logger_1["default"].warn("You should always specify a cluster when connecting. " + suffix); - } - this.key = app_key; - this.config = Collections.extend(DefaultConfig.getGlobalConfig(), options.cluster ? DefaultConfig.getClusterConfig(options.cluster) : {}, options); - this.channels = factory_1["default"].createChannels(); - this.global_emitter = new dispatcher_1["default"](); - this.sessionID = Math.floor(Math.random() * 1000000000); - this.timeline = new timeline_1["default"](this.key, this.sessionID, { - cluster: this.config.cluster, - features: Pusher.getClientFeatures(), - params: this.config.timelineParams || {}, - limit: 50, - level: level_1["default"].INFO, - version: defaults_1["default"].VERSION - }); - if (!this.config.disableStats) { - this.timelineSender = factory_1["default"].createTimelineSender(this.timeline, { - host: this.config.statsHost, - path: "/timeline/v2/" + runtime_1["default"].TimelineTransport.name - }); - } - var getStrategy = function (options) { - var config = Collections.extend({}, _this.config, options); - return runtime_1["default"].getDefaultStrategy(config, strategy_builder_1.defineTransport); - }; - this.connection = factory_1["default"].createConnectionManager(this.key, Collections.extend({ getStrategy: getStrategy, - timeline: this.timeline, - activityTimeout: this.config.activity_timeout, - pongTimeout: this.config.pong_timeout, - unavailableTimeout: this.config.unavailable_timeout - }, this.config, { useTLS: this.shouldUseTLS() })); - this.connection.bind('connected', function () { - _this.subscribeAll(); - if (_this.timelineSender) { - _this.timelineSender.send(_this.connection.isUsingTLS()); - } - }); - this.connection.bind('message', function (event) { - var eventName = event.event; - var internal = (eventName.indexOf('pusher_internal:') === 0); - if (event.channel) { - var channel = _this.channel(event.channel); - if (channel) { - channel.handleEvent(event); - } - } - if (!internal) { - _this.global_emitter.emit(event.event, event.data); - } - }); - this.connection.bind('connecting', function () { - _this.channels.disconnect(); - }); - this.connection.bind('disconnected', function () { - _this.channels.disconnect(); - }); - this.connection.bind('error', function (err) { - logger_1["default"].warn('Error', err); - }); - Pusher.instances.push(this); - this.timeline.info({ instances: Pusher.instances.length }); - if (Pusher.isReady) { - this.connect(); - } - } - Pusher.ready = function () { - Pusher.isReady = true; - for (var i = 0, l = Pusher.instances.length; i < l; i++) { - Pusher.instances[i].connect(); - } - }; - Pusher.log = function (message) { - if (Pusher.logToConsole && global.console && global.console.log) { - global.console.log(message); - } - }; - Pusher.getClientFeatures = function () { - return Collections.keys(Collections.filterObject({ "ws": runtime_1["default"].Transports.ws }, function (t) { return t.isSupported({}); })); - }; - Pusher.prototype.channel = function (name) { - return this.channels.find(name); - }; - Pusher.prototype.allChannels = function () { - return this.channels.all(); - }; - Pusher.prototype.connect = function () { - this.connection.connect(); - if (this.timelineSender) { - if (!this.timelineSenderTimer) { - var usingTLS = this.connection.isUsingTLS(); - var timelineSender = this.timelineSender; - this.timelineSenderTimer = new timers_1.PeriodicTimer(60000, function () { - timelineSender.send(usingTLS); - }); - } - } - }; - Pusher.prototype.disconnect = function () { - this.connection.disconnect(); - if (this.timelineSenderTimer) { - this.timelineSenderTimer.ensureAborted(); - this.timelineSenderTimer = null; - } - }; - Pusher.prototype.bind = function (event_name, callback, context) { - this.global_emitter.bind(event_name, callback, context); - return this; - }; - Pusher.prototype.unbind = function (event_name, callback, context) { - this.global_emitter.unbind(event_name, callback, context); - return this; - }; - Pusher.prototype.bind_global = function (callback) { - this.global_emitter.bind_global(callback); - return this; - }; - Pusher.prototype.unbind_global = function (callback) { - this.global_emitter.unbind_global(callback); - return this; - }; - Pusher.prototype.unbind_all = function (callback) { - this.global_emitter.unbind_all(); - return this; - }; - Pusher.prototype.subscribeAll = function () { - var channelName; - for (channelName in this.channels.channels) { - if (this.channels.channels.hasOwnProperty(channelName)) { - this.subscribe(channelName); - } - } - }; - Pusher.prototype.subscribe = function (channel_name) { - var channel = this.channels.add(channel_name, this); - if (channel.subscriptionPending && channel.subscriptionCancelled) { - channel.reinstateSubscription(); - } - else if (!channel.subscriptionPending && this.connection.state === "connected") { - channel.subscribe(); - } - return channel; - }; - Pusher.prototype.unsubscribe = function (channel_name) { - var channel = this.channels.find(channel_name); - if (channel && channel.subscriptionPending) { - channel.cancelSubscription(); - } - else { - channel = this.channels.remove(channel_name); - if (channel && this.connection.state === "connected") { - channel.unsubscribe(); - } - } - }; - Pusher.prototype.send_event = function (event_name, data, channel) { - return this.connection.send_event(event_name, data, channel); - }; - Pusher.prototype.shouldUseTLS = function () { - if (runtime_1["default"].getProtocol() === "https:") { - return true; - } - else if (this.config.forceTLS === true) { - return true; - } - else { - return Boolean(this.config.encrypted); - } - }; - Pusher.instances = []; - Pusher.isReady = false; - Pusher.logToConsole = false; - Pusher.Runtime = runtime_1["default"]; - Pusher.ScriptReceivers = runtime_1["default"].ScriptReceivers; - Pusher.DependenciesReceivers = runtime_1["default"].DependenciesReceivers; - Pusher.auth_callbacks = runtime_1["default"].auth_callbacks; - return Pusher; -}()); -exports["default"] = Pusher; -function checkAppKey(key) { - if (key === null || key === undefined) { - throw "You must pass your app key when you instantiate Pusher."; - } +function A(o, a, b) { + for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]; } -runtime_1["default"].setup(Pusher); - - -/***/ }), -/* 23 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; +function Z(o, a, b) { + for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]; +} -exports.__esModule = true; -exports.decodeMessage = function (messageEvent) { - try { - var messageData = JSON.parse(messageEvent.data); - var pusherEventData = messageData.data; - if (typeof pusherEventData === 'string') { - try { - pusherEventData = JSON.parse(messageData.data); - } - catch (e) { } - } - var pusherEvent = { - event: messageData.event, - channel: messageData.channel, - data: pusherEventData, - }; - if (messageData.user_id) { - pusherEvent.user_id = messageData.user_id; - } - return pusherEvent; - } - catch (e) { - throw { type: 'MessageParseError', error: e, data: messageEvent.data }; - } -}; -exports.encodeMessage = function (event) { - return JSON.stringify(event); -}; -exports.processHandshake = function (messageEvent) { - var message = exports.decodeMessage(messageEvent); - if (message.event === "pusher:connection_established") { - if (!message.data.activity_timeout) { - throw "No activity timeout specified in handshake"; - } - return { - action: "connected", - id: message.data.socket_id, - activityTimeout: message.data.activity_timeout * 1000 - }; - } - else if (message.event === "pusher:error") { - return { - action: this.getCloseAction(message.data), - error: this.getCloseError(message.data) - }; - } - else { - throw "Invalid handshake"; - } -}; -exports.getCloseAction = function (closeEvent) { - if (closeEvent.code < 4000) { - if (closeEvent.code >= 1002 && closeEvent.code <= 1004) { - return "backoff"; - } - else { - return null; - } - } - else if (closeEvent.code === 4000) { - return "tls_only"; - } - else if (closeEvent.code < 4100) { - return "refused"; - } - else if (closeEvent.code < 4200) { - return "backoff"; - } - else if (closeEvent.code < 4300) { - return "retry"; - } - else { - return "refused"; - } -}; -exports.getCloseError = function (closeEvent) { - if (closeEvent.code !== 1000 && closeEvent.code !== 1001) { - return { - type: 'PusherError', - data: { - code: closeEvent.code, - message: closeEvent.reason || closeEvent.message - } - }; - } - else { - return null; - } -}; - - -/***/ }), -/* 24 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var dispatcher_1 = __webpack_require__(6); -var Errors = __webpack_require__(10); -var logger_1 = __webpack_require__(4); -var url_store_1 = __webpack_require__(12); -var Channel = (function (_super) { - __extends(Channel, _super); - function Channel(name, pusher) { - var _this = _super.call(this, function (event, data) { - logger_1["default"].debug('No callbacks on ' + name + ' for ' + event); - }) || this; - _this.name = name; - _this.pusher = pusher; - _this.subscribed = false; - _this.subscriptionPending = false; - _this.subscriptionCancelled = false; - return _this; - } - Channel.prototype.authorize = function (socketId, callback) { - return callback(false, {}); - }; - Channel.prototype.trigger = function (event, data) { - if (event.indexOf("client-") !== 0) { - throw new Errors.BadEventName("Event '" + event + "' does not start with 'client-'"); - } - if (!this.subscribed) { - var suffix = url_store_1["default"].buildLogSuffix("triggeringClientEvents"); - logger_1["default"].warn("Client event triggered before channel 'subscription_succeeded' event . " + suffix); - } - return this.pusher.send_event(event, data, this.name); - }; - Channel.prototype.disconnect = function () { - this.subscribed = false; - this.subscriptionPending = false; - }; - Channel.prototype.handleEvent = function (event) { - var eventName = event.event; - var data = event.data; - if (eventName === "pusher_internal:subscription_succeeded") { - this.handleSubscriptionSucceededEvent(event); - } - else if (eventName.indexOf("pusher_internal:") !== 0) { - var metadata = {}; - this.emit(eventName, data, metadata); - } - }; - Channel.prototype.handleSubscriptionSucceededEvent = function (event) { - this.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } - else { - this.emit("pusher:subscription_succeeded", event.data); - } - }; - Channel.prototype.subscribe = function () { - var _this = this; - if (this.subscribed) { - return; - } - this.subscriptionPending = true; - this.subscriptionCancelled = false; - this.authorize(this.pusher.connection.socket_id, function (error, data) { - if (error) { - _this.emit('pusher:subscription_error', data); - } - else { - _this.pusher.send_event('pusher:subscribe', { - auth: data.auth, - channel_data: data.channel_data, - channel: _this.name - }); - } - }); - }; - Channel.prototype.unsubscribe = function () { - this.subscribed = false; - this.pusher.send_event('pusher:unsubscribe', { - channel: this.name - }); - }; - Channel.prototype.cancelSubscription = function () { - this.subscriptionCancelled = true; - }; - Channel.prototype.reinstateSubscription = function () { - this.subscriptionCancelled = false; - }; - return Channel; -}(dispatcher_1["default"])); -exports["default"] = Channel; - - -/***/ }), -/* 25 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Collections = __webpack_require__(0); -var util_1 = __webpack_require__(3); -var timers_1 = __webpack_require__(8); -var SequentialStrategy = (function () { - function SequentialStrategy(strategies, options) { - this.strategies = strategies; - this.loop = Boolean(options.loop); - this.failFast = Boolean(options.failFast); - this.timeout = options.timeout; - this.timeoutLimit = options.timeoutLimit; - } - SequentialStrategy.prototype.isSupported = function () { - return Collections.any(this.strategies, util_1["default"].method("isSupported")); - }; - SequentialStrategy.prototype.connect = function (minPriority, callback) { - var _this = this; - var strategies = this.strategies; - var current = 0; - var timeout = this.timeout; - var runner = null; - var tryNextStrategy = function (error, handshake) { - if (handshake) { - callback(null, handshake); - } - else { - current = current + 1; - if (_this.loop) { - current = current % strategies.length; - } - if (current < strategies.length) { - if (timeout) { - timeout = timeout * 2; - if (_this.timeoutLimit) { - timeout = Math.min(timeout, _this.timeoutLimit); - } - } - runner = _this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: _this.failFast }, tryNextStrategy); - } - else { - callback(true); - } - } - }; - runner = this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: this.failFast }, tryNextStrategy); - return { - abort: function () { - runner.abort(); - }, - forceMinPriority: function (p) { - minPriority = p; - if (runner) { - runner.forceMinPriority(p); - } - } - }; - }; - SequentialStrategy.prototype.tryStrategy = function (strategy, minPriority, options, callback) { - var timer = null; - var runner = null; - if (options.timeout > 0) { - timer = new timers_1.OneOffTimer(options.timeout, function () { - runner.abort(); - callback(true); - }); - } - runner = strategy.connect(minPriority, function (error, handshake) { - if (error && timer && timer.isRunning() && !options.failFast) { - return; - } - if (timer) { - timer.ensureAborted(); - } - callback(error, handshake); - }); - return { - abort: function () { - if (timer) { - timer.ensureAborted(); - } - runner.abort(); - }, - forceMinPriority: function (p) { - runner.forceMinPriority(p); - } - }; - }; - return SequentialStrategy; -}()); -exports["default"] = SequentialStrategy; - - -/***/ }), -/* 26 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -var Buffer = __webpack_require__(5).Buffer, - crypto = __webpack_require__(11), - util = __webpack_require__(2), - Extensions = __webpack_require__(76), - Base = __webpack_require__(7), - Frame = __webpack_require__(81), - Message = __webpack_require__(82); - -var Hybi = function(request, url, options) { - Base.apply(this, arguments); - - this._extensions = new Extensions(); - this._stage = 0; - this._masking = this._options.masking; - this._protocols = this._options.protocols || []; - this._requireMasking = this._options.requireMasking; - this._pingCallbacks = {}; - - if (typeof this._protocols === 'string') - this._protocols = this._protocols.split(/ *, */); - - if (!this._request) return; - - var protos = this._request.headers['sec-websocket-protocol'], - supported = this._protocols; - - if (protos !== undefined) { - if (typeof protos === 'string') protos = protos.split(/ *, */); - this.protocol = protos.filter(function(p) { return supported.indexOf(p) >= 0 })[0]; - } - - this.version = 'hybi-' + Hybi.VERSION; -}; -util.inherits(Hybi, Base); - -Hybi.VERSION = '13'; - -Hybi.mask = function(payload, mask, offset) { - if (!mask || mask.length === 0) return payload; - offset = offset || 0; - - for (var i = 0, n = payload.length - offset; i < n; i++) { - payload[offset + i] = payload[offset + i] ^ mask[i % 4]; - } - return payload; -}; - -Hybi.generateAccept = function(key) { - var sha1 = crypto.createHash('sha1'); - sha1.update(key + Hybi.GUID); - return sha1.digest('base64'); -}; - -Hybi.GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'; - -var instance = { - FIN: 0x80, - MASK: 0x80, - RSV1: 0x40, - RSV2: 0x20, - RSV3: 0x10, - OPCODE: 0x0F, - LENGTH: 0x7F, - - OPCODES: { - continuation: 0, - text: 1, - binary: 2, - close: 8, - ping: 9, - pong: 10 - }, - - OPCODE_CODES: [0, 1, 2, 8, 9, 10], - MESSAGE_OPCODES: [0, 1, 2], - OPENING_OPCODES: [1, 2], - - ERRORS: { - normal_closure: 1000, - going_away: 1001, - protocol_error: 1002, - unacceptable: 1003, - encoding_error: 1007, - policy_violation: 1008, - too_large: 1009, - extension_error: 1010, - unexpected_condition: 1011 - }, - - ERROR_CODES: [1000, 1001, 1002, 1003, 1007, 1008, 1009, 1010, 1011], - DEFAULT_ERROR_CODE: 1000, - MIN_RESERVED_ERROR: 3000, - MAX_RESERVED_ERROR: 4999, - - // http://www.w3.org/International/questions/qa-forms-utf-8.en.php - UTF8_MATCH: /^([\x00-\x7F]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$/, - - addExtension: function(extension) { - this._extensions.add(extension); - return true; - }, - - parse: function(chunk) { - this._reader.put(chunk); - var buffer = true; - while (buffer) { - switch (this._stage) { - case 0: - buffer = this._reader.read(1); - if (buffer) this._parseOpcode(buffer[0]); - break; - - case 1: - buffer = this._reader.read(1); - if (buffer) this._parseLength(buffer[0]); - break; - - case 2: - buffer = this._reader.read(this._frame.lengthBytes); - if (buffer) this._parseExtendedLength(buffer); - break; - - case 3: - buffer = this._reader.read(4); - if (buffer) { - this._stage = 4; - this._frame.maskingKey = buffer; - } - break; - - case 4: - buffer = this._reader.read(this._frame.length); - if (buffer) { - this._stage = 0; - this._emitFrame(buffer); - } - break; - - default: - buffer = null; - } - } - }, - - text: function(message) { - if (this.readyState > 1) return false; - return this.frame(message, 'text'); - }, - - binary: function(message) { - if (this.readyState > 1) return false; - return this.frame(message, 'binary'); - }, - - ping: function(message, callback) { - if (this.readyState > 1) return false; - message = message || ''; - if (callback) this._pingCallbacks[message] = callback; - return this.frame(message, 'ping'); - }, - - pong: function(message) { - if (this.readyState > 1) return false; - message = message ||''; - return this.frame(message, 'pong'); - }, - - close: function(reason, code) { - reason = reason || ''; - code = code || this.ERRORS.normal_closure; - - if (this.readyState <= 0) { - this.readyState = 3; - this.emit('close', new Base.CloseEvent(code, reason)); - return true; - } else if (this.readyState === 1) { - this.readyState = 2; - this._extensions.close(function() { this.frame(reason, 'close', code) }, this); - return true; - } else { - return false; - } - }, - - frame: function(buffer, type, code) { - if (this.readyState <= 0) return this._queue([buffer, type, code]); - if (this.readyState > 2) return false; - - if (buffer instanceof Array) buffer = Buffer.from(buffer); - if (typeof buffer === 'number') buffer = buffer.toString(); - - var message = new Message(), - isText = (typeof buffer === 'string'), - payload, copy; - - message.rsv1 = message.rsv2 = message.rsv3 = false; - message.opcode = this.OPCODES[type || (isText ? 'text' : 'binary')]; - - payload = isText ? Buffer.from(buffer, 'utf8') : buffer; - - if (code) { - copy = payload; - payload = Buffer.allocUnsafe(2 + copy.length); - payload.writeUInt16BE(code, 0); - copy.copy(payload, 2); - } - message.data = payload; - - var onMessageReady = function(message) { - var frame = new Frame(); - - frame.final = true; - frame.rsv1 = message.rsv1; - frame.rsv2 = message.rsv2; - frame.rsv3 = message.rsv3; - frame.opcode = message.opcode; - frame.masked = !!this._masking; - frame.length = message.data.length; - frame.payload = message.data; - - if (frame.masked) frame.maskingKey = crypto.randomBytes(4); - - this._sendFrame(frame); - }; - - if (this.MESSAGE_OPCODES.indexOf(message.opcode) >= 0) - this._extensions.processOutgoingMessage(message, function(error, message) { - if (error) return this._fail('extension_error', error.message); - onMessageReady.call(this, message); - }, this); - else - onMessageReady.call(this, message); - - return true; - }, - - _sendFrame: function(frame) { - var length = frame.length, - header = (length <= 125) ? 2 : (length <= 65535 ? 4 : 10), - offset = header + (frame.masked ? 4 : 0), - buffer = Buffer.allocUnsafe(offset + length), - masked = frame.masked ? this.MASK : 0; - - buffer[0] = (frame.final ? this.FIN : 0) | - (frame.rsv1 ? this.RSV1 : 0) | - (frame.rsv2 ? this.RSV2 : 0) | - (frame.rsv3 ? this.RSV3 : 0) | - frame.opcode; - - if (length <= 125) { - buffer[1] = masked | length; - } else if (length <= 65535) { - buffer[1] = masked | 126; - buffer.writeUInt16BE(length, 2); - } else { - buffer[1] = masked | 127; - buffer.writeUInt32BE(Math.floor(length / 0x100000000), 2); - buffer.writeUInt32BE(length % 0x100000000, 6); - } - - frame.payload.copy(buffer, offset); - - if (frame.masked) { - frame.maskingKey.copy(buffer, header); - Hybi.mask(buffer, frame.maskingKey, offset); - } - - this._write(buffer); - }, - - _handshakeResponse: function() { - var secKey = this._request.headers['sec-websocket-key'], - version = this._request.headers['sec-websocket-version']; - - if (version !== Hybi.VERSION) - throw new Error('Unsupported WebSocket version: ' + version); - - if (typeof secKey !== 'string') - throw new Error('Missing handshake request header: Sec-WebSocket-Key'); - - this._headers.set('Upgrade', 'websocket'); - this._headers.set('Connection', 'Upgrade'); - this._headers.set('Sec-WebSocket-Accept', Hybi.generateAccept(secKey)); - - if (this.protocol) this._headers.set('Sec-WebSocket-Protocol', this.protocol); - - var extensions = this._extensions.generateResponse(this._request.headers['sec-websocket-extensions']); - if (extensions) this._headers.set('Sec-WebSocket-Extensions', extensions); - - var start = 'HTTP/1.1 101 Switching Protocols', - headers = [start, this._headers.toString(), '']; - - return Buffer.from(headers.join('\r\n'), 'utf8'); - }, - - _shutdown: function(code, reason, error) { - delete this._frame; - delete this._message; - this._stage = 5; - - var sendCloseFrame = (this.readyState === 1); - this.readyState = 2; - - this._extensions.close(function() { - if (sendCloseFrame) this.frame(reason, 'close', code); - this.readyState = 3; - if (error) this.emit('error', new Error(reason)); - this.emit('close', new Base.CloseEvent(code, reason)); - }, this); - }, - - _fail: function(type, message) { - if (this.readyState > 1) return; - this._shutdown(this.ERRORS[type], message, true); - }, - - _parseOpcode: function(octet) { - var rsvs = [this.RSV1, this.RSV2, this.RSV3].map(function(rsv) { - return (octet & rsv) === rsv; - }); - - var frame = this._frame = new Frame(); - - frame.final = (octet & this.FIN) === this.FIN; - frame.rsv1 = rsvs[0]; - frame.rsv2 = rsvs[1]; - frame.rsv3 = rsvs[2]; - frame.opcode = (octet & this.OPCODE); - - this._stage = 1; - - if (!this._extensions.validFrameRsv(frame)) - return this._fail('protocol_error', - 'One or more reserved bits are on: reserved1 = ' + (frame.rsv1 ? 1 : 0) + - ', reserved2 = ' + (frame.rsv2 ? 1 : 0) + - ', reserved3 = ' + (frame.rsv3 ? 1 : 0)); - - if (this.OPCODE_CODES.indexOf(frame.opcode) < 0) - return this._fail('protocol_error', 'Unrecognized frame opcode: ' + frame.opcode); - - if (this.MESSAGE_OPCODES.indexOf(frame.opcode) < 0 && !frame.final) - return this._fail('protocol_error', 'Received fragmented control frame: opcode = ' + frame.opcode); - - if (this._message && this.OPENING_OPCODES.indexOf(frame.opcode) >= 0) - return this._fail('protocol_error', 'Received new data frame but previous continuous frame is unfinished'); - }, - - _parseLength: function(octet) { - var frame = this._frame; - frame.masked = (octet & this.MASK) === this.MASK; - frame.length = (octet & this.LENGTH); - - if (frame.length >= 0 && frame.length <= 125) { - this._stage = frame.masked ? 3 : 4; - if (!this._checkFrameLength()) return; - } else { - this._stage = 2; - frame.lengthBytes = (frame.length === 126 ? 2 : 8); - } - - if (this._requireMasking && !frame.masked) - return this._fail('unacceptable', 'Received unmasked frame but masking is required'); - }, - - _parseExtendedLength: function(buffer) { - var frame = this._frame; - frame.length = this._readUInt(buffer); - - this._stage = frame.masked ? 3 : 4; - - if (this.MESSAGE_OPCODES.indexOf(frame.opcode) < 0 && frame.length > 125) - return this._fail('protocol_error', 'Received control frame having too long payload: ' + frame.length); - - if (!this._checkFrameLength()) return; - }, - - _checkFrameLength: function() { - var length = this._message ? this._message.length : 0; - - if (length + this._frame.length > this._maxLength) { - this._fail('too_large', 'WebSocket frame length too large'); - return false; - } else { - return true; - } - }, - - _emitFrame: function(buffer) { - var frame = this._frame, - payload = frame.payload = Hybi.mask(buffer, frame.maskingKey), - opcode = frame.opcode, - message, - code, reason, - callbacks, callback; - - delete this._frame; - - if (opcode === this.OPCODES.continuation) { - if (!this._message) return this._fail('protocol_error', 'Received unexpected continuation frame'); - this._message.pushFrame(frame); - } - - if (opcode === this.OPCODES.text || opcode === this.OPCODES.binary) { - this._message = new Message(); - this._message.pushFrame(frame); - } - - if (frame.final && this.MESSAGE_OPCODES.indexOf(opcode) >= 0) - return this._emitMessage(this._message); - - if (opcode === this.OPCODES.close) { - code = (payload.length >= 2) ? payload.readUInt16BE(0) : null; - reason = (payload.length > 2) ? this._encode(payload.slice(2)) : null; - - if (!(payload.length === 0) && - !(code !== null && code >= this.MIN_RESERVED_ERROR && code <= this.MAX_RESERVED_ERROR) && - this.ERROR_CODES.indexOf(code) < 0) - code = this.ERRORS.protocol_error; - - if (payload.length > 125 || (payload.length > 2 && !reason)) - code = this.ERRORS.protocol_error; - - this._shutdown(code || this.DEFAULT_ERROR_CODE, reason || ''); - } - - if (opcode === this.OPCODES.ping) { - this.frame(payload, 'pong'); - this.emit('ping', new Base.PingEvent(payload.toString())) - } - - if (opcode === this.OPCODES.pong) { - callbacks = this._pingCallbacks; - message = this._encode(payload); - callback = callbacks[message]; - - delete callbacks[message]; - if (callback) callback() - - this.emit('pong', new Base.PongEvent(payload.toString())) - } - }, - - _emitMessage: function(message) { - var message = this._message; - message.read(); - - delete this._message; - - this._extensions.processIncomingMessage(message, function(error, message) { - if (error) return this._fail('extension_error', error.message); - - var payload = message.data; - if (message.opcode === this.OPCODES.text) payload = this._encode(payload); - - if (payload === null) - return this._fail('encoding_error', 'Could not decode a text frame as UTF-8'); - else - this.emit('message', new Base.MessageEvent(payload)); - }, this); - }, - - _encode: function(buffer) { - try { - var string = buffer.toString('binary', 0, buffer.length); - if (!this.UTF8_MATCH.test(string)) return null; - } catch (e) {} - return buffer.toString('utf8', 0, buffer.length); - }, - - _readUInt: function(buffer) { - if (buffer.length === 2) return buffer.readUInt16BE(0); - - return buffer.readUInt32BE(0) * 0x100000000 + - buffer.readUInt32BE(4); - } -}; - -for (var key in instance) - Hybi.prototype[key] = instance[key]; - -module.exports = Hybi; - - -/***/ }), -/* 27 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -var RingBuffer = function(bufferSize) { - this._bufferSize = bufferSize; - this.clear(); -}; - -RingBuffer.prototype.clear = function() { - this._buffer = new Array(this._bufferSize); - this._ringOffset = 0; - this._ringSize = this._bufferSize; - this._head = 0; - this._tail = 0; - this.length = 0; -}; - -RingBuffer.prototype.push = function(value) { - var expandBuffer = false, - expandRing = false; - - if (this._ringSize < this._bufferSize) { - expandBuffer = (this._tail === 0); - } else if (this._ringOffset === this._ringSize) { - expandBuffer = true; - expandRing = (this._tail === 0); - } - - if (expandBuffer) { - this._tail = this._bufferSize; - this._buffer = this._buffer.concat(new Array(this._bufferSize)); - this._bufferSize = this._buffer.length; - - if (expandRing) - this._ringSize = this._bufferSize; - } - - this._buffer[this._tail] = value; - this.length += 1; - if (this._tail < this._ringSize) this._ringOffset += 1; - this._tail = (this._tail + 1) % this._bufferSize; -}; - -RingBuffer.prototype.peek = function() { - if (this.length === 0) return void 0; - return this._buffer[this._head]; -}; - -RingBuffer.prototype.shift = function() { - if (this.length === 0) return void 0; - - var value = this._buffer[this._head]; - this._buffer[this._head] = void 0; - this.length -= 1; - this._ringOffset -= 1; - - if (this._ringOffset === 0 && this.length > 0) { - this._head = this._ringSize; - this._ringOffset = this.length; - this._ringSize = this._bufferSize; - } else { - this._head = (this._head + 1) % this._ringSize; - } - return value; -}; - -module.exports = RingBuffer; - - -/***/ }), -/* 28 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -var RingBuffer = __webpack_require__(27); - -var Pledge = function() { - this._complete = false; - this._callbacks = new RingBuffer(Pledge.QUEUE_SIZE); -}; - -Pledge.QUEUE_SIZE = 4; - -Pledge.all = function(list) { - var pledge = new Pledge(), - pending = list.length, - n = pending; - - if (pending === 0) pledge.done(); - - while (n--) list[n].then(function() { - pending -= 1; - if (pending === 0) pledge.done(); - }); - return pledge; -}; - -Pledge.prototype.then = function(callback) { - if (this._complete) callback(); - else this._callbacks.push(callback); -}; - -Pledge.prototype.done = function() { - this._complete = true; - var callbacks = this._callbacks, callback; - while (callback = callbacks.shift()) callback(); -}; - -module.exports = Pledge; - - -/***/ }), -/* 29 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -var Buffer = __webpack_require__(5).Buffer, - Base = __webpack_require__(7), - util = __webpack_require__(2); - -var Draft75 = function(request, url, options) { - Base.apply(this, arguments); - this._stage = 0; - this.version = 'hixie-75'; - - this._headers.set('Upgrade', 'WebSocket'); - this._headers.set('Connection', 'Upgrade'); - this._headers.set('WebSocket-Origin', this._request.headers.origin); - this._headers.set('WebSocket-Location', this.url); -}; -util.inherits(Draft75, Base); - -var instance = { - close: function() { - if (this.readyState === 3) return false; - this.readyState = 3; - this.emit('close', new Base.CloseEvent(null, null)); - return true; - }, - - parse: function(chunk) { - if (this.readyState > 1) return; - - this._reader.put(chunk); - - this._reader.eachByte(function(octet) { - var message; - - switch (this._stage) { - case -1: - this._body.push(octet); - this._sendHandshakeBody(); - break; - - case 0: - this._parseLeadingByte(octet); - break; - - case 1: - this._length = (octet & 0x7F) + 128 * this._length; - - if (this._closing && this._length === 0) { - return this.close(); - } - else if ((octet & 0x80) !== 0x80) { - if (this._length === 0) { - this._stage = 0; - } - else { - this._skipped = 0; - this._stage = 2; - } - } - break; - - case 2: - if (octet === 0xFF) { - this._stage = 0; - message = Buffer.from(this._buffer).toString('utf8', 0, this._buffer.length); - this.emit('message', new Base.MessageEvent(message)); - } - else { - if (this._length) { - this._skipped += 1; - if (this._skipped === this._length) - this._stage = 0; - } else { - this._buffer.push(octet); - if (this._buffer.length > this._maxLength) return this.close(); - } - } - break; - } - }, this); - }, - - frame: function(buffer) { - if (this.readyState === 0) return this._queue([buffer]); - if (this.readyState > 1) return false; - - if (typeof buffer !== 'string') buffer = buffer.toString(); - - var length = Buffer.byteLength(buffer), - frame = Buffer.allocUnsafe(length + 2); - - frame[0] = 0x00; - frame.write(buffer, 1); - frame[frame.length - 1] = 0xFF; - - this._write(frame); - return true; - }, - - _handshakeResponse: function() { - var start = 'HTTP/1.1 101 Web Socket Protocol Handshake', - headers = [start, this._headers.toString(), '']; - - return Buffer.from(headers.join('\r\n'), 'utf8'); - }, - - _parseLeadingByte: function(octet) { - if ((octet & 0x80) === 0x80) { - this._length = 0; - this._stage = 1; - } else { - delete this._length; - delete this._skipped; - this._buffer = []; - this._stage = 2; - } - } -}; - -for (var key in instance) - Draft75.prototype[key] = instance[key]; - -module.exports = Draft75; - - -/***/ }), -/* 30 */ -/***/ (function(module, exports, __webpack_require__) { - -var Event = __webpack_require__(16); - -var EventTarget = { - onopen: null, - onmessage: null, - onerror: null, - onclose: null, - - addEventListener: function(eventType, listener, useCapture) { - this.on(eventType, listener); - }, - - removeEventListener: function(eventType, listener, useCapture) { - this.removeListener(eventType, listener); - }, - - dispatchEvent: function(event) { - event.target = event.currentTarget = this; - event.eventPhase = Event.AT_TARGET; - - if (this['on' + event.type]) - this['on' + event.type](event); - - this.emit(event.type, event); - } -}; - -module.exports = EventTarget; - - -/***/ }), -/* 31 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var TimelineLevel; -(function (TimelineLevel) { - TimelineLevel[TimelineLevel["ERROR"] = 3] = "ERROR"; - TimelineLevel[TimelineLevel["INFO"] = 6] = "INFO"; - TimelineLevel[TimelineLevel["DEBUG"] = 7] = "DEBUG"; -})(TimelineLevel || (TimelineLevel = {})); -exports["default"] = TimelineLevel; - - -/***/ }), -/* 32 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var pusher_1 = __webpack_require__(22); -module.exports = pusher_1["default"]; - - -/***/ }), -/* 33 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Collections = __webpack_require__(0); -var transports_1 = __webpack_require__(36); -var default_strategy_1 = __webpack_require__(41); -var transport_connection_initializer_1 = __webpack_require__(60); -var http_1 = __webpack_require__(61); -var Isomorphic = { - getDefaultStrategy: default_strategy_1["default"], - Transports: transports_1["default"], - transportConnectionInitializer: transport_connection_initializer_1["default"], - HTTPFactory: http_1["default"], - setup: function (PusherClass) { - PusherClass.ready(); - }, - getLocalStorage: function () { - return undefined; - }, - getClientFeatures: function () { - return Collections.keys(Collections.filterObject({ "ws": transports_1["default"].ws }, function (t) { return t.isSupported({}); })); - }, - getProtocol: function () { - return "http:"; - }, - isXHRSupported: function () { - return true; - }, - createSocketRequest: function (method, url) { - if (this.isXHRSupported()) { - return this.HTTPFactory.createXHR(method, url); - } - else { - throw "Cross-origin HTTP requests are not supported"; - } - }, - createXHR: function () { - var Constructor = this.getXHRAPI(); - return new Constructor(); - }, - createWebSocket: function (url) { - var Constructor = this.getWebSocketAPI(); - return new Constructor(url); - }, - addUnloadListener: function (listener) { }, - removeUnloadListener: function (listener) { } -}; -exports["default"] = Isomorphic; - - -/***/ }), -/* 34 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -function encode(s) { - return btoa(utob(s)); -} -exports["default"] = encode; -var fromCharCode = String.fromCharCode; -var b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; -var b64tab = {}; -for (var i = 0, l = b64chars.length; i < l; i++) { - b64tab[b64chars.charAt(i)] = i; -} -var cb_utob = function (c) { - var cc = c.charCodeAt(0); - return cc < 0x80 ? c - : cc < 0x800 ? fromCharCode(0xc0 | (cc >>> 6)) + - fromCharCode(0x80 | (cc & 0x3f)) - : fromCharCode(0xe0 | ((cc >>> 12) & 0x0f)) + - fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) + - fromCharCode(0x80 | (cc & 0x3f)); -}; -var utob = function (u) { - return u.replace(/[^\x00-\x7F]/g, cb_utob); -}; -var cb_encode = function (ccc) { - var padlen = [0, 2, 1][ccc.length % 3]; - var ord = ccc.charCodeAt(0) << 16 - | ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8) - | ((ccc.length > 2 ? ccc.charCodeAt(2) : 0)); - var chars = [ - b64chars.charAt(ord >>> 18), - b64chars.charAt((ord >>> 12) & 63), - padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63), - padlen >= 1 ? '=' : b64chars.charAt(ord & 63) - ]; - return chars.join(''); -}; -var btoa = global.btoa || function (b) { - return b.replace(/[\s\S]{1,3}/g, cb_encode); -}; - - -/***/ }), -/* 35 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Timer = (function () { - function Timer(set, clear, delay, callback) { - var _this = this; - this.clear = clear; - this.timer = set(function () { - if (_this.timer) { - _this.timer = callback(_this.timer); - } - }, delay); - } - Timer.prototype.isRunning = function () { - return this.timer !== null; - }; - Timer.prototype.ensureAborted = function () { - if (this.timer) { - this.clear(this.timer); - this.timer = null; - } - }; - return Timer; -}()); -exports["default"] = Timer; - - -/***/ }), -/* 36 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var URLSchemes = __webpack_require__(37); -var transport_1 = __webpack_require__(38); -var Collections = __webpack_require__(0); -var runtime_1 = __webpack_require__(1); -var WSTransport = new transport_1["default"]({ - urls: URLSchemes.ws, - handlesActivityChecks: false, - supportsPing: false, - isInitialized: function () { - return Boolean(runtime_1["default"].getWebSocketAPI()); - }, - isSupported: function () { - return Boolean(runtime_1["default"].getWebSocketAPI()); - }, - getSocket: function (url) { - return runtime_1["default"].createWebSocket(url); - } -}); -var httpConfiguration = { - urls: URLSchemes.http, - handlesActivityChecks: false, - supportsPing: true, - isInitialized: function () { - return true; - } -}; -exports.streamingConfiguration = Collections.extend({ getSocket: function (url) { - return runtime_1["default"].HTTPFactory.createStreamingSocket(url); - } -}, httpConfiguration); -exports.pollingConfiguration = Collections.extend({ getSocket: function (url) { - return runtime_1["default"].HTTPFactory.createPollingSocket(url); - } -}, httpConfiguration); -var xhrConfiguration = { - isSupported: function () { - return runtime_1["default"].isXHRSupported(); - } -}; -var XHRStreamingTransport = new transport_1["default"](Collections.extend({}, exports.streamingConfiguration, xhrConfiguration)); -var XHRPollingTransport = new transport_1["default"](Collections.extend({}, exports.pollingConfiguration, xhrConfiguration)); -var Transports = { - ws: WSTransport, - xhr_streaming: XHRStreamingTransport, - xhr_polling: XHRPollingTransport -}; -exports["default"] = Transports; - - -/***/ }), -/* 37 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var defaults_1 = __webpack_require__(17); -function getGenericURL(baseScheme, params, path) { - var scheme = baseScheme + (params.useTLS ? "s" : ""); - var host = params.useTLS ? params.hostTLS : params.hostNonTLS; - return scheme + "://" + host + path; -} -function getGenericPath(key, queryString) { - var path = "/app/" + key; - var query = "?protocol=" + defaults_1["default"].PROTOCOL + - "&client=js" + - "&version=" + defaults_1["default"].VERSION + - (queryString ? ("&" + queryString) : ""); - return path + query; -} -exports.ws = { - getInitial: function (key, params) { - var path = (params.httpPath || "") + getGenericPath(key, "flash=false"); - return getGenericURL("ws", params, path); - } -}; -exports.http = { - getInitial: function (key, params) { - var path = (params.httpPath || "/pusher") + getGenericPath(key); - return getGenericURL("http", params, path); - } -}; -exports.sockjs = { - getInitial: function (key, params) { - return getGenericURL("http", params, params.httpPath || "/pusher"); - }, - getPath: function (key, params) { - return getGenericPath(key); - } -}; - - -/***/ }), -/* 38 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var transport_connection_1 = __webpack_require__(39); -var Transport = (function () { - function Transport(hooks) { - this.hooks = hooks; - } - Transport.prototype.isSupported = function (environment) { - return this.hooks.isSupported(environment); - }; - Transport.prototype.createConnection = function (name, priority, key, options) { - return new transport_connection_1["default"](this.hooks, name, priority, key, options); - }; - return Transport; -}()); -exports["default"] = Transport; - - -/***/ }), -/* 39 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var util_1 = __webpack_require__(3); -var Collections = __webpack_require__(0); -var dispatcher_1 = __webpack_require__(6); -var logger_1 = __webpack_require__(4); -var runtime_1 = __webpack_require__(1); -var TransportConnection = (function (_super) { - __extends(TransportConnection, _super); - function TransportConnection(hooks, name, priority, key, options) { - var _this = _super.call(this) || this; - _this.initialize = runtime_1["default"].transportConnectionInitializer; - _this.hooks = hooks; - _this.name = name; - _this.priority = priority; - _this.key = key; - _this.options = options; - _this.state = "new"; - _this.timeline = options.timeline; - _this.activityTimeout = options.activityTimeout; - _this.id = _this.timeline.generateUniqueID(); - return _this; - } - TransportConnection.prototype.handlesActivityChecks = function () { - return Boolean(this.hooks.handlesActivityChecks); - }; - TransportConnection.prototype.supportsPing = function () { - return Boolean(this.hooks.supportsPing); - }; - TransportConnection.prototype.connect = function () { - var _this = this; - if (this.socket || this.state !== "initialized") { - return false; - } - var url = this.hooks.urls.getInitial(this.key, this.options); - try { - this.socket = this.hooks.getSocket(url, this.options); - } - catch (e) { - util_1["default"].defer(function () { - _this.onError(e); - _this.changeState("closed"); - }); - return false; - } - this.bindListeners(); - logger_1["default"].debug("Connecting", { transport: this.name, url: url }); - this.changeState("connecting"); - return true; - }; - TransportConnection.prototype.close = function () { - if (this.socket) { - this.socket.close(); - return true; - } - else { - return false; - } - }; - TransportConnection.prototype.send = function (data) { - var _this = this; - if (this.state === "open") { - util_1["default"].defer(function () { - if (_this.socket) { - _this.socket.send(data); - } - }); - return true; - } - else { - return false; - } - }; - TransportConnection.prototype.ping = function () { - if (this.state === "open" && this.supportsPing()) { - this.socket.ping(); - } - }; - TransportConnection.prototype.onOpen = function () { - if (this.hooks.beforeOpen) { - this.hooks.beforeOpen(this.socket, this.hooks.urls.getPath(this.key, this.options)); - } - this.changeState("open"); - this.socket.onopen = undefined; - }; - TransportConnection.prototype.onError = function (error) { - this.emit("error", { type: 'WebSocketError', error: error }); - this.timeline.error(this.buildTimelineMessage({ error: error.toString() })); - }; - TransportConnection.prototype.onClose = function (closeEvent) { - if (closeEvent) { - this.changeState("closed", { - code: closeEvent.code, - reason: closeEvent.reason, - wasClean: closeEvent.wasClean - }); - } - else { - this.changeState("closed"); - } - this.unbindListeners(); - this.socket = undefined; - }; - TransportConnection.prototype.onMessage = function (message) { - this.emit("message", message); - }; - TransportConnection.prototype.onActivity = function () { - this.emit("activity"); - }; - TransportConnection.prototype.bindListeners = function () { - var _this = this; - this.socket.onopen = function () { - _this.onOpen(); - }; - this.socket.onerror = function (error) { - _this.onError(error); - }; - this.socket.onclose = function (closeEvent) { - _this.onClose(closeEvent); - }; - this.socket.onmessage = function (message) { - _this.onMessage(message); - }; - if (this.supportsPing()) { - this.socket.onactivity = function () { _this.onActivity(); }; - } - }; - TransportConnection.prototype.unbindListeners = function () { - if (this.socket) { - this.socket.onopen = undefined; - this.socket.onerror = undefined; - this.socket.onclose = undefined; - this.socket.onmessage = undefined; - if (this.supportsPing()) { - this.socket.onactivity = undefined; - } - } - }; - TransportConnection.prototype.changeState = function (state, params) { - this.state = state; - this.timeline.info(this.buildTimelineMessage({ - state: state, - params: params - })); - this.emit(state, params); - }; - TransportConnection.prototype.buildTimelineMessage = function (message) { - return Collections.extend({ cid: this.id }, message); - }; - return TransportConnection; -}(dispatcher_1["default"])); -exports["default"] = TransportConnection; - - -/***/ }), -/* 40 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Collections = __webpack_require__(0); -var CallbackRegistry = (function () { - function CallbackRegistry() { - this._callbacks = {}; - } - CallbackRegistry.prototype.get = function (name) { - return this._callbacks[prefix(name)]; - }; - CallbackRegistry.prototype.add = function (name, callback, context) { - var prefixedEventName = prefix(name); - this._callbacks[prefixedEventName] = this._callbacks[prefixedEventName] || []; - this._callbacks[prefixedEventName].push({ - fn: callback, - context: context - }); - }; - CallbackRegistry.prototype.remove = function (name, callback, context) { - if (!name && !callback && !context) { - this._callbacks = {}; - return; - } - var names = name ? [prefix(name)] : Collections.keys(this._callbacks); - if (callback || context) { - this.removeCallback(names, callback, context); - } - else { - this.removeAllCallbacks(names); - } - }; - CallbackRegistry.prototype.removeCallback = function (names, callback, context) { - Collections.apply(names, function (name) { - this._callbacks[name] = Collections.filter(this._callbacks[name] || [], function (binding) { - return (callback && callback !== binding.fn) || - (context && context !== binding.context); - }); - if (this._callbacks[name].length === 0) { - delete this._callbacks[name]; - } - }, this); - }; - CallbackRegistry.prototype.removeAllCallbacks = function (names) { - Collections.apply(names, function (name) { - delete this._callbacks[name]; - }, this); - }; - return CallbackRegistry; -}()); -exports["default"] = CallbackRegistry; -function prefix(name) { - return "_" + name; -} - - -/***/ }), -/* 41 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Collections = __webpack_require__(0); -var transport_manager_1 = __webpack_require__(42); -var sequential_strategy_1 = __webpack_require__(25); -var best_connected_ever_strategy_1 = __webpack_require__(55); -var cached_strategy_1 = __webpack_require__(56); -var delayed_strategy_1 = __webpack_require__(57); -var if_strategy_1 = __webpack_require__(58); -var first_connected_strategy_1 = __webpack_require__(59); -function testSupportsStrategy(strategy) { - return function () { - return strategy.isSupported(); - }; -} -var getDefaultStrategy = function (config, defineTransport) { - var definedTransports = {}; - function defineTransportStrategy(name, type, priority, options, manager) { - var transport = defineTransport(config, name, type, priority, options, manager); - definedTransports[name] = transport; - return transport; - } - var ws_options = { - hostNonTLS: config.wsHost + ":" + config.wsPort, - hostTLS: config.wsHost + ":" + config.wssPort, - httpPath: config.wsPath - }; - var wss_options = Collections.extend({}, ws_options, { - useTLS: true - }); - var http_options = { - hostNonTLS: config.httpHost + ":" + config.httpPort, - hostTLS: config.httpHost + ":" + config.httpsPort, - httpPath: config.httpPath - }; - var timeouts = { - loop: true, - timeout: 15000, - timeoutLimit: 60000 - }; - var ws_manager = new transport_manager_1["default"]({ - lives: 2, - minPingDelay: 10000, - maxPingDelay: config.activity_timeout - }); - var streaming_manager = new transport_manager_1["default"]({ - lives: 2, - minPingDelay: 10000, - maxPingDelay: config.activity_timeout - }); - var ws_transport = defineTransportStrategy("ws", "ws", 3, ws_options, ws_manager); - var wss_transport = defineTransportStrategy("wss", "ws", 3, wss_options, ws_manager); - var xhr_streaming_transport = defineTransportStrategy("xhr_streaming", "xhr_streaming", 1, http_options, streaming_manager); - var xhr_polling_transport = defineTransportStrategy("xhr_polling", "xhr_polling", 1, http_options); - var ws_loop = new sequential_strategy_1["default"]([ws_transport], timeouts); - var wss_loop = new sequential_strategy_1["default"]([wss_transport], timeouts); - var streaming_loop = new sequential_strategy_1["default"]([xhr_streaming_transport], timeouts); - var polling_loop = new sequential_strategy_1["default"]([xhr_polling_transport], timeouts); - var http_loop = new sequential_strategy_1["default"]([new if_strategy_1["default"](testSupportsStrategy(streaming_loop), new best_connected_ever_strategy_1["default"]([streaming_loop, new delayed_strategy_1["default"](polling_loop, { delay: 4000 })]), polling_loop)], timeouts); - var wsStrategy; - if (config.useTLS) { - wsStrategy = new best_connected_ever_strategy_1["default"]([ws_loop, new delayed_strategy_1["default"](http_loop, { delay: 2000 })]); - } - else { - wsStrategy = new best_connected_ever_strategy_1["default"]([ - ws_loop, - new delayed_strategy_1["default"](wss_loop, { delay: 2000 }), - new delayed_strategy_1["default"](http_loop, { delay: 5000 }) - ]); - } - return new cached_strategy_1["default"](new first_connected_strategy_1["default"](new if_strategy_1["default"](testSupportsStrategy(ws_transport), wsStrategy, http_loop)), definedTransports, { - ttl: 1800000, - timeline: config.timeline, - useTLS: config.useTLS - }); -}; -exports["default"] = getDefaultStrategy; - - -/***/ }), -/* 42 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var factory_1 = __webpack_require__(9); -var TransportManager = (function () { - function TransportManager(options) { - this.options = options || {}; - this.livesLeft = this.options.lives || Infinity; - } - TransportManager.prototype.getAssistant = function (transport) { - return factory_1["default"].createAssistantToTheTransportManager(this, transport, { - minPingDelay: this.options.minPingDelay, - maxPingDelay: this.options.maxPingDelay - }); - }; - TransportManager.prototype.isAlive = function () { - return this.livesLeft > 0; - }; - TransportManager.prototype.reportDeath = function () { - this.livesLeft -= 1; - }; - return TransportManager; -}()); -exports["default"] = TransportManager; - - -/***/ }), -/* 43 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var util_1 = __webpack_require__(3); -var Collections = __webpack_require__(0); -var AssistantToTheTransportManager = (function () { - function AssistantToTheTransportManager(manager, transport, options) { - this.manager = manager; - this.transport = transport; - this.minPingDelay = options.minPingDelay; - this.maxPingDelay = options.maxPingDelay; - this.pingDelay = undefined; - } - AssistantToTheTransportManager.prototype.createConnection = function (name, priority, key, options) { - var _this = this; - options = Collections.extend({}, options, { - activityTimeout: this.pingDelay - }); - var connection = this.transport.createConnection(name, priority, key, options); - var openTimestamp = null; - var onOpen = function () { - connection.unbind("open", onOpen); - connection.bind("closed", onClosed); - openTimestamp = util_1["default"].now(); - }; - var onClosed = function (closeEvent) { - connection.unbind("closed", onClosed); - if (closeEvent.code === 1002 || closeEvent.code === 1003) { - _this.manager.reportDeath(); - } - else if (!closeEvent.wasClean && openTimestamp) { - var lifespan = util_1["default"].now() - openTimestamp; - if (lifespan < 2 * _this.maxPingDelay) { - _this.manager.reportDeath(); - _this.pingDelay = Math.max(lifespan / 2, _this.minPingDelay); - } - } - }; - connection.bind("open", onOpen); - return connection; - }; - AssistantToTheTransportManager.prototype.isSupported = function (environment) { - return this.manager.isAlive() && this.transport.isSupported(environment); - }; - return AssistantToTheTransportManager; -}()); -exports["default"] = AssistantToTheTransportManager; - - -/***/ }), -/* 44 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Collections = __webpack_require__(0); -var Protocol = __webpack_require__(23); -var connection_1 = __webpack_require__(45); -var Handshake = (function () { - function Handshake(transport, callback) { - this.transport = transport; - this.callback = callback; - this.bindListeners(); - } - Handshake.prototype.close = function () { - this.unbindListeners(); - this.transport.close(); - }; - Handshake.prototype.bindListeners = function () { - var _this = this; - this.onMessage = function (m) { - _this.unbindListeners(); - var result; - try { - result = Protocol.processHandshake(m); - } - catch (e) { - _this.finish("error", { error: e }); - _this.transport.close(); - return; - } - if (result.action === "connected") { - _this.finish("connected", { - connection: new connection_1["default"](result.id, _this.transport), - activityTimeout: result.activityTimeout - }); - } - else { - _this.finish(result.action, { error: result.error }); - _this.transport.close(); - } - }; - this.onClosed = function (closeEvent) { - _this.unbindListeners(); - var action = Protocol.getCloseAction(closeEvent) || "backoff"; - var error = Protocol.getCloseError(closeEvent); - _this.finish(action, { error: error }); - }; - this.transport.bind("message", this.onMessage); - this.transport.bind("closed", this.onClosed); - }; - Handshake.prototype.unbindListeners = function () { - this.transport.unbind("message", this.onMessage); - this.transport.unbind("closed", this.onClosed); - }; - Handshake.prototype.finish = function (action, params) { - this.callback(Collections.extend({ transport: this.transport, action: action }, params)); - }; - return Handshake; -}()); -exports["default"] = Handshake; - - -/***/ }), -/* 45 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var Collections = __webpack_require__(0); -var dispatcher_1 = __webpack_require__(6); -var Protocol = __webpack_require__(23); -var logger_1 = __webpack_require__(4); -var Connection = (function (_super) { - __extends(Connection, _super); - function Connection(id, transport) { - var _this = _super.call(this) || this; - _this.id = id; - _this.transport = transport; - _this.activityTimeout = transport.activityTimeout; - _this.bindListeners(); - return _this; - } - Connection.prototype.handlesActivityChecks = function () { - return this.transport.handlesActivityChecks(); - }; - Connection.prototype.send = function (data) { - return this.transport.send(data); - }; - Connection.prototype.send_event = function (name, data, channel) { - var event = { event: name, data: data }; - if (channel) { - event.channel = channel; - } - logger_1["default"].debug('Event sent', event); - return this.send(Protocol.encodeMessage(event)); - }; - Connection.prototype.ping = function () { - if (this.transport.supportsPing()) { - this.transport.ping(); - } - else { - this.send_event('pusher:ping', {}); - } - }; - Connection.prototype.close = function () { - this.transport.close(); - }; - Connection.prototype.bindListeners = function () { - var _this = this; - var listeners = { - message: function (messageEvent) { - var pusherEvent; - try { - pusherEvent = Protocol.decodeMessage(messageEvent); - } - catch (e) { - _this.emit('error', { - type: 'MessageParseError', - error: e, - data: messageEvent.data - }); - } - if (pusherEvent !== undefined) { - logger_1["default"].debug('Event recd', pusherEvent); - switch (pusherEvent.event) { - case 'pusher:error': - _this.emit('error', { type: 'PusherError', data: pusherEvent.data }); - break; - case 'pusher:ping': - _this.emit("ping"); - break; - case 'pusher:pong': - _this.emit("pong"); - break; - } - _this.emit('message', pusherEvent); - } - }, - activity: function () { - _this.emit("activity"); - }, - error: function (error) { - _this.emit("error", { type: "WebSocketError", error: error }); - }, - closed: function (closeEvent) { - unbindListeners(); - if (closeEvent && closeEvent.code) { - _this.handleCloseEvent(closeEvent); - } - _this.transport = null; - _this.emit("closed"); - } - }; - var unbindListeners = function () { - Collections.objectApply(listeners, function (listener, event) { - _this.transport.unbind(event, listener); - }); - }; - Collections.objectApply(listeners, function (listener, event) { - _this.transport.bind(event, listener); - }); - }; - Connection.prototype.handleCloseEvent = function (closeEvent) { - var action = Protocol.getCloseAction(closeEvent); - var error = Protocol.getCloseError(closeEvent); - if (error) { - this.emit('error', error); - } - if (action) { - this.emit(action, { action: action, error: error }); - } - }; - return Connection; -}(dispatcher_1["default"])); -exports["default"] = Connection; - - -/***/ }), -/* 46 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var PusherAuthorizer = (function () { - function PusherAuthorizer(channel, options) { - this.channel = channel; - var authTransport = options.authTransport; - if (typeof runtime_1["default"].getAuthorizers()[authTransport] === "undefined") { - throw "'" + authTransport + "' is not a recognized auth transport"; - } - this.type = authTransport; - this.options = options; - this.authOptions = (options || {}).auth || {}; - } - PusherAuthorizer.prototype.composeQuery = function (socketId) { - var query = 'socket_id=' + encodeURIComponent(socketId) + - '&channel_name=' + encodeURIComponent(this.channel.name); - for (var i in this.authOptions.params) { - query += "&" + encodeURIComponent(i) + "=" + encodeURIComponent(this.authOptions.params[i]); - } - return query; - }; - PusherAuthorizer.prototype.authorize = function (socketId, callback) { - PusherAuthorizer.authorizers = PusherAuthorizer.authorizers || runtime_1["default"].getAuthorizers(); - return PusherAuthorizer.authorizers[this.type].call(this, runtime_1["default"], socketId, callback); - }; - return PusherAuthorizer; -}()); -exports["default"] = PusherAuthorizer; - - -/***/ }), -/* 47 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var TimelineSender = (function () { - function TimelineSender(timeline, options) { - this.timeline = timeline; - this.options = options || {}; - } - TimelineSender.prototype.send = function (useTLS, callback) { - if (this.timeline.isEmpty()) { - return; - } - this.timeline.send(runtime_1["default"].TimelineTransport.getAgent(this, useTLS), callback); - }; - return TimelineSender; -}()); -exports["default"] = TimelineSender; - - -/***/ }), -/* 48 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var private_channel_1 = __webpack_require__(18); -var logger_1 = __webpack_require__(4); -var members_1 = __webpack_require__(49); -var url_store_1 = __webpack_require__(12); -var PresenceChannel = (function (_super) { - __extends(PresenceChannel, _super); - function PresenceChannel(name, pusher) { - var _this = _super.call(this, name, pusher) || this; - _this.members = new members_1["default"](); - return _this; - } - PresenceChannel.prototype.authorize = function (socketId, callback) { - var _this = this; - _super.prototype.authorize.call(this, socketId, function (error, authData) { - if (!error) { - if (authData.channel_data === undefined) { - var suffix = url_store_1["default"].buildLogSuffix("authenticationEndpoint"); - logger_1["default"].warn("Invalid auth response for channel '" + _this.name + "'," + - ("expected 'channel_data' field. " + suffix)); - callback("Invalid auth response"); - return; - } - var channelData = JSON.parse(authData.channel_data); - _this.members.setMyID(channelData.user_id); - } - callback(error, authData); - }); - }; - PresenceChannel.prototype.handleEvent = function (event) { - var eventName = event.event; - if (eventName.indexOf("pusher_internal:") === 0) { - this.handleInternalEvent(event); - } - else { - var data = event.data; - var metadata = {}; - if (event.user_id) { - metadata.user_id = event.user_id; - } - this.emit(eventName, data, metadata); - } - }; - PresenceChannel.prototype.handleInternalEvent = function (event) { - var eventName = event.event; - var data = event.data; - switch (eventName) { - case "pusher_internal:subscription_succeeded": - this.handleSubscriptionSucceededEvent(event); - break; - case "pusher_internal:member_added": - var addedMember = this.members.addMember(data); - this.emit('pusher:member_added', addedMember); - break; - case "pusher_internal:member_removed": - var removedMember = this.members.removeMember(data); - if (removedMember) { - this.emit('pusher:member_removed', removedMember); - } - break; - } - }; - PresenceChannel.prototype.handleSubscriptionSucceededEvent = function (event) { - this.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } - else { - this.members.onSubscription(event.data); - this.emit("pusher:subscription_succeeded", this.members); - } - }; - PresenceChannel.prototype.disconnect = function () { - this.members.reset(); - _super.prototype.disconnect.call(this); - }; - return PresenceChannel; -}(private_channel_1["default"])); -exports["default"] = PresenceChannel; - - -/***/ }), -/* 49 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Collections = __webpack_require__(0); -var Members = (function () { - function Members() { - this.reset(); - } - Members.prototype.get = function (id) { - if (Object.prototype.hasOwnProperty.call(this.members, id)) { - return { - id: id, - info: this.members[id] - }; - } - else { - return null; - } - }; - Members.prototype.each = function (callback) { - var _this = this; - Collections.objectApply(this.members, function (member, id) { - callback(_this.get(id)); - }); - }; - Members.prototype.setMyID = function (id) { - this.myID = id; - }; - Members.prototype.onSubscription = function (subscriptionData) { - this.members = subscriptionData.presence.hash; - this.count = subscriptionData.presence.count; - this.me = this.get(this.myID); - }; - Members.prototype.addMember = function (memberData) { - if (this.get(memberData.user_id) === null) { - this.count++; - } - this.members[memberData.user_id] = memberData.user_info; - return this.get(memberData.user_id); - }; - Members.prototype.removeMember = function (memberData) { - var member = this.get(memberData.user_id); - if (member) { - delete this.members[memberData.user_id]; - this.count--; - } - return member; - }; - Members.prototype.reset = function () { - this.members = {}; - this.count = 0; - this.myID = null; - this.me = null; - }; - return Members; -}()); -exports["default"] = Members; - - -/***/ }), -/* 50 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var private_channel_1 = __webpack_require__(18); -var Errors = __webpack_require__(10); -var logger_1 = __webpack_require__(4); -var tweetnacl_1 = __webpack_require__(51); -var tweetnacl_util_1 = __webpack_require__(52); -var EncryptedChannel = (function (_super) { - __extends(EncryptedChannel, _super); - function EncryptedChannel() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.key = null; - return _this; - } - EncryptedChannel.prototype.authorize = function (socketId, callback) { - var _this = this; - _super.prototype.authorize.call(this, socketId, function (error, authData) { - if (error) { - callback(true, authData); - return; - } - var sharedSecret = authData["shared_secret"]; - if (!sharedSecret) { - var errorMsg = "No shared_secret key in auth payload for encrypted channel: " + _this.name; - callback(true, errorMsg); - logger_1["default"].warn("Error: " + errorMsg); - return; - } - _this.key = tweetnacl_util_1.decodeBase64(sharedSecret); - delete authData["shared_secret"]; - callback(false, authData); - }); - }; - EncryptedChannel.prototype.trigger = function (event, data) { - throw new Errors.UnsupportedFeature('Client events are not currently supported for encrypted channels'); - }; - EncryptedChannel.prototype.handleEvent = function (event) { - var eventName = event.event; - var data = event.data; - if (eventName.indexOf("pusher_internal:") === 0 || eventName.indexOf("pusher:") === 0) { - _super.prototype.handleEvent.call(this, event); - return; - } - this.handleEncryptedEvent(eventName, data); - }; - EncryptedChannel.prototype.handleEncryptedEvent = function (event, data) { - var _this = this; - if (!this.key) { - logger_1["default"].debug('Received encrypted event before key has been retrieved from the authEndpoint'); - return; - } - if (!data.ciphertext || !data.nonce) { - logger_1["default"].warn('Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: ' + data); - return; - } - var cipherText = tweetnacl_util_1.decodeBase64(data.ciphertext); - if (cipherText.length < tweetnacl_1.secretbox.overheadLength) { - logger_1["default"].warn("Expected encrypted event ciphertext length to be " + tweetnacl_1.secretbox.overheadLength + ", got: " + cipherText.length); - return; - } - var nonce = tweetnacl_util_1.decodeBase64(data.nonce); - if (nonce.length < tweetnacl_1.secretbox.nonceLength) { - logger_1["default"].warn("Expected encrypted event nonce length to be " + tweetnacl_1.secretbox.nonceLength + ", got: " + nonce.length); - return; - } - var bytes = tweetnacl_1.secretbox.open(cipherText, nonce, this.key); - if (bytes === null) { - logger_1["default"].debug('Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint...'); - this.authorize(this.pusher.connection.socket_id, function (error, authData) { - if (error) { - logger_1["default"].warn("Failed to make a request to the authEndpoint: " + authData + ". Unable to fetch new key, so dropping encrypted event"); - return; - } - bytes = tweetnacl_1.secretbox.open(cipherText, nonce, _this.key); - if (bytes === null) { - logger_1["default"].warn("Failed to decrypt event with new key. Dropping encrypted event"); - return; - } - _this.emitJSON(event, tweetnacl_util_1.encodeUTF8(bytes)); - return; - }); - return; - } - this.emitJSON(event, tweetnacl_util_1.encodeUTF8(bytes)); - }; - EncryptedChannel.prototype.emitJSON = function (eventName, data) { - try { - this.emit(eventName, JSON.parse(data)); - } - catch (e) { - this.emit(eventName, data); - } - return this; - }; - return EncryptedChannel; -}(private_channel_1["default"])); -exports["default"] = EncryptedChannel; - - -/***/ }), -/* 51 */ -/***/ (function(module, exports, __webpack_require__) { - -(function(nacl) { -'use strict'; - -// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. -// Public domain. -// -// Implementation derived from TweetNaCl version 20140427. -// See for details: http://tweetnacl.cr.yp.to/ - -var gf = function(init) { - var i, r = new Float64Array(16); - if (init) for (i = 0; i < init.length; i++) r[i] = init[i]; - return r; -}; - -// Pluggable, initialized in high-level API below. -var randombytes = function(/* x, n */) { throw new Error('no PRNG'); }; - -var _0 = new Uint8Array(16); -var _9 = new Uint8Array(32); _9[0] = 9; - -var gf0 = gf(), - gf1 = gf([1]), - _121665 = gf([0xdb41, 1]), - D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]), - D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]), - X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]), - Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]), - I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]); - -function ts64(x, i, h, l) { - x[i] = (h >> 24) & 0xff; - x[i+1] = (h >> 16) & 0xff; - x[i+2] = (h >> 8) & 0xff; - x[i+3] = h & 0xff; - x[i+4] = (l >> 24) & 0xff; - x[i+5] = (l >> 16) & 0xff; - x[i+6] = (l >> 8) & 0xff; - x[i+7] = l & 0xff; -} - -function vn(x, xi, y, yi, n) { - var i,d = 0; - for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i]; - return (1 & ((d - 1) >>> 8)) - 1; -} - -function crypto_verify_16(x, xi, y, yi) { - return vn(x,xi,y,yi,16); -} - -function crypto_verify_32(x, xi, y, yi) { - return vn(x,xi,y,yi,32); -} - -function core_salsa20(o, p, k, c) { - var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, - j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, - j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, - j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, - j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, - j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, - j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, - j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, - j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, - j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, - j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, - j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, - j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, - j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, - j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, - j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; - - var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, - x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, - x15 = j15, u; - - for (var i = 0; i < 20; i += 2) { - u = x0 + x12 | 0; - x4 ^= u<<7 | u>>>(32-7); - u = x4 + x0 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x4 | 0; - x12 ^= u<<13 | u>>>(32-13); - u = x12 + x8 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x1 | 0; - x9 ^= u<<7 | u>>>(32-7); - u = x9 + x5 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x9 | 0; - x1 ^= u<<13 | u>>>(32-13); - u = x1 + x13 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x6 | 0; - x14 ^= u<<7 | u>>>(32-7); - u = x14 + x10 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x14 | 0; - x6 ^= u<<13 | u>>>(32-13); - u = x6 + x2 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x11 | 0; - x3 ^= u<<7 | u>>>(32-7); - u = x3 + x15 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x3 | 0; - x11 ^= u<<13 | u>>>(32-13); - u = x11 + x7 | 0; - x15 ^= u<<18 | u>>>(32-18); - - u = x0 + x3 | 0; - x1 ^= u<<7 | u>>>(32-7); - u = x1 + x0 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x1 | 0; - x3 ^= u<<13 | u>>>(32-13); - u = x3 + x2 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x4 | 0; - x6 ^= u<<7 | u>>>(32-7); - u = x6 + x5 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x6 | 0; - x4 ^= u<<13 | u>>>(32-13); - u = x4 + x7 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x9 | 0; - x11 ^= u<<7 | u>>>(32-7); - u = x11 + x10 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x11 | 0; - x9 ^= u<<13 | u>>>(32-13); - u = x9 + x8 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x14 | 0; - x12 ^= u<<7 | u>>>(32-7); - u = x12 + x15 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x12 | 0; - x14 ^= u<<13 | u>>>(32-13); - u = x14 + x13 | 0; - x15 ^= u<<18 | u>>>(32-18); - } - x0 = x0 + j0 | 0; - x1 = x1 + j1 | 0; - x2 = x2 + j2 | 0; - x3 = x3 + j3 | 0; - x4 = x4 + j4 | 0; - x5 = x5 + j5 | 0; - x6 = x6 + j6 | 0; - x7 = x7 + j7 | 0; - x8 = x8 + j8 | 0; - x9 = x9 + j9 | 0; - x10 = x10 + j10 | 0; - x11 = x11 + j11 | 0; - x12 = x12 + j12 | 0; - x13 = x13 + j13 | 0; - x14 = x14 + j14 | 0; - x15 = x15 + j15 | 0; - - o[ 0] = x0 >>> 0 & 0xff; - o[ 1] = x0 >>> 8 & 0xff; - o[ 2] = x0 >>> 16 & 0xff; - o[ 3] = x0 >>> 24 & 0xff; - - o[ 4] = x1 >>> 0 & 0xff; - o[ 5] = x1 >>> 8 & 0xff; - o[ 6] = x1 >>> 16 & 0xff; - o[ 7] = x1 >>> 24 & 0xff; - - o[ 8] = x2 >>> 0 & 0xff; - o[ 9] = x2 >>> 8 & 0xff; - o[10] = x2 >>> 16 & 0xff; - o[11] = x2 >>> 24 & 0xff; - - o[12] = x3 >>> 0 & 0xff; - o[13] = x3 >>> 8 & 0xff; - o[14] = x3 >>> 16 & 0xff; - o[15] = x3 >>> 24 & 0xff; - - o[16] = x4 >>> 0 & 0xff; - o[17] = x4 >>> 8 & 0xff; - o[18] = x4 >>> 16 & 0xff; - o[19] = x4 >>> 24 & 0xff; - - o[20] = x5 >>> 0 & 0xff; - o[21] = x5 >>> 8 & 0xff; - o[22] = x5 >>> 16 & 0xff; - o[23] = x5 >>> 24 & 0xff; - - o[24] = x6 >>> 0 & 0xff; - o[25] = x6 >>> 8 & 0xff; - o[26] = x6 >>> 16 & 0xff; - o[27] = x6 >>> 24 & 0xff; - - o[28] = x7 >>> 0 & 0xff; - o[29] = x7 >>> 8 & 0xff; - o[30] = x7 >>> 16 & 0xff; - o[31] = x7 >>> 24 & 0xff; - - o[32] = x8 >>> 0 & 0xff; - o[33] = x8 >>> 8 & 0xff; - o[34] = x8 >>> 16 & 0xff; - o[35] = x8 >>> 24 & 0xff; - - o[36] = x9 >>> 0 & 0xff; - o[37] = x9 >>> 8 & 0xff; - o[38] = x9 >>> 16 & 0xff; - o[39] = x9 >>> 24 & 0xff; - - o[40] = x10 >>> 0 & 0xff; - o[41] = x10 >>> 8 & 0xff; - o[42] = x10 >>> 16 & 0xff; - o[43] = x10 >>> 24 & 0xff; - - o[44] = x11 >>> 0 & 0xff; - o[45] = x11 >>> 8 & 0xff; - o[46] = x11 >>> 16 & 0xff; - o[47] = x11 >>> 24 & 0xff; - - o[48] = x12 >>> 0 & 0xff; - o[49] = x12 >>> 8 & 0xff; - o[50] = x12 >>> 16 & 0xff; - o[51] = x12 >>> 24 & 0xff; - - o[52] = x13 >>> 0 & 0xff; - o[53] = x13 >>> 8 & 0xff; - o[54] = x13 >>> 16 & 0xff; - o[55] = x13 >>> 24 & 0xff; - - o[56] = x14 >>> 0 & 0xff; - o[57] = x14 >>> 8 & 0xff; - o[58] = x14 >>> 16 & 0xff; - o[59] = x14 >>> 24 & 0xff; - - o[60] = x15 >>> 0 & 0xff; - o[61] = x15 >>> 8 & 0xff; - o[62] = x15 >>> 16 & 0xff; - o[63] = x15 >>> 24 & 0xff; -} - -function core_hsalsa20(o,p,k,c) { - var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, - j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, - j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, - j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, - j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, - j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, - j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, - j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, - j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, - j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, - j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, - j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, - j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, - j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, - j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, - j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; - - var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, - x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, - x15 = j15, u; - - for (var i = 0; i < 20; i += 2) { - u = x0 + x12 | 0; - x4 ^= u<<7 | u>>>(32-7); - u = x4 + x0 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x4 | 0; - x12 ^= u<<13 | u>>>(32-13); - u = x12 + x8 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x1 | 0; - x9 ^= u<<7 | u>>>(32-7); - u = x9 + x5 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x9 | 0; - x1 ^= u<<13 | u>>>(32-13); - u = x1 + x13 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x6 | 0; - x14 ^= u<<7 | u>>>(32-7); - u = x14 + x10 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x14 | 0; - x6 ^= u<<13 | u>>>(32-13); - u = x6 + x2 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x11 | 0; - x3 ^= u<<7 | u>>>(32-7); - u = x3 + x15 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x3 | 0; - x11 ^= u<<13 | u>>>(32-13); - u = x11 + x7 | 0; - x15 ^= u<<18 | u>>>(32-18); - - u = x0 + x3 | 0; - x1 ^= u<<7 | u>>>(32-7); - u = x1 + x0 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x1 | 0; - x3 ^= u<<13 | u>>>(32-13); - u = x3 + x2 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x4 | 0; - x6 ^= u<<7 | u>>>(32-7); - u = x6 + x5 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x6 | 0; - x4 ^= u<<13 | u>>>(32-13); - u = x4 + x7 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x9 | 0; - x11 ^= u<<7 | u>>>(32-7); - u = x11 + x10 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x11 | 0; - x9 ^= u<<13 | u>>>(32-13); - u = x9 + x8 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x14 | 0; - x12 ^= u<<7 | u>>>(32-7); - u = x12 + x15 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x12 | 0; - x14 ^= u<<13 | u>>>(32-13); - u = x14 + x13 | 0; - x15 ^= u<<18 | u>>>(32-18); - } - - o[ 0] = x0 >>> 0 & 0xff; - o[ 1] = x0 >>> 8 & 0xff; - o[ 2] = x0 >>> 16 & 0xff; - o[ 3] = x0 >>> 24 & 0xff; - - o[ 4] = x5 >>> 0 & 0xff; - o[ 5] = x5 >>> 8 & 0xff; - o[ 6] = x5 >>> 16 & 0xff; - o[ 7] = x5 >>> 24 & 0xff; - - o[ 8] = x10 >>> 0 & 0xff; - o[ 9] = x10 >>> 8 & 0xff; - o[10] = x10 >>> 16 & 0xff; - o[11] = x10 >>> 24 & 0xff; - - o[12] = x15 >>> 0 & 0xff; - o[13] = x15 >>> 8 & 0xff; - o[14] = x15 >>> 16 & 0xff; - o[15] = x15 >>> 24 & 0xff; - - o[16] = x6 >>> 0 & 0xff; - o[17] = x6 >>> 8 & 0xff; - o[18] = x6 >>> 16 & 0xff; - o[19] = x6 >>> 24 & 0xff; - - o[20] = x7 >>> 0 & 0xff; - o[21] = x7 >>> 8 & 0xff; - o[22] = x7 >>> 16 & 0xff; - o[23] = x7 >>> 24 & 0xff; - - o[24] = x8 >>> 0 & 0xff; - o[25] = x8 >>> 8 & 0xff; - o[26] = x8 >>> 16 & 0xff; - o[27] = x8 >>> 24 & 0xff; - - o[28] = x9 >>> 0 & 0xff; - o[29] = x9 >>> 8 & 0xff; - o[30] = x9 >>> 16 & 0xff; - o[31] = x9 >>> 24 & 0xff; -} - -function crypto_core_salsa20(out,inp,k,c) { - core_salsa20(out,inp,k,c); -} - -function crypto_core_hsalsa20(out,inp,k,c) { - core_hsalsa20(out,inp,k,c); -} - -var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]); - // "expand 32-byte k" - -function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) { - var z = new Uint8Array(16), x = new Uint8Array(64); - var u, i; - for (i = 0; i < 16; i++) z[i] = 0; - for (i = 0; i < 8; i++) z[i] = n[i]; - while (b >= 64) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i]; - u = 1; - for (i = 8; i < 16; i++) { - u = u + (z[i] & 0xff) | 0; - z[i] = u & 0xff; - u >>>= 8; - } - b -= 64; - cpos += 64; - mpos += 64; - } - if (b > 0) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i]; - } - return 0; -} - -function crypto_stream_salsa20(c,cpos,b,n,k) { - var z = new Uint8Array(16), x = new Uint8Array(64); - var u, i; - for (i = 0; i < 16; i++) z[i] = 0; - for (i = 0; i < 8; i++) z[i] = n[i]; - while (b >= 64) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < 64; i++) c[cpos+i] = x[i]; - u = 1; - for (i = 8; i < 16; i++) { - u = u + (z[i] & 0xff) | 0; - z[i] = u & 0xff; - u >>>= 8; - } - b -= 64; - cpos += 64; - } - if (b > 0) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < b; i++) c[cpos+i] = x[i]; - } - return 0; -} - -function crypto_stream(c,cpos,d,n,k) { - var s = new Uint8Array(32); - crypto_core_hsalsa20(s,n,k,sigma); - var sn = new Uint8Array(8); - for (var i = 0; i < 8; i++) sn[i] = n[i+16]; - return crypto_stream_salsa20(c,cpos,d,sn,s); -} - -function crypto_stream_xor(c,cpos,m,mpos,d,n,k) { - var s = new Uint8Array(32); - crypto_core_hsalsa20(s,n,k,sigma); - var sn = new Uint8Array(8); - for (var i = 0; i < 8; i++) sn[i] = n[i+16]; - return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s); -} - -/* -* Port of Andrew Moon's Poly1305-donna-16. Public domain. -* https://github.com/floodyberry/poly1305-donna -*/ - -var poly1305 = function(key) { - this.buffer = new Uint8Array(16); - this.r = new Uint16Array(10); - this.h = new Uint16Array(10); - this.pad = new Uint16Array(8); - this.leftover = 0; - this.fin = 0; - - var t0, t1, t2, t3, t4, t5, t6, t7; - - t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff; - t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff; - t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03; - t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff; - t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff; - this.r[5] = ((t4 >>> 1)) & 0x1ffe; - t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff; - t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81; - t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff; - this.r[9] = ((t7 >>> 5)) & 0x007f; - - this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8; - this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8; - this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8; - this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8; - this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8; - this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8; - this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8; - this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8; -}; - -poly1305.prototype.blocks = function(m, mpos, bytes) { - var hibit = this.fin ? 0 : (1 << 11); - var t0, t1, t2, t3, t4, t5, t6, t7, c; - var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9; - - var h0 = this.h[0], - h1 = this.h[1], - h2 = this.h[2], - h3 = this.h[3], - h4 = this.h[4], - h5 = this.h[5], - h6 = this.h[6], - h7 = this.h[7], - h8 = this.h[8], - h9 = this.h[9]; - - var r0 = this.r[0], - r1 = this.r[1], - r2 = this.r[2], - r3 = this.r[3], - r4 = this.r[4], - r5 = this.r[5], - r6 = this.r[6], - r7 = this.r[7], - r8 = this.r[8], - r9 = this.r[9]; - - while (bytes >= 16) { - t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff; - t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff; - t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff; - t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff; - t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff; - h5 += ((t4 >>> 1)) & 0x1fff; - t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff; - t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff; - t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff; - h9 += ((t7 >>> 5)) | hibit; - - c = 0; - - d0 = c; - d0 += h0 * r0; - d0 += h1 * (5 * r9); - d0 += h2 * (5 * r8); - d0 += h3 * (5 * r7); - d0 += h4 * (5 * r6); - c = (d0 >>> 13); d0 &= 0x1fff; - d0 += h5 * (5 * r5); - d0 += h6 * (5 * r4); - d0 += h7 * (5 * r3); - d0 += h8 * (5 * r2); - d0 += h9 * (5 * r1); - c += (d0 >>> 13); d0 &= 0x1fff; - - d1 = c; - d1 += h0 * r1; - d1 += h1 * r0; - d1 += h2 * (5 * r9); - d1 += h3 * (5 * r8); - d1 += h4 * (5 * r7); - c = (d1 >>> 13); d1 &= 0x1fff; - d1 += h5 * (5 * r6); - d1 += h6 * (5 * r5); - d1 += h7 * (5 * r4); - d1 += h8 * (5 * r3); - d1 += h9 * (5 * r2); - c += (d1 >>> 13); d1 &= 0x1fff; - - d2 = c; - d2 += h0 * r2; - d2 += h1 * r1; - d2 += h2 * r0; - d2 += h3 * (5 * r9); - d2 += h4 * (5 * r8); - c = (d2 >>> 13); d2 &= 0x1fff; - d2 += h5 * (5 * r7); - d2 += h6 * (5 * r6); - d2 += h7 * (5 * r5); - d2 += h8 * (5 * r4); - d2 += h9 * (5 * r3); - c += (d2 >>> 13); d2 &= 0x1fff; - - d3 = c; - d3 += h0 * r3; - d3 += h1 * r2; - d3 += h2 * r1; - d3 += h3 * r0; - d3 += h4 * (5 * r9); - c = (d3 >>> 13); d3 &= 0x1fff; - d3 += h5 * (5 * r8); - d3 += h6 * (5 * r7); - d3 += h7 * (5 * r6); - d3 += h8 * (5 * r5); - d3 += h9 * (5 * r4); - c += (d3 >>> 13); d3 &= 0x1fff; - - d4 = c; - d4 += h0 * r4; - d4 += h1 * r3; - d4 += h2 * r2; - d4 += h3 * r1; - d4 += h4 * r0; - c = (d4 >>> 13); d4 &= 0x1fff; - d4 += h5 * (5 * r9); - d4 += h6 * (5 * r8); - d4 += h7 * (5 * r7); - d4 += h8 * (5 * r6); - d4 += h9 * (5 * r5); - c += (d4 >>> 13); d4 &= 0x1fff; - - d5 = c; - d5 += h0 * r5; - d5 += h1 * r4; - d5 += h2 * r3; - d5 += h3 * r2; - d5 += h4 * r1; - c = (d5 >>> 13); d5 &= 0x1fff; - d5 += h5 * r0; - d5 += h6 * (5 * r9); - d5 += h7 * (5 * r8); - d5 += h8 * (5 * r7); - d5 += h9 * (5 * r6); - c += (d5 >>> 13); d5 &= 0x1fff; - - d6 = c; - d6 += h0 * r6; - d6 += h1 * r5; - d6 += h2 * r4; - d6 += h3 * r3; - d6 += h4 * r2; - c = (d6 >>> 13); d6 &= 0x1fff; - d6 += h5 * r1; - d6 += h6 * r0; - d6 += h7 * (5 * r9); - d6 += h8 * (5 * r8); - d6 += h9 * (5 * r7); - c += (d6 >>> 13); d6 &= 0x1fff; - - d7 = c; - d7 += h0 * r7; - d7 += h1 * r6; - d7 += h2 * r5; - d7 += h3 * r4; - d7 += h4 * r3; - c = (d7 >>> 13); d7 &= 0x1fff; - d7 += h5 * r2; - d7 += h6 * r1; - d7 += h7 * r0; - d7 += h8 * (5 * r9); - d7 += h9 * (5 * r8); - c += (d7 >>> 13); d7 &= 0x1fff; - - d8 = c; - d8 += h0 * r8; - d8 += h1 * r7; - d8 += h2 * r6; - d8 += h3 * r5; - d8 += h4 * r4; - c = (d8 >>> 13); d8 &= 0x1fff; - d8 += h5 * r3; - d8 += h6 * r2; - d8 += h7 * r1; - d8 += h8 * r0; - d8 += h9 * (5 * r9); - c += (d8 >>> 13); d8 &= 0x1fff; - - d9 = c; - d9 += h0 * r9; - d9 += h1 * r8; - d9 += h2 * r7; - d9 += h3 * r6; - d9 += h4 * r5; - c = (d9 >>> 13); d9 &= 0x1fff; - d9 += h5 * r4; - d9 += h6 * r3; - d9 += h7 * r2; - d9 += h8 * r1; - d9 += h9 * r0; - c += (d9 >>> 13); d9 &= 0x1fff; - - c = (((c << 2) + c)) | 0; - c = (c + d0) | 0; - d0 = c & 0x1fff; - c = (c >>> 13); - d1 += c; - - h0 = d0; - h1 = d1; - h2 = d2; - h3 = d3; - h4 = d4; - h5 = d5; - h6 = d6; - h7 = d7; - h8 = d8; - h9 = d9; - - mpos += 16; - bytes -= 16; - } - this.h[0] = h0; - this.h[1] = h1; - this.h[2] = h2; - this.h[3] = h3; - this.h[4] = h4; - this.h[5] = h5; - this.h[6] = h6; - this.h[7] = h7; - this.h[8] = h8; - this.h[9] = h9; -}; - -poly1305.prototype.finish = function(mac, macpos) { - var g = new Uint16Array(10); - var c, mask, f, i; - - if (this.leftover) { - i = this.leftover; - this.buffer[i++] = 1; - for (; i < 16; i++) this.buffer[i] = 0; - this.fin = 1; - this.blocks(this.buffer, 0, 16); - } - - c = this.h[1] >>> 13; - this.h[1] &= 0x1fff; - for (i = 2; i < 10; i++) { - this.h[i] += c; - c = this.h[i] >>> 13; - this.h[i] &= 0x1fff; - } - this.h[0] += (c * 5); - c = this.h[0] >>> 13; - this.h[0] &= 0x1fff; - this.h[1] += c; - c = this.h[1] >>> 13; - this.h[1] &= 0x1fff; - this.h[2] += c; - - g[0] = this.h[0] + 5; - c = g[0] >>> 13; - g[0] &= 0x1fff; - for (i = 1; i < 10; i++) { - g[i] = this.h[i] + c; - c = g[i] >>> 13; - g[i] &= 0x1fff; - } - g[9] -= (1 << 13); - - mask = (c ^ 1) - 1; - for (i = 0; i < 10; i++) g[i] &= mask; - mask = ~mask; - for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]; - - this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff; - this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff; - this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff; - this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff; - this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff; - this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff; - this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff; - this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff; - - f = this.h[0] + this.pad[0]; - this.h[0] = f & 0xffff; - for (i = 1; i < 8; i++) { - f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0; - this.h[i] = f & 0xffff; - } - - mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff; - mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff; - mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff; - mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff; - mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff; - mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff; - mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff; - mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff; - mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff; - mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff; - mac[macpos+10] = (this.h[5] >>> 0) & 0xff; - mac[macpos+11] = (this.h[5] >>> 8) & 0xff; - mac[macpos+12] = (this.h[6] >>> 0) & 0xff; - mac[macpos+13] = (this.h[6] >>> 8) & 0xff; - mac[macpos+14] = (this.h[7] >>> 0) & 0xff; - mac[macpos+15] = (this.h[7] >>> 8) & 0xff; -}; - -poly1305.prototype.update = function(m, mpos, bytes) { - var i, want; - - if (this.leftover) { - want = (16 - this.leftover); - if (want > bytes) - want = bytes; - for (i = 0; i < want; i++) - this.buffer[this.leftover + i] = m[mpos+i]; - bytes -= want; - mpos += want; - this.leftover += want; - if (this.leftover < 16) - return; - this.blocks(this.buffer, 0, 16); - this.leftover = 0; - } - - if (bytes >= 16) { - want = bytes - (bytes % 16); - this.blocks(m, mpos, want); - mpos += want; - bytes -= want; - } - - if (bytes) { - for (i = 0; i < bytes; i++) - this.buffer[this.leftover + i] = m[mpos+i]; - this.leftover += bytes; - } -}; - -function crypto_onetimeauth(out, outpos, m, mpos, n, k) { - var s = new poly1305(k); - s.update(m, mpos, n); - s.finish(out, outpos); - return 0; -} - -function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) { - var x = new Uint8Array(16); - crypto_onetimeauth(x,0,m,mpos,n,k); - return crypto_verify_16(h,hpos,x,0); -} - -function crypto_secretbox(c,m,d,n,k) { - var i; - if (d < 32) return -1; - crypto_stream_xor(c,0,m,0,d,n,k); - crypto_onetimeauth(c, 16, c, 32, d - 32, c); - for (i = 0; i < 16; i++) c[i] = 0; - return 0; -} - -function crypto_secretbox_open(m,c,d,n,k) { - var i; - var x = new Uint8Array(32); - if (d < 32) return -1; - crypto_stream(x,0,32,n,k); - if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1; - crypto_stream_xor(m,0,c,0,d,n,k); - for (i = 0; i < 32; i++) m[i] = 0; - return 0; -} - -function set25519(r, a) { - var i; - for (i = 0; i < 16; i++) r[i] = a[i]|0; -} - -function car25519(o) { - var i, v, c = 1; - for (i = 0; i < 16; i++) { - v = o[i] + c + 65535; - c = Math.floor(v / 65536); - o[i] = v - c * 65536; - } - o[0] += c-1 + 37 * (c-1); -} - -function sel25519(p, q, b) { - var t, c = ~(b-1); - for (var i = 0; i < 16; i++) { - t = c & (p[i] ^ q[i]); - p[i] ^= t; - q[i] ^= t; - } -} - -function pack25519(o, n) { - var i, j, b; - var m = gf(), t = gf(); - for (i = 0; i < 16; i++) t[i] = n[i]; - car25519(t); - car25519(t); - car25519(t); - for (j = 0; j < 2; j++) { - m[0] = t[0] - 0xffed; - for (i = 1; i < 15; i++) { - m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1); - m[i-1] &= 0xffff; - } - m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1); - b = (m[15]>>16) & 1; - m[14] &= 0xffff; - sel25519(t, m, 1-b); - } - for (i = 0; i < 16; i++) { - o[2*i] = t[i] & 0xff; - o[2*i+1] = t[i]>>8; - } -} - -function neq25519(a, b) { - var c = new Uint8Array(32), d = new Uint8Array(32); - pack25519(c, a); - pack25519(d, b); - return crypto_verify_32(c, 0, d, 0); -} - -function par25519(a) { - var d = new Uint8Array(32); - pack25519(d, a); - return d[0] & 1; -} - -function unpack25519(o, n) { - var i; - for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8); - o[15] &= 0x7fff; -} - -function A(o, a, b) { - for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]; -} - -function Z(o, a, b) { - for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]; -} - -function M(o, a, b) { - var v, c, - t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, - t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, - t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, - t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, - b0 = b[0], - b1 = b[1], - b2 = b[2], - b3 = b[3], - b4 = b[4], - b5 = b[5], - b6 = b[6], - b7 = b[7], - b8 = b[8], - b9 = b[9], - b10 = b[10], - b11 = b[11], - b12 = b[12], - b13 = b[13], - b14 = b[14], - b15 = b[15]; +function M(o, a, b) { + var v, c, + t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, + t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, + t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, + t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, + b0 = b[0], + b1 = b[1], + b2 = b[2], + b3 = b[3], + b4 = b[4], + b5 = b[5], + b6 = b[6], + b7 = b[7], + b8 = b[8], + b9 = b[9], + b10 = b[10], + b11 = b[11], + b12 = b[12], + b13 = b[13], + b14 = b[14], + b15 = b[15]; v = a[0]; t0 += v * b0; @@ -5278,4983 +1593,8069 @@ function M(o, a, b) { t29 += v * b14; t30 += v * b15; - t0 += 38 * t16; - t1 += 38 * t17; - t2 += 38 * t18; - t3 += 38 * t19; - t4 += 38 * t20; - t5 += 38 * t21; - t6 += 38 * t22; - t7 += 38 * t23; - t8 += 38 * t24; - t9 += 38 * t25; - t10 += 38 * t26; - t11 += 38 * t27; - t12 += 38 * t28; - t13 += 38 * t29; - t14 += 38 * t30; - // t15 left as is + t0 += 38 * t16; + t1 += 38 * t17; + t2 += 38 * t18; + t3 += 38 * t19; + t4 += 38 * t20; + t5 += 38 * t21; + t6 += 38 * t22; + t7 += 38 * t23; + t8 += 38 * t24; + t9 += 38 * t25; + t10 += 38 * t26; + t11 += 38 * t27; + t12 += 38 * t28; + t13 += 38 * t29; + t14 += 38 * t30; + // t15 left as is + + // first car + c = 1; + v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; + v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; + v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; + v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; + v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; + v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; + v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; + v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; + v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; + v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; + v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; + v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; + v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; + v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; + v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; + v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; + t0 += c-1 + 37 * (c-1); + + // second car + c = 1; + v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; + v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; + v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; + v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; + v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; + v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; + v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; + v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; + v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; + v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; + v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; + v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; + v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; + v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; + v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; + v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; + t0 += c-1 + 37 * (c-1); + + o[ 0] = t0; + o[ 1] = t1; + o[ 2] = t2; + o[ 3] = t3; + o[ 4] = t4; + o[ 5] = t5; + o[ 6] = t6; + o[ 7] = t7; + o[ 8] = t8; + o[ 9] = t9; + o[10] = t10; + o[11] = t11; + o[12] = t12; + o[13] = t13; + o[14] = t14; + o[15] = t15; +} + +function S(o, a) { + M(o, a, a); +} + +function inv25519(o, i) { + var c = gf(); + var a; + for (a = 0; a < 16; a++) c[a] = i[a]; + for (a = 253; a >= 0; a--) { + S(c, c); + if(a !== 2 && a !== 4) M(c, c, i); + } + for (a = 0; a < 16; a++) o[a] = c[a]; +} + +function pow2523(o, i) { + var c = gf(); + var a; + for (a = 0; a < 16; a++) c[a] = i[a]; + for (a = 250; a >= 0; a--) { + S(c, c); + if(a !== 1) M(c, c, i); + } + for (a = 0; a < 16; a++) o[a] = c[a]; +} + +function crypto_scalarmult(q, n, p) { + var z = new Uint8Array(32); + var x = new Float64Array(80), r, i; + var a = gf(), b = gf(), c = gf(), + d = gf(), e = gf(), f = gf(); + for (i = 0; i < 31; i++) z[i] = n[i]; + z[31]=(n[31]&127)|64; + z[0]&=248; + unpack25519(x,p); + for (i = 0; i < 16; i++) { + b[i]=x[i]; + d[i]=a[i]=c[i]=0; + } + a[0]=d[0]=1; + for (i=254; i>=0; --i) { + r=(z[i>>>3]>>>(i&7))&1; + sel25519(a,b,r); + sel25519(c,d,r); + A(e,a,c); + Z(a,a,c); + A(c,b,d); + Z(b,b,d); + S(d,e); + S(f,a); + M(a,c,a); + M(c,b,e); + A(e,a,c); + Z(a,a,c); + S(b,a); + Z(c,d,f); + M(a,c,_121665); + A(a,a,d); + M(c,c,a); + M(a,d,f); + M(d,b,x); + S(b,e); + sel25519(a,b,r); + sel25519(c,d,r); + } + for (i = 0; i < 16; i++) { + x[i+16]=a[i]; + x[i+32]=c[i]; + x[i+48]=b[i]; + x[i+64]=d[i]; + } + var x32 = x.subarray(32); + var x16 = x.subarray(16); + inv25519(x32,x32); + M(x16,x16,x32); + pack25519(q,x16); + return 0; +} + +function crypto_scalarmult_base(q, n) { + return crypto_scalarmult(q, n, _9); +} + +function crypto_box_keypair(y, x) { + randombytes(x, 32); + return crypto_scalarmult_base(y, x); +} + +function crypto_box_beforenm(k, y, x) { + var s = new Uint8Array(32); + crypto_scalarmult(s, x, y); + return crypto_core_hsalsa20(k, _0, s, sigma); +} + +var crypto_box_afternm = crypto_secretbox; +var crypto_box_open_afternm = crypto_secretbox_open; + +function crypto_box(c, m, d, n, y, x) { + var k = new Uint8Array(32); + crypto_box_beforenm(k, y, x); + return crypto_box_afternm(c, m, d, n, k); +} + +function crypto_box_open(m, c, d, n, y, x) { + var k = new Uint8Array(32); + crypto_box_beforenm(k, y, x); + return crypto_box_open_afternm(m, c, d, n, k); +} + +var K = [ + 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, + 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, + 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, + 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, + 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, + 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, + 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, + 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, + 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, + 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, + 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, + 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, + 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, + 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, + 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, + 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, + 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, + 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, + 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, + 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, + 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, + 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, + 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, + 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, + 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, + 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, + 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, + 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, + 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, + 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, + 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, + 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, + 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, + 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, + 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, + 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, + 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, + 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, + 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, + 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 +]; + +function crypto_hashblocks_hl(hh, hl, m, n) { + var wh = new Int32Array(16), wl = new Int32Array(16), + bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, + bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, + th, tl, i, j, h, l, a, b, c, d; + + var ah0 = hh[0], + ah1 = hh[1], + ah2 = hh[2], + ah3 = hh[3], + ah4 = hh[4], + ah5 = hh[5], + ah6 = hh[6], + ah7 = hh[7], + + al0 = hl[0], + al1 = hl[1], + al2 = hl[2], + al3 = hl[3], + al4 = hl[4], + al5 = hl[5], + al6 = hl[6], + al7 = hl[7]; + + var pos = 0; + while (n >= 128) { + for (i = 0; i < 16; i++) { + j = 8 * i + pos; + wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3]; + wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7]; + } + for (i = 0; i < 80; i++) { + bh0 = ah0; + bh1 = ah1; + bh2 = ah2; + bh3 = ah3; + bh4 = ah4; + bh5 = ah5; + bh6 = ah6; + bh7 = ah7; + + bl0 = al0; + bl1 = al1; + bl2 = al2; + bl3 = al3; + bl4 = al4; + bl5 = al5; + bl6 = al6; + bl7 = al7; + + // add + h = ah7; + l = al7; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + // Sigma1 + h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32)))); + l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32)))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // Ch + h = (ah4 & ah5) ^ (~ah4 & ah6); + l = (al4 & al5) ^ (~al4 & al6); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // K + h = K[i*2]; + l = K[i*2+1]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // w + h = wh[i%16]; + l = wl[i%16]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + th = c & 0xffff | d << 16; + tl = a & 0xffff | b << 16; + + // add + h = th; + l = tl; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + // Sigma0 + h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32)))); + l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32)))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // Maj + h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + bh7 = (c & 0xffff) | (d << 16); + bl7 = (a & 0xffff) | (b << 16); + + // add + h = bh3; + l = bl3; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = th; + l = tl; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + bh3 = (c & 0xffff) | (d << 16); + bl3 = (a & 0xffff) | (b << 16); + + ah1 = bh0; + ah2 = bh1; + ah3 = bh2; + ah4 = bh3; + ah5 = bh4; + ah6 = bh5; + ah7 = bh6; + ah0 = bh7; + + al1 = bl0; + al2 = bl1; + al3 = bl2; + al4 = bl3; + al5 = bl4; + al6 = bl5; + al7 = bl6; + al0 = bl7; + + if (i%16 === 15) { + for (j = 0; j < 16; j++) { + // add + h = wh[j]; + l = wl[j]; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = wh[(j+9)%16]; + l = wl[(j+9)%16]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // sigma0 + th = wh[(j+1)%16]; + tl = wl[(j+1)%16]; + h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7); + l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // sigma1 + th = wh[(j+14)%16]; + tl = wl[(j+14)%16]; + h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6); + l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + wh[j] = (c & 0xffff) | (d << 16); + wl[j] = (a & 0xffff) | (b << 16); + } + } + } + + // add + h = ah0; + l = al0; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[0]; + l = hl[0]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[0] = ah0 = (c & 0xffff) | (d << 16); + hl[0] = al0 = (a & 0xffff) | (b << 16); + + h = ah1; + l = al1; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[1]; + l = hl[1]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[1] = ah1 = (c & 0xffff) | (d << 16); + hl[1] = al1 = (a & 0xffff) | (b << 16); + + h = ah2; + l = al2; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[2]; + l = hl[2]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[2] = ah2 = (c & 0xffff) | (d << 16); + hl[2] = al2 = (a & 0xffff) | (b << 16); + + h = ah3; + l = al3; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[3]; + l = hl[3]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[3] = ah3 = (c & 0xffff) | (d << 16); + hl[3] = al3 = (a & 0xffff) | (b << 16); + + h = ah4; + l = al4; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[4]; + l = hl[4]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[4] = ah4 = (c & 0xffff) | (d << 16); + hl[4] = al4 = (a & 0xffff) | (b << 16); + + h = ah5; + l = al5; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[5]; + l = hl[5]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[5] = ah5 = (c & 0xffff) | (d << 16); + hl[5] = al5 = (a & 0xffff) | (b << 16); + + h = ah6; + l = al6; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[6]; + l = hl[6]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[6] = ah6 = (c & 0xffff) | (d << 16); + hl[6] = al6 = (a & 0xffff) | (b << 16); + + h = ah7; + l = al7; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[7]; + l = hl[7]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[7] = ah7 = (c & 0xffff) | (d << 16); + hl[7] = al7 = (a & 0xffff) | (b << 16); + + pos += 128; + n -= 128; + } + + return n; +} + +function crypto_hash(out, m, n) { + var hh = new Int32Array(8), + hl = new Int32Array(8), + x = new Uint8Array(256), + i, b = n; + + hh[0] = 0x6a09e667; + hh[1] = 0xbb67ae85; + hh[2] = 0x3c6ef372; + hh[3] = 0xa54ff53a; + hh[4] = 0x510e527f; + hh[5] = 0x9b05688c; + hh[6] = 0x1f83d9ab; + hh[7] = 0x5be0cd19; + + hl[0] = 0xf3bcc908; + hl[1] = 0x84caa73b; + hl[2] = 0xfe94f82b; + hl[3] = 0x5f1d36f1; + hl[4] = 0xade682d1; + hl[5] = 0x2b3e6c1f; + hl[6] = 0xfb41bd6b; + hl[7] = 0x137e2179; + + crypto_hashblocks_hl(hh, hl, m, n); + n %= 128; + + for (i = 0; i < n; i++) x[i] = m[b-n+i]; + x[n] = 128; + + n = 256-128*(n<112?1:0); + x[n-9] = 0; + ts64(x, n-8, (b / 0x20000000) | 0, b << 3); + crypto_hashblocks_hl(hh, hl, x, n); + + for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); + + return 0; +} + +function add(p, q) { + var a = gf(), b = gf(), c = gf(), + d = gf(), e = gf(), f = gf(), + g = gf(), h = gf(), t = gf(); + + Z(a, p[1], p[0]); + Z(t, q[1], q[0]); + M(a, a, t); + A(b, p[0], p[1]); + A(t, q[0], q[1]); + M(b, b, t); + M(c, p[3], q[3]); + M(c, c, D2); + M(d, p[2], q[2]); + A(d, d, d); + Z(e, b, a); + Z(f, d, c); + A(g, d, c); + A(h, b, a); + + M(p[0], e, f); + M(p[1], h, g); + M(p[2], g, f); + M(p[3], e, h); +} + +function cswap(p, q, b) { + var i; + for (i = 0; i < 4; i++) { + sel25519(p[i], q[i], b); + } +} + +function pack(r, p) { + var tx = gf(), ty = gf(), zi = gf(); + inv25519(zi, p[2]); + M(tx, p[0], zi); + M(ty, p[1], zi); + pack25519(r, ty); + r[31] ^= par25519(tx) << 7; +} + +function scalarmult(p, q, s) { + var b, i; + set25519(p[0], gf0); + set25519(p[1], gf1); + set25519(p[2], gf1); + set25519(p[3], gf0); + for (i = 255; i >= 0; --i) { + b = (s[(i/8)|0] >> (i&7)) & 1; + cswap(p, q, b); + add(q, p); + add(p, p); + cswap(p, q, b); + } +} + +function scalarbase(p, s) { + var q = [gf(), gf(), gf(), gf()]; + set25519(q[0], X); + set25519(q[1], Y); + set25519(q[2], gf1); + M(q[3], X, Y); + scalarmult(p, q, s); +} + +function crypto_sign_keypair(pk, sk, seeded) { + var d = new Uint8Array(64); + var p = [gf(), gf(), gf(), gf()]; + var i; + + if (!seeded) randombytes(sk, 32); + crypto_hash(d, sk, 32); + d[0] &= 248; + d[31] &= 127; + d[31] |= 64; + + scalarbase(p, d); + pack(pk, p); + + for (i = 0; i < 32; i++) sk[i+32] = pk[i]; + return 0; +} + +var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); + +function modL(r, x) { + var carry, i, j, k; + for (i = 63; i >= 32; --i) { + carry = 0; + for (j = i - 32, k = i - 12; j < k; ++j) { + x[j] += carry - 16 * x[i] * L[j - (i - 32)]; + carry = (x[j] + 128) >> 8; + x[j] -= carry * 256; + } + x[j] += carry; + x[i] = 0; + } + carry = 0; + for (j = 0; j < 32; j++) { + x[j] += carry - (x[31] >> 4) * L[j]; + carry = x[j] >> 8; + x[j] &= 255; + } + for (j = 0; j < 32; j++) x[j] -= carry * L[j]; + for (i = 0; i < 32; i++) { + x[i+1] += x[i] >> 8; + r[i] = x[i] & 255; + } +} + +function reduce(r) { + var x = new Float64Array(64), i; + for (i = 0; i < 64; i++) x[i] = r[i]; + for (i = 0; i < 64; i++) r[i] = 0; + modL(r, x); +} + +// Note: difference from C - smlen returned, not passed as argument. +function crypto_sign(sm, m, n, sk) { + var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); + var i, j, x = new Float64Array(64); + var p = [gf(), gf(), gf(), gf()]; + + crypto_hash(d, sk, 32); + d[0] &= 248; + d[31] &= 127; + d[31] |= 64; + + var smlen = n + 64; + for (i = 0; i < n; i++) sm[64 + i] = m[i]; + for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]; + + crypto_hash(r, sm.subarray(32), n+32); + reduce(r); + scalarbase(p, r); + pack(sm, p); + + for (i = 32; i < 64; i++) sm[i] = sk[i]; + crypto_hash(h, sm, n + 64); + reduce(h); + + for (i = 0; i < 64; i++) x[i] = 0; + for (i = 0; i < 32; i++) x[i] = r[i]; + for (i = 0; i < 32; i++) { + for (j = 0; j < 32; j++) { + x[i+j] += h[i] * d[j]; + } + } + + modL(sm.subarray(32), x); + return smlen; +} + +function unpackneg(r, p) { + var t = gf(), chk = gf(), num = gf(), + den = gf(), den2 = gf(), den4 = gf(), + den6 = gf(); + + set25519(r[2], gf1); + unpack25519(r[1], p); + S(num, r[1]); + M(den, num, D); + Z(num, num, r[2]); + A(den, r[2], den); + + S(den2, den); + S(den4, den2); + M(den6, den4, den2); + M(t, den6, num); + M(t, t, den); + + pow2523(t, t); + M(t, t, num); + M(t, t, den); + M(t, t, den); + M(r[0], t, den); + + S(chk, r[0]); + M(chk, chk, den); + if (neq25519(chk, num)) M(r[0], r[0], I); + + S(chk, r[0]); + M(chk, chk, den); + if (neq25519(chk, num)) return -1; + + if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]); + + M(r[3], r[0], r[1]); + return 0; +} + +function crypto_sign_open(m, sm, n, pk) { + var i, mlen; + var t = new Uint8Array(32), h = new Uint8Array(64); + var p = [gf(), gf(), gf(), gf()], + q = [gf(), gf(), gf(), gf()]; + + mlen = -1; + if (n < 64) return -1; + + if (unpackneg(q, pk)) return -1; + + for (i = 0; i < n; i++) m[i] = sm[i]; + for (i = 0; i < 32; i++) m[i+32] = pk[i]; + crypto_hash(h, m, n); + reduce(h); + scalarmult(p, q, h); + + scalarbase(q, sm.subarray(32)); + add(p, q); + pack(t, p); + + n -= 64; + if (crypto_verify_32(sm, 0, t, 0)) { + for (i = 0; i < n; i++) m[i] = 0; + return -1; + } + + for (i = 0; i < n; i++) m[i] = sm[i + 64]; + mlen = n; + return mlen; +} + +var crypto_secretbox_KEYBYTES = 32, + crypto_secretbox_NONCEBYTES = 24, + crypto_secretbox_ZEROBYTES = 32, + crypto_secretbox_BOXZEROBYTES = 16, + crypto_scalarmult_BYTES = 32, + crypto_scalarmult_SCALARBYTES = 32, + crypto_box_PUBLICKEYBYTES = 32, + crypto_box_SECRETKEYBYTES = 32, + crypto_box_BEFORENMBYTES = 32, + crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, + crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, + crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, + crypto_sign_BYTES = 64, + crypto_sign_PUBLICKEYBYTES = 32, + crypto_sign_SECRETKEYBYTES = 64, + crypto_sign_SEEDBYTES = 32, + crypto_hash_BYTES = 64; + +nacl.lowlevel = { + crypto_core_hsalsa20: crypto_core_hsalsa20, + crypto_stream_xor: crypto_stream_xor, + crypto_stream: crypto_stream, + crypto_stream_salsa20_xor: crypto_stream_salsa20_xor, + crypto_stream_salsa20: crypto_stream_salsa20, + crypto_onetimeauth: crypto_onetimeauth, + crypto_onetimeauth_verify: crypto_onetimeauth_verify, + crypto_verify_16: crypto_verify_16, + crypto_verify_32: crypto_verify_32, + crypto_secretbox: crypto_secretbox, + crypto_secretbox_open: crypto_secretbox_open, + crypto_scalarmult: crypto_scalarmult, + crypto_scalarmult_base: crypto_scalarmult_base, + crypto_box_beforenm: crypto_box_beforenm, + crypto_box_afternm: crypto_box_afternm, + crypto_box: crypto_box, + crypto_box_open: crypto_box_open, + crypto_box_keypair: crypto_box_keypair, + crypto_hash: crypto_hash, + crypto_sign: crypto_sign, + crypto_sign_keypair: crypto_sign_keypair, + crypto_sign_open: crypto_sign_open, + + crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES, + crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES, + crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES, + crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES, + crypto_scalarmult_BYTES: crypto_scalarmult_BYTES, + crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES, + crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES, + crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES, + crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES, + crypto_box_NONCEBYTES: crypto_box_NONCEBYTES, + crypto_box_ZEROBYTES: crypto_box_ZEROBYTES, + crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES, + crypto_sign_BYTES: crypto_sign_BYTES, + crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES, + crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES, + crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES, + crypto_hash_BYTES: crypto_hash_BYTES +}; + +/* High-level API */ + +function checkLengths(k, n) { + if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size'); + if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size'); +} + +function checkBoxLengths(pk, sk) { + if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size'); + if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size'); +} + +function checkArrayTypes() { + for (var i = 0; i < arguments.length; i++) { + if (!(arguments[i] instanceof Uint8Array)) + throw new TypeError('unexpected type, use Uint8Array'); + } +} + +function cleanup(arr) { + for (var i = 0; i < arr.length; i++) arr[i] = 0; +} + +nacl.randomBytes = function(n) { + var b = new Uint8Array(n); + randombytes(b, n); + return b; +}; + +nacl.secretbox = function(msg, nonce, key) { + checkArrayTypes(msg, nonce, key); + checkLengths(key, nonce); + var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length); + var c = new Uint8Array(m.length); + for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i]; + crypto_secretbox(c, m, m.length, nonce, key); + return c.subarray(crypto_secretbox_BOXZEROBYTES); +}; + +nacl.secretbox.open = function(box, nonce, key) { + checkArrayTypes(box, nonce, key); + checkLengths(key, nonce); + var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length); + var m = new Uint8Array(c.length); + for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i]; + if (c.length < 32) return null; + if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null; + return m.subarray(crypto_secretbox_ZEROBYTES); +}; + +nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES; +nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES; +nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES; + +nacl.scalarMult = function(n, p) { + checkArrayTypes(n, p); + if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); + if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size'); + var q = new Uint8Array(crypto_scalarmult_BYTES); + crypto_scalarmult(q, n, p); + return q; +}; + +nacl.scalarMult.base = function(n) { + checkArrayTypes(n); + if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); + var q = new Uint8Array(crypto_scalarmult_BYTES); + crypto_scalarmult_base(q, n); + return q; +}; + +nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES; +nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES; + +nacl.box = function(msg, nonce, publicKey, secretKey) { + var k = nacl.box.before(publicKey, secretKey); + return nacl.secretbox(msg, nonce, k); +}; + +nacl.box.before = function(publicKey, secretKey) { + checkArrayTypes(publicKey, secretKey); + checkBoxLengths(publicKey, secretKey); + var k = new Uint8Array(crypto_box_BEFORENMBYTES); + crypto_box_beforenm(k, publicKey, secretKey); + return k; +}; + +nacl.box.after = nacl.secretbox; + +nacl.box.open = function(msg, nonce, publicKey, secretKey) { + var k = nacl.box.before(publicKey, secretKey); + return nacl.secretbox.open(msg, nonce, k); +}; + +nacl.box.open.after = nacl.secretbox.open; + +nacl.box.keyPair = function() { + var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_box_SECRETKEYBYTES); + crypto_box_keypair(pk, sk); + return {publicKey: pk, secretKey: sk}; +}; + +nacl.box.keyPair.fromSecretKey = function(secretKey) { + checkArrayTypes(secretKey); + if (secretKey.length !== crypto_box_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); + crypto_scalarmult_base(pk, secretKey); + return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; +}; + +nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES; +nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES; +nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES; +nacl.box.nonceLength = crypto_box_NONCEBYTES; +nacl.box.overheadLength = nacl.secretbox.overheadLength; + +nacl.sign = function(msg, secretKey) { + checkArrayTypes(msg, secretKey); + if (secretKey.length !== crypto_sign_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length); + crypto_sign(signedMsg, msg, msg.length, secretKey); + return signedMsg; +}; + +nacl.sign.open = function(signedMsg, publicKey) { + checkArrayTypes(signedMsg, publicKey); + if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) + throw new Error('bad public key size'); + var tmp = new Uint8Array(signedMsg.length); + var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey); + if (mlen < 0) return null; + var m = new Uint8Array(mlen); + for (var i = 0; i < m.length; i++) m[i] = tmp[i]; + return m; +}; + +nacl.sign.detached = function(msg, secretKey) { + var signedMsg = nacl.sign(msg, secretKey); + var sig = new Uint8Array(crypto_sign_BYTES); + for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; + return sig; +}; + +nacl.sign.detached.verify = function(msg, sig, publicKey) { + checkArrayTypes(msg, sig, publicKey); + if (sig.length !== crypto_sign_BYTES) + throw new Error('bad signature size'); + if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) + throw new Error('bad public key size'); + var sm = new Uint8Array(crypto_sign_BYTES + msg.length); + var m = new Uint8Array(crypto_sign_BYTES + msg.length); + var i; + for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]; + for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i]; + return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); +}; + +nacl.sign.keyPair = function() { + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); + crypto_sign_keypair(pk, sk); + return {publicKey: pk, secretKey: sk}; +}; + +nacl.sign.keyPair.fromSecretKey = function(secretKey) { + checkArrayTypes(secretKey); + if (secretKey.length !== crypto_sign_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i]; + return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; +}; + +nacl.sign.keyPair.fromSeed = function(seed) { + checkArrayTypes(seed); + if (seed.length !== crypto_sign_SEEDBYTES) + throw new Error('bad seed size'); + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); + for (var i = 0; i < 32; i++) sk[i] = seed[i]; + crypto_sign_keypair(pk, sk, true); + return {publicKey: pk, secretKey: sk}; +}; + +nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; +nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; +nacl.sign.seedLength = crypto_sign_SEEDBYTES; +nacl.sign.signatureLength = crypto_sign_BYTES; + +nacl.hash = function(msg) { + checkArrayTypes(msg); + var h = new Uint8Array(crypto_hash_BYTES); + crypto_hash(h, msg, msg.length); + return h; +}; + +nacl.hash.hashLength = crypto_hash_BYTES; + +nacl.verify = function(x, y) { + checkArrayTypes(x, y); + // Zero length arguments are considered not equal. + if (x.length === 0 || y.length === 0) return false; + if (x.length !== y.length) return false; + return (vn(x, 0, y, 0, x.length) === 0) ? true : false; +}; + +nacl.setPRNG = function(fn) { + randombytes = fn; +}; + +(function() { + // Initialize PRNG if environment provides CSPRNG. + // If not, methods calling randombytes will throw. + var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null; + if (crypto && crypto.getRandomValues) { + // Browsers. + var QUOTA = 65536; + nacl.setPRNG(function(x, n) { + var i, v = new Uint8Array(n); + for (i = 0; i < n; i += QUOTA) { + crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); + } + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); + } else if (true) { + // Node.js. + crypto = __webpack_require__(5); + if (crypto && crypto.randomBytes) { + nacl.setPRNG(function(x, n) { + var i, v = crypto.randomBytes(n); + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); + } + } +})(); + +})( true && module.exports ? module.exports : (self.nacl = self.nacl || {})); + + +/***/ }), +/* 4 */ +/***/ (function(module, exports, __webpack_require__) { + +// Written in 2014-2016 by Dmitry Chestnykh and Devi Mandiri. +// Public domain. +(function(root, f) { + 'use strict'; + if ( true && module.exports) module.exports = f(); + else if (root.nacl) root.nacl.util = f(); + else { + root.nacl = {}; + root.nacl.util = f(); + } +}(this, function() { + 'use strict'; + + var util = {}; + + function validateBase64(s) { + if (!(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(s))) { + throw new TypeError('invalid encoding'); + } + } + + util.decodeUTF8 = function(s) { + if (typeof s !== 'string') throw new TypeError('expected string'); + var i, d = unescape(encodeURIComponent(s)), b = new Uint8Array(d.length); + for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); + return b; + }; + + util.encodeUTF8 = function(arr) { + var i, s = []; + for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i])); + return decodeURIComponent(escape(s.join(''))); + }; + + if (typeof atob === 'undefined') { + // Node.js + + if (typeof Buffer.from !== 'undefined') { + // Node v6 and later + util.encodeBase64 = function (arr) { // v6 and later + return Buffer.from(arr).toString('base64'); + }; + + util.decodeBase64 = function (s) { + validateBase64(s); + return new Uint8Array(Array.prototype.slice.call(Buffer.from(s, 'base64'), 0)); + }; + + } else { + // Node earlier than v6 + util.encodeBase64 = function (arr) { // v6 and later + return (new Buffer(arr)).toString('base64'); + }; + + util.decodeBase64 = function(s) { + validateBase64(s); + return new Uint8Array(Array.prototype.slice.call(new Buffer(s, 'base64'), 0)); + }; + } + + } else { + // Browsers + + util.encodeBase64 = function(arr) { + var i, s = [], len = arr.length; + for (i = 0; i < len; i++) s.push(String.fromCharCode(arr[i])); + return btoa(s.join('')); + }; + + util.decodeBase64 = function(s) { + validateBase64(s); + var i, d = atob(s), b = new Uint8Array(d.length); + for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); + return b; + }; + + } + + return util; + +})); + + +/***/ }), +/* 5 */ +/***/ (function(module, exports) { + +module.exports = require("crypto"); + +/***/ }), +/* 6 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +// Protocol references: +// +// * http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75 +// * http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76 +// * http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17 + +var Base = __webpack_require__(2), + Client = __webpack_require__(25), + Server = __webpack_require__(36); + +var Driver = { + client: function(url, options) { + options = options || {}; + if (options.masking === undefined) options.masking = true; + return new Client(url, options); + }, + + server: function(options) { + options = options || {}; + if (options.requireMasking === undefined) options.requireMasking = true; + return new Server(options); + }, + + http: function() { + return Server.http.apply(Server, arguments); + }, + + isSecureRequest: function(request) { + return Server.isSecureRequest(request); + }, + + isWebSocket: function(request) { + return Base.isWebSocket(request); + }, + + validateOptions: function(options, validKeys) { + Base.validateOptions(options, validKeys); + } +}; + +module.exports = Driver; + + +/***/ }), +/* 7 */ +/***/ (function(module, exports) { + +module.exports = require("stream"); + +/***/ }), +/* 8 */ +/***/ (function(module, exports) { + +module.exports = require("url"); + +/***/ }), +/* 9 */ +/***/ (function(module, exports) { + +var Event = function(eventType, options) { + this.type = eventType; + for (var key in options) + this[key] = options[key]; +}; + +Event.prototype.initEvent = function(eventType, canBubble, cancelable) { + this.type = eventType; + this.bubbles = canBubble; + this.cancelable = cancelable; +}; + +Event.prototype.stopPropagation = function() {}; +Event.prototype.preventDefault = function() {}; + +Event.CAPTURING_PHASE = 1; +Event.AT_TARGET = 2; +Event.BUBBLING_PHASE = 3; + +module.exports = Event; + + +/***/ }), +/* 10 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var Headers = function() { + this.clear(); +}; + +Headers.prototype.ALLOWED_DUPLICATES = ['set-cookie', 'set-cookie2', 'warning', 'www-authenticate']; + +Headers.prototype.clear = function() { + this._sent = {}; + this._lines = []; +}; + +Headers.prototype.set = function(name, value) { + if (value === undefined) return; + + name = this._strip(name); + value = this._strip(value); + + var key = name.toLowerCase(); + if (!this._sent.hasOwnProperty(key) || this.ALLOWED_DUPLICATES.indexOf(key) >= 0) { + this._sent[key] = true; + this._lines.push(name + ': ' + value + '\r\n'); + } +}; + +Headers.prototype.toString = function() { + return this._lines.join(''); +}; + +Headers.prototype._strip = function(string) { + return string.toString().replace(/^ */, '').replace(/ *$/, ''); +}; + +module.exports = Headers; + + +/***/ }), +/* 11 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var NodeHTTPParser = __webpack_require__(26).HTTPParser, + Buffer = __webpack_require__(1).Buffer; + +var TYPES = { + request: NodeHTTPParser.REQUEST || 'request', + response: NodeHTTPParser.RESPONSE || 'response' +}; + +var HttpParser = function(type) { + this._type = type; + this._parser = new NodeHTTPParser(TYPES[type]); + this._complete = false; + this.headers = {}; + + var current = null, + self = this; + + this._parser.onHeaderField = function(b, start, length) { + current = b.toString('utf8', start, start + length).toLowerCase(); + }; + + this._parser.onHeaderValue = function(b, start, length) { + var value = b.toString('utf8', start, start + length); + + if (self.headers.hasOwnProperty(current)) + self.headers[current] += ', ' + value; + else + self.headers[current] = value; + }; + + this._parser.onHeadersComplete = this._parser[NodeHTTPParser.kOnHeadersComplete] = + function(majorVersion, minorVersion, headers, method, pathname, statusCode) { + var info = arguments[0]; + + if (typeof info === 'object') { + method = info.method; + pathname = info.url; + statusCode = info.statusCode; + headers = info.headers; + } + + self.method = (typeof method === 'number') ? HttpParser.METHODS[method] : method; + self.statusCode = statusCode; + self.url = pathname; + + if (!headers) return; + + for (var i = 0, n = headers.length, key, value; i < n; i += 2) { + key = headers[i].toLowerCase(); + value = headers[i+1]; + if (self.headers.hasOwnProperty(key)) + self.headers[key] += ', ' + value; + else + self.headers[key] = value; + } + + self._complete = true; + }; +}; + +HttpParser.METHODS = { + 0: 'DELETE', + 1: 'GET', + 2: 'HEAD', + 3: 'POST', + 4: 'PUT', + 5: 'CONNECT', + 6: 'OPTIONS', + 7: 'TRACE', + 8: 'COPY', + 9: 'LOCK', + 10: 'MKCOL', + 11: 'MOVE', + 12: 'PROPFIND', + 13: 'PROPPATCH', + 14: 'SEARCH', + 15: 'UNLOCK', + 16: 'BIND', + 17: 'REBIND', + 18: 'UNBIND', + 19: 'ACL', + 20: 'REPORT', + 21: 'MKACTIVITY', + 22: 'CHECKOUT', + 23: 'MERGE', + 24: 'M-SEARCH', + 25: 'NOTIFY', + 26: 'SUBSCRIBE', + 27: 'UNSUBSCRIBE', + 28: 'PATCH', + 29: 'PURGE', + 30: 'MKCALENDAR', + 31: 'LINK', + 32: 'UNLINK' +}; + +var VERSION = (process.version || '') + .match(/[0-9]+/g) + .map(function(n) { return parseInt(n, 10) }); + +if (VERSION[0] === 0 && VERSION[1] === 12) { + HttpParser.METHODS[16] = 'REPORT'; + HttpParser.METHODS[17] = 'MKACTIVITY'; + HttpParser.METHODS[18] = 'CHECKOUT'; + HttpParser.METHODS[19] = 'MERGE'; + HttpParser.METHODS[20] = 'M-SEARCH'; + HttpParser.METHODS[21] = 'NOTIFY'; + HttpParser.METHODS[22] = 'SUBSCRIBE'; + HttpParser.METHODS[23] = 'UNSUBSCRIBE'; + HttpParser.METHODS[24] = 'PATCH'; + HttpParser.METHODS[25] = 'PURGE'; +} + +HttpParser.prototype.isComplete = function() { + return this._complete; +}; + +HttpParser.prototype.parse = function(chunk) { + var consumed = this._parser.execute(chunk, 0, chunk.length); + + if (typeof consumed !== 'number') { + this.error = consumed; + this._complete = true; + return; + } + + if (this._complete) + this.body = (consumed < chunk.length) + ? chunk.slice(consumed) + : Buffer.alloc(0); +}; + +module.exports = HttpParser; + + +/***/ }), +/* 12 */ +/***/ (function(module, exports, __webpack_require__) { + +var Stream = __webpack_require__(7).Stream, + util = __webpack_require__(0), + driver = __webpack_require__(6), + EventTarget = __webpack_require__(17), + Event = __webpack_require__(9); + +var API = function(options) { + options = options || {}; + driver.validateOptions(options, ['headers', 'extensions', 'maxLength', 'ping', 'proxy', 'tls', 'ca']); + + this.readable = this.writable = true; + + var headers = options.headers; + if (headers) { + for (var name in headers) this._driver.setHeader(name, headers[name]); + } + + var extensions = options.extensions; + if (extensions) { + [].concat(extensions).forEach(this._driver.addExtension, this._driver); + } + + this._ping = options.ping; + this._pingId = 0; + this.readyState = API.CONNECTING; + this.bufferedAmount = 0; + this.protocol = ''; + this.url = this._driver.url; + this.version = this._driver.version; + + var self = this; + + this._driver.on('open', function(e) { self._open() }); + this._driver.on('message', function(e) { self._receiveMessage(e.data) }); + this._driver.on('close', function(e) { self._beginClose(e.reason, e.code) }); + + this._driver.on('error', function(error) { + self._emitError(error.message); + }); + this.on('error', function() {}); + + this._driver.messages.on('drain', function() { + self.emit('drain'); + }); + + if (this._ping) + this._pingTimer = setInterval(function() { + self._pingId += 1; + self.ping(self._pingId.toString()); + }, this._ping * 1000); + + this._configureStream(); + + if (!this._proxy) { + this._stream.pipe(this._driver.io); + this._driver.io.pipe(this._stream); + } +}; +util.inherits(API, Stream); + +API.CONNECTING = 0; +API.OPEN = 1; +API.CLOSING = 2; +API.CLOSED = 3; + +var instance = { + write: function(data) { + return this.send(data); + }, + + end: function(data) { + if (data !== undefined) this.send(data); + this.close(); + }, + + pause: function() { + return this._driver.messages.pause(); + }, + + resume: function() { + return this._driver.messages.resume(); + }, + + send: function(data) { + if (this.readyState > API.OPEN) return false; + if (!(data instanceof Buffer)) data = String(data); + return this._driver.messages.write(data); + }, + + ping: function(message, callback) { + if (this.readyState > API.OPEN) return false; + return this._driver.ping(message, callback); + }, + + close: function() { + if (this.readyState !== API.CLOSED) this.readyState = API.CLOSING; + this._driver.close(); + }, - // first car - c = 1; - v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; - v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; - v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; - v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; - v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; - v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; - v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; - v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; - v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; - v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; - v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; - v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; - v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; - v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; - v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; - v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; - t0 += c-1 + 37 * (c-1); + _configureStream: function() { + var self = this; + + this._stream.setTimeout(0); + this._stream.setNoDelay(true); + + ['close', 'end'].forEach(function(event) { + this._stream.on(event, function() { self._finalizeClose() }); + }, this); + + this._stream.on('error', function(error) { + self._emitError('Network error: ' + self.url + ': ' + error.message); + self._finalizeClose(); + }); + }, + + _open: function() { + if (this.readyState !== API.CONNECTING) return; + + this.readyState = API.OPEN; + this.protocol = this._driver.protocol || ''; + + var event = new Event('open'); + event.initEvent('open', false, false); + this.dispatchEvent(event); + }, + + _receiveMessage: function(data) { + if (this.readyState > API.OPEN) return false; + + if (this.readable) this.emit('data', data); + + var event = new Event('message', {data: data}); + event.initEvent('message', false, false); + this.dispatchEvent(event); + }, + + _emitError: function(message) { + if (this.readyState >= API.CLOSING) return; + + var event = new Event('error', {message: message}); + event.initEvent('error', false, false); + this.dispatchEvent(event); + }, + + _beginClose: function(reason, code) { + if (this.readyState === API.CLOSED) return; + this.readyState = API.CLOSING; + + if (this._stream) { + this._stream.end(); + if (!this._stream.readable) this._finalizeClose(); + } + this._closeParams = [reason, code]; + }, + + _finalizeClose: function() { + if (this.readyState === API.CLOSED) return; + this.readyState = API.CLOSED; + + if (this._pingTimer) clearInterval(this._pingTimer); + if (this._stream) this._stream.end(); + + if (this.readable) this.emit('end'); + this.readable = this.writable = false; + + var reason = this._closeParams ? this._closeParams[0] : '', + code = this._closeParams ? this._closeParams[1] : 1006; + + var event = new Event('close', {code: code, reason: reason}); + event.initEvent('close', false, false); + this.dispatchEvent(event); + } +}; + +for (var method in instance) API.prototype[method] = instance[method]; +for (var key in EventTarget) API.prototype[key] = EventTarget[key]; + +module.exports = API; + + +/***/ }), +/* 13 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var Buffer = __webpack_require__(1).Buffer, + crypto = __webpack_require__(5), + util = __webpack_require__(0), + Extensions = __webpack_require__(28), + Base = __webpack_require__(2), + Frame = __webpack_require__(33), + Message = __webpack_require__(34); + +var Hybi = function(request, url, options) { + Base.apply(this, arguments); + + this._extensions = new Extensions(); + this._stage = 0; + this._masking = this._options.masking; + this._protocols = this._options.protocols || []; + this._requireMasking = this._options.requireMasking; + this._pingCallbacks = {}; + + if (typeof this._protocols === 'string') + this._protocols = this._protocols.split(/ *, */); + + if (!this._request) return; + + var protos = this._request.headers['sec-websocket-protocol'], + supported = this._protocols; + + if (protos !== undefined) { + if (typeof protos === 'string') protos = protos.split(/ *, */); + this.protocol = protos.filter(function(p) { return supported.indexOf(p) >= 0 })[0]; + } + + this.version = 'hybi-' + Hybi.VERSION; +}; +util.inherits(Hybi, Base); + +Hybi.VERSION = '13'; + +Hybi.mask = function(payload, mask, offset) { + if (!mask || mask.length === 0) return payload; + offset = offset || 0; + + for (var i = 0, n = payload.length - offset; i < n; i++) { + payload[offset + i] = payload[offset + i] ^ mask[i % 4]; + } + return payload; +}; + +Hybi.generateAccept = function(key) { + var sha1 = crypto.createHash('sha1'); + sha1.update(key + Hybi.GUID); + return sha1.digest('base64'); +}; + +Hybi.GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'; + +var instance = { + FIN: 0x80, + MASK: 0x80, + RSV1: 0x40, + RSV2: 0x20, + RSV3: 0x10, + OPCODE: 0x0F, + LENGTH: 0x7F, + + OPCODES: { + continuation: 0, + text: 1, + binary: 2, + close: 8, + ping: 9, + pong: 10 + }, + + OPCODE_CODES: [0, 1, 2, 8, 9, 10], + MESSAGE_OPCODES: [0, 1, 2], + OPENING_OPCODES: [1, 2], + + ERRORS: { + normal_closure: 1000, + going_away: 1001, + protocol_error: 1002, + unacceptable: 1003, + encoding_error: 1007, + policy_violation: 1008, + too_large: 1009, + extension_error: 1010, + unexpected_condition: 1011 + }, + + ERROR_CODES: [1000, 1001, 1002, 1003, 1007, 1008, 1009, 1010, 1011], + DEFAULT_ERROR_CODE: 1000, + MIN_RESERVED_ERROR: 3000, + MAX_RESERVED_ERROR: 4999, + + // http://www.w3.org/International/questions/qa-forms-utf-8.en.php + UTF8_MATCH: /^([\x00-\x7F]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$/, + + addExtension: function(extension) { + this._extensions.add(extension); + return true; + }, + + parse: function(chunk) { + this._reader.put(chunk); + var buffer = true; + while (buffer) { + switch (this._stage) { + case 0: + buffer = this._reader.read(1); + if (buffer) this._parseOpcode(buffer[0]); + break; + + case 1: + buffer = this._reader.read(1); + if (buffer) this._parseLength(buffer[0]); + break; + + case 2: + buffer = this._reader.read(this._frame.lengthBytes); + if (buffer) this._parseExtendedLength(buffer); + break; + + case 3: + buffer = this._reader.read(4); + if (buffer) { + this._stage = 4; + this._frame.maskingKey = buffer; + } + break; + + case 4: + buffer = this._reader.read(this._frame.length); + if (buffer) { + this._stage = 0; + this._emitFrame(buffer); + } + break; - // second car - c = 1; - v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; - v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; - v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; - v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; - v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; - v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; - v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; - v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; - v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; - v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; - v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; - v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; - v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; - v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; - v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; - v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; - t0 += c-1 + 37 * (c-1); + default: + buffer = null; + } + } + }, - o[ 0] = t0; - o[ 1] = t1; - o[ 2] = t2; - o[ 3] = t3; - o[ 4] = t4; - o[ 5] = t5; - o[ 6] = t6; - o[ 7] = t7; - o[ 8] = t8; - o[ 9] = t9; - o[10] = t10; - o[11] = t11; - o[12] = t12; - o[13] = t13; - o[14] = t14; - o[15] = t15; -} + text: function(message) { + if (this.readyState > 1) return false; + return this.frame(message, 'text'); + }, -function S(o, a) { - M(o, a, a); -} + binary: function(message) { + if (this.readyState > 1) return false; + return this.frame(message, 'binary'); + }, -function inv25519(o, i) { - var c = gf(); - var a; - for (a = 0; a < 16; a++) c[a] = i[a]; - for (a = 253; a >= 0; a--) { - S(c, c); - if(a !== 2 && a !== 4) M(c, c, i); - } - for (a = 0; a < 16; a++) o[a] = c[a]; -} + ping: function(message, callback) { + if (this.readyState > 1) return false; + message = message || ''; + if (callback) this._pingCallbacks[message] = callback; + return this.frame(message, 'ping'); + }, -function pow2523(o, i) { - var c = gf(); - var a; - for (a = 0; a < 16; a++) c[a] = i[a]; - for (a = 250; a >= 0; a--) { - S(c, c); - if(a !== 1) M(c, c, i); - } - for (a = 0; a < 16; a++) o[a] = c[a]; -} + pong: function(message) { + if (this.readyState > 1) return false; + message = message ||''; + return this.frame(message, 'pong'); + }, -function crypto_scalarmult(q, n, p) { - var z = new Uint8Array(32); - var x = new Float64Array(80), r, i; - var a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(); - for (i = 0; i < 31; i++) z[i] = n[i]; - z[31]=(n[31]&127)|64; - z[0]&=248; - unpack25519(x,p); - for (i = 0; i < 16; i++) { - b[i]=x[i]; - d[i]=a[i]=c[i]=0; - } - a[0]=d[0]=1; - for (i=254; i>=0; --i) { - r=(z[i>>>3]>>>(i&7))&1; - sel25519(a,b,r); - sel25519(c,d,r); - A(e,a,c); - Z(a,a,c); - A(c,b,d); - Z(b,b,d); - S(d,e); - S(f,a); - M(a,c,a); - M(c,b,e); - A(e,a,c); - Z(a,a,c); - S(b,a); - Z(c,d,f); - M(a,c,_121665); - A(a,a,d); - M(c,c,a); - M(a,d,f); - M(d,b,x); - S(b,e); - sel25519(a,b,r); - sel25519(c,d,r); - } - for (i = 0; i < 16; i++) { - x[i+16]=a[i]; - x[i+32]=c[i]; - x[i+48]=b[i]; - x[i+64]=d[i]; - } - var x32 = x.subarray(32); - var x16 = x.subarray(16); - inv25519(x32,x32); - M(x16,x16,x32); - pack25519(q,x16); - return 0; -} + close: function(reason, code) { + reason = reason || ''; + code = code || this.ERRORS.normal_closure; -function crypto_scalarmult_base(q, n) { - return crypto_scalarmult(q, n, _9); -} + if (this.readyState <= 0) { + this.readyState = 3; + this.emit('close', new Base.CloseEvent(code, reason)); + return true; + } else if (this.readyState === 1) { + this.readyState = 2; + this._extensions.close(function() { this.frame(reason, 'close', code) }, this); + return true; + } else { + return false; + } + }, -function crypto_box_keypair(y, x) { - randombytes(x, 32); - return crypto_scalarmult_base(y, x); -} + frame: function(buffer, type, code) { + if (this.readyState <= 0) return this._queue([buffer, type, code]); + if (this.readyState > 2) return false; -function crypto_box_beforenm(k, y, x) { - var s = new Uint8Array(32); - crypto_scalarmult(s, x, y); - return crypto_core_hsalsa20(k, _0, s, sigma); -} + if (buffer instanceof Array) buffer = Buffer.from(buffer); + if (typeof buffer === 'number') buffer = buffer.toString(); -var crypto_box_afternm = crypto_secretbox; -var crypto_box_open_afternm = crypto_secretbox_open; + var message = new Message(), + isText = (typeof buffer === 'string'), + payload, copy; -function crypto_box(c, m, d, n, y, x) { - var k = new Uint8Array(32); - crypto_box_beforenm(k, y, x); - return crypto_box_afternm(c, m, d, n, k); -} + message.rsv1 = message.rsv2 = message.rsv3 = false; + message.opcode = this.OPCODES[type || (isText ? 'text' : 'binary')]; -function crypto_box_open(m, c, d, n, y, x) { - var k = new Uint8Array(32); - crypto_box_beforenm(k, y, x); - return crypto_box_open_afternm(m, c, d, n, k); -} + payload = isText ? Buffer.from(buffer, 'utf8') : buffer; -var K = [ - 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, - 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, - 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, - 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, - 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, - 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, - 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, - 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, - 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, - 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, - 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, - 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, - 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, - 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, - 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, - 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, - 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, - 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, - 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, - 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, - 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, - 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, - 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, - 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, - 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, - 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, - 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, - 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, - 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, - 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, - 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, - 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, - 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, - 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, - 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, - 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, - 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, - 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, - 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, - 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 -]; + if (code) { + copy = payload; + payload = Buffer.allocUnsafe(2 + copy.length); + payload.writeUInt16BE(code, 0); + copy.copy(payload, 2); + } + message.data = payload; -function crypto_hashblocks_hl(hh, hl, m, n) { - var wh = new Int32Array(16), wl = new Int32Array(16), - bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, - bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, - th, tl, i, j, h, l, a, b, c, d; + var onMessageReady = function(message) { + var frame = new Frame(); + + frame.final = true; + frame.rsv1 = message.rsv1; + frame.rsv2 = message.rsv2; + frame.rsv3 = message.rsv3; + frame.opcode = message.opcode; + frame.masked = !!this._masking; + frame.length = message.data.length; + frame.payload = message.data; + + if (frame.masked) frame.maskingKey = crypto.randomBytes(4); - var ah0 = hh[0], - ah1 = hh[1], - ah2 = hh[2], - ah3 = hh[3], - ah4 = hh[4], - ah5 = hh[5], - ah6 = hh[6], - ah7 = hh[7], + this._sendFrame(frame); + }; - al0 = hl[0], - al1 = hl[1], - al2 = hl[2], - al3 = hl[3], - al4 = hl[4], - al5 = hl[5], - al6 = hl[6], - al7 = hl[7]; + if (this.MESSAGE_OPCODES.indexOf(message.opcode) >= 0) + this._extensions.processOutgoingMessage(message, function(error, message) { + if (error) return this._fail('extension_error', error.message); + onMessageReady.call(this, message); + }, this); + else + onMessageReady.call(this, message); - var pos = 0; - while (n >= 128) { - for (i = 0; i < 16; i++) { - j = 8 * i + pos; - wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3]; - wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7]; - } - for (i = 0; i < 80; i++) { - bh0 = ah0; - bh1 = ah1; - bh2 = ah2; - bh3 = ah3; - bh4 = ah4; - bh5 = ah5; - bh6 = ah6; - bh7 = ah7; + return true; + }, - bl0 = al0; - bl1 = al1; - bl2 = al2; - bl3 = al3; - bl4 = al4; - bl5 = al5; - bl6 = al6; - bl7 = al7; + _sendFrame: function(frame) { + var length = frame.length, + header = (length <= 125) ? 2 : (length <= 65535 ? 4 : 10), + offset = header + (frame.masked ? 4 : 0), + buffer = Buffer.allocUnsafe(offset + length), + masked = frame.masked ? this.MASK : 0; - // add - h = ah7; - l = al7; + buffer[0] = (frame.final ? this.FIN : 0) | + (frame.rsv1 ? this.RSV1 : 0) | + (frame.rsv2 ? this.RSV2 : 0) | + (frame.rsv3 ? this.RSV3 : 0) | + frame.opcode; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + if (length <= 125) { + buffer[1] = masked | length; + } else if (length <= 65535) { + buffer[1] = masked | 126; + buffer.writeUInt16BE(length, 2); + } else { + buffer[1] = masked | 127; + buffer.writeUInt32BE(Math.floor(length / 0x100000000), 2); + buffer.writeUInt32BE(length % 0x100000000, 6); + } - // Sigma1 - h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32)))); - l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32)))); + frame.payload.copy(buffer, offset); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + if (frame.masked) { + frame.maskingKey.copy(buffer, header); + Hybi.mask(buffer, frame.maskingKey, offset); + } - // Ch - h = (ah4 & ah5) ^ (~ah4 & ah6); - l = (al4 & al5) ^ (~al4 & al6); + this._write(buffer); + }, - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + _handshakeResponse: function() { + var secKey = this._request.headers['sec-websocket-key'], + version = this._request.headers['sec-websocket-version']; - // K - h = K[i*2]; - l = K[i*2+1]; + if (version !== Hybi.VERSION) + throw new Error('Unsupported WebSocket version: ' + version); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + if (typeof secKey !== 'string') + throw new Error('Missing handshake request header: Sec-WebSocket-Key'); - // w - h = wh[i%16]; - l = wl[i%16]; + this._headers.set('Upgrade', 'websocket'); + this._headers.set('Connection', 'Upgrade'); + this._headers.set('Sec-WebSocket-Accept', Hybi.generateAccept(secKey)); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + if (this.protocol) this._headers.set('Sec-WebSocket-Protocol', this.protocol); - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + var extensions = this._extensions.generateResponse(this._request.headers['sec-websocket-extensions']); + if (extensions) this._headers.set('Sec-WebSocket-Extensions', extensions); - th = c & 0xffff | d << 16; - tl = a & 0xffff | b << 16; + var start = 'HTTP/1.1 101 Switching Protocols', + headers = [start, this._headers.toString(), '']; - // add - h = th; - l = tl; + return Buffer.from(headers.join('\r\n'), 'utf8'); + }, - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + _shutdown: function(code, reason, error) { + delete this._frame; + delete this._message; + this._stage = 5; - // Sigma0 - h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32)))); - l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32)))); + var sendCloseFrame = (this.readyState === 1); + this.readyState = 2; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + this._extensions.close(function() { + if (sendCloseFrame) this.frame(reason, 'close', code); + this.readyState = 3; + if (error) this.emit('error', new Error(reason)); + this.emit('close', new Base.CloseEvent(code, reason)); + }, this); + }, - // Maj - h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); - l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2); + _fail: function(type, message) { + if (this.readyState > 1) return; + this._shutdown(this.ERRORS[type], message, true); + }, - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + _parseOpcode: function(octet) { + var rsvs = [this.RSV1, this.RSV2, this.RSV3].map(function(rsv) { + return (octet & rsv) === rsv; + }); - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + var frame = this._frame = new Frame(); - bh7 = (c & 0xffff) | (d << 16); - bl7 = (a & 0xffff) | (b << 16); + frame.final = (octet & this.FIN) === this.FIN; + frame.rsv1 = rsvs[0]; + frame.rsv2 = rsvs[1]; + frame.rsv3 = rsvs[2]; + frame.opcode = (octet & this.OPCODE); - // add - h = bh3; - l = bl3; + this._stage = 1; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + if (!this._extensions.validFrameRsv(frame)) + return this._fail('protocol_error', + 'One or more reserved bits are on: reserved1 = ' + (frame.rsv1 ? 1 : 0) + + ', reserved2 = ' + (frame.rsv2 ? 1 : 0) + + ', reserved3 = ' + (frame.rsv3 ? 1 : 0)); - h = th; - l = tl; + if (this.OPCODE_CODES.indexOf(frame.opcode) < 0) + return this._fail('protocol_error', 'Unrecognized frame opcode: ' + frame.opcode); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + if (this.MESSAGE_OPCODES.indexOf(frame.opcode) < 0 && !frame.final) + return this._fail('protocol_error', 'Received fragmented control frame: opcode = ' + frame.opcode); - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + if (this._message && this.OPENING_OPCODES.indexOf(frame.opcode) >= 0) + return this._fail('protocol_error', 'Received new data frame but previous continuous frame is unfinished'); + }, - bh3 = (c & 0xffff) | (d << 16); - bl3 = (a & 0xffff) | (b << 16); + _parseLength: function(octet) { + var frame = this._frame; + frame.masked = (octet & this.MASK) === this.MASK; + frame.length = (octet & this.LENGTH); - ah1 = bh0; - ah2 = bh1; - ah3 = bh2; - ah4 = bh3; - ah5 = bh4; - ah6 = bh5; - ah7 = bh6; - ah0 = bh7; + if (frame.length >= 0 && frame.length <= 125) { + this._stage = frame.masked ? 3 : 4; + if (!this._checkFrameLength()) return; + } else { + this._stage = 2; + frame.lengthBytes = (frame.length === 126 ? 2 : 8); + } - al1 = bl0; - al2 = bl1; - al3 = bl2; - al4 = bl3; - al5 = bl4; - al6 = bl5; - al7 = bl6; - al0 = bl7; + if (this._requireMasking && !frame.masked) + return this._fail('unacceptable', 'Received unmasked frame but masking is required'); + }, - if (i%16 === 15) { - for (j = 0; j < 16; j++) { - // add - h = wh[j]; - l = wl[j]; + _parseExtendedLength: function(buffer) { + var frame = this._frame; + frame.length = this._readUInt(buffer); - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + this._stage = frame.masked ? 3 : 4; - h = wh[(j+9)%16]; - l = wl[(j+9)%16]; + if (this.MESSAGE_OPCODES.indexOf(frame.opcode) < 0 && frame.length > 125) + return this._fail('protocol_error', 'Received control frame having too long payload: ' + frame.length); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + if (!this._checkFrameLength()) return; + }, - // sigma0 - th = wh[(j+1)%16]; - tl = wl[(j+1)%16]; - h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7); - l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7))); + _checkFrameLength: function() { + var length = this._message ? this._message.length : 0; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + if (length + this._frame.length > this._maxLength) { + this._fail('too_large', 'WebSocket frame length too large'); + return false; + } else { + return true; + } + }, - // sigma1 - th = wh[(j+14)%16]; - tl = wl[(j+14)%16]; - h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6); - l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6))); + _emitFrame: function(buffer) { + var frame = this._frame, + payload = frame.payload = Hybi.mask(buffer, frame.maskingKey), + opcode = frame.opcode, + message, + code, reason, + callbacks, callback; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + delete this._frame; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + if (opcode === this.OPCODES.continuation) { + if (!this._message) return this._fail('protocol_error', 'Received unexpected continuation frame'); + this._message.pushFrame(frame); + } - wh[j] = (c & 0xffff) | (d << 16); - wl[j] = (a & 0xffff) | (b << 16); - } - } + if (opcode === this.OPCODES.text || opcode === this.OPCODES.binary) { + this._message = new Message(); + this._message.pushFrame(frame); } - // add - h = ah0; - l = al0; + if (frame.final && this.MESSAGE_OPCODES.indexOf(opcode) >= 0) + return this._emitMessage(this._message); - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + if (opcode === this.OPCODES.close) { + code = (payload.length >= 2) ? payload.readUInt16BE(0) : null; + reason = (payload.length > 2) ? this._encode(payload.slice(2)) : null; - h = hh[0]; - l = hl[0]; + if (!(payload.length === 0) && + !(code !== null && code >= this.MIN_RESERVED_ERROR && code <= this.MAX_RESERVED_ERROR) && + this.ERROR_CODES.indexOf(code) < 0) + code = this.ERRORS.protocol_error; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + if (payload.length > 125 || (payload.length > 2 && !reason)) + code = this.ERRORS.protocol_error; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + this._shutdown(code || this.DEFAULT_ERROR_CODE, reason || ''); + } - hh[0] = ah0 = (c & 0xffff) | (d << 16); - hl[0] = al0 = (a & 0xffff) | (b << 16); + if (opcode === this.OPCODES.ping) { + this.frame(payload, 'pong'); + this.emit('ping', new Base.PingEvent(payload.toString())) + } - h = ah1; - l = al1; + if (opcode === this.OPCODES.pong) { + callbacks = this._pingCallbacks; + message = this._encode(payload); + callback = callbacks[message]; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + delete callbacks[message]; + if (callback) callback() - h = hh[1]; - l = hl[1]; + this.emit('pong', new Base.PongEvent(payload.toString())) + } + }, - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + _emitMessage: function(message) { + var message = this._message; + message.read(); - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + delete this._message; - hh[1] = ah1 = (c & 0xffff) | (d << 16); - hl[1] = al1 = (a & 0xffff) | (b << 16); + this._extensions.processIncomingMessage(message, function(error, message) { + if (error) return this._fail('extension_error', error.message); - h = ah2; - l = al2; + var payload = message.data; + if (message.opcode === this.OPCODES.text) payload = this._encode(payload); - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + if (payload === null) + return this._fail('encoding_error', 'Could not decode a text frame as UTF-8'); + else + this.emit('message', new Base.MessageEvent(payload)); + }, this); + }, - h = hh[2]; - l = hl[2]; + _encode: function(buffer) { + try { + var string = buffer.toString('binary', 0, buffer.length); + if (!this.UTF8_MATCH.test(string)) return null; + } catch (e) {} + return buffer.toString('utf8', 0, buffer.length); + }, - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + _readUInt: function(buffer) { + if (buffer.length === 2) return buffer.readUInt16BE(0); - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + return buffer.readUInt32BE(0) * 0x100000000 + + buffer.readUInt32BE(4); + } +}; - hh[2] = ah2 = (c & 0xffff) | (d << 16); - hl[2] = al2 = (a & 0xffff) | (b << 16); +for (var key in instance) + Hybi.prototype[key] = instance[key]; - h = ah3; - l = al3; +module.exports = Hybi; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - h = hh[3]; - l = hl[3]; +/***/ }), +/* 14 */ +/***/ (function(module, exports, __webpack_require__) { - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +"use strict"; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - hh[3] = ah3 = (c & 0xffff) | (d << 16); - hl[3] = al3 = (a & 0xffff) | (b << 16); +var RingBuffer = function(bufferSize) { + this._bufferSize = bufferSize; + this.clear(); +}; - h = ah4; - l = al4; +RingBuffer.prototype.clear = function() { + this._buffer = new Array(this._bufferSize); + this._ringOffset = 0; + this._ringSize = this._bufferSize; + this._head = 0; + this._tail = 0; + this.length = 0; +}; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +RingBuffer.prototype.push = function(value) { + var expandBuffer = false, + expandRing = false; - h = hh[4]; - l = hl[4]; + if (this._ringSize < this._bufferSize) { + expandBuffer = (this._tail === 0); + } else if (this._ringOffset === this._ringSize) { + expandBuffer = true; + expandRing = (this._tail === 0); + } - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + if (expandBuffer) { + this._tail = this._bufferSize; + this._buffer = this._buffer.concat(new Array(this._bufferSize)); + this._bufferSize = this._buffer.length; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + if (expandRing) + this._ringSize = this._bufferSize; + } - hh[4] = ah4 = (c & 0xffff) | (d << 16); - hl[4] = al4 = (a & 0xffff) | (b << 16); + this._buffer[this._tail] = value; + this.length += 1; + if (this._tail < this._ringSize) this._ringOffset += 1; + this._tail = (this._tail + 1) % this._bufferSize; +}; - h = ah5; - l = al5; +RingBuffer.prototype.peek = function() { + if (this.length === 0) return void 0; + return this._buffer[this._head]; +}; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +RingBuffer.prototype.shift = function() { + if (this.length === 0) return void 0; - h = hh[5]; - l = hl[5]; + var value = this._buffer[this._head]; + this._buffer[this._head] = void 0; + this.length -= 1; + this._ringOffset -= 1; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + if (this._ringOffset === 0 && this.length > 0) { + this._head = this._ringSize; + this._ringOffset = this.length; + this._ringSize = this._bufferSize; + } else { + this._head = (this._head + 1) % this._ringSize; + } + return value; +}; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +module.exports = RingBuffer; - hh[5] = ah5 = (c & 0xffff) | (d << 16); - hl[5] = al5 = (a & 0xffff) | (b << 16); - h = ah6; - l = al6; +/***/ }), +/* 15 */ +/***/ (function(module, exports, __webpack_require__) { - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +"use strict"; - h = hh[6]; - l = hl[6]; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +var RingBuffer = __webpack_require__(14); - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +var Pledge = function() { + this._complete = false; + this._callbacks = new RingBuffer(Pledge.QUEUE_SIZE); +}; - hh[6] = ah6 = (c & 0xffff) | (d << 16); - hl[6] = al6 = (a & 0xffff) | (b << 16); +Pledge.QUEUE_SIZE = 4; + +Pledge.all = function(list) { + var pledge = new Pledge(), + pending = list.length, + n = pending; - h = ah7; - l = al7; + if (pending === 0) pledge.done(); - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + while (n--) list[n].then(function() { + pending -= 1; + if (pending === 0) pledge.done(); + }); + return pledge; +}; - h = hh[7]; - l = hl[7]; +Pledge.prototype.then = function(callback) { + if (this._complete) callback(); + else this._callbacks.push(callback); +}; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +Pledge.prototype.done = function() { + this._complete = true; + var callbacks = this._callbacks, callback; + while (callback = callbacks.shift()) callback(); +}; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +module.exports = Pledge; - hh[7] = ah7 = (c & 0xffff) | (d << 16); - hl[7] = al7 = (a & 0xffff) | (b << 16); - pos += 128; - n -= 128; - } +/***/ }), +/* 16 */ +/***/ (function(module, exports, __webpack_require__) { - return n; -} +"use strict"; -function crypto_hash(out, m, n) { - var hh = new Int32Array(8), - hl = new Int32Array(8), - x = new Uint8Array(256), - i, b = n; - hh[0] = 0x6a09e667; - hh[1] = 0xbb67ae85; - hh[2] = 0x3c6ef372; - hh[3] = 0xa54ff53a; - hh[4] = 0x510e527f; - hh[5] = 0x9b05688c; - hh[6] = 0x1f83d9ab; - hh[7] = 0x5be0cd19; +var Buffer = __webpack_require__(1).Buffer, + Base = __webpack_require__(2), + util = __webpack_require__(0); - hl[0] = 0xf3bcc908; - hl[1] = 0x84caa73b; - hl[2] = 0xfe94f82b; - hl[3] = 0x5f1d36f1; - hl[4] = 0xade682d1; - hl[5] = 0x2b3e6c1f; - hl[6] = 0xfb41bd6b; - hl[7] = 0x137e2179; +var Draft75 = function(request, url, options) { + Base.apply(this, arguments); + this._stage = 0; + this.version = 'hixie-75'; - crypto_hashblocks_hl(hh, hl, m, n); - n %= 128; + this._headers.set('Upgrade', 'WebSocket'); + this._headers.set('Connection', 'Upgrade'); + this._headers.set('WebSocket-Origin', this._request.headers.origin); + this._headers.set('WebSocket-Location', this.url); +}; +util.inherits(Draft75, Base); - for (i = 0; i < n; i++) x[i] = m[b-n+i]; - x[n] = 128; +var instance = { + close: function() { + if (this.readyState === 3) return false; + this.readyState = 3; + this.emit('close', new Base.CloseEvent(null, null)); + return true; + }, - n = 256-128*(n<112?1:0); - x[n-9] = 0; - ts64(x, n-8, (b / 0x20000000) | 0, b << 3); - crypto_hashblocks_hl(hh, hl, x, n); + parse: function(chunk) { + if (this.readyState > 1) return; - for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); + this._reader.put(chunk); - return 0; -} + this._reader.eachByte(function(octet) { + var message; -function add(p, q) { - var a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(), - g = gf(), h = gf(), t = gf(); + switch (this._stage) { + case -1: + this._body.push(octet); + this._sendHandshakeBody(); + break; - Z(a, p[1], p[0]); - Z(t, q[1], q[0]); - M(a, a, t); - A(b, p[0], p[1]); - A(t, q[0], q[1]); - M(b, b, t); - M(c, p[3], q[3]); - M(c, c, D2); - M(d, p[2], q[2]); - A(d, d, d); - Z(e, b, a); - Z(f, d, c); - A(g, d, c); - A(h, b, a); + case 0: + this._parseLeadingByte(octet); + break; - M(p[0], e, f); - M(p[1], h, g); - M(p[2], g, f); - M(p[3], e, h); -} + case 1: + this._length = (octet & 0x7F) + 128 * this._length; -function cswap(p, q, b) { - var i; - for (i = 0; i < 4; i++) { - sel25519(p[i], q[i], b); - } -} + if (this._closing && this._length === 0) { + return this.close(); + } + else if ((octet & 0x80) !== 0x80) { + if (this._length === 0) { + this._stage = 0; + } + else { + this._skipped = 0; + this._stage = 2; + } + } + break; -function pack(r, p) { - var tx = gf(), ty = gf(), zi = gf(); - inv25519(zi, p[2]); - M(tx, p[0], zi); - M(ty, p[1], zi); - pack25519(r, ty); - r[31] ^= par25519(tx) << 7; -} + case 2: + if (octet === 0xFF) { + this._stage = 0; + message = Buffer.from(this._buffer).toString('utf8', 0, this._buffer.length); + this.emit('message', new Base.MessageEvent(message)); + } + else { + if (this._length) { + this._skipped += 1; + if (this._skipped === this._length) + this._stage = 0; + } else { + this._buffer.push(octet); + if (this._buffer.length > this._maxLength) return this.close(); + } + } + break; + } + }, this); + }, -function scalarmult(p, q, s) { - var b, i; - set25519(p[0], gf0); - set25519(p[1], gf1); - set25519(p[2], gf1); - set25519(p[3], gf0); - for (i = 255; i >= 0; --i) { - b = (s[(i/8)|0] >> (i&7)) & 1; - cswap(p, q, b); - add(q, p); - add(p, p); - cswap(p, q, b); - } -} + frame: function(buffer) { + if (this.readyState === 0) return this._queue([buffer]); + if (this.readyState > 1) return false; -function scalarbase(p, s) { - var q = [gf(), gf(), gf(), gf()]; - set25519(q[0], X); - set25519(q[1], Y); - set25519(q[2], gf1); - M(q[3], X, Y); - scalarmult(p, q, s); -} + if (typeof buffer !== 'string') buffer = buffer.toString(); -function crypto_sign_keypair(pk, sk, seeded) { - var d = new Uint8Array(64); - var p = [gf(), gf(), gf(), gf()]; - var i; + var length = Buffer.byteLength(buffer), + frame = Buffer.allocUnsafe(length + 2); - if (!seeded) randombytes(sk, 32); - crypto_hash(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; + frame[0] = 0x00; + frame.write(buffer, 1); + frame[frame.length - 1] = 0xFF; - scalarbase(p, d); - pack(pk, p); + this._write(frame); + return true; + }, - for (i = 0; i < 32; i++) sk[i+32] = pk[i]; - return 0; -} + _handshakeResponse: function() { + var start = 'HTTP/1.1 101 Web Socket Protocol Handshake', + headers = [start, this._headers.toString(), '']; -var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); + return Buffer.from(headers.join('\r\n'), 'utf8'); + }, -function modL(r, x) { - var carry, i, j, k; - for (i = 63; i >= 32; --i) { - carry = 0; - for (j = i - 32, k = i - 12; j < k; ++j) { - x[j] += carry - 16 * x[i] * L[j - (i - 32)]; - carry = (x[j] + 128) >> 8; - x[j] -= carry * 256; - } - x[j] += carry; - x[i] = 0; - } - carry = 0; - for (j = 0; j < 32; j++) { - x[j] += carry - (x[31] >> 4) * L[j]; - carry = x[j] >> 8; - x[j] &= 255; - } - for (j = 0; j < 32; j++) x[j] -= carry * L[j]; - for (i = 0; i < 32; i++) { - x[i+1] += x[i] >> 8; - r[i] = x[i] & 255; + _parseLeadingByte: function(octet) { + if ((octet & 0x80) === 0x80) { + this._length = 0; + this._stage = 1; + } else { + delete this._length; + delete this._skipped; + this._buffer = []; + this._stage = 2; + } } -} +}; -function reduce(r) { - var x = new Float64Array(64), i; - for (i = 0; i < 64; i++) x[i] = r[i]; - for (i = 0; i < 64; i++) r[i] = 0; - modL(r, x); -} +for (var key in instance) + Draft75.prototype[key] = instance[key]; -// Note: difference from C - smlen returned, not passed as argument. -function crypto_sign(sm, m, n, sk) { - var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); - var i, j, x = new Float64Array(64); - var p = [gf(), gf(), gf(), gf()]; +module.exports = Draft75; - crypto_hash(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; - var smlen = n + 64; - for (i = 0; i < n; i++) sm[64 + i] = m[i]; - for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]; +/***/ }), +/* 17 */ +/***/ (function(module, exports, __webpack_require__) { - crypto_hash(r, sm.subarray(32), n+32); - reduce(r); - scalarbase(p, r); - pack(sm, p); +var Event = __webpack_require__(9); - for (i = 32; i < 64; i++) sm[i] = sk[i]; - crypto_hash(h, sm, n + 64); - reduce(h); +var EventTarget = { + onopen: null, + onmessage: null, + onerror: null, + onclose: null, - for (i = 0; i < 64; i++) x[i] = 0; - for (i = 0; i < 32; i++) x[i] = r[i]; - for (i = 0; i < 32; i++) { - for (j = 0; j < 32; j++) { - x[i+j] += h[i] * d[j]; - } - } + addEventListener: function(eventType, listener, useCapture) { + this.on(eventType, listener); + }, - modL(sm.subarray(32), x); - return smlen; -} + removeEventListener: function(eventType, listener, useCapture) { + this.removeListener(eventType, listener); + }, -function unpackneg(r, p) { - var t = gf(), chk = gf(), num = gf(), - den = gf(), den2 = gf(), den4 = gf(), - den6 = gf(); + dispatchEvent: function(event) { + event.target = event.currentTarget = this; + event.eventPhase = Event.AT_TARGET; - set25519(r[2], gf1); - unpack25519(r[1], p); - S(num, r[1]); - M(den, num, D); - Z(num, num, r[2]); - A(den, r[2], den); + if (this['on' + event.type]) + this['on' + event.type](event); - S(den2, den); - S(den4, den2); - M(den6, den4, den2); - M(t, den6, num); - M(t, t, den); + this.emit(event.type, event); + } +}; - pow2523(t, t); - M(t, t, num); - M(t, t, den); - M(t, t, den); - M(r[0], t, den); +module.exports = EventTarget; - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) M(r[0], r[0], I); - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) return -1; +/***/ }), +/* 18 */ +/***/ (function(module, exports, __webpack_require__) { - if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]); +// API references: +// +// * http://dev.w3.org/html5/websockets/ +// * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-eventtarget +// * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-event - M(r[3], r[0], r[1]); - return 0; -} +var util = __webpack_require__(0), + driver = __webpack_require__(6), + API = __webpack_require__(12); -function crypto_sign_open(m, sm, n, pk) { - var i, mlen; - var t = new Uint8Array(32), h = new Uint8Array(64); - var p = [gf(), gf(), gf(), gf()], - q = [gf(), gf(), gf(), gf()]; +var WebSocket = function(request, socket, body, protocols, options) { + options = options || {}; - mlen = -1; - if (n < 64) return -1; + this._stream = socket; + this._driver = driver.http(request, {maxLength: options.maxLength, protocols: protocols}); - if (unpackneg(q, pk)) return -1; + var self = this; + if (!this._stream || !this._stream.writable) return; + if (!this._stream.readable) return this._stream.end(); - for (i = 0; i < n; i++) m[i] = sm[i]; - for (i = 0; i < 32; i++) m[i+32] = pk[i]; - crypto_hash(h, m, n); - reduce(h); - scalarmult(p, q, h); + var catchup = function() { self._stream.removeListener('data', catchup) }; + this._stream.on('data', catchup); - scalarbase(q, sm.subarray(32)); - add(p, q); - pack(t, p); + API.call(this, options); - n -= 64; - if (crypto_verify_32(sm, 0, t, 0)) { - for (i = 0; i < n; i++) m[i] = 0; - return -1; - } + process.nextTick(function() { + self._driver.start(); + self._driver.io.write(body); + }); +}; +util.inherits(WebSocket, API); - for (i = 0; i < n; i++) m[i] = sm[i + 64]; - mlen = n; - return mlen; -} +WebSocket.isWebSocket = function(request) { + return driver.isWebSocket(request); +}; -var crypto_secretbox_KEYBYTES = 32, - crypto_secretbox_NONCEBYTES = 24, - crypto_secretbox_ZEROBYTES = 32, - crypto_secretbox_BOXZEROBYTES = 16, - crypto_scalarmult_BYTES = 32, - crypto_scalarmult_SCALARBYTES = 32, - crypto_box_PUBLICKEYBYTES = 32, - crypto_box_SECRETKEYBYTES = 32, - crypto_box_BEFORENMBYTES = 32, - crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, - crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, - crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, - crypto_sign_BYTES = 64, - crypto_sign_PUBLICKEYBYTES = 32, - crypto_sign_SECRETKEYBYTES = 64, - crypto_sign_SEEDBYTES = 32, - crypto_hash_BYTES = 64; +WebSocket.validateOptions = function(options, validKeys) { + driver.validateOptions(options, validKeys); +}; -nacl.lowlevel = { - crypto_core_hsalsa20: crypto_core_hsalsa20, - crypto_stream_xor: crypto_stream_xor, - crypto_stream: crypto_stream, - crypto_stream_salsa20_xor: crypto_stream_salsa20_xor, - crypto_stream_salsa20: crypto_stream_salsa20, - crypto_onetimeauth: crypto_onetimeauth, - crypto_onetimeauth_verify: crypto_onetimeauth_verify, - crypto_verify_16: crypto_verify_16, - crypto_verify_32: crypto_verify_32, - crypto_secretbox: crypto_secretbox, - crypto_secretbox_open: crypto_secretbox_open, - crypto_scalarmult: crypto_scalarmult, - crypto_scalarmult_base: crypto_scalarmult_base, - crypto_box_beforenm: crypto_box_beforenm, - crypto_box_afternm: crypto_box_afternm, - crypto_box: crypto_box, - crypto_box_open: crypto_box_open, - crypto_box_keypair: crypto_box_keypair, - crypto_hash: crypto_hash, - crypto_sign: crypto_sign, - crypto_sign_keypair: crypto_sign_keypair, - crypto_sign_open: crypto_sign_open, +WebSocket.WebSocket = WebSocket; +WebSocket.Client = __webpack_require__(38); +WebSocket.EventSource = __webpack_require__(41); - crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES, - crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES, - crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES, - crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES, - crypto_scalarmult_BYTES: crypto_scalarmult_BYTES, - crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES, - crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES, - crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES, - crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES, - crypto_box_NONCEBYTES: crypto_box_NONCEBYTES, - crypto_box_ZEROBYTES: crypto_box_ZEROBYTES, - crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES, - crypto_sign_BYTES: crypto_sign_BYTES, - crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES, - crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES, - crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES, - crypto_hash_BYTES: crypto_hash_BYTES -}; +module.exports = WebSocket; -/* High-level API */ -function checkLengths(k, n) { - if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size'); - if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size'); -} +/***/ }), +/* 19 */ +/***/ (function(module, exports, __webpack_require__) { -function checkBoxLengths(pk, sk) { - if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size'); - if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size'); -} +/** + * Wrapper for built-in http.js to emulate the browser XMLHttpRequest object. + * + * This can be used with JS designed for browsers to improve reuse of code and + * allow the use of existing libraries. + * + * Usage: include("XMLHttpRequest.js") and use XMLHttpRequest per W3C specs. + * + * @author Dan DeFelippi + * @contributor David Ellis + * @license MIT + */ -function checkArrayTypes() { - for (var i = 0; i < arguments.length; i++) { - if (!(arguments[i] instanceof Uint8Array)) - throw new TypeError('unexpected type, use Uint8Array'); - } -} +var Url = __webpack_require__(8); +var spawn = __webpack_require__(42).spawn; +var fs = __webpack_require__(43); -function cleanup(arr) { - for (var i = 0; i < arr.length; i++) arr[i] = 0; -} +exports.XMLHttpRequest = function() { + "use strict"; -nacl.randomBytes = function(n) { - var b = new Uint8Array(n); - randombytes(b, n); - return b; -}; + /** + * Private variables + */ + var self = this; + var http = __webpack_require__(44); + var https = __webpack_require__(45); -nacl.secretbox = function(msg, nonce, key) { - checkArrayTypes(msg, nonce, key); - checkLengths(key, nonce); - var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length); - var c = new Uint8Array(m.length); - for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i]; - crypto_secretbox(c, m, m.length, nonce, key); - return c.subarray(crypto_secretbox_BOXZEROBYTES); -}; + // Holds http.js objects + var request; + var response; -nacl.secretbox.open = function(box, nonce, key) { - checkArrayTypes(box, nonce, key); - checkLengths(key, nonce); - var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length); - var m = new Uint8Array(c.length); - for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i]; - if (c.length < 32) return null; - if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null; - return m.subarray(crypto_secretbox_ZEROBYTES); -}; + // Request settings + var settings = {}; -nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES; -nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES; -nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES; + // Disable header blacklist. + // Not part of XHR specs. + var disableHeaderCheck = false; -nacl.scalarMult = function(n, p) { - checkArrayTypes(n, p); - if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); - if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size'); - var q = new Uint8Array(crypto_scalarmult_BYTES); - crypto_scalarmult(q, n, p); - return q; -}; + // Set some default headers + var defaultHeaders = { + "User-Agent": "node-XMLHttpRequest", + "Accept": "*/*", + }; -nacl.scalarMult.base = function(n) { - checkArrayTypes(n); - if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); - var q = new Uint8Array(crypto_scalarmult_BYTES); - crypto_scalarmult_base(q, n); - return q; -}; + var headers = {}; + var headersCase = {}; -nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES; -nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES; + // These headers are not user setable. + // The following are allowed but banned in the spec: + // * user-agent + var forbiddenRequestHeaders = [ + "accept-charset", + "accept-encoding", + "access-control-request-headers", + "access-control-request-method", + "connection", + "content-length", + "content-transfer-encoding", + "cookie", + "cookie2", + "date", + "expect", + "host", + "keep-alive", + "origin", + "referer", + "te", + "trailer", + "transfer-encoding", + "upgrade", + "via" + ]; -nacl.box = function(msg, nonce, publicKey, secretKey) { - var k = nacl.box.before(publicKey, secretKey); - return nacl.secretbox(msg, nonce, k); -}; + // These request methods are not allowed + var forbiddenRequestMethods = [ + "TRACE", + "TRACK", + "CONNECT" + ]; -nacl.box.before = function(publicKey, secretKey) { - checkArrayTypes(publicKey, secretKey); - checkBoxLengths(publicKey, secretKey); - var k = new Uint8Array(crypto_box_BEFORENMBYTES); - crypto_box_beforenm(k, publicKey, secretKey); - return k; -}; + // Send flag + var sendFlag = false; + // Error flag, used when errors occur or abort is called + var errorFlag = false; -nacl.box.after = nacl.secretbox; + // Event listeners + var listeners = {}; -nacl.box.open = function(msg, nonce, publicKey, secretKey) { - var k = nacl.box.before(publicKey, secretKey); - return nacl.secretbox.open(msg, nonce, k); -}; + /** + * Constants + */ -nacl.box.open.after = nacl.secretbox.open; + this.UNSENT = 0; + this.OPENED = 1; + this.HEADERS_RECEIVED = 2; + this.LOADING = 3; + this.DONE = 4; -nacl.box.keyPair = function() { - var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_box_SECRETKEYBYTES); - crypto_box_keypair(pk, sk); - return {publicKey: pk, secretKey: sk}; -}; + /** + * Public vars + */ -nacl.box.keyPair.fromSecretKey = function(secretKey) { - checkArrayTypes(secretKey); - if (secretKey.length !== crypto_box_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); - crypto_scalarmult_base(pk, secretKey); - return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; -}; + // Current state + this.readyState = this.UNSENT; -nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES; -nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES; -nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES; -nacl.box.nonceLength = crypto_box_NONCEBYTES; -nacl.box.overheadLength = nacl.secretbox.overheadLength; + // default ready state change handler in case one is not set or is set late + this.onreadystatechange = null; -nacl.sign = function(msg, secretKey) { - checkArrayTypes(msg, secretKey); - if (secretKey.length !== crypto_sign_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length); - crypto_sign(signedMsg, msg, msg.length, secretKey); - return signedMsg; -}; + // Result & response + this.responseText = ""; + this.responseXML = ""; + this.status = null; + this.statusText = null; + + // Whether cross-site Access-Control requests should be made using + // credentials such as cookies or authorization headers + this.withCredentials = false; -nacl.sign.open = function(signedMsg, publicKey) { - checkArrayTypes(signedMsg, publicKey); - if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) - throw new Error('bad public key size'); - var tmp = new Uint8Array(signedMsg.length); - var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey); - if (mlen < 0) return null; - var m = new Uint8Array(mlen); - for (var i = 0; i < m.length; i++) m[i] = tmp[i]; - return m; -}; + /** + * Private methods + */ -nacl.sign.detached = function(msg, secretKey) { - var signedMsg = nacl.sign(msg, secretKey); - var sig = new Uint8Array(crypto_sign_BYTES); - for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; - return sig; -}; + /** + * Check if the specified header is allowed. + * + * @param string header Header to validate + * @return boolean False if not allowed, otherwise true + */ + var isAllowedHttpHeader = function(header) { + return disableHeaderCheck || (header && forbiddenRequestHeaders.indexOf(header.toLowerCase()) === -1); + }; -nacl.sign.detached.verify = function(msg, sig, publicKey) { - checkArrayTypes(msg, sig, publicKey); - if (sig.length !== crypto_sign_BYTES) - throw new Error('bad signature size'); - if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) - throw new Error('bad public key size'); - var sm = new Uint8Array(crypto_sign_BYTES + msg.length); - var m = new Uint8Array(crypto_sign_BYTES + msg.length); - var i; - for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]; - for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i]; - return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); -}; + /** + * Check if the specified method is allowed. + * + * @param string method Request method to validate + * @return boolean False if not allowed, otherwise true + */ + var isAllowedHttpMethod = function(method) { + return (method && forbiddenRequestMethods.indexOf(method) === -1); + }; -nacl.sign.keyPair = function() { - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); - crypto_sign_keypair(pk, sk); - return {publicKey: pk, secretKey: sk}; -}; + /** + * Public methods + */ -nacl.sign.keyPair.fromSecretKey = function(secretKey) { - checkArrayTypes(secretKey); - if (secretKey.length !== crypto_sign_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i]; - return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; -}; + /** + * Open the connection. Currently supports local server requests. + * + * @param string method Connection method (eg GET, POST) + * @param string url URL for the connection. + * @param boolean async Asynchronous connection. Default is true. + * @param string user Username for basic authentication (optional) + * @param string password Password for basic authentication (optional) + */ + this.open = function(method, url, async, user, password) { + this.abort(); + errorFlag = false; -nacl.sign.keyPair.fromSeed = function(seed) { - checkArrayTypes(seed); - if (seed.length !== crypto_sign_SEEDBYTES) - throw new Error('bad seed size'); - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); - for (var i = 0; i < 32; i++) sk[i] = seed[i]; - crypto_sign_keypair(pk, sk, true); - return {publicKey: pk, secretKey: sk}; -}; + // Check for valid request method + if (!isAllowedHttpMethod(method)) { + throw new Error("SecurityError: Request method not allowed"); + } + + settings = { + "method": method, + "url": url.toString(), + "async": (typeof async !== "boolean" ? true : async), + "user": user || null, + "password": password || null + }; -nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; -nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; -nacl.sign.seedLength = crypto_sign_SEEDBYTES; -nacl.sign.signatureLength = crypto_sign_BYTES; + setState(this.OPENED); + }; -nacl.hash = function(msg) { - checkArrayTypes(msg); - var h = new Uint8Array(crypto_hash_BYTES); - crypto_hash(h, msg, msg.length); - return h; -}; + /** + * Disables or enables isAllowedHttpHeader() check the request. Enabled by default. + * This does not conform to the W3C spec. + * + * @param boolean state Enable or disable header checking. + */ + this.setDisableHeaderCheck = function(state) { + disableHeaderCheck = state; + }; -nacl.hash.hashLength = crypto_hash_BYTES; + /** + * Sets a header for the request or appends the value if one is already set. + * + * @param string header Header name + * @param string value Header value + */ + this.setRequestHeader = function(header, value) { + if (this.readyState !== this.OPENED) { + throw new Error("INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN"); + } + if (!isAllowedHttpHeader(header)) { + console.warn("Refused to set unsafe header \"" + header + "\""); + return; + } + if (sendFlag) { + throw new Error("INVALID_STATE_ERR: send flag is true"); + } + header = headersCase[header.toLowerCase()] || header; + headersCase[header.toLowerCase()] = header; + headers[header] = headers[header] ? headers[header] + ', ' + value : value; + }; -nacl.verify = function(x, y) { - checkArrayTypes(x, y); - // Zero length arguments are considered not equal. - if (x.length === 0 || y.length === 0) return false; - if (x.length !== y.length) return false; - return (vn(x, 0, y, 0, x.length) === 0) ? true : false; -}; + /** + * Gets a header from the server response. + * + * @param string header Name of header to get. + * @return string Text of the header or null if it doesn't exist. + */ + this.getResponseHeader = function(header) { + if (typeof header === "string" + && this.readyState > this.OPENED + && response + && response.headers + && response.headers[header.toLowerCase()] + && !errorFlag + ) { + return response.headers[header.toLowerCase()]; + } -nacl.setPRNG = function(fn) { - randombytes = fn; -}; + return null; + }; -(function() { - // Initialize PRNG if environment provides CSPRNG. - // If not, methods calling randombytes will throw. - var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null; - if (crypto && crypto.getRandomValues) { - // Browsers. - var QUOTA = 65536; - nacl.setPRNG(function(x, n) { - var i, v = new Uint8Array(n); - for (i = 0; i < n; i += QUOTA) { - crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); + /** + * Gets all the response headers. + * + * @return string A string with all response headers separated by CR+LF + */ + this.getAllResponseHeaders = function() { + if (this.readyState < this.HEADERS_RECEIVED || errorFlag) { + return ""; + } + var result = ""; + + for (var i in response.headers) { + // Cookie headers are excluded + if (i !== "set-cookie" && i !== "set-cookie2") { + result += i + ": " + response.headers[i] + "\r\n"; } - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); - } else if (true) { - // Node.js. - crypto = __webpack_require__(11); - if (crypto && crypto.randomBytes) { - nacl.setPRNG(function(x, n) { - var i, v = crypto.randomBytes(n); - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); } - } -})(); + return result.substr(0, result.length - 2); + }; -})( true && module.exports ? module.exports : (self.nacl = self.nacl || {})); + /** + * Gets a request header + * + * @param string name Name of header to get + * @return string Returns the request header or empty string if not set + */ + this.getRequestHeader = function(name) { + if (typeof name === "string" && headersCase[name.toLowerCase()]) { + return headers[headersCase[name.toLowerCase()]]; + } + return ""; + }; -/***/ }), -/* 52 */ -/***/ (function(module, exports, __webpack_require__) { + /** + * Sends the request to the server. + * + * @param string data Optional data to send as request body. + */ + this.send = function(data) { + if (this.readyState !== this.OPENED) { + throw new Error("INVALID_STATE_ERR: connection must be opened before send() is called"); + } -// Written in 2014-2016 by Dmitry Chestnykh and Devi Mandiri. -// Public domain. -(function(root, f) { - 'use strict'; - if ( true && module.exports) module.exports = f(); - else if (root.nacl) root.nacl.util = f(); - else { - root.nacl = {}; - root.nacl.util = f(); - } -}(this, function() { - 'use strict'; + if (sendFlag) { + throw new Error("INVALID_STATE_ERR: send has already been called"); + } - var util = {}; + var ssl = false, local = false; + var url = Url.parse(settings.url); + var host; + // Determine the server + switch (url.protocol) { + case "https:": + ssl = true; + // SSL & non-SSL both need host, no break here. + case "http:": + host = url.hostname; + break; - function validateBase64(s) { - if (!(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(s))) { - throw new TypeError('invalid encoding'); - } - } + case "file:": + local = true; + break; - util.decodeUTF8 = function(s) { - if (typeof s !== 'string') throw new TypeError('expected string'); - var i, d = unescape(encodeURIComponent(s)), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; - }; + case undefined: + case null: + case "": + host = "localhost"; + break; - util.encodeUTF8 = function(arr) { - var i, s = []; - for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i])); - return decodeURIComponent(escape(s.join(''))); - }; + default: + throw new Error("Protocol not supported."); + } - if (typeof atob === 'undefined') { - // Node.js + // Load files off the local filesystem (file://) + if (local) { + if (settings.method !== "GET") { + throw new Error("XMLHttpRequest: Only GET method is supported"); + } - if (typeof Buffer.from !== 'undefined') { - // Node v6 and later - util.encodeBase64 = function (arr) { // v6 and later - return Buffer.from(arr).toString('base64'); - }; + if (settings.async) { + fs.readFile(url.pathname, "utf8", function(error, data) { + if (error) { + self.handleError(error); + } else { + self.status = 200; + self.responseText = data; + setState(self.DONE); + } + }); + } else { + try { + this.responseText = fs.readFileSync(url.pathname, "utf8"); + this.status = 200; + setState(self.DONE); + } catch(e) { + this.handleError(e); + } + } - util.decodeBase64 = function (s) { - validateBase64(s); - return new Uint8Array(Array.prototype.slice.call(Buffer.from(s, 'base64'), 0)); - }; + return; + } - } else { - // Node earlier than v6 - util.encodeBase64 = function (arr) { // v6 and later - return (new Buffer(arr)).toString('base64'); - }; + // Default to port 80. If accessing localhost on another port be sure + // to use http://localhost:port/path + var port = url.port || (ssl ? 443 : 80); + // Add query string if one is used + var uri = url.pathname + (url.search ? url.search : ""); - util.decodeBase64 = function(s) { - validateBase64(s); - return new Uint8Array(Array.prototype.slice.call(new Buffer(s, 'base64'), 0)); - }; + // Set the defaults if they haven't been set + for (var name in defaultHeaders) { + if (!headersCase[name.toLowerCase()]) { + headers[name] = defaultHeaders[name]; + } + } + + // Set the Host header or the server may reject the request + headers.Host = host; + if (!((ssl && port === 443) || port === 80)) { + headers.Host += ":" + url.port; } - } else { - // Browsers + // Set Basic Auth if necessary + if (settings.user) { + if (typeof settings.password === "undefined") { + settings.password = ""; + } + var authBuf = new Buffer(settings.user + ":" + settings.password); + headers.Authorization = "Basic " + authBuf.toString("base64"); + } - util.encodeBase64 = function(arr) { - var i, s = [], len = arr.length; - for (i = 0; i < len; i++) s.push(String.fromCharCode(arr[i])); - return btoa(s.join('')); - }; + // Set content length header + if (settings.method === "GET" || settings.method === "HEAD") { + data = null; + } else if (data) { + headers["Content-Length"] = Buffer.isBuffer(data) ? data.length : Buffer.byteLength(data); - util.decodeBase64 = function(s) { - validateBase64(s); - var i, d = atob(s), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; - }; + if (!headers["Content-Type"]) { + headers["Content-Type"] = "text/plain;charset=UTF-8"; + } + } else if (settings.method === "POST") { + // For a post with no data set Content-Length: 0. + // This is required by buggy servers that don't meet the specs. + headers["Content-Length"] = 0; + } - } + var options = { + host: host, + port: port, + path: uri, + method: settings.method, + headers: headers, + agent: false, + withCredentials: self.withCredentials + }; - return util; + // Reset error flag + errorFlag = false; -})); + // Handle async requests + if (settings.async) { + // Use the proper protocol + var doRequest = ssl ? https.request : http.request; + // Request is being sent, set send flag + sendFlag = true; -/***/ }), -/* 53 */ -/***/ (function(module, exports, __webpack_require__) { + // As per spec, this is called here for historical reasons. + self.dispatchEvent("readystatechange"); -"use strict"; + // Handler for the response + var responseHandler = function responseHandler(resp) { + // Set response var to the response we got back + // This is so it remains accessable outside this scope + response = resp; + // Check for redirect + // @TODO Prevent looped redirects + if (response.statusCode === 301 || response.statusCode === 302 || response.statusCode === 303 || response.statusCode === 307) { + // Change URL to the redirect location + settings.url = response.headers.location; + var url = Url.parse(settings.url); + // Set host var in case it's used later + host = url.hostname; + // Options for the new request + var newOptions = { + hostname: url.hostname, + port: url.port, + path: url.path, + method: response.statusCode === 303 ? "GET" : settings.method, + headers: headers, + withCredentials: self.withCredentials + }; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var dispatcher_1 = __webpack_require__(6); -var timers_1 = __webpack_require__(8); -var logger_1 = __webpack_require__(4); -var Collections = __webpack_require__(0); -var runtime_1 = __webpack_require__(1); -var ConnectionManager = (function (_super) { - __extends(ConnectionManager, _super); - function ConnectionManager(key, options) { - var _this = _super.call(this) || this; - _this.key = key; - _this.options = options || {}; - _this.state = "initialized"; - _this.connection = null; - _this.usingTLS = !!options.useTLS; - _this.timeline = _this.options.timeline; - _this.errorCallbacks = _this.buildErrorCallbacks(); - _this.connectionCallbacks = _this.buildConnectionCallbacks(_this.errorCallbacks); - _this.handshakeCallbacks = _this.buildHandshakeCallbacks(_this.errorCallbacks); - var Network = runtime_1["default"].getNetwork(); - Network.bind("online", function () { - _this.timeline.info({ netinfo: "online" }); - if (_this.state === "connecting" || _this.state === "unavailable") { - _this.retryIn(0); - } - }); - Network.bind("offline", function () { - _this.timeline.info({ netinfo: "offline" }); - if (_this.connection) { - _this.sendActivityCheck(); - } - }); - _this.updateStrategy(); - return _this; - } - ConnectionManager.prototype.connect = function () { - if (this.connection || this.runner) { - return; - } - if (!this.strategy.isSupported()) { - this.updateState("failed"); - return; - } - this.updateState("connecting"); - this.startConnecting(); - this.setUnavailableTimer(); - }; - ; - ConnectionManager.prototype.send = function (data) { - if (this.connection) { - return this.connection.send(data); - } - else { - return false; - } - }; - ; - ConnectionManager.prototype.send_event = function (name, data, channel) { - if (this.connection) { - return this.connection.send_event(name, data, channel); - } - else { - return false; - } - }; - ; - ConnectionManager.prototype.disconnect = function () { - this.disconnectInternally(); - this.updateState("disconnected"); - }; - ; - ConnectionManager.prototype.isUsingTLS = function () { - return this.usingTLS; - }; - ; - ConnectionManager.prototype.startConnecting = function () { - var _this = this; - var callback = function (error, handshake) { - if (error) { - _this.runner = _this.strategy.connect(0, callback); - } - else { - if (handshake.action === "error") { - _this.emit("error", { type: "HandshakeError", error: handshake.error }); - _this.timeline.error({ handshakeError: handshake.error }); - } - else { - _this.abortConnecting(); - _this.handshakeCallbacks[handshake.action](handshake); - } - } - }; - this.runner = this.strategy.connect(0, callback); - }; - ; - ConnectionManager.prototype.abortConnecting = function () { - if (this.runner) { - this.runner.abort(); - this.runner = null; - } - }; - ; - ConnectionManager.prototype.disconnectInternally = function () { - this.abortConnecting(); - this.clearRetryTimer(); - this.clearUnavailableTimer(); - if (this.connection) { - var connection = this.abandonConnection(); - connection.close(); - } - }; - ; - ConnectionManager.prototype.updateStrategy = function () { - this.strategy = this.options.getStrategy({ - key: this.key, - timeline: this.timeline, - useTLS: this.usingTLS - }); - }; - ; - ConnectionManager.prototype.retryIn = function (delay) { - var _this = this; - this.timeline.info({ action: "retry", delay: delay }); - if (delay > 0) { - this.emit("connecting_in", Math.round(delay / 1000)); - } - this.retryTimer = new timers_1.OneOffTimer(delay || 0, function () { - _this.disconnectInternally(); - _this.connect(); - }); - }; - ; - ConnectionManager.prototype.clearRetryTimer = function () { - if (this.retryTimer) { - this.retryTimer.ensureAborted(); - this.retryTimer = null; - } - }; - ; - ConnectionManager.prototype.setUnavailableTimer = function () { - var _this = this; - this.unavailableTimer = new timers_1.OneOffTimer(this.options.unavailableTimeout, function () { - _this.updateState("unavailable"); - }); - }; - ; - ConnectionManager.prototype.clearUnavailableTimer = function () { - if (this.unavailableTimer) { - this.unavailableTimer.ensureAborted(); - } - }; - ; - ConnectionManager.prototype.sendActivityCheck = function () { - var _this = this; - this.stopActivityCheck(); - this.connection.ping(); - this.activityTimer = new timers_1.OneOffTimer(this.options.pongTimeout, function () { - _this.timeline.error({ pong_timed_out: _this.options.pongTimeout }); - _this.retryIn(0); - }); - }; - ; - ConnectionManager.prototype.resetActivityCheck = function () { - var _this = this; - this.stopActivityCheck(); - if (this.connection && !this.connection.handlesActivityChecks()) { - this.activityTimer = new timers_1.OneOffTimer(this.activityTimeout, function () { - _this.sendActivityCheck(); - }); - } - }; - ; - ConnectionManager.prototype.stopActivityCheck = function () { - if (this.activityTimer) { - this.activityTimer.ensureAborted(); + // Issue the new request + request = doRequest(newOptions, responseHandler).on("error", errorHandler); + request.end(); + // @TODO Check if an XHR event needs to be fired here + return; } - }; - ; - ConnectionManager.prototype.buildConnectionCallbacks = function (errorCallbacks) { - var _this = this; - return Collections.extend({}, errorCallbacks, { - message: function (message) { - _this.resetActivityCheck(); - _this.emit('message', message); - }, - ping: function () { - _this.send_event('pusher:pong', {}); - }, - activity: function () { - _this.resetActivityCheck(); - }, - error: function (error) { - _this.emit("error", { type: "WebSocketError", error: error }); - }, - closed: function () { - _this.abandonConnection(); - if (_this.shouldRetry()) { - _this.retryIn(1000); - } - } + + response.setEncoding("utf8"); + + setState(self.HEADERS_RECEIVED); + self.status = response.statusCode; + + response.on("data", function(chunk) { + // Make sure there's some data + if (chunk) { + self.responseText += chunk; + } + // Don't emit state changes if the connection has been aborted. + if (sendFlag) { + setState(self.LOADING); + } }); - }; - ; - ConnectionManager.prototype.buildHandshakeCallbacks = function (errorCallbacks) { - var _this = this; - return Collections.extend({}, errorCallbacks, { - connected: function (handshake) { - _this.activityTimeout = Math.min(_this.options.activityTimeout, handshake.activityTimeout, handshake.connection.activityTimeout || Infinity); - _this.clearUnavailableTimer(); - _this.setConnection(handshake.connection); - _this.socket_id = _this.connection.id; - _this.updateState("connected", { socket_id: _this.socket_id }); - } + + response.on("end", function() { + if (sendFlag) { + // Discard the end event if the connection has been aborted + setState(self.DONE); + sendFlag = false; + } }); - }; - ; - ConnectionManager.prototype.buildErrorCallbacks = function () { - var _this = this; - var withErrorEmitted = function (callback) { - return function (result) { - if (result.error) { - _this.emit("error", { type: "WebSocketError", error: result.error }); - } - callback(result); - }; - }; - return { - tls_only: withErrorEmitted(function () { - _this.usingTLS = true; - _this.updateStrategy(); - _this.retryIn(0); - }), - refused: withErrorEmitted(function () { - _this.disconnect(); - }), - backoff: withErrorEmitted(function () { - _this.retryIn(1000); - }), - retry: withErrorEmitted(function () { - _this.retryIn(0); - }) - }; - }; - ; - ConnectionManager.prototype.setConnection = function (connection) { - this.connection = connection; - for (var event in this.connectionCallbacks) { - this.connection.bind(event, this.connectionCallbacks[event]); - } - this.resetActivityCheck(); - }; - ; - ConnectionManager.prototype.abandonConnection = function () { - if (!this.connection) { - return; - } - this.stopActivityCheck(); - for (var event in this.connectionCallbacks) { - this.connection.unbind(event, this.connectionCallbacks[event]); - } - var connection = this.connection; - this.connection = null; - return connection; - }; - ConnectionManager.prototype.updateState = function (newState, data) { - var previousState = this.state; - this.state = newState; - if (previousState !== newState) { - var newStateDescription = newState; - if (newStateDescription === "connected") { - newStateDescription += " with new socket ID " + data.socket_id; - } - logger_1["default"].debug('State changed', previousState + ' -> ' + newStateDescription); - this.timeline.info({ state: newState, params: data }); - this.emit('state_change', { previous: previousState, current: newState }); - this.emit(newState, data); - } - }; - ConnectionManager.prototype.shouldRetry = function () { - return this.state === "connecting" || this.state === "connected"; - }; - return ConnectionManager; -}(dispatcher_1["default"])); -exports["default"] = ConnectionManager; + response.on("error", function(error) { + self.handleError(error); + }); + }; + + // Error handler for the request + var errorHandler = function errorHandler(error) { + self.handleError(error); + }; + + // Create the request + request = doRequest(options, responseHandler).on("error", errorHandler); + + // Node 0.4 and later won't accept empty data. Make sure it's needed. + if (data) { + request.write(data); + } + + request.end(); + + self.dispatchEvent("loadstart"); + } else { // Synchronous + // Create a temporary file for communication with the other Node process + var contentFile = ".node-xmlhttprequest-content-" + process.pid; + var syncFile = ".node-xmlhttprequest-sync-" + process.pid; + fs.writeFileSync(syncFile, "", "utf8"); + // The async request the other Node process executes + var execString = "var http = require('http'), https = require('https'), fs = require('fs');" + + "var doRequest = http" + (ssl ? "s" : "") + ".request;" + + "var options = " + JSON.stringify(options) + ";" + + "var responseText = '';" + + "var req = doRequest(options, function(response) {" + + "response.setEncoding('utf8');" + + "response.on('data', function(chunk) {" + + " responseText += chunk;" + + "});" + + "response.on('end', function() {" + + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: null, data: {statusCode: response.statusCode, headers: response.headers, text: responseText}}), 'utf8');" + + "fs.unlinkSync('" + syncFile + "');" + + "});" + + "response.on('error', function(error) {" + + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: error}), 'utf8');" + + "fs.unlinkSync('" + syncFile + "');" + + "});" + + "}).on('error', function(error) {" + + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: error}), 'utf8');" + + "fs.unlinkSync('" + syncFile + "');" + + "});" + + (data ? "req.write('" + JSON.stringify(data).slice(1,-1).replace(/'/g, "\\'") + "');":"") + + "req.end();"; + // Start the other Node Process, executing this string + var syncProc = spawn(process.argv[0], ["-e", execString]); + while(fs.existsSync(syncFile)) { + // Wait while the sync file is empty + } + var resp = JSON.parse(fs.readFileSync(contentFile, 'utf8')); + // Kill the child process once the file has data + syncProc.stdin.end(); + // Remove the temporary file + fs.unlinkSync(contentFile); + + if (resp.err) { + self.handleError(resp.err); + } else { + response = resp.data; + self.status = resp.data.statusCode; + self.responseText = resp.data.text; + setState(self.DONE); + } + } + }; + + /** + * Called when an error is encountered to deal with it. + */ + this.handleError = function(error) { + this.status = 0; + this.statusText = error; + this.responseText = error.stack; + errorFlag = true; + setState(this.DONE); + this.dispatchEvent('error'); + }; + + /** + * Aborts a request. + */ + this.abort = function() { + if (request) { + request.abort(); + request = null; + } + + headers = defaultHeaders; + this.status = 0; + this.responseText = ""; + this.responseXML = ""; + + errorFlag = true; + + if (this.readyState !== this.UNSENT + && (this.readyState !== this.OPENED || sendFlag) + && this.readyState !== this.DONE) { + sendFlag = false; + setState(this.DONE); + } + this.readyState = this.UNSENT; + this.dispatchEvent('abort'); + }; + + /** + * Adds an event listener. Preferred method of binding to events. + */ + this.addEventListener = function(event, callback) { + if (!(event in listeners)) { + listeners[event] = []; + } + // Currently allows duplicate callbacks. Should it? + listeners[event].push(callback); + }; + + /** + * Remove an event callback that has already been bound. + * Only works on the matching funciton, cannot be a copy. + */ + this.removeEventListener = function(event, callback) { + if (event in listeners) { + // Filter will return a new array with the callback removed + listeners[event] = listeners[event].filter(function(ev) { + return ev !== callback; + }); + } + }; + + /** + * Dispatch any events, including both "on" methods and events attached using addEventListener. + */ + this.dispatchEvent = function(event) { + if (typeof self["on" + event] === "function") { + self["on" + event](); + } + if (event in listeners) { + for (var i = 0, len = listeners[event].length; i < len; i++) { + listeners[event][i].call(self); + } + } + }; -/***/ }), -/* 54 */ -/***/ (function(module, exports, __webpack_require__) { + /** + * Changes readyState and calls onreadystatechange. + * + * @param int state New state + */ + var setState = function(state) { + if (state == self.LOADING || self.readyState !== state) { + self.readyState = state; -"use strict"; + if (settings.async || self.readyState < self.OPENED || self.readyState === self.DONE) { + self.dispatchEvent("readystatechange"); + } -exports.__esModule = true; -var Collections = __webpack_require__(0); -var factory_1 = __webpack_require__(9); -var Errors = __webpack_require__(10); -var Channels = (function () { - function Channels() { - this.channels = {}; - } - Channels.prototype.add = function (name, pusher) { - if (!this.channels[name]) { - this.channels[name] = createChannel(name, pusher); - } - return this.channels[name]; - }; - Channels.prototype.all = function () { - return Collections.values(this.channels); - }; - Channels.prototype.find = function (name) { - return this.channels[name]; - }; - Channels.prototype.remove = function (name) { - var channel = this.channels[name]; - delete this.channels[name]; - return channel; - }; - Channels.prototype.disconnect = function () { - Collections.objectApply(this.channels, function (channel) { - channel.disconnect(); - }); - }; - return Channels; -}()); -exports["default"] = Channels; -function createChannel(name, pusher) { - if (name.indexOf('private-encrypted-') === 0) { - if (false) { var errorMsg; } - return factory_1["default"].createEncryptedChannel(name, pusher); - } - else if (name.indexOf('private-') === 0) { - return factory_1["default"].createPrivateChannel(name, pusher); - } - else if (name.indexOf('presence-') === 0) { - return factory_1["default"].createPresenceChannel(name, pusher); - } - else { - return factory_1["default"].createChannel(name, pusher); + if (self.readyState === self.DONE && !errorFlag) { + self.dispatchEvent("load"); + // @TODO figure out InspectorInstrumentation::didLoadXHR(cookie) + self.dispatchEvent("loadend"); + } } -} + }; +}; /***/ }), -/* 55 */ +/* 20 */ /***/ (function(module, exports, __webpack_require__) { -"use strict"; +// required so we don't have to do require('pusher').default etc. +module.exports = __webpack_require__(46).default; -exports.__esModule = true; -var Collections = __webpack_require__(0); -var util_1 = __webpack_require__(3); -var BestConnectedEverStrategy = (function () { - function BestConnectedEverStrategy(strategies) { - this.strategies = strategies; - } - BestConnectedEverStrategy.prototype.isSupported = function () { - return Collections.any(this.strategies, util_1["default"].method("isSupported")); - }; - BestConnectedEverStrategy.prototype.connect = function (minPriority, callback) { - return connect(this.strategies, minPriority, function (i, runners) { - return function (error, handshake) { - runners[i].error = error; - if (error) { - if (allRunnersFailed(runners)) { - callback(true); - } - return; - } - Collections.apply(runners, function (runner) { - runner.forceMinPriority(handshake.transport.priority); - }); - callback(null, handshake); - }; - }); - }; - return BestConnectedEverStrategy; -}()); -exports["default"] = BestConnectedEverStrategy; -function connect(strategies, minPriority, callbackBuilder) { - var runners = Collections.map(strategies, function (strategy, i, _, rs) { - return strategy.connect(minPriority, callbackBuilder(i, rs)); - }); - return { - abort: function () { - Collections.apply(runners, abortRunner); - }, - forceMinPriority: function (p) { - Collections.apply(runners, function (runner) { - runner.forceMinPriority(p); - }); - } - }; -} -function allRunnersFailed(runners) { - return Collections.all(runners, function (runner) { - return Boolean(runner.error); - }); -} -function abortRunner(runner) { - if (!runner.error && !runner.aborted) { - runner.abort(); - runner.aborted = true; - } -} +/***/ }), +/* 21 */ +/***/ (function(module, exports) { + +module.exports = require("buffer"); + +/***/ }), +/* 22 */ +/***/ (function(module, exports) { + +module.exports = require("events"); /***/ }), -/* 56 */ +/* 23 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -exports.__esModule = true; -var util_1 = __webpack_require__(3); -var runtime_1 = __webpack_require__(1); -var sequential_strategy_1 = __webpack_require__(25); -var Collections = __webpack_require__(0); -var CachedStrategy = (function () { - function CachedStrategy(strategy, transports, options) { - this.strategy = strategy; - this.transports = transports; - this.ttl = options.ttl || 1800 * 1000; - this.usingTLS = options.useTLS; - this.timeline = options.timeline; - } - CachedStrategy.prototype.isSupported = function () { - return this.strategy.isSupported(); - }; - CachedStrategy.prototype.connect = function (minPriority, callback) { - var usingTLS = this.usingTLS; - var info = fetchTransportCache(usingTLS); - var strategies = [this.strategy]; - if (info && info.timestamp + this.ttl >= util_1["default"].now()) { - var transport = this.transports[info.transport]; - if (transport) { - this.timeline.info({ - cached: true, - transport: info.transport, - latency: info.latency - }); - strategies.push(new sequential_strategy_1["default"]([transport], { - timeout: info.latency * 2 + 1000, - failFast: true - })); - } - } - var startTimestamp = util_1["default"].now(); - var runner = strategies.pop().connect(minPriority, function cb(error, handshake) { - if (error) { - flushTransportCache(usingTLS); - if (strategies.length > 0) { - startTimestamp = util_1["default"].now(); - runner = strategies.pop().connect(minPriority, cb); - } - else { - callback(error); - } - } - else { - storeTransportCache(usingTLS, handshake.transport.name, util_1["default"].now() - startTimestamp); - callback(null, handshake); - } - }); - return { - abort: function () { - runner.abort(); - }, - forceMinPriority: function (p) { - minPriority = p; - if (runner) { - runner.forceMinPriority(p); - } - } - }; - }; - return CachedStrategy; -}()); -exports["default"] = CachedStrategy; -function getTransportCacheKey(usingTLS) { - return "pusherTransport" + (usingTLS ? "TLS" : "NonTLS"); -} -function fetchTransportCache(usingTLS) { - var storage = runtime_1["default"].getLocalStorage(); - if (storage) { - try { - var serializedCache = storage[getTransportCacheKey(usingTLS)]; - if (serializedCache) { - return JSON.parse(serializedCache); - } - } - catch (e) { - flushTransportCache(usingTLS); - } - } - return null; -} -function storeTransportCache(usingTLS, transport, latency) { - var storage = runtime_1["default"].getLocalStorage(); - if (storage) { - try { - storage[getTransportCacheKey(usingTLS)] = Collections.safeJSONStringify({ - timestamp: util_1["default"].now(), - transport: transport, - latency: latency - }); - } - catch (e) { - } - } -} -function flushTransportCache(usingTLS) { - var storage = runtime_1["default"].getLocalStorage(); - if (storage) { - try { - delete storage[getTransportCacheKey(usingTLS)]; - } - catch (e) { - } - } -} +/** + +Streams in a WebSocket connection +--------------------------------- + +We model a WebSocket as two duplex streams: one stream is for the wire protocol +over an I/O socket, and the other is for incoming/outgoing messages. + + + +----------+ +---------+ +----------+ + [1] write(chunk) -->| ~~~~~~~~ +----->| parse() +----->| ~~~~~~~~ +--> emit('data') [2] + | | +----+----+ | | + | | | | | + | IO | | [5] | Messages | + | | V | | + | | +---------+ | | + [4] emit('data') <--+ ~~~~~~~~ |<-----+ frame() |<-----+ ~~~~~~~~ |<-- write(chunk) [3] + +----------+ +---------+ +----------+ + + +Message transfer in each direction is simple: IO receives a byte stream [1] and +sends this stream for parsing. The parser will periodically emit a complete +message text on the Messages stream [2]. Similarly, when messages are written +to the Messages stream [3], they are framed using the WebSocket wire format and +emitted via IO [4]. + +There is a feedback loop via [5] since some input from [1] will be things like +ping, pong and close frames. In these cases the protocol responds by emitting +responses directly back to [4] rather than emitting messages via [2]. + +For the purposes of flow control, we consider the sources of each Readable +stream to be as follows: + +* [2] receives input from [1] +* [4] receives input from [1] and [3] -/***/ }), -/* 57 */ -/***/ (function(module, exports, __webpack_require__) { +The classes below express the relationships described above without prescribing +anything about how parse() and frame() work, other than assuming they emit +'data' events to the IO and Messages streams. They will work with any protocol +driver having these two methods. +**/ -"use strict"; -exports.__esModule = true; -var timers_1 = __webpack_require__(8); -var DelayedStrategy = (function () { - function DelayedStrategy(strategy, _a) { - var number = _a.delay; - this.strategy = strategy; - this.options = { delay: number }; - } - DelayedStrategy.prototype.isSupported = function () { - return this.strategy.isSupported(); - }; - DelayedStrategy.prototype.connect = function (minPriority, callback) { - var strategy = this.strategy; - var runner; - var timer = new timers_1.OneOffTimer(this.options.delay, function () { - runner = strategy.connect(minPriority, callback); - }); - return { - abort: function () { - timer.ensureAborted(); - if (runner) { - runner.abort(); - } - }, - forceMinPriority: function (p) { - minPriority = p; - if (runner) { - runner.forceMinPriority(p); - } - } - }; - }; - return DelayedStrategy; -}()); -exports["default"] = DelayedStrategy; +var Stream = __webpack_require__(7).Stream, + util = __webpack_require__(0); -/***/ }), -/* 58 */ -/***/ (function(module, exports, __webpack_require__) { +var IO = function(driver) { + this.readable = this.writable = true; + this._paused = false; + this._driver = driver; +}; +util.inherits(IO, Stream); -"use strict"; +// The IO pause() and resume() methods will be called when the socket we are +// piping to gets backed up and drains. Since IO output [4] comes from IO input +// [1] and Messages input [3], we need to tell both of those to return false +// from write() when this stream is paused. -exports.__esModule = true; -var IfStrategy = (function () { - function IfStrategy(test, trueBranch, falseBranch) { - this.test = test; - this.trueBranch = trueBranch; - this.falseBranch = falseBranch; - } - IfStrategy.prototype.isSupported = function () { - var branch = this.test() ? this.trueBranch : this.falseBranch; - return branch.isSupported(); - }; - IfStrategy.prototype.connect = function (minPriority, callback) { - var branch = this.test() ? this.trueBranch : this.falseBranch; - return branch.connect(minPriority, callback); - }; - return IfStrategy; -}()); -exports["default"] = IfStrategy; +IO.prototype.pause = function() { + this._paused = true; + this._driver.messages._paused = true; +}; +IO.prototype.resume = function() { + this._paused = false; + this.emit('drain'); -/***/ }), -/* 59 */ -/***/ (function(module, exports, __webpack_require__) { + var messages = this._driver.messages; + messages._paused = false; + messages.emit('drain'); +}; -"use strict"; +// When we receive input from a socket, send it to the parser and tell the +// source whether to back off. +IO.prototype.write = function(chunk) { + if (!this.writable) return false; + this._driver.parse(chunk); + return !this._paused; +}; -exports.__esModule = true; -var FirstConnectedStrategy = (function () { - function FirstConnectedStrategy(strategy) { - this.strategy = strategy; - } - FirstConnectedStrategy.prototype.isSupported = function () { - return this.strategy.isSupported(); - }; - FirstConnectedStrategy.prototype.connect = function (minPriority, callback) { - var runner = this.strategy.connect(minPriority, function (error, handshake) { - if (handshake) { - runner.abort(); - } - callback(error, handshake); - }); - return runner; - }; - return FirstConnectedStrategy; -}()); -exports["default"] = FirstConnectedStrategy; +// The IO end() method will be called when the socket piping into it emits +// 'close' or 'end', i.e. the socket is closed. In this situation the Messages +// stream will not emit any more data so we emit 'end'. +IO.prototype.end = function(chunk) { + if (!this.writable) return; + if (chunk !== undefined) this.write(chunk); + this.writable = false; + + var messages = this._driver.messages; + if (messages.readable) { + messages.readable = messages.writable = false; + messages.emit('end'); + } +}; + +IO.prototype.destroy = function() { + this.end(); +}; + + +var Messages = function(driver) { + this.readable = this.writable = true; + this._paused = false; + this._driver = driver; +}; +util.inherits(Messages, Stream); + +// The Messages pause() and resume() methods will be called when the app that's +// processing the messages gets backed up and drains. If we're emitting +// messages too fast we should tell the source to slow down. Message output [2] +// comes from IO input [1]. + +Messages.prototype.pause = function() { + this._driver.io._paused = true; +}; + +Messages.prototype.resume = function() { + this._driver.io._paused = false; + this._driver.io.emit('drain'); +}; + +// When we receive messages from the user, send them to the formatter and tell +// the source whether to back off. +Messages.prototype.write = function(message) { + if (!this.writable) return false; + if (typeof message === 'string') this._driver.text(message); + else this._driver.binary(message); + return !this._paused; +}; + +// The Messages end() method will be called when a stream piping into it emits +// 'end'. Many streams may be piped into the WebSocket and one of them ending +// does not mean the whole socket is done, so just process the input and move +// on leaving the socket open. +Messages.prototype.end = function(message) { + if (message !== undefined) this.write(message); +}; + +Messages.prototype.destroy = function() {}; + + +exports.IO = IO; +exports.Messages = Messages; /***/ }), -/* 60 */ +/* 24 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -exports.__esModule = true; -function default_1() { - var self = this; - self.timeline.info(self.buildTimelineMessage({ - transport: self.name + (self.options.useTLS ? "s" : "") - })); - if (self.hooks.isInitialized()) { - self.changeState("initialized"); - } - else { - self.onClose(); + +var Buffer = __webpack_require__(1).Buffer; + +var StreamReader = function() { + this._queue = []; + this._queueSize = 0; + this._offset = 0; +}; + +StreamReader.prototype.put = function(buffer) { + if (!buffer || buffer.length === 0) return; + if (!Buffer.isBuffer(buffer)) buffer = Buffer.from(buffer); + this._queue.push(buffer); + this._queueSize += buffer.length; +}; + +StreamReader.prototype.read = function(length) { + if (length > this._queueSize) return null; + if (length === 0) return Buffer.alloc(0); + + this._queueSize -= length; + + var queue = this._queue, + remain = length, + first = queue[0], + buffers, buffer; + + if (first.length >= length) { + if (first.length === length) { + return queue.shift(); + } else { + buffer = first.slice(0, length); + queue[0] = first.slice(length); + return buffer; } -} -exports["default"] = default_1; + } + for (var i = 0, n = queue.length; i < n; i++) { + if (remain < queue[i].length) break; + remain -= queue[i].length; + } + buffers = queue.splice(0, i); -/***/ }), -/* 61 */ -/***/ (function(module, exports, __webpack_require__) { + if (remain > 0 && queue.length > 0) { + buffers.push(queue[0].slice(0, remain)); + queue[0] = queue[0].slice(remain); + } + return Buffer.concat(buffers, length); +}; -"use strict"; +StreamReader.prototype.eachByte = function(callback, context) { + var buffer, n, index; -exports.__esModule = true; -var http_request_1 = __webpack_require__(62); -var http_socket_1 = __webpack_require__(63); -var http_streaming_socket_1 = __webpack_require__(65); -var http_polling_socket_1 = __webpack_require__(66); -var http_xhr_request_1 = __webpack_require__(67); -var HTTP = { - createStreamingSocket: function (url) { - return this.createSocket(http_streaming_socket_1["default"], url); - }, - createPollingSocket: function (url) { - return this.createSocket(http_polling_socket_1["default"], url); - }, - createSocket: function (hooks, url) { - return new http_socket_1["default"](hooks, url); - }, - createXHR: function (method, url) { - return this.createRequest(http_xhr_request_1["default"], method, url); - }, - createRequest: function (hooks, method, url) { - return new http_request_1["default"](hooks, method, url); + while (this._queue.length > 0) { + buffer = this._queue[0]; + n = buffer.length; + + while (this._offset < n) { + index = this._offset; + this._offset += 1; + callback.call(context, buffer[index]); } + this._offset = 0; + this._queue.shift(); + } }; -exports["default"] = HTTP; + +module.exports = StreamReader; /***/ }), -/* 62 */ +/* 25 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var dispatcher_1 = __webpack_require__(6); -var MAX_BUFFER_LENGTH = 256 * 1024; -var HTTPRequest = (function (_super) { - __extends(HTTPRequest, _super); - function HTTPRequest(hooks, method, url) { - var _this = _super.call(this) || this; - _this.hooks = hooks; - _this.method = method; - _this.url = url; - return _this; - } - HTTPRequest.prototype.start = function (payload) { - var _this = this; - this.position = 0; - this.xhr = this.hooks.getRequest(this); - this.unloader = function () { - _this.close(); - }; - runtime_1["default"].addUnloadListener(this.unloader); - this.xhr.open(this.method, this.url, true); - if (this.xhr.setRequestHeader) { - this.xhr.setRequestHeader("Content-Type", "application/json"); - } - this.xhr.send(payload); - }; - HTTPRequest.prototype.close = function () { - if (this.unloader) { - runtime_1["default"].removeUnloadListener(this.unloader); - this.unloader = null; - } - if (this.xhr) { - this.hooks.abortRequest(this.xhr); - this.xhr = null; - } - }; - HTTPRequest.prototype.onChunk = function (status, data) { - while (true) { - var chunk = this.advanceBuffer(data); - if (chunk) { - this.emit("chunk", { status: status, data: chunk }); - } - else { - break; - } - } - if (this.isBufferTooLong(data)) { - this.emit("buffer_too_long"); - } - }; - HTTPRequest.prototype.advanceBuffer = function (buffer) { - var unreadData = buffer.slice(this.position); - var endOfLinePosition = unreadData.indexOf("\n"); - if (endOfLinePosition !== -1) { - this.position += endOfLinePosition + 1; - return unreadData.slice(0, endOfLinePosition); - } - else { - return null; - } - }; - HTTPRequest.prototype.isBufferTooLong = function (buffer) { - return this.position === buffer.length && buffer.length > MAX_BUFFER_LENGTH; - }; - return HTTPRequest; -}(dispatcher_1["default"])); -exports["default"] = HTTPRequest; +var Buffer = __webpack_require__(1).Buffer, + crypto = __webpack_require__(5), + url = __webpack_require__(8), + util = __webpack_require__(0), + HttpParser = __webpack_require__(11), + Base = __webpack_require__(2), + Hybi = __webpack_require__(13), + Proxy = __webpack_require__(35); -/***/ }), -/* 63 */ -/***/ (function(module, exports, __webpack_require__) { +var Client = function(_url, options) { + this.version = 'hybi-' + Hybi.VERSION; + Hybi.call(this, null, _url, options); -"use strict"; + this.readyState = -1; + this._key = Client.generateKey(); + this._accept = Hybi.generateAccept(this._key); + this._http = new HttpParser('response'); -exports.__esModule = true; -var state_1 = __webpack_require__(64); -var util_1 = __webpack_require__(3); -var runtime_1 = __webpack_require__(1); -var autoIncrement = 1; -var HTTPSocket = (function () { - function HTTPSocket(hooks, url) { - this.hooks = hooks; - this.session = randomNumber(1000) + "/" + randomString(8); - this.location = getLocation(url); - this.readyState = state_1["default"].CONNECTING; - this.openStream(); - } - HTTPSocket.prototype.send = function (payload) { - return this.sendRaw(JSON.stringify([payload])); - }; - HTTPSocket.prototype.ping = function () { - this.hooks.sendHeartbeat(this); - }; - HTTPSocket.prototype.close = function (code, reason) { - this.onClose(code, reason, true); - }; - HTTPSocket.prototype.sendRaw = function (payload) { - if (this.readyState === state_1["default"].OPEN) { - try { - runtime_1["default"].createSocketRequest("POST", getUniqueURL(getSendURL(this.location, this.session))).start(payload); - return true; - } - catch (e) { - return false; - } - } - else { - return false; - } - }; - HTTPSocket.prototype.reconnect = function () { - this.closeStream(); - this.openStream(); - }; - ; - HTTPSocket.prototype.onClose = function (code, reason, wasClean) { - this.closeStream(); - this.readyState = state_1["default"].CLOSED; - if (this.onclose) { - this.onclose({ - code: code, - reason: reason, - wasClean: wasClean - }); - } - }; - HTTPSocket.prototype.onChunk = function (chunk) { - if (chunk.status !== 200) { - return; - } - if (this.readyState === state_1["default"].OPEN) { - this.onActivity(); - } - var payload; - var type = chunk.data.slice(0, 1); - switch (type) { - case 'o': - payload = JSON.parse(chunk.data.slice(1) || '{}'); - this.onOpen(payload); - break; - case 'a': - payload = JSON.parse(chunk.data.slice(1) || '[]'); - for (var i = 0; i < payload.length; i++) { - this.onEvent(payload[i]); - } - break; - case 'm': - payload = JSON.parse(chunk.data.slice(1) || 'null'); - this.onEvent(payload); - break; - case 'h': - this.hooks.onHeartbeat(this); - break; - case 'c': - payload = JSON.parse(chunk.data.slice(1) || '[]'); - this.onClose(payload[0], payload[1], true); - break; - } - }; - HTTPSocket.prototype.onOpen = function (options) { - if (this.readyState === state_1["default"].CONNECTING) { - if (options && options.hostname) { - this.location.base = replaceHost(this.location.base, options.hostname); - } - this.readyState = state_1["default"].OPEN; - if (this.onopen) { - this.onopen(); - } - } - else { - this.onClose(1006, "Server lost session", true); - } - }; - HTTPSocket.prototype.onEvent = function (event) { - if (this.readyState === state_1["default"].OPEN && this.onmessage) { - this.onmessage({ data: event }); - } - }; - HTTPSocket.prototype.onActivity = function () { - if (this.onactivity) { - this.onactivity(); - } - }; - HTTPSocket.prototype.onError = function (error) { - if (this.onerror) { - this.onerror(error); - } - }; - HTTPSocket.prototype.openStream = function () { - var _this = this; - this.stream = runtime_1["default"].createSocketRequest("POST", getUniqueURL(this.hooks.getReceiveURL(this.location, this.session))); - this.stream.bind("chunk", function (chunk) { - _this.onChunk(chunk); - }); - this.stream.bind("finished", function (status) { - _this.hooks.onFinished(_this, status); - }); - this.stream.bind("buffer_too_long", function () { - _this.reconnect(); - }); - try { - this.stream.start(); - } - catch (error) { - util_1["default"].defer(function () { - _this.onError(error); - _this.onClose(1006, "Could not start streaming", false); - }); - } - }; - HTTPSocket.prototype.closeStream = function () { - if (this.stream) { - this.stream.unbind_all(); - this.stream.close(); - this.stream = null; - } - }; - return HTTPSocket; -}()); -function getLocation(url) { - var parts = /([^\?]*)\/*(\??.*)/.exec(url); - return { - base: parts[1], - queryString: parts[2] - }; -} -function getSendURL(url, session) { - return url.base + "/" + session + "/xhr_send"; -} -function getUniqueURL(url) { - var separator = (url.indexOf('?') === -1) ? "?" : "&"; - return url + separator + "t=" + (+new Date()) + "&n=" + autoIncrement++; -} -function replaceHost(url, hostname) { - var urlParts = /(https?:\/\/)([^\/:]+)((\/|:)?.*)/.exec(url); - return urlParts[1] + hostname + urlParts[3]; -} -function randomNumber(max) { - return Math.floor(Math.random() * max); -} -function randomString(length) { - var result = []; - for (var i = 0; i < length; i++) { - result.push(randomNumber(32).toString(32)); + var uri = url.parse(this.url), + auth = uri.auth && Buffer.from(uri.auth, 'utf8').toString('base64'); + + if (this.VALID_PROTOCOLS.indexOf(uri.protocol) < 0) + throw new Error(this.url + ' is not a valid WebSocket URL'); + + this._pathname = (uri.pathname || '/') + (uri.search || ''); + + this._headers.set('Host', uri.host); + this._headers.set('Upgrade', 'websocket'); + this._headers.set('Connection', 'Upgrade'); + this._headers.set('Sec-WebSocket-Key', this._key); + this._headers.set('Sec-WebSocket-Version', Hybi.VERSION); + + if (this._protocols.length > 0) + this._headers.set('Sec-WebSocket-Protocol', this._protocols.join(', ')); + + if (auth) + this._headers.set('Authorization', 'Basic ' + auth); +}; +util.inherits(Client, Hybi); + +Client.generateKey = function() { + return crypto.randomBytes(16).toString('base64'); +}; + +var instance = { + VALID_PROTOCOLS: ['ws:', 'wss:'], + + proxy: function(origin, options) { + return new Proxy(this, origin, options); + }, + + start: function() { + if (this.readyState !== -1) return false; + this._write(this._handshakeRequest()); + this.readyState = 0; + return true; + }, + + parse: function(chunk) { + if (this.readyState === 3) return; + if (this.readyState > 0) return Hybi.prototype.parse.call(this, chunk); + + this._http.parse(chunk); + if (!this._http.isComplete()) return; + + this._validateHandshake(); + if (this.readyState === 3) return; + + this._open(); + this.parse(this._http.body); + }, + + _handshakeRequest: function() { + var extensions = this._extensions.generateOffer(); + if (extensions) + this._headers.set('Sec-WebSocket-Extensions', extensions); + + var start = 'GET ' + this._pathname + ' HTTP/1.1', + headers = [start, this._headers.toString(), '']; + + return Buffer.from(headers.join('\r\n'), 'utf8'); + }, + + _failHandshake: function(message) { + message = 'Error during WebSocket handshake: ' + message; + this.readyState = 3; + this.emit('error', new Error(message)); + this.emit('close', new Base.CloseEvent(this.ERRORS.protocol_error, message)); + }, + + _validateHandshake: function() { + this.statusCode = this._http.statusCode; + this.headers = this._http.headers; + + if (this._http.error) + return this._failHandshake(this._http.error.message); + + if (this._http.statusCode !== 101) + return this._failHandshake('Unexpected response code: ' + this._http.statusCode); + + var headers = this._http.headers, + upgrade = headers['upgrade'] || '', + connection = headers['connection'] || '', + accept = headers['sec-websocket-accept'] || '', + protocol = headers['sec-websocket-protocol'] || ''; + + if (upgrade === '') + return this._failHandshake("'Upgrade' header is missing"); + if (upgrade.toLowerCase() !== 'websocket') + return this._failHandshake("'Upgrade' header value is not 'WebSocket'"); + + if (connection === '') + return this._failHandshake("'Connection' header is missing"); + if (connection.toLowerCase() !== 'upgrade') + return this._failHandshake("'Connection' header value is not 'Upgrade'"); + + if (accept !== this._accept) + return this._failHandshake('Sec-WebSocket-Accept mismatch'); + + this.protocol = null; + + if (protocol !== '') { + if (this._protocols.indexOf(protocol) < 0) + return this._failHandshake('Sec-WebSocket-Protocol mismatch'); + else + this.protocol = protocol; } - return result.join(''); -} -exports["default"] = HTTPSocket; + + try { + this._extensions.activate(this.headers['sec-websocket-extensions']); + } catch (e) { + return this._failHandshake(e.message); + } + } +}; + +for (var key in instance) + Client.prototype[key] = instance[key]; + +module.exports = Client; /***/ }), -/* 64 */ +/* 26 */ /***/ (function(module, exports, __webpack_require__) { -"use strict"; +/*jshint node:true */ -exports.__esModule = true; -var State; -(function (State) { - State[State["CONNECTING"] = 0] = "CONNECTING"; - State[State["OPEN"] = 1] = "OPEN"; - State[State["CLOSED"] = 3] = "CLOSED"; -})(State || (State = {})); -exports["default"] = State; +var assert = __webpack_require__(27); + +exports.HTTPParser = HTTPParser; +function HTTPParser(type) { + assert.ok(type === HTTPParser.REQUEST || type === HTTPParser.RESPONSE); + this.type = type; + this.state = type + '_LINE'; + this.info = { + headers: [], + upgrade: false + }; + this.trailers = []; + this.line = ''; + this.isChunked = false; + this.connection = ''; + this.headerSize = 0; // for preventing too big headers + this.body_bytes = null; + this.isUserCall = false; + this.hadError = false; +} +HTTPParser.maxHeaderSize = 80 * 1024; // maxHeaderSize (in bytes) is configurable, but 80kb by default; +HTTPParser.REQUEST = 'REQUEST'; +HTTPParser.RESPONSE = 'RESPONSE'; +var kOnHeaders = HTTPParser.kOnHeaders = 0; +var kOnHeadersComplete = HTTPParser.kOnHeadersComplete = 1; +var kOnBody = HTTPParser.kOnBody = 2; +var kOnMessageComplete = HTTPParser.kOnMessageComplete = 3; +// Some handler stubs, needed for compatibility +HTTPParser.prototype[kOnHeaders] = +HTTPParser.prototype[kOnHeadersComplete] = +HTTPParser.prototype[kOnBody] = +HTTPParser.prototype[kOnMessageComplete] = function () {}; -/***/ }), -/* 65 */ -/***/ (function(module, exports, __webpack_require__) { +var compatMode0_12 = true; +Object.defineProperty(HTTPParser, 'kOnExecute', { + get: function () { + // hack for backward compatibility + compatMode0_12 = false; + return 4; + } + }); -"use strict"; +var methods = exports.methods = HTTPParser.methods = [ + 'DELETE', + 'GET', + 'HEAD', + 'POST', + 'PUT', + 'CONNECT', + 'OPTIONS', + 'TRACE', + 'COPY', + 'LOCK', + 'MKCOL', + 'MOVE', + 'PROPFIND', + 'PROPPATCH', + 'SEARCH', + 'UNLOCK', + 'BIND', + 'REBIND', + 'UNBIND', + 'ACL', + 'REPORT', + 'MKACTIVITY', + 'CHECKOUT', + 'MERGE', + 'M-SEARCH', + 'NOTIFY', + 'SUBSCRIBE', + 'UNSUBSCRIBE', + 'PATCH', + 'PURGE', + 'MKCALENDAR', + 'LINK', + 'UNLINK' +]; +HTTPParser.prototype.reinitialize = HTTPParser; +HTTPParser.prototype.close = +HTTPParser.prototype.pause = +HTTPParser.prototype.resume = +HTTPParser.prototype.free = function () {}; +HTTPParser.prototype._compatMode0_11 = false; +HTTPParser.prototype.getAsyncId = function() { return 0; }; -exports.__esModule = true; -var hooks = { - getReceiveURL: function (url, session) { - return url.base + "/" + session + "/xhr_streaming" + url.queryString; - }, - onHeartbeat: function (socket) { - socket.sendRaw("[]"); - }, - sendHeartbeat: function (socket) { - socket.sendRaw("[]"); - }, - onFinished: function (socket, status) { - socket.onClose(1006, "Connection interrupted (" + status + ")", false); +var headerState = { + REQUEST_LINE: true, + RESPONSE_LINE: true, + HEADER: true +}; +HTTPParser.prototype.execute = function (chunk, start, length) { + if (!(this instanceof HTTPParser)) { + throw new TypeError('not a HTTPParser'); + } + + // backward compat to node < 0.11.4 + // Note: the start and length params were removed in newer version + start = start || 0; + length = typeof length === 'number' ? length : chunk.length; + + this.chunk = chunk; + this.offset = start; + var end = this.end = start + length; + try { + while (this.offset < end) { + if (this[this.state]()) { + break; + } + } + } catch (err) { + if (this.isUserCall) { + throw err; + } + this.hadError = true; + return err; + } + this.chunk = null; + length = this.offset - start; + if (headerState[this.state]) { + this.headerSize += length; + if (this.headerSize > HTTPParser.maxHeaderSize) { + return new Error('max header size exceeded'); } + } + return length; +}; + +var stateFinishAllowed = { + REQUEST_LINE: true, + RESPONSE_LINE: true, + BODY_RAW: true +}; +HTTPParser.prototype.finish = function () { + if (this.hadError) { + return; + } + if (!stateFinishAllowed[this.state]) { + return new Error('invalid state for EOF'); + } + if (this.state === 'BODY_RAW') { + this.userCall()(this[kOnMessageComplete]()); + } }; -exports["default"] = hooks; +// These three methods are used for an internal speed optimization, and it also +// works if theses are noops. Basically consume() asks us to read the bytes +// ourselves, but if we don't do it we get them through execute(). +HTTPParser.prototype.consume = +HTTPParser.prototype.unconsume = +HTTPParser.prototype.getCurrentBuffer = function () {}; -/***/ }), -/* 66 */ -/***/ (function(module, exports, __webpack_require__) { +//For correct error handling - see HTTPParser#execute +//Usage: this.userCall()(userFunction('arg')); +HTTPParser.prototype.userCall = function () { + this.isUserCall = true; + var self = this; + return function (ret) { + self.isUserCall = false; + return ret; + }; +}; -"use strict"; +HTTPParser.prototype.nextRequest = function () { + this.userCall()(this[kOnMessageComplete]()); + this.reinitialize(this.type); +}; -exports.__esModule = true; -var hooks = { - getReceiveURL: function (url, session) { - return url.base + "/" + session + "/xhr" + url.queryString; - }, - onHeartbeat: function () { - }, - sendHeartbeat: function (socket) { - socket.sendRaw("[]"); - }, - onFinished: function (socket, status) { - if (status === 200) { - socket.reconnect(); - } - else { - socket.onClose(1006, "Connection interrupted (" + status + ")", false); - } +HTTPParser.prototype.consumeLine = function () { + var end = this.end, + chunk = this.chunk; + for (var i = this.offset; i < end; i++) { + if (chunk[i] === 0x0a) { // \n + var line = this.line + chunk.toString('ascii', this.offset, i); + if (line.charAt(line.length - 1) === '\r') { + line = line.substr(0, line.length - 1); + } + this.line = ''; + this.offset = i + 1; + return line; } + } + //line split over multiple chunks + this.line += chunk.toString('ascii', this.offset, this.end); + this.offset = this.end; }; -exports["default"] = hooks; - -/***/ }), -/* 67 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +var headerExp = /^([^: \t]+):[ \t]*((?:.*[^ \t])|)/; +var headerContinueExp = /^[ \t]+(.*[^ \t])/; +HTTPParser.prototype.parseHeader = function (line, headers) { + if (line.indexOf('\r') !== -1) { + throw parseErrorCode('HPE_LF_EXPECTED'); + } -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var hooks = { - getRequest: function (socket) { - var Constructor = runtime_1["default"].getXHRAPI(); - var xhr = new Constructor(); - xhr.onreadystatechange = xhr.onprogress = function () { - switch (xhr.readyState) { - case 3: - if (xhr.responseText && xhr.responseText.length > 0) { - socket.onChunk(xhr.status, xhr.responseText); - } - break; - case 4: - if (xhr.responseText && xhr.responseText.length > 0) { - socket.onChunk(xhr.status, xhr.responseText); - } - socket.emit("finished", xhr.status); - socket.close(); - break; - } - }; - return xhr; - }, - abortRequest: function (xhr) { - xhr.onreadystatechange = null; - xhr.abort(); + var match = headerExp.exec(line); + var k = match && match[1]; + if (k) { // skip empty string (malformed header) + headers.push(k); + headers.push(match[2]); + } else { + var matchContinue = headerContinueExp.exec(line); + if (matchContinue && headers.length) { + if (headers[headers.length - 1]) { + headers[headers.length - 1] += ' '; + } + headers[headers.length - 1] += matchContinue[1]; } + } }; -exports["default"] = hooks; - - -/***/ }), -/* 68 */ -/***/ (function(module, exports, __webpack_require__) { -// API references: -// -// * http://dev.w3.org/html5/websockets/ -// * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-eventtarget -// * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-event +var requestExp = /^([A-Z-]+) ([^ ]+) HTTP\/(\d)\.(\d)$/; +HTTPParser.prototype.REQUEST_LINE = function () { + var line = this.consumeLine(); + if (!line) { + return; + } + var match = requestExp.exec(line); + if (match === null) { + throw parseErrorCode('HPE_INVALID_CONSTANT'); + } + this.info.method = this._compatMode0_11 ? match[1] : methods.indexOf(match[1]); + if (this.info.method === -1) { + throw new Error('invalid request method'); + } + if (match[1] === 'CONNECT') { + this.info.upgrade = true; + } + this.info.url = match[2]; + this.info.versionMajor = +match[3]; + this.info.versionMinor = +match[4]; + this.body_bytes = 0; + this.state = 'HEADER'; +}; -var util = __webpack_require__(2), - driver = __webpack_require__(13), - API = __webpack_require__(21); +var responseExp = /^HTTP\/(\d)\.(\d) (\d{3}) ?(.*)$/; +HTTPParser.prototype.RESPONSE_LINE = function () { + var line = this.consumeLine(); + if (!line) { + return; + } + var match = responseExp.exec(line); + if (match === null) { + throw parseErrorCode('HPE_INVALID_CONSTANT'); + } + this.info.versionMajor = +match[1]; + this.info.versionMinor = +match[2]; + var statusCode = this.info.statusCode = +match[3]; + this.info.statusMessage = match[4]; + // Implied zero length. + if ((statusCode / 100 | 0) === 1 || statusCode === 204 || statusCode === 304) { + this.body_bytes = 0; + } + this.state = 'HEADER'; +}; -var WebSocket = function(request, socket, body, protocols, options) { - options = options || {}; +HTTPParser.prototype.shouldKeepAlive = function () { + if (this.info.versionMajor > 0 && this.info.versionMinor > 0) { + if (this.connection.indexOf('close') !== -1) { + return false; + } + } else if (this.connection.indexOf('keep-alive') === -1) { + return false; + } + if (this.body_bytes !== null || this.isChunked) { // || skipBody + return true; + } + return false; +}; - this._stream = socket; - this._driver = driver.http(request, {maxLength: options.maxLength, protocols: protocols}); +HTTPParser.prototype.HEADER = function () { + var line = this.consumeLine(); + if (line === undefined) { + return; + } + var info = this.info; + if (line) { + this.parseHeader(line, info.headers); + } else { + var headers = info.headers; + var hasContentLength = false; + var currentContentLengthValue; + for (var i = 0; i < headers.length; i += 2) { + switch (headers[i].toLowerCase()) { + case 'transfer-encoding': + this.isChunked = headers[i + 1].toLowerCase() === 'chunked'; + break; + case 'content-length': + currentContentLengthValue = +headers[i + 1]; + if (hasContentLength) { + // Fix duplicate Content-Length header with same values. + // Throw error only if values are different. + // Known issues: + // https://github.com/request/request/issues/2091#issuecomment-328715113 + // https://github.com/nodejs/node/issues/6517#issuecomment-216263771 + if (currentContentLengthValue !== this.body_bytes) { + throw parseErrorCode('HPE_UNEXPECTED_CONTENT_LENGTH'); + } + } else { + hasContentLength = true; + this.body_bytes = currentContentLengthValue; + } + break; + case 'connection': + this.connection += headers[i + 1].toLowerCase(); + break; + case 'upgrade': + info.upgrade = true; + break; + } + } - var self = this; - if (!this._stream || !this._stream.writable) return; - if (!this._stream.readable) return this._stream.end(); + if (this.isChunked && hasContentLength) { + throw parseErrorCode('HPE_UNEXPECTED_CONTENT_LENGTH'); + } - var catchup = function() { self._stream.removeListener('data', catchup) }; - this._stream.on('data', catchup); + info.shouldKeepAlive = this.shouldKeepAlive(); + //problem which also exists in original node: we should know skipBody before calling onHeadersComplete + var skipBody; + if (compatMode0_12) { + skipBody = this.userCall()(this[kOnHeadersComplete](info)); + } else { + skipBody = this.userCall()(this[kOnHeadersComplete](info.versionMajor, + info.versionMinor, info.headers, info.method, info.url, info.statusCode, + info.statusMessage, info.upgrade, info.shouldKeepAlive)); + } + if (info.upgrade || skipBody === 2) { + this.nextRequest(); + return true; + } else if (this.isChunked && !skipBody) { + this.state = 'BODY_CHUNKHEAD'; + } else if (skipBody || this.body_bytes === 0) { + this.nextRequest(); + } else if (this.body_bytes === null) { + this.state = 'BODY_RAW'; + } else { + this.state = 'BODY_SIZED'; + } + } +}; - API.call(this, options); +HTTPParser.prototype.BODY_CHUNKHEAD = function () { + var line = this.consumeLine(); + if (line === undefined) { + return; + } + this.body_bytes = parseInt(line, 16); + if (!this.body_bytes) { + this.state = 'BODY_CHUNKTRAILERS'; + } else { + this.state = 'BODY_CHUNK'; + } +}; - process.nextTick(function() { - self._driver.start(); - self._driver.io.write(body); - }); +HTTPParser.prototype.BODY_CHUNK = function () { + var length = Math.min(this.end - this.offset, this.body_bytes); + this.userCall()(this[kOnBody](this.chunk, this.offset, length)); + this.offset += length; + this.body_bytes -= length; + if (!this.body_bytes) { + this.state = 'BODY_CHUNKEMPTYLINE'; + } }; -util.inherits(WebSocket, API); -WebSocket.isWebSocket = function(request) { - return driver.isWebSocket(request); +HTTPParser.prototype.BODY_CHUNKEMPTYLINE = function () { + var line = this.consumeLine(); + if (line === undefined) { + return; + } + assert.equal(line, ''); + this.state = 'BODY_CHUNKHEAD'; }; -WebSocket.validateOptions = function(options, validKeys) { - driver.validateOptions(options, validKeys); +HTTPParser.prototype.BODY_CHUNKTRAILERS = function () { + var line = this.consumeLine(); + if (line === undefined) { + return; + } + if (line) { + this.parseHeader(line, this.trailers); + } else { + if (this.trailers.length) { + this.userCall()(this[kOnHeaders](this.trailers, '')); + } + this.nextRequest(); + } }; -WebSocket.WebSocket = WebSocket; -WebSocket.Client = __webpack_require__(86); -WebSocket.EventSource = __webpack_require__(89); +HTTPParser.prototype.BODY_RAW = function () { + var length = this.end - this.offset; + this.userCall()(this[kOnBody](this.chunk, this.offset, length)); + this.offset = this.end; +}; -module.exports = WebSocket; +HTTPParser.prototype.BODY_SIZED = function () { + var length = Math.min(this.end - this.offset, this.body_bytes); + this.userCall()(this[kOnBody](this.chunk, this.offset, length)); + this.offset += length; + this.body_bytes -= length; + if (!this.body_bytes) { + this.nextRequest(); + } +}; +// backward compat to node < 0.11.6 +['Headers', 'HeadersComplete', 'Body', 'MessageComplete'].forEach(function (name) { + var k = HTTPParser['kOn' + name]; + Object.defineProperty(HTTPParser.prototype, 'on' + name, { + get: function () { + return this[k]; + }, + set: function (to) { + // hack for backward compatibility + this._compatMode0_11 = true; + return (this[k] = to); + } + }); +}); -/***/ }), -/* 69 */ -/***/ (function(module, exports) { +function parseErrorCode(code) { + var err = new Error('Parse Error'); + err.code = code; + return err; +} -module.exports = require("buffer"); /***/ }), -/* 70 */ +/* 27 */ /***/ (function(module, exports) { -module.exports = require("events"); +module.exports = require("assert"); /***/ }), -/* 71 */ +/* 28 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -/** +var Parser = __webpack_require__(29), + Pipeline = __webpack_require__(30); -Streams in a WebSocket connection ---------------------------------- +var Extensions = function() { + this._rsv1 = this._rsv2 = this._rsv3 = null; -We model a WebSocket as two duplex streams: one stream is for the wire protocol -over an I/O socket, and the other is for incoming/outgoing messages. + this._byName = {}; + this._inOrder = []; + this._sessions = []; + this._index = {}; +}; +Extensions.MESSAGE_OPCODES = [1, 2]; - +----------+ +---------+ +----------+ - [1] write(chunk) -->| ~~~~~~~~ +----->| parse() +----->| ~~~~~~~~ +--> emit('data') [2] - | | +----+----+ | | - | | | | | - | IO | | [5] | Messages | - | | V | | - | | +---------+ | | - [4] emit('data') <--+ ~~~~~~~~ |<-----+ frame() |<-----+ ~~~~~~~~ |<-- write(chunk) [3] - +----------+ +---------+ +----------+ +var instance = { + add: function(ext) { + if (typeof ext.name !== 'string') throw new TypeError('extension.name must be a string'); + if (ext.type !== 'permessage') throw new TypeError('extension.type must be "permessage"'); + if (typeof ext.rsv1 !== 'boolean') throw new TypeError('extension.rsv1 must be true or false'); + if (typeof ext.rsv2 !== 'boolean') throw new TypeError('extension.rsv2 must be true or false'); + if (typeof ext.rsv3 !== 'boolean') throw new TypeError('extension.rsv3 must be true or false'); -Message transfer in each direction is simple: IO receives a byte stream [1] and -sends this stream for parsing. The parser will periodically emit a complete -message text on the Messages stream [2]. Similarly, when messages are written -to the Messages stream [3], they are framed using the WebSocket wire format and -emitted via IO [4]. + if (this._byName.hasOwnProperty(ext.name)) + throw new TypeError('An extension with name "' + ext.name + '" is already registered'); -There is a feedback loop via [5] since some input from [1] will be things like -ping, pong and close frames. In these cases the protocol responds by emitting -responses directly back to [4] rather than emitting messages via [2]. + this._byName[ext.name] = ext; + this._inOrder.push(ext); + }, -For the purposes of flow control, we consider the sources of each Readable -stream to be as follows: + generateOffer: function() { + var sessions = [], + offer = [], + index = {}; -* [2] receives input from [1] -* [4] receives input from [1] and [3] + this._inOrder.forEach(function(ext) { + var session = ext.createClientSession(); + if (!session) return; -The classes below express the relationships described above without prescribing -anything about how parse() and frame() work, other than assuming they emit -'data' events to the IO and Messages streams. They will work with any protocol -driver having these two methods. -**/ + var record = [ext, session]; + sessions.push(record); + index[ext.name] = record; + var offers = session.generateOffer(); + offers = offers ? [].concat(offers) : []; -var Stream = __webpack_require__(14).Stream, - util = __webpack_require__(2); + offers.forEach(function(off) { + offer.push(Parser.serializeParams(ext.name, off)); + }, this); + }, this); + this._sessions = sessions; + this._index = index; -var IO = function(driver) { - this.readable = this.writable = true; - this._paused = false; - this._driver = driver; -}; -util.inherits(IO, Stream); + return offer.length > 0 ? offer.join(', ') : null; + }, -// The IO pause() and resume() methods will be called when the socket we are -// piping to gets backed up and drains. Since IO output [4] comes from IO input -// [1] and Messages input [3], we need to tell both of those to return false -// from write() when this stream is paused. + activate: function(header) { + var responses = Parser.parseHeader(header), + sessions = []; -IO.prototype.pause = function() { - this._paused = true; - this._driver.messages._paused = true; -}; + responses.eachOffer(function(name, params) { + var record = this._index[name]; -IO.prototype.resume = function() { - this._paused = false; - this.emit('drain'); + if (!record) + throw new Error('Server sent an extension response for unknown extension "' + name + '"'); - var messages = this._driver.messages; - messages._paused = false; - messages.emit('drain'); -}; + var ext = record[0], + session = record[1], + reserved = this._reserved(ext); -// When we receive input from a socket, send it to the parser and tell the -// source whether to back off. -IO.prototype.write = function(chunk) { - if (!this.writable) return false; - this._driver.parse(chunk); - return !this._paused; -}; + if (reserved) + throw new Error('Server sent two extension responses that use the RSV' + + reserved[0] + ' bit: "' + + reserved[1] + '" and "' + ext.name + '"'); -// The IO end() method will be called when the socket piping into it emits -// 'close' or 'end', i.e. the socket is closed. In this situation the Messages -// stream will not emit any more data so we emit 'end'. -IO.prototype.end = function(chunk) { - if (!this.writable) return; - if (chunk !== undefined) this.write(chunk); - this.writable = false; + if (session.activate(params) !== true) + throw new Error('Server sent unacceptable extension parameters: ' + + Parser.serializeParams(name, params)); - var messages = this._driver.messages; - if (messages.readable) { - messages.readable = messages.writable = false; - messages.emit('end'); - } -}; + this._reserve(ext); + sessions.push(record); + }, this); -IO.prototype.destroy = function() { - this.end(); -}; + this._sessions = sessions; + this._pipeline = new Pipeline(sessions); + }, + + generateResponse: function(header) { + var sessions = [], + response = [], + offers = Parser.parseHeader(header); + + this._inOrder.forEach(function(ext) { + var offer = offers.byName(ext.name); + if (offer.length === 0 || this._reserved(ext)) return; + + var session = ext.createServerSession(offer); + if (!session) return; + + this._reserve(ext); + sessions.push([ext, session]); + response.push(Parser.serializeParams(ext.name, session.generateResponse())); + }, this); + + this._sessions = sessions; + this._pipeline = new Pipeline(sessions); + + return response.length > 0 ? response.join(', ') : null; + }, + + validFrameRsv: function(frame) { + var allowed = {rsv1: false, rsv2: false, rsv3: false}, + ext; + if (Extensions.MESSAGE_OPCODES.indexOf(frame.opcode) >= 0) { + for (var i = 0, n = this._sessions.length; i < n; i++) { + ext = this._sessions[i][0]; + allowed.rsv1 = allowed.rsv1 || ext.rsv1; + allowed.rsv2 = allowed.rsv2 || ext.rsv2; + allowed.rsv3 = allowed.rsv3 || ext.rsv3; + } + } -var Messages = function(driver) { - this.readable = this.writable = true; - this._paused = false; - this._driver = driver; -}; -util.inherits(Messages, Stream); + return (allowed.rsv1 || !frame.rsv1) && + (allowed.rsv2 || !frame.rsv2) && + (allowed.rsv3 || !frame.rsv3); + }, -// The Messages pause() and resume() methods will be called when the app that's -// processing the messages gets backed up and drains. If we're emitting -// messages too fast we should tell the source to slow down. Message output [2] -// comes from IO input [1]. + processIncomingMessage: function(message, callback, context) { + this._pipeline.processIncomingMessage(message, callback, context); + }, -Messages.prototype.pause = function() { - this._driver.io._paused = true; -}; + processOutgoingMessage: function(message, callback, context) { + this._pipeline.processOutgoingMessage(message, callback, context); + }, -Messages.prototype.resume = function() { - this._driver.io._paused = false; - this._driver.io.emit('drain'); -}; + close: function(callback, context) { + if (!this._pipeline) return callback.call(context); + this._pipeline.close(callback, context); + }, -// When we receive messages from the user, send them to the formatter and tell -// the source whether to back off. -Messages.prototype.write = function(message) { - if (!this.writable) return false; - if (typeof message === 'string') this._driver.text(message); - else this._driver.binary(message); - return !this._paused; -}; + _reserve: function(ext) { + this._rsv1 = this._rsv1 || (ext.rsv1 && ext.name); + this._rsv2 = this._rsv2 || (ext.rsv2 && ext.name); + this._rsv3 = this._rsv3 || (ext.rsv3 && ext.name); + }, -// The Messages end() method will be called when a stream piping into it emits -// 'end'. Many streams may be piped into the WebSocket and one of them ending -// does not mean the whole socket is done, so just process the input and move -// on leaving the socket open. -Messages.prototype.end = function(message) { - if (message !== undefined) this.write(message); + _reserved: function(ext) { + if (this._rsv1 && ext.rsv1) return [1, this._rsv1]; + if (this._rsv2 && ext.rsv2) return [2, this._rsv2]; + if (this._rsv3 && ext.rsv3) return [3, this._rsv3]; + return false; + } }; -Messages.prototype.destroy = function() {}; - +for (var key in instance) + Extensions.prototype[key] = instance[key]; -exports.IO = IO; -exports.Messages = Messages; +module.exports = Extensions; /***/ }), -/* 72 */ +/* 29 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -var Buffer = __webpack_require__(5).Buffer; +var TOKEN = /([!#\$%&'\*\+\-\.\^_`\|~0-9A-Za-z]+)/, + NOTOKEN = /([^!#\$%&'\*\+\-\.\^_`\|~0-9A-Za-z])/g, + QUOTED = /"((?:\\[\x00-\x7f]|[^\x00-\x08\x0a-\x1f\x7f"])*)"/, + PARAM = new RegExp(TOKEN.source + '(?:=(?:' + TOKEN.source + '|' + QUOTED.source + '))?'), + EXT = new RegExp(TOKEN.source + '(?: *; *' + PARAM.source + ')*', 'g'), + EXT_LIST = new RegExp('^' + EXT.source + '(?: *, *' + EXT.source + ')*$'), + NUMBER = /^-?(0|[1-9][0-9]*)(\.[0-9]+)?$/; -var StreamReader = function() { - this._queue = []; - this._queueSize = 0; - this._offset = 0; -}; +var hasOwnProperty = Object.prototype.hasOwnProperty; -StreamReader.prototype.put = function(buffer) { - if (!buffer || buffer.length === 0) return; - if (!Buffer.isBuffer(buffer)) buffer = Buffer.from(buffer); - this._queue.push(buffer); - this._queueSize += buffer.length; -}; +var Parser = { + parseHeader: function(header) { + var offers = new Offers(); + if (header === '' || header === undefined) return offers; -StreamReader.prototype.read = function(length) { - if (length > this._queueSize) return null; - if (length === 0) return Buffer.alloc(0); + if (!EXT_LIST.test(header)) + throw new SyntaxError('Invalid Sec-WebSocket-Extensions header: ' + header); - this._queueSize -= length; + var values = header.match(EXT); - var queue = this._queue, - remain = length, - first = queue[0], - buffers, buffer; + values.forEach(function(value) { + var params = value.match(new RegExp(PARAM.source, 'g')), + name = params.shift(), + offer = {}; - if (first.length >= length) { - if (first.length === length) { - return queue.shift(); - } else { - buffer = first.slice(0, length); - queue[0] = first.slice(length); - return buffer; - } - } + params.forEach(function(param) { + var args = param.match(PARAM), key = args[1], data; - for (var i = 0, n = queue.length; i < n; i++) { - if (remain < queue[i].length) break; - remain -= queue[i].length; - } - buffers = queue.splice(0, i); + if (args[2] !== undefined) { + data = args[2]; + } else if (args[3] !== undefined) { + data = args[3].replace(/\\/g, ''); + } else { + data = true; + } + if (NUMBER.test(data)) data = parseFloat(data); - if (remain > 0 && queue.length > 0) { - buffers.push(queue[0].slice(0, remain)); - queue[0] = queue[0].slice(remain); - } - return Buffer.concat(buffers, length); -}; + if (hasOwnProperty.call(offer, key)) { + offer[key] = [].concat(offer[key]); + offer[key].push(data); + } else { + offer[key] = data; + } + }, this); + offers.push(name, offer); + }, this); -StreamReader.prototype.eachByte = function(callback, context) { - var buffer, n, index; + return offers; + }, - while (this._queue.length > 0) { - buffer = this._queue[0]; - n = buffer.length; + serializeParams: function(name, params) { + var values = []; - while (this._offset < n) { - index = this._offset; - this._offset += 1; - callback.call(context, buffer[index]); - } - this._offset = 0; - this._queue.shift(); + var print = function(key, value) { + if (value instanceof Array) { + value.forEach(function(v) { print(key, v) }); + } else if (value === true) { + values.push(key); + } else if (typeof value === 'number') { + values.push(key + '=' + value); + } else if (NOTOKEN.test(value)) { + values.push(key + '="' + value.replace(/"/g, '\\"') + '"'); + } else { + values.push(key + '=' + value); + } + }; + + for (var key in params) print(key, params[key]); + + return [name].concat(values).join('; '); } }; -module.exports = StreamReader; - +var Offers = function() { + this._byName = {}; + this._inOrder = []; +}; -/***/ }), -/* 73 */ -/***/ (function(module, exports, __webpack_require__) { +Offers.prototype.push = function(name, params) { + if (!hasOwnProperty.call(this._byName, name)) + this._byName[name] = []; -"use strict"; + this._byName[name].push(params); + this._inOrder.push({name: name, params: params}); +}; +Offers.prototype.eachOffer = function(callback, context) { + var list = this._inOrder; + for (var i = 0, n = list.length; i < n; i++) + callback.call(context, list[i].name, list[i].params); +}; -var Buffer = __webpack_require__(5).Buffer, - crypto = __webpack_require__(11), - url = __webpack_require__(15), - util = __webpack_require__(2), - HttpParser = __webpack_require__(20), - Base = __webpack_require__(7), - Hybi = __webpack_require__(26), - Proxy = __webpack_require__(83); +Offers.prototype.byName = function(name) { + return this._byName[name] || []; +}; -var Client = function(_url, options) { - this.version = 'hybi-' + Hybi.VERSION; - Hybi.call(this, null, _url, options); +Offers.prototype.toArray = function() { + return this._inOrder.slice(); +}; - this.readyState = -1; - this._key = Client.generateKey(); - this._accept = Hybi.generateAccept(this._key); - this._http = new HttpParser('response'); +module.exports = Parser; - var uri = url.parse(this.url), - auth = uri.auth && Buffer.from(uri.auth, 'utf8').toString('base64'); - if (this.VALID_PROTOCOLS.indexOf(uri.protocol) < 0) - throw new Error(this.url + ' is not a valid WebSocket URL'); +/***/ }), +/* 30 */ +/***/ (function(module, exports, __webpack_require__) { - this._pathname = (uri.pathname || '/') + (uri.search || ''); +"use strict"; - this._headers.set('Host', uri.host); - this._headers.set('Upgrade', 'websocket'); - this._headers.set('Connection', 'Upgrade'); - this._headers.set('Sec-WebSocket-Key', this._key); - this._headers.set('Sec-WebSocket-Version', Hybi.VERSION); - if (this._protocols.length > 0) - this._headers.set('Sec-WebSocket-Protocol', this._protocols.join(', ')); +var Cell = __webpack_require__(31), + Pledge = __webpack_require__(15); - if (auth) - this._headers.set('Authorization', 'Basic ' + auth); +var Pipeline = function(sessions) { + this._cells = sessions.map(function(session) { return new Cell(session) }); + this._stopped = {incoming: false, outgoing: false}; }; -util.inherits(Client, Hybi); -Client.generateKey = function() { - return crypto.randomBytes(16).toString('base64'); +Pipeline.prototype.processIncomingMessage = function(message, callback, context) { + if (this._stopped.incoming) return; + this._loop('incoming', this._cells.length - 1, -1, -1, message, callback, context); }; -var instance = { - VALID_PROTOCOLS: ['ws:', 'wss:'], - - proxy: function(origin, options) { - return new Proxy(this, origin, options); - }, +Pipeline.prototype.processOutgoingMessage = function(message, callback, context) { + if (this._stopped.outgoing) return; + this._loop('outgoing', 0, this._cells.length, 1, message, callback, context); +}; - start: function() { - if (this.readyState !== -1) return false; - this._write(this._handshakeRequest()); - this.readyState = 0; - return true; - }, +Pipeline.prototype.close = function(callback, context) { + this._stopped = {incoming: true, outgoing: true}; - parse: function(chunk) { - if (this.readyState === 3) return; - if (this.readyState > 0) return Hybi.prototype.parse.call(this, chunk); + var closed = this._cells.map(function(a) { return a.close() }); + if (callback) + Pledge.all(closed).then(function() { callback.call(context) }); +}; - this._http.parse(chunk); - if (!this._http.isComplete()) return; +Pipeline.prototype._loop = function(direction, start, end, step, message, callback, context) { + var cells = this._cells, + n = cells.length, + self = this; - this._validateHandshake(); - if (this.readyState === 3) return; + while (n--) cells[n].pending(direction); - this._open(); - this.parse(this._http.body); - }, + var pipe = function(index, error, msg) { + if (index === end) return callback.call(context, error, msg); - _handshakeRequest: function() { - var extensions = this._extensions.generateOffer(); - if (extensions) - this._headers.set('Sec-WebSocket-Extensions', extensions); + cells[index][direction](error, msg, function(err, m) { + if (err) self._stopped[direction] = true; + pipe(index + step, err, m); + }); + }; + pipe(start, null, message); +}; - var start = 'GET ' + this._pathname + ' HTTP/1.1', - headers = [start, this._headers.toString(), '']; +module.exports = Pipeline; - return Buffer.from(headers.join('\r\n'), 'utf8'); - }, - _failHandshake: function(message) { - message = 'Error during WebSocket handshake: ' + message; - this.readyState = 3; - this.emit('error', new Error(message)); - this.emit('close', new Base.CloseEvent(this.ERRORS.protocol_error, message)); - }, +/***/ }), +/* 31 */ +/***/ (function(module, exports, __webpack_require__) { - _validateHandshake: function() { - this.statusCode = this._http.statusCode; - this.headers = this._http.headers; +"use strict"; - if (this._http.error) - return this._failHandshake(this._http.error.message); - if (this._http.statusCode !== 101) - return this._failHandshake('Unexpected response code: ' + this._http.statusCode); +var Functor = __webpack_require__(32), + Pledge = __webpack_require__(15); - var headers = this._http.headers, - upgrade = headers['upgrade'] || '', - connection = headers['connection'] || '', - accept = headers['sec-websocket-accept'] || '', - protocol = headers['sec-websocket-protocol'] || ''; +var Cell = function(tuple) { + this._ext = tuple[0]; + this._session = tuple[1]; - if (upgrade === '') - return this._failHandshake("'Upgrade' header is missing"); - if (upgrade.toLowerCase() !== 'websocket') - return this._failHandshake("'Upgrade' header value is not 'WebSocket'"); + this._functors = { + incoming: new Functor(this._session, 'processIncomingMessage'), + outgoing: new Functor(this._session, 'processOutgoingMessage') + }; +}; - if (connection === '') - return this._failHandshake("'Connection' header is missing"); - if (connection.toLowerCase() !== 'upgrade') - return this._failHandshake("'Connection' header value is not 'Upgrade'"); +Cell.prototype.pending = function(direction) { + var functor = this._functors[direction]; + if (!functor._stopped) functor.pending += 1; +}; - if (accept !== this._accept) - return this._failHandshake('Sec-WebSocket-Accept mismatch'); +Cell.prototype.incoming = function(error, message, callback, context) { + this._exec('incoming', error, message, callback, context); +}; - this.protocol = null; +Cell.prototype.outgoing = function(error, message, callback, context) { + this._exec('outgoing', error, message, callback, context); +}; - if (protocol !== '') { - if (this._protocols.indexOf(protocol) < 0) - return this._failHandshake('Sec-WebSocket-Protocol mismatch'); - else - this.protocol = protocol; - } +Cell.prototype.close = function() { + this._closed = this._closed || new Pledge(); + this._doClose(); + return this._closed; +}; - try { - this._extensions.activate(this.headers['sec-websocket-extensions']); - } catch (e) { - return this._failHandshake(e.message); - } - } +Cell.prototype._exec = function(direction, error, message, callback, context) { + this._functors[direction].call(error, message, function(err, msg) { + if (err) err.message = this._ext.name + ': ' + err.message; + callback.call(context, err, msg); + this._doClose(); + }, this); }; -for (var key in instance) - Client.prototype[key] = instance[key]; +Cell.prototype._doClose = function() { + var fin = this._functors.incoming, + fout = this._functors.outgoing; -module.exports = Client; + if (!this._closed || fin.pending + fout.pending !== 0) return; + if (this._session) this._session.close(); + this._session = null; + this._closed.done(); +}; + +module.exports = Cell; /***/ }), -/* 74 */ +/* 32 */ /***/ (function(module, exports, __webpack_require__) { -/*jshint node:true */ +"use strict"; -var assert = __webpack_require__(75); -exports.HTTPParser = HTTPParser; -function HTTPParser(type) { - assert.ok(type === HTTPParser.REQUEST || type === HTTPParser.RESPONSE); - this.type = type; - this.state = type + '_LINE'; - this.info = { - headers: [], - upgrade: false - }; - this.trailers = []; - this.line = ''; - this.isChunked = false; - this.connection = ''; - this.headerSize = 0; // for preventing too big headers - this.body_bytes = null; - this.isUserCall = false; - this.hadError = false; -} -HTTPParser.maxHeaderSize = 80 * 1024; // maxHeaderSize (in bytes) is configurable, but 80kb by default; -HTTPParser.REQUEST = 'REQUEST'; -HTTPParser.RESPONSE = 'RESPONSE'; -var kOnHeaders = HTTPParser.kOnHeaders = 0; -var kOnHeadersComplete = HTTPParser.kOnHeadersComplete = 1; -var kOnBody = HTTPParser.kOnBody = 2; -var kOnMessageComplete = HTTPParser.kOnMessageComplete = 3; +var RingBuffer = __webpack_require__(14); -// Some handler stubs, needed for compatibility -HTTPParser.prototype[kOnHeaders] = -HTTPParser.prototype[kOnHeadersComplete] = -HTTPParser.prototype[kOnBody] = -HTTPParser.prototype[kOnMessageComplete] = function () {}; +var Functor = function(session, method) { + this._session = session; + this._method = method; + this._queue = new RingBuffer(Functor.QUEUE_SIZE); + this._stopped = false; + this.pending = 0; +}; -var compatMode0_12 = true; -Object.defineProperty(HTTPParser, 'kOnExecute', { - get: function () { - // hack for backward compatibility - compatMode0_12 = false; - return 4; - } - }); +Functor.QUEUE_SIZE = 8; -var methods = exports.methods = HTTPParser.methods = [ - 'DELETE', - 'GET', - 'HEAD', - 'POST', - 'PUT', - 'CONNECT', - 'OPTIONS', - 'TRACE', - 'COPY', - 'LOCK', - 'MKCOL', - 'MOVE', - 'PROPFIND', - 'PROPPATCH', - 'SEARCH', - 'UNLOCK', - 'BIND', - 'REBIND', - 'UNBIND', - 'ACL', - 'REPORT', - 'MKACTIVITY', - 'CHECKOUT', - 'MERGE', - 'M-SEARCH', - 'NOTIFY', - 'SUBSCRIBE', - 'UNSUBSCRIBE', - 'PATCH', - 'PURGE', - 'MKCALENDAR', - 'LINK', - 'UNLINK' -]; -HTTPParser.prototype.reinitialize = HTTPParser; -HTTPParser.prototype.close = -HTTPParser.prototype.pause = -HTTPParser.prototype.resume = -HTTPParser.prototype.free = function () {}; -HTTPParser.prototype._compatMode0_11 = false; -HTTPParser.prototype.getAsyncId = function() { return 0; }; +Functor.prototype.call = function(error, message, callback, context) { + if (this._stopped) return; -var headerState = { - REQUEST_LINE: true, - RESPONSE_LINE: true, - HEADER: true -}; -HTTPParser.prototype.execute = function (chunk, start, length) { - if (!(this instanceof HTTPParser)) { - throw new TypeError('not a HTTPParser'); + var record = {error: error, message: message, callback: callback, context: context, done: false}, + called = false, + self = this; + + this._queue.push(record); + + if (record.error) { + record.done = true; + this._stop(); + return this._flushQueue(); } - // backward compat to node < 0.11.4 - // Note: the start and length params were removed in newer version - start = start || 0; - length = typeof length === 'number' ? length : chunk.length; + var handler = function(err, msg) { + if (!(called ^ (called = true))) return; - this.chunk = chunk; - this.offset = start; - var end = this.end = start + length; - try { - while (this.offset < end) { - if (this[this.state]()) { - break; - } + if (err) { + self._stop(); + record.error = err; + record.message = null; + } else { + record.message = msg; } + + record.done = true; + self._flushQueue(); + }; + + try { + this._session[this._method](message, handler); } catch (err) { - if (this.isUserCall) { - throw err; - } - this.hadError = true; - return err; - } - this.chunk = null; - length = this.offset - start; - if (headerState[this.state]) { - this.headerSize += length; - if (this.headerSize > HTTPParser.maxHeaderSize) { - return new Error('max header size exceeded'); - } + handler(err); } - return length; }; -var stateFinishAllowed = { - REQUEST_LINE: true, - RESPONSE_LINE: true, - BODY_RAW: true +Functor.prototype._stop = function() { + this.pending = this._queue.length; + this._stopped = true; }; -HTTPParser.prototype.finish = function () { - if (this.hadError) { - return; - } - if (!stateFinishAllowed[this.state]) { - return new Error('invalid state for EOF'); - } - if (this.state === 'BODY_RAW') { - this.userCall()(this[kOnMessageComplete]()); + +Functor.prototype._flushQueue = function() { + var queue = this._queue, record; + + while (queue.length > 0 && queue.peek().done) { + record = queue.shift(); + if (record.error) { + this.pending = 0; + queue.clear(); + } else { + this.pending -= 1; + } + record.callback.call(record.context, record.error, record.message); } }; -// These three methods are used for an internal speed optimization, and it also -// works if theses are noops. Basically consume() asks us to read the bytes -// ourselves, but if we don't do it we get them through execute(). -HTTPParser.prototype.consume = -HTTPParser.prototype.unconsume = -HTTPParser.prototype.getCurrentBuffer = function () {}; +module.exports = Functor; -//For correct error handling - see HTTPParser#execute -//Usage: this.userCall()(userFunction('arg')); -HTTPParser.prototype.userCall = function () { - this.isUserCall = true; - var self = this; - return function (ret) { - self.isUserCall = false; - return ret; - }; -}; -HTTPParser.prototype.nextRequest = function () { - this.userCall()(this[kOnMessageComplete]()); - this.reinitialize(this.type); -}; +/***/ }), +/* 33 */ +/***/ (function(module, exports, __webpack_require__) { -HTTPParser.prototype.consumeLine = function () { - var end = this.end, - chunk = this.chunk; - for (var i = this.offset; i < end; i++) { - if (chunk[i] === 0x0a) { // \n - var line = this.line + chunk.toString('ascii', this.offset, i); - if (line.charAt(line.length - 1) === '\r') { - line = line.substr(0, line.length - 1); - } - this.line = ''; - this.offset = i + 1; - return line; - } - } - //line split over multiple chunks - this.line += chunk.toString('ascii', this.offset, this.end); - this.offset = this.end; +"use strict"; + + +var Frame = function() {}; + +var instance = { + final: false, + rsv1: false, + rsv2: false, + rsv3: false, + opcode: null, + masked: false, + maskingKey: null, + lengthBytes: 1, + length: 0, + payload: null }; -var headerExp = /^([^: \t]+):[ \t]*((?:.*[^ \t])|)/; -var headerContinueExp = /^[ \t]+(.*[^ \t])/; -HTTPParser.prototype.parseHeader = function (line, headers) { - if (line.indexOf('\r') !== -1) { - throw parseErrorCode('HPE_LF_EXPECTED'); - } +for (var key in instance) + Frame.prototype[key] = instance[key]; - var match = headerExp.exec(line); - var k = match && match[1]; - if (k) { // skip empty string (malformed header) - headers.push(k); - headers.push(match[2]); - } else { - var matchContinue = headerContinueExp.exec(line); - if (matchContinue && headers.length) { - if (headers[headers.length - 1]) { - headers[headers.length - 1] += ' '; - } - headers[headers.length - 1] += matchContinue[1]; - } - } +module.exports = Frame; + + +/***/ }), +/* 34 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var Buffer = __webpack_require__(1).Buffer; + +var Message = function() { + this.rsv1 = false; + this.rsv2 = false; + this.rsv3 = false; + this.opcode = null; + this.length = 0; + this._chunks = []; }; -var requestExp = /^([A-Z-]+) ([^ ]+) HTTP\/(\d)\.(\d)$/; -HTTPParser.prototype.REQUEST_LINE = function () { - var line = this.consumeLine(); - if (!line) { - return; - } - var match = requestExp.exec(line); - if (match === null) { - throw parseErrorCode('HPE_INVALID_CONSTANT'); - } - this.info.method = this._compatMode0_11 ? match[1] : methods.indexOf(match[1]); - if (this.info.method === -1) { - throw new Error('invalid request method'); - } - if (match[1] === 'CONNECT') { - this.info.upgrade = true; +var instance = { + read: function() { + return this.data = this.data || Buffer.concat(this._chunks, this.length); + }, + + pushFrame: function(frame) { + this.rsv1 = this.rsv1 || frame.rsv1; + this.rsv2 = this.rsv2 || frame.rsv2; + this.rsv3 = this.rsv3 || frame.rsv3; + + if (this.opcode === null) this.opcode = frame.opcode; + + this._chunks.push(frame.payload); + this.length += frame.length; } - this.info.url = match[2]; - this.info.versionMajor = +match[3]; - this.info.versionMinor = +match[4]; - this.body_bytes = 0; - this.state = 'HEADER'; }; -var responseExp = /^HTTP\/(\d)\.(\d) (\d{3}) ?(.*)$/; -HTTPParser.prototype.RESPONSE_LINE = function () { - var line = this.consumeLine(); - if (!line) { - return; - } - var match = responseExp.exec(line); - if (match === null) { - throw parseErrorCode('HPE_INVALID_CONSTANT'); - } - this.info.versionMajor = +match[1]; - this.info.versionMinor = +match[2]; - var statusCode = this.info.statusCode = +match[3]; - this.info.statusMessage = match[4]; - // Implied zero length. - if ((statusCode / 100 | 0) === 1 || statusCode === 204 || statusCode === 304) { - this.body_bytes = 0; - } - this.state = 'HEADER'; +for (var key in instance) + Message.prototype[key] = instance[key]; + +module.exports = Message; + + +/***/ }), +/* 35 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var Buffer = __webpack_require__(1).Buffer, + Stream = __webpack_require__(7).Stream, + url = __webpack_require__(8), + util = __webpack_require__(0), + Base = __webpack_require__(2), + Headers = __webpack_require__(10), + HttpParser = __webpack_require__(11); + +var PORTS = { 'ws:': 80, 'wss:': 443 }; + +var Proxy = function(client, origin, options) { + this._client = client; + this._http = new HttpParser('response'); + this._origin = (typeof client.url === 'object') ? client.url : url.parse(client.url); + this._url = (typeof origin === 'object') ? origin : url.parse(origin); + this._options = options || {}; + this._state = 0; + + this.readable = this.writable = true; + this._paused = false; + + this._headers = new Headers(); + this._headers.set('Host', this._origin.host); + this._headers.set('Connection', 'keep-alive'); + this._headers.set('Proxy-Connection', 'keep-alive'); + + var auth = this._url.auth && Buffer.from(this._url.auth, 'utf8').toString('base64'); + if (auth) this._headers.set('Proxy-Authorization', 'Basic ' + auth); }; +util.inherits(Proxy, Stream); -HTTPParser.prototype.shouldKeepAlive = function () { - if (this.info.versionMajor > 0 && this.info.versionMinor > 0) { - if (this.connection.indexOf('close') !== -1) { - return false; - } - } else if (this.connection.indexOf('keep-alive') === -1) { - return false; - } - if (this.body_bytes !== null || this.isChunked) { // || skipBody +var instance = { + setHeader: function(name, value) { + if (this._state !== 0) return false; + this._headers.set(name, value); + return true; + }, + + start: function() { + if (this._state !== 0) return false; + this._state = 1; + + var origin = this._origin, + port = origin.port || PORTS[origin.protocol], + start = 'CONNECT ' + origin.hostname + ':' + port + ' HTTP/1.1'; + + var headers = [start, this._headers.toString(), '']; + + this.emit('data', Buffer.from(headers.join('\r\n'), 'utf8')); return true; - } - return false; -}; + }, -HTTPParser.prototype.HEADER = function () { - var line = this.consumeLine(); - if (line === undefined) { - return; - } - var info = this.info; - if (line) { - this.parseHeader(line, info.headers); - } else { - var headers = info.headers; - var hasContentLength = false; - var currentContentLengthValue; - for (var i = 0; i < headers.length; i += 2) { - switch (headers[i].toLowerCase()) { - case 'transfer-encoding': - this.isChunked = headers[i + 1].toLowerCase() === 'chunked'; - break; - case 'content-length': - currentContentLengthValue = +headers[i + 1]; - if (hasContentLength) { - // Fix duplicate Content-Length header with same values. - // Throw error only if values are different. - // Known issues: - // https://github.com/request/request/issues/2091#issuecomment-328715113 - // https://github.com/nodejs/node/issues/6517#issuecomment-216263771 - if (currentContentLengthValue !== this.body_bytes) { - throw parseErrorCode('HPE_UNEXPECTED_CONTENT_LENGTH'); - } - } else { - hasContentLength = true; - this.body_bytes = currentContentLengthValue; - } - break; - case 'connection': - this.connection += headers[i + 1].toLowerCase(); - break; - case 'upgrade': - info.upgrade = true; - break; - } - } + pause: function() { + this._paused = true; + }, - if (this.isChunked && hasContentLength) { - throw parseErrorCode('HPE_UNEXPECTED_CONTENT_LENGTH'); - } + resume: function() { + this._paused = false; + this.emit('drain'); + }, - info.shouldKeepAlive = this.shouldKeepAlive(); - //problem which also exists in original node: we should know skipBody before calling onHeadersComplete - var skipBody; - if (compatMode0_12) { - skipBody = this.userCall()(this[kOnHeadersComplete](info)); - } else { - skipBody = this.userCall()(this[kOnHeadersComplete](info.versionMajor, - info.versionMinor, info.headers, info.method, info.url, info.statusCode, - info.statusMessage, info.upgrade, info.shouldKeepAlive)); - } - if (info.upgrade || skipBody === 2) { - this.nextRequest(); - return true; - } else if (this.isChunked && !skipBody) { - this.state = 'BODY_CHUNKHEAD'; - } else if (skipBody || this.body_bytes === 0) { - this.nextRequest(); - } else if (this.body_bytes === null) { - this.state = 'BODY_RAW'; + write: function(chunk) { + if (!this.writable) return false; + + this._http.parse(chunk); + if (!this._http.isComplete()) return !this._paused; + + this.statusCode = this._http.statusCode; + this.headers = this._http.headers; + + if (this.statusCode === 200) { + this.emit('connect', new Base.ConnectEvent()); } else { - this.state = 'BODY_SIZED'; + var message = "Can't establish a connection to the server at " + this._origin.href; + this.emit('error', new Error(message)); } - } -}; + this.end(); + return !this._paused; + }, -HTTPParser.prototype.BODY_CHUNKHEAD = function () { - var line = this.consumeLine(); - if (line === undefined) { - return; - } - this.body_bytes = parseInt(line, 16); - if (!this.body_bytes) { - this.state = 'BODY_CHUNKTRAILERS'; - } else { - this.state = 'BODY_CHUNK'; - } -}; + end: function(chunk) { + if (!this.writable) return; + if (chunk !== undefined) this.write(chunk); + this.readable = this.writable = false; + this.emit('close'); + this.emit('end'); + }, -HTTPParser.prototype.BODY_CHUNK = function () { - var length = Math.min(this.end - this.offset, this.body_bytes); - this.userCall()(this[kOnBody](this.chunk, this.offset, length)); - this.offset += length; - this.body_bytes -= length; - if (!this.body_bytes) { - this.state = 'BODY_CHUNKEMPTYLINE'; + destroy: function() { + this.end(); } }; -HTTPParser.prototype.BODY_CHUNKEMPTYLINE = function () { - var line = this.consumeLine(); - if (line === undefined) { - return; - } - assert.equal(line, ''); - this.state = 'BODY_CHUNKHEAD'; -}; +for (var key in instance) + Proxy.prototype[key] = instance[key]; -HTTPParser.prototype.BODY_CHUNKTRAILERS = function () { - var line = this.consumeLine(); - if (line === undefined) { - return; - } - if (line) { - this.parseHeader(line, this.trailers); - } else { - if (this.trailers.length) { - this.userCall()(this[kOnHeaders](this.trailers, '')); - } - this.nextRequest(); - } -}; +module.exports = Proxy; -HTTPParser.prototype.BODY_RAW = function () { - var length = this.end - this.offset; - this.userCall()(this[kOnBody](this.chunk, this.offset, length)); - this.offset = this.end; + +/***/ }), +/* 36 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var util = __webpack_require__(0), + HttpParser = __webpack_require__(11), + Base = __webpack_require__(2), + Draft75 = __webpack_require__(16), + Draft76 = __webpack_require__(37), + Hybi = __webpack_require__(13); + +var Server = function(options) { + Base.call(this, null, null, options); + this._http = new HttpParser('request'); }; +util.inherits(Server, Base); -HTTPParser.prototype.BODY_SIZED = function () { - var length = Math.min(this.end - this.offset, this.body_bytes); - this.userCall()(this[kOnBody](this.chunk, this.offset, length)); - this.offset += length; - this.body_bytes -= length; - if (!this.body_bytes) { - this.nextRequest(); +var instance = { + EVENTS: ['open', 'message', 'error', 'close'], + + _bindEventListeners: function() { + this.messages.on('error', function() {}); + this.on('error', function() {}); + }, + + parse: function(chunk) { + if (this._delegate) return this._delegate.parse(chunk); + + this._http.parse(chunk); + if (!this._http.isComplete()) return; + + this.method = this._http.method; + this.url = this._http.url; + this.headers = this._http.headers; + this.body = this._http.body; + + var self = this; + this._delegate = Server.http(this, this._options); + this._delegate.messages = this.messages; + this._delegate.io = this.io; + this._open(); + + this.EVENTS.forEach(function(event) { + this._delegate.on(event, function(e) { self.emit(event, e) }); + }, this); + + this.protocol = this._delegate.protocol; + this.version = this._delegate.version; + + this.parse(this._http.body); + this.emit('connect', new Base.ConnectEvent()); + }, + + _open: function() { + this.__queue.forEach(function(msg) { + this._delegate[msg[0]].apply(this._delegate, msg[1]); + }, this); + this.__queue = []; } }; -// backward compat to node < 0.11.6 -['Headers', 'HeadersComplete', 'Body', 'MessageComplete'].forEach(function (name) { - var k = HTTPParser['kOn' + name]; - Object.defineProperty(HTTPParser.prototype, 'on' + name, { - get: function () { - return this[k]; - }, - set: function (to) { - // hack for backward compatibility - this._compatMode0_11 = true; - return (this[k] = to); +['addExtension', 'setHeader', 'start', 'frame', 'text', 'binary', 'ping', 'close'].forEach(function(method) { + instance[method] = function() { + if (this._delegate) { + return this._delegate[method].apply(this._delegate, arguments); + } else { + this.__queue.push([method, arguments]); + return true; } - }); + }; }); -function parseErrorCode(code) { - var err = new Error('Parse Error'); - err.code = code; - return err; -} +for (var key in instance) + Server.prototype[key] = instance[key]; + +Server.isSecureRequest = function(request) { + if (request.connection && request.connection.authorized !== undefined) return true; + if (request.socket && request.socket.secure) return true; + + var headers = request.headers; + if (!headers) return false; + if (headers['https'] === 'on') return true; + if (headers['x-forwarded-ssl'] === 'on') return true; + if (headers['x-forwarded-scheme'] === 'https') return true; + if (headers['x-forwarded-proto'] === 'https') return true; + + return false; +}; + +Server.determineUrl = function(request) { + var scheme = this.isSecureRequest(request) ? 'wss:' : 'ws:'; + return scheme + '//' + request.headers.host + request.url; +}; +Server.http = function(request, options) { + options = options || {}; + if (options.requireMasking === undefined) options.requireMasking = true; -/***/ }), -/* 75 */ -/***/ (function(module, exports) { + var headers = request.headers, + version = headers['sec-websocket-version'], + key = headers['sec-websocket-key'], + key1 = headers['sec-websocket-key1'], + key2 = headers['sec-websocket-key2'], + url = this.determineUrl(request); + + if (version || key) + return new Hybi(request, url, options); + else if (key1 || key2) + return new Draft76(request, url, options); + else + return new Draft75(request, url, options); +}; + +module.exports = Server; -module.exports = require("assert"); /***/ }), -/* 76 */ +/* 37 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -var Parser = __webpack_require__(77), - Pipeline = __webpack_require__(78); +var Buffer = __webpack_require__(1).Buffer, + Base = __webpack_require__(2), + Draft75 = __webpack_require__(16), + crypto = __webpack_require__(5), + util = __webpack_require__(0); -var Extensions = function() { - this._rsv1 = this._rsv2 = this._rsv3 = null; - this._byName = {}; - this._inOrder = []; - this._sessions = []; - this._index = {}; +var numberFromKey = function(key) { + return parseInt((key.match(/[0-9]/g) || []).join(''), 10); }; -Extensions.MESSAGE_OPCODES = [1, 2]; +var spacesInKey = function(key) { + return (key.match(/ /g) || []).length; +}; + + +var Draft76 = function(request, url, options) { + Draft75.apply(this, arguments); + this._stage = -1; + this._body = []; + this.version = 'hixie-76'; + + this._headers.clear(); + + this._headers.set('Upgrade', 'WebSocket'); + this._headers.set('Connection', 'Upgrade'); + this._headers.set('Sec-WebSocket-Origin', this._request.headers.origin); + this._headers.set('Sec-WebSocket-Location', this.url); +}; +util.inherits(Draft76, Draft75); var instance = { - add: function(ext) { - if (typeof ext.name !== 'string') throw new TypeError('extension.name must be a string'); - if (ext.type !== 'permessage') throw new TypeError('extension.type must be "permessage"'); + BODY_SIZE: 8, - if (typeof ext.rsv1 !== 'boolean') throw new TypeError('extension.rsv1 must be true or false'); - if (typeof ext.rsv2 !== 'boolean') throw new TypeError('extension.rsv2 must be true or false'); - if (typeof ext.rsv3 !== 'boolean') throw new TypeError('extension.rsv3 must be true or false'); + start: function() { + if (!Draft75.prototype.start.call(this)) return false; + this._started = true; + this._sendHandshakeBody(); + return true; + }, - if (this._byName.hasOwnProperty(ext.name)) - throw new TypeError('An extension with name "' + ext.name + '" is already registered'); + close: function() { + if (this.readyState === 3) return false; + if (this.readyState === 1) this._write(Buffer.from([0xFF, 0x00])); + this.readyState = 3; + this.emit('close', new Base.CloseEvent(null, null)); + return true; + }, - this._byName[ext.name] = ext; - this._inOrder.push(ext); + _handshakeResponse: function() { + var headers = this._request.headers, + key1 = headers['sec-websocket-key1'], + key2 = headers['sec-websocket-key2']; + + if (!key1) throw new Error('Missing required header: Sec-WebSocket-Key1'); + if (!key2) throw new Error('Missing required header: Sec-WebSocket-Key2'); + + var number1 = numberFromKey(key1), + spaces1 = spacesInKey(key1), + + number2 = numberFromKey(key2), + spaces2 = spacesInKey(key2); + + if (number1 % spaces1 !== 0 || number2 % spaces2 !== 0) + throw new Error('Client sent invalid Sec-WebSocket-Key headers'); + + this._keyValues = [number1 / spaces1, number2 / spaces2]; + + var start = 'HTTP/1.1 101 WebSocket Protocol Handshake', + headers = [start, this._headers.toString(), '']; + + return Buffer.from(headers.join('\r\n'), 'binary'); }, - generateOffer: function() { - var sessions = [], - offer = [], - index = {}; + _handshakeSignature: function() { + if (this._body.length < this.BODY_SIZE) return null; - this._inOrder.forEach(function(ext) { - var session = ext.createClientSession(); - if (!session) return; + var md5 = crypto.createHash('md5'), + buffer = Buffer.allocUnsafe(8 + this.BODY_SIZE); - var record = [ext, session]; - sessions.push(record); - index[ext.name] = record; + buffer.writeUInt32BE(this._keyValues[0], 0); + buffer.writeUInt32BE(this._keyValues[1], 4); + Buffer.from(this._body).copy(buffer, 8, 0, this.BODY_SIZE); - var offers = session.generateOffer(); - offers = offers ? [].concat(offers) : []; + md5.update(buffer); + return Buffer.from(md5.digest('binary'), 'binary'); + }, - offers.forEach(function(off) { - offer.push(Parser.serializeParams(ext.name, off)); - }, this); - }, this); + _sendHandshakeBody: function() { + if (!this._started) return; + var signature = this._handshakeSignature(); + if (!signature) return; - this._sessions = sessions; - this._index = index; + this._write(signature); + this._stage = 0; + this._open(); - return offer.length > 0 ? offer.join(', ') : null; + if (this._body.length > this.BODY_SIZE) + this.parse(this._body.slice(this.BODY_SIZE)); }, - activate: function(header) { - var responses = Parser.parseHeader(header), - sessions = []; + _parseLeadingByte: function(octet) { + if (octet !== 0xFF) + return Draft75.prototype._parseLeadingByte.call(this, octet); - responses.eachOffer(function(name, params) { - var record = this._index[name]; + this._closing = true; + this._length = 0; + this._stage = 1; + } +}; - if (!record) - throw new Error('Server sent an extension response for unknown extension "' + name + '"'); +for (var key in instance) + Draft76.prototype[key] = instance[key]; - var ext = record[0], - session = record[1], - reserved = this._reserved(ext); +module.exports = Draft76; - if (reserved) - throw new Error('Server sent two extension responses that use the RSV' + - reserved[0] + ' bit: "' + - reserved[1] + '" and "' + ext.name + '"'); - if (session.activate(params) !== true) - throw new Error('Server sent unacceptable extension parameters: ' + - Parser.serializeParams(name, params)); +/***/ }), +/* 38 */ +/***/ (function(module, exports, __webpack_require__) { - this._reserve(ext); - sessions.push(record); - }, this); +var util = __webpack_require__(0), + net = __webpack_require__(39), + tls = __webpack_require__(40), + crypto = __webpack_require__(5), + url = __webpack_require__(8), + driver = __webpack_require__(6), + API = __webpack_require__(12), + Event = __webpack_require__(9); - this._sessions = sessions; - this._pipeline = new Pipeline(sessions); - }, +var DEFAULT_PORTS = {'http:': 80, 'https:': 443, 'ws:':80, 'wss:': 443}, + SECURE_PROTOCOLS = ['https:', 'wss:']; - generateResponse: function(header) { - var sessions = [], - response = [], - offers = Parser.parseHeader(header); +var Client = function(_url, protocols, options) { + options = options || {}; - this._inOrder.forEach(function(ext) { - var offer = offers.byName(ext.name); - if (offer.length === 0 || this._reserved(ext)) return; + this.url = _url; + this._driver = driver.client(this.url, {maxLength: options.maxLength, protocols: protocols}); - var session = ext.createServerSession(offer); - if (!session) return; + ['open', 'error'].forEach(function(event) { + this._driver.on(event, function() { + self.headers = self._driver.headers; + self.statusCode = self._driver.statusCode; + }); + }, this); - this._reserve(ext); - sessions.push([ext, session]); - response.push(Parser.serializeParams(ext.name, session.generateResponse())); - }, this); + var proxy = options.proxy || {}, + endpoint = url.parse(proxy.origin || this.url), + port = endpoint.port || DEFAULT_PORTS[endpoint.protocol], + secure = SECURE_PROTOCOLS.indexOf(endpoint.protocol) >= 0, + onConnect = function() { self._onConnect() }, + originTLS = options.tls || {}, + socketTLS = proxy.origin ? (proxy.tls || {}) : originTLS, + self = this; - this._sessions = sessions; - this._pipeline = new Pipeline(sessions); + originTLS.ca = originTLS.ca || options.ca; - return response.length > 0 ? response.join(', ') : null; - }, + this._stream = secure + ? tls.connect(port, endpoint.hostname, socketTLS, onConnect) + : net.connect(port, endpoint.hostname, onConnect); - validFrameRsv: function(frame) { - var allowed = {rsv1: false, rsv2: false, rsv3: false}, - ext; + if (proxy.origin) this._configureProxy(proxy, originTLS); - if (Extensions.MESSAGE_OPCODES.indexOf(frame.opcode) >= 0) { - for (var i = 0, n = this._sessions.length; i < n; i++) { - ext = this._sessions[i][0]; - allowed.rsv1 = allowed.rsv1 || ext.rsv1; - allowed.rsv2 = allowed.rsv2 || ext.rsv2; - allowed.rsv3 = allowed.rsv3 || ext.rsv3; - } - } + API.call(this, options); +}; +util.inherits(Client, API); - return (allowed.rsv1 || !frame.rsv1) && - (allowed.rsv2 || !frame.rsv2) && - (allowed.rsv3 || !frame.rsv3); - }, +Client.prototype._onConnect = function() { + var worker = this._proxy || this._driver; + worker.start(); +}; - processIncomingMessage: function(message, callback, context) { - this._pipeline.processIncomingMessage(message, callback, context); - }, +Client.prototype._configureProxy = function(proxy, originTLS) { + var uri = url.parse(this.url), + secure = SECURE_PROTOCOLS.indexOf(uri.protocol) >= 0, + self = this, + name; + + this._proxy = this._driver.proxy(proxy.origin); - processOutgoingMessage: function(message, callback, context) { - this._pipeline.processOutgoingMessage(message, callback, context); - }, + if (proxy.headers) { + for (name in proxy.headers) this._proxy.setHeader(name, proxy.headers[name]); + } - close: function(callback, context) { - if (!this._pipeline) return callback.call(context); - this._pipeline.close(callback, context); - }, + this._proxy.pipe(this._stream, {end: false}); + this._stream.pipe(this._proxy); - _reserve: function(ext) { - this._rsv1 = this._rsv1 || (ext.rsv1 && ext.name); - this._rsv2 = this._rsv2 || (ext.rsv2 && ext.name); - this._rsv3 = this._rsv3 || (ext.rsv3 && ext.name); - }, + this._proxy.on('connect', function() { + if (secure) { + var options = {socket: self._stream, servername: uri.hostname}; + for (name in originTLS) options[name] = originTLS[name]; + self._stream = tls.connect(options); + self._configureStream(); + } + self._driver.io.pipe(self._stream); + self._stream.pipe(self._driver.io); + self._driver.start(); + }); - _reserved: function(ext) { - if (this._rsv1 && ext.rsv1) return [1, this._rsv1]; - if (this._rsv2 && ext.rsv2) return [2, this._rsv2]; - if (this._rsv3 && ext.rsv3) return [3, this._rsv3]; - return false; - } + this._proxy.on('error', function(error) { + self._driver.emit('error', error); + }); }; -for (var key in instance) - Extensions.prototype[key] = instance[key]; - -module.exports = Extensions; +module.exports = Client; /***/ }), -/* 77 */ -/***/ (function(module, exports, __webpack_require__) { +/* 39 */ +/***/ (function(module, exports) { -"use strict"; +module.exports = require("net"); +/***/ }), +/* 40 */ +/***/ (function(module, exports) { -var TOKEN = /([!#\$%&'\*\+\-\.\^_`\|~0-9A-Za-z]+)/, - NOTOKEN = /([^!#\$%&'\*\+\-\.\^_`\|~0-9A-Za-z])/g, - QUOTED = /"((?:\\[\x00-\x7f]|[^\x00-\x08\x0a-\x1f\x7f"])*)"/, - PARAM = new RegExp(TOKEN.source + '(?:=(?:' + TOKEN.source + '|' + QUOTED.source + '))?'), - EXT = new RegExp(TOKEN.source + '(?: *; *' + PARAM.source + ')*', 'g'), - EXT_LIST = new RegExp('^' + EXT.source + '(?: *, *' + EXT.source + ')*$'), - NUMBER = /^-?(0|[1-9][0-9]*)(\.[0-9]+)?$/; +module.exports = require("tls"); -var hasOwnProperty = Object.prototype.hasOwnProperty; +/***/ }), +/* 41 */ +/***/ (function(module, exports, __webpack_require__) { -var Parser = { - parseHeader: function(header) { - var offers = new Offers(); - if (header === '' || header === undefined) return offers; +var Stream = __webpack_require__(7).Stream, + util = __webpack_require__(0), + driver = __webpack_require__(6), + Headers = __webpack_require__(10), + API = __webpack_require__(12), + EventTarget = __webpack_require__(17), + Event = __webpack_require__(9); - if (!EXT_LIST.test(header)) - throw new SyntaxError('Invalid Sec-WebSocket-Extensions header: ' + header); +var EventSource = function(request, response, options) { + this.writable = true; + options = options || {}; - var values = header.match(EXT); + this._stream = response.socket; + this._ping = options.ping || this.DEFAULT_PING; + this._retry = options.retry || this.DEFAULT_RETRY; - values.forEach(function(value) { - var params = value.match(new RegExp(PARAM.source, 'g')), - name = params.shift(), - offer = {}; + var scheme = driver.isSecureRequest(request) ? 'https:' : 'http:'; + this.url = scheme + '//' + request.headers.host + request.url; + this.lastEventId = request.headers['last-event-id'] || ''; + this.readyState = API.CONNECTING; - params.forEach(function(param) { - var args = param.match(PARAM), key = args[1], data; + var headers = new Headers(), + self = this; - if (args[2] !== undefined) { - data = args[2]; - } else if (args[3] !== undefined) { - data = args[3].replace(/\\/g, ''); - } else { - data = true; - } - if (NUMBER.test(data)) data = parseFloat(data); + if (options.headers) { + for (var key in options.headers) headers.set(key, options.headers[key]); + } - if (hasOwnProperty.call(offer, key)) { - offer[key] = [].concat(offer[key]); - offer[key].push(data); - } else { - offer[key] = data; - } - }, this); - offers.push(name, offer); - }, this); + if (!this._stream || !this._stream.writable) return; + process.nextTick(function() { self._open() }); - return offers; - }, + this._stream.setTimeout(0); + this._stream.setNoDelay(true); - serializeParams: function(name, params) { - var values = []; + var handshake = 'HTTP/1.1 200 OK\r\n' + + 'Content-Type: text/event-stream\r\n' + + 'Cache-Control: no-cache, no-store\r\n' + + 'Connection: close\r\n' + + headers.toString() + + '\r\n' + + 'retry: ' + Math.floor(this._retry * 1000) + '\r\n\r\n'; - var print = function(key, value) { - if (value instanceof Array) { - value.forEach(function(v) { print(key, v) }); - } else if (value === true) { - values.push(key); - } else if (typeof value === 'number') { - values.push(key + '=' + value); - } else if (NOTOKEN.test(value)) { - values.push(key + '="' + value.replace(/"/g, '\\"') + '"'); - } else { - values.push(key + '=' + value); - } - }; + this._write(handshake); - for (var key in params) print(key, params[key]); + this._stream.on('drain', function() { self.emit('drain') }); - return [name].concat(values).join('; '); - } + if (this._ping) + this._pingTimer = setInterval(function() { self.ping() }, this._ping * 1000); + + ['error', 'end'].forEach(function(event) { + self._stream.on(event, function() { self.close() }); + }); }; +util.inherits(EventSource, Stream); -var Offers = function() { - this._byName = {}; - this._inOrder = []; +EventSource.isEventSource = function(request) { + if (request.method !== 'GET') return false; + var accept = (request.headers.accept || '').split(/\s*,\s*/); + return accept.indexOf('text/event-stream') >= 0; }; -Offers.prototype.push = function(name, params) { - if (!hasOwnProperty.call(this._byName, name)) - this._byName[name] = []; +var instance = { + DEFAULT_PING: 10, + DEFAULT_RETRY: 5, - this._byName[name].push(params); - this._inOrder.push({name: name, params: params}); -}; + _write: function(chunk) { + if (!this.writable) return false; + try { + return this._stream.write(chunk, 'utf8'); + } catch (e) { + return false; + } + }, -Offers.prototype.eachOffer = function(callback, context) { - var list = this._inOrder; - for (var i = 0, n = list.length; i < n; i++) - callback.call(context, list[i].name, list[i].params); -}; + _open: function() { + if (this.readyState !== API.CONNECTING) return; -Offers.prototype.byName = function(name) { - return this._byName[name] || []; -}; + this.readyState = API.OPEN; -Offers.prototype.toArray = function() { - return this._inOrder.slice(); -}; + var event = new Event('open'); + event.initEvent('open', false, false); + this.dispatchEvent(event); + }, -module.exports = Parser; + write: function(message) { + return this.send(message); + }, + end: function(message) { + if (message !== undefined) this.write(message); + this.close(); + }, -/***/ }), -/* 78 */ -/***/ (function(module, exports, __webpack_require__) { + send: function(message, options) { + if (this.readyState > API.OPEN) return false; -"use strict"; + message = String(message).replace(/(\r\n|\r|\n)/g, '$1data: '); + options = options || {}; + var frame = ''; + if (options.event) frame += 'event: ' + options.event + '\r\n'; + if (options.id) frame += 'id: ' + options.id + '\r\n'; + frame += 'data: ' + message + '\r\n\r\n'; -var Cell = __webpack_require__(79), - Pledge = __webpack_require__(28); + return this._write(frame); + }, -var Pipeline = function(sessions) { - this._cells = sessions.map(function(session) { return new Cell(session) }); - this._stopped = {incoming: false, outgoing: false}; -}; + ping: function() { + return this._write(':\r\n\r\n'); + }, -Pipeline.prototype.processIncomingMessage = function(message, callback, context) { - if (this._stopped.incoming) return; - this._loop('incoming', this._cells.length - 1, -1, -1, message, callback, context); -}; + close: function() { + if (this.readyState > API.OPEN) return false; -Pipeline.prototype.processOutgoingMessage = function(message, callback, context) { - if (this._stopped.outgoing) return; - this._loop('outgoing', 0, this._cells.length, 1, message, callback, context); -}; + this.readyState = API.CLOSED; + this.writable = false; + if (this._pingTimer) clearInterval(this._pingTimer); + if (this._stream) this._stream.end(); -Pipeline.prototype.close = function(callback, context) { - this._stopped = {incoming: true, outgoing: true}; + var event = new Event('close'); + event.initEvent('close', false, false); + this.dispatchEvent(event); - var closed = this._cells.map(function(a) { return a.close() }); - if (callback) - Pledge.all(closed).then(function() { callback.call(context) }); + return true; + } }; -Pipeline.prototype._loop = function(direction, start, end, step, message, callback, context) { - var cells = this._cells, - n = cells.length, - self = this; +for (var method in instance) EventSource.prototype[method] = instance[method]; +for (var key in EventTarget) EventSource.prototype[key] = EventTarget[key]; - while (n--) cells[n].pending(direction); +module.exports = EventSource; - var pipe = function(index, error, msg) { - if (index === end) return callback.call(context, error, msg); - cells[index][direction](error, msg, function(err, m) { - if (err) self._stopped[direction] = true; - pipe(index + step, err, m); - }); - }; - pipe(start, null, message); -}; +/***/ }), +/* 42 */ +/***/ (function(module, exports) { + +module.exports = require("child_process"); -module.exports = Pipeline; +/***/ }), +/* 43 */ +/***/ (function(module, exports) { +module.exports = require("fs"); /***/ }), -/* 79 */ -/***/ (function(module, exports, __webpack_require__) { +/* 44 */ +/***/ (function(module, exports) { -"use strict"; +module.exports = require("http"); +/***/ }), +/* 45 */ +/***/ (function(module, exports) { -var Functor = __webpack_require__(80), - Pledge = __webpack_require__(28); +module.exports = require("https"); -var Cell = function(tuple) { - this._ext = tuple[0]; - this._session = tuple[1]; +/***/ }), +/* 46 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { - this._functors = { - incoming: new Functor(this._session, 'processIncomingMessage'), - outgoing: new Functor(this._session, 'processOutgoingMessage') - }; -}; +"use strict"; +__webpack_require__.r(__webpack_exports__); -Cell.prototype.pending = function(direction) { - var functor = this._functors[direction]; - if (!functor._stopped) functor.pending += 1; +// CONCATENATED MODULE: ./src/core/base64.ts +function encode(s) { + return btoa(utob(s)); +} +var fromCharCode = String.fromCharCode; +var b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; +var b64tab = {}; +for (var base64_i = 0, l = b64chars.length; base64_i < l; base64_i++) { + b64tab[b64chars.charAt(base64_i)] = base64_i; +} +var cb_utob = function (c) { + var cc = c.charCodeAt(0); + return cc < 0x80 + ? c + : cc < 0x800 + ? fromCharCode(0xc0 | (cc >>> 6)) + fromCharCode(0x80 | (cc & 0x3f)) + : fromCharCode(0xe0 | ((cc >>> 12) & 0x0f)) + + fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) + + fromCharCode(0x80 | (cc & 0x3f)); }; - -Cell.prototype.incoming = function(error, message, callback, context) { - this._exec('incoming', error, message, callback, context); +var utob = function (u) { + return u.replace(/[^\x00-\x7F]/g, cb_utob); }; - -Cell.prototype.outgoing = function(error, message, callback, context) { - this._exec('outgoing', error, message, callback, context); +var cb_encode = function (ccc) { + var padlen = [0, 2, 1][ccc.length % 3]; + var ord = (ccc.charCodeAt(0) << 16) | + ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8) | + (ccc.length > 2 ? ccc.charCodeAt(2) : 0); + var chars = [ + b64chars.charAt(ord >>> 18), + b64chars.charAt((ord >>> 12) & 63), + padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63), + padlen >= 1 ? '=' : b64chars.charAt(ord & 63) + ]; + return chars.join(''); }; +var btoa = global.btoa || + function (b) { + return b.replace(/[\s\S]{1,3}/g, cb_encode); + }; -Cell.prototype.close = function() { - this._closed = this._closed || new Pledge(); - this._doClose(); - return this._closed; -}; +// CONCATENATED MODULE: ./src/core/utils/timers/abstract_timer.ts +var Timer = (function () { + function Timer(set, clear, delay, callback) { + var _this = this; + this.clear = clear; + this.timer = set(function () { + if (_this.timer) { + _this.timer = callback(_this.timer); + } + }, delay); + } + Timer.prototype.isRunning = function () { + return this.timer !== null; + }; + Timer.prototype.ensureAborted = function () { + if (this.timer) { + this.clear(this.timer); + this.timer = null; + } + }; + return Timer; +}()); +/* harmony default export */ var abstract_timer = (Timer); -Cell.prototype._exec = function(direction, error, message, callback, context) { - this._functors[direction].call(error, message, function(err, msg) { - if (err) err.message = this._ext.name + ': ' + err.message; - callback.call(context, err, msg); - this._doClose(); - }, this); -}; +// CONCATENATED MODULE: ./src/core/utils/timers/index.ts +var __extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); -Cell.prototype._doClose = function() { - var fin = this._functors.incoming, - fout = this._functors.outgoing; +function timers_clearTimeout(timer) { + global.clearTimeout(timer); +} +function timers_clearInterval(timer) { + global.clearInterval(timer); +} +var OneOffTimer = (function (_super) { + __extends(OneOffTimer, _super); + function OneOffTimer(delay, callback) { + return _super.call(this, setTimeout, timers_clearTimeout, delay, function (timer) { + callback(); + return null; + }) || this; + } + return OneOffTimer; +}(abstract_timer)); - if (!this._closed || fin.pending + fout.pending !== 0) return; - if (this._session) this._session.close(); - this._session = null; - this._closed.done(); -}; +var PeriodicTimer = (function (_super) { + __extends(PeriodicTimer, _super); + function PeriodicTimer(delay, callback) { + return _super.call(this, setInterval, timers_clearInterval, delay, function (timer) { + callback(); + return timer; + }) || this; + } + return PeriodicTimer; +}(abstract_timer)); -module.exports = Cell; +// CONCATENATED MODULE: ./src/core/util.ts -/***/ }), -/* 80 */ -/***/ (function(module, exports, __webpack_require__) { +var Util = { + now: function () { + if (Date.now) { + return Date.now(); + } + else { + return new Date().valueOf(); + } + }, + defer: function (callback) { + return new OneOffTimer(0, callback); + }, + method: function (name) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + var boundArguments = Array.prototype.slice.call(arguments, 1); + return function (object) { + return object[name].apply(object, boundArguments.concat(arguments)); + }; + } +}; +/* harmony default export */ var util = (Util); -"use strict"; +// CONCATENATED MODULE: ./src/core/utils/collections.ts -var RingBuffer = __webpack_require__(27); +function extend(target) { + var sources = []; + for (var _i = 1; _i < arguments.length; _i++) { + sources[_i - 1] = arguments[_i]; + } + for (var i = 0; i < sources.length; i++) { + var extensions = sources[i]; + for (var property in extensions) { + if (extensions[property] && extensions[property].constructor && + extensions[property].constructor === Object) { + target[property] = extend(target[property] || {}, extensions[property]); + } + else { + target[property] = extensions[property]; + } + } + } + return target; +} +function stringify() { + var m = ["Pusher"]; + for (var i = 0; i < arguments.length; i++) { + if (typeof arguments[i] === "string") { + m.push(arguments[i]); + } + else { + m.push(safeJSONStringify(arguments[i])); + } + } + return m.join(" : "); +} +function arrayIndexOf(array, item) { + var nativeIndexOf = Array.prototype.indexOf; + if (array === null) { + return -1; + } + if (nativeIndexOf && array.indexOf === nativeIndexOf) { + return array.indexOf(item); + } + for (var i = 0, l = array.length; i < l; i++) { + if (array[i] === item) { + return i; + } + } + return -1; +} +function objectApply(object, f) { + for (var key in object) { + if (Object.prototype.hasOwnProperty.call(object, key)) { + f(object[key], key, object); + } + } +} +function keys(object) { + var keys = []; + objectApply(object, function (_, key) { + keys.push(key); + }); + return keys; +} +function values(object) { + var values = []; + objectApply(object, function (value) { + values.push(value); + }); + return values; +} +function apply(array, f, context) { + for (var i = 0; i < array.length; i++) { + f.call(context || global, array[i], i, array); + } +} +function map(array, f) { + var result = []; + for (var i = 0; i < array.length; i++) { + result.push(f(array[i], i, array, result)); + } + return result; +} +function mapObject(object, f) { + var result = {}; + objectApply(object, function (value, key) { + result[key] = f(value); + }); + return result; +} +function filter(array, test) { + test = test || function (value) { return !!value; }; + var result = []; + for (var i = 0; i < array.length; i++) { + if (test(array[i], i, array, result)) { + result.push(array[i]); + } + } + return result; +} +function filterObject(object, test) { + var result = {}; + objectApply(object, function (value, key) { + if ((test && test(value, key, object, result)) || Boolean(value)) { + result[key] = value; + } + }); + return result; +} +function flatten(object) { + var result = []; + objectApply(object, function (value, key) { + result.push([key, value]); + }); + return result; +} +function any(array, test) { + for (var i = 0; i < array.length; i++) { + if (test(array[i], i, array)) { + return true; + } + } + return false; +} +function collections_all(array, test) { + for (var i = 0; i < array.length; i++) { + if (!test(array[i], i, array)) { + return false; + } + } + return true; +} +function encodeParamsObject(data) { + return mapObject(data, function (value) { + if (typeof value === "object") { + value = safeJSONStringify(value); + } + return encodeURIComponent(encode(value.toString())); + }); +} +function buildQueryString(data) { + var params = filterObject(data, function (value) { + return value !== undefined; + }); + var query = map(flatten(encodeParamsObject(params)), util.method("join", "=")).join("&"); + return query; +} +function decycleObject(object) { + var objects = [], paths = []; + return (function derez(value, path) { + var i, name, nu; + switch (typeof value) { + case 'object': + if (!value) { + return null; + } + for (i = 0; i < objects.length; i += 1) { + if (objects[i] === value) { + return { $ref: paths[i] }; + } + } + objects.push(value); + paths.push(path); + if (Object.prototype.toString.apply(value) === '[object Array]') { + nu = []; + for (i = 0; i < value.length; i += 1) { + nu[i] = derez(value[i], path + '[' + i + ']'); + } + } + else { + nu = {}; + for (name in value) { + if (Object.prototype.hasOwnProperty.call(value, name)) { + nu[name] = derez(value[name], path + '[' + JSON.stringify(name) + ']'); + } + } + } + return nu; + case 'number': + case 'string': + case 'boolean': + return value; + } + }(object, '$')); +} +function safeJSONStringify(source) { + try { + return JSON.stringify(source); + } + catch (e) { + return JSON.stringify(decycleObject(source)); + } +} -var Functor = function(session, method) { - this._session = session; - this._method = method; - this._queue = new RingBuffer(Functor.QUEUE_SIZE); - this._stopped = false; - this.pending = 0; +// CONCATENATED MODULE: ./src/core/defaults.ts +var Defaults = { + VERSION: "5.0.2", + PROTOCOL: 7, + host: 'ws.pusherapp.com', + ws_port: 80, + wss_port: 443, + ws_path: '', + sockjs_host: 'sockjs.pusher.com', + sockjs_http_port: 80, + sockjs_https_port: 443, + sockjs_path: '/pusher', + stats_host: 'stats.pusher.com', + channel_auth_endpoint: '/pusher/auth', + channel_auth_transport: 'ajax', + activity_timeout: 120000, + pong_timeout: 30000, + unavailable_timeout: 10000, + cdn_http: "http://js.pusher.com", + cdn_https: "https://js.pusher.com", + dependency_suffix: "" }; +/* harmony default export */ var defaults = (Defaults); -Functor.QUEUE_SIZE = 8; - -Functor.prototype.call = function(error, message, callback, context) { - if (this._stopped) return; - - var record = {error: error, message: message, callback: callback, context: context, done: false}, - called = false, - self = this; - - this._queue.push(record); - - if (record.error) { - record.done = true; - this._stop(); - return this._flushQueue(); - } - - var handler = function(err, msg) { - if (!(called ^ (called = true))) return; +// CONCATENATED MODULE: ./src/core/transports/url_schemes.ts - if (err) { - self._stop(); - record.error = err; - record.message = null; - } else { - record.message = msg; +function getGenericURL(baseScheme, params, path) { + var scheme = baseScheme + (params.useTLS ? "s" : ""); + var host = params.useTLS ? params.hostTLS : params.hostNonTLS; + return scheme + "://" + host + path; +} +function getGenericPath(key, queryString) { + var path = "/app/" + key; + var query = "?protocol=" + defaults.PROTOCOL + + "&client=js" + + "&version=" + defaults.VERSION + + (queryString ? ("&" + queryString) : ""); + return path + query; +} +var ws = { + getInitial: function (key, params) { + var path = (params.httpPath || "") + getGenericPath(key, "flash=false"); + return getGenericURL("ws", params, path); } - - record.done = true; - self._flushQueue(); - }; - - try { - this._session[this._method](message, handler); - } catch (err) { - handler(err); - } }; - -Functor.prototype._stop = function() { - this.pending = this._queue.length; - this._stopped = true; -}; - -Functor.prototype._flushQueue = function() { - var queue = this._queue, record; - - while (queue.length > 0 && queue.peek().done) { - record = queue.shift(); - if (record.error) { - this.pending = 0; - queue.clear(); - } else { - this.pending -= 1; +var http = { + getInitial: function (key, params) { + var path = (params.httpPath || "/pusher") + getGenericPath(key); + return getGenericURL("http", params, path); } - record.callback.call(record.context, record.error, record.message); - } }; - -module.exports = Functor; - - -/***/ }), -/* 81 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -var Frame = function() {}; - -var instance = { - final: false, - rsv1: false, - rsv2: false, - rsv3: false, - opcode: null, - masked: false, - maskingKey: null, - lengthBytes: 1, - length: 0, - payload: null +var sockjs = { + getInitial: function (key, params) { + return getGenericURL("http", params, params.httpPath || "/pusher"); + }, + getPath: function (key, params) { + return getGenericPath(key); + } }; -for (var key in instance) - Frame.prototype[key] = instance[key]; +// CONCATENATED MODULE: ./src/core/events/callback_registry.ts -module.exports = Frame; +var callback_registry_CallbackRegistry = (function () { + function CallbackRegistry() { + this._callbacks = {}; + } + CallbackRegistry.prototype.get = function (name) { + return this._callbacks[prefix(name)]; + }; + CallbackRegistry.prototype.add = function (name, callback, context) { + var prefixedEventName = prefix(name); + this._callbacks[prefixedEventName] = this._callbacks[prefixedEventName] || []; + this._callbacks[prefixedEventName].push({ + fn: callback, + context: context + }); + }; + CallbackRegistry.prototype.remove = function (name, callback, context) { + if (!name && !callback && !context) { + this._callbacks = {}; + return; + } + var names = name ? [prefix(name)] : keys(this._callbacks); + if (callback || context) { + this.removeCallback(names, callback, context); + } + else { + this.removeAllCallbacks(names); + } + }; + CallbackRegistry.prototype.removeCallback = function (names, callback, context) { + apply(names, function (name) { + this._callbacks[name] = filter(this._callbacks[name] || [], function (binding) { + return (callback && callback !== binding.fn) || + (context && context !== binding.context); + }); + if (this._callbacks[name].length === 0) { + delete this._callbacks[name]; + } + }, this); + }; + CallbackRegistry.prototype.removeAllCallbacks = function (names) { + apply(names, function (name) { + delete this._callbacks[name]; + }, this); + }; + return CallbackRegistry; +}()); +/* harmony default export */ var callback_registry = (callback_registry_CallbackRegistry); +function prefix(name) { + return "_" + name; +} +// CONCATENATED MODULE: ./src/core/events/dispatcher.ts -/***/ }), -/* 82 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; +var dispatcher_Dispatcher = (function () { + function Dispatcher(failThrough) { + this.callbacks = new callback_registry(); + this.global_callbacks = []; + this.failThrough = failThrough; + } + Dispatcher.prototype.bind = function (eventName, callback, context) { + this.callbacks.add(eventName, callback, context); + return this; + }; + Dispatcher.prototype.bind_global = function (callback) { + this.global_callbacks.push(callback); + return this; + }; + Dispatcher.prototype.unbind = function (eventName, callback, context) { + this.callbacks.remove(eventName, callback, context); + return this; + }; + Dispatcher.prototype.unbind_global = function (callback) { + if (!callback) { + this.global_callbacks = []; + return this; + } + this.global_callbacks = filter(this.global_callbacks || [], function (c) { return c !== callback; }); + return this; + }; + Dispatcher.prototype.unbind_all = function () { + this.unbind(); + this.unbind_global(); + return this; + }; + Dispatcher.prototype.emit = function (eventName, data, metadata) { + for (var i = 0; i < this.global_callbacks.length; i++) { + this.global_callbacks[i](eventName, data); + } + var callbacks = this.callbacks.get(eventName); + var args = []; + if (metadata) { + args.push(data, metadata); + } + else if (data) { + args.push(data); + } + if (callbacks && callbacks.length > 0) { + for (var i = 0; i < callbacks.length; i++) { + callbacks[i].fn.apply(callbacks[i].context || global, args); + } + } + else if (this.failThrough) { + this.failThrough(eventName, data); + } + return this; + }; + return Dispatcher; +}()); +/* harmony default export */ var dispatcher = (dispatcher_Dispatcher); +// CONCATENATED MODULE: ./src/core/logger.ts -var Buffer = __webpack_require__(5).Buffer; -var Message = function() { - this.rsv1 = false; - this.rsv2 = false; - this.rsv3 = false; - this.opcode = null; - this.length = 0; - this._chunks = []; +var Logger = { + debug: function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + if (!core_pusher.log) { + return; + } + core_pusher.log(stringify.apply(this, arguments)); + }, + warn: function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + var message = stringify.apply(this, arguments); + if (core_pusher.log) { + core_pusher.log(message); + } + else if (global.console) { + if (global.console.warn) { + global.console.warn(message); + } + else if (global.console.log) { + global.console.log(message); + } + } + } }; +/* harmony default export */ var logger = (Logger); -var instance = { - read: function() { - return this.data = this.data || Buffer.concat(this._chunks, this.length); - }, - - pushFrame: function(frame) { - this.rsv1 = this.rsv1 || frame.rsv1; - this.rsv2 = this.rsv2 || frame.rsv2; - this.rsv3 = this.rsv3 || frame.rsv3; - - if (this.opcode === null) this.opcode = frame.opcode; - - this._chunks.push(frame.payload); - this.length += frame.length; - } -}; +// CONCATENATED MODULE: ./src/core/transports/transport_connection.ts +var transport_connection_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); -for (var key in instance) - Message.prototype[key] = instance[key]; -module.exports = Message; -/***/ }), -/* 83 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; +var transport_connection_TransportConnection = (function (_super) { + transport_connection_extends(TransportConnection, _super); + function TransportConnection(hooks, name, priority, key, options) { + var _this = _super.call(this) || this; + _this.initialize = node_runtime.transportConnectionInitializer; + _this.hooks = hooks; + _this.name = name; + _this.priority = priority; + _this.key = key; + _this.options = options; + _this.state = "new"; + _this.timeline = options.timeline; + _this.activityTimeout = options.activityTimeout; + _this.id = _this.timeline.generateUniqueID(); + return _this; + } + TransportConnection.prototype.handlesActivityChecks = function () { + return Boolean(this.hooks.handlesActivityChecks); + }; + TransportConnection.prototype.supportsPing = function () { + return Boolean(this.hooks.supportsPing); + }; + TransportConnection.prototype.connect = function () { + var _this = this; + if (this.socket || this.state !== "initialized") { + return false; + } + var url = this.hooks.urls.getInitial(this.key, this.options); + try { + this.socket = this.hooks.getSocket(url, this.options); + } + catch (e) { + util.defer(function () { + _this.onError(e); + _this.changeState("closed"); + }); + return false; + } + this.bindListeners(); + logger.debug("Connecting", { transport: this.name, url: url }); + this.changeState("connecting"); + return true; + }; + TransportConnection.prototype.close = function () { + if (this.socket) { + this.socket.close(); + return true; + } + else { + return false; + } + }; + TransportConnection.prototype.send = function (data) { + var _this = this; + if (this.state === "open") { + util.defer(function () { + if (_this.socket) { + _this.socket.send(data); + } + }); + return true; + } + else { + return false; + } + }; + TransportConnection.prototype.ping = function () { + if (this.state === "open" && this.supportsPing()) { + this.socket.ping(); + } + }; + TransportConnection.prototype.onOpen = function () { + if (this.hooks.beforeOpen) { + this.hooks.beforeOpen(this.socket, this.hooks.urls.getPath(this.key, this.options)); + } + this.changeState("open"); + this.socket.onopen = undefined; + }; + TransportConnection.prototype.onError = function (error) { + this.emit("error", { type: 'WebSocketError', error: error }); + this.timeline.error(this.buildTimelineMessage({ error: error.toString() })); + }; + TransportConnection.prototype.onClose = function (closeEvent) { + if (closeEvent) { + this.changeState("closed", { + code: closeEvent.code, + reason: closeEvent.reason, + wasClean: closeEvent.wasClean + }); + } + else { + this.changeState("closed"); + } + this.unbindListeners(); + this.socket = undefined; + }; + TransportConnection.prototype.onMessage = function (message) { + this.emit("message", message); + }; + TransportConnection.prototype.onActivity = function () { + this.emit("activity"); + }; + TransportConnection.prototype.bindListeners = function () { + var _this = this; + this.socket.onopen = function () { + _this.onOpen(); + }; + this.socket.onerror = function (error) { + _this.onError(error); + }; + this.socket.onclose = function (closeEvent) { + _this.onClose(closeEvent); + }; + this.socket.onmessage = function (message) { + _this.onMessage(message); + }; + if (this.supportsPing()) { + this.socket.onactivity = function () { _this.onActivity(); }; + } + }; + TransportConnection.prototype.unbindListeners = function () { + if (this.socket) { + this.socket.onopen = undefined; + this.socket.onerror = undefined; + this.socket.onclose = undefined; + this.socket.onmessage = undefined; + if (this.supportsPing()) { + this.socket.onactivity = undefined; + } + } + }; + TransportConnection.prototype.changeState = function (state, params) { + this.state = state; + this.timeline.info(this.buildTimelineMessage({ + state: state, + params: params + })); + this.emit(state, params); + }; + TransportConnection.prototype.buildTimelineMessage = function (message) { + return extend({ cid: this.id }, message); + }; + return TransportConnection; +}(dispatcher)); +/* harmony default export */ var transport_connection = (transport_connection_TransportConnection); +// CONCATENATED MODULE: ./src/core/transports/transport.ts -var Buffer = __webpack_require__(5).Buffer, - Stream = __webpack_require__(14).Stream, - url = __webpack_require__(15), - util = __webpack_require__(2), - Base = __webpack_require__(7), - Headers = __webpack_require__(19), - HttpParser = __webpack_require__(20); +var transport_Transport = (function () { + function Transport(hooks) { + this.hooks = hooks; + } + Transport.prototype.isSupported = function (environment) { + return this.hooks.isSupported(environment); + }; + Transport.prototype.createConnection = function (name, priority, key, options) { + return new transport_connection(this.hooks, name, priority, key, options); + }; + return Transport; +}()); +/* harmony default export */ var transports_transport = (transport_Transport); -var PORTS = { 'ws:': 80, 'wss:': 443 }; +// CONCATENATED MODULE: ./src/runtimes/isomorphic/transports/transports.ts -var Proxy = function(client, origin, options) { - this._client = client; - this._http = new HttpParser('response'); - this._origin = (typeof client.url === 'object') ? client.url : url.parse(client.url); - this._url = (typeof origin === 'object') ? origin : url.parse(origin); - this._options = options || {}; - this._state = 0; - this.readable = this.writable = true; - this._paused = false; - this._headers = new Headers(); - this._headers.set('Host', this._origin.host); - this._headers.set('Connection', 'keep-alive'); - this._headers.set('Proxy-Connection', 'keep-alive'); - var auth = this._url.auth && Buffer.from(this._url.auth, 'utf8').toString('base64'); - if (auth) this._headers.set('Proxy-Authorization', 'Basic ' + auth); +var WSTransport = new transports_transport({ + urls: ws, + handlesActivityChecks: false, + supportsPing: false, + isInitialized: function () { + return Boolean(node_runtime.getWebSocketAPI()); + }, + isSupported: function () { + return Boolean(node_runtime.getWebSocketAPI()); + }, + getSocket: function (url) { + return node_runtime.createWebSocket(url); + } +}); +var httpConfiguration = { + urls: http, + handlesActivityChecks: false, + supportsPing: true, + isInitialized: function () { + return true; + } }; -util.inherits(Proxy, Stream); - -var instance = { - setHeader: function(name, value) { - if (this._state !== 0) return false; - this._headers.set(name, value); - return true; - }, - - start: function() { - if (this._state !== 0) return false; - this._state = 1; - - var origin = this._origin, - port = origin.port || PORTS[origin.protocol], - start = 'CONNECT ' + origin.hostname + ':' + port + ' HTTP/1.1'; - - var headers = [start, this._headers.toString(), '']; - - this.emit('data', Buffer.from(headers.join('\r\n'), 'utf8')); - return true; - }, - - pause: function() { - this._paused = true; - }, - - resume: function() { - this._paused = false; - this.emit('drain'); - }, - - write: function(chunk) { - if (!this.writable) return false; - - this._http.parse(chunk); - if (!this._http.isComplete()) return !this._paused; - - this.statusCode = this._http.statusCode; - this.headers = this._http.headers; - - if (this.statusCode === 200) { - this.emit('connect', new Base.ConnectEvent()); - } else { - var message = "Can't establish a connection to the server at " + this._origin.href; - this.emit('error', new Error(message)); +var streamingConfiguration = extend({ getSocket: function (url) { + return node_runtime.HTTPFactory.createStreamingSocket(url); + } +}, httpConfiguration); +var pollingConfiguration = extend({ getSocket: function (url) { + return node_runtime.HTTPFactory.createPollingSocket(url); + } +}, httpConfiguration); +var xhrConfiguration = { + isSupported: function () { + return node_runtime.isXHRSupported(); } - this.end(); - return !this._paused; - }, - - end: function(chunk) { - if (!this.writable) return; - if (chunk !== undefined) this.write(chunk); - this.readable = this.writable = false; - this.emit('close'); - this.emit('end'); - }, - - destroy: function() { - this.end(); - } }; - -for (var key in instance) - Proxy.prototype[key] = instance[key]; - -module.exports = Proxy; - - -/***/ }), -/* 84 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -var util = __webpack_require__(2), - HttpParser = __webpack_require__(20), - Base = __webpack_require__(7), - Draft75 = __webpack_require__(29), - Draft76 = __webpack_require__(85), - Hybi = __webpack_require__(26); - -var Server = function(options) { - Base.call(this, null, null, options); - this._http = new HttpParser('request'); +var XHRStreamingTransport = new transports_transport(extend({}, streamingConfiguration, xhrConfiguration)); +var XHRPollingTransport = new transports_transport(extend({}, pollingConfiguration, xhrConfiguration)); +var Transports = { + ws: WSTransport, + xhr_streaming: XHRStreamingTransport, + xhr_polling: XHRPollingTransport }; -util.inherits(Server, Base); - -var instance = { - EVENTS: ['open', 'message', 'error', 'close'], - - _bindEventListeners: function() { - this.messages.on('error', function() {}); - this.on('error', function() {}); - }, - - parse: function(chunk) { - if (this._delegate) return this._delegate.parse(chunk); - - this._http.parse(chunk); - if (!this._http.isComplete()) return; - - this.method = this._http.method; - this.url = this._http.url; - this.headers = this._http.headers; - this.body = this._http.body; - - var self = this; - this._delegate = Server.http(this, this._options); - this._delegate.messages = this.messages; - this._delegate.io = this.io; - this._open(); - - this.EVENTS.forEach(function(event) { - this._delegate.on(event, function(e) { self.emit(event, e) }); - }, this); +/* harmony default export */ var transports = (Transports); - this.protocol = this._delegate.protocol; - this.version = this._delegate.version; +// CONCATENATED MODULE: ./src/core/transports/assistant_to_the_transport_manager.ts - this.parse(this._http.body); - this.emit('connect', new Base.ConnectEvent()); - }, - _open: function() { - this.__queue.forEach(function(msg) { - this._delegate[msg[0]].apply(this._delegate, msg[1]); - }, this); - this.__queue = []; - } -}; +var assistant_to_the_transport_manager_AssistantToTheTransportManager = (function () { + function AssistantToTheTransportManager(manager, transport, options) { + this.manager = manager; + this.transport = transport; + this.minPingDelay = options.minPingDelay; + this.maxPingDelay = options.maxPingDelay; + this.pingDelay = undefined; + } + AssistantToTheTransportManager.prototype.createConnection = function (name, priority, key, options) { + var _this = this; + options = extend({}, options, { + activityTimeout: this.pingDelay + }); + var connection = this.transport.createConnection(name, priority, key, options); + var openTimestamp = null; + var onOpen = function () { + connection.unbind("open", onOpen); + connection.bind("closed", onClosed); + openTimestamp = util.now(); + }; + var onClosed = function (closeEvent) { + connection.unbind("closed", onClosed); + if (closeEvent.code === 1002 || closeEvent.code === 1003) { + _this.manager.reportDeath(); + } + else if (!closeEvent.wasClean && openTimestamp) { + var lifespan = util.now() - openTimestamp; + if (lifespan < 2 * _this.maxPingDelay) { + _this.manager.reportDeath(); + _this.pingDelay = Math.max(lifespan / 2, _this.minPingDelay); + } + } + }; + connection.bind("open", onOpen); + return connection; + }; + AssistantToTheTransportManager.prototype.isSupported = function (environment) { + return this.manager.isAlive() && this.transport.isSupported(environment); + }; + return AssistantToTheTransportManager; +}()); +/* harmony default export */ var assistant_to_the_transport_manager = (assistant_to_the_transport_manager_AssistantToTheTransportManager); -['addExtension', 'setHeader', 'start', 'frame', 'text', 'binary', 'ping', 'close'].forEach(function(method) { - instance[method] = function() { - if (this._delegate) { - return this._delegate[method].apply(this._delegate, arguments); - } else { - this.__queue.push([method, arguments]); - return true; +// CONCATENATED MODULE: ./src/core/connection/protocol/protocol.ts +var Protocol = { + decodeMessage: function (messageEvent) { + try { + var messageData = JSON.parse(messageEvent.data); + var pusherEventData = messageData.data; + if (typeof pusherEventData === 'string') { + try { + pusherEventData = JSON.parse(messageData.data); + } + catch (e) { } + } + var pusherEvent = { + event: messageData.event, + channel: messageData.channel, + data: pusherEventData, + }; + if (messageData.user_id) { + pusherEvent.user_id = messageData.user_id; + } + return pusherEvent; + } + catch (e) { + throw { type: 'MessageParseError', error: e, data: messageEvent.data }; + } + }, + encodeMessage: function (event) { + return JSON.stringify(event); + }, + processHandshake: function (messageEvent) { + var message = Protocol.decodeMessage(messageEvent); + if (message.event === "pusher:connection_established") { + if (!message.data.activity_timeout) { + throw "No activity timeout specified in handshake"; + } + return { + action: "connected", + id: message.data.socket_id, + activityTimeout: message.data.activity_timeout * 1000 + }; + } + else if (message.event === "pusher:error") { + return { + action: this.getCloseAction(message.data), + error: this.getCloseError(message.data) + }; + } + else { + throw "Invalid handshake"; + } + }, + getCloseAction: function (closeEvent) { + if (closeEvent.code < 4000) { + if (closeEvent.code >= 1002 && closeEvent.code <= 1004) { + return "backoff"; + } + else { + return null; + } + } + else if (closeEvent.code === 4000) { + return "tls_only"; + } + else if (closeEvent.code < 4100) { + return "refused"; + } + else if (closeEvent.code < 4200) { + return "backoff"; + } + else if (closeEvent.code < 4300) { + return "retry"; + } + else { + return "refused"; + } + }, + getCloseError: function (closeEvent) { + if (closeEvent.code !== 1000 && closeEvent.code !== 1001) { + return { + type: 'PusherError', + data: { + code: closeEvent.code, + message: closeEvent.reason || closeEvent.message + } + }; + } + else { + return null; + } } - }; -}); - -for (var key in instance) - Server.prototype[key] = instance[key]; - -Server.isSecureRequest = function(request) { - if (request.connection && request.connection.authorized !== undefined) return true; - if (request.socket && request.socket.secure) return true; - - var headers = request.headers; - if (!headers) return false; - if (headers['https'] === 'on') return true; - if (headers['x-forwarded-ssl'] === 'on') return true; - if (headers['x-forwarded-scheme'] === 'https') return true; - if (headers['x-forwarded-proto'] === 'https') return true; - - return false; -}; - -Server.determineUrl = function(request) { - var scheme = this.isSecureRequest(request) ? 'wss:' : 'ws:'; - return scheme + '//' + request.headers.host + request.url; }; +/* harmony default export */ var protocol = (Protocol); -Server.http = function(request, options) { - options = options || {}; - if (options.requireMasking === undefined) options.requireMasking = true; - - var headers = request.headers, - version = headers['sec-websocket-version'], - key = headers['sec-websocket-key'], - key1 = headers['sec-websocket-key1'], - key2 = headers['sec-websocket-key2'], - url = this.determineUrl(request); - - if (version || key) - return new Hybi(request, url, options); - else if (key1 || key2) - return new Draft76(request, url, options); - else - return new Draft75(request, url, options); -}; +// CONCATENATED MODULE: ./src/core/connection/connection.ts +var connection_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); -module.exports = Server; -/***/ }), -/* 85 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; +var connection_Connection = (function (_super) { + connection_extends(Connection, _super); + function Connection(id, transport) { + var _this = _super.call(this) || this; + _this.id = id; + _this.transport = transport; + _this.activityTimeout = transport.activityTimeout; + _this.bindListeners(); + return _this; + } + Connection.prototype.handlesActivityChecks = function () { + return this.transport.handlesActivityChecks(); + }; + Connection.prototype.send = function (data) { + return this.transport.send(data); + }; + Connection.prototype.send_event = function (name, data, channel) { + var event = { event: name, data: data }; + if (channel) { + event.channel = channel; + } + logger.debug('Event sent', event); + return this.send(protocol.encodeMessage(event)); + }; + Connection.prototype.ping = function () { + if (this.transport.supportsPing()) { + this.transport.ping(); + } + else { + this.send_event('pusher:ping', {}); + } + }; + Connection.prototype.close = function () { + this.transport.close(); + }; + Connection.prototype.bindListeners = function () { + var _this = this; + var listeners = { + message: function (messageEvent) { + var pusherEvent; + try { + pusherEvent = protocol.decodeMessage(messageEvent); + } + catch (e) { + _this.emit('error', { + type: 'MessageParseError', + error: e, + data: messageEvent.data + }); + } + if (pusherEvent !== undefined) { + logger.debug('Event recd', pusherEvent); + switch (pusherEvent.event) { + case 'pusher:error': + _this.emit('error', { type: 'PusherError', data: pusherEvent.data }); + break; + case 'pusher:ping': + _this.emit("ping"); + break; + case 'pusher:pong': + _this.emit("pong"); + break; + } + _this.emit('message', pusherEvent); + } + }, + activity: function () { + _this.emit("activity"); + }, + error: function (error) { + _this.emit("error", { type: "WebSocketError", error: error }); + }, + closed: function (closeEvent) { + unbindListeners(); + if (closeEvent && closeEvent.code) { + _this.handleCloseEvent(closeEvent); + } + _this.transport = null; + _this.emit("closed"); + } + }; + var unbindListeners = function () { + objectApply(listeners, function (listener, event) { + _this.transport.unbind(event, listener); + }); + }; + objectApply(listeners, function (listener, event) { + _this.transport.bind(event, listener); + }); + }; + Connection.prototype.handleCloseEvent = function (closeEvent) { + var action = protocol.getCloseAction(closeEvent); + var error = protocol.getCloseError(closeEvent); + if (error) { + this.emit('error', error); + } + if (action) { + this.emit(action, { action: action, error: error }); + } + }; + return Connection; +}(dispatcher)); +/* harmony default export */ var connection_connection = (connection_Connection); +// CONCATENATED MODULE: ./src/core/connection/handshake/index.ts -var Buffer = __webpack_require__(5).Buffer, - Base = __webpack_require__(7), - Draft75 = __webpack_require__(29), - crypto = __webpack_require__(11), - util = __webpack_require__(2); -var numberFromKey = function(key) { - return parseInt((key.match(/[0-9]/g) || []).join(''), 10); -}; +var handshake_Handshake = (function () { + function Handshake(transport, callback) { + this.transport = transport; + this.callback = callback; + this.bindListeners(); + } + Handshake.prototype.close = function () { + this.unbindListeners(); + this.transport.close(); + }; + Handshake.prototype.bindListeners = function () { + var _this = this; + this.onMessage = function (m) { + _this.unbindListeners(); + var result; + try { + result = protocol.processHandshake(m); + } + catch (e) { + _this.finish("error", { error: e }); + _this.transport.close(); + return; + } + if (result.action === "connected") { + _this.finish("connected", { + connection: new connection_connection(result.id, _this.transport), + activityTimeout: result.activityTimeout + }); + } + else { + _this.finish(result.action, { error: result.error }); + _this.transport.close(); + } + }; + this.onClosed = function (closeEvent) { + _this.unbindListeners(); + var action = protocol.getCloseAction(closeEvent) || "backoff"; + var error = protocol.getCloseError(closeEvent); + _this.finish(action, { error: error }); + }; + this.transport.bind("message", this.onMessage); + this.transport.bind("closed", this.onClosed); + }; + Handshake.prototype.unbindListeners = function () { + this.transport.unbind("message", this.onMessage); + this.transport.unbind("closed", this.onClosed); + }; + Handshake.prototype.finish = function (action, params) { + this.callback(extend({ transport: this.transport, action: action }, params)); + }; + return Handshake; +}()); +/* harmony default export */ var connection_handshake = (handshake_Handshake); -var spacesInKey = function(key) { - return (key.match(/ /g) || []).length; -}; +// CONCATENATED MODULE: ./src/core/auth/pusher_authorizer.ts +var pusher_authorizer_PusherAuthorizer = (function () { + function PusherAuthorizer(channel, options) { + this.channel = channel; + var authTransport = options.authTransport; + if (typeof node_runtime.getAuthorizers()[authTransport] === "undefined") { + throw "'" + authTransport + "' is not a recognized auth transport"; + } + this.type = authTransport; + this.options = options; + this.authOptions = (options || {}).auth || {}; + } + PusherAuthorizer.prototype.composeQuery = function (socketId) { + var query = 'socket_id=' + encodeURIComponent(socketId) + + '&channel_name=' + encodeURIComponent(this.channel.name); + for (var i in this.authOptions.params) { + query += "&" + encodeURIComponent(i) + "=" + encodeURIComponent(this.authOptions.params[i]); + } + return query; + }; + PusherAuthorizer.prototype.authorize = function (socketId, callback) { + PusherAuthorizer.authorizers = PusherAuthorizer.authorizers || node_runtime.getAuthorizers(); + return PusherAuthorizer.authorizers[this.type].call(this, node_runtime, socketId, callback); + }; + return PusherAuthorizer; +}()); +/* harmony default export */ var pusher_authorizer = (pusher_authorizer_PusherAuthorizer); -var Draft76 = function(request, url, options) { - Draft75.apply(this, arguments); - this._stage = -1; - this._body = []; - this.version = 'hixie-76'; +// CONCATENATED MODULE: ./src/core/timeline/timeline_sender.ts - this._headers.clear(); +var timeline_sender_TimelineSender = (function () { + function TimelineSender(timeline, options) { + this.timeline = timeline; + this.options = options || {}; + } + TimelineSender.prototype.send = function (useTLS, callback) { + if (this.timeline.isEmpty()) { + return; + } + this.timeline.send(node_runtime.TimelineTransport.getAgent(this, useTLS), callback); + }; + return TimelineSender; +}()); +/* harmony default export */ var timeline_sender = (timeline_sender_TimelineSender); - this._headers.set('Upgrade', 'WebSocket'); - this._headers.set('Connection', 'Upgrade'); - this._headers.set('Sec-WebSocket-Origin', this._request.headers.origin); - this._headers.set('Sec-WebSocket-Location', this.url); -}; -util.inherits(Draft76, Draft75); +// CONCATENATED MODULE: ./src/core/errors.ts +var errors_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var BadEventName = (function (_super) { + errors_extends(BadEventName, _super); + function BadEventName(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return BadEventName; +}(Error)); -var instance = { - BODY_SIZE: 8, +var RequestTimedOut = (function (_super) { + errors_extends(RequestTimedOut, _super); + function RequestTimedOut(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return RequestTimedOut; +}(Error)); - start: function() { - if (!Draft75.prototype.start.call(this)) return false; - this._started = true; - this._sendHandshakeBody(); - return true; - }, +var TransportPriorityTooLow = (function (_super) { + errors_extends(TransportPriorityTooLow, _super); + function TransportPriorityTooLow(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return TransportPriorityTooLow; +}(Error)); - close: function() { - if (this.readyState === 3) return false; - if (this.readyState === 1) this._write(Buffer.from([0xFF, 0x00])); - this.readyState = 3; - this.emit('close', new Base.CloseEvent(null, null)); - return true; - }, +var TransportClosed = (function (_super) { + errors_extends(TransportClosed, _super); + function TransportClosed(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return TransportClosed; +}(Error)); - _handshakeResponse: function() { - var headers = this._request.headers, - key1 = headers['sec-websocket-key1'], - key2 = headers['sec-websocket-key2']; +var UnsupportedFeature = (function (_super) { + errors_extends(UnsupportedFeature, _super); + function UnsupportedFeature(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return UnsupportedFeature; +}(Error)); - if (!key1) throw new Error('Missing required header: Sec-WebSocket-Key1'); - if (!key2) throw new Error('Missing required header: Sec-WebSocket-Key2'); +var UnsupportedTransport = (function (_super) { + errors_extends(UnsupportedTransport, _super); + function UnsupportedTransport(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return UnsupportedTransport; +}(Error)); - var number1 = numberFromKey(key1), - spaces1 = spacesInKey(key1), +var UnsupportedStrategy = (function (_super) { + errors_extends(UnsupportedStrategy, _super); + function UnsupportedStrategy(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return UnsupportedStrategy; +}(Error)); - number2 = numberFromKey(key2), - spaces2 = spacesInKey(key2); - if (number1 % spaces1 !== 0 || number2 % spaces2 !== 0) - throw new Error('Client sent invalid Sec-WebSocket-Key headers'); +// CONCATENATED MODULE: ./src/core/utils/url_store.ts +var urlStore = { + baseUrl: "https://pusher.com", + urls: { + authenticationEndpoint: { + path: "/docs/authenticating_users", + }, + javascriptQuickStart: { + path: "/docs/javascript_quick_start" + }, + triggeringClientEvents: { + path: "/docs/client_api_guide/client_events#trigger-events" + } + } +}; +var buildLogSuffix = function (key) { + var urlPrefix = "See:"; + var urlObj = urlStore.urls[key]; + if (!urlObj) + return ""; + var url; + if (urlObj.fullUrl) { + url = urlObj.fullUrl; + } + else if (urlObj.path) { + url = urlStore.baseUrl + urlObj.path; + } + if (!url) + return ""; + return urlPrefix + " " + url; +}; +/* harmony default export */ var url_store = ({ buildLogSuffix: buildLogSuffix }); - this._keyValues = [number1 / spaces1, number2 / spaces2]; +// CONCATENATED MODULE: ./src/core/channels/channel.ts +var channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); - var start = 'HTTP/1.1 101 WebSocket Protocol Handshake', - headers = [start, this._headers.toString(), '']; - return Buffer.from(headers.join('\r\n'), 'binary'); - }, - _handshakeSignature: function() { - if (this._body.length < this.BODY_SIZE) return null; - var md5 = crypto.createHash('md5'), - buffer = Buffer.allocUnsafe(8 + this.BODY_SIZE); +var channel_Channel = (function (_super) { + channel_extends(Channel, _super); + function Channel(name, pusher) { + var _this = _super.call(this, function (event, data) { + logger.debug('No callbacks on ' + name + ' for ' + event); + }) || this; + _this.name = name; + _this.pusher = pusher; + _this.subscribed = false; + _this.subscriptionPending = false; + _this.subscriptionCancelled = false; + return _this; + } + Channel.prototype.authorize = function (socketId, callback) { + return callback(false, {}); + }; + Channel.prototype.trigger = function (event, data) { + if (event.indexOf("client-") !== 0) { + throw new BadEventName("Event '" + event + "' does not start with 'client-'"); + } + if (!this.subscribed) { + var suffix = url_store.buildLogSuffix("triggeringClientEvents"); + logger.warn("Client event triggered before channel 'subscription_succeeded' event . " + suffix); + } + return this.pusher.send_event(event, data, this.name); + }; + Channel.prototype.disconnect = function () { + this.subscribed = false; + this.subscriptionPending = false; + }; + Channel.prototype.handleEvent = function (event) { + var eventName = event.event; + var data = event.data; + if (eventName === "pusher_internal:subscription_succeeded") { + this.handleSubscriptionSucceededEvent(event); + } + else if (eventName.indexOf("pusher_internal:") !== 0) { + var metadata = {}; + this.emit(eventName, data, metadata); + } + }; + Channel.prototype.handleSubscriptionSucceededEvent = function (event) { + this.subscriptionPending = false; + this.subscribed = true; + if (this.subscriptionCancelled) { + this.pusher.unsubscribe(this.name); + } + else { + this.emit("pusher:subscription_succeeded", event.data); + } + }; + Channel.prototype.subscribe = function () { + var _this = this; + if (this.subscribed) { + return; + } + this.subscriptionPending = true; + this.subscriptionCancelled = false; + this.authorize(this.pusher.connection.socket_id, function (error, data) { + if (error) { + _this.emit('pusher:subscription_error', data); + } + else { + _this.pusher.send_event('pusher:subscribe', { + auth: data.auth, + channel_data: data.channel_data, + channel: _this.name + }); + } + }); + }; + Channel.prototype.unsubscribe = function () { + this.subscribed = false; + this.pusher.send_event('pusher:unsubscribe', { + channel: this.name + }); + }; + Channel.prototype.cancelSubscription = function () { + this.subscriptionCancelled = true; + }; + Channel.prototype.reinstateSubscription = function () { + this.subscriptionCancelled = false; + }; + return Channel; +}(dispatcher)); +/* harmony default export */ var channels_channel = (channel_Channel); - buffer.writeUInt32BE(this._keyValues[0], 0); - buffer.writeUInt32BE(this._keyValues[1], 4); - Buffer.from(this._body).copy(buffer, 8, 0, this.BODY_SIZE); +// CONCATENATED MODULE: ./src/core/channels/private_channel.ts +var private_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); - md5.update(buffer); - return Buffer.from(md5.digest('binary'), 'binary'); - }, - _sendHandshakeBody: function() { - if (!this._started) return; - var signature = this._handshakeSignature(); - if (!signature) return; +var private_channel_PrivateChannel = (function (_super) { + private_channel_extends(PrivateChannel, _super); + function PrivateChannel() { + return _super !== null && _super.apply(this, arguments) || this; + } + PrivateChannel.prototype.authorize = function (socketId, callback) { + var authorizer = factory.createAuthorizer(this, this.pusher.config); + return authorizer.authorize(socketId, callback); + }; + return PrivateChannel; +}(channels_channel)); +/* harmony default export */ var private_channel = (private_channel_PrivateChannel); - this._write(signature); - this._stage = 0; - this._open(); +// CONCATENATED MODULE: ./src/core/channels/members.ts - if (this._body.length > this.BODY_SIZE) - this.parse(this._body.slice(this.BODY_SIZE)); - }, +var members_Members = (function () { + function Members() { + this.reset(); + } + Members.prototype.get = function (id) { + if (Object.prototype.hasOwnProperty.call(this.members, id)) { + return { + id: id, + info: this.members[id] + }; + } + else { + return null; + } + }; + Members.prototype.each = function (callback) { + var _this = this; + objectApply(this.members, function (member, id) { + callback(_this.get(id)); + }); + }; + Members.prototype.setMyID = function (id) { + this.myID = id; + }; + Members.prototype.onSubscription = function (subscriptionData) { + this.members = subscriptionData.presence.hash; + this.count = subscriptionData.presence.count; + this.me = this.get(this.myID); + }; + Members.prototype.addMember = function (memberData) { + if (this.get(memberData.user_id) === null) { + this.count++; + } + this.members[memberData.user_id] = memberData.user_info; + return this.get(memberData.user_id); + }; + Members.prototype.removeMember = function (memberData) { + var member = this.get(memberData.user_id); + if (member) { + delete this.members[memberData.user_id]; + this.count--; + } + return member; + }; + Members.prototype.reset = function () { + this.members = {}; + this.count = 0; + this.myID = null; + this.me = null; + }; + return Members; +}()); +/* harmony default export */ var members = (members_Members); - _parseLeadingByte: function(octet) { - if (octet !== 0xFF) - return Draft75.prototype._parseLeadingByte.call(this, octet); +// CONCATENATED MODULE: ./src/core/channels/presence_channel.ts +var presence_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); - this._closing = true; - this._length = 0; - this._stage = 1; - } -}; -for (var key in instance) - Draft76.prototype[key] = instance[key]; -module.exports = Draft76; +var presence_channel_PresenceChannel = (function (_super) { + presence_channel_extends(PresenceChannel, _super); + function PresenceChannel(name, pusher) { + var _this = _super.call(this, name, pusher) || this; + _this.members = new members(); + return _this; + } + PresenceChannel.prototype.authorize = function (socketId, callback) { + var _this = this; + _super.prototype.authorize.call(this, socketId, function (error, authData) { + if (!error) { + if (authData.channel_data === undefined) { + var suffix = url_store.buildLogSuffix("authenticationEndpoint"); + logger.warn("Invalid auth response for channel '" + _this.name + "'," + + ("expected 'channel_data' field. " + suffix)); + callback("Invalid auth response"); + return; + } + var channelData = JSON.parse(authData.channel_data); + _this.members.setMyID(channelData.user_id); + } + callback(error, authData); + }); + }; + PresenceChannel.prototype.handleEvent = function (event) { + var eventName = event.event; + if (eventName.indexOf("pusher_internal:") === 0) { + this.handleInternalEvent(event); + } + else { + var data = event.data; + var metadata = {}; + if (event.user_id) { + metadata.user_id = event.user_id; + } + this.emit(eventName, data, metadata); + } + }; + PresenceChannel.prototype.handleInternalEvent = function (event) { + var eventName = event.event; + var data = event.data; + switch (eventName) { + case "pusher_internal:subscription_succeeded": + this.handleSubscriptionSucceededEvent(event); + break; + case "pusher_internal:member_added": + var addedMember = this.members.addMember(data); + this.emit('pusher:member_added', addedMember); + break; + case "pusher_internal:member_removed": + var removedMember = this.members.removeMember(data); + if (removedMember) { + this.emit('pusher:member_removed', removedMember); + } + break; + } + }; + PresenceChannel.prototype.handleSubscriptionSucceededEvent = function (event) { + this.subscriptionPending = false; + this.subscribed = true; + if (this.subscriptionCancelled) { + this.pusher.unsubscribe(this.name); + } + else { + this.members.onSubscription(event.data); + this.emit("pusher:subscription_succeeded", this.members); + } + }; + PresenceChannel.prototype.disconnect = function () { + this.members.reset(); + _super.prototype.disconnect.call(this); + }; + return PresenceChannel; +}(private_channel)); +/* harmony default export */ var presence_channel = (presence_channel_PresenceChannel); + +// EXTERNAL MODULE: ./node_modules/tweetnacl/nacl-fast.js +var nacl_fast = __webpack_require__(3); -/***/ }), -/* 86 */ -/***/ (function(module, exports, __webpack_require__) { +// EXTERNAL MODULE: ./node_modules/tweetnacl-util/nacl-util.js +var nacl_util = __webpack_require__(4); -var util = __webpack_require__(2), - net = __webpack_require__(87), - tls = __webpack_require__(88), - crypto = __webpack_require__(11), - url = __webpack_require__(15), - driver = __webpack_require__(13), - API = __webpack_require__(21), - Event = __webpack_require__(16); +// CONCATENATED MODULE: ./src/core/channels/encrypted_channel.ts +var encrypted_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); -var DEFAULT_PORTS = {'http:': 80, 'https:': 443, 'ws:':80, 'wss:': 443}, - SECURE_PROTOCOLS = ['https:', 'wss:']; -var Client = function(_url, protocols, options) { - options = options || {}; - this.url = _url; - this._driver = driver.client(this.url, {maxLength: options.maxLength, protocols: protocols}); - ['open', 'error'].forEach(function(event) { - this._driver.on(event, function() { - self.headers = self._driver.headers; - self.statusCode = self._driver.statusCode; - }); - }, this); - var proxy = options.proxy || {}, - endpoint = url.parse(proxy.origin || this.url), - port = endpoint.port || DEFAULT_PORTS[endpoint.protocol], - secure = SECURE_PROTOCOLS.indexOf(endpoint.protocol) >= 0, - onConnect = function() { self._onConnect() }, - originTLS = options.tls || {}, - socketTLS = proxy.origin ? (proxy.tls || {}) : originTLS, - self = this; +var encrypted_channel_EncryptedChannel = (function (_super) { + encrypted_channel_extends(EncryptedChannel, _super); + function EncryptedChannel() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.key = null; + return _this; + } + EncryptedChannel.prototype.authorize = function (socketId, callback) { + var _this = this; + _super.prototype.authorize.call(this, socketId, function (error, authData) { + if (error) { + callback(true, authData); + return; + } + var sharedSecret = authData["shared_secret"]; + if (!sharedSecret) { + var errorMsg = "No shared_secret key in auth payload for encrypted channel: " + _this.name; + callback(true, errorMsg); + logger.warn("Error: " + errorMsg); + return; + } + _this.key = Object(nacl_util["decodeBase64"])(sharedSecret); + delete authData["shared_secret"]; + callback(false, authData); + }); + }; + EncryptedChannel.prototype.trigger = function (event, data) { + throw new UnsupportedFeature('Client events are not currently supported for encrypted channels'); + }; + EncryptedChannel.prototype.handleEvent = function (event) { + var eventName = event.event; + var data = event.data; + if (eventName.indexOf("pusher_internal:") === 0 || eventName.indexOf("pusher:") === 0) { + _super.prototype.handleEvent.call(this, event); + return; + } + this.handleEncryptedEvent(eventName, data); + }; + EncryptedChannel.prototype.handleEncryptedEvent = function (event, data) { + var _this = this; + if (!this.key) { + logger.debug('Received encrypted event before key has been retrieved from the authEndpoint'); + return; + } + if (!data.ciphertext || !data.nonce) { + logger.warn('Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: ' + data); + return; + } + var cipherText = Object(nacl_util["decodeBase64"])(data.ciphertext); + if (cipherText.length < nacl_fast["secretbox"].overheadLength) { + logger.warn("Expected encrypted event ciphertext length to be " + nacl_fast["secretbox"].overheadLength + ", got: " + cipherText.length); + return; + } + var nonce = Object(nacl_util["decodeBase64"])(data.nonce); + if (nonce.length < nacl_fast["secretbox"].nonceLength) { + logger.warn("Expected encrypted event nonce length to be " + nacl_fast["secretbox"].nonceLength + ", got: " + nonce.length); + return; + } + var bytes = nacl_fast["secretbox"].open(cipherText, nonce, this.key); + if (bytes === null) { + logger.debug('Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint...'); + this.authorize(this.pusher.connection.socket_id, function (error, authData) { + if (error) { + logger.warn("Failed to make a request to the authEndpoint: " + authData + ". Unable to fetch new key, so dropping encrypted event"); + return; + } + bytes = nacl_fast["secretbox"].open(cipherText, nonce, _this.key); + if (bytes === null) { + logger.warn("Failed to decrypt event with new key. Dropping encrypted event"); + return; + } + _this.emitJSON(event, Object(nacl_util["encodeUTF8"])(bytes)); + return; + }); + return; + } + this.emitJSON(event, Object(nacl_util["encodeUTF8"])(bytes)); + }; + EncryptedChannel.prototype.emitJSON = function (eventName, data) { + try { + this.emit(eventName, JSON.parse(data)); + } + catch (e) { + this.emit(eventName, data); + } + return this; + }; + return EncryptedChannel; +}(private_channel)); +/* harmony default export */ var encrypted_channel = (encrypted_channel_EncryptedChannel); - originTLS.ca = originTLS.ca || options.ca; +// CONCATENATED MODULE: ./src/core/connection/connection_manager.ts +var connection_manager_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); - this._stream = secure - ? tls.connect(port, endpoint.hostname, socketTLS, onConnect) - : net.connect(port, endpoint.hostname, onConnect); - if (proxy.origin) this._configureProxy(proxy, originTLS); - API.call(this, options); -}; -util.inherits(Client, API); -Client.prototype._onConnect = function() { - var worker = this._proxy || this._driver; - worker.start(); -}; -Client.prototype._configureProxy = function(proxy, originTLS) { - var uri = url.parse(this.url), - secure = SECURE_PROTOCOLS.indexOf(uri.protocol) >= 0, - self = this, - name; +var connection_manager_ConnectionManager = (function (_super) { + connection_manager_extends(ConnectionManager, _super); + function ConnectionManager(key, options) { + var _this = _super.call(this) || this; + _this.key = key; + _this.options = options || {}; + _this.state = "initialized"; + _this.connection = null; + _this.usingTLS = !!options.useTLS; + _this.timeline = _this.options.timeline; + _this.errorCallbacks = _this.buildErrorCallbacks(); + _this.connectionCallbacks = _this.buildConnectionCallbacks(_this.errorCallbacks); + _this.handshakeCallbacks = _this.buildHandshakeCallbacks(_this.errorCallbacks); + var Network = node_runtime.getNetwork(); + Network.bind("online", function () { + _this.timeline.info({ netinfo: "online" }); + if (_this.state === "connecting" || _this.state === "unavailable") { + _this.retryIn(0); + } + }); + Network.bind("offline", function () { + _this.timeline.info({ netinfo: "offline" }); + if (_this.connection) { + _this.sendActivityCheck(); + } + }); + _this.updateStrategy(); + return _this; + } + ConnectionManager.prototype.connect = function () { + if (this.connection || this.runner) { + return; + } + if (!this.strategy.isSupported()) { + this.updateState("failed"); + return; + } + this.updateState("connecting"); + this.startConnecting(); + this.setUnavailableTimer(); + }; + ; + ConnectionManager.prototype.send = function (data) { + if (this.connection) { + return this.connection.send(data); + } + else { + return false; + } + }; + ; + ConnectionManager.prototype.send_event = function (name, data, channel) { + if (this.connection) { + return this.connection.send_event(name, data, channel); + } + else { + return false; + } + }; + ; + ConnectionManager.prototype.disconnect = function () { + this.disconnectInternally(); + this.updateState("disconnected"); + }; + ; + ConnectionManager.prototype.isUsingTLS = function () { + return this.usingTLS; + }; + ; + ConnectionManager.prototype.startConnecting = function () { + var _this = this; + var callback = function (error, handshake) { + if (error) { + _this.runner = _this.strategy.connect(0, callback); + } + else { + if (handshake.action === "error") { + _this.emit("error", { type: "HandshakeError", error: handshake.error }); + _this.timeline.error({ handshakeError: handshake.error }); + } + else { + _this.abortConnecting(); + _this.handshakeCallbacks[handshake.action](handshake); + } + } + }; + this.runner = this.strategy.connect(0, callback); + }; + ; + ConnectionManager.prototype.abortConnecting = function () { + if (this.runner) { + this.runner.abort(); + this.runner = null; + } + }; + ; + ConnectionManager.prototype.disconnectInternally = function () { + this.abortConnecting(); + this.clearRetryTimer(); + this.clearUnavailableTimer(); + if (this.connection) { + var connection = this.abandonConnection(); + connection.close(); + } + }; + ; + ConnectionManager.prototype.updateStrategy = function () { + this.strategy = this.options.getStrategy({ + key: this.key, + timeline: this.timeline, + useTLS: this.usingTLS + }); + }; + ; + ConnectionManager.prototype.retryIn = function (delay) { + var _this = this; + this.timeline.info({ action: "retry", delay: delay }); + if (delay > 0) { + this.emit("connecting_in", Math.round(delay / 1000)); + } + this.retryTimer = new OneOffTimer(delay || 0, function () { + _this.disconnectInternally(); + _this.connect(); + }); + }; + ; + ConnectionManager.prototype.clearRetryTimer = function () { + if (this.retryTimer) { + this.retryTimer.ensureAborted(); + this.retryTimer = null; + } + }; + ; + ConnectionManager.prototype.setUnavailableTimer = function () { + var _this = this; + this.unavailableTimer = new OneOffTimer(this.options.unavailableTimeout, function () { + _this.updateState("unavailable"); + }); + }; + ; + ConnectionManager.prototype.clearUnavailableTimer = function () { + if (this.unavailableTimer) { + this.unavailableTimer.ensureAborted(); + } + }; + ; + ConnectionManager.prototype.sendActivityCheck = function () { + var _this = this; + this.stopActivityCheck(); + this.connection.ping(); + this.activityTimer = new OneOffTimer(this.options.pongTimeout, function () { + _this.timeline.error({ pong_timed_out: _this.options.pongTimeout }); + _this.retryIn(0); + }); + }; + ; + ConnectionManager.prototype.resetActivityCheck = function () { + var _this = this; + this.stopActivityCheck(); + if (this.connection && !this.connection.handlesActivityChecks()) { + this.activityTimer = new OneOffTimer(this.activityTimeout, function () { + _this.sendActivityCheck(); + }); + } + }; + ; + ConnectionManager.prototype.stopActivityCheck = function () { + if (this.activityTimer) { + this.activityTimer.ensureAborted(); + } + }; + ; + ConnectionManager.prototype.buildConnectionCallbacks = function (errorCallbacks) { + var _this = this; + return extend({}, errorCallbacks, { + message: function (message) { + _this.resetActivityCheck(); + _this.emit('message', message); + }, + ping: function () { + _this.send_event('pusher:pong', {}); + }, + activity: function () { + _this.resetActivityCheck(); + }, + error: function (error) { + _this.emit("error", { type: "WebSocketError", error: error }); + }, + closed: function () { + _this.abandonConnection(); + if (_this.shouldRetry()) { + _this.retryIn(1000); + } + } + }); + }; + ; + ConnectionManager.prototype.buildHandshakeCallbacks = function (errorCallbacks) { + var _this = this; + return extend({}, errorCallbacks, { + connected: function (handshake) { + _this.activityTimeout = Math.min(_this.options.activityTimeout, handshake.activityTimeout, handshake.connection.activityTimeout || Infinity); + _this.clearUnavailableTimer(); + _this.setConnection(handshake.connection); + _this.socket_id = _this.connection.id; + _this.updateState("connected", { socket_id: _this.socket_id }); + } + }); + }; + ; + ConnectionManager.prototype.buildErrorCallbacks = function () { + var _this = this; + var withErrorEmitted = function (callback) { + return function (result) { + if (result.error) { + _this.emit("error", { type: "WebSocketError", error: result.error }); + } + callback(result); + }; + }; + return { + tls_only: withErrorEmitted(function () { + _this.usingTLS = true; + _this.updateStrategy(); + _this.retryIn(0); + }), + refused: withErrorEmitted(function () { + _this.disconnect(); + }), + backoff: withErrorEmitted(function () { + _this.retryIn(1000); + }), + retry: withErrorEmitted(function () { + _this.retryIn(0); + }) + }; + }; + ; + ConnectionManager.prototype.setConnection = function (connection) { + this.connection = connection; + for (var event in this.connectionCallbacks) { + this.connection.bind(event, this.connectionCallbacks[event]); + } + this.resetActivityCheck(); + }; + ; + ConnectionManager.prototype.abandonConnection = function () { + if (!this.connection) { + return; + } + this.stopActivityCheck(); + for (var event in this.connectionCallbacks) { + this.connection.unbind(event, this.connectionCallbacks[event]); + } + var connection = this.connection; + this.connection = null; + return connection; + }; + ConnectionManager.prototype.updateState = function (newState, data) { + var previousState = this.state; + this.state = newState; + if (previousState !== newState) { + var newStateDescription = newState; + if (newStateDescription === "connected") { + newStateDescription += " with new socket ID " + data.socket_id; + } + logger.debug('State changed', previousState + ' -> ' + newStateDescription); + this.timeline.info({ state: newState, params: data }); + this.emit('state_change', { previous: previousState, current: newState }); + this.emit(newState, data); + } + }; + ConnectionManager.prototype.shouldRetry = function () { + return this.state === "connecting" || this.state === "connected"; + }; + return ConnectionManager; +}(dispatcher)); +/* harmony default export */ var connection_manager = (connection_manager_ConnectionManager); - this._proxy = this._driver.proxy(proxy.origin); +// CONCATENATED MODULE: ./src/core/channels/channels.ts - if (proxy.headers) { - for (name in proxy.headers) this._proxy.setHeader(name, proxy.headers[name]); - } - this._proxy.pipe(this._stream, {end: false}); - this._stream.pipe(this._proxy); - this._proxy.on('connect', function() { - if (secure) { - var options = {socket: self._stream, servername: uri.hostname}; - for (name in originTLS) options[name] = originTLS[name]; - self._stream = tls.connect(options); - self._configureStream(); +var channels_Channels = (function () { + function Channels() { + this.channels = {}; } - self._driver.io.pipe(self._stream); - self._stream.pipe(self._driver.io); - self._driver.start(); - }); - - this._proxy.on('error', function(error) { - self._driver.emit('error', error); - }); -}; - -module.exports = Client; - - -/***/ }), -/* 87 */ -/***/ (function(module, exports) { - -module.exports = require("net"); - -/***/ }), -/* 88 */ -/***/ (function(module, exports) { - -module.exports = require("tls"); - -/***/ }), -/* 89 */ -/***/ (function(module, exports, __webpack_require__) { - -var Stream = __webpack_require__(14).Stream, - util = __webpack_require__(2), - driver = __webpack_require__(13), - Headers = __webpack_require__(19), - API = __webpack_require__(21), - EventTarget = __webpack_require__(30), - Event = __webpack_require__(16); - -var EventSource = function(request, response, options) { - this.writable = true; - options = options || {}; - - this._stream = response.socket; - this._ping = options.ping || this.DEFAULT_PING; - this._retry = options.retry || this.DEFAULT_RETRY; - - var scheme = driver.isSecureRequest(request) ? 'https:' : 'http:'; - this.url = scheme + '//' + request.headers.host + request.url; - this.lastEventId = request.headers['last-event-id'] || ''; - this.readyState = API.CONNECTING; - - var headers = new Headers(), - self = this; - - if (options.headers) { - for (var key in options.headers) headers.set(key, options.headers[key]); - } - - if (!this._stream || !this._stream.writable) return; - process.nextTick(function() { self._open() }); - - this._stream.setTimeout(0); - this._stream.setNoDelay(true); - - var handshake = 'HTTP/1.1 200 OK\r\n' + - 'Content-Type: text/event-stream\r\n' + - 'Cache-Control: no-cache, no-store\r\n' + - 'Connection: close\r\n' + - headers.toString() + - '\r\n' + - 'retry: ' + Math.floor(this._retry * 1000) + '\r\n\r\n'; - - this._write(handshake); - - this._stream.on('drain', function() { self.emit('drain') }); - - if (this._ping) - this._pingTimer = setInterval(function() { self.ping() }, this._ping * 1000); - - ['error', 'end'].forEach(function(event) { - self._stream.on(event, function() { self.close() }); - }); -}; -util.inherits(EventSource, Stream); - -EventSource.isEventSource = function(request) { - if (request.method !== 'GET') return false; - var accept = (request.headers.accept || '').split(/\s*,\s*/); - return accept.indexOf('text/event-stream') >= 0; -}; - -var instance = { - DEFAULT_PING: 10, - DEFAULT_RETRY: 5, - - _write: function(chunk) { - if (!this.writable) return false; - try { - return this._stream.write(chunk, 'utf8'); - } catch (e) { - return false; + Channels.prototype.add = function (name, pusher) { + if (!this.channels[name]) { + this.channels[name] = createChannel(name, pusher); + } + return this.channels[name]; + }; + Channels.prototype.all = function () { + return values(this.channels); + }; + Channels.prototype.find = function (name) { + return this.channels[name]; + }; + Channels.prototype.remove = function (name) { + var channel = this.channels[name]; + delete this.channels[name]; + return channel; + }; + Channels.prototype.disconnect = function () { + objectApply(this.channels, function (channel) { + channel.disconnect(); + }); + }; + return Channels; +}()); +/* harmony default export */ var channels = (channels_Channels); +function createChannel(name, pusher) { + if (name.indexOf('private-encrypted-') === 0) { + if (false) { var errorMsg; } + return factory.createEncryptedChannel(name, pusher); } - }, - - _open: function() { - if (this.readyState !== API.CONNECTING) return; - - this.readyState = API.OPEN; - - var event = new Event('open'); - event.initEvent('open', false, false); - this.dispatchEvent(event); - }, - - write: function(message) { - return this.send(message); - }, - - end: function(message) { - if (message !== undefined) this.write(message); - this.close(); - }, - - send: function(message, options) { - if (this.readyState > API.OPEN) return false; - - message = String(message).replace(/(\r\n|\r|\n)/g, '$1data: '); - options = options || {}; - - var frame = ''; - if (options.event) frame += 'event: ' + options.event + '\r\n'; - if (options.id) frame += 'id: ' + options.id + '\r\n'; - frame += 'data: ' + message + '\r\n\r\n'; - - return this._write(frame); - }, - - ping: function() { - return this._write(':\r\n\r\n'); - }, - - close: function() { - if (this.readyState > API.OPEN) return false; - - this.readyState = API.CLOSED; - this.writable = false; - if (this._pingTimer) clearInterval(this._pingTimer); - if (this._stream) this._stream.end(); - - var event = new Event('close'); - event.initEvent('close', false, false); - this.dispatchEvent(event); - - return true; - } -}; - -for (var method in instance) EventSource.prototype[method] = instance[method]; -for (var key in EventTarget) EventSource.prototype[key] = EventTarget[key]; - -module.exports = EventSource; - - -/***/ }), -/* 90 */ -/***/ (function(module, exports, __webpack_require__) { - -/** - * Wrapper for built-in http.js to emulate the browser XMLHttpRequest object. - * - * This can be used with JS designed for browsers to improve reuse of code and - * allow the use of existing libraries. - * - * Usage: include("XMLHttpRequest.js") and use XMLHttpRequest per W3C specs. - * - * @author Dan DeFelippi - * @contributor David Ellis - * @license MIT - */ - -var Url = __webpack_require__(15); -var spawn = __webpack_require__(91).spawn; -var fs = __webpack_require__(92); - -exports.XMLHttpRequest = function() { - "use strict"; - - /** - * Private variables - */ - var self = this; - var http = __webpack_require__(93); - var https = __webpack_require__(94); - - // Holds http.js objects - var request; - var response; + else if (name.indexOf('private-') === 0) { + return factory.createPrivateChannel(name, pusher); + } + else if (name.indexOf('presence-') === 0) { + return factory.createPresenceChannel(name, pusher); + } + else { + return factory.createChannel(name, pusher); + } +} - // Request settings - var settings = {}; +// CONCATENATED MODULE: ./src/core/utils/factory.ts - // Disable header blacklist. - // Not part of XHR specs. - var disableHeaderCheck = false; - // Set some default headers - var defaultHeaders = { - "User-Agent": "node-XMLHttpRequest", - "Accept": "*/*", - }; - var headers = {}; - var headersCase = {}; - // These headers are not user setable. - // The following are allowed but banned in the spec: - // * user-agent - var forbiddenRequestHeaders = [ - "accept-charset", - "accept-encoding", - "access-control-request-headers", - "access-control-request-method", - "connection", - "content-length", - "content-transfer-encoding", - "cookie", - "cookie2", - "date", - "expect", - "host", - "keep-alive", - "origin", - "referer", - "te", - "trailer", - "transfer-encoding", - "upgrade", - "via" - ]; - // These request methods are not allowed - var forbiddenRequestMethods = [ - "TRACE", - "TRACK", - "CONNECT" - ]; - // Send flag - var sendFlag = false; - // Error flag, used when errors occur or abort is called - var errorFlag = false; - // Event listeners - var listeners = {}; - /** - * Constants - */ - this.UNSENT = 0; - this.OPENED = 1; - this.HEADERS_RECEIVED = 2; - this.LOADING = 3; - this.DONE = 4; - /** - * Public vars - */ +var Factory = { + createChannels: function () { + return new channels(); + }, + createConnectionManager: function (key, options) { + return new connection_manager(key, options); + }, + createChannel: function (name, pusher) { + return new channels_channel(name, pusher); + }, + createPrivateChannel: function (name, pusher) { + return new private_channel(name, pusher); + }, + createPresenceChannel: function (name, pusher) { + return new presence_channel(name, pusher); + }, + createEncryptedChannel: function (name, pusher) { + return new encrypted_channel(name, pusher); + }, + createTimelineSender: function (timeline, options) { + return new timeline_sender(timeline, options); + }, + createAuthorizer: function (channel, options) { + if (options.authorizer) { + return options.authorizer(channel, options); + } + return new pusher_authorizer(channel, options); + }, + createHandshake: function (transport, callback) { + return new connection_handshake(transport, callback); + }, + createAssistantToTheTransportManager: function (manager, transport, options) { + return new assistant_to_the_transport_manager(manager, transport, options); + } +}; +/* harmony default export */ var factory = (Factory); - // Current state - this.readyState = this.UNSENT; +// CONCATENATED MODULE: ./src/core/transports/transport_manager.ts - // default ready state change handler in case one is not set or is set late - this.onreadystatechange = null; +var transport_manager_TransportManager = (function () { + function TransportManager(options) { + this.options = options || {}; + this.livesLeft = this.options.lives || Infinity; + } + TransportManager.prototype.getAssistant = function (transport) { + return factory.createAssistantToTheTransportManager(this, transport, { + minPingDelay: this.options.minPingDelay, + maxPingDelay: this.options.maxPingDelay + }); + }; + TransportManager.prototype.isAlive = function () { + return this.livesLeft > 0; + }; + TransportManager.prototype.reportDeath = function () { + this.livesLeft -= 1; + }; + return TransportManager; +}()); +/* harmony default export */ var transport_manager = (transport_manager_TransportManager); - // Result & response - this.responseText = ""; - this.responseXML = ""; - this.status = null; - this.statusText = null; - - // Whether cross-site Access-Control requests should be made using - // credentials such as cookies or authorization headers - this.withCredentials = false; +// CONCATENATED MODULE: ./src/core/strategies/sequential_strategy.ts - /** - * Private methods - */ - /** - * Check if the specified header is allowed. - * - * @param string header Header to validate - * @return boolean False if not allowed, otherwise true - */ - var isAllowedHttpHeader = function(header) { - return disableHeaderCheck || (header && forbiddenRequestHeaders.indexOf(header.toLowerCase()) === -1); - }; - /** - * Check if the specified method is allowed. - * - * @param string method Request method to validate - * @return boolean False if not allowed, otherwise true - */ - var isAllowedHttpMethod = function(method) { - return (method && forbiddenRequestMethods.indexOf(method) === -1); - }; +var sequential_strategy_SequentialStrategy = (function () { + function SequentialStrategy(strategies, options) { + this.strategies = strategies; + this.loop = Boolean(options.loop); + this.failFast = Boolean(options.failFast); + this.timeout = options.timeout; + this.timeoutLimit = options.timeoutLimit; + } + SequentialStrategy.prototype.isSupported = function () { + return any(this.strategies, util.method("isSupported")); + }; + SequentialStrategy.prototype.connect = function (minPriority, callback) { + var _this = this; + var strategies = this.strategies; + var current = 0; + var timeout = this.timeout; + var runner = null; + var tryNextStrategy = function (error, handshake) { + if (handshake) { + callback(null, handshake); + } + else { + current = current + 1; + if (_this.loop) { + current = current % strategies.length; + } + if (current < strategies.length) { + if (timeout) { + timeout = timeout * 2; + if (_this.timeoutLimit) { + timeout = Math.min(timeout, _this.timeoutLimit); + } + } + runner = _this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: _this.failFast }, tryNextStrategy); + } + else { + callback(true); + } + } + }; + runner = this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: this.failFast }, tryNextStrategy); + return { + abort: function () { + runner.abort(); + }, + forceMinPriority: function (p) { + minPriority = p; + if (runner) { + runner.forceMinPriority(p); + } + } + }; + }; + SequentialStrategy.prototype.tryStrategy = function (strategy, minPriority, options, callback) { + var timer = null; + var runner = null; + if (options.timeout > 0) { + timer = new OneOffTimer(options.timeout, function () { + runner.abort(); + callback(true); + }); + } + runner = strategy.connect(minPriority, function (error, handshake) { + if (error && timer && timer.isRunning() && !options.failFast) { + return; + } + if (timer) { + timer.ensureAborted(); + } + callback(error, handshake); + }); + return { + abort: function () { + if (timer) { + timer.ensureAborted(); + } + runner.abort(); + }, + forceMinPriority: function (p) { + runner.forceMinPriority(p); + } + }; + }; + return SequentialStrategy; +}()); +/* harmony default export */ var sequential_strategy = (sequential_strategy_SequentialStrategy); - /** - * Public methods - */ +// CONCATENATED MODULE: ./src/core/strategies/best_connected_ever_strategy.ts - /** - * Open the connection. Currently supports local server requests. - * - * @param string method Connection method (eg GET, POST) - * @param string url URL for the connection. - * @param boolean async Asynchronous connection. Default is true. - * @param string user Username for basic authentication (optional) - * @param string password Password for basic authentication (optional) - */ - this.open = function(method, url, async, user, password) { - this.abort(); - errorFlag = false; - // Check for valid request method - if (!isAllowedHttpMethod(method)) { - throw new Error("SecurityError: Request method not allowed"); +var best_connected_ever_strategy_BestConnectedEverStrategy = (function () { + function BestConnectedEverStrategy(strategies) { + this.strategies = strategies; + } + BestConnectedEverStrategy.prototype.isSupported = function () { + return any(this.strategies, util.method("isSupported")); + }; + BestConnectedEverStrategy.prototype.connect = function (minPriority, callback) { + return connect(this.strategies, minPriority, function (i, runners) { + return function (error, handshake) { + runners[i].error = error; + if (error) { + if (allRunnersFailed(runners)) { + callback(true); + } + return; + } + apply(runners, function (runner) { + runner.forceMinPriority(handshake.transport.priority); + }); + callback(null, handshake); + }; + }); + }; + return BestConnectedEverStrategy; +}()); +/* harmony default export */ var best_connected_ever_strategy = (best_connected_ever_strategy_BestConnectedEverStrategy); +function connect(strategies, minPriority, callbackBuilder) { + var runners = map(strategies, function (strategy, i, _, rs) { + return strategy.connect(minPriority, callbackBuilder(i, rs)); + }); + return { + abort: function () { + apply(runners, abortRunner); + }, + forceMinPriority: function (p) { + apply(runners, function (runner) { + runner.forceMinPriority(p); + }); + } + }; +} +function allRunnersFailed(runners) { + return collections_all(runners, function (runner) { + return Boolean(runner.error); + }); +} +function abortRunner(runner) { + if (!runner.error && !runner.aborted) { + runner.abort(); + runner.aborted = true; } +} - settings = { - "method": method, - "url": url.toString(), - "async": (typeof async !== "boolean" ? true : async), - "user": user || null, - "password": password || null - }; +// CONCATENATED MODULE: ./src/core/strategies/cached_strategy.ts - setState(this.OPENED); - }; - /** - * Disables or enables isAllowedHttpHeader() check the request. Enabled by default. - * This does not conform to the W3C spec. - * - * @param boolean state Enable or disable header checking. - */ - this.setDisableHeaderCheck = function(state) { - disableHeaderCheck = state; - }; - /** - * Sets a header for the request or appends the value if one is already set. - * - * @param string header Header name - * @param string value Header value - */ - this.setRequestHeader = function(header, value) { - if (this.readyState !== this.OPENED) { - throw new Error("INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN"); - } - if (!isAllowedHttpHeader(header)) { - console.warn("Refused to set unsafe header \"" + header + "\""); - return; - } - if (sendFlag) { - throw new Error("INVALID_STATE_ERR: send flag is true"); - } - header = headersCase[header.toLowerCase()] || header; - headersCase[header.toLowerCase()] = header; - headers[header] = headers[header] ? headers[header] + ', ' + value : value; - }; - /** - * Gets a header from the server response. - * - * @param string header Name of header to get. - * @return string Text of the header or null if it doesn't exist. - */ - this.getResponseHeader = function(header) { - if (typeof header === "string" - && this.readyState > this.OPENED - && response - && response.headers - && response.headers[header.toLowerCase()] - && !errorFlag - ) { - return response.headers[header.toLowerCase()]; +var cached_strategy_CachedStrategy = (function () { + function CachedStrategy(strategy, transports, options) { + this.strategy = strategy; + this.transports = transports; + this.ttl = options.ttl || 1800 * 1000; + this.usingTLS = options.useTLS; + this.timeline = options.timeline; + } + CachedStrategy.prototype.isSupported = function () { + return this.strategy.isSupported(); + }; + CachedStrategy.prototype.connect = function (minPriority, callback) { + var usingTLS = this.usingTLS; + var info = fetchTransportCache(usingTLS); + var strategies = [this.strategy]; + if (info && info.timestamp + this.ttl >= util.now()) { + var transport = this.transports[info.transport]; + if (transport) { + this.timeline.info({ + cached: true, + transport: info.transport, + latency: info.latency + }); + strategies.push(new sequential_strategy([transport], { + timeout: info.latency * 2 + 1000, + failFast: true + })); + } + } + var startTimestamp = util.now(); + var runner = strategies.pop().connect(minPriority, function cb(error, handshake) { + if (error) { + flushTransportCache(usingTLS); + if (strategies.length > 0) { + startTimestamp = util.now(); + runner = strategies.pop().connect(minPriority, cb); + } + else { + callback(error); + } + } + else { + storeTransportCache(usingTLS, handshake.transport.name, util.now() - startTimestamp); + callback(null, handshake); + } + }); + return { + abort: function () { + runner.abort(); + }, + forceMinPriority: function (p) { + minPriority = p; + if (runner) { + runner.forceMinPriority(p); + } + } + }; + }; + return CachedStrategy; +}()); +/* harmony default export */ var cached_strategy = (cached_strategy_CachedStrategy); +function getTransportCacheKey(usingTLS) { + return "pusherTransport" + (usingTLS ? "TLS" : "NonTLS"); +} +function fetchTransportCache(usingTLS) { + var storage = node_runtime.getLocalStorage(); + if (storage) { + try { + var serializedCache = storage[getTransportCacheKey(usingTLS)]; + if (serializedCache) { + return JSON.parse(serializedCache); + } + } + catch (e) { + flushTransportCache(usingTLS); + } } - return null; - }; - - /** - * Gets all the response headers. - * - * @return string A string with all response headers separated by CR+LF - */ - this.getAllResponseHeaders = function() { - if (this.readyState < this.HEADERS_RECEIVED || errorFlag) { - return ""; +} +function storeTransportCache(usingTLS, transport, latency) { + var storage = node_runtime.getLocalStorage(); + if (storage) { + try { + storage[getTransportCacheKey(usingTLS)] = safeJSONStringify({ + timestamp: util.now(), + transport: transport, + latency: latency + }); + } + catch (e) { + } } - var result = ""; - - for (var i in response.headers) { - // Cookie headers are excluded - if (i !== "set-cookie" && i !== "set-cookie2") { - result += i + ": " + response.headers[i] + "\r\n"; - } +} +function flushTransportCache(usingTLS) { + var storage = node_runtime.getLocalStorage(); + if (storage) { + try { + delete storage[getTransportCacheKey(usingTLS)]; + } + catch (e) { + } } - return result.substr(0, result.length - 2); - }; +} - /** - * Gets a request header - * - * @param string name Name of header to get - * @return string Returns the request header or empty string if not set - */ - this.getRequestHeader = function(name) { - if (typeof name === "string" && headersCase[name.toLowerCase()]) { - return headers[headersCase[name.toLowerCase()]]; - } +// CONCATENATED MODULE: ./src/core/strategies/delayed_strategy.ts - return ""; - }; +var delayed_strategy_DelayedStrategy = (function () { + function DelayedStrategy(strategy, _a) { + var number = _a.delay; + this.strategy = strategy; + this.options = { delay: number }; + } + DelayedStrategy.prototype.isSupported = function () { + return this.strategy.isSupported(); + }; + DelayedStrategy.prototype.connect = function (minPriority, callback) { + var strategy = this.strategy; + var runner; + var timer = new OneOffTimer(this.options.delay, function () { + runner = strategy.connect(minPriority, callback); + }); + return { + abort: function () { + timer.ensureAborted(); + if (runner) { + runner.abort(); + } + }, + forceMinPriority: function (p) { + minPriority = p; + if (runner) { + runner.forceMinPriority(p); + } + } + }; + }; + return DelayedStrategy; +}()); +/* harmony default export */ var delayed_strategy = (delayed_strategy_DelayedStrategy); - /** - * Sends the request to the server. - * - * @param string data Optional data to send as request body. - */ - this.send = function(data) { - if (this.readyState !== this.OPENED) { - throw new Error("INVALID_STATE_ERR: connection must be opened before send() is called"); +// CONCATENATED MODULE: ./src/core/strategies/if_strategy.ts +var IfStrategy = (function () { + function IfStrategy(test, trueBranch, falseBranch) { + this.test = test; + this.trueBranch = trueBranch; + this.falseBranch = falseBranch; } + IfStrategy.prototype.isSupported = function () { + var branch = this.test() ? this.trueBranch : this.falseBranch; + return branch.isSupported(); + }; + IfStrategy.prototype.connect = function (minPriority, callback) { + var branch = this.test() ? this.trueBranch : this.falseBranch; + return branch.connect(minPriority, callback); + }; + return IfStrategy; +}()); +/* harmony default export */ var if_strategy = (IfStrategy); - if (sendFlag) { - throw new Error("INVALID_STATE_ERR: send has already been called"); +// CONCATENATED MODULE: ./src/core/strategies/first_connected_strategy.ts +var FirstConnectedStrategy = (function () { + function FirstConnectedStrategy(strategy) { + this.strategy = strategy; } + FirstConnectedStrategy.prototype.isSupported = function () { + return this.strategy.isSupported(); + }; + FirstConnectedStrategy.prototype.connect = function (minPriority, callback) { + var runner = this.strategy.connect(minPriority, function (error, handshake) { + if (handshake) { + runner.abort(); + } + callback(error, handshake); + }); + return runner; + }; + return FirstConnectedStrategy; +}()); +/* harmony default export */ var first_connected_strategy = (FirstConnectedStrategy); - var ssl = false, local = false; - var url = Url.parse(settings.url); - var host; - // Determine the server - switch (url.protocol) { - case "https:": - ssl = true; - // SSL & non-SSL both need host, no break here. - case "http:": - host = url.hostname; - break; +// CONCATENATED MODULE: ./src/runtimes/isomorphic/default_strategy.ts - case "file:": - local = true; - break; - case undefined: - case null: - case "": - host = "localhost"; - break; - default: - throw new Error("Protocol not supported."); - } - // Load files off the local filesystem (file://) - if (local) { - if (settings.method !== "GET") { - throw new Error("XMLHttpRequest: Only GET method is supported"); - } - if (settings.async) { - fs.readFile(url.pathname, "utf8", function(error, data) { - if (error) { - self.handleError(error); - } else { - self.status = 200; - self.responseText = data; - setState(self.DONE); - } - }); - } else { - try { - this.responseText = fs.readFileSync(url.pathname, "utf8"); - this.status = 200; - setState(self.DONE); - } catch(e) { - this.handleError(e); - } - } - return; - } - // Default to port 80. If accessing localhost on another port be sure - // to use http://localhost:port/path - var port = url.port || (ssl ? 443 : 80); - // Add query string if one is used - var uri = url.pathname + (url.search ? url.search : ""); - // Set the defaults if they haven't been set - for (var name in defaultHeaders) { - if (!headersCase[name.toLowerCase()]) { - headers[name] = defaultHeaders[name]; - } +function testSupportsStrategy(strategy) { + return function () { + return strategy.isSupported(); + }; +} +var getDefaultStrategy = function (config, defineTransport) { + var definedTransports = {}; + function defineTransportStrategy(name, type, priority, options, manager) { + var transport = defineTransport(config, name, type, priority, options, manager); + definedTransports[name] = transport; + return transport; } - - // Set the Host header or the server may reject the request - headers.Host = host; - if (!((ssl && port === 443) || port === 80)) { - headers.Host += ":" + url.port; + var ws_options = { + hostNonTLS: config.wsHost + ":" + config.wsPort, + hostTLS: config.wsHost + ":" + config.wssPort, + httpPath: config.wsPath + }; + var wss_options = extend({}, ws_options, { + useTLS: true + }); + var http_options = { + hostNonTLS: config.httpHost + ":" + config.httpPort, + hostTLS: config.httpHost + ":" + config.httpsPort, + httpPath: config.httpPath + }; + var timeouts = { + loop: true, + timeout: 15000, + timeoutLimit: 60000 + }; + var ws_manager = new transport_manager({ + lives: 2, + minPingDelay: 10000, + maxPingDelay: config.activity_timeout + }); + var streaming_manager = new transport_manager({ + lives: 2, + minPingDelay: 10000, + maxPingDelay: config.activity_timeout + }); + var ws_transport = defineTransportStrategy("ws", "ws", 3, ws_options, ws_manager); + var wss_transport = defineTransportStrategy("wss", "ws", 3, wss_options, ws_manager); + var xhr_streaming_transport = defineTransportStrategy("xhr_streaming", "xhr_streaming", 1, http_options, streaming_manager); + var xhr_polling_transport = defineTransportStrategy("xhr_polling", "xhr_polling", 1, http_options); + var ws_loop = new sequential_strategy([ws_transport], timeouts); + var wss_loop = new sequential_strategy([wss_transport], timeouts); + var streaming_loop = new sequential_strategy([xhr_streaming_transport], timeouts); + var polling_loop = new sequential_strategy([xhr_polling_transport], timeouts); + var http_loop = new sequential_strategy([new if_strategy(testSupportsStrategy(streaming_loop), new best_connected_ever_strategy([streaming_loop, new delayed_strategy(polling_loop, { delay: 4000 })]), polling_loop)], timeouts); + var wsStrategy; + if (config.useTLS) { + wsStrategy = new best_connected_ever_strategy([ws_loop, new delayed_strategy(http_loop, { delay: 2000 })]); } - - // Set Basic Auth if necessary - if (settings.user) { - if (typeof settings.password === "undefined") { - settings.password = ""; - } - var authBuf = new Buffer(settings.user + ":" + settings.password); - headers.Authorization = "Basic " + authBuf.toString("base64"); + else { + wsStrategy = new best_connected_ever_strategy([ + ws_loop, + new delayed_strategy(wss_loop, { delay: 2000 }), + new delayed_strategy(http_loop, { delay: 5000 }) + ]); } + return new cached_strategy(new first_connected_strategy(new if_strategy(testSupportsStrategy(ws_transport), wsStrategy, http_loop)), definedTransports, { + ttl: 1800000, + timeline: config.timeline, + useTLS: config.useTLS + }); +}; +/* harmony default export */ var default_strategy = (getDefaultStrategy); - // Set content length header - if (settings.method === "GET" || settings.method === "HEAD") { - data = null; - } else if (data) { - headers["Content-Length"] = Buffer.isBuffer(data) ? data.length : Buffer.byteLength(data); - - if (!headers["Content-Type"]) { - headers["Content-Type"] = "text/plain;charset=UTF-8"; - } - } else if (settings.method === "POST") { - // For a post with no data set Content-Length: 0. - // This is required by buggy servers that don't meet the specs. - headers["Content-Length"] = 0; +// CONCATENATED MODULE: ./src/runtimes/isomorphic/transports/transport_connection_initializer.ts +/* harmony default export */ var transport_connection_initializer = (function () { + var self = this; + self.timeline.info(self.buildTimelineMessage({ + transport: self.name + (self.options.useTLS ? "s" : "") + })); + if (self.hooks.isInitialized()) { + self.changeState("initialized"); + } + else { + self.onClose(); } +}); - var options = { - host: host, - port: port, - path: uri, - method: settings.method, - headers: headers, - agent: false, - withCredentials: self.withCredentials +// CONCATENATED MODULE: ./src/core/http/http_request.ts +var http_request_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); - // Reset error flag - errorFlag = false; - - // Handle async requests - if (settings.async) { - // Use the proper protocol - var doRequest = ssl ? https.request : http.request; - - // Request is being sent, set send flag - sendFlag = true; - - // As per spec, this is called here for historical reasons. - self.dispatchEvent("readystatechange"); - - // Handler for the response - var responseHandler = function responseHandler(resp) { - // Set response var to the response we got back - // This is so it remains accessable outside this scope - response = resp; - // Check for redirect - // @TODO Prevent looped redirects - if (response.statusCode === 301 || response.statusCode === 302 || response.statusCode === 303 || response.statusCode === 307) { - // Change URL to the redirect location - settings.url = response.headers.location; - var url = Url.parse(settings.url); - // Set host var in case it's used later - host = url.hostname; - // Options for the new request - var newOptions = { - hostname: url.hostname, - port: url.port, - path: url.path, - method: response.statusCode === 303 ? "GET" : settings.method, - headers: headers, - withCredentials: self.withCredentials - }; - // Issue the new request - request = doRequest(newOptions, responseHandler).on("error", errorHandler); - request.end(); - // @TODO Check if an XHR event needs to be fired here - return; +var MAX_BUFFER_LENGTH = 256 * 1024; +var http_request_HTTPRequest = (function (_super) { + http_request_extends(HTTPRequest, _super); + function HTTPRequest(hooks, method, url) { + var _this = _super.call(this) || this; + _this.hooks = hooks; + _this.method = method; + _this.url = url; + return _this; + } + HTTPRequest.prototype.start = function (payload) { + var _this = this; + this.position = 0; + this.xhr = this.hooks.getRequest(this); + this.unloader = function () { + _this.close(); + }; + node_runtime.addUnloadListener(this.unloader); + this.xhr.open(this.method, this.url, true); + if (this.xhr.setRequestHeader) { + this.xhr.setRequestHeader("Content-Type", "application/json"); + } + this.xhr.send(payload); + }; + HTTPRequest.prototype.close = function () { + if (this.unloader) { + node_runtime.removeUnloadListener(this.unloader); + this.unloader = null; + } + if (this.xhr) { + this.hooks.abortRequest(this.xhr); + this.xhr = null; + } + }; + HTTPRequest.prototype.onChunk = function (status, data) { + while (true) { + var chunk = this.advanceBuffer(data); + if (chunk) { + this.emit("chunk", { status: status, data: chunk }); + } + else { + break; + } + } + if (this.isBufferTooLong(data)) { + this.emit("buffer_too_long"); + } + }; + HTTPRequest.prototype.advanceBuffer = function (buffer) { + var unreadData = buffer.slice(this.position); + var endOfLinePosition = unreadData.indexOf("\n"); + if (endOfLinePosition !== -1) { + this.position += endOfLinePosition + 1; + return unreadData.slice(0, endOfLinePosition); + } + else { + return null; } + }; + HTTPRequest.prototype.isBufferTooLong = function (buffer) { + return this.position === buffer.length && buffer.length > MAX_BUFFER_LENGTH; + }; + return HTTPRequest; +}(dispatcher)); +/* harmony default export */ var http_request = (http_request_HTTPRequest); - response.setEncoding("utf8"); +// CONCATENATED MODULE: ./src/core/http/state.ts +var State; +(function (State) { + State[State["CONNECTING"] = 0] = "CONNECTING"; + State[State["OPEN"] = 1] = "OPEN"; + State[State["CLOSED"] = 3] = "CLOSED"; +})(State || (State = {})); +/* harmony default export */ var state = (State); - setState(self.HEADERS_RECEIVED); - self.status = response.statusCode; +// CONCATENATED MODULE: ./src/core/http/http_socket.ts - response.on("data", function(chunk) { - // Make sure there's some data - if (chunk) { - self.responseText += chunk; - } - // Don't emit state changes if the connection has been aborted. - if (sendFlag) { - setState(self.LOADING); - } - }); - response.on("end", function() { - if (sendFlag) { - // Discard the end event if the connection has been aborted - setState(self.DONE); - sendFlag = false; - } - }); - response.on("error", function(error) { - self.handleError(error); +var autoIncrement = 1; +var http_socket_HTTPSocket = (function () { + function HTTPSocket(hooks, url) { + this.hooks = hooks; + this.session = randomNumber(1000) + "/" + randomString(8); + this.location = getLocation(url); + this.readyState = state.CONNECTING; + this.openStream(); + } + HTTPSocket.prototype.send = function (payload) { + return this.sendRaw(JSON.stringify([payload])); + }; + HTTPSocket.prototype.ping = function () { + this.hooks.sendHeartbeat(this); + }; + HTTPSocket.prototype.close = function (code, reason) { + this.onClose(code, reason, true); + }; + HTTPSocket.prototype.sendRaw = function (payload) { + if (this.readyState === state.OPEN) { + try { + node_runtime.createSocketRequest("POST", getUniqueURL(getSendURL(this.location, this.session))).start(payload); + return true; + } + catch (e) { + return false; + } + } + else { + return false; + } + }; + HTTPSocket.prototype.reconnect = function () { + this.closeStream(); + this.openStream(); + }; + ; + HTTPSocket.prototype.onClose = function (code, reason, wasClean) { + this.closeStream(); + this.readyState = state.CLOSED; + if (this.onclose) { + this.onclose({ + code: code, + reason: reason, + wasClean: wasClean + }); + } + }; + HTTPSocket.prototype.onChunk = function (chunk) { + if (chunk.status !== 200) { + return; + } + if (this.readyState === state.OPEN) { + this.onActivity(); + } + var payload; + var type = chunk.data.slice(0, 1); + switch (type) { + case 'o': + payload = JSON.parse(chunk.data.slice(1) || '{}'); + this.onOpen(payload); + break; + case 'a': + payload = JSON.parse(chunk.data.slice(1) || '[]'); + for (var i = 0; i < payload.length; i++) { + this.onEvent(payload[i]); + } + break; + case 'm': + payload = JSON.parse(chunk.data.slice(1) || 'null'); + this.onEvent(payload); + break; + case 'h': + this.hooks.onHeartbeat(this); + break; + case 'c': + payload = JSON.parse(chunk.data.slice(1) || '[]'); + this.onClose(payload[0], payload[1], true); + break; + } + }; + HTTPSocket.prototype.onOpen = function (options) { + if (this.readyState === state.CONNECTING) { + if (options && options.hostname) { + this.location.base = replaceHost(this.location.base, options.hostname); + } + this.readyState = state.OPEN; + if (this.onopen) { + this.onopen(); + } + } + else { + this.onClose(1006, "Server lost session", true); + } + }; + HTTPSocket.prototype.onEvent = function (event) { + if (this.readyState === state.OPEN && this.onmessage) { + this.onmessage({ data: event }); + } + }; + HTTPSocket.prototype.onActivity = function () { + if (this.onactivity) { + this.onactivity(); + } + }; + HTTPSocket.prototype.onError = function (error) { + if (this.onerror) { + this.onerror(error); + } + }; + HTTPSocket.prototype.openStream = function () { + var _this = this; + this.stream = node_runtime.createSocketRequest("POST", getUniqueURL(this.hooks.getReceiveURL(this.location, this.session))); + this.stream.bind("chunk", function (chunk) { + _this.onChunk(chunk); }); - }; - - // Error handler for the request - var errorHandler = function errorHandler(error) { - self.handleError(error); - }; - - // Create the request - request = doRequest(options, responseHandler).on("error", errorHandler); - - // Node 0.4 and later won't accept empty data. Make sure it's needed. - if (data) { - request.write(data); - } - - request.end(); - - self.dispatchEvent("loadstart"); - } else { // Synchronous - // Create a temporary file for communication with the other Node process - var contentFile = ".node-xmlhttprequest-content-" + process.pid; - var syncFile = ".node-xmlhttprequest-sync-" + process.pid; - fs.writeFileSync(syncFile, "", "utf8"); - // The async request the other Node process executes - var execString = "var http = require('http'), https = require('https'), fs = require('fs');" - + "var doRequest = http" + (ssl ? "s" : "") + ".request;" - + "var options = " + JSON.stringify(options) + ";" - + "var responseText = '';" - + "var req = doRequest(options, function(response) {" - + "response.setEncoding('utf8');" - + "response.on('data', function(chunk) {" - + " responseText += chunk;" - + "});" - + "response.on('end', function() {" - + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: null, data: {statusCode: response.statusCode, headers: response.headers, text: responseText}}), 'utf8');" - + "fs.unlinkSync('" + syncFile + "');" - + "});" - + "response.on('error', function(error) {" - + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: error}), 'utf8');" - + "fs.unlinkSync('" + syncFile + "');" - + "});" - + "}).on('error', function(error) {" - + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: error}), 'utf8');" - + "fs.unlinkSync('" + syncFile + "');" - + "});" - + (data ? "req.write('" + JSON.stringify(data).slice(1,-1).replace(/'/g, "\\'") + "');":"") - + "req.end();"; - // Start the other Node Process, executing this string - var syncProc = spawn(process.argv[0], ["-e", execString]); - while(fs.existsSync(syncFile)) { - // Wait while the sync file is empty - } - var resp = JSON.parse(fs.readFileSync(contentFile, 'utf8')); - // Kill the child process once the file has data - syncProc.stdin.end(); - // Remove the temporary file - fs.unlinkSync(contentFile); - - if (resp.err) { - self.handleError(resp.err); - } else { - response = resp.data; - self.status = resp.data.statusCode; - self.responseText = resp.data.text; - setState(self.DONE); - } + this.stream.bind("finished", function (status) { + _this.hooks.onFinished(_this, status); + }); + this.stream.bind("buffer_too_long", function () { + _this.reconnect(); + }); + try { + this.stream.start(); + } + catch (error) { + util.defer(function () { + _this.onError(error); + _this.onClose(1006, "Could not start streaming", false); + }); + } + }; + HTTPSocket.prototype.closeStream = function () { + if (this.stream) { + this.stream.unbind_all(); + this.stream.close(); + this.stream = null; + } + }; + return HTTPSocket; +}()); +function getLocation(url) { + var parts = /([^\?]*)\/*(\??.*)/.exec(url); + return { + base: parts[1], + queryString: parts[2] + }; +} +function getSendURL(url, session) { + return url.base + "/" + session + "/xhr_send"; +} +function getUniqueURL(url) { + var separator = (url.indexOf('?') === -1) ? "?" : "&"; + return url + separator + "t=" + (+new Date()) + "&n=" + autoIncrement++; +} +function replaceHost(url, hostname) { + var urlParts = /(https?:\/\/)([^\/:]+)((\/|:)?.*)/.exec(url); + return urlParts[1] + hostname + urlParts[3]; +} +function randomNumber(max) { + return Math.floor(Math.random() * max); +} +function randomString(length) { + var result = []; + for (var i = 0; i < length; i++) { + result.push(randomNumber(32).toString(32)); } - }; - - /** - * Called when an error is encountered to deal with it. - */ - this.handleError = function(error) { - this.status = 0; - this.statusText = error; - this.responseText = error.stack; - errorFlag = true; - setState(this.DONE); - this.dispatchEvent('error'); - }; + return result.join(''); +} +/* harmony default export */ var http_socket = (http_socket_HTTPSocket); - /** - * Aborts a request. - */ - this.abort = function() { - if (request) { - request.abort(); - request = null; +// CONCATENATED MODULE: ./src/core/http/http_streaming_socket.ts +var http_streaming_socket_hooks = { + getReceiveURL: function (url, session) { + return url.base + "/" + session + "/xhr_streaming" + url.queryString; + }, + onHeartbeat: function (socket) { + socket.sendRaw("[]"); + }, + sendHeartbeat: function (socket) { + socket.sendRaw("[]"); + }, + onFinished: function (socket, status) { + socket.onClose(1006, "Connection interrupted (" + status + ")", false); } +}; +/* harmony default export */ var http_streaming_socket = (http_streaming_socket_hooks); - headers = defaultHeaders; - this.status = 0; - this.responseText = ""; - this.responseXML = ""; +// CONCATENATED MODULE: ./src/core/http/http_polling_socket.ts +var http_polling_socket_hooks = { + getReceiveURL: function (url, session) { + return url.base + "/" + session + "/xhr" + url.queryString; + }, + onHeartbeat: function () { + }, + sendHeartbeat: function (socket) { + socket.sendRaw("[]"); + }, + onFinished: function (socket, status) { + if (status === 200) { + socket.reconnect(); + } + else { + socket.onClose(1006, "Connection interrupted (" + status + ")", false); + } + } +}; +/* harmony default export */ var http_polling_socket = (http_polling_socket_hooks); - errorFlag = true; +// CONCATENATED MODULE: ./src/runtimes/isomorphic/http/http_xhr_request.ts - if (this.readyState !== this.UNSENT - && (this.readyState !== this.OPENED || sendFlag) - && this.readyState !== this.DONE) { - sendFlag = false; - setState(this.DONE); +var http_xhr_request_hooks = { + getRequest: function (socket) { + var Constructor = node_runtime.getXHRAPI(); + var xhr = new Constructor(); + xhr.onreadystatechange = xhr.onprogress = function () { + switch (xhr.readyState) { + case 3: + if (xhr.responseText && xhr.responseText.length > 0) { + socket.onChunk(xhr.status, xhr.responseText); + } + break; + case 4: + if (xhr.responseText && xhr.responseText.length > 0) { + socket.onChunk(xhr.status, xhr.responseText); + } + socket.emit("finished", xhr.status); + socket.close(); + break; + } + }; + return xhr; + }, + abortRequest: function (xhr) { + xhr.onreadystatechange = null; + xhr.abort(); } - this.readyState = this.UNSENT; - this.dispatchEvent('abort'); - }; +}; +/* harmony default export */ var http_xhr_request = (http_xhr_request_hooks); - /** - * Adds an event listener. Preferred method of binding to events. - */ - this.addEventListener = function(event, callback) { - if (!(event in listeners)) { - listeners[event] = []; - } - // Currently allows duplicate callbacks. Should it? - listeners[event].push(callback); - }; +// CONCATENATED MODULE: ./src/runtimes/isomorphic/http/http.ts - /** - * Remove an event callback that has already been bound. - * Only works on the matching funciton, cannot be a copy. - */ - this.removeEventListener = function(event, callback) { - if (event in listeners) { - // Filter will return a new array with the callback removed - listeners[event] = listeners[event].filter(function(ev) { - return ev !== callback; - }); - } - }; - /** - * Dispatch any events, including both "on" methods and events attached using addEventListener. - */ - this.dispatchEvent = function(event) { - if (typeof self["on" + event] === "function") { - self["on" + event](); - } - if (event in listeners) { - for (var i = 0, len = listeners[event].length; i < len; i++) { - listeners[event][i].call(self); - } - } - }; - /** - * Changes readyState and calls onreadystatechange. - * - * @param int state New state - */ - var setState = function(state) { - if (state == self.LOADING || self.readyState !== state) { - self.readyState = state; - if (settings.async || self.readyState < self.OPENED || self.readyState === self.DONE) { - self.dispatchEvent("readystatechange"); - } - if (self.readyState === self.DONE && !errorFlag) { - self.dispatchEvent("load"); - // @TODO figure out InspectorInstrumentation::didLoadXHR(cookie) - self.dispatchEvent("loadend"); - } +var HTTP = { + createStreamingSocket: function (url) { + return this.createSocket(http_streaming_socket, url); + }, + createPollingSocket: function (url) { + return this.createSocket(http_polling_socket, url); + }, + createSocket: function (hooks, url) { + return new http_socket(hooks, url); + }, + createXHR: function (method, url) { + return this.createRequest(http_xhr_request, method, url); + }, + createRequest: function (hooks, method, url) { + return new http_request(hooks, method, url); } - }; }; +/* harmony default export */ var http_http = (HTTP); +// CONCATENATED MODULE: ./src/runtimes/isomorphic/runtime.ts -/***/ }), -/* 91 */ -/***/ (function(module, exports) { - -module.exports = require("child_process"); - -/***/ }), -/* 92 */ -/***/ (function(module, exports) { - -module.exports = require("fs"); -/***/ }), -/* 93 */ -/***/ (function(module, exports) { -module.exports = require("http"); -/***/ }), -/* 94 */ -/***/ (function(module, exports) { -module.exports = require("https"); +var Isomorphic = { + getDefaultStrategy: default_strategy, + Transports: transports, + transportConnectionInitializer: transport_connection_initializer, + HTTPFactory: http_http, + setup: function (PusherClass) { + PusherClass.ready(); + }, + getLocalStorage: function () { + return undefined; + }, + getClientFeatures: function () { + return keys(filterObject({ "ws": transports.ws }, function (t) { return t.isSupported({}); })); + }, + getProtocol: function () { + return "http:"; + }, + isXHRSupported: function () { + return true; + }, + createSocketRequest: function (method, url) { + if (this.isXHRSupported()) { + return this.HTTPFactory.createXHR(method, url); + } + else { + throw "Cross-origin HTTP requests are not supported"; + } + }, + createXHR: function () { + var Constructor = this.getXHRAPI(); + return new Constructor(); + }, + createWebSocket: function (url) { + var Constructor = this.getWebSocketAPI(); + return new Constructor(url); + }, + addUnloadListener: function (listener) { }, + removeUnloadListener: function (listener) { } +}; +/* harmony default export */ var runtime = (Isomorphic); -/***/ }), -/* 95 */ -/***/ (function(module, exports, __webpack_require__) { +// EXTERNAL MODULE: ./node_modules/faye-websocket/lib/faye/websocket.js +var websocket = __webpack_require__(18); -"use strict"; +// EXTERNAL MODULE: ./node_modules/xmlhttprequest/lib/XMLHttpRequest.js +var XMLHttpRequest = __webpack_require__(19); -var __extends = (this && this.__extends) || (function () { +// CONCATENATED MODULE: ./src/runtimes/node/net_info.ts +var net_info_extends = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || @@ -10267,10 +9668,9 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -exports.__esModule = true; -var dispatcher_1 = __webpack_require__(6); + var NetInfo = (function (_super) { - __extends(NetInfo, _super); + net_info_extends(NetInfo, _super); function NetInfo() { return _super !== null && _super.apply(this, arguments) || this; } @@ -10278,24 +9678,17 @@ var NetInfo = (function (_super) { return true; }; return NetInfo; -}(dispatcher_1["default"])); -exports.NetInfo = NetInfo; -exports.Network = new NetInfo(); +}(dispatcher)); +var net_info_Network = new NetInfo(); + +// CONCATENATED MODULE: ./src/runtimes/isomorphic/auth/xhr_auth.ts -/***/ }), -/* 96 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var logger_1 = __webpack_require__(4); -var runtime_1 = __webpack_require__(1); -var url_store_1 = __webpack_require__(12); var ajax = function (context, socketId, callback) { var self = this, xhr; - xhr = runtime_1["default"].createXHR(); + xhr = node_runtime.createXHR(); xhr.open("POST", self.options.authEndpoint, true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); for (var headerName in this.authOptions.headers) { @@ -10317,8 +9710,9 @@ var ajax = function (context, socketId, callback) { } } else { - var suffix = url_store_1["default"].buildLogSuffix("authenticationEndpoint"); - logger_1["default"].warn("Couldn't retrieve authentication info. " + xhr.status + + var suffix = url_store.buildLogSuffix("authenticationEndpoint"); + logger.warn('Unable to retrieve auth string from auth endpoint - ' + + ("received status " + xhr.status + " from " + self.options.authEndpoint + ". ") + ("Clients must be authenticated to join private or presence channels. " + suffix)); callback(true, xhr.status); } @@ -10327,39 +9721,32 @@ var ajax = function (context, socketId, callback) { xhr.send(this.composeQuery(socketId)); return xhr; }; -exports["default"] = ajax; +/* harmony default export */ var xhr_auth = (ajax); +// CONCATENATED MODULE: ./src/runtimes/isomorphic/timeline/xhr_timeline.ts -/***/ }), -/* 97 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var logger_1 = __webpack_require__(4); -var Collections = __webpack_require__(0); -var runtime_1 = __webpack_require__(1); var getAgent = function (sender, useTLS) { return function (data, callback) { var scheme = "http" + (useTLS ? "s" : "") + "://"; var url = scheme + (sender.host || sender.options.host) + sender.options.path; - var query = Collections.buildQueryString(data); + var query = buildQueryString(data); url += ("/" + 2 + "?" + query); - var xhr = runtime_1["default"].createXHR(); + var xhr = node_runtime.createXHR(); xhr.open("GET", url, true); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { var status_1 = xhr.status, responseText = xhr.responseText; if (status_1 !== 200) { - logger_1["default"].debug("TimelineSender Error: received " + status_1 + " from stats.pusher.com"); + logger.debug("TimelineSender Error: received " + status_1 + " from stats.pusher.com"); return; } try { var host = JSON.parse(responseText).host; } catch (e) { - logger_1["default"].debug("TimelineSenderError: invalid response " + responseText); + logger.debug("TimelineSenderError: invalid response " + responseText); } if (host) { sender.host = host; @@ -10369,24 +9756,64 @@ var getAgent = function (sender, useTLS) { xhr.send(); }; }; -var xhr = { +var xhr_timeline_xhr = { name: 'xhr', getAgent: getAgent }; -exports["default"] = xhr; +/* harmony default export */ var xhr_timeline = (xhr_timeline_xhr); + +// CONCATENATED MODULE: ./src/runtimes/node/runtime.ts + + + + + + +var runtime_getDefaultStrategy = runtime.getDefaultStrategy, runtime_Transports = runtime.Transports, setup = runtime.setup, getProtocol = runtime.getProtocol, isXHRSupported = runtime.isXHRSupported, getLocalStorage = runtime.getLocalStorage, createXHR = runtime.createXHR, createWebSocket = runtime.createWebSocket, addUnloadListener = runtime.addUnloadListener, removeUnloadListener = runtime.removeUnloadListener, transportConnectionInitializer = runtime.transportConnectionInitializer, createSocketRequest = runtime.createSocketRequest, HTTPFactory = runtime.HTTPFactory; +var NodeJS = { + getDefaultStrategy: runtime_getDefaultStrategy, + Transports: runtime_Transports, + setup: setup, + getProtocol: getProtocol, + isXHRSupported: isXHRSupported, + createSocketRequest: createSocketRequest, + getLocalStorage: getLocalStorage, + createXHR: createXHR, + createWebSocket: createWebSocket, + addUnloadListener: addUnloadListener, + removeUnloadListener: removeUnloadListener, + transportConnectionInitializer: transportConnectionInitializer, + HTTPFactory: HTTPFactory, + TimelineTransport: xhr_timeline, + getAuthorizers: function () { + return { ajax: xhr_auth }; + }, + getWebSocketAPI: function () { + return websocket["Client"]; + }, + getXHRAPI: function () { + return XMLHttpRequest["XMLHttpRequest"]; + }, + getNetwork: function () { + return net_info_Network; + } +}; +/* harmony default export */ var node_runtime = (NodeJS); + +// CONCATENATED MODULE: ./src/core/timeline/level.ts +var TimelineLevel; +(function (TimelineLevel) { + TimelineLevel[TimelineLevel["ERROR"] = 3] = "ERROR"; + TimelineLevel[TimelineLevel["INFO"] = 6] = "INFO"; + TimelineLevel[TimelineLevel["DEBUG"] = 7] = "DEBUG"; +})(TimelineLevel || (TimelineLevel = {})); +/* harmony default export */ var timeline_level = (TimelineLevel); +// CONCATENATED MODULE: ./src/core/timeline/timeline.ts -/***/ }), -/* 98 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var Collections = __webpack_require__(0); -var util_1 = __webpack_require__(3); -var level_1 = __webpack_require__(31); -var Timeline = (function () { +var timeline_Timeline = (function () { function Timeline(key, session, options) { this.key = key; this.session = session; @@ -10397,27 +9824,27 @@ var Timeline = (function () { } Timeline.prototype.log = function (level, event) { if (level <= this.options.level) { - this.events.push(Collections.extend({}, event, { timestamp: util_1["default"].now() })); + this.events.push(extend({}, event, { timestamp: util.now() })); if (this.options.limit && this.events.length > this.options.limit) { this.events.shift(); } } }; Timeline.prototype.error = function (event) { - this.log(level_1["default"].ERROR, event); + this.log(timeline_level.ERROR, event); }; Timeline.prototype.info = function (event) { - this.log(level_1["default"].INFO, event); + this.log(timeline_level.INFO, event); }; Timeline.prototype.debug = function (event) { - this.log(level_1["default"].DEBUG, event); + this.log(timeline_level.DEBUG, event); }; Timeline.prototype.isEmpty = function () { return this.events.length === 0; }; Timeline.prototype.send = function (sendfn, callback) { var _this = this; - var data = Collections.extend({ + var data = extend({ session: this.session, bundle: this.sent + 1, key: this.key, @@ -10444,75 +9871,14 @@ var Timeline = (function () { }; return Timeline; }()); -exports["default"] = Timeline; - - -/***/ }), -/* 99 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +/* harmony default export */ var timeline_timeline = (timeline_Timeline); -exports.__esModule = true; -var Collections = __webpack_require__(0); -var util_1 = __webpack_require__(3); -var Errors = __webpack_require__(10); -var transport_strategy_1 = __webpack_require__(100); -var runtime_1 = __webpack_require__(1); -var Transports = runtime_1["default"].Transports; -exports.defineTransport = function (config, name, type, priority, options, manager) { - var transportClass = Transports[type]; - if (!transportClass) { - throw new Errors.UnsupportedTransport(type); - } - var enabled = (!config.enabledTransports || - Collections.arrayIndexOf(config.enabledTransports, name) !== -1) && - (!config.disabledTransports || - Collections.arrayIndexOf(config.disabledTransports, name) === -1); - var transport; - if (enabled) { - transport = new transport_strategy_1["default"](name, priority, manager ? manager.getAssistant(transportClass) : transportClass, Collections.extend({ - key: config.key, - useTLS: config.useTLS, - timeline: config.timeline, - ignoreNullOrigin: config.ignoreNullOrigin - }, options)); - } - else { - transport = UnsupportedStrategy; - } - return transport; -}; -var UnsupportedStrategy = { - isSupported: function () { - return false; - }, - connect: function (_, callback) { - var deferred = util_1["default"].defer(function () { - callback(new Errors.UnsupportedStrategy()); - }); - return { - abort: function () { - deferred.ensureAborted(); - }, - forceMinPriority: function () { } - }; - } -}; +// CONCATENATED MODULE: ./src/core/strategies/transport_strategy.ts -/***/ }), -/* 100 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var factory_1 = __webpack_require__(9); -var util_1 = __webpack_require__(3); -var Errors = __webpack_require__(10); -var Collections = __webpack_require__(0); -var TransportStrategy = (function () { +var transport_strategy_TransportStrategy = (function () { function TransportStrategy(name, priority, transport, options) { this.name = name; this.priority = priority; @@ -10527,10 +9893,10 @@ var TransportStrategy = (function () { TransportStrategy.prototype.connect = function (minPriority, callback) { var _this = this; if (!this.isSupported()) { - return failAttempt(new Errors.UnsupportedStrategy(), callback); + return failAttempt(new UnsupportedStrategy(), callback); } else if (this.priority < minPriority) { - return failAttempt(new Errors.TransportPriorityTooLow(), callback); + return failAttempt(new TransportPriorityTooLow(), callback); } var connected = false; var transport = this.transport.createConnection(this.name, this.priority, this.options.key, this.options); @@ -10540,7 +9906,7 @@ var TransportStrategy = (function () { transport.connect(); }; var onOpen = function () { - handshake = factory_1["default"].createHandshake(transport, function (result) { + handshake = factory.createHandshake(transport, function (result) { connected = true; unbindListeners(); callback(null, result); @@ -10553,8 +9919,8 @@ var TransportStrategy = (function () { var onClosed = function () { unbindListeners(); var serializedTransport; - serializedTransport = Collections.safeJSONStringify(transport); - callback(new Errors.TransportClosed(serializedTransport)); + serializedTransport = safeJSONStringify(transport); + callback(new TransportClosed(serializedTransport)); }; var unbindListeners = function () { transport.unbind("initialized", onInitialized); @@ -10597,9 +9963,9 @@ var TransportStrategy = (function () { }; return TransportStrategy; }()); -exports["default"] = TransportStrategy; +/* harmony default export */ var transport_strategy = (transport_strategy_TransportStrategy); function failAttempt(error, callback) { - util_1["default"].defer(function () { + util.defer(function () { callback(error); }); return { @@ -10608,40 +9974,289 @@ function failAttempt(error, callback) { }; } +// CONCATENATED MODULE: ./src/core/strategies/strategy_builder.ts -/***/ }), -/* 101 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var defaults_1 = __webpack_require__(17); -exports.getGlobalConfig = function () { + + +var strategy_builder_Transports = node_runtime.Transports; +var strategy_builder_defineTransport = function (config, name, type, priority, options, manager) { + var transportClass = strategy_builder_Transports[type]; + if (!transportClass) { + throw new UnsupportedTransport(type); + } + var enabled = (!config.enabledTransports || + arrayIndexOf(config.enabledTransports, name) !== -1) && + (!config.disabledTransports || + arrayIndexOf(config.disabledTransports, name) === -1); + var transport; + if (enabled) { + transport = new transport_strategy(name, priority, manager ? manager.getAssistant(transportClass) : transportClass, extend({ + key: config.key, + useTLS: config.useTLS, + timeline: config.timeline, + ignoreNullOrigin: config.ignoreNullOrigin + }, options)); + } + else { + transport = strategy_builder_UnsupportedStrategy; + } + return transport; +}; +var strategy_builder_UnsupportedStrategy = { + isSupported: function () { + return false; + }, + connect: function (_, callback) { + var deferred = util.defer(function () { + callback(new UnsupportedStrategy()); + }); + return { + abort: function () { + deferred.ensureAborted(); + }, + forceMinPriority: function () { } + }; + } +}; + +// CONCATENATED MODULE: ./src/core/config.ts + +var getGlobalConfig = function () { return { - wsHost: defaults_1["default"].host, - wsPort: defaults_1["default"].ws_port, - wssPort: defaults_1["default"].wss_port, - wsPath: defaults_1["default"].ws_path, - httpHost: defaults_1["default"].sockjs_host, - httpPort: defaults_1["default"].sockjs_http_port, - httpsPort: defaults_1["default"].sockjs_https_port, - httpPath: defaults_1["default"].sockjs_path, - statsHost: defaults_1["default"].stats_host, - authEndpoint: defaults_1["default"].channel_auth_endpoint, - authTransport: defaults_1["default"].channel_auth_transport, - activity_timeout: defaults_1["default"].activity_timeout, - pong_timeout: defaults_1["default"].pong_timeout, - unavailable_timeout: defaults_1["default"].unavailable_timeout - }; -}; -exports.getClusterConfig = function (clusterName) { + wsHost: defaults.host, + wsPort: defaults.ws_port, + wssPort: defaults.wss_port, + wsPath: defaults.ws_path, + httpHost: defaults.sockjs_host, + httpPort: defaults.sockjs_http_port, + httpsPort: defaults.sockjs_https_port, + httpPath: defaults.sockjs_path, + statsHost: defaults.stats_host, + authEndpoint: defaults.channel_auth_endpoint, + authTransport: defaults.channel_auth_transport, + activity_timeout: defaults.activity_timeout, + pong_timeout: defaults.pong_timeout, + unavailable_timeout: defaults.unavailable_timeout + }; +}; +var getClusterConfig = function (clusterName) { return { - wsHost: "ws-" + clusterName + ".pusher.com", - httpHost: "sockjs-" + clusterName + ".pusher.com" + wsHost: 'ws-' + clusterName + '.pusher.com', + httpHost: 'sockjs-' + clusterName + '.pusher.com' }; }; +// CONCATENATED MODULE: ./src/core/pusher.ts + + + + + + + + + + + + +var pusher_Pusher = (function () { + function Pusher(app_key, options) { + var _this = this; + checkAppKey(app_key); + options = options || {}; + if (!options.cluster && !(options.wsHost || options.httpHost)) { + var suffix = url_store.buildLogSuffix('javascriptQuickStart'); + logger.warn("You should always specify a cluster when connecting. " + suffix); + } + this.key = app_key; + this.config = extend(getGlobalConfig(), options.cluster ? getClusterConfig(options.cluster) : {}, options); + this.channels = factory.createChannels(); + this.global_emitter = new dispatcher(); + this.sessionID = Math.floor(Math.random() * 1000000000); + this.timeline = new timeline_timeline(this.key, this.sessionID, { + cluster: this.config.cluster, + features: Pusher.getClientFeatures(), + params: this.config.timelineParams || {}, + limit: 50, + level: timeline_level.INFO, + version: defaults.VERSION + }); + if (!this.config.disableStats) { + this.timelineSender = factory.createTimelineSender(this.timeline, { + host: this.config.statsHost, + path: '/timeline/v2/' + node_runtime.TimelineTransport.name + }); + } + var getStrategy = function (options) { + var config = extend({}, _this.config, options); + return node_runtime.getDefaultStrategy(config, strategy_builder_defineTransport); + }; + this.connection = factory.createConnectionManager(this.key, extend({ + getStrategy: getStrategy, + timeline: this.timeline, + activityTimeout: this.config.activity_timeout, + pongTimeout: this.config.pong_timeout, + unavailableTimeout: this.config.unavailable_timeout + }, this.config, { useTLS: this.shouldUseTLS() })); + this.connection.bind('connected', function () { + _this.subscribeAll(); + if (_this.timelineSender) { + _this.timelineSender.send(_this.connection.isUsingTLS()); + } + }); + this.connection.bind('message', function (event) { + var eventName = event.event; + var internal = eventName.indexOf('pusher_internal:') === 0; + if (event.channel) { + var channel = _this.channel(event.channel); + if (channel) { + channel.handleEvent(event); + } + } + if (!internal) { + _this.global_emitter.emit(event.event, event.data); + } + }); + this.connection.bind('connecting', function () { + _this.channels.disconnect(); + }); + this.connection.bind('disconnected', function () { + _this.channels.disconnect(); + }); + this.connection.bind('error', function (err) { + logger.warn('Error', err); + }); + Pusher.instances.push(this); + this.timeline.info({ instances: Pusher.instances.length }); + if (Pusher.isReady) { + this.connect(); + } + } + Pusher.ready = function () { + Pusher.isReady = true; + for (var i = 0, l = Pusher.instances.length; i < l; i++) { + Pusher.instances[i].connect(); + } + }; + Pusher.log = function (message) { + if (Pusher.logToConsole && global.console && global.console.log) { + global.console.log(message); + } + }; + Pusher.getClientFeatures = function () { + return keys(filterObject({ ws: node_runtime.Transports.ws }, function (t) { + return t.isSupported({}); + })); + }; + Pusher.prototype.channel = function (name) { + return this.channels.find(name); + }; + Pusher.prototype.allChannels = function () { + return this.channels.all(); + }; + Pusher.prototype.connect = function () { + this.connection.connect(); + if (this.timelineSender) { + if (!this.timelineSenderTimer) { + var usingTLS = this.connection.isUsingTLS(); + var timelineSender = this.timelineSender; + this.timelineSenderTimer = new PeriodicTimer(60000, function () { + timelineSender.send(usingTLS); + }); + } + } + }; + Pusher.prototype.disconnect = function () { + this.connection.disconnect(); + if (this.timelineSenderTimer) { + this.timelineSenderTimer.ensureAborted(); + this.timelineSenderTimer = null; + } + }; + Pusher.prototype.bind = function (event_name, callback, context) { + this.global_emitter.bind(event_name, callback, context); + return this; + }; + Pusher.prototype.unbind = function (event_name, callback, context) { + this.global_emitter.unbind(event_name, callback, context); + return this; + }; + Pusher.prototype.bind_global = function (callback) { + this.global_emitter.bind_global(callback); + return this; + }; + Pusher.prototype.unbind_global = function (callback) { + this.global_emitter.unbind_global(callback); + return this; + }; + Pusher.prototype.unbind_all = function (callback) { + this.global_emitter.unbind_all(); + return this; + }; + Pusher.prototype.subscribeAll = function () { + var channelName; + for (channelName in this.channels.channels) { + if (this.channels.channels.hasOwnProperty(channelName)) { + this.subscribe(channelName); + } + } + }; + Pusher.prototype.subscribe = function (channel_name) { + var channel = this.channels.add(channel_name, this); + if (channel.subscriptionPending && channel.subscriptionCancelled) { + channel.reinstateSubscription(); + } + else if (!channel.subscriptionPending && + this.connection.state === 'connected') { + channel.subscribe(); + } + return channel; + }; + Pusher.prototype.unsubscribe = function (channel_name) { + var channel = this.channels.find(channel_name); + if (channel && channel.subscriptionPending) { + channel.cancelSubscription(); + } + else { + channel = this.channels.remove(channel_name); + if (channel && this.connection.state === 'connected') { + channel.unsubscribe(); + } + } + }; + Pusher.prototype.send_event = function (event_name, data, channel) { + return this.connection.send_event(event_name, data, channel); + }; + Pusher.prototype.shouldUseTLS = function () { + if (node_runtime.getProtocol() === 'https:') { + return true; + } + else if (this.config.forceTLS === true) { + return true; + } + else { + return Boolean(this.config.encrypted); + } + }; + Pusher.instances = []; + Pusher.isReady = false; + Pusher.logToConsole = false; + Pusher.Runtime = node_runtime; + Pusher.ScriptReceivers = node_runtime.ScriptReceivers; + Pusher.DependenciesReceivers = node_runtime.DependenciesReceivers; + Pusher.auth_callbacks = node_runtime.auth_callbacks; + return Pusher; +}()); +/* harmony default export */ var core_pusher = __webpack_exports__["default"] = (pusher_Pusher); +function checkAppKey(key) { + if (key === null || key === undefined) { + throw 'You must pass your app key when you instantiate Pusher.'; + } +} +node_runtime.setup(pusher_Pusher); + /***/ }) /******/ ]); \ No newline at end of file diff --git a/dist/react-native/pusher.js b/dist/react-native/pusher.js index d43b10177..1c3640293 100644 --- a/dist/react-native/pusher.js +++ b/dist/react-native/pusher.js @@ -1,8 +1,8 @@ /*! - * Pusher JavaScript Library v5.0.1 + * Pusher JavaScript Library v5.0.2 * https://pusher.com/ * * Copyright 2017, Pusher * Released under the MIT licence. */ -module.exports=function(t){var e={};function n(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(o,i,function(e){return t[e]}.bind(null,i));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=16)}([function(t,e,n){"use strict";e.__esModule=!0;var o=n(18),i=n(2);function r(t,e){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e(t[n],n,t)}function s(t,e){for(var n=[],o=0;o0)for(o=0;o=1002&&t.code<=1004?"backoff":null:4e3===t.code?"tls_only":t.code<4100?"refused":t.code<4200?"backoff":t.code<4300?"retry":"refused"},e.getCloseError=function(t){return 1e3!==t.code&&1001!==t.code?{type:"PusherError",data:{code:t.code,message:t.reason||t.message}}:null}},function(t,e,n){"use strict";var o,i=this&&this.__extends||(o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var r=n(4),s=n(7),a=n(3),u=n(8),c=function(t){function e(e,n){var o=t.call(this,function(t,n){a.default.debug("No callbacks on "+e+" for "+t)})||this;return o.name=e,o.pusher=n,o.subscribed=!1,o.subscriptionPending=!1,o.subscriptionCancelled=!1,o}return i(e,t),e.prototype.authorize=function(t,e){return e(!1,{})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new s.BadEventName("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var n=u.default.buildLogSuffix("triggeringClientEvents");a.default.warn("Client event triggered before channel 'subscription_succeeded' event . "+n)}return this.pusher.send_event(t,e,this.name)},e.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},e.prototype.handleEvent=function(t){var e=t.event,n=t.data;if("pusher_internal:subscription_succeeded"===e)this.handleSubscriptionSucceededEvent(t);else if(0!==e.indexOf("pusher_internal:")){this.emit(e,n,{})}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",t.data)},e.prototype.subscribe=function(){var t=this;this.subscribed||(this.subscriptionPending=!0,this.subscriptionCancelled=!1,this.authorize(this.pusher.connection.socket_id,function(e,n){e?t.emit("pusher:subscription_error",n):t.pusher.send_event("pusher:subscribe",{auth:n.auth,channel_data:n.channel_data,channel:t.name})}))},e.prototype.unsubscribe=function(){this.subscribed=!1,this.pusher.send_event("pusher:unsubscribe",{channel:this.name})},e.prototype.cancelSubscription=function(){this.subscriptionCancelled=!0},e.prototype.reinstateSubscription=function(){this.subscriptionCancelled=!1},e}(r.default);e.default=c},function(t,e,n){"use strict";e.__esModule=!0;var o=n(0),i=n(2),r=n(5),s=function(){function t(t,e){this.strategies=t,this.loop=Boolean(e.loop),this.failFast=Boolean(e.failFast),this.timeout=e.timeout,this.timeoutLimit=e.timeoutLimit}return t.prototype.isSupported=function(){return o.any(this.strategies,i.default.method("isSupported"))},t.prototype.connect=function(t,e){var n=this,o=this.strategies,i=0,r=this.timeout,s=null,a=function(u,c){c?e(null,c):(i+=1,n.loop&&(i%=o.length),i0&&(i=new r.OneOffTimer(n.timeout,function(){s.abort(),o(!0)})),s=t.connect(e,function(t,e){t&&i&&i.isRunning()&&!n.failFast||(i&&i.ensureAborted(),o(t,e))}),{abort:function(){i&&i.ensureAborted(),s.abort()},forceMinPriority:function(t){s.forceMinPriority(t)}}},t}();e.default=s},function(t,e,n){"use strict";var o;e.__esModule=!0,function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(o||(o={})),e.default=o},function(t,e,n){"use strict";e.__esModule=!0;var o=n(11);t.exports=o.default},function(t,e,n){"use strict";e.__esModule=!0;var o=n(0),i=n(20),r=n(25),s=n(44),a=n(45),u={getDefaultStrategy:r.default,Transports:i.default,transportConnectionInitializer:s.default,HTTPFactory:a.default,setup:function(t){t.ready()},getLocalStorage:function(){},getClientFeatures:function(){return o.keys(o.filterObject({ws:i.default.ws},function(t){return t.isSupported({})}))},getProtocol:function(){return"http:"},isXHRSupported:function(){return!0},createSocketRequest:function(t,e){if(this.isXHRSupported())return this.HTTPFactory.createXHR(t,e);throw"Cross-origin HTTP requests are not supported"},createXHR:function(){return new(this.getXHRAPI())},createWebSocket:function(t){return new(this.getWebSocketAPI())(t)},addUnloadListener:function(t){},removeUnloadListener:function(t){}};e.default=u},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(t){return f(c(t))};for(var o=String.fromCharCode,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r={},s=0,a=i.length;s>>6)+o(128|63&e):o(224|e>>>12&15)+o(128|e>>>6&63)+o(128|63&e)},c=function(t){return t.replace(/[^\x00-\x7F]/g,u)},l=function(t){var e=[0,2,1][t.length%3],n=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[i.charAt(n>>>18),i.charAt(n>>>12&63),e>=2?"=":i.charAt(n>>>6&63),e>=1?"=":i.charAt(63&n)].join("")},f=global.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,l)}},function(t,e,n){"use strict";e.__esModule=!0;var o=function(){function t(t,e,n,o){var i=this;this.clear=e,this.timer=t(function(){i.timer&&(i.timer=o(i.timer))},n)}return t.prototype.isRunning=function(){return null!==this.timer},t.prototype.ensureAborted=function(){this.timer&&(this.clear(this.timer),this.timer=null)},t}();e.default=o},function(t,e,n){"use strict";e.__esModule=!0;var o=n(21),i=n(22),r=n(0),s=n(1),a=new i.default({urls:o.ws,handlesActivityChecks:!1,supportsPing:!1,isInitialized:function(){return Boolean(s.default.getWebSocketAPI())},isSupported:function(){return Boolean(s.default.getWebSocketAPI())},getSocket:function(t){return s.default.createWebSocket(t)}}),u={urls:o.http,handlesActivityChecks:!1,supportsPing:!0,isInitialized:function(){return!0}};e.streamingConfiguration=r.extend({getSocket:function(t){return s.default.HTTPFactory.createStreamingSocket(t)}},u),e.pollingConfiguration=r.extend({getSocket:function(t){return s.default.HTTPFactory.createPollingSocket(t)}},u);var c={isSupported:function(){return s.default.isXHRSupported()}},l={ws:a,xhr_streaming:new i.default(r.extend({},e.streamingConfiguration,c)),xhr_polling:new i.default(r.extend({},e.pollingConfiguration,c))};e.default=l},function(t,e,n){"use strict";e.__esModule=!0;var o=n(9);function i(t,e,n){return t+(e.useTLS?"s":"")+"://"+(e.useTLS?e.hostTLS:e.hostNonTLS)+n}function r(t,e){return"/app/"+t+("?protocol="+o.default.PROTOCOL+"&client=js&version="+o.default.VERSION+(e?"&"+e:""))}e.ws={getInitial:function(t,e){return i("ws",e,(e.httpPath||"")+r(t,"flash=false"))}},e.http={getInitial:function(t,e){return i("http",e,(e.httpPath||"/pusher")+r(t))}},e.sockjs={getInitial:function(t,e){return i("http",e,e.httpPath||"/pusher")},getPath:function(t,e){return r(t)}}},function(t,e,n){"use strict";e.__esModule=!0;var o=n(23),i=function(){function t(t){this.hooks=t}return t.prototype.isSupported=function(t){return this.hooks.isSupported(t)},t.prototype.createConnection=function(t,e,n,i){return new o.default(this.hooks,t,e,n,i)},t}();e.default=i},function(t,e,n){"use strict";var o,i=this&&this.__extends||(o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var r=n(2),s=n(0),a=n(4),u=n(3),c=n(1),l=function(t){function e(e,n,o,i,r){var s=t.call(this)||this;return s.initialize=c.default.transportConnectionInitializer,s.hooks=e,s.name=n,s.priority=o,s.key=i,s.options=r,s.state="new",s.timeline=r.timeline,s.activityTimeout=r.activityTimeout,s.id=s.timeline.generateUniqueID(),s}return i(e,t),e.prototype.handlesActivityChecks=function(){return Boolean(this.hooks.handlesActivityChecks)},e.prototype.supportsPing=function(){return Boolean(this.hooks.supportsPing)},e.prototype.connect=function(){var t=this;if(this.socket||"initialized"!==this.state)return!1;var e=this.hooks.urls.getInitial(this.key,this.options);try{this.socket=this.hooks.getSocket(e,this.options)}catch(e){return r.default.defer(function(){t.onError(e),t.changeState("closed")}),!1}return this.bindListeners(),u.default.debug("Connecting",{transport:this.name,url:e}),this.changeState("connecting"),!0},e.prototype.close=function(){return!!this.socket&&(this.socket.close(),!0)},e.prototype.send=function(t){var e=this;return"open"===this.state&&(r.default.defer(function(){e.socket&&e.socket.send(t)}),!0)},e.prototype.ping=function(){"open"===this.state&&this.supportsPing()&&this.socket.ping()},e.prototype.onOpen=function(){this.hooks.beforeOpen&&this.hooks.beforeOpen(this.socket,this.hooks.urls.getPath(this.key,this.options)),this.changeState("open"),this.socket.onopen=void 0},e.prototype.onError=function(t){this.emit("error",{type:"WebSocketError",error:t}),this.timeline.error(this.buildTimelineMessage({error:t.toString()}))},e.prototype.onClose=function(t){t?this.changeState("closed",{code:t.code,reason:t.reason,wasClean:t.wasClean}):this.changeState("closed"),this.unbindListeners(),this.socket=void 0},e.prototype.onMessage=function(t){this.emit("message",t)},e.prototype.onActivity=function(){this.emit("activity")},e.prototype.bindListeners=function(){var t=this;this.socket.onopen=function(){t.onOpen()},this.socket.onerror=function(e){t.onError(e)},this.socket.onclose=function(e){t.onClose(e)},this.socket.onmessage=function(e){t.onMessage(e)},this.supportsPing()&&(this.socket.onactivity=function(){t.onActivity()})},e.prototype.unbindListeners=function(){this.socket&&(this.socket.onopen=void 0,this.socket.onerror=void 0,this.socket.onclose=void 0,this.socket.onmessage=void 0,this.supportsPing()&&(this.socket.onactivity=void 0))},e.prototype.changeState=function(t,e){this.state=t,this.timeline.info(this.buildTimelineMessage({state:t,params:e})),this.emit(t,e)},e.prototype.buildTimelineMessage=function(t){return s.extend({cid:this.id},t)},e}(a.default);e.default=l},function(t,e,n){"use strict";e.__esModule=!0;var o=n(0),i=function(){function t(){this._callbacks={}}return t.prototype.get=function(t){return this._callbacks[r(t)]},t.prototype.add=function(t,e,n){var o=r(t);this._callbacks[o]=this._callbacks[o]||[],this._callbacks[o].push({fn:e,context:n})},t.prototype.remove=function(t,e,n){if(t||e||n){var i=t?[r(t)]:o.keys(this._callbacks);e||n?this.removeCallback(i,e,n):this.removeAllCallbacks(i)}else this._callbacks={}},t.prototype.removeCallback=function(t,e,n){o.apply(t,function(t){this._callbacks[t]=o.filter(this._callbacks[t]||[],function(t){return e&&e!==t.fn||n&&n!==t.context}),0===this._callbacks[t].length&&delete this._callbacks[t]},this)},t.prototype.removeAllCallbacks=function(t){o.apply(t,function(t){delete this._callbacks[t]},this)},t}();function r(t){return"_"+t}e.default=i},function(t,e,n){"use strict";e.__esModule=!0;var o=n(0),i=n(26),r=n(14),s=n(39),a=n(40),u=n(41),c=n(42),l=n(43);function f(t){return function(){return t.isSupported()}}e.default=function(t,e){var n={};function h(o,i,r,s,a){var u=e(t,o,i,r,s,a);return n[o]=u,u}var p,d={hostNonTLS:t.wsHost+":"+t.wsPort,hostTLS:t.wsHost+":"+t.wssPort,httpPath:t.wsPath},y=o.extend({},d,{useTLS:!0}),v={hostNonTLS:t.httpHost+":"+t.httpPort,hostTLS:t.httpHost+":"+t.httpsPort,httpPath:t.httpPath},g={loop:!0,timeout:15e3,timeoutLimit:6e4},b=new i.default({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),m=new i.default({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),_=h("ws","ws",3,d,b),S=h("wss","ws",3,y,b),k=h("xhr_streaming","xhr_streaming",1,v,m),w=h("xhr_polling","xhr_polling",1,v),O=new r.default([_],g),T=new r.default([S],g),C=new r.default([k],g),P=new r.default([w],g),x=new r.default([new c.default(f(C),new s.default([C,new u.default(P,{delay:4e3})]),P)],g);return p=t.useTLS?new s.default([O,new u.default(x,{delay:2e3})]):new s.default([O,new u.default(T,{delay:2e3}),new u.default(x,{delay:5e3})]),new a.default(new l.default(new c.default(f(_),p,x)),n,{ttl:18e5,timeline:t.timeline,useTLS:t.useTLS})}},function(t,e,n){"use strict";e.__esModule=!0;var o=n(6),i=function(){function t(t){this.options=t||{},this.livesLeft=this.options.lives||1/0}return t.prototype.getAssistant=function(t){return o.default.createAssistantToTheTransportManager(this,t,{minPingDelay:this.options.minPingDelay,maxPingDelay:this.options.maxPingDelay})},t.prototype.isAlive=function(){return this.livesLeft>0},t.prototype.reportDeath=function(){this.livesLeft-=1},t}();e.default=i},function(t,e,n){"use strict";e.__esModule=!0;var o=n(2),i=n(0),r=function(){function t(t,e,n){this.manager=t,this.transport=e,this.minPingDelay=n.minPingDelay,this.maxPingDelay=n.maxPingDelay,this.pingDelay=void 0}return t.prototype.createConnection=function(t,e,n,r){var s=this;r=i.extend({},r,{activityTimeout:this.pingDelay});var a=this.transport.createConnection(t,e,n,r),u=null,c=function(){a.unbind("open",c),a.bind("closed",l),u=o.default.now()},l=function(t){if(a.unbind("closed",l),1002===t.code||1003===t.code)s.manager.reportDeath();else if(!t.wasClean&&u){var e=o.default.now()-u;e<2*s.maxPingDelay&&(s.manager.reportDeath(),s.pingDelay=Math.max(e/2,s.minPingDelay))}};return a.bind("open",c),a},t.prototype.isSupported=function(t){return this.manager.isAlive()&&this.transport.isSupported(t)},t}();e.default=r},function(t,e,n){"use strict";e.__esModule=!0;var o=n(0),i=n(12),r=n(29),s=function(){function t(t,e){this.transport=t,this.callback=e,this.bindListeners()}return t.prototype.close=function(){this.unbindListeners(),this.transport.close()},t.prototype.bindListeners=function(){var t=this;this.onMessage=function(e){var n;t.unbindListeners();try{n=i.processHandshake(e)}catch(e){return t.finish("error",{error:e}),void t.transport.close()}"connected"===n.action?t.finish("connected",{connection:new r.default(n.id,t.transport),activityTimeout:n.activityTimeout}):(t.finish(n.action,{error:n.error}),t.transport.close())},this.onClosed=function(e){t.unbindListeners();var n=i.getCloseAction(e)||"backoff",o=i.getCloseError(e);t.finish(n,{error:o})},this.transport.bind("message",this.onMessage),this.transport.bind("closed",this.onClosed)},t.prototype.unbindListeners=function(){this.transport.unbind("message",this.onMessage),this.transport.unbind("closed",this.onClosed)},t.prototype.finish=function(t,e){this.callback(o.extend({transport:this.transport,action:t},e))},t}();e.default=s},function(t,e,n){"use strict";var o,i=this&&this.__extends||(o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var r=n(0),s=n(4),a=n(12),u=n(3),c=function(t){function e(e,n){var o=t.call(this)||this;return o.id=e,o.transport=n,o.activityTimeout=n.activityTimeout,o.bindListeners(),o}return i(e,t),e.prototype.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()},e.prototype.send=function(t){return this.transport.send(t)},e.prototype.send_event=function(t,e,n){var o={event:t,data:e};return n&&(o.channel=n),u.default.debug("Event sent",o),this.send(a.encodeMessage(o))},e.prototype.ping=function(){this.transport.supportsPing()?this.transport.ping():this.send_event("pusher:ping",{})},e.prototype.close=function(){this.transport.close()},e.prototype.bindListeners=function(){var t=this,e={message:function(e){var n;try{n=a.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(u.default.debug("Event recd",n),n.event){case"pusher:error":t.emit("error",{type:"PusherError",data:n.data});break;case"pusher:ping":t.emit("ping");break;case"pusher:pong":t.emit("pong")}t.emit("message",n)}},activity:function(){t.emit("activity")},error:function(e){t.emit("error",{type:"WebSocketError",error:e})},closed:function(e){n(),e&&e.code&&t.handleCloseEvent(e),t.transport=null,t.emit("closed")}},n=function(){r.objectApply(e,function(e,n){t.transport.unbind(n,e)})};r.objectApply(e,function(e,n){t.transport.bind(n,e)})},e.prototype.handleCloseEvent=function(t){var e=a.getCloseAction(t),n=a.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(s.default);e.default=c},function(t,e,n){"use strict";e.__esModule=!0;var o=n(1),i=function(){function t(t,e){this.channel=t;var n=e.authTransport;if(void 0===o.default.getAuthorizers()[n])throw"'"+n+"' is not a recognized auth transport";this.type=n,this.options=e,this.authOptions=(e||{}).auth||{}}return t.prototype.composeQuery=function(t){var e="socket_id="+encodeURIComponent(t)+"&channel_name="+encodeURIComponent(this.channel.name);for(var n in this.authOptions.params)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(this.authOptions.params[n]);return e},t.prototype.authorize=function(e,n){return t.authorizers=t.authorizers||o.default.getAuthorizers(),t.authorizers[this.type].call(this,o.default,e,n)},t}();e.default=i},function(t,e,n){"use strict";e.__esModule=!0;var o=n(1),i=function(){function t(t,e){this.timeline=t,this.options=e||{}}return t.prototype.send=function(t,e){this.timeline.isEmpty()||this.timeline.send(o.default.TimelineTransport.getAgent(this,t),e)},t}();e.default=i},function(t,e,n){"use strict";var o,i=this&&this.__extends||(o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var r=n(10),s=n(3),a=n(33),u=n(8),c=function(t){function e(e,n){var o=t.call(this,e,n)||this;return o.members=new a.default,o}return i(e,t),e.prototype.authorize=function(e,n){var o=this;t.prototype.authorize.call(this,e,function(t,e){if(!t){if(void 0===e.channel_data){var i=u.default.buildLogSuffix("authenticationEndpoint");return s.default.warn("Invalid auth response for channel '"+o.name+"',expected 'channel_data' field. "+i),void n("Invalid auth response")}var r=JSON.parse(e.channel_data);o.members.setMyID(r.user_id)}n(t,e)})},e.prototype.handleEvent=function(t){var e=t.event;if(0===e.indexOf("pusher_internal:"))this.handleInternalEvent(t);else{var n=t.data,o={};t.user_id&&(o.user_id=t.user_id),this.emit(e,n,o)}},e.prototype.handleInternalEvent=function(t){var e=t.event,n=t.data;switch(e){case"pusher_internal:subscription_succeeded":this.handleSubscriptionSucceededEvent(t);break;case"pusher_internal:member_added":var o=this.members.addMember(n);this.emit("pusher:member_added",o);break;case"pusher_internal:member_removed":var i=this.members.removeMember(n);i&&this.emit("pusher:member_removed",i)}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(t.data),this.emit("pusher:subscription_succeeded",this.members))},e.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},e}(r.default);e.default=c},function(t,e,n){"use strict";e.__esModule=!0;var o=n(0),i=function(){function t(){this.reset()}return t.prototype.get=function(t){return Object.prototype.hasOwnProperty.call(this.members,t)?{id:t,info:this.members[t]}:null},t.prototype.each=function(t){var e=this;o.objectApply(this.members,function(n,o){t(e.get(o))})},t.prototype.setMyID=function(t){this.myID=t},t.prototype.onSubscription=function(t){this.members=t.presence.hash,this.count=t.presence.count,this.me=this.get(this.myID)},t.prototype.addMember=function(t){return null===this.get(t.user_id)&&this.count++,this.members[t.user_id]=t.user_info,this.get(t.user_id)},t.prototype.removeMember=function(t){var e=this.get(t.user_id);return e&&(delete this.members[t.user_id],this.count--),e},t.prototype.reset=function(){this.members={},this.count=0,this.myID=null,this.me=null},t}();e.default=i},function(t,e,n){"use strict";var o,i=this&&this.__extends||(o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var r=n(10),s=n(7),a=n(3),u=n(35),c=n(36),l=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.key=null,e}return i(e,t),e.prototype.authorize=function(e,n){var o=this;t.prototype.authorize.call(this,e,function(t,e){if(t)n(!0,e);else{var i=e.shared_secret;if(!i){var r="No shared_secret key in auth payload for encrypted channel: "+o.name;return n(!0,r),void a.default.warn("Error: "+r)}o.key=c.decodeBase64(i),delete e.shared_secret,n(!1,e)}})},e.prototype.trigger=function(t,e){throw new s.UnsupportedFeature("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e){var n=e.event,o=e.data;0!==n.indexOf("pusher_internal:")&&0!==n.indexOf("pusher:")?this.handleEncryptedEvent(n,o):t.prototype.handleEvent.call(this,e)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(this.key)if(e.ciphertext&&e.nonce){var o=c.decodeBase64(e.ciphertext);if(o.length0&&this.emit("connecting_in",Math.round(t/1e3)),this.retryTimer=new s.OneOffTimer(t||0,function(){e.disconnectInternally(),e.connect()})},e.prototype.clearRetryTimer=function(){this.retryTimer&&(this.retryTimer.ensureAborted(),this.retryTimer=null)},e.prototype.setUnavailableTimer=function(){var t=this;this.unavailableTimer=new s.OneOffTimer(this.options.unavailableTimeout,function(){t.updateState("unavailable")})},e.prototype.clearUnavailableTimer=function(){this.unavailableTimer&&this.unavailableTimer.ensureAborted()},e.prototype.sendActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection.ping(),this.activityTimer=new s.OneOffTimer(this.options.pongTimeout,function(){t.timeline.error({pong_timed_out:t.options.pongTimeout}),t.retryIn(0)})},e.prototype.resetActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection&&!this.connection.handlesActivityChecks()&&(this.activityTimer=new s.OneOffTimer(this.activityTimeout,function(){t.sendActivityCheck()}))},e.prototype.stopActivityCheck=function(){this.activityTimer&&this.activityTimer.ensureAborted()},e.prototype.buildConnectionCallbacks=function(t){var e=this;return u.extend({},t,{message:function(t){e.resetActivityCheck(),e.emit("message",t)},ping:function(){e.send_event("pusher:pong",{})},activity:function(){e.resetActivityCheck()},error:function(t){e.emit("error",{type:"WebSocketError",error:t})},closed:function(){e.abandonConnection(),e.shouldRetry()&&e.retryIn(1e3)}})},e.prototype.buildHandshakeCallbacks=function(t){var e=this;return u.extend({},t,{connected:function(t){e.activityTimeout=Math.min(e.options.activityTimeout,t.activityTimeout,t.connection.activityTimeout||1/0),e.clearUnavailableTimer(),e.setConnection(t.connection),e.socket_id=e.connection.id,e.updateState("connected",{socket_id:e.socket_id})}})},e.prototype.buildErrorCallbacks=function(){var t=this,e=function(e){return function(n){n.error&&t.emit("error",{type:"WebSocketError",error:n.error}),e(n)}};return{tls_only:e(function(){t.usingTLS=!0,t.updateStrategy(),t.retryIn(0)}),refused:e(function(){t.disconnect()}),backoff:e(function(){t.retryIn(1e3)}),retry:e(function(){t.retryIn(0)})}},e.prototype.setConnection=function(t){for(var e in this.connection=t,this.connectionCallbacks)this.connection.bind(e,this.connectionCallbacks[e]);this.resetActivityCheck()},e.prototype.abandonConnection=function(){if(this.connection){for(var t in this.stopActivityCheck(),this.connectionCallbacks)this.connection.unbind(t,this.connectionCallbacks[t]);var e=this.connection;return this.connection=null,e}},e.prototype.updateState=function(t,e){var n=this.state;if(this.state=t,n!==t){var o=t;"connected"===o&&(o+=" with new socket ID "+e.socket_id),a.default.debug("State changed",n+" -> "+o),this.timeline.info({state:t,params:e}),this.emit("state_change",{previous:n,current:t}),this.emit(t,e)}},e.prototype.shouldRetry=function(){return"connecting"===this.state||"connected"===this.state},e}(r.default);e.default=l},function(t,e,n){"use strict";e.__esModule=!0;var o=n(0),i=n(6),r=n(7),s=function(){function t(){this.channels={}}return t.prototype.add=function(t,e){return this.channels[t]||(this.channels[t]=function(t,e){if(0===t.indexOf("private-encrypted-")){throw new r.UnsupportedFeature("Encrypted channels are not yet supported when using React Native builds.")}return 0===t.indexOf("private-")?i.default.createPrivateChannel(t,e):0===t.indexOf("presence-")?i.default.createPresenceChannel(t,e):i.default.createChannel(t,e)}(t,e)),this.channels[t]},t.prototype.all=function(){return o.values(this.channels)},t.prototype.find=function(t){return this.channels[t]},t.prototype.remove=function(t){var e=this.channels[t];return delete this.channels[t],e},t.prototype.disconnect=function(){o.objectApply(this.channels,function(t){t.disconnect()})},t}();e.default=s},function(t,e,n){"use strict";e.__esModule=!0;var o=n(0),i=n(2),r=function(){function t(t){this.strategies=t}return t.prototype.isSupported=function(){return o.any(this.strategies,i.default.method("isSupported"))},t.prototype.connect=function(t,e){return function(t,e,n){var i=o.map(t,function(t,o,i,r){return t.connect(e,n(o,r))});return{abort:function(){o.apply(i,s)},forceMinPriority:function(t){o.apply(i,function(e){e.forceMinPriority(t)})}}}(this.strategies,t,function(t,n){return function(i,r){n[t].error=i,i?function(t){return o.all(t,function(t){return Boolean(t.error)})}(n)&&e(!0):(o.apply(n,function(t){t.forceMinPriority(r.transport.priority)}),e(null,r))}})},t}();function s(t){t.error||t.aborted||(t.abort(),t.aborted=!0)}e.default=r},function(t,e,n){"use strict";e.__esModule=!0;var o=n(2),i=n(1),r=n(14),s=n(0),a=function(){function t(t,e,n){this.strategy=t,this.transports=e,this.ttl=n.ttl||18e5,this.usingTLS=n.useTLS,this.timeline=n.timeline}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.usingTLS,a=function(t){var e=i.default.getLocalStorage();if(e)try{var n=e[u(t)];if(n)return JSON.parse(n)}catch(e){c(t)}return null}(n),l=[this.strategy];if(a&&a.timestamp+this.ttl>=o.default.now()){var f=this.transports[a.transport];f&&(this.timeline.info({cached:!0,transport:a.transport,latency:a.latency}),l.push(new r.default([f],{timeout:2*a.latency+1e3,failFast:!0})))}var h=o.default.now(),p=l.pop().connect(t,function r(a,f){a?(c(n),l.length>0?(h=o.default.now(),p=l.pop().connect(t,r)):e(a)):(!function(t,e,n){var r=i.default.getLocalStorage();if(r)try{r[u(t)]=s.safeJSONStringify({timestamp:o.default.now(),transport:e,latency:n})}catch(t){}}(n,f.transport.name,o.default.now()-h),e(null,f))});return{abort:function(){p.abort()},forceMinPriority:function(e){t=e,p&&p.forceMinPriority(e)}}},t}();function u(t){return"pusherTransport"+(t?"TLS":"NonTLS")}function c(t){var e=i.default.getLocalStorage();if(e)try{delete e[u(t)]}catch(t){}}e.default=a},function(t,e,n){"use strict";e.__esModule=!0;var o=n(5),i=function(){function t(t,e){var n=e.delay;this.strategy=t,this.options={delay:n}}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n,i=this.strategy,r=new o.OneOffTimer(this.options.delay,function(){n=i.connect(t,e)});return{abort:function(){r.ensureAborted(),n&&n.abort()},forceMinPriority:function(e){t=e,n&&n.forceMinPriority(e)}}},t}();e.default=i},function(t,e,n){"use strict";e.__esModule=!0;var o=function(){function t(t,e,n){this.test=t,this.trueBranch=e,this.falseBranch=n}return t.prototype.isSupported=function(){return(this.test()?this.trueBranch:this.falseBranch).isSupported()},t.prototype.connect=function(t,e){return(this.test()?this.trueBranch:this.falseBranch).connect(t,e)},t}();e.default=o},function(t,e,n){"use strict";e.__esModule=!0;var o=function(){function t(t){this.strategy=t}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.strategy.connect(t,function(t,o){o&&n.abort(),e(t,o)});return n},t}();e.default=o},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(){this.timeline.info(this.buildTimelineMessage({transport:this.name+(this.options.useTLS?"s":"")})),this.hooks.isInitialized()?this.changeState("initialized"):this.onClose()}},function(t,e,n){"use strict";e.__esModule=!0;var o=n(46),i=n(47),r=n(49),s=n(50),a=n(51),u={createStreamingSocket:function(t){return this.createSocket(r.default,t)},createPollingSocket:function(t){return this.createSocket(s.default,t)},createSocket:function(t,e){return new i.default(t,e)},createXHR:function(t,e){return this.createRequest(a.default,t,e)},createRequest:function(t,e,n){return new o.default(t,e,n)}};e.default=u},function(t,e,n){"use strict";var o,i=this&&this.__extends||(o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var r=n(1),s=n(4),a=function(t){function e(e,n,o){var i=t.call(this)||this;return i.hooks=e,i.method=n,i.url=o,i}return i(e,t),e.prototype.start=function(t){var e=this;this.position=0,this.xhr=this.hooks.getRequest(this),this.unloader=function(){e.close()},r.default.addUnloadListener(this.unloader),this.xhr.open(this.method,this.url,!0),this.xhr.setRequestHeader&&this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.send(t)},e.prototype.close=function(){this.unloader&&(r.default.removeUnloadListener(this.unloader),this.unloader=null),this.xhr&&(this.hooks.abortRequest(this.xhr),this.xhr=null)},e.prototype.onChunk=function(t,e){for(;;){var n=this.advanceBuffer(e);if(!n)break;this.emit("chunk",{status:t,data:n})}this.isBufferTooLong(e)&&this.emit("buffer_too_long")},e.prototype.advanceBuffer=function(t){var e=t.slice(this.position),n=e.indexOf("\n");return-1!==n?(this.position+=n+1,e.slice(0,n)):null},e.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>262144},e}(s.default);e.default=a},function(t,e,n){"use strict";e.__esModule=!0;var o=n(48),i=n(2),r=n(1),s=1,a=function(){function t(t,e){this.hooks=t,this.session=c(1e3)+"/"+function(t){for(var e=[],n=0;n0&&t.onChunk(e.status,e.responseText);break;case 4:e.responseText&&e.responseText.length>0&&t.onChunk(e.status,e.responseText),t.emit("finished",e.status),t.close()}},e},abortRequest:function(t){t.onreadystatechange=null,t.abort()}};e.default=i},function(t,e,n){"use strict";var o,i=this&&this.__extends||(o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var r=n(53);function s(t){return"none"!==t.type.toLowerCase()}var a=function(t){function e(){var e=t.call(this)||this;return e.online=!0,r.default.getConnectionInfo().then(function(t){e.online=s(t)}),r.default.addEventListener("connectionChange",function(t){var n=s(t);e.online!==n&&(e.online=n,e.online?e.emit("online"):e.emit("offline"))}),e}return i(e,t),e.prototype.isOnline=function(){return this.online},e}(n(4).default);e.NetInfo=a,e.Network=new a},function(t,e){t.exports=require("@react-native-community/netinfo")},function(t,e,n){"use strict";e.__esModule=!0;var o=n(3),i=n(1),r=n(8);e.default=function(t,e,n){var s;for(var a in(s=i.default.createXHR()).open("POST",this.options.authEndpoint,!0),s.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),this.authOptions.headers)s.setRequestHeader(a,this.authOptions.headers[a]);return s.onreadystatechange=function(){if(4===s.readyState)if(200===s.status){var t,e=!1;try{t=JSON.parse(s.responseText),e=!0}catch(t){n(!0,"JSON returned from webapp was invalid, yet status code was 200. Data was: "+s.responseText)}e&&n(!1,t)}else{var i=r.default.buildLogSuffix("authenticationEndpoint");o.default.warn("Couldn't retrieve authentication info. "+s.status+"Clients must be authenticated to join private or presence channels. "+i),n(!0,s.status)}},s.send(this.composeQuery(e)),s}},function(t,e,n){"use strict";e.__esModule=!0;var o=n(3),i=n(0),r=n(1),s={name:"xhr",getAgent:function(t,e){return function(n,s){var a="http"+(e?"s":"")+"://"+(t.host||t.options.host)+t.options.path;a+="/2?"+i.buildQueryString(n);var u=r.default.createXHR();u.open("GET",a,!0),u.onreadystatechange=function(){if(4===u.readyState){var e=u.status,n=u.responseText;if(200!==e)return void o.default.debug("TimelineSender Error: received "+e+" from stats.pusher.com");try{var i=JSON.parse(n).host}catch(t){o.default.debug("TimelineSenderError: invalid response "+n)}i&&(t.host=i)}},u.send()}}};e.default=s},function(t,e,n){"use strict";e.__esModule=!0;var o=n(0),i=n(2),r=n(15),s=function(){function t(t,e,n){this.key=t,this.session=e,this.events=[],this.options=n||{},this.sent=0,this.uniqueID=0}return t.prototype.log=function(t,e){t<=this.options.level&&(this.events.push(o.extend({},e,{timestamp:i.default.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(r.default.ERROR,t)},t.prototype.info=function(t){this.log(r.default.INFO,t)},t.prototype.debug=function(t){this.log(r.default.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,i=o.extend({session:this.session,bundle:this.sent+1,key:this.key,lib:"js",version:this.options.version,cluster:this.options.cluster,features:this.options.features,timeline:this.events},this.options.params);return this.events=[],t(i,function(t,o){t||n.sent++,e&&e(t,o)}),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}();e.default=s},function(t,e,n){"use strict";e.__esModule=!0;var o=n(0),i=n(2),r=n(7),s=n(58),a=n(1).default.Transports;e.defineTransport=function(t,e,n,i,c,l){var f=a[n];if(!f)throw new r.UnsupportedTransport(n);return!(t.enabledTransports&&-1===o.arrayIndexOf(t.enabledTransports,e)||t.disabledTransports&&-1!==o.arrayIndexOf(t.disabledTransports,e))?new s.default(e,i,l?l.getAssistant(f):f,o.extend({key:t.key,useTLS:t.useTLS,timeline:t.timeline,ignoreNullOrigin:t.ignoreNullOrigin},c)):u};var u={isSupported:function(){return!1},connect:function(t,e){var n=i.default.defer(function(){e(new r.UnsupportedStrategy)});return{abort:function(){n.ensureAborted()},forceMinPriority:function(){}}}}},function(t,e,n){"use strict";e.__esModule=!0;var o=n(6),i=n(2),r=n(7),s=n(0),a=function(){function t(t,e,n,o){this.name=t,this.priority=e,this.transport=n,this.options=o||{}}return t.prototype.isSupported=function(){return this.transport.isSupported({useTLS:this.options.useTLS})},t.prototype.connect=function(t,e){var n=this;if(!this.isSupported())return u(new r.UnsupportedStrategy,e);if(this.priority>>6)+o(128|63&e):o(224|e>>>12&15)+o(128|e>>>6&63)+o(128|63&e)},h=function(t){return t.replace(/[^\x00-\x7F]/g,u)},p=function(t){var e=[0,2,1][t.length%3],n=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[i.charAt(n>>>18),i.charAt(n>>>12&63),e>=2?"=":i.charAt(n>>>6&63),e>=1?"=":i.charAt(63&n)].join("")},l=global.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,p)},f=function(){function t(t,e,n,o){var i=this;this.clear=e,this.timer=t(function(){i.timer&&(i.timer=o(i.timer))},n)}return t.prototype.isRunning=function(){return null!==this.timer},t.prototype.ensureAborted=function(){this.timer&&(this.clear(this.timer),this.timer=null)},t}(),d=(a=function(t,e){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});function y(t){global.clearTimeout(t)}function v(t){global.clearInterval(t)}var b=function(t){function e(e,n){return t.call(this,setTimeout,y,e,function(t){return n(),null})||this}return d(e,t),e}(f),g=function(t){function e(e,n){return t.call(this,setInterval,v,e,function(t){return n(),t})||this}return d(e,t),e}(f),m={now:function(){return Date.now?Date.now():(new Date).valueOf()},defer:function(t){return new b(0,t)},method:function(t){for(var e=[],n=1;n0)for(o=0;o=1002&&t.code<=1004?"backoff":null:4e3===t.code?"tls_only":t.code<4100?"refused":t.code<4200?"backoff":t.code<4300?"retry":"refused"},getCloseError:function(t){return 1e3!==t.code&&1001!==t.code?{type:"PusherError",data:{code:t.code,message:t.reason||t.message}}:null}},Z=K,tt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),et=function(t){function e(e,n){var o=t.call(this)||this;return o.id=e,o.transport=n,o.activityTimeout=n.activityTimeout,o.bindListeners(),o}return tt(e,t),e.prototype.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()},e.prototype.send=function(t){return this.transport.send(t)},e.prototype.send_event=function(t,e,n){var o={event:t,data:e};return n&&(o.channel=n),F.debug("Event sent",o),this.send(Z.encodeMessage(o))},e.prototype.ping=function(){this.transport.supportsPing()?this.transport.ping():this.send_event("pusher:ping",{})},e.prototype.close=function(){this.transport.close()},e.prototype.bindListeners=function(){var t=this,e={message:function(e){var n;try{n=Z.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(F.debug("Event recd",n),n.event){case"pusher:error":t.emit("error",{type:"PusherError",data:n.data});break;case"pusher:ping":t.emit("ping");break;case"pusher:pong":t.emit("pong")}t.emit("message",n)}},activity:function(){t.emit("activity")},error:function(e){t.emit("error",{type:"WebSocketError",error:e})},closed:function(e){n(),e&&e.code&&t.handleCloseEvent(e),t.transport=null,t.emit("closed")}},n=function(){w(e,function(e,n){t.transport.unbind(n,e)})};w(e,function(e,n){t.transport.bind(n,e)})},e.prototype.handleCloseEvent=function(t){var e=Z.getCloseAction(t),n=Z.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(z),nt=function(){function t(t,e){this.transport=t,this.callback=e,this.bindListeners()}return t.prototype.close=function(){this.unbindListeners(),this.transport.close()},t.prototype.bindListeners=function(){var t=this;this.onMessage=function(e){var n;t.unbindListeners();try{n=Z.processHandshake(e)}catch(e){return t.finish("error",{error:e}),void t.transport.close()}"connected"===n.action?t.finish("connected",{connection:new et(n.id,t.transport),activityTimeout:n.activityTimeout}):(t.finish(n.action,{error:n.error}),t.transport.close())},this.onClosed=function(e){t.unbindListeners();var n=Z.getCloseAction(e)||"backoff",o=Z.getCloseError(e);t.finish(n,{error:o})},this.transport.bind("message",this.onMessage),this.transport.bind("closed",this.onClosed)},t.prototype.unbindListeners=function(){this.transport.unbind("message",this.onMessage),this.transport.unbind("closed",this.onClosed)},t.prototype.finish=function(t,e){this.callback(_({transport:this.transport,action:t},e))},t}(),ot=function(){function t(t,e){this.channel=t;var n=e.authTransport;if(void 0===ie.getAuthorizers()[n])throw"'"+n+"' is not a recognized auth transport";this.type=n,this.options=e,this.authOptions=(e||{}).auth||{}}return t.prototype.composeQuery=function(t){var e="socket_id="+encodeURIComponent(t)+"&channel_name="+encodeURIComponent(this.channel.name);for(var n in this.authOptions.params)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(this.authOptions.params[n]);return e},t.prototype.authorize=function(e,n){return t.authorizers=t.authorizers||ie.getAuthorizers(),t.authorizers[this.type].call(this,ie,e,n)},t}(),it=function(){function t(t,e){this.timeline=t,this.options=e||{}}return t.prototype.send=function(t,e){this.timeline.isEmpty()||this.timeline.send(ie.TimelineTransport.getAgent(this,t),e)},t}(),rt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),st=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return rt(e,t),e}(Error),ct=(function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}rt(e,t)}(Error),function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return rt(e,t),e}(Error)),at=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return rt(e,t),e}(Error),ut=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return rt(e,t),e}(Error),ht=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return rt(e,t),e}(Error),pt=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return rt(e,t),e}(Error),lt={baseUrl:"https://pusher.com",urls:{authenticationEndpoint:{path:"/docs/authenticating_users"},javascriptQuickStart:{path:"/docs/javascript_quick_start"},triggeringClientEvents:{path:"/docs/client_api_guide/client_events#trigger-events"}}},ft={buildLogSuffix:function(t){var e,n=lt.urls[t];return n?(n.fullUrl?e=n.fullUrl:n.path&&(e=lt.baseUrl+n.path),e?"See: "+e:""):""}},dt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),yt=function(t){function e(e,n){var o=t.call(this,function(t,n){F.debug("No callbacks on "+e+" for "+t)})||this;return o.name=e,o.pusher=n,o.subscribed=!1,o.subscriptionPending=!1,o.subscriptionCancelled=!1,o}return dt(e,t),e.prototype.authorize=function(t,e){return e(!1,{})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new st("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var n=ft.buildLogSuffix("triggeringClientEvents");F.warn("Client event triggered before channel 'subscription_succeeded' event . "+n)}return this.pusher.send_event(t,e,this.name)},e.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},e.prototype.handleEvent=function(t){var e=t.event,n=t.data;if("pusher_internal:subscription_succeeded"===e)this.handleSubscriptionSucceededEvent(t);else if(0!==e.indexOf("pusher_internal:")){this.emit(e,n,{})}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",t.data)},e.prototype.subscribe=function(){var t=this;this.subscribed||(this.subscriptionPending=!0,this.subscriptionCancelled=!1,this.authorize(this.pusher.connection.socket_id,function(e,n){e?t.emit("pusher:subscription_error",n):t.pusher.send_event("pusher:subscribe",{auth:n.auth,channel_data:n.channel_data,channel:t.name})}))},e.prototype.unsubscribe=function(){this.subscribed=!1,this.pusher.send_event("pusher:unsubscribe",{channel:this.name})},e.prototype.cancelSubscription=function(){this.subscriptionCancelled=!0},e.prototype.reinstateSubscription=function(){this.subscriptionCancelled=!1},e}(z),vt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),bt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return vt(e,t),e.prototype.authorize=function(t,e){return Ct.createAuthorizer(this,this.pusher.config).authorize(t,e)},e}(yt),gt=function(){function t(){this.reset()}return t.prototype.get=function(t){return Object.prototype.hasOwnProperty.call(this.members,t)?{id:t,info:this.members[t]}:null},t.prototype.each=function(t){var e=this;w(this.members,function(n,o){t(e.get(o))})},t.prototype.setMyID=function(t){this.myID=t},t.prototype.onSubscription=function(t){this.members=t.presence.hash,this.count=t.presence.count,this.me=this.get(this.myID)},t.prototype.addMember=function(t){return null===this.get(t.user_id)&&this.count++,this.members[t.user_id]=t.user_info,this.get(t.user_id)},t.prototype.removeMember=function(t){var e=this.get(t.user_id);return e&&(delete this.members[t.user_id],this.count--),e},t.prototype.reset=function(){this.members={},this.count=0,this.myID=null,this.me=null},t}(),mt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),_t=function(t){function e(e,n){var o=t.call(this,e,n)||this;return o.members=new gt,o}return mt(e,t),e.prototype.authorize=function(e,n){var o=this;t.prototype.authorize.call(this,e,function(t,e){if(!t){if(void 0===e.channel_data){var i=ft.buildLogSuffix("authenticationEndpoint");return F.warn("Invalid auth response for channel '"+o.name+"',expected 'channel_data' field. "+i),void n("Invalid auth response")}var r=JSON.parse(e.channel_data);o.members.setMyID(r.user_id)}n(t,e)})},e.prototype.handleEvent=function(t){var e=t.event;if(0===e.indexOf("pusher_internal:"))this.handleInternalEvent(t);else{var n=t.data,o={};t.user_id&&(o.user_id=t.user_id),this.emit(e,n,o)}},e.prototype.handleInternalEvent=function(t){var e=t.event,n=t.data;switch(e){case"pusher_internal:subscription_succeeded":this.handleSubscriptionSucceededEvent(t);break;case"pusher_internal:member_added":var o=this.members.addMember(n);this.emit("pusher:member_added",o);break;case"pusher_internal:member_removed":var i=this.members.removeMember(n);i&&this.emit("pusher:member_removed",i)}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(t.data),this.emit("pusher:subscription_succeeded",this.members))},e.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},e}(bt),St=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),kt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.key=null,e}return St(e,t),e.prototype.authorize=function(e,n){var o=this;t.prototype.authorize.call(this,e,function(t,e){if(t)n(!0,e);else{var i=e.shared_secret;if(!i){var r="No shared_secret key in auth payload for encrypted channel: "+o.name;return n(!0,r),void F.warn("Error: "+r)}o.key=(void 0)(i),delete e.shared_secret,n(!1,e)}})},e.prototype.trigger=function(t,e){throw new ut("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e){var n=e.event,o=e.data;0!==n.indexOf("pusher_internal:")&&0!==n.indexOf("pusher:")?this.handleEncryptedEvent(n,o):t.prototype.handleEvent.call(this,e)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(this.key)if(e.ciphertext&&e.nonce){var o=(void 0)(e.ciphertext);if(o.length<(void 0).overheadLength)F.warn("Expected encrypted event ciphertext length to be "+(void 0).overheadLength+", got: "+o.length);else{var i=(void 0)(e.nonce);if(i.length<(void 0).nonceLength)F.warn("Expected encrypted event nonce length to be "+(void 0).nonceLength+", got: "+i.length);else{var r=(void 0).open(o,i,this.key);if(null===r)return F.debug("Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint..."),void this.authorize(this.pusher.connection.socket_id,function(e,s){e?F.warn("Failed to make a request to the authEndpoint: "+s+". Unable to fetch new key, so dropping encrypted event"):null!==(r=(void 0).open(o,i,n.key))?n.emitJSON(t,(void 0)(r)):F.warn("Failed to decrypt event with new key. Dropping encrypted event")});this.emitJSON(t,(void 0)(r))}}}else F.warn("Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: "+e);else F.debug("Received encrypted event before key has been retrieved from the authEndpoint")},e.prototype.emitJSON=function(t,e){try{this.emit(t,JSON.parse(e))}catch(n){this.emit(t,e)}return this},e}(bt),wt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),Ot=function(t){function e(e,n){var o=t.call(this)||this;o.key=e,o.options=n||{},o.state="initialized",o.connection=null,o.usingTLS=!!n.useTLS,o.timeline=o.options.timeline,o.errorCallbacks=o.buildErrorCallbacks(),o.connectionCallbacks=o.buildConnectionCallbacks(o.errorCallbacks),o.handshakeCallbacks=o.buildHandshakeCallbacks(o.errorCallbacks);var i=ie.getNetwork();return i.bind("online",function(){o.timeline.info({netinfo:"online"}),"connecting"!==o.state&&"unavailable"!==o.state||o.retryIn(0)}),i.bind("offline",function(){o.timeline.info({netinfo:"offline"}),o.connection&&o.sendActivityCheck()}),o.updateStrategy(),o}return wt(e,t),e.prototype.connect=function(){this.connection||this.runner||(this.strategy.isSupported()?(this.updateState("connecting"),this.startConnecting(),this.setUnavailableTimer()):this.updateState("failed"))},e.prototype.send=function(t){return!!this.connection&&this.connection.send(t)},e.prototype.send_event=function(t,e,n){return!!this.connection&&this.connection.send_event(t,e,n)},e.prototype.disconnect=function(){this.disconnectInternally(),this.updateState("disconnected")},e.prototype.isUsingTLS=function(){return this.usingTLS},e.prototype.startConnecting=function(){var t=this,e=function(n,o){n?t.runner=t.strategy.connect(0,e):"error"===o.action?(t.emit("error",{type:"HandshakeError",error:o.error}),t.timeline.error({handshakeError:o.error})):(t.abortConnecting(),t.handshakeCallbacks[o.action](o))};this.runner=this.strategy.connect(0,e)},e.prototype.abortConnecting=function(){this.runner&&(this.runner.abort(),this.runner=null)},e.prototype.disconnectInternally=function(){(this.abortConnecting(),this.clearRetryTimer(),this.clearUnavailableTimer(),this.connection)&&this.abandonConnection().close()},e.prototype.updateStrategy=function(){this.strategy=this.options.getStrategy({key:this.key,timeline:this.timeline,useTLS:this.usingTLS})},e.prototype.retryIn=function(t){var e=this;this.timeline.info({action:"retry",delay:t}),t>0&&this.emit("connecting_in",Math.round(t/1e3)),this.retryTimer=new b(t||0,function(){e.disconnectInternally(),e.connect()})},e.prototype.clearRetryTimer=function(){this.retryTimer&&(this.retryTimer.ensureAborted(),this.retryTimer=null)},e.prototype.setUnavailableTimer=function(){var t=this;this.unavailableTimer=new b(this.options.unavailableTimeout,function(){t.updateState("unavailable")})},e.prototype.clearUnavailableTimer=function(){this.unavailableTimer&&this.unavailableTimer.ensureAborted()},e.prototype.sendActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection.ping(),this.activityTimer=new b(this.options.pongTimeout,function(){t.timeline.error({pong_timed_out:t.options.pongTimeout}),t.retryIn(0)})},e.prototype.resetActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection&&!this.connection.handlesActivityChecks()&&(this.activityTimer=new b(this.activityTimeout,function(){t.sendActivityCheck()}))},e.prototype.stopActivityCheck=function(){this.activityTimer&&this.activityTimer.ensureAborted()},e.prototype.buildConnectionCallbacks=function(t){var e=this;return _({},t,{message:function(t){e.resetActivityCheck(),e.emit("message",t)},ping:function(){e.send_event("pusher:pong",{})},activity:function(){e.resetActivityCheck()},error:function(t){e.emit("error",{type:"WebSocketError",error:t})},closed:function(){e.abandonConnection(),e.shouldRetry()&&e.retryIn(1e3)}})},e.prototype.buildHandshakeCallbacks=function(t){var e=this;return _({},t,{connected:function(t){e.activityTimeout=Math.min(e.options.activityTimeout,t.activityTimeout,t.connection.activityTimeout||1/0),e.clearUnavailableTimer(),e.setConnection(t.connection),e.socket_id=e.connection.id,e.updateState("connected",{socket_id:e.socket_id})}})},e.prototype.buildErrorCallbacks=function(){var t=this,e=function(e){return function(n){n.error&&t.emit("error",{type:"WebSocketError",error:n.error}),e(n)}};return{tls_only:e(function(){t.usingTLS=!0,t.updateStrategy(),t.retryIn(0)}),refused:e(function(){t.disconnect()}),backoff:e(function(){t.retryIn(1e3)}),retry:e(function(){t.retryIn(0)})}},e.prototype.setConnection=function(t){for(var e in this.connection=t,this.connectionCallbacks)this.connection.bind(e,this.connectionCallbacks[e]);this.resetActivityCheck()},e.prototype.abandonConnection=function(){if(this.connection){for(var t in this.stopActivityCheck(),this.connectionCallbacks)this.connection.unbind(t,this.connectionCallbacks[t]);var e=this.connection;return this.connection=null,e}},e.prototype.updateState=function(t,e){var n=this.state;if(this.state=t,n!==t){var o=t;"connected"===o&&(o+=" with new socket ID "+e.socket_id),F.debug("State changed",n+" -> "+o),this.timeline.info({state:t,params:e}),this.emit("state_change",{previous:n,current:t}),this.emit(t,e)}},e.prototype.shouldRetry=function(){return"connecting"===this.state||"connected"===this.state},e}(z),Tt=function(){function t(){this.channels={}}return t.prototype.add=function(t,e){return this.channels[t]||(this.channels[t]=function(t,e){if(0===t.indexOf("private-encrypted-")){throw new ut("Encrypted channels are not yet supported when using React Native builds.")}return 0===t.indexOf("private-")?Ct.createPrivateChannel(t,e):0===t.indexOf("presence-")?Ct.createPresenceChannel(t,e):Ct.createChannel(t,e)}(t,e)),this.channels[t]},t.prototype.all=function(){return function(t){var e=[];return w(t,function(t){e.push(t)}),e}(this.channels)},t.prototype.find=function(t){return this.channels[t]},t.prototype.remove=function(t){var e=this.channels[t];return delete this.channels[t],e},t.prototype.disconnect=function(){w(this.channels,function(t){t.disconnect()})},t}();var Ct={createChannels:function(){return new Tt},createConnectionManager:function(t,e){return new Ot(t,e)},createChannel:function(t,e){return new yt(t,e)},createPrivateChannel:function(t,e){return new bt(t,e)},createPresenceChannel:function(t,e){return new _t(t,e)},createEncryptedChannel:function(t,e){return new kt(t,e)},createTimelineSender:function(t,e){return new it(t,e)},createAuthorizer:function(t,e){return e.authorizer?e.authorizer(t,e):new ot(t,e)},createHandshake:function(t,e){return new nt(t,e)},createAssistantToTheTransportManager:function(t,e,n){return new $(t,e,n)}},Pt=function(){function t(t){this.options=t||{},this.livesLeft=this.options.lives||1/0}return t.prototype.getAssistant=function(t){return Ct.createAssistantToTheTransportManager(this,t,{minPingDelay:this.options.minPingDelay,maxPingDelay:this.options.maxPingDelay})},t.prototype.isAlive=function(){return this.livesLeft>0},t.prototype.reportDeath=function(){this.livesLeft-=1},t}(),Et=function(){function t(t,e){this.strategies=t,this.loop=Boolean(e.loop),this.failFast=Boolean(e.failFast),this.timeout=e.timeout,this.timeoutLimit=e.timeoutLimit}return t.prototype.isSupported=function(){return L(this.strategies,m.method("isSupported"))},t.prototype.connect=function(t,e){var n=this,o=this.strategies,i=0,r=this.timeout,s=null,c=function(a,u){u?e(null,u):(i+=1,n.loop&&(i%=o.length),i0&&(i=new b(n.timeout,function(){r.abort(),o(!0)})),r=t.connect(e,function(t,e){t&&i&&i.isRunning()&&!n.failFast||(i&&i.ensureAborted(),o(t,e))}),{abort:function(){i&&i.ensureAborted(),r.abort()},forceMinPriority:function(t){r.forceMinPriority(t)}}},t}(),Lt=function(){function t(t){this.strategies=t}return t.prototype.isSupported=function(){return L(this.strategies,m.method("isSupported"))},t.prototype.connect=function(t,e){return function(t,e,n){var o=C(t,function(t,o,i,r){return t.connect(e,n(o,r))});return{abort:function(){T(o,xt)},forceMinPriority:function(t){T(o,function(e){e.forceMinPriority(t)})}}}(this.strategies,t,function(t,n){return function(o,i){n[t].error=o,o?function(t){return function(t,e){for(var n=0;n=m.now()){var r=this.transports[o.transport];r&&(this.timeline.info({cached:!0,transport:o.transport,latency:o.latency}),i.push(new Et([r],{timeout:2*o.latency+1e3,failFast:!0})))}var s=m.now(),c=i.pop().connect(t,function o(r,a){r?(jt(n),i.length>0?(s=m.now(),c=i.pop().connect(t,o)):e(r)):(!function(t,e,n){var o=ie.getLocalStorage();if(o)try{o[Rt(t)]=R({timestamp:m.now(),transport:e,latency:n})}catch(t){}}(n,a.transport.name,m.now()-s),e(null,a))});return{abort:function(){c.abort()},forceMinPriority:function(e){t=e,c&&c.forceMinPriority(e)}}},t}();function Rt(t){return"pusherTransport"+(t?"TLS":"NonTLS")}function jt(t){var e=ie.getLocalStorage();if(e)try{delete e[Rt(t)]}catch(t){}}var It=function(){function t(t,e){var n=e.delay;this.strategy=t,this.options={delay:n}}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n,o=this.strategy,i=new b(this.options.delay,function(){n=o.connect(t,e)});return{abort:function(){i.ensureAborted(),n&&n.abort()},forceMinPriority:function(e){t=e,n&&n.forceMinPriority(e)}}},t}(),Nt=function(){function t(t,e,n){this.test=t,this.trueBranch=e,this.falseBranch=n}return t.prototype.isSupported=function(){return(this.test()?this.trueBranch:this.falseBranch).isSupported()},t.prototype.connect=function(t,e){return(this.test()?this.trueBranch:this.falseBranch).connect(t,e)},t}(),Mt=function(){function t(t){this.strategy=t}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.strategy.connect(t,function(t,o){o&&n.abort(),e(t,o)});return n},t}();function Ht(t){return function(){return t.isSupported()}}var Dt,Ut=function(t,e){var n={};function o(o,i,r,s,c){var a=e(t,o,i,r,s,c);return n[o]=a,a}var i,r={hostNonTLS:t.wsHost+":"+t.wsPort,hostTLS:t.wsHost+":"+t.wssPort,httpPath:t.wsPath},s=_({},r,{useTLS:!0}),c={hostNonTLS:t.httpHost+":"+t.httpPort,hostTLS:t.httpHost+":"+t.httpsPort,httpPath:t.httpPath},a={loop:!0,timeout:15e3,timeoutLimit:6e4},u=new Pt({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),h=new Pt({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),p=o("ws","ws",3,r,u),l=o("wss","ws",3,s,u),f=o("xhr_streaming","xhr_streaming",1,c,h),d=o("xhr_polling","xhr_polling",1,c),y=new Et([p],a),v=new Et([l],a),b=new Et([f],a),g=new Et([d],a),m=new Et([new Nt(Ht(b),new Lt([b,new It(g,{delay:4e3})]),g)],a);return i=t.useTLS?new Lt([y,new It(m,{delay:2e3})]):new Lt([y,new It(v,{delay:2e3}),new It(m,{delay:5e3})]),new At(new Mt(new Nt(Ht(p),i,m)),n,{ttl:18e5,timeline:t.timeline,useTLS:t.useTLS})},zt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),Ft=function(t){function e(e,n,o){var i=t.call(this)||this;return i.hooks=e,i.method=n,i.url=o,i}return zt(e,t),e.prototype.start=function(t){var e=this;this.position=0,this.xhr=this.hooks.getRequest(this),this.unloader=function(){e.close()},ie.addUnloadListener(this.unloader),this.xhr.open(this.method,this.url,!0),this.xhr.setRequestHeader&&this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.send(t)},e.prototype.close=function(){this.unloader&&(ie.removeUnloadListener(this.unloader),this.unloader=null),this.xhr&&(this.hooks.abortRequest(this.xhr),this.xhr=null)},e.prototype.onChunk=function(t,e){for(;;){var n=this.advanceBuffer(e);if(!n)break;this.emit("chunk",{status:t,data:n})}this.isBufferTooLong(e)&&this.emit("buffer_too_long")},e.prototype.advanceBuffer=function(t){var e=t.slice(this.position),n=e.indexOf("\n");return-1!==n?(this.position+=n+1,e.slice(0,n)):null},e.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>262144},e}(z);!function(t){t[t.CONNECTING=0]="CONNECTING",t[t.OPEN=1]="OPEN",t[t.CLOSED=3]="CLOSED"}(Dt||(Dt={}));var qt=Dt,Bt=1;function Jt(t){var e=-1===t.indexOf("?")?"?":"&";return t+e+"t="+ +new Date+"&n="+Bt++}function Xt(t){return Math.floor(Math.random()*t)}var Wt=function(){function t(t,e){this.hooks=t,this.session=Xt(1e3)+"/"+function(t){for(var e=[],n=0;n0&&t.onChunk(e.status,e.responseText);break;case 4:e.responseText&&e.responseText.length>0&&t.onChunk(e.status,e.responseText),t.emit("finished",e.status),t.close()}},e},abortRequest:function(t){t.onreadystatechange=null,t.abort()}},Yt={getDefaultStrategy:Ut,Transports:Y,transportConnectionInitializer:function(){this.timeline.info(this.buildTimelineMessage({transport:this.name+(this.options.useTLS?"s":"")})),this.hooks.isInitialized()?this.changeState("initialized"):this.onClose()},HTTPFactory:{createStreamingSocket:function(t){return this.createSocket(Gt,t)},createPollingSocket:function(t){return this.createSocket(Qt,t)},createSocket:function(t,e){return new Wt(t,e)},createXHR:function(t,e){return this.createRequest(Vt,t,e)},createRequest:function(t,e,n){return new Ft(t,e,n)}},setup:function(t){t.ready()},getLocalStorage:function(){},getClientFeatures:function(){return O(E({ws:Y.ws},function(t){return t.isSupported({})}))},getProtocol:function(){return"http:"},isXHRSupported:function(){return!0},createSocketRequest:function(t,e){if(this.isXHRSupported())return this.HTTPFactory.createXHR(t,e);throw"Cross-origin HTTP requests are not supported"},createXHR:function(){return new(this.getXHRAPI())},createWebSocket:function(t){return new(this.getWebSocketAPI())(t)},addUnloadListener:function(t){},removeUnloadListener:function(t){}},$t=n(0),Kt=n.n($t),Zt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}();function te(t){return"none"!==t.type.toLowerCase()}var ee,ne=new(function(t){function e(){var e=t.call(this)||this;return e.online=!0,Kt.a.fetch().then(function(t){e.online=te(t)}),Kt.a.addEventListener(function(t){var n=te(t);e.online!==n&&(e.online=n,e.online?e.emit("online"):e.emit("offline"))}),e}return Zt(e,t),e.prototype.isOnline=function(){return this.online},e}(z)),oe=function(t,e,n){var o,i=this;for(var r in(o=ie.createXHR()).open("POST",i.options.authEndpoint,!0),o.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),this.authOptions.headers)o.setRequestHeader(r,this.authOptions.headers[r]);return o.onreadystatechange=function(){if(4===o.readyState)if(200===o.status){var t,e=!1;try{t=JSON.parse(o.responseText),e=!0}catch(t){n(!0,"JSON returned from webapp was invalid, yet status code was 200. Data was: "+o.responseText)}e&&n(!1,t)}else{var r=ft.buildLogSuffix("authenticationEndpoint");F.warn("Unable to retrieve auth string from auth endpoint - received status "+o.status+" from "+i.options.authEndpoint+". Clients must be authenticated to join private or presence channels. "+r),n(!0,o.status)}},o.send(this.composeQuery(e)),o},ie={getDefaultStrategy:Yt.getDefaultStrategy,Transports:Yt.Transports,setup:Yt.setup,getProtocol:Yt.getProtocol,isXHRSupported:Yt.isXHRSupported,getLocalStorage:Yt.getLocalStorage,createXHR:Yt.createXHR,createWebSocket:Yt.createWebSocket,addUnloadListener:Yt.addUnloadListener,removeUnloadListener:Yt.removeUnloadListener,transportConnectionInitializer:Yt.transportConnectionInitializer,createSocketRequest:Yt.createSocketRequest,HTTPFactory:Yt.HTTPFactory,TimelineTransport:{name:"xhr",getAgent:function(t,e){return function(n,o){var i="http"+(e?"s":"")+"://"+(t.host||t.options.host)+t.options.path;i+="/2?"+A(n);var r=ie.createXHR();r.open("GET",i,!0),r.onreadystatechange=function(){if(4===r.readyState){var e=r.status,n=r.responseText;if(200!==e)return void F.debug("TimelineSender Error: received "+e+" from stats.pusher.com");try{var o=JSON.parse(n).host}catch(t){F.debug("TimelineSenderError: invalid response "+n)}o&&(t.host=o)}},r.send()}}},getAuthorizers:function(){return{ajax:oe}},getWebSocketAPI:function(){return WebSocket},getXHRAPI:function(){return XMLHttpRequest},getNetwork:function(){return ne}};!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(ee||(ee={}));var re=ee,se=function(){function t(t,e,n){this.key=t,this.session=e,this.events=[],this.options=n||{},this.sent=0,this.uniqueID=0}return t.prototype.log=function(t,e){t<=this.options.level&&(this.events.push(_({},e,{timestamp:m.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(re.ERROR,t)},t.prototype.info=function(t){this.log(re.INFO,t)},t.prototype.debug=function(t){this.log(re.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,o=_({session:this.session,bundle:this.sent+1,key:this.key,lib:"js",version:this.options.version,cluster:this.options.cluster,features:this.options.features,timeline:this.events},this.options.params);return this.events=[],t(o,function(t,o){t||n.sent++,e&&e(t,o)}),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}(),ce=function(){function t(t,e,n,o){this.name=t,this.priority=e,this.transport=n,this.options=o||{}}return t.prototype.isSupported=function(){return this.transport.isSupported({useTLS:this.options.useTLS})},t.prototype.connect=function(t,e){var n=this;if(!this.isSupported())return ae(new pt,e);if(this.priority> 24) & 0xff; + x[i+1] = (h >> 16) & 0xff; + x[i+2] = (h >> 8) & 0xff; + x[i+3] = h & 0xff; + x[i+4] = (l >> 24) & 0xff; + x[i+5] = (l >> 16) & 0xff; + x[i+6] = (l >> 8) & 0xff; + x[i+7] = l & 0xff; } -exports.encodeParamsObject = encodeParamsObject; -function buildQueryString(data) { - var params = filterObject(data, function (value) { - return value !== undefined; - }); - var query = map(flatten(encodeParamsObject(params)), util_1["default"].method("join", "=")).join("&"); - return query; + +function vn(x, xi, y, yi, n) { + var i,d = 0; + for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i]; + return (1 & ((d - 1) >>> 8)) - 1; } -exports.buildQueryString = buildQueryString; -function decycleObject(object) { - var objects = [], paths = []; - return (function derez(value, path) { - var i, name, nu; - switch (typeof value) { - case 'object': - if (!value) { - return null; - } - for (i = 0; i < objects.length; i += 1) { - if (objects[i] === value) { - return { $ref: paths[i] }; - } - } - objects.push(value); - paths.push(path); - if (Object.prototype.toString.apply(value) === '[object Array]') { - nu = []; - for (i = 0; i < value.length; i += 1) { - nu[i] = derez(value[i], path + '[' + i + ']'); - } - } - else { - nu = {}; - for (name in value) { - if (Object.prototype.hasOwnProperty.call(value, name)) { - nu[name] = derez(value[name], path + '[' + JSON.stringify(name) + ']'); - } - } - } - return nu; - case 'number': - case 'string': - case 'boolean': - return value; - } - }(object, '$')); + +function crypto_verify_16(x, xi, y, yi) { + return vn(x,xi,y,yi,16); } -exports.decycleObject = decycleObject; -function safeJSONStringify(source) { - try { - return JSON.stringify(source); - } - catch (e) { - return JSON.stringify(decycleObject(source)); - } + +function crypto_verify_32(x, xi, y, yi) { + return vn(x,xi,y,yi,32); } -exports.safeJSONStringify = safeJSONStringify; +function core_salsa20(o, p, k, c) { + var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, + j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, + j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, + j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, + j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, + j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, + j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, + j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, + j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, + j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, + j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, + j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, + j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, + j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, + j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, + j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { + var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, + x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, + x15 = j15, u; -"use strict"; - -exports.__esModule = true; -var dependencies_1 = __webpack_require__(11); -var xhr_auth_1 = __webpack_require__(22); -var jsonp_auth_1 = __webpack_require__(25); -var script_request_1 = __webpack_require__(26); -var jsonp_request_1 = __webpack_require__(27); -var script_receiver_factory_1 = __webpack_require__(8); -var jsonp_timeline_1 = __webpack_require__(28); -var transports_1 = __webpack_require__(29); -var net_info_1 = __webpack_require__(33); -var default_strategy_1 = __webpack_require__(34); -var transport_connection_initializer_1 = __webpack_require__(54); -var http_1 = __webpack_require__(55); -var Runtime = { - nextAuthCallbackID: 1, - auth_callbacks: {}, - ScriptReceivers: script_receiver_factory_1.ScriptReceivers, - DependenciesReceivers: dependencies_1.DependenciesReceivers, - getDefaultStrategy: default_strategy_1["default"], - Transports: transports_1["default"], - transportConnectionInitializer: transport_connection_initializer_1["default"], - HTTPFactory: http_1["default"], - TimelineTransport: jsonp_timeline_1["default"], - getXHRAPI: function () { - return window.XMLHttpRequest; - }, - getWebSocketAPI: function () { - return window.WebSocket || window.MozWebSocket; - }, - setup: function (PusherClass) { - var _this = this; - window.Pusher = PusherClass; - var initializeOnDocumentBody = function () { - _this.onDocumentBody(PusherClass.ready); - }; - if (!window.JSON) { - dependencies_1.Dependencies.load("json2", {}, initializeOnDocumentBody); - } - else { - initializeOnDocumentBody(); - } - }, - getDocument: function () { - return document; - }, - getProtocol: function () { - return this.getDocument().location.protocol; - }, - getAuthorizers: function () { - return { ajax: xhr_auth_1["default"], jsonp: jsonp_auth_1["default"] }; - }, - onDocumentBody: function (callback) { - var _this = this; - if (document.body) { - callback(); - } - else { - setTimeout(function () { - _this.onDocumentBody(callback); - }, 0); - } - }, - createJSONPRequest: function (url, data) { - return new jsonp_request_1["default"](url, data); - }, - createScriptRequest: function (src) { - return new script_request_1["default"](src); - }, - getLocalStorage: function () { - try { - return window.localStorage; - } - catch (e) { - return undefined; - } - }, - createXHR: function () { - if (this.getXHRAPI()) { - return this.createXMLHttpRequest(); - } - else { - return this.createMicrosoftXHR(); - } - }, - createXMLHttpRequest: function () { - var Constructor = this.getXHRAPI(); - return new Constructor(); - }, - createMicrosoftXHR: function () { - return new ActiveXObject("Microsoft.XMLHTTP"); - }, - getNetwork: function () { - return net_info_1.Network; - }, - createWebSocket: function (url) { - var Constructor = this.getWebSocketAPI(); - return new Constructor(url); - }, - createSocketRequest: function (method, url) { - if (this.isXHRSupported()) { - return this.HTTPFactory.createXHR(method, url); - } - else if (this.isXDRSupported(url.indexOf("https:") === 0)) { - return this.HTTPFactory.createXDR(method, url); - } - else { - throw "Cross-origin HTTP requests are not supported"; - } - }, - isXHRSupported: function () { - var Constructor = this.getXHRAPI(); - return Boolean(Constructor) && (new Constructor()).withCredentials !== undefined; - }, - isXDRSupported: function (useTLS) { - var protocol = useTLS ? "https:" : "http:"; - var documentProtocol = this.getProtocol(); - return Boolean((window['XDomainRequest'])) && documentProtocol === protocol; - }, - addUnloadListener: function (listener) { - if (window.addEventListener !== undefined) { - window.addEventListener("unload", listener, false); - } - else if (window.attachEvent !== undefined) { - window.attachEvent("onunload", listener); - } - }, - removeUnloadListener: function (listener) { - if (window.addEventListener !== undefined) { - window.removeEventListener("unload", listener, false); - } - else if (window.detachEvent !== undefined) { - window.detachEvent("onunload", listener); - } - } -}; -exports["default"] = Runtime; + for (var i = 0; i < 20; i += 2) { + u = x0 + x12 | 0; + x4 ^= u<<7 | u>>>(32-7); + u = x4 + x0 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x4 | 0; + x12 ^= u<<13 | u>>>(32-13); + u = x12 + x8 | 0; + x0 ^= u<<18 | u>>>(32-18); + u = x5 + x1 | 0; + x9 ^= u<<7 | u>>>(32-7); + u = x9 + x5 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x9 | 0; + x1 ^= u<<13 | u>>>(32-13); + u = x1 + x13 | 0; + x5 ^= u<<18 | u>>>(32-18); -/***/ }), -/* 2 */ -/***/ (function(module, exports, __webpack_require__) { + u = x10 + x6 | 0; + x14 ^= u<<7 | u>>>(32-7); + u = x14 + x10 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x14 | 0; + x6 ^= u<<13 | u>>>(32-13); + u = x6 + x2 | 0; + x10 ^= u<<18 | u>>>(32-18); -"use strict"; + u = x15 + x11 | 0; + x3 ^= u<<7 | u>>>(32-7); + u = x3 + x15 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x3 | 0; + x11 ^= u<<13 | u>>>(32-13); + u = x11 + x7 | 0; + x15 ^= u<<18 | u>>>(32-18); -exports.__esModule = true; -var timers_1 = __webpack_require__(6); -var Util = { - now: function () { - if (Date.now) { - return Date.now(); - } - else { - return new Date().valueOf(); - } - }, - defer: function (callback) { - return new timers_1.OneOffTimer(0, callback); - }, - method: function (name) { - var args = []; - for (var _i = 1; _i < arguments.length; _i++) { - args[_i - 1] = arguments[_i]; - } - var boundArguments = Array.prototype.slice.call(arguments, 1); - return function (object) { - return object[name].apply(object, boundArguments.concat(arguments)); - }; - } -}; -exports["default"] = Util; + u = x0 + x3 | 0; + x1 ^= u<<7 | u>>>(32-7); + u = x1 + x0 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x1 | 0; + x3 ^= u<<13 | u>>>(32-13); + u = x3 + x2 | 0; + x0 ^= u<<18 | u>>>(32-18); + u = x5 + x4 | 0; + x6 ^= u<<7 | u>>>(32-7); + u = x6 + x5 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x6 | 0; + x4 ^= u<<13 | u>>>(32-13); + u = x4 + x7 | 0; + x5 ^= u<<18 | u>>>(32-18); -/***/ }), -/* 3 */ -/***/ (function(module, exports, __webpack_require__) { + u = x10 + x9 | 0; + x11 ^= u<<7 | u>>>(32-7); + u = x11 + x10 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x11 | 0; + x9 ^= u<<13 | u>>>(32-13); + u = x9 + x8 | 0; + x10 ^= u<<18 | u>>>(32-18); -"use strict"; + u = x15 + x14 | 0; + x12 ^= u<<7 | u>>>(32-7); + u = x12 + x15 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x12 | 0; + x14 ^= u<<13 | u>>>(32-13); + u = x14 + x13 | 0; + x15 ^= u<<18 | u>>>(32-18); + } + x0 = x0 + j0 | 0; + x1 = x1 + j1 | 0; + x2 = x2 + j2 | 0; + x3 = x3 + j3 | 0; + x4 = x4 + j4 | 0; + x5 = x5 + j5 | 0; + x6 = x6 + j6 | 0; + x7 = x7 + j7 | 0; + x8 = x8 + j8 | 0; + x9 = x9 + j9 | 0; + x10 = x10 + j10 | 0; + x11 = x11 + j11 | 0; + x12 = x12 + j12 | 0; + x13 = x13 + j13 | 0; + x14 = x14 + j14 | 0; + x15 = x15 + j15 | 0; -exports.__esModule = true; -var collections_1 = __webpack_require__(0); -var pusher_1 = __webpack_require__(13); -var Logger = { - debug: function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - if (!pusher_1["default"].log) { - return; - } - pusher_1["default"].log(collections_1.stringify.apply(this, arguments)); - }, - warn: function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - var message = collections_1.stringify.apply(this, arguments); - if (pusher_1["default"].log) { - pusher_1["default"].log(message); - } - else if (window.console) { - if (window.console.warn) { - window.console.warn(message); - } - else if (window.console.log) { - window.console.log(message); - } - } - } -}; -exports["default"] = Logger; + o[ 0] = x0 >>> 0 & 0xff; + o[ 1] = x0 >>> 8 & 0xff; + o[ 2] = x0 >>> 16 & 0xff; + o[ 3] = x0 >>> 24 & 0xff; + o[ 4] = x1 >>> 0 & 0xff; + o[ 5] = x1 >>> 8 & 0xff; + o[ 6] = x1 >>> 16 & 0xff; + o[ 7] = x1 >>> 24 & 0xff; -/***/ }), -/* 4 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Collections = __webpack_require__(0); -var callback_registry_1 = __webpack_require__(32); -var Dispatcher = (function () { - function Dispatcher(failThrough) { - this.callbacks = new callback_registry_1["default"](); - this.global_callbacks = []; - this.failThrough = failThrough; - } - Dispatcher.prototype.bind = function (eventName, callback, context) { - this.callbacks.add(eventName, callback, context); - return this; - }; - Dispatcher.prototype.bind_global = function (callback) { - this.global_callbacks.push(callback); - return this; - }; - Dispatcher.prototype.unbind = function (eventName, callback, context) { - this.callbacks.remove(eventName, callback, context); - return this; - }; - Dispatcher.prototype.unbind_global = function (callback) { - if (!callback) { - this.global_callbacks = []; - return this; - } - this.global_callbacks = Collections.filter(this.global_callbacks || [], function (c) { return c !== callback; }); - return this; - }; - Dispatcher.prototype.unbind_all = function () { - this.unbind(); - this.unbind_global(); - return this; - }; - Dispatcher.prototype.emit = function (eventName, data, metadata) { - for (var i = 0; i < this.global_callbacks.length; i++) { - this.global_callbacks[i](eventName, data); - } - var callbacks = this.callbacks.get(eventName); - var args = []; - if (metadata) { - args.push(data, metadata); - } - else if (data) { - args.push(data); - } - if (callbacks && callbacks.length > 0) { - for (var i = 0; i < callbacks.length; i++) { - callbacks[i].fn.apply(callbacks[i].context || window, args); - } - } - else if (this.failThrough) { - this.failThrough(eventName, data); - } - return this; - }; - return Dispatcher; -}()); -exports["default"] = Dispatcher; + o[ 8] = x2 >>> 0 & 0xff; + o[ 9] = x2 >>> 8 & 0xff; + o[10] = x2 >>> 16 & 0xff; + o[11] = x2 >>> 24 & 0xff; + o[12] = x3 >>> 0 & 0xff; + o[13] = x3 >>> 8 & 0xff; + o[14] = x3 >>> 16 & 0xff; + o[15] = x3 >>> 24 & 0xff; -/***/ }), -/* 5 */ -/***/ (function(module, exports, __webpack_require__) { + o[16] = x4 >>> 0 & 0xff; + o[17] = x4 >>> 8 & 0xff; + o[18] = x4 >>> 16 & 0xff; + o[19] = x4 >>> 24 & 0xff; -"use strict"; + o[20] = x5 >>> 0 & 0xff; + o[21] = x5 >>> 8 & 0xff; + o[22] = x5 >>> 16 & 0xff; + o[23] = x5 >>> 24 & 0xff; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var BadEventName = (function (_super) { - __extends(BadEventName, _super); - function BadEventName(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return BadEventName; -}(Error)); -exports.BadEventName = BadEventName; -var RequestTimedOut = (function (_super) { - __extends(RequestTimedOut, _super); - function RequestTimedOut(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return RequestTimedOut; -}(Error)); -exports.RequestTimedOut = RequestTimedOut; -var TransportPriorityTooLow = (function (_super) { - __extends(TransportPriorityTooLow, _super); - function TransportPriorityTooLow(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return TransportPriorityTooLow; -}(Error)); -exports.TransportPriorityTooLow = TransportPriorityTooLow; -var TransportClosed = (function (_super) { - __extends(TransportClosed, _super); - function TransportClosed(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return TransportClosed; -}(Error)); -exports.TransportClosed = TransportClosed; -var UnsupportedFeature = (function (_super) { - __extends(UnsupportedFeature, _super); - function UnsupportedFeature(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return UnsupportedFeature; -}(Error)); -exports.UnsupportedFeature = UnsupportedFeature; -var UnsupportedTransport = (function (_super) { - __extends(UnsupportedTransport, _super); - function UnsupportedTransport(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return UnsupportedTransport; -}(Error)); -exports.UnsupportedTransport = UnsupportedTransport; -var UnsupportedStrategy = (function (_super) { - __extends(UnsupportedStrategy, _super); - function UnsupportedStrategy(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return UnsupportedStrategy; -}(Error)); -exports.UnsupportedStrategy = UnsupportedStrategy; + o[24] = x6 >>> 0 & 0xff; + o[25] = x6 >>> 8 & 0xff; + o[26] = x6 >>> 16 & 0xff; + o[27] = x6 >>> 24 & 0xff; + o[28] = x7 >>> 0 & 0xff; + o[29] = x7 >>> 8 & 0xff; + o[30] = x7 >>> 16 & 0xff; + o[31] = x7 >>> 24 & 0xff; -/***/ }), -/* 6 */ -/***/ (function(module, exports, __webpack_require__) { + o[32] = x8 >>> 0 & 0xff; + o[33] = x8 >>> 8 & 0xff; + o[34] = x8 >>> 16 & 0xff; + o[35] = x8 >>> 24 & 0xff; -"use strict"; + o[36] = x9 >>> 0 & 0xff; + o[37] = x9 >>> 8 & 0xff; + o[38] = x9 >>> 16 & 0xff; + o[39] = x9 >>> 24 & 0xff; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var abstract_timer_1 = __webpack_require__(24); -function clearTimeout(timer) { - window.clearTimeout(timer); -} -function clearInterval(timer) { - window.clearInterval(timer); -} -var OneOffTimer = (function (_super) { - __extends(OneOffTimer, _super); - function OneOffTimer(delay, callback) { - return _super.call(this, setTimeout, clearTimeout, delay, function (timer) { - callback(); - return null; - }) || this; - } - return OneOffTimer; -}(abstract_timer_1["default"])); -exports.OneOffTimer = OneOffTimer; -var PeriodicTimer = (function (_super) { - __extends(PeriodicTimer, _super); - function PeriodicTimer(delay, callback) { - return _super.call(this, setInterval, clearInterval, delay, function (timer) { - callback(); - return timer; - }) || this; - } - return PeriodicTimer; -}(abstract_timer_1["default"])); -exports.PeriodicTimer = PeriodicTimer; + o[40] = x10 >>> 0 & 0xff; + o[41] = x10 >>> 8 & 0xff; + o[42] = x10 >>> 16 & 0xff; + o[43] = x10 >>> 24 & 0xff; + o[44] = x11 >>> 0 & 0xff; + o[45] = x11 >>> 8 & 0xff; + o[46] = x11 >>> 16 & 0xff; + o[47] = x11 >>> 24 & 0xff; -/***/ }), -/* 7 */ -/***/ (function(module, exports, __webpack_require__) { + o[48] = x12 >>> 0 & 0xff; + o[49] = x12 >>> 8 & 0xff; + o[50] = x12 >>> 16 & 0xff; + o[51] = x12 >>> 24 & 0xff; -"use strict"; + o[52] = x13 >>> 0 & 0xff; + o[53] = x13 >>> 8 & 0xff; + o[54] = x13 >>> 16 & 0xff; + o[55] = x13 >>> 24 & 0xff; -exports.__esModule = true; -var assistant_to_the_transport_manager_1 = __webpack_require__(36); -var handshake_1 = __webpack_require__(37); -var pusher_authorizer_1 = __webpack_require__(39); -var timeline_sender_1 = __webpack_require__(40); -var presence_channel_1 = __webpack_require__(41); -var private_channel_1 = __webpack_require__(12); -var encrypted_channel_1 = __webpack_require__(43); -var channel_1 = __webpack_require__(17); -var connection_manager_1 = __webpack_require__(47); -var channels_1 = __webpack_require__(48); -var Factory = { - createChannels: function () { - return new channels_1["default"](); - }, - createConnectionManager: function (key, options) { - return new connection_manager_1["default"](key, options); - }, - createChannel: function (name, pusher) { - return new channel_1["default"](name, pusher); - }, - createPrivateChannel: function (name, pusher) { - return new private_channel_1["default"](name, pusher); - }, - createPresenceChannel: function (name, pusher) { - return new presence_channel_1["default"](name, pusher); - }, - createEncryptedChannel: function (name, pusher) { - return new encrypted_channel_1["default"](name, pusher); - }, - createTimelineSender: function (timeline, options) { - return new timeline_sender_1["default"](timeline, options); - }, - createAuthorizer: function (channel, options) { - if (options.authorizer) { - return options.authorizer(channel, options); - } - return new pusher_authorizer_1["default"](channel, options); - }, - createHandshake: function (transport, callback) { - return new handshake_1["default"](transport, callback); - }, - createAssistantToTheTransportManager: function (manager, transport, options) { - return new assistant_to_the_transport_manager_1["default"](manager, transport, options); - } -}; -exports["default"] = Factory; + o[56] = x14 >>> 0 & 0xff; + o[57] = x14 >>> 8 & 0xff; + o[58] = x14 >>> 16 & 0xff; + o[59] = x14 >>> 24 & 0xff; + o[60] = x15 >>> 0 & 0xff; + o[61] = x15 >>> 8 & 0xff; + o[62] = x15 >>> 16 & 0xff; + o[63] = x15 >>> 24 & 0xff; +} -/***/ }), -/* 8 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +function core_hsalsa20(o,p,k,c) { + var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, + j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, + j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, + j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, + j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, + j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, + j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, + j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, + j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, + j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, + j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, + j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, + j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, + j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, + j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, + j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; -exports.__esModule = true; -var ScriptReceiverFactory = (function () { - function ScriptReceiverFactory(prefix, name) { - this.lastId = 0; - this.prefix = prefix; - this.name = name; - } - ScriptReceiverFactory.prototype.create = function (callback) { - this.lastId++; - var number = this.lastId; - var id = this.prefix + number; - var name = this.name + "[" + number + "]"; - var called = false; - var callbackWrapper = function () { - if (!called) { - callback.apply(null, arguments); - called = true; - } - }; - this[number] = callbackWrapper; - return { number: number, id: id, name: name, callback: callbackWrapper }; - }; - ScriptReceiverFactory.prototype.remove = function (receiver) { - delete this[receiver.number]; - }; - return ScriptReceiverFactory; -}()); -exports.ScriptReceiverFactory = ScriptReceiverFactory; -exports.ScriptReceivers = new ScriptReceiverFactory("_pusher_script_", "Pusher.ScriptReceivers"); + var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, + x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, + x15 = j15, u; + for (var i = 0; i < 20; i += 2) { + u = x0 + x12 | 0; + x4 ^= u<<7 | u>>>(32-7); + u = x4 + x0 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x4 | 0; + x12 ^= u<<13 | u>>>(32-13); + u = x12 + x8 | 0; + x0 ^= u<<18 | u>>>(32-18); -/***/ }), -/* 9 */ -/***/ (function(module, exports, __webpack_require__) { + u = x5 + x1 | 0; + x9 ^= u<<7 | u>>>(32-7); + u = x9 + x5 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x9 | 0; + x1 ^= u<<13 | u>>>(32-13); + u = x1 + x13 | 0; + x5 ^= u<<18 | u>>>(32-18); -"use strict"; + u = x10 + x6 | 0; + x14 ^= u<<7 | u>>>(32-7); + u = x14 + x10 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x14 | 0; + x6 ^= u<<13 | u>>>(32-13); + u = x6 + x2 | 0; + x10 ^= u<<18 | u>>>(32-18); -exports.__esModule = true; -var Defaults = { - VERSION: "5.0.1", - PROTOCOL: 7, - host: 'ws.pusherapp.com', - ws_port: 80, - wss_port: 443, - ws_path: '', - sockjs_host: 'sockjs.pusher.com', - sockjs_http_port: 80, - sockjs_https_port: 443, - sockjs_path: "/pusher", - stats_host: 'stats.pusher.com', - channel_auth_endpoint: '/pusher/auth', - channel_auth_transport: 'ajax', - activity_timeout: 120000, - pong_timeout: 30000, - unavailable_timeout: 10000, - cdn_http: "http://js.pusher.com", - cdn_https: "https://js.pusher.com", - dependency_suffix: "" -}; -exports["default"] = Defaults; + u = x15 + x11 | 0; + x3 ^= u<<7 | u>>>(32-7); + u = x3 + x15 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x3 | 0; + x11 ^= u<<13 | u>>>(32-13); + u = x11 + x7 | 0; + x15 ^= u<<18 | u>>>(32-18); + u = x0 + x3 | 0; + x1 ^= u<<7 | u>>>(32-7); + u = x1 + x0 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x1 | 0; + x3 ^= u<<13 | u>>>(32-13); + u = x3 + x2 | 0; + x0 ^= u<<18 | u>>>(32-18); -/***/ }), -/* 10 */ -/***/ (function(module, exports, __webpack_require__) { + u = x5 + x4 | 0; + x6 ^= u<<7 | u>>>(32-7); + u = x6 + x5 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x6 | 0; + x4 ^= u<<13 | u>>>(32-13); + u = x4 + x7 | 0; + x5 ^= u<<18 | u>>>(32-18); -"use strict"; + u = x10 + x9 | 0; + x11 ^= u<<7 | u>>>(32-7); + u = x11 + x10 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x11 | 0; + x9 ^= u<<13 | u>>>(32-13); + u = x9 + x8 | 0; + x10 ^= u<<18 | u>>>(32-18); -exports.__esModule = true; -var urlStore = { - baseUrl: "https://pusher.com", - urls: { - authenticationEndpoint: { - path: "/docs/authenticating_users", - }, - javascriptQuickStart: { - path: "/docs/javascript_quick_start" - }, - triggeringClientEvents: { - path: "/docs/client_api_guide/client_events#trigger-events" - } - } -}; -var buildLogSuffix = function (key) { - var urlPrefix = "See:"; - var urlObj = urlStore.urls[key]; - if (!urlObj) - return ""; - var url; - if (urlObj.fullUrl) { - url = urlObj.fullUrl; - } - else if (urlObj.path) { - url = urlStore.baseUrl + urlObj.path; - } - if (!url) - return ""; - return urlPrefix + " " + url; -}; -exports["default"] = { buildLogSuffix: buildLogSuffix }; + u = x15 + x14 | 0; + x12 ^= u<<7 | u>>>(32-7); + u = x12 + x15 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x12 | 0; + x14 ^= u<<13 | u>>>(32-13); + u = x14 + x13 | 0; + x15 ^= u<<18 | u>>>(32-18); + } + o[ 0] = x0 >>> 0 & 0xff; + o[ 1] = x0 >>> 8 & 0xff; + o[ 2] = x0 >>> 16 & 0xff; + o[ 3] = x0 >>> 24 & 0xff; -/***/ }), -/* 11 */ -/***/ (function(module, exports, __webpack_require__) { + o[ 4] = x5 >>> 0 & 0xff; + o[ 5] = x5 >>> 8 & 0xff; + o[ 6] = x5 >>> 16 & 0xff; + o[ 7] = x5 >>> 24 & 0xff; -"use strict"; + o[ 8] = x10 >>> 0 & 0xff; + o[ 9] = x10 >>> 8 & 0xff; + o[10] = x10 >>> 16 & 0xff; + o[11] = x10 >>> 24 & 0xff; -exports.__esModule = true; -var script_receiver_factory_1 = __webpack_require__(8); -var defaults_1 = __webpack_require__(9); -var dependency_loader_1 = __webpack_require__(21); -exports.DependenciesReceivers = new script_receiver_factory_1.ScriptReceiverFactory("_pusher_dependencies", "Pusher.DependenciesReceivers"); -exports.Dependencies = new dependency_loader_1["default"]({ - cdn_http: defaults_1["default"].cdn_http, - cdn_https: defaults_1["default"].cdn_https, - version: defaults_1["default"].VERSION, - suffix: defaults_1["default"].dependency_suffix, - receivers: exports.DependenciesReceivers -}); + o[12] = x15 >>> 0 & 0xff; + o[13] = x15 >>> 8 & 0xff; + o[14] = x15 >>> 16 & 0xff; + o[15] = x15 >>> 24 & 0xff; + o[16] = x6 >>> 0 & 0xff; + o[17] = x6 >>> 8 & 0xff; + o[18] = x6 >>> 16 & 0xff; + o[19] = x6 >>> 24 & 0xff; -/***/ }), -/* 12 */ -/***/ (function(module, exports, __webpack_require__) { + o[20] = x7 >>> 0 & 0xff; + o[21] = x7 >>> 8 & 0xff; + o[22] = x7 >>> 16 & 0xff; + o[23] = x7 >>> 24 & 0xff; -"use strict"; + o[24] = x8 >>> 0 & 0xff; + o[25] = x8 >>> 8 & 0xff; + o[26] = x8 >>> 16 & 0xff; + o[27] = x8 >>> 24 & 0xff; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var factory_1 = __webpack_require__(7); -var channel_1 = __webpack_require__(17); -var PrivateChannel = (function (_super) { - __extends(PrivateChannel, _super); - function PrivateChannel() { - return _super !== null && _super.apply(this, arguments) || this; - } - PrivateChannel.prototype.authorize = function (socketId, callback) { - var authorizer = factory_1["default"].createAuthorizer(this, this.pusher.config); - return authorizer.authorize(socketId, callback); - }; - return PrivateChannel; -}(channel_1["default"])); -exports["default"] = PrivateChannel; + o[28] = x9 >>> 0 & 0xff; + o[29] = x9 >>> 8 & 0xff; + o[30] = x9 >>> 16 & 0xff; + o[31] = x9 >>> 24 & 0xff; +} +function crypto_core_salsa20(out,inp,k,c) { + core_salsa20(out,inp,k,c); +} -/***/ }), -/* 13 */ -/***/ (function(module, exports, __webpack_require__) { +function crypto_core_hsalsa20(out,inp,k,c) { + core_hsalsa20(out,inp,k,c); +} -"use strict"; +var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]); + // "expand 32-byte k" -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var Collections = __webpack_require__(0); -var dispatcher_1 = __webpack_require__(4); -var timeline_1 = __webpack_require__(64); -var level_1 = __webpack_require__(19); -var strategy_builder_1 = __webpack_require__(65); -var timers_1 = __webpack_require__(6); -var defaults_1 = __webpack_require__(9); -var DefaultConfig = __webpack_require__(67); -var logger_1 = __webpack_require__(3); -var factory_1 = __webpack_require__(7); -var url_store_1 = __webpack_require__(10); -var Pusher = (function () { - function Pusher(app_key, options) { - var _this = this; - checkAppKey(app_key); - options = options || {}; - if (!options.cluster && !(options.wsHost || options.httpHost)) { - var suffix = url_store_1["default"].buildLogSuffix("javascriptQuickStart"); - logger_1["default"].warn("You should always specify a cluster when connecting. " + suffix); - } - this.key = app_key; - this.config = Collections.extend(DefaultConfig.getGlobalConfig(), options.cluster ? DefaultConfig.getClusterConfig(options.cluster) : {}, options); - this.channels = factory_1["default"].createChannels(); - this.global_emitter = new dispatcher_1["default"](); - this.sessionID = Math.floor(Math.random() * 1000000000); - this.timeline = new timeline_1["default"](this.key, this.sessionID, { - cluster: this.config.cluster, - features: Pusher.getClientFeatures(), - params: this.config.timelineParams || {}, - limit: 50, - level: level_1["default"].INFO, - version: defaults_1["default"].VERSION - }); - if (!this.config.disableStats) { - this.timelineSender = factory_1["default"].createTimelineSender(this.timeline, { - host: this.config.statsHost, - path: "/timeline/v2/" + runtime_1["default"].TimelineTransport.name - }); - } - var getStrategy = function (options) { - var config = Collections.extend({}, _this.config, options); - return runtime_1["default"].getDefaultStrategy(config, strategy_builder_1.defineTransport); - }; - this.connection = factory_1["default"].createConnectionManager(this.key, Collections.extend({ getStrategy: getStrategy, - timeline: this.timeline, - activityTimeout: this.config.activity_timeout, - pongTimeout: this.config.pong_timeout, - unavailableTimeout: this.config.unavailable_timeout - }, this.config, { useTLS: this.shouldUseTLS() })); - this.connection.bind('connected', function () { - _this.subscribeAll(); - if (_this.timelineSender) { - _this.timelineSender.send(_this.connection.isUsingTLS()); - } - }); - this.connection.bind('message', function (event) { - var eventName = event.event; - var internal = (eventName.indexOf('pusher_internal:') === 0); - if (event.channel) { - var channel = _this.channel(event.channel); - if (channel) { - channel.handleEvent(event); - } - } - if (!internal) { - _this.global_emitter.emit(event.event, event.data); - } - }); - this.connection.bind('connecting', function () { - _this.channels.disconnect(); - }); - this.connection.bind('disconnected', function () { - _this.channels.disconnect(); - }); - this.connection.bind('error', function (err) { - logger_1["default"].warn('Error', err); - }); - Pusher.instances.push(this); - this.timeline.info({ instances: Pusher.instances.length }); - if (Pusher.isReady) { - this.connect(); - } - } - Pusher.ready = function () { - Pusher.isReady = true; - for (var i = 0, l = Pusher.instances.length; i < l; i++) { - Pusher.instances[i].connect(); - } - }; - Pusher.log = function (message) { - if (Pusher.logToConsole && window.console && window.console.log) { - window.console.log(message); - } - }; - Pusher.getClientFeatures = function () { - return Collections.keys(Collections.filterObject({ "ws": runtime_1["default"].Transports.ws }, function (t) { return t.isSupported({}); })); - }; - Pusher.prototype.channel = function (name) { - return this.channels.find(name); - }; - Pusher.prototype.allChannels = function () { - return this.channels.all(); - }; - Pusher.prototype.connect = function () { - this.connection.connect(); - if (this.timelineSender) { - if (!this.timelineSenderTimer) { - var usingTLS = this.connection.isUsingTLS(); - var timelineSender = this.timelineSender; - this.timelineSenderTimer = new timers_1.PeriodicTimer(60000, function () { - timelineSender.send(usingTLS); - }); - } - } - }; - Pusher.prototype.disconnect = function () { - this.connection.disconnect(); - if (this.timelineSenderTimer) { - this.timelineSenderTimer.ensureAborted(); - this.timelineSenderTimer = null; - } - }; - Pusher.prototype.bind = function (event_name, callback, context) { - this.global_emitter.bind(event_name, callback, context); - return this; - }; - Pusher.prototype.unbind = function (event_name, callback, context) { - this.global_emitter.unbind(event_name, callback, context); - return this; - }; - Pusher.prototype.bind_global = function (callback) { - this.global_emitter.bind_global(callback); - return this; - }; - Pusher.prototype.unbind_global = function (callback) { - this.global_emitter.unbind_global(callback); - return this; - }; - Pusher.prototype.unbind_all = function (callback) { - this.global_emitter.unbind_all(); - return this; - }; - Pusher.prototype.subscribeAll = function () { - var channelName; - for (channelName in this.channels.channels) { - if (this.channels.channels.hasOwnProperty(channelName)) { - this.subscribe(channelName); - } - } - }; - Pusher.prototype.subscribe = function (channel_name) { - var channel = this.channels.add(channel_name, this); - if (channel.subscriptionPending && channel.subscriptionCancelled) { - channel.reinstateSubscription(); - } - else if (!channel.subscriptionPending && this.connection.state === "connected") { - channel.subscribe(); - } - return channel; - }; - Pusher.prototype.unsubscribe = function (channel_name) { - var channel = this.channels.find(channel_name); - if (channel && channel.subscriptionPending) { - channel.cancelSubscription(); - } - else { - channel = this.channels.remove(channel_name); - if (channel && this.connection.state === "connected") { - channel.unsubscribe(); - } - } - }; - Pusher.prototype.send_event = function (event_name, data, channel) { - return this.connection.send_event(event_name, data, channel); - }; - Pusher.prototype.shouldUseTLS = function () { - if (runtime_1["default"].getProtocol() === "https:") { - return true; - } - else if (this.config.forceTLS === true) { - return true; - } - else { - return Boolean(this.config.encrypted); - } - }; - Pusher.instances = []; - Pusher.isReady = false; - Pusher.logToConsole = false; - Pusher.Runtime = runtime_1["default"]; - Pusher.ScriptReceivers = runtime_1["default"].ScriptReceivers; - Pusher.DependenciesReceivers = runtime_1["default"].DependenciesReceivers; - Pusher.auth_callbacks = runtime_1["default"].auth_callbacks; - return Pusher; -}()); -exports["default"] = Pusher; -function checkAppKey(key) { - if (key === null || key === undefined) { - throw "You must pass your app key when you instantiate Pusher."; +function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) { + var z = new Uint8Array(16), x = new Uint8Array(64); + var u, i; + for (i = 0; i < 16; i++) z[i] = 0; + for (i = 0; i < 8; i++) z[i] = n[i]; + while (b >= 64) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i]; + u = 1; + for (i = 8; i < 16; i++) { + u = u + (z[i] & 0xff) | 0; + z[i] = u & 0xff; + u >>>= 8; } + b -= 64; + cpos += 64; + mpos += 64; + } + if (b > 0) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i]; + } + return 0; } -runtime_1["default"].setup(Pusher); +function crypto_stream_salsa20(c,cpos,b,n,k) { + var z = new Uint8Array(16), x = new Uint8Array(64); + var u, i; + for (i = 0; i < 16; i++) z[i] = 0; + for (i = 0; i < 8; i++) z[i] = n[i]; + while (b >= 64) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < 64; i++) c[cpos+i] = x[i]; + u = 1; + for (i = 8; i < 16; i++) { + u = u + (z[i] & 0xff) | 0; + z[i] = u & 0xff; + u >>>= 8; + } + b -= 64; + cpos += 64; + } + if (b > 0) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < b; i++) c[cpos+i] = x[i]; + } + return 0; +} -/***/ }), -/* 14 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var defaults_1 = __webpack_require__(9); -function getGenericURL(baseScheme, params, path) { - var scheme = baseScheme + (params.useTLS ? "s" : ""); - var host = params.useTLS ? params.hostTLS : params.hostNonTLS; - return scheme + "://" + host + path; +function crypto_stream(c,cpos,d,n,k) { + var s = new Uint8Array(32); + crypto_core_hsalsa20(s,n,k,sigma); + var sn = new Uint8Array(8); + for (var i = 0; i < 8; i++) sn[i] = n[i+16]; + return crypto_stream_salsa20(c,cpos,d,sn,s); } -function getGenericPath(key, queryString) { - var path = "/app/" + key; - var query = "?protocol=" + defaults_1["default"].PROTOCOL + - "&client=js" + - "&version=" + defaults_1["default"].VERSION + - (queryString ? ("&" + queryString) : ""); - return path + query; + +function crypto_stream_xor(c,cpos,m,mpos,d,n,k) { + var s = new Uint8Array(32); + crypto_core_hsalsa20(s,n,k,sigma); + var sn = new Uint8Array(8); + for (var i = 0; i < 8; i++) sn[i] = n[i+16]; + return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s); } -exports.ws = { - getInitial: function (key, params) { - var path = (params.httpPath || "") + getGenericPath(key, "flash=false"); - return getGenericURL("ws", params, path); - } -}; -exports.http = { - getInitial: function (key, params) { - var path = (params.httpPath || "/pusher") + getGenericPath(key); - return getGenericURL("http", params, path); - } -}; -exports.sockjs = { - getInitial: function (key, params) { - return getGenericURL("http", params, params.httpPath || "/pusher"); - }, - getPath: function (key, params) { - return getGenericPath(key); - } -}; +/* +* Port of Andrew Moon's Poly1305-donna-16. Public domain. +* https://github.com/floodyberry/poly1305-donna +*/ -/***/ }), -/* 15 */ -/***/ (function(module, exports, __webpack_require__) { +var poly1305 = function(key) { + this.buffer = new Uint8Array(16); + this.r = new Uint16Array(10); + this.h = new Uint16Array(10); + this.pad = new Uint16Array(8); + this.leftover = 0; + this.fin = 0; -"use strict"; - -exports.__esModule = true; -var transport_connection_1 = __webpack_require__(31); -var Transport = (function () { - function Transport(hooks) { - this.hooks = hooks; - } - Transport.prototype.isSupported = function (environment) { - return this.hooks.isSupported(environment); - }; - Transport.prototype.createConnection = function (name, priority, key, options) { - return new transport_connection_1["default"](this.hooks, name, priority, key, options); - }; - return Transport; -}()); -exports["default"] = Transport; + var t0, t1, t2, t3, t4, t5, t6, t7; + t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff; + t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff; + t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03; + t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff; + t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff; + this.r[5] = ((t4 >>> 1)) & 0x1ffe; + t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff; + t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81; + t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff; + this.r[9] = ((t7 >>> 5)) & 0x007f; -/***/ }), -/* 16 */ -/***/ (function(module, exports, __webpack_require__) { + this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8; + this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8; + this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8; + this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8; + this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8; + this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8; + this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8; + this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8; +}; -"use strict"; +poly1305.prototype.blocks = function(m, mpos, bytes) { + var hibit = this.fin ? 0 : (1 << 11); + var t0, t1, t2, t3, t4, t5, t6, t7, c; + var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9; -exports.__esModule = true; -exports.decodeMessage = function (messageEvent) { - try { - var messageData = JSON.parse(messageEvent.data); - var pusherEventData = messageData.data; - if (typeof pusherEventData === 'string') { - try { - pusherEventData = JSON.parse(messageData.data); - } - catch (e) { } - } - var pusherEvent = { - event: messageData.event, - channel: messageData.channel, - data: pusherEventData, - }; - if (messageData.user_id) { - pusherEvent.user_id = messageData.user_id; - } - return pusherEvent; - } - catch (e) { - throw { type: 'MessageParseError', error: e, data: messageEvent.data }; - } -}; -exports.encodeMessage = function (event) { - return JSON.stringify(event); -}; -exports.processHandshake = function (messageEvent) { - var message = exports.decodeMessage(messageEvent); - if (message.event === "pusher:connection_established") { - if (!message.data.activity_timeout) { - throw "No activity timeout specified in handshake"; - } - return { - action: "connected", - id: message.data.socket_id, - activityTimeout: message.data.activity_timeout * 1000 - }; - } - else if (message.event === "pusher:error") { - return { - action: this.getCloseAction(message.data), - error: this.getCloseError(message.data) - }; - } - else { - throw "Invalid handshake"; - } -}; -exports.getCloseAction = function (closeEvent) { - if (closeEvent.code < 4000) { - if (closeEvent.code >= 1002 && closeEvent.code <= 1004) { - return "backoff"; - } - else { - return null; - } - } - else if (closeEvent.code === 4000) { - return "tls_only"; - } - else if (closeEvent.code < 4100) { - return "refused"; - } - else if (closeEvent.code < 4200) { - return "backoff"; - } - else if (closeEvent.code < 4300) { - return "retry"; - } - else { - return "refused"; - } -}; -exports.getCloseError = function (closeEvent) { - if (closeEvent.code !== 1000 && closeEvent.code !== 1001) { - return { - type: 'PusherError', - data: { - code: closeEvent.code, - message: closeEvent.reason || closeEvent.message - } - }; - } - else { - return null; - } -}; + var h0 = this.h[0], + h1 = this.h[1], + h2 = this.h[2], + h3 = this.h[3], + h4 = this.h[4], + h5 = this.h[5], + h6 = this.h[6], + h7 = this.h[7], + h8 = this.h[8], + h9 = this.h[9]; + var r0 = this.r[0], + r1 = this.r[1], + r2 = this.r[2], + r3 = this.r[3], + r4 = this.r[4], + r5 = this.r[5], + r6 = this.r[6], + r7 = this.r[7], + r8 = this.r[8], + r9 = this.r[9]; -/***/ }), -/* 17 */ -/***/ (function(module, exports, __webpack_require__) { + while (bytes >= 16) { + t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff; + t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff; + t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff; + t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff; + t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff; + h5 += ((t4 >>> 1)) & 0x1fff; + t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff; + t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff; + t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff; + h9 += ((t7 >>> 5)) | hibit; -"use strict"; + c = 0; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var dispatcher_1 = __webpack_require__(4); -var Errors = __webpack_require__(5); -var logger_1 = __webpack_require__(3); -var url_store_1 = __webpack_require__(10); -var Channel = (function (_super) { - __extends(Channel, _super); - function Channel(name, pusher) { - var _this = _super.call(this, function (event, data) { - logger_1["default"].debug('No callbacks on ' + name + ' for ' + event); - }) || this; - _this.name = name; - _this.pusher = pusher; - _this.subscribed = false; - _this.subscriptionPending = false; - _this.subscriptionCancelled = false; - return _this; - } - Channel.prototype.authorize = function (socketId, callback) { - return callback(false, {}); - }; - Channel.prototype.trigger = function (event, data) { - if (event.indexOf("client-") !== 0) { - throw new Errors.BadEventName("Event '" + event + "' does not start with 'client-'"); - } - if (!this.subscribed) { - var suffix = url_store_1["default"].buildLogSuffix("triggeringClientEvents"); - logger_1["default"].warn("Client event triggered before channel 'subscription_succeeded' event . " + suffix); - } - return this.pusher.send_event(event, data, this.name); - }; - Channel.prototype.disconnect = function () { - this.subscribed = false; - this.subscriptionPending = false; - }; - Channel.prototype.handleEvent = function (event) { - var eventName = event.event; - var data = event.data; - if (eventName === "pusher_internal:subscription_succeeded") { - this.handleSubscriptionSucceededEvent(event); - } - else if (eventName.indexOf("pusher_internal:") !== 0) { - var metadata = {}; - this.emit(eventName, data, metadata); - } - }; - Channel.prototype.handleSubscriptionSucceededEvent = function (event) { - this.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } - else { - this.emit("pusher:subscription_succeeded", event.data); - } - }; - Channel.prototype.subscribe = function () { - var _this = this; - if (this.subscribed) { - return; - } - this.subscriptionPending = true; - this.subscriptionCancelled = false; - this.authorize(this.pusher.connection.socket_id, function (error, data) { - if (error) { - _this.emit('pusher:subscription_error', data); - } - else { - _this.pusher.send_event('pusher:subscribe', { - auth: data.auth, - channel_data: data.channel_data, - channel: _this.name - }); - } - }); - }; - Channel.prototype.unsubscribe = function () { - this.subscribed = false; - this.pusher.send_event('pusher:unsubscribe', { - channel: this.name - }); - }; - Channel.prototype.cancelSubscription = function () { - this.subscriptionCancelled = true; - }; - Channel.prototype.reinstateSubscription = function () { - this.subscriptionCancelled = false; - }; - return Channel; -}(dispatcher_1["default"])); -exports["default"] = Channel; + d0 = c; + d0 += h0 * r0; + d0 += h1 * (5 * r9); + d0 += h2 * (5 * r8); + d0 += h3 * (5 * r7); + d0 += h4 * (5 * r6); + c = (d0 >>> 13); d0 &= 0x1fff; + d0 += h5 * (5 * r5); + d0 += h6 * (5 * r4); + d0 += h7 * (5 * r3); + d0 += h8 * (5 * r2); + d0 += h9 * (5 * r1); + c += (d0 >>> 13); d0 &= 0x1fff; + d1 = c; + d1 += h0 * r1; + d1 += h1 * r0; + d1 += h2 * (5 * r9); + d1 += h3 * (5 * r8); + d1 += h4 * (5 * r7); + c = (d1 >>> 13); d1 &= 0x1fff; + d1 += h5 * (5 * r6); + d1 += h6 * (5 * r5); + d1 += h7 * (5 * r4); + d1 += h8 * (5 * r3); + d1 += h9 * (5 * r2); + c += (d1 >>> 13); d1 &= 0x1fff; -/***/ }), -/* 18 */ -/***/ (function(module, exports, __webpack_require__) { + d2 = c; + d2 += h0 * r2; + d2 += h1 * r1; + d2 += h2 * r0; + d2 += h3 * (5 * r9); + d2 += h4 * (5 * r8); + c = (d2 >>> 13); d2 &= 0x1fff; + d2 += h5 * (5 * r7); + d2 += h6 * (5 * r6); + d2 += h7 * (5 * r5); + d2 += h8 * (5 * r4); + d2 += h9 * (5 * r3); + c += (d2 >>> 13); d2 &= 0x1fff; -"use strict"; + d3 = c; + d3 += h0 * r3; + d3 += h1 * r2; + d3 += h2 * r1; + d3 += h3 * r0; + d3 += h4 * (5 * r9); + c = (d3 >>> 13); d3 &= 0x1fff; + d3 += h5 * (5 * r8); + d3 += h6 * (5 * r7); + d3 += h7 * (5 * r6); + d3 += h8 * (5 * r5); + d3 += h9 * (5 * r4); + c += (d3 >>> 13); d3 &= 0x1fff; -exports.__esModule = true; -var Collections = __webpack_require__(0); -var util_1 = __webpack_require__(2); -var timers_1 = __webpack_require__(6); -var SequentialStrategy = (function () { - function SequentialStrategy(strategies, options) { - this.strategies = strategies; - this.loop = Boolean(options.loop); - this.failFast = Boolean(options.failFast); - this.timeout = options.timeout; - this.timeoutLimit = options.timeoutLimit; - } - SequentialStrategy.prototype.isSupported = function () { - return Collections.any(this.strategies, util_1["default"].method("isSupported")); - }; - SequentialStrategy.prototype.connect = function (minPriority, callback) { - var _this = this; - var strategies = this.strategies; - var current = 0; - var timeout = this.timeout; - var runner = null; - var tryNextStrategy = function (error, handshake) { - if (handshake) { - callback(null, handshake); - } - else { - current = current + 1; - if (_this.loop) { - current = current % strategies.length; - } - if (current < strategies.length) { - if (timeout) { - timeout = timeout * 2; - if (_this.timeoutLimit) { - timeout = Math.min(timeout, _this.timeoutLimit); - } - } - runner = _this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: _this.failFast }, tryNextStrategy); - } - else { - callback(true); - } - } - }; - runner = this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: this.failFast }, tryNextStrategy); - return { - abort: function () { - runner.abort(); - }, - forceMinPriority: function (p) { - minPriority = p; - if (runner) { - runner.forceMinPriority(p); - } - } - }; - }; - SequentialStrategy.prototype.tryStrategy = function (strategy, minPriority, options, callback) { - var timer = null; - var runner = null; - if (options.timeout > 0) { - timer = new timers_1.OneOffTimer(options.timeout, function () { - runner.abort(); - callback(true); - }); - } - runner = strategy.connect(minPriority, function (error, handshake) { - if (error && timer && timer.isRunning() && !options.failFast) { - return; - } - if (timer) { - timer.ensureAborted(); - } - callback(error, handshake); - }); - return { - abort: function () { - if (timer) { - timer.ensureAborted(); - } - runner.abort(); - }, - forceMinPriority: function (p) { - runner.forceMinPriority(p); - } - }; - }; - return SequentialStrategy; -}()); -exports["default"] = SequentialStrategy; + d4 = c; + d4 += h0 * r4; + d4 += h1 * r3; + d4 += h2 * r2; + d4 += h3 * r1; + d4 += h4 * r0; + c = (d4 >>> 13); d4 &= 0x1fff; + d4 += h5 * (5 * r9); + d4 += h6 * (5 * r8); + d4 += h7 * (5 * r7); + d4 += h8 * (5 * r6); + d4 += h9 * (5 * r5); + c += (d4 >>> 13); d4 &= 0x1fff; + d5 = c; + d5 += h0 * r5; + d5 += h1 * r4; + d5 += h2 * r3; + d5 += h3 * r2; + d5 += h4 * r1; + c = (d5 >>> 13); d5 &= 0x1fff; + d5 += h5 * r0; + d5 += h6 * (5 * r9); + d5 += h7 * (5 * r8); + d5 += h8 * (5 * r7); + d5 += h9 * (5 * r6); + c += (d5 >>> 13); d5 &= 0x1fff; -/***/ }), -/* 19 */ -/***/ (function(module, exports, __webpack_require__) { + d6 = c; + d6 += h0 * r6; + d6 += h1 * r5; + d6 += h2 * r4; + d6 += h3 * r3; + d6 += h4 * r2; + c = (d6 >>> 13); d6 &= 0x1fff; + d6 += h5 * r1; + d6 += h6 * r0; + d6 += h7 * (5 * r9); + d6 += h8 * (5 * r8); + d6 += h9 * (5 * r7); + c += (d6 >>> 13); d6 &= 0x1fff; -"use strict"; + d7 = c; + d7 += h0 * r7; + d7 += h1 * r6; + d7 += h2 * r5; + d7 += h3 * r4; + d7 += h4 * r3; + c = (d7 >>> 13); d7 &= 0x1fff; + d7 += h5 * r2; + d7 += h6 * r1; + d7 += h7 * r0; + d7 += h8 * (5 * r9); + d7 += h9 * (5 * r8); + c += (d7 >>> 13); d7 &= 0x1fff; -exports.__esModule = true; -var TimelineLevel; -(function (TimelineLevel) { - TimelineLevel[TimelineLevel["ERROR"] = 3] = "ERROR"; - TimelineLevel[TimelineLevel["INFO"] = 6] = "INFO"; - TimelineLevel[TimelineLevel["DEBUG"] = 7] = "DEBUG"; -})(TimelineLevel || (TimelineLevel = {})); -exports["default"] = TimelineLevel; + d8 = c; + d8 += h0 * r8; + d8 += h1 * r7; + d8 += h2 * r6; + d8 += h3 * r5; + d8 += h4 * r4; + c = (d8 >>> 13); d8 &= 0x1fff; + d8 += h5 * r3; + d8 += h6 * r2; + d8 += h7 * r1; + d8 += h8 * r0; + d8 += h9 * (5 * r9); + c += (d8 >>> 13); d8 &= 0x1fff; + d9 = c; + d9 += h0 * r9; + d9 += h1 * r8; + d9 += h2 * r7; + d9 += h3 * r6; + d9 += h4 * r5; + c = (d9 >>> 13); d9 &= 0x1fff; + d9 += h5 * r4; + d9 += h6 * r3; + d9 += h7 * r2; + d9 += h8 * r1; + d9 += h9 * r0; + c += (d9 >>> 13); d9 &= 0x1fff; -/***/ }), -/* 20 */ -/***/ (function(module, exports, __webpack_require__) { + c = (((c << 2) + c)) | 0; + c = (c + d0) | 0; + d0 = c & 0x1fff; + c = (c >>> 13); + d1 += c; -"use strict"; + h0 = d0; + h1 = d1; + h2 = d2; + h3 = d3; + h4 = d4; + h5 = d5; + h6 = d6; + h7 = d7; + h8 = d8; + h9 = d9; -exports.__esModule = true; -var pusher_1 = __webpack_require__(13); -module.exports = pusher_1["default"]; + mpos += 16; + bytes -= 16; + } + this.h[0] = h0; + this.h[1] = h1; + this.h[2] = h2; + this.h[3] = h3; + this.h[4] = h4; + this.h[5] = h5; + this.h[6] = h6; + this.h[7] = h7; + this.h[8] = h8; + this.h[9] = h9; +}; +poly1305.prototype.finish = function(mac, macpos) { + var g = new Uint16Array(10); + var c, mask, f, i; -/***/ }), -/* 21 */ -/***/ (function(module, exports, __webpack_require__) { + if (this.leftover) { + i = this.leftover; + this.buffer[i++] = 1; + for (; i < 16; i++) this.buffer[i] = 0; + this.fin = 1; + this.blocks(this.buffer, 0, 16); + } -"use strict"; + c = this.h[1] >>> 13; + this.h[1] &= 0x1fff; + for (i = 2; i < 10; i++) { + this.h[i] += c; + c = this.h[i] >>> 13; + this.h[i] &= 0x1fff; + } + this.h[0] += (c * 5); + c = this.h[0] >>> 13; + this.h[0] &= 0x1fff; + this.h[1] += c; + c = this.h[1] >>> 13; + this.h[1] &= 0x1fff; + this.h[2] += c; -exports.__esModule = true; -var script_receiver_factory_1 = __webpack_require__(8); -var runtime_1 = __webpack_require__(1); -var DependencyLoader = (function () { - function DependencyLoader(options) { - this.options = options; - this.receivers = options.receivers || script_receiver_factory_1.ScriptReceivers; - this.loading = {}; - } - DependencyLoader.prototype.load = function (name, options, callback) { - var self = this; - if (self.loading[name] && self.loading[name].length > 0) { - self.loading[name].push(callback); - } - else { - self.loading[name] = [callback]; - var request = runtime_1["default"].createScriptRequest(self.getPath(name, options)); - var receiver = self.receivers.create(function (error) { - self.receivers.remove(receiver); - if (self.loading[name]) { - var callbacks = self.loading[name]; - delete self.loading[name]; - var successCallback = function (wasSuccessful) { - if (!wasSuccessful) { - request.cleanup(); - } - }; - for (var i = 0; i < callbacks.length; i++) { - callbacks[i](error, successCallback); - } - } - }); - request.send(receiver); - } - }; - DependencyLoader.prototype.getRoot = function (options) { - var cdn; - var protocol = runtime_1["default"].getDocument().location.protocol; - if ((options && options.useTLS) || protocol === "https:") { - cdn = this.options.cdn_https; - } - else { - cdn = this.options.cdn_http; - } - return cdn.replace(/\/*$/, "") + "/" + this.options.version; - }; - DependencyLoader.prototype.getPath = function (name, options) { - return this.getRoot(options) + '/' + name + this.options.suffix + '.js'; - }; - ; - return DependencyLoader; -}()); -exports["default"] = DependencyLoader; + g[0] = this.h[0] + 5; + c = g[0] >>> 13; + g[0] &= 0x1fff; + for (i = 1; i < 10; i++) { + g[i] = this.h[i] + c; + c = g[i] >>> 13; + g[i] &= 0x1fff; + } + g[9] -= (1 << 13); + mask = (c ^ 1) - 1; + for (i = 0; i < 10; i++) g[i] &= mask; + mask = ~mask; + for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]; -/***/ }), -/* 22 */ -/***/ (function(module, exports, __webpack_require__) { + this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff; + this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff; + this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff; + this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff; + this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff; + this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff; + this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff; + this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff; -"use strict"; + f = this.h[0] + this.pad[0]; + this.h[0] = f & 0xffff; + for (i = 1; i < 8; i++) { + f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0; + this.h[i] = f & 0xffff; + } -exports.__esModule = true; -var logger_1 = __webpack_require__(3); -var runtime_1 = __webpack_require__(1); -var url_store_1 = __webpack_require__(10); -var ajax = function (context, socketId, callback) { - var self = this, xhr; - xhr = runtime_1["default"].createXHR(); - xhr.open("POST", self.options.authEndpoint, true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - for (var headerName in this.authOptions.headers) { - xhr.setRequestHeader(headerName, this.authOptions.headers[headerName]); - } - xhr.onreadystatechange = function () { - if (xhr.readyState === 4) { - if (xhr.status === 200) { - var data, parsed = false; - try { - data = JSON.parse(xhr.responseText); - parsed = true; - } - catch (e) { - callback(true, 'JSON returned from webapp was invalid, yet status code was 200. Data was: ' + xhr.responseText); - } - if (parsed) { - callback(false, data); - } - } - else { - var suffix = url_store_1["default"].buildLogSuffix("authenticationEndpoint"); - logger_1["default"].warn("Couldn't retrieve authentication info. " + xhr.status + - ("Clients must be authenticated to join private or presence channels. " + suffix)); - callback(true, xhr.status); - } - } - }; - xhr.send(this.composeQuery(socketId)); - return xhr; + mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff; + mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff; + mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff; + mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff; + mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff; + mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff; + mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff; + mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff; + mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff; + mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff; + mac[macpos+10] = (this.h[5] >>> 0) & 0xff; + mac[macpos+11] = (this.h[5] >>> 8) & 0xff; + mac[macpos+12] = (this.h[6] >>> 0) & 0xff; + mac[macpos+13] = (this.h[6] >>> 8) & 0xff; + mac[macpos+14] = (this.h[7] >>> 0) & 0xff; + mac[macpos+15] = (this.h[7] >>> 8) & 0xff; }; -exports["default"] = ajax; +poly1305.prototype.update = function(m, mpos, bytes) { + var i, want; -/***/ }), -/* 23 */ -/***/ (function(module, exports, __webpack_require__) { + if (this.leftover) { + want = (16 - this.leftover); + if (want > bytes) + want = bytes; + for (i = 0; i < want; i++) + this.buffer[this.leftover + i] = m[mpos+i]; + bytes -= want; + mpos += want; + this.leftover += want; + if (this.leftover < 16) + return; + this.blocks(this.buffer, 0, 16); + this.leftover = 0; + } -"use strict"; + if (bytes >= 16) { + want = bytes - (bytes % 16); + this.blocks(m, mpos, want); + mpos += want; + bytes -= want; + } -exports.__esModule = true; -function encode(s) { - return btoa(utob(s)); -} -exports["default"] = encode; -var fromCharCode = String.fromCharCode; -var b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; -var b64tab = {}; -for (var i = 0, l = b64chars.length; i < l; i++) { - b64tab[b64chars.charAt(i)] = i; -} -var cb_utob = function (c) { - var cc = c.charCodeAt(0); - return cc < 0x80 ? c - : cc < 0x800 ? fromCharCode(0xc0 | (cc >>> 6)) + - fromCharCode(0x80 | (cc & 0x3f)) - : fromCharCode(0xe0 | ((cc >>> 12) & 0x0f)) + - fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) + - fromCharCode(0x80 | (cc & 0x3f)); -}; -var utob = function (u) { - return u.replace(/[^\x00-\x7F]/g, cb_utob); -}; -var cb_encode = function (ccc) { - var padlen = [0, 2, 1][ccc.length % 3]; - var ord = ccc.charCodeAt(0) << 16 - | ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8) - | ((ccc.length > 2 ? ccc.charCodeAt(2) : 0)); - var chars = [ - b64chars.charAt(ord >>> 18), - b64chars.charAt((ord >>> 12) & 63), - padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63), - padlen >= 1 ? '=' : b64chars.charAt(ord & 63) - ]; - return chars.join(''); -}; -var btoa = window.btoa || function (b) { - return b.replace(/[\s\S]{1,3}/g, cb_encode); + if (bytes) { + for (i = 0; i < bytes; i++) + this.buffer[this.leftover + i] = m[mpos+i]; + this.leftover += bytes; + } }; +function crypto_onetimeauth(out, outpos, m, mpos, n, k) { + var s = new poly1305(k); + s.update(m, mpos, n); + s.finish(out, outpos); + return 0; +} -/***/ }), -/* 24 */ -/***/ (function(module, exports, __webpack_require__) { +function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) { + var x = new Uint8Array(16); + crypto_onetimeauth(x,0,m,mpos,n,k); + return crypto_verify_16(h,hpos,x,0); +} -"use strict"; +function crypto_secretbox(c,m,d,n,k) { + var i; + if (d < 32) return -1; + crypto_stream_xor(c,0,m,0,d,n,k); + crypto_onetimeauth(c, 16, c, 32, d - 32, c); + for (i = 0; i < 16; i++) c[i] = 0; + return 0; +} -exports.__esModule = true; -var Timer = (function () { - function Timer(set, clear, delay, callback) { - var _this = this; - this.clear = clear; - this.timer = set(function () { - if (_this.timer) { - _this.timer = callback(_this.timer); - } - }, delay); - } - Timer.prototype.isRunning = function () { - return this.timer !== null; - }; - Timer.prototype.ensureAborted = function () { - if (this.timer) { - this.clear(this.timer); - this.timer = null; - } - }; - return Timer; -}()); -exports["default"] = Timer; +function crypto_secretbox_open(m,c,d,n,k) { + var i; + var x = new Uint8Array(32); + if (d < 32) return -1; + crypto_stream(x,0,32,n,k); + if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1; + crypto_stream_xor(m,0,c,0,d,n,k); + for (i = 0; i < 32; i++) m[i] = 0; + return 0; +} +function set25519(r, a) { + var i; + for (i = 0; i < 16; i++) r[i] = a[i]|0; +} -/***/ }), -/* 25 */ -/***/ (function(module, exports, __webpack_require__) { +function car25519(o) { + var i, v, c = 1; + for (i = 0; i < 16; i++) { + v = o[i] + c + 65535; + c = Math.floor(v / 65536); + o[i] = v - c * 65536; + } + o[0] += c-1 + 37 * (c-1); +} -"use strict"; +function sel25519(p, q, b) { + var t, c = ~(b-1); + for (var i = 0; i < 16; i++) { + t = c & (p[i] ^ q[i]); + p[i] ^= t; + q[i] ^= t; + } +} -exports.__esModule = true; -var logger_1 = __webpack_require__(3); -var jsonp = function (context, socketId, callback) { - if (this.authOptions.headers !== undefined) { - logger_1["default"].warn("Warn", "To send headers with the auth request, you must use AJAX, rather than JSONP."); +function pack25519(o, n) { + var i, j, b; + var m = gf(), t = gf(); + for (i = 0; i < 16; i++) t[i] = n[i]; + car25519(t); + car25519(t); + car25519(t); + for (j = 0; j < 2; j++) { + m[0] = t[0] - 0xffed; + for (i = 1; i < 15; i++) { + m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1); + m[i-1] &= 0xffff; } - var callbackName = context.nextAuthCallbackID.toString(); - context.nextAuthCallbackID++; - var document = context.getDocument(); - var script = document.createElement("script"); - context.auth_callbacks[callbackName] = function (data) { - callback(false, data); - }; - var callback_name = "Pusher.auth_callbacks['" + callbackName + "']"; - script.src = this.options.authEndpoint + - '?callback=' + - encodeURIComponent(callback_name) + - '&' + - this.composeQuery(socketId); - var head = document.getElementsByTagName("head")[0] || document.documentElement; - head.insertBefore(script, head.firstChild); -}; -exports["default"] = jsonp; - - -/***/ }), -/* 26 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var ScriptRequest = (function () { - function ScriptRequest(src) { - this.src = src; - } - ScriptRequest.prototype.send = function (receiver) { - var self = this; - var errorString = "Error loading " + self.src; - self.script = document.createElement("script"); - self.script.id = receiver.id; - self.script.src = self.src; - self.script.type = "text/javascript"; - self.script.charset = "UTF-8"; - if (self.script.addEventListener) { - self.script.onerror = function () { - receiver.callback(errorString); - }; - self.script.onload = function () { - receiver.callback(null); - }; - } - else { - self.script.onreadystatechange = function () { - if (self.script.readyState === 'loaded' || - self.script.readyState === 'complete') { - receiver.callback(null); - } - }; - } - if (self.script.async === undefined && document.attachEvent && - /opera/i.test(navigator.userAgent)) { - self.errorScript = document.createElement("script"); - self.errorScript.id = receiver.id + "_error"; - self.errorScript.text = receiver.name + "('" + errorString + "');"; - self.script.async = self.errorScript.async = false; - } - else { - self.script.async = true; - } - var head = document.getElementsByTagName('head')[0]; - head.insertBefore(self.script, head.firstChild); - if (self.errorScript) { - head.insertBefore(self.errorScript, self.script.nextSibling); - } - }; - ScriptRequest.prototype.cleanup = function () { - if (this.script) { - this.script.onload = this.script.onerror = null; - this.script.onreadystatechange = null; - } - if (this.script && this.script.parentNode) { - this.script.parentNode.removeChild(this.script); - } - if (this.errorScript && this.errorScript.parentNode) { - this.errorScript.parentNode.removeChild(this.errorScript); - } - this.script = null; - this.errorScript = null; - }; - return ScriptRequest; -}()); -exports["default"] = ScriptRequest; - - -/***/ }), -/* 27 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Collections = __webpack_require__(0); -var runtime_1 = __webpack_require__(1); -var JSONPRequest = (function () { - function JSONPRequest(url, data) { - this.url = url; - this.data = data; - } - JSONPRequest.prototype.send = function (receiver) { - if (this.request) { - return; - } - var query = Collections.buildQueryString(this.data); - var url = this.url + "/" + receiver.number + "?" + query; - this.request = runtime_1["default"].createScriptRequest(url); - this.request.send(receiver); - }; - JSONPRequest.prototype.cleanup = function () { - if (this.request) { - this.request.cleanup(); - } - }; - return JSONPRequest; -}()); -exports["default"] = JSONPRequest; - - -/***/ }), -/* 28 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var script_receiver_factory_1 = __webpack_require__(8); -var getAgent = function (sender, useTLS) { - return function (data, callback) { - var scheme = "http" + (useTLS ? "s" : "") + "://"; - var url = scheme + (sender.host || sender.options.host) + sender.options.path; - var request = runtime_1["default"].createJSONPRequest(url, data); - var receiver = runtime_1["default"].ScriptReceivers.create(function (error, result) { - script_receiver_factory_1.ScriptReceivers.remove(receiver); - request.cleanup(); - if (result && result.host) { - sender.host = result.host; - } - if (callback) { - callback(error, result); - } - }); - request.send(receiver); - }; -}; -var jsonp = { - name: 'jsonp', - getAgent: getAgent -}; -exports["default"] = jsonp; - - -/***/ }), -/* 29 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var transports_1 = __webpack_require__(30); -var transport_1 = __webpack_require__(15); -var URLSchemes = __webpack_require__(14); -var runtime_1 = __webpack_require__(1); -var dependencies_1 = __webpack_require__(11); -var Collections = __webpack_require__(0); -var SockJSTransport = new transport_1["default"]({ - file: "sockjs", - urls: URLSchemes.sockjs, - handlesActivityChecks: true, - supportsPing: false, - isSupported: function () { - return true; - }, - isInitialized: function () { - return window.SockJS !== undefined; - }, - getSocket: function (url, options) { - return new window.SockJS(url, null, { - js_path: dependencies_1.Dependencies.getPath("sockjs", { - useTLS: options.useTLS - }), - ignore_null_origin: options.ignoreNullOrigin - }); - }, - beforeOpen: function (socket, path) { - socket.send(JSON.stringify({ - path: path - })); - } -}); -var xdrConfiguration = { - isSupported: function (environment) { - var yes = runtime_1["default"].isXDRSupported(environment.useTLS); - return yes; - } -}; -var XDRStreamingTransport = new transport_1["default"](Collections.extend({}, transports_1.streamingConfiguration, xdrConfiguration)); -var XDRPollingTransport = new transport_1["default"](Collections.extend({}, transports_1.pollingConfiguration, xdrConfiguration)); -transports_1["default"].xdr_streaming = XDRStreamingTransport; -transports_1["default"].xdr_polling = XDRPollingTransport; -transports_1["default"].sockjs = SockJSTransport; -exports["default"] = transports_1["default"]; - + m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1); + b = (m[15]>>16) & 1; + m[14] &= 0xffff; + sel25519(t, m, 1-b); + } + for (i = 0; i < 16; i++) { + o[2*i] = t[i] & 0xff; + o[2*i+1] = t[i]>>8; + } +} -/***/ }), -/* 30 */ -/***/ (function(module, exports, __webpack_require__) { +function neq25519(a, b) { + var c = new Uint8Array(32), d = new Uint8Array(32); + pack25519(c, a); + pack25519(d, b); + return crypto_verify_32(c, 0, d, 0); +} -"use strict"; +function par25519(a) { + var d = new Uint8Array(32); + pack25519(d, a); + return d[0] & 1; +} -exports.__esModule = true; -var URLSchemes = __webpack_require__(14); -var transport_1 = __webpack_require__(15); -var Collections = __webpack_require__(0); -var runtime_1 = __webpack_require__(1); -var WSTransport = new transport_1["default"]({ - urls: URLSchemes.ws, - handlesActivityChecks: false, - supportsPing: false, - isInitialized: function () { - return Boolean(runtime_1["default"].getWebSocketAPI()); - }, - isSupported: function () { - return Boolean(runtime_1["default"].getWebSocketAPI()); - }, - getSocket: function (url) { - return runtime_1["default"].createWebSocket(url); - } -}); -var httpConfiguration = { - urls: URLSchemes.http, - handlesActivityChecks: false, - supportsPing: true, - isInitialized: function () { - return true; - } -}; -exports.streamingConfiguration = Collections.extend({ getSocket: function (url) { - return runtime_1["default"].HTTPFactory.createStreamingSocket(url); - } -}, httpConfiguration); -exports.pollingConfiguration = Collections.extend({ getSocket: function (url) { - return runtime_1["default"].HTTPFactory.createPollingSocket(url); - } -}, httpConfiguration); -var xhrConfiguration = { - isSupported: function () { - return runtime_1["default"].isXHRSupported(); - } -}; -var XHRStreamingTransport = new transport_1["default"](Collections.extend({}, exports.streamingConfiguration, xhrConfiguration)); -var XHRPollingTransport = new transport_1["default"](Collections.extend({}, exports.pollingConfiguration, xhrConfiguration)); -var Transports = { - ws: WSTransport, - xhr_streaming: XHRStreamingTransport, - xhr_polling: XHRPollingTransport -}; -exports["default"] = Transports; +function unpack25519(o, n) { + var i; + for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8); + o[15] &= 0x7fff; +} +function A(o, a, b) { + for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]; +} -/***/ }), -/* 31 */ -/***/ (function(module, exports, __webpack_require__) { +function Z(o, a, b) { + for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]; +} -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var util_1 = __webpack_require__(2); -var Collections = __webpack_require__(0); -var dispatcher_1 = __webpack_require__(4); -var logger_1 = __webpack_require__(3); -var runtime_1 = __webpack_require__(1); -var TransportConnection = (function (_super) { - __extends(TransportConnection, _super); - function TransportConnection(hooks, name, priority, key, options) { - var _this = _super.call(this) || this; - _this.initialize = runtime_1["default"].transportConnectionInitializer; - _this.hooks = hooks; - _this.name = name; - _this.priority = priority; - _this.key = key; - _this.options = options; - _this.state = "new"; - _this.timeline = options.timeline; - _this.activityTimeout = options.activityTimeout; - _this.id = _this.timeline.generateUniqueID(); - return _this; - } - TransportConnection.prototype.handlesActivityChecks = function () { - return Boolean(this.hooks.handlesActivityChecks); - }; - TransportConnection.prototype.supportsPing = function () { - return Boolean(this.hooks.supportsPing); - }; - TransportConnection.prototype.connect = function () { - var _this = this; - if (this.socket || this.state !== "initialized") { - return false; - } - var url = this.hooks.urls.getInitial(this.key, this.options); - try { - this.socket = this.hooks.getSocket(url, this.options); - } - catch (e) { - util_1["default"].defer(function () { - _this.onError(e); - _this.changeState("closed"); - }); - return false; - } - this.bindListeners(); - logger_1["default"].debug("Connecting", { transport: this.name, url: url }); - this.changeState("connecting"); - return true; - }; - TransportConnection.prototype.close = function () { - if (this.socket) { - this.socket.close(); - return true; - } - else { - return false; - } - }; - TransportConnection.prototype.send = function (data) { - var _this = this; - if (this.state === "open") { - util_1["default"].defer(function () { - if (_this.socket) { - _this.socket.send(data); - } - }); - return true; - } - else { - return false; - } - }; - TransportConnection.prototype.ping = function () { - if (this.state === "open" && this.supportsPing()) { - this.socket.ping(); - } - }; - TransportConnection.prototype.onOpen = function () { - if (this.hooks.beforeOpen) { - this.hooks.beforeOpen(this.socket, this.hooks.urls.getPath(this.key, this.options)); - } - this.changeState("open"); - this.socket.onopen = undefined; - }; - TransportConnection.prototype.onError = function (error) { - this.emit("error", { type: 'WebSocketError', error: error }); - this.timeline.error(this.buildTimelineMessage({ error: error.toString() })); - }; - TransportConnection.prototype.onClose = function (closeEvent) { - if (closeEvent) { - this.changeState("closed", { - code: closeEvent.code, - reason: closeEvent.reason, - wasClean: closeEvent.wasClean - }); - } - else { - this.changeState("closed"); - } - this.unbindListeners(); - this.socket = undefined; - }; - TransportConnection.prototype.onMessage = function (message) { - this.emit("message", message); - }; - TransportConnection.prototype.onActivity = function () { - this.emit("activity"); - }; - TransportConnection.prototype.bindListeners = function () { - var _this = this; - this.socket.onopen = function () { - _this.onOpen(); - }; - this.socket.onerror = function (error) { - _this.onError(error); - }; - this.socket.onclose = function (closeEvent) { - _this.onClose(closeEvent); - }; - this.socket.onmessage = function (message) { - _this.onMessage(message); - }; - if (this.supportsPing()) { - this.socket.onactivity = function () { _this.onActivity(); }; - } - }; - TransportConnection.prototype.unbindListeners = function () { - if (this.socket) { - this.socket.onopen = undefined; - this.socket.onerror = undefined; - this.socket.onclose = undefined; - this.socket.onmessage = undefined; - if (this.supportsPing()) { - this.socket.onactivity = undefined; - } - } - }; - TransportConnection.prototype.changeState = function (state, params) { - this.state = state; - this.timeline.info(this.buildTimelineMessage({ - state: state, - params: params - })); - this.emit(state, params); - }; - TransportConnection.prototype.buildTimelineMessage = function (message) { - return Collections.extend({ cid: this.id }, message); - }; - return TransportConnection; -}(dispatcher_1["default"])); -exports["default"] = TransportConnection; - - -/***/ }), -/* 32 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Collections = __webpack_require__(0); -var CallbackRegistry = (function () { - function CallbackRegistry() { - this._callbacks = {}; - } - CallbackRegistry.prototype.get = function (name) { - return this._callbacks[prefix(name)]; - }; - CallbackRegistry.prototype.add = function (name, callback, context) { - var prefixedEventName = prefix(name); - this._callbacks[prefixedEventName] = this._callbacks[prefixedEventName] || []; - this._callbacks[prefixedEventName].push({ - fn: callback, - context: context - }); - }; - CallbackRegistry.prototype.remove = function (name, callback, context) { - if (!name && !callback && !context) { - this._callbacks = {}; - return; - } - var names = name ? [prefix(name)] : Collections.keys(this._callbacks); - if (callback || context) { - this.removeCallback(names, callback, context); - } - else { - this.removeAllCallbacks(names); - } - }; - CallbackRegistry.prototype.removeCallback = function (names, callback, context) { - Collections.apply(names, function (name) { - this._callbacks[name] = Collections.filter(this._callbacks[name] || [], function (binding) { - return (callback && callback !== binding.fn) || - (context && context !== binding.context); - }); - if (this._callbacks[name].length === 0) { - delete this._callbacks[name]; - } - }, this); - }; - CallbackRegistry.prototype.removeAllCallbacks = function (names) { - Collections.apply(names, function (name) { - delete this._callbacks[name]; - }, this); - }; - return CallbackRegistry; -}()); -exports["default"] = CallbackRegistry; -function prefix(name) { - return "_" + name; -} - - -/***/ }), -/* 33 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var dispatcher_1 = __webpack_require__(4); -var NetInfo = (function (_super) { - __extends(NetInfo, _super); - function NetInfo() { - var _this = _super.call(this) || this; - var self = _this; - if (window.addEventListener !== undefined) { - window.addEventListener("online", function () { - self.emit('online'); - }, false); - window.addEventListener("offline", function () { - self.emit('offline'); - }, false); - } - return _this; - } - NetInfo.prototype.isOnline = function () { - if (window.navigator.onLine === undefined) { - return true; - } - else { - return window.navigator.onLine; - } - }; - return NetInfo; -}(dispatcher_1["default"])); -exports.NetInfo = NetInfo; -exports.Network = new NetInfo(); - - -/***/ }), -/* 34 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Collections = __webpack_require__(0); -var transport_manager_1 = __webpack_require__(35); -var sequential_strategy_1 = __webpack_require__(18); -var best_connected_ever_strategy_1 = __webpack_require__(49); -var cached_strategy_1 = __webpack_require__(50); -var delayed_strategy_1 = __webpack_require__(51); -var if_strategy_1 = __webpack_require__(52); -var first_connected_strategy_1 = __webpack_require__(53); -function testSupportsStrategy(strategy) { - return function () { - return strategy.isSupported(); - }; -} -var getDefaultStrategy = function (config, defineTransport) { - var definedTransports = {}; - function defineTransportStrategy(name, type, priority, options, manager) { - var transport = defineTransport(config, name, type, priority, options, manager); - definedTransports[name] = transport; - return transport; - } - var ws_options = { - hostNonTLS: config.wsHost + ":" + config.wsPort, - hostTLS: config.wsHost + ":" + config.wssPort, - httpPath: config.wsPath - }; - var wss_options = Collections.extend({}, ws_options, { - useTLS: true - }); - var sockjs_options = { - hostNonTLS: config.httpHost + ":" + config.httpPort, - hostTLS: config.httpHost + ":" + config.httpsPort, - httpPath: config.httpPath - }; - var timeouts = { - loop: true, - timeout: 15000, - timeoutLimit: 60000 - }; - var ws_manager = new transport_manager_1["default"]({ - lives: 2, - minPingDelay: 10000, - maxPingDelay: config.activity_timeout - }); - var streaming_manager = new transport_manager_1["default"]({ - lives: 2, - minPingDelay: 10000, - maxPingDelay: config.activity_timeout - }); - var ws_transport = defineTransportStrategy("ws", "ws", 3, ws_options, ws_manager); - var wss_transport = defineTransportStrategy("wss", "ws", 3, wss_options, ws_manager); - var sockjs_transport = defineTransportStrategy("sockjs", "sockjs", 1, sockjs_options); - var xhr_streaming_transport = defineTransportStrategy("xhr_streaming", "xhr_streaming", 1, sockjs_options, streaming_manager); - var xdr_streaming_transport = defineTransportStrategy("xdr_streaming", "xdr_streaming", 1, sockjs_options, streaming_manager); - var xhr_polling_transport = defineTransportStrategy("xhr_polling", "xhr_polling", 1, sockjs_options); - var xdr_polling_transport = defineTransportStrategy("xdr_polling", "xdr_polling", 1, sockjs_options); - var ws_loop = new sequential_strategy_1["default"]([ws_transport], timeouts); - var wss_loop = new sequential_strategy_1["default"]([wss_transport], timeouts); - var sockjs_loop = new sequential_strategy_1["default"]([sockjs_transport], timeouts); - var streaming_loop = new sequential_strategy_1["default"]([new if_strategy_1["default"](testSupportsStrategy(xhr_streaming_transport), xhr_streaming_transport, xdr_streaming_transport)], timeouts); - var polling_loop = new sequential_strategy_1["default"]([new if_strategy_1["default"](testSupportsStrategy(xhr_polling_transport), xhr_polling_transport, xdr_polling_transport)], timeouts); - var http_loop = new sequential_strategy_1["default"]([new if_strategy_1["default"](testSupportsStrategy(streaming_loop), new best_connected_ever_strategy_1["default"]([streaming_loop, new delayed_strategy_1["default"](polling_loop, { delay: 4000 })]), polling_loop)], timeouts); - var http_fallback_loop = new if_strategy_1["default"](testSupportsStrategy(http_loop), http_loop, sockjs_loop); - var wsStrategy; - if (config.useTLS) { - wsStrategy = new best_connected_ever_strategy_1["default"]([ws_loop, new delayed_strategy_1["default"](http_fallback_loop, { delay: 2000 })]); - } - else { - wsStrategy = new best_connected_ever_strategy_1["default"]([ - ws_loop, - new delayed_strategy_1["default"](wss_loop, { delay: 2000 }), - new delayed_strategy_1["default"](http_fallback_loop, { delay: 5000 }) - ]); - } - return new cached_strategy_1["default"](new first_connected_strategy_1["default"](new if_strategy_1["default"](testSupportsStrategy(ws_transport), wsStrategy, http_fallback_loop)), definedTransports, { - ttl: 1800000, - timeline: config.timeline, - useTLS: config.useTLS - }); -}; -exports["default"] = getDefaultStrategy; - - -/***/ }), -/* 35 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var factory_1 = __webpack_require__(7); -var TransportManager = (function () { - function TransportManager(options) { - this.options = options || {}; - this.livesLeft = this.options.lives || Infinity; - } - TransportManager.prototype.getAssistant = function (transport) { - return factory_1["default"].createAssistantToTheTransportManager(this, transport, { - minPingDelay: this.options.minPingDelay, - maxPingDelay: this.options.maxPingDelay - }); - }; - TransportManager.prototype.isAlive = function () { - return this.livesLeft > 0; - }; - TransportManager.prototype.reportDeath = function () { - this.livesLeft -= 1; - }; - return TransportManager; -}()); -exports["default"] = TransportManager; - - -/***/ }), -/* 36 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var util_1 = __webpack_require__(2); -var Collections = __webpack_require__(0); -var AssistantToTheTransportManager = (function () { - function AssistantToTheTransportManager(manager, transport, options) { - this.manager = manager; - this.transport = transport; - this.minPingDelay = options.minPingDelay; - this.maxPingDelay = options.maxPingDelay; - this.pingDelay = undefined; - } - AssistantToTheTransportManager.prototype.createConnection = function (name, priority, key, options) { - var _this = this; - options = Collections.extend({}, options, { - activityTimeout: this.pingDelay - }); - var connection = this.transport.createConnection(name, priority, key, options); - var openTimestamp = null; - var onOpen = function () { - connection.unbind("open", onOpen); - connection.bind("closed", onClosed); - openTimestamp = util_1["default"].now(); - }; - var onClosed = function (closeEvent) { - connection.unbind("closed", onClosed); - if (closeEvent.code === 1002 || closeEvent.code === 1003) { - _this.manager.reportDeath(); - } - else if (!closeEvent.wasClean && openTimestamp) { - var lifespan = util_1["default"].now() - openTimestamp; - if (lifespan < 2 * _this.maxPingDelay) { - _this.manager.reportDeath(); - _this.pingDelay = Math.max(lifespan / 2, _this.minPingDelay); - } - } - }; - connection.bind("open", onOpen); - return connection; - }; - AssistantToTheTransportManager.prototype.isSupported = function (environment) { - return this.manager.isAlive() && this.transport.isSupported(environment); - }; - return AssistantToTheTransportManager; -}()); -exports["default"] = AssistantToTheTransportManager; - - -/***/ }), -/* 37 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Collections = __webpack_require__(0); -var Protocol = __webpack_require__(16); -var connection_1 = __webpack_require__(38); -var Handshake = (function () { - function Handshake(transport, callback) { - this.transport = transport; - this.callback = callback; - this.bindListeners(); - } - Handshake.prototype.close = function () { - this.unbindListeners(); - this.transport.close(); - }; - Handshake.prototype.bindListeners = function () { - var _this = this; - this.onMessage = function (m) { - _this.unbindListeners(); - var result; - try { - result = Protocol.processHandshake(m); - } - catch (e) { - _this.finish("error", { error: e }); - _this.transport.close(); - return; - } - if (result.action === "connected") { - _this.finish("connected", { - connection: new connection_1["default"](result.id, _this.transport), - activityTimeout: result.activityTimeout - }); - } - else { - _this.finish(result.action, { error: result.error }); - _this.transport.close(); - } - }; - this.onClosed = function (closeEvent) { - _this.unbindListeners(); - var action = Protocol.getCloseAction(closeEvent) || "backoff"; - var error = Protocol.getCloseError(closeEvent); - _this.finish(action, { error: error }); - }; - this.transport.bind("message", this.onMessage); - this.transport.bind("closed", this.onClosed); - }; - Handshake.prototype.unbindListeners = function () { - this.transport.unbind("message", this.onMessage); - this.transport.unbind("closed", this.onClosed); - }; - Handshake.prototype.finish = function (action, params) { - this.callback(Collections.extend({ transport: this.transport, action: action }, params)); - }; - return Handshake; -}()); -exports["default"] = Handshake; - - -/***/ }), -/* 38 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var Collections = __webpack_require__(0); -var dispatcher_1 = __webpack_require__(4); -var Protocol = __webpack_require__(16); -var logger_1 = __webpack_require__(3); -var Connection = (function (_super) { - __extends(Connection, _super); - function Connection(id, transport) { - var _this = _super.call(this) || this; - _this.id = id; - _this.transport = transport; - _this.activityTimeout = transport.activityTimeout; - _this.bindListeners(); - return _this; - } - Connection.prototype.handlesActivityChecks = function () { - return this.transport.handlesActivityChecks(); - }; - Connection.prototype.send = function (data) { - return this.transport.send(data); - }; - Connection.prototype.send_event = function (name, data, channel) { - var event = { event: name, data: data }; - if (channel) { - event.channel = channel; - } - logger_1["default"].debug('Event sent', event); - return this.send(Protocol.encodeMessage(event)); - }; - Connection.prototype.ping = function () { - if (this.transport.supportsPing()) { - this.transport.ping(); - } - else { - this.send_event('pusher:ping', {}); - } - }; - Connection.prototype.close = function () { - this.transport.close(); - }; - Connection.prototype.bindListeners = function () { - var _this = this; - var listeners = { - message: function (messageEvent) { - var pusherEvent; - try { - pusherEvent = Protocol.decodeMessage(messageEvent); - } - catch (e) { - _this.emit('error', { - type: 'MessageParseError', - error: e, - data: messageEvent.data - }); - } - if (pusherEvent !== undefined) { - logger_1["default"].debug('Event recd', pusherEvent); - switch (pusherEvent.event) { - case 'pusher:error': - _this.emit('error', { type: 'PusherError', data: pusherEvent.data }); - break; - case 'pusher:ping': - _this.emit("ping"); - break; - case 'pusher:pong': - _this.emit("pong"); - break; - } - _this.emit('message', pusherEvent); - } - }, - activity: function () { - _this.emit("activity"); - }, - error: function (error) { - _this.emit("error", { type: "WebSocketError", error: error }); - }, - closed: function (closeEvent) { - unbindListeners(); - if (closeEvent && closeEvent.code) { - _this.handleCloseEvent(closeEvent); - } - _this.transport = null; - _this.emit("closed"); - } - }; - var unbindListeners = function () { - Collections.objectApply(listeners, function (listener, event) { - _this.transport.unbind(event, listener); - }); - }; - Collections.objectApply(listeners, function (listener, event) { - _this.transport.bind(event, listener); - }); - }; - Connection.prototype.handleCloseEvent = function (closeEvent) { - var action = Protocol.getCloseAction(closeEvent); - var error = Protocol.getCloseError(closeEvent); - if (error) { - this.emit('error', error); - } - if (action) { - this.emit(action, { action: action, error: error }); - } - }; - return Connection; -}(dispatcher_1["default"])); -exports["default"] = Connection; - - -/***/ }), -/* 39 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var PusherAuthorizer = (function () { - function PusherAuthorizer(channel, options) { - this.channel = channel; - var authTransport = options.authTransport; - if (typeof runtime_1["default"].getAuthorizers()[authTransport] === "undefined") { - throw "'" + authTransport + "' is not a recognized auth transport"; - } - this.type = authTransport; - this.options = options; - this.authOptions = (options || {}).auth || {}; - } - PusherAuthorizer.prototype.composeQuery = function (socketId) { - var query = 'socket_id=' + encodeURIComponent(socketId) + - '&channel_name=' + encodeURIComponent(this.channel.name); - for (var i in this.authOptions.params) { - query += "&" + encodeURIComponent(i) + "=" + encodeURIComponent(this.authOptions.params[i]); - } - return query; - }; - PusherAuthorizer.prototype.authorize = function (socketId, callback) { - PusherAuthorizer.authorizers = PusherAuthorizer.authorizers || runtime_1["default"].getAuthorizers(); - return PusherAuthorizer.authorizers[this.type].call(this, runtime_1["default"], socketId, callback); - }; - return PusherAuthorizer; -}()); -exports["default"] = PusherAuthorizer; - - -/***/ }), -/* 40 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var TimelineSender = (function () { - function TimelineSender(timeline, options) { - this.timeline = timeline; - this.options = options || {}; - } - TimelineSender.prototype.send = function (useTLS, callback) { - if (this.timeline.isEmpty()) { - return; - } - this.timeline.send(runtime_1["default"].TimelineTransport.getAgent(this, useTLS), callback); - }; - return TimelineSender; -}()); -exports["default"] = TimelineSender; - - -/***/ }), -/* 41 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var private_channel_1 = __webpack_require__(12); -var logger_1 = __webpack_require__(3); -var members_1 = __webpack_require__(42); -var url_store_1 = __webpack_require__(10); -var PresenceChannel = (function (_super) { - __extends(PresenceChannel, _super); - function PresenceChannel(name, pusher) { - var _this = _super.call(this, name, pusher) || this; - _this.members = new members_1["default"](); - return _this; - } - PresenceChannel.prototype.authorize = function (socketId, callback) { - var _this = this; - _super.prototype.authorize.call(this, socketId, function (error, authData) { - if (!error) { - if (authData.channel_data === undefined) { - var suffix = url_store_1["default"].buildLogSuffix("authenticationEndpoint"); - logger_1["default"].warn("Invalid auth response for channel '" + _this.name + "'," + - ("expected 'channel_data' field. " + suffix)); - callback("Invalid auth response"); - return; - } - var channelData = JSON.parse(authData.channel_data); - _this.members.setMyID(channelData.user_id); - } - callback(error, authData); - }); - }; - PresenceChannel.prototype.handleEvent = function (event) { - var eventName = event.event; - if (eventName.indexOf("pusher_internal:") === 0) { - this.handleInternalEvent(event); - } - else { - var data = event.data; - var metadata = {}; - if (event.user_id) { - metadata.user_id = event.user_id; - } - this.emit(eventName, data, metadata); - } - }; - PresenceChannel.prototype.handleInternalEvent = function (event) { - var eventName = event.event; - var data = event.data; - switch (eventName) { - case "pusher_internal:subscription_succeeded": - this.handleSubscriptionSucceededEvent(event); - break; - case "pusher_internal:member_added": - var addedMember = this.members.addMember(data); - this.emit('pusher:member_added', addedMember); - break; - case "pusher_internal:member_removed": - var removedMember = this.members.removeMember(data); - if (removedMember) { - this.emit('pusher:member_removed', removedMember); - } - break; - } - }; - PresenceChannel.prototype.handleSubscriptionSucceededEvent = function (event) { - this.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } - else { - this.members.onSubscription(event.data); - this.emit("pusher:subscription_succeeded", this.members); - } - }; - PresenceChannel.prototype.disconnect = function () { - this.members.reset(); - _super.prototype.disconnect.call(this); - }; - return PresenceChannel; -}(private_channel_1["default"])); -exports["default"] = PresenceChannel; - - -/***/ }), -/* 42 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Collections = __webpack_require__(0); -var Members = (function () { - function Members() { - this.reset(); - } - Members.prototype.get = function (id) { - if (Object.prototype.hasOwnProperty.call(this.members, id)) { - return { - id: id, - info: this.members[id] - }; - } - else { - return null; - } - }; - Members.prototype.each = function (callback) { - var _this = this; - Collections.objectApply(this.members, function (member, id) { - callback(_this.get(id)); - }); - }; - Members.prototype.setMyID = function (id) { - this.myID = id; - }; - Members.prototype.onSubscription = function (subscriptionData) { - this.members = subscriptionData.presence.hash; - this.count = subscriptionData.presence.count; - this.me = this.get(this.myID); - }; - Members.prototype.addMember = function (memberData) { - if (this.get(memberData.user_id) === null) { - this.count++; - } - this.members[memberData.user_id] = memberData.user_info; - return this.get(memberData.user_id); - }; - Members.prototype.removeMember = function (memberData) { - var member = this.get(memberData.user_id); - if (member) { - delete this.members[memberData.user_id]; - this.count--; - } - return member; - }; - Members.prototype.reset = function () { - this.members = {}; - this.count = 0; - this.myID = null; - this.me = null; - }; - return Members; -}()); -exports["default"] = Members; - - -/***/ }), -/* 43 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var private_channel_1 = __webpack_require__(12); -var Errors = __webpack_require__(5); -var logger_1 = __webpack_require__(3); -var tweetnacl_1 = __webpack_require__(44); -var tweetnacl_util_1 = __webpack_require__(46); -var EncryptedChannel = (function (_super) { - __extends(EncryptedChannel, _super); - function EncryptedChannel() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.key = null; - return _this; - } - EncryptedChannel.prototype.authorize = function (socketId, callback) { - var _this = this; - _super.prototype.authorize.call(this, socketId, function (error, authData) { - if (error) { - callback(true, authData); - return; - } - var sharedSecret = authData["shared_secret"]; - if (!sharedSecret) { - var errorMsg = "No shared_secret key in auth payload for encrypted channel: " + _this.name; - callback(true, errorMsg); - logger_1["default"].warn("Error: " + errorMsg); - return; - } - _this.key = tweetnacl_util_1.decodeBase64(sharedSecret); - delete authData["shared_secret"]; - callback(false, authData); - }); - }; - EncryptedChannel.prototype.trigger = function (event, data) { - throw new Errors.UnsupportedFeature('Client events are not currently supported for encrypted channels'); - }; - EncryptedChannel.prototype.handleEvent = function (event) { - var eventName = event.event; - var data = event.data; - if (eventName.indexOf("pusher_internal:") === 0 || eventName.indexOf("pusher:") === 0) { - _super.prototype.handleEvent.call(this, event); - return; - } - this.handleEncryptedEvent(eventName, data); - }; - EncryptedChannel.prototype.handleEncryptedEvent = function (event, data) { - var _this = this; - if (!this.key) { - logger_1["default"].debug('Received encrypted event before key has been retrieved from the authEndpoint'); - return; - } - if (!data.ciphertext || !data.nonce) { - logger_1["default"].warn('Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: ' + data); - return; - } - var cipherText = tweetnacl_util_1.decodeBase64(data.ciphertext); - if (cipherText.length < tweetnacl_1.secretbox.overheadLength) { - logger_1["default"].warn("Expected encrypted event ciphertext length to be " + tweetnacl_1.secretbox.overheadLength + ", got: " + cipherText.length); - return; - } - var nonce = tweetnacl_util_1.decodeBase64(data.nonce); - if (nonce.length < tweetnacl_1.secretbox.nonceLength) { - logger_1["default"].warn("Expected encrypted event nonce length to be " + tweetnacl_1.secretbox.nonceLength + ", got: " + nonce.length); - return; - } - var bytes = tweetnacl_1.secretbox.open(cipherText, nonce, this.key); - if (bytes === null) { - logger_1["default"].debug('Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint...'); - this.authorize(this.pusher.connection.socket_id, function (error, authData) { - if (error) { - logger_1["default"].warn("Failed to make a request to the authEndpoint: " + authData + ". Unable to fetch new key, so dropping encrypted event"); - return; - } - bytes = tweetnacl_1.secretbox.open(cipherText, nonce, _this.key); - if (bytes === null) { - logger_1["default"].warn("Failed to decrypt event with new key. Dropping encrypted event"); - return; - } - _this.emitJSON(event, tweetnacl_util_1.encodeUTF8(bytes)); - return; - }); - return; - } - this.emitJSON(event, tweetnacl_util_1.encodeUTF8(bytes)); - }; - EncryptedChannel.prototype.emitJSON = function (eventName, data) { - try { - this.emit(eventName, JSON.parse(data)); - } - catch (e) { - this.emit(eventName, data); - } - return this; - }; - return EncryptedChannel; -}(private_channel_1["default"])); -exports["default"] = EncryptedChannel; - - -/***/ }), -/* 44 */ -/***/ (function(module, exports, __webpack_require__) { - -(function(nacl) { -'use strict'; - -// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. -// Public domain. -// -// Implementation derived from TweetNaCl version 20140427. -// See for details: http://tweetnacl.cr.yp.to/ - -var gf = function(init) { - var i, r = new Float64Array(16); - if (init) for (i = 0; i < init.length; i++) r[i] = init[i]; - return r; -}; - -// Pluggable, initialized in high-level API below. -var randombytes = function(/* x, n */) { throw new Error('no PRNG'); }; - -var _0 = new Uint8Array(16); -var _9 = new Uint8Array(32); _9[0] = 9; - -var gf0 = gf(), - gf1 = gf([1]), - _121665 = gf([0xdb41, 1]), - D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]), - D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]), - X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]), - Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]), - I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]); - -function ts64(x, i, h, l) { - x[i] = (h >> 24) & 0xff; - x[i+1] = (h >> 16) & 0xff; - x[i+2] = (h >> 8) & 0xff; - x[i+3] = h & 0xff; - x[i+4] = (l >> 24) & 0xff; - x[i+5] = (l >> 16) & 0xff; - x[i+6] = (l >> 8) & 0xff; - x[i+7] = l & 0xff; -} - -function vn(x, xi, y, yi, n) { - var i,d = 0; - for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i]; - return (1 & ((d - 1) >>> 8)) - 1; -} - -function crypto_verify_16(x, xi, y, yi) { - return vn(x,xi,y,yi,16); -} - -function crypto_verify_32(x, xi, y, yi) { - return vn(x,xi,y,yi,32); -} - -function core_salsa20(o, p, k, c) { - var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, - j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, - j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, - j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, - j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, - j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, - j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, - j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, - j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, - j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, - j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, - j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, - j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, - j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, - j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, - j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; - - var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, - x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, - x15 = j15, u; - - for (var i = 0; i < 20; i += 2) { - u = x0 + x12 | 0; - x4 ^= u<<7 | u>>>(32-7); - u = x4 + x0 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x4 | 0; - x12 ^= u<<13 | u>>>(32-13); - u = x12 + x8 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x1 | 0; - x9 ^= u<<7 | u>>>(32-7); - u = x9 + x5 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x9 | 0; - x1 ^= u<<13 | u>>>(32-13); - u = x1 + x13 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x6 | 0; - x14 ^= u<<7 | u>>>(32-7); - u = x14 + x10 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x14 | 0; - x6 ^= u<<13 | u>>>(32-13); - u = x6 + x2 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x11 | 0; - x3 ^= u<<7 | u>>>(32-7); - u = x3 + x15 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x3 | 0; - x11 ^= u<<13 | u>>>(32-13); - u = x11 + x7 | 0; - x15 ^= u<<18 | u>>>(32-18); - - u = x0 + x3 | 0; - x1 ^= u<<7 | u>>>(32-7); - u = x1 + x0 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x1 | 0; - x3 ^= u<<13 | u>>>(32-13); - u = x3 + x2 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x4 | 0; - x6 ^= u<<7 | u>>>(32-7); - u = x6 + x5 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x6 | 0; - x4 ^= u<<13 | u>>>(32-13); - u = x4 + x7 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x9 | 0; - x11 ^= u<<7 | u>>>(32-7); - u = x11 + x10 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x11 | 0; - x9 ^= u<<13 | u>>>(32-13); - u = x9 + x8 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x14 | 0; - x12 ^= u<<7 | u>>>(32-7); - u = x12 + x15 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x12 | 0; - x14 ^= u<<13 | u>>>(32-13); - u = x14 + x13 | 0; - x15 ^= u<<18 | u>>>(32-18); - } - x0 = x0 + j0 | 0; - x1 = x1 + j1 | 0; - x2 = x2 + j2 | 0; - x3 = x3 + j3 | 0; - x4 = x4 + j4 | 0; - x5 = x5 + j5 | 0; - x6 = x6 + j6 | 0; - x7 = x7 + j7 | 0; - x8 = x8 + j8 | 0; - x9 = x9 + j9 | 0; - x10 = x10 + j10 | 0; - x11 = x11 + j11 | 0; - x12 = x12 + j12 | 0; - x13 = x13 + j13 | 0; - x14 = x14 + j14 | 0; - x15 = x15 + j15 | 0; - - o[ 0] = x0 >>> 0 & 0xff; - o[ 1] = x0 >>> 8 & 0xff; - o[ 2] = x0 >>> 16 & 0xff; - o[ 3] = x0 >>> 24 & 0xff; - - o[ 4] = x1 >>> 0 & 0xff; - o[ 5] = x1 >>> 8 & 0xff; - o[ 6] = x1 >>> 16 & 0xff; - o[ 7] = x1 >>> 24 & 0xff; - - o[ 8] = x2 >>> 0 & 0xff; - o[ 9] = x2 >>> 8 & 0xff; - o[10] = x2 >>> 16 & 0xff; - o[11] = x2 >>> 24 & 0xff; - - o[12] = x3 >>> 0 & 0xff; - o[13] = x3 >>> 8 & 0xff; - o[14] = x3 >>> 16 & 0xff; - o[15] = x3 >>> 24 & 0xff; - - o[16] = x4 >>> 0 & 0xff; - o[17] = x4 >>> 8 & 0xff; - o[18] = x4 >>> 16 & 0xff; - o[19] = x4 >>> 24 & 0xff; - - o[20] = x5 >>> 0 & 0xff; - o[21] = x5 >>> 8 & 0xff; - o[22] = x5 >>> 16 & 0xff; - o[23] = x5 >>> 24 & 0xff; - - o[24] = x6 >>> 0 & 0xff; - o[25] = x6 >>> 8 & 0xff; - o[26] = x6 >>> 16 & 0xff; - o[27] = x6 >>> 24 & 0xff; - - o[28] = x7 >>> 0 & 0xff; - o[29] = x7 >>> 8 & 0xff; - o[30] = x7 >>> 16 & 0xff; - o[31] = x7 >>> 24 & 0xff; - - o[32] = x8 >>> 0 & 0xff; - o[33] = x8 >>> 8 & 0xff; - o[34] = x8 >>> 16 & 0xff; - o[35] = x8 >>> 24 & 0xff; - - o[36] = x9 >>> 0 & 0xff; - o[37] = x9 >>> 8 & 0xff; - o[38] = x9 >>> 16 & 0xff; - o[39] = x9 >>> 24 & 0xff; - - o[40] = x10 >>> 0 & 0xff; - o[41] = x10 >>> 8 & 0xff; - o[42] = x10 >>> 16 & 0xff; - o[43] = x10 >>> 24 & 0xff; - - o[44] = x11 >>> 0 & 0xff; - o[45] = x11 >>> 8 & 0xff; - o[46] = x11 >>> 16 & 0xff; - o[47] = x11 >>> 24 & 0xff; - - o[48] = x12 >>> 0 & 0xff; - o[49] = x12 >>> 8 & 0xff; - o[50] = x12 >>> 16 & 0xff; - o[51] = x12 >>> 24 & 0xff; - - o[52] = x13 >>> 0 & 0xff; - o[53] = x13 >>> 8 & 0xff; - o[54] = x13 >>> 16 & 0xff; - o[55] = x13 >>> 24 & 0xff; - - o[56] = x14 >>> 0 & 0xff; - o[57] = x14 >>> 8 & 0xff; - o[58] = x14 >>> 16 & 0xff; - o[59] = x14 >>> 24 & 0xff; - - o[60] = x15 >>> 0 & 0xff; - o[61] = x15 >>> 8 & 0xff; - o[62] = x15 >>> 16 & 0xff; - o[63] = x15 >>> 24 & 0xff; -} - -function core_hsalsa20(o,p,k,c) { - var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, - j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, - j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, - j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, - j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, - j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, - j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, - j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, - j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, - j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, - j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, - j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, - j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, - j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, - j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, - j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; - - var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, - x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, - x15 = j15, u; - - for (var i = 0; i < 20; i += 2) { - u = x0 + x12 | 0; - x4 ^= u<<7 | u>>>(32-7); - u = x4 + x0 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x4 | 0; - x12 ^= u<<13 | u>>>(32-13); - u = x12 + x8 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x1 | 0; - x9 ^= u<<7 | u>>>(32-7); - u = x9 + x5 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x9 | 0; - x1 ^= u<<13 | u>>>(32-13); - u = x1 + x13 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x6 | 0; - x14 ^= u<<7 | u>>>(32-7); - u = x14 + x10 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x14 | 0; - x6 ^= u<<13 | u>>>(32-13); - u = x6 + x2 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x11 | 0; - x3 ^= u<<7 | u>>>(32-7); - u = x3 + x15 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x3 | 0; - x11 ^= u<<13 | u>>>(32-13); - u = x11 + x7 | 0; - x15 ^= u<<18 | u>>>(32-18); - - u = x0 + x3 | 0; - x1 ^= u<<7 | u>>>(32-7); - u = x1 + x0 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x1 | 0; - x3 ^= u<<13 | u>>>(32-13); - u = x3 + x2 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x4 | 0; - x6 ^= u<<7 | u>>>(32-7); - u = x6 + x5 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x6 | 0; - x4 ^= u<<13 | u>>>(32-13); - u = x4 + x7 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x9 | 0; - x11 ^= u<<7 | u>>>(32-7); - u = x11 + x10 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x11 | 0; - x9 ^= u<<13 | u>>>(32-13); - u = x9 + x8 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x14 | 0; - x12 ^= u<<7 | u>>>(32-7); - u = x12 + x15 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x12 | 0; - x14 ^= u<<13 | u>>>(32-13); - u = x14 + x13 | 0; - x15 ^= u<<18 | u>>>(32-18); - } - - o[ 0] = x0 >>> 0 & 0xff; - o[ 1] = x0 >>> 8 & 0xff; - o[ 2] = x0 >>> 16 & 0xff; - o[ 3] = x0 >>> 24 & 0xff; - - o[ 4] = x5 >>> 0 & 0xff; - o[ 5] = x5 >>> 8 & 0xff; - o[ 6] = x5 >>> 16 & 0xff; - o[ 7] = x5 >>> 24 & 0xff; - - o[ 8] = x10 >>> 0 & 0xff; - o[ 9] = x10 >>> 8 & 0xff; - o[10] = x10 >>> 16 & 0xff; - o[11] = x10 >>> 24 & 0xff; - - o[12] = x15 >>> 0 & 0xff; - o[13] = x15 >>> 8 & 0xff; - o[14] = x15 >>> 16 & 0xff; - o[15] = x15 >>> 24 & 0xff; - - o[16] = x6 >>> 0 & 0xff; - o[17] = x6 >>> 8 & 0xff; - o[18] = x6 >>> 16 & 0xff; - o[19] = x6 >>> 24 & 0xff; - - o[20] = x7 >>> 0 & 0xff; - o[21] = x7 >>> 8 & 0xff; - o[22] = x7 >>> 16 & 0xff; - o[23] = x7 >>> 24 & 0xff; - - o[24] = x8 >>> 0 & 0xff; - o[25] = x8 >>> 8 & 0xff; - o[26] = x8 >>> 16 & 0xff; - o[27] = x8 >>> 24 & 0xff; - - o[28] = x9 >>> 0 & 0xff; - o[29] = x9 >>> 8 & 0xff; - o[30] = x9 >>> 16 & 0xff; - o[31] = x9 >>> 24 & 0xff; -} - -function crypto_core_salsa20(out,inp,k,c) { - core_salsa20(out,inp,k,c); -} - -function crypto_core_hsalsa20(out,inp,k,c) { - core_hsalsa20(out,inp,k,c); -} - -var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]); - // "expand 32-byte k" - -function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) { - var z = new Uint8Array(16), x = new Uint8Array(64); - var u, i; - for (i = 0; i < 16; i++) z[i] = 0; - for (i = 0; i < 8; i++) z[i] = n[i]; - while (b >= 64) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i]; - u = 1; - for (i = 8; i < 16; i++) { - u = u + (z[i] & 0xff) | 0; - z[i] = u & 0xff; - u >>>= 8; - } - b -= 64; - cpos += 64; - mpos += 64; - } - if (b > 0) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i]; - } - return 0; -} - -function crypto_stream_salsa20(c,cpos,b,n,k) { - var z = new Uint8Array(16), x = new Uint8Array(64); - var u, i; - for (i = 0; i < 16; i++) z[i] = 0; - for (i = 0; i < 8; i++) z[i] = n[i]; - while (b >= 64) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < 64; i++) c[cpos+i] = x[i]; - u = 1; - for (i = 8; i < 16; i++) { - u = u + (z[i] & 0xff) | 0; - z[i] = u & 0xff; - u >>>= 8; - } - b -= 64; - cpos += 64; - } - if (b > 0) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < b; i++) c[cpos+i] = x[i]; - } - return 0; -} - -function crypto_stream(c,cpos,d,n,k) { - var s = new Uint8Array(32); - crypto_core_hsalsa20(s,n,k,sigma); - var sn = new Uint8Array(8); - for (var i = 0; i < 8; i++) sn[i] = n[i+16]; - return crypto_stream_salsa20(c,cpos,d,sn,s); -} - -function crypto_stream_xor(c,cpos,m,mpos,d,n,k) { - var s = new Uint8Array(32); - crypto_core_hsalsa20(s,n,k,sigma); - var sn = new Uint8Array(8); - for (var i = 0; i < 8; i++) sn[i] = n[i+16]; - return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s); -} - -/* -* Port of Andrew Moon's Poly1305-donna-16. Public domain. -* https://github.com/floodyberry/poly1305-donna -*/ - -var poly1305 = function(key) { - this.buffer = new Uint8Array(16); - this.r = new Uint16Array(10); - this.h = new Uint16Array(10); - this.pad = new Uint16Array(8); - this.leftover = 0; - this.fin = 0; - - var t0, t1, t2, t3, t4, t5, t6, t7; - - t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff; - t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff; - t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03; - t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff; - t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff; - this.r[5] = ((t4 >>> 1)) & 0x1ffe; - t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff; - t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81; - t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff; - this.r[9] = ((t7 >>> 5)) & 0x007f; - - this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8; - this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8; - this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8; - this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8; - this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8; - this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8; - this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8; - this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8; -}; - -poly1305.prototype.blocks = function(m, mpos, bytes) { - var hibit = this.fin ? 0 : (1 << 11); - var t0, t1, t2, t3, t4, t5, t6, t7, c; - var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9; - - var h0 = this.h[0], - h1 = this.h[1], - h2 = this.h[2], - h3 = this.h[3], - h4 = this.h[4], - h5 = this.h[5], - h6 = this.h[6], - h7 = this.h[7], - h8 = this.h[8], - h9 = this.h[9]; - - var r0 = this.r[0], - r1 = this.r[1], - r2 = this.r[2], - r3 = this.r[3], - r4 = this.r[4], - r5 = this.r[5], - r6 = this.r[6], - r7 = this.r[7], - r8 = this.r[8], - r9 = this.r[9]; - - while (bytes >= 16) { - t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff; - t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff; - t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff; - t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff; - t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff; - h5 += ((t4 >>> 1)) & 0x1fff; - t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff; - t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff; - t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff; - h9 += ((t7 >>> 5)) | hibit; - - c = 0; - - d0 = c; - d0 += h0 * r0; - d0 += h1 * (5 * r9); - d0 += h2 * (5 * r8); - d0 += h3 * (5 * r7); - d0 += h4 * (5 * r6); - c = (d0 >>> 13); d0 &= 0x1fff; - d0 += h5 * (5 * r5); - d0 += h6 * (5 * r4); - d0 += h7 * (5 * r3); - d0 += h8 * (5 * r2); - d0 += h9 * (5 * r1); - c += (d0 >>> 13); d0 &= 0x1fff; - - d1 = c; - d1 += h0 * r1; - d1 += h1 * r0; - d1 += h2 * (5 * r9); - d1 += h3 * (5 * r8); - d1 += h4 * (5 * r7); - c = (d1 >>> 13); d1 &= 0x1fff; - d1 += h5 * (5 * r6); - d1 += h6 * (5 * r5); - d1 += h7 * (5 * r4); - d1 += h8 * (5 * r3); - d1 += h9 * (5 * r2); - c += (d1 >>> 13); d1 &= 0x1fff; - - d2 = c; - d2 += h0 * r2; - d2 += h1 * r1; - d2 += h2 * r0; - d2 += h3 * (5 * r9); - d2 += h4 * (5 * r8); - c = (d2 >>> 13); d2 &= 0x1fff; - d2 += h5 * (5 * r7); - d2 += h6 * (5 * r6); - d2 += h7 * (5 * r5); - d2 += h8 * (5 * r4); - d2 += h9 * (5 * r3); - c += (d2 >>> 13); d2 &= 0x1fff; - - d3 = c; - d3 += h0 * r3; - d3 += h1 * r2; - d3 += h2 * r1; - d3 += h3 * r0; - d3 += h4 * (5 * r9); - c = (d3 >>> 13); d3 &= 0x1fff; - d3 += h5 * (5 * r8); - d3 += h6 * (5 * r7); - d3 += h7 * (5 * r6); - d3 += h8 * (5 * r5); - d3 += h9 * (5 * r4); - c += (d3 >>> 13); d3 &= 0x1fff; - - d4 = c; - d4 += h0 * r4; - d4 += h1 * r3; - d4 += h2 * r2; - d4 += h3 * r1; - d4 += h4 * r0; - c = (d4 >>> 13); d4 &= 0x1fff; - d4 += h5 * (5 * r9); - d4 += h6 * (5 * r8); - d4 += h7 * (5 * r7); - d4 += h8 * (5 * r6); - d4 += h9 * (5 * r5); - c += (d4 >>> 13); d4 &= 0x1fff; - - d5 = c; - d5 += h0 * r5; - d5 += h1 * r4; - d5 += h2 * r3; - d5 += h3 * r2; - d5 += h4 * r1; - c = (d5 >>> 13); d5 &= 0x1fff; - d5 += h5 * r0; - d5 += h6 * (5 * r9); - d5 += h7 * (5 * r8); - d5 += h8 * (5 * r7); - d5 += h9 * (5 * r6); - c += (d5 >>> 13); d5 &= 0x1fff; - - d6 = c; - d6 += h0 * r6; - d6 += h1 * r5; - d6 += h2 * r4; - d6 += h3 * r3; - d6 += h4 * r2; - c = (d6 >>> 13); d6 &= 0x1fff; - d6 += h5 * r1; - d6 += h6 * r0; - d6 += h7 * (5 * r9); - d6 += h8 * (5 * r8); - d6 += h9 * (5 * r7); - c += (d6 >>> 13); d6 &= 0x1fff; - - d7 = c; - d7 += h0 * r7; - d7 += h1 * r6; - d7 += h2 * r5; - d7 += h3 * r4; - d7 += h4 * r3; - c = (d7 >>> 13); d7 &= 0x1fff; - d7 += h5 * r2; - d7 += h6 * r1; - d7 += h7 * r0; - d7 += h8 * (5 * r9); - d7 += h9 * (5 * r8); - c += (d7 >>> 13); d7 &= 0x1fff; - - d8 = c; - d8 += h0 * r8; - d8 += h1 * r7; - d8 += h2 * r6; - d8 += h3 * r5; - d8 += h4 * r4; - c = (d8 >>> 13); d8 &= 0x1fff; - d8 += h5 * r3; - d8 += h6 * r2; - d8 += h7 * r1; - d8 += h8 * r0; - d8 += h9 * (5 * r9); - c += (d8 >>> 13); d8 &= 0x1fff; - - d9 = c; - d9 += h0 * r9; - d9 += h1 * r8; - d9 += h2 * r7; - d9 += h3 * r6; - d9 += h4 * r5; - c = (d9 >>> 13); d9 &= 0x1fff; - d9 += h5 * r4; - d9 += h6 * r3; - d9 += h7 * r2; - d9 += h8 * r1; - d9 += h9 * r0; - c += (d9 >>> 13); d9 &= 0x1fff; - - c = (((c << 2) + c)) | 0; - c = (c + d0) | 0; - d0 = c & 0x1fff; - c = (c >>> 13); - d1 += c; - - h0 = d0; - h1 = d1; - h2 = d2; - h3 = d3; - h4 = d4; - h5 = d5; - h6 = d6; - h7 = d7; - h8 = d8; - h9 = d9; - - mpos += 16; - bytes -= 16; - } - this.h[0] = h0; - this.h[1] = h1; - this.h[2] = h2; - this.h[3] = h3; - this.h[4] = h4; - this.h[5] = h5; - this.h[6] = h6; - this.h[7] = h7; - this.h[8] = h8; - this.h[9] = h9; -}; - -poly1305.prototype.finish = function(mac, macpos) { - var g = new Uint16Array(10); - var c, mask, f, i; - - if (this.leftover) { - i = this.leftover; - this.buffer[i++] = 1; - for (; i < 16; i++) this.buffer[i] = 0; - this.fin = 1; - this.blocks(this.buffer, 0, 16); - } - - c = this.h[1] >>> 13; - this.h[1] &= 0x1fff; - for (i = 2; i < 10; i++) { - this.h[i] += c; - c = this.h[i] >>> 13; - this.h[i] &= 0x1fff; - } - this.h[0] += (c * 5); - c = this.h[0] >>> 13; - this.h[0] &= 0x1fff; - this.h[1] += c; - c = this.h[1] >>> 13; - this.h[1] &= 0x1fff; - this.h[2] += c; - - g[0] = this.h[0] + 5; - c = g[0] >>> 13; - g[0] &= 0x1fff; - for (i = 1; i < 10; i++) { - g[i] = this.h[i] + c; - c = g[i] >>> 13; - g[i] &= 0x1fff; - } - g[9] -= (1 << 13); - - mask = (c ^ 1) - 1; - for (i = 0; i < 10; i++) g[i] &= mask; - mask = ~mask; - for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]; - - this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff; - this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff; - this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff; - this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff; - this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff; - this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff; - this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff; - this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff; - - f = this.h[0] + this.pad[0]; - this.h[0] = f & 0xffff; - for (i = 1; i < 8; i++) { - f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0; - this.h[i] = f & 0xffff; - } - - mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff; - mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff; - mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff; - mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff; - mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff; - mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff; - mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff; - mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff; - mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff; - mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff; - mac[macpos+10] = (this.h[5] >>> 0) & 0xff; - mac[macpos+11] = (this.h[5] >>> 8) & 0xff; - mac[macpos+12] = (this.h[6] >>> 0) & 0xff; - mac[macpos+13] = (this.h[6] >>> 8) & 0xff; - mac[macpos+14] = (this.h[7] >>> 0) & 0xff; - mac[macpos+15] = (this.h[7] >>> 8) & 0xff; -}; - -poly1305.prototype.update = function(m, mpos, bytes) { - var i, want; - - if (this.leftover) { - want = (16 - this.leftover); - if (want > bytes) - want = bytes; - for (i = 0; i < want; i++) - this.buffer[this.leftover + i] = m[mpos+i]; - bytes -= want; - mpos += want; - this.leftover += want; - if (this.leftover < 16) - return; - this.blocks(this.buffer, 0, 16); - this.leftover = 0; - } - - if (bytes >= 16) { - want = bytes - (bytes % 16); - this.blocks(m, mpos, want); - mpos += want; - bytes -= want; - } - - if (bytes) { - for (i = 0; i < bytes; i++) - this.buffer[this.leftover + i] = m[mpos+i]; - this.leftover += bytes; - } -}; - -function crypto_onetimeauth(out, outpos, m, mpos, n, k) { - var s = new poly1305(k); - s.update(m, mpos, n); - s.finish(out, outpos); - return 0; -} - -function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) { - var x = new Uint8Array(16); - crypto_onetimeauth(x,0,m,mpos,n,k); - return crypto_verify_16(h,hpos,x,0); -} - -function crypto_secretbox(c,m,d,n,k) { - var i; - if (d < 32) return -1; - crypto_stream_xor(c,0,m,0,d,n,k); - crypto_onetimeauth(c, 16, c, 32, d - 32, c); - for (i = 0; i < 16; i++) c[i] = 0; - return 0; -} - -function crypto_secretbox_open(m,c,d,n,k) { - var i; - var x = new Uint8Array(32); - if (d < 32) return -1; - crypto_stream(x,0,32,n,k); - if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1; - crypto_stream_xor(m,0,c,0,d,n,k); - for (i = 0; i < 32; i++) m[i] = 0; - return 0; -} - -function set25519(r, a) { - var i; - for (i = 0; i < 16; i++) r[i] = a[i]|0; -} - -function car25519(o) { - var i, v, c = 1; - for (i = 0; i < 16; i++) { - v = o[i] + c + 65535; - c = Math.floor(v / 65536); - o[i] = v - c * 65536; - } - o[0] += c-1 + 37 * (c-1); -} - -function sel25519(p, q, b) { - var t, c = ~(b-1); - for (var i = 0; i < 16; i++) { - t = c & (p[i] ^ q[i]); - p[i] ^= t; - q[i] ^= t; - } -} - -function pack25519(o, n) { - var i, j, b; - var m = gf(), t = gf(); - for (i = 0; i < 16; i++) t[i] = n[i]; - car25519(t); - car25519(t); - car25519(t); - for (j = 0; j < 2; j++) { - m[0] = t[0] - 0xffed; - for (i = 1; i < 15; i++) { - m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1); - m[i-1] &= 0xffff; - } - m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1); - b = (m[15]>>16) & 1; - m[14] &= 0xffff; - sel25519(t, m, 1-b); - } - for (i = 0; i < 16; i++) { - o[2*i] = t[i] & 0xff; - o[2*i+1] = t[i]>>8; - } -} - -function neq25519(a, b) { - var c = new Uint8Array(32), d = new Uint8Array(32); - pack25519(c, a); - pack25519(d, b); - return crypto_verify_32(c, 0, d, 0); -} - -function par25519(a) { - var d = new Uint8Array(32); - pack25519(d, a); - return d[0] & 1; -} - -function unpack25519(o, n) { - var i; - for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8); - o[15] &= 0x7fff; -} - -function A(o, a, b) { - for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]; -} - -function Z(o, a, b) { - for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]; -} - -function M(o, a, b) { - var v, c, - t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, - t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, - t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, - t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, - b0 = b[0], - b1 = b[1], - b2 = b[2], - b3 = b[3], - b4 = b[4], - b5 = b[5], - b6 = b[6], - b7 = b[7], - b8 = b[8], - b9 = b[9], - b10 = b[10], - b11 = b[11], - b12 = b[12], - b13 = b[13], - b14 = b[14], - b15 = b[15]; +function M(o, a, b) { + var v, c, + t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, + t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, + t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, + t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, + b0 = b[0], + b1 = b[1], + b2 = b[2], + b3 = b[3], + b4 = b[4], + b5 = b[5], + b6 = b[6], + b7 = b[7], + b8 = b[8], + b9 = b[9], + b10 = b[10], + b11 = b[11], + b12 = b[12], + b13 = b[13], + b14 = b[14], + b15 = b[15]; v = a[0]; t0 += v * b0; @@ -4265,1263 +1328,3296 @@ function M(o, a, b) { t29 += v * b14; t30 += v * b15; - t0 += 38 * t16; - t1 += 38 * t17; - t2 += 38 * t18; - t3 += 38 * t19; - t4 += 38 * t20; - t5 += 38 * t21; - t6 += 38 * t22; - t7 += 38 * t23; - t8 += 38 * t24; - t9 += 38 * t25; - t10 += 38 * t26; - t11 += 38 * t27; - t12 += 38 * t28; - t13 += 38 * t29; - t14 += 38 * t30; - // t15 left as is + t0 += 38 * t16; + t1 += 38 * t17; + t2 += 38 * t18; + t3 += 38 * t19; + t4 += 38 * t20; + t5 += 38 * t21; + t6 += 38 * t22; + t7 += 38 * t23; + t8 += 38 * t24; + t9 += 38 * t25; + t10 += 38 * t26; + t11 += 38 * t27; + t12 += 38 * t28; + t13 += 38 * t29; + t14 += 38 * t30; + // t15 left as is + + // first car + c = 1; + v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; + v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; + v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; + v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; + v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; + v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; + v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; + v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; + v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; + v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; + v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; + v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; + v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; + v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; + v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; + v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; + t0 += c-1 + 37 * (c-1); + + // second car + c = 1; + v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; + v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; + v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; + v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; + v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; + v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; + v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; + v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; + v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; + v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; + v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; + v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; + v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; + v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; + v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; + v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; + t0 += c-1 + 37 * (c-1); + + o[ 0] = t0; + o[ 1] = t1; + o[ 2] = t2; + o[ 3] = t3; + o[ 4] = t4; + o[ 5] = t5; + o[ 6] = t6; + o[ 7] = t7; + o[ 8] = t8; + o[ 9] = t9; + o[10] = t10; + o[11] = t11; + o[12] = t12; + o[13] = t13; + o[14] = t14; + o[15] = t15; +} + +function S(o, a) { + M(o, a, a); +} + +function inv25519(o, i) { + var c = gf(); + var a; + for (a = 0; a < 16; a++) c[a] = i[a]; + for (a = 253; a >= 0; a--) { + S(c, c); + if(a !== 2 && a !== 4) M(c, c, i); + } + for (a = 0; a < 16; a++) o[a] = c[a]; +} + +function pow2523(o, i) { + var c = gf(); + var a; + for (a = 0; a < 16; a++) c[a] = i[a]; + for (a = 250; a >= 0; a--) { + S(c, c); + if(a !== 1) M(c, c, i); + } + for (a = 0; a < 16; a++) o[a] = c[a]; +} + +function crypto_scalarmult(q, n, p) { + var z = new Uint8Array(32); + var x = new Float64Array(80), r, i; + var a = gf(), b = gf(), c = gf(), + d = gf(), e = gf(), f = gf(); + for (i = 0; i < 31; i++) z[i] = n[i]; + z[31]=(n[31]&127)|64; + z[0]&=248; + unpack25519(x,p); + for (i = 0; i < 16; i++) { + b[i]=x[i]; + d[i]=a[i]=c[i]=0; + } + a[0]=d[0]=1; + for (i=254; i>=0; --i) { + r=(z[i>>>3]>>>(i&7))&1; + sel25519(a,b,r); + sel25519(c,d,r); + A(e,a,c); + Z(a,a,c); + A(c,b,d); + Z(b,b,d); + S(d,e); + S(f,a); + M(a,c,a); + M(c,b,e); + A(e,a,c); + Z(a,a,c); + S(b,a); + Z(c,d,f); + M(a,c,_121665); + A(a,a,d); + M(c,c,a); + M(a,d,f); + M(d,b,x); + S(b,e); + sel25519(a,b,r); + sel25519(c,d,r); + } + for (i = 0; i < 16; i++) { + x[i+16]=a[i]; + x[i+32]=c[i]; + x[i+48]=b[i]; + x[i+64]=d[i]; + } + var x32 = x.subarray(32); + var x16 = x.subarray(16); + inv25519(x32,x32); + M(x16,x16,x32); + pack25519(q,x16); + return 0; +} + +function crypto_scalarmult_base(q, n) { + return crypto_scalarmult(q, n, _9); +} + +function crypto_box_keypair(y, x) { + randombytes(x, 32); + return crypto_scalarmult_base(y, x); +} + +function crypto_box_beforenm(k, y, x) { + var s = new Uint8Array(32); + crypto_scalarmult(s, x, y); + return crypto_core_hsalsa20(k, _0, s, sigma); +} + +var crypto_box_afternm = crypto_secretbox; +var crypto_box_open_afternm = crypto_secretbox_open; + +function crypto_box(c, m, d, n, y, x) { + var k = new Uint8Array(32); + crypto_box_beforenm(k, y, x); + return crypto_box_afternm(c, m, d, n, k); +} + +function crypto_box_open(m, c, d, n, y, x) { + var k = new Uint8Array(32); + crypto_box_beforenm(k, y, x); + return crypto_box_open_afternm(m, c, d, n, k); +} + +var K = [ + 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, + 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, + 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, + 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, + 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, + 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, + 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, + 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, + 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, + 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, + 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, + 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, + 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, + 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, + 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, + 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, + 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, + 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, + 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, + 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, + 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, + 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, + 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, + 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, + 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, + 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, + 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, + 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, + 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, + 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, + 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, + 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, + 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, + 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, + 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, + 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, + 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, + 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, + 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, + 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 +]; + +function crypto_hashblocks_hl(hh, hl, m, n) { + var wh = new Int32Array(16), wl = new Int32Array(16), + bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, + bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, + th, tl, i, j, h, l, a, b, c, d; + + var ah0 = hh[0], + ah1 = hh[1], + ah2 = hh[2], + ah3 = hh[3], + ah4 = hh[4], + ah5 = hh[5], + ah6 = hh[6], + ah7 = hh[7], + + al0 = hl[0], + al1 = hl[1], + al2 = hl[2], + al3 = hl[3], + al4 = hl[4], + al5 = hl[5], + al6 = hl[6], + al7 = hl[7]; + + var pos = 0; + while (n >= 128) { + for (i = 0; i < 16; i++) { + j = 8 * i + pos; + wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3]; + wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7]; + } + for (i = 0; i < 80; i++) { + bh0 = ah0; + bh1 = ah1; + bh2 = ah2; + bh3 = ah3; + bh4 = ah4; + bh5 = ah5; + bh6 = ah6; + bh7 = ah7; + + bl0 = al0; + bl1 = al1; + bl2 = al2; + bl3 = al3; + bl4 = al4; + bl5 = al5; + bl6 = al6; + bl7 = al7; + + // add + h = ah7; + l = al7; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + // Sigma1 + h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32)))); + l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32)))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // Ch + h = (ah4 & ah5) ^ (~ah4 & ah6); + l = (al4 & al5) ^ (~al4 & al6); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // K + h = K[i*2]; + l = K[i*2+1]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // w + h = wh[i%16]; + l = wl[i%16]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + th = c & 0xffff | d << 16; + tl = a & 0xffff | b << 16; + + // add + h = th; + l = tl; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + // Sigma0 + h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32)))); + l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32)))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // Maj + h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + bh7 = (c & 0xffff) | (d << 16); + bl7 = (a & 0xffff) | (b << 16); + + // add + h = bh3; + l = bl3; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = th; + l = tl; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + bh3 = (c & 0xffff) | (d << 16); + bl3 = (a & 0xffff) | (b << 16); + + ah1 = bh0; + ah2 = bh1; + ah3 = bh2; + ah4 = bh3; + ah5 = bh4; + ah6 = bh5; + ah7 = bh6; + ah0 = bh7; + + al1 = bl0; + al2 = bl1; + al3 = bl2; + al4 = bl3; + al5 = bl4; + al6 = bl5; + al7 = bl6; + al0 = bl7; + + if (i%16 === 15) { + for (j = 0; j < 16; j++) { + // add + h = wh[j]; + l = wl[j]; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = wh[(j+9)%16]; + l = wl[(j+9)%16]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // sigma0 + th = wh[(j+1)%16]; + tl = wl[(j+1)%16]; + h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7); + l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // sigma1 + th = wh[(j+14)%16]; + tl = wl[(j+14)%16]; + h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6); + l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + wh[j] = (c & 0xffff) | (d << 16); + wl[j] = (a & 0xffff) | (b << 16); + } + } + } + + // add + h = ah0; + l = al0; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[0]; + l = hl[0]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[0] = ah0 = (c & 0xffff) | (d << 16); + hl[0] = al0 = (a & 0xffff) | (b << 16); + + h = ah1; + l = al1; - // first car - c = 1; - v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; - v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; - v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; - v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; - v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; - v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; - v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; - v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; - v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; - v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; - v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; - v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; - v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; - v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; - v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; - v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; - t0 += c-1 + 37 * (c-1); + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - // second car - c = 1; - v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; - v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; - v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; - v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; - v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; - v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; - v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; - v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; - v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; - v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; - v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; - v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; - v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; - v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; - v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; - v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; - t0 += c-1 + 37 * (c-1); + h = hh[1]; + l = hl[1]; - o[ 0] = t0; - o[ 1] = t1; - o[ 2] = t2; - o[ 3] = t3; - o[ 4] = t4; - o[ 5] = t5; - o[ 6] = t6; - o[ 7] = t7; - o[ 8] = t8; - o[ 9] = t9; - o[10] = t10; - o[11] = t11; - o[12] = t12; - o[13] = t13; - o[14] = t14; - o[15] = t15; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[1] = ah1 = (c & 0xffff) | (d << 16); + hl[1] = al1 = (a & 0xffff) | (b << 16); + + h = ah2; + l = al2; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[2]; + l = hl[2]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[2] = ah2 = (c & 0xffff) | (d << 16); + hl[2] = al2 = (a & 0xffff) | (b << 16); + + h = ah3; + l = al3; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[3]; + l = hl[3]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[3] = ah3 = (c & 0xffff) | (d << 16); + hl[3] = al3 = (a & 0xffff) | (b << 16); + + h = ah4; + l = al4; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[4]; + l = hl[4]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[4] = ah4 = (c & 0xffff) | (d << 16); + hl[4] = al4 = (a & 0xffff) | (b << 16); + + h = ah5; + l = al5; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[5]; + l = hl[5]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[5] = ah5 = (c & 0xffff) | (d << 16); + hl[5] = al5 = (a & 0xffff) | (b << 16); + + h = ah6; + l = al6; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[6]; + l = hl[6]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[6] = ah6 = (c & 0xffff) | (d << 16); + hl[6] = al6 = (a & 0xffff) | (b << 16); + + h = ah7; + l = al7; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[7]; + l = hl[7]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[7] = ah7 = (c & 0xffff) | (d << 16); + hl[7] = al7 = (a & 0xffff) | (b << 16); + + pos += 128; + n -= 128; + } + + return n; +} + +function crypto_hash(out, m, n) { + var hh = new Int32Array(8), + hl = new Int32Array(8), + x = new Uint8Array(256), + i, b = n; + + hh[0] = 0x6a09e667; + hh[1] = 0xbb67ae85; + hh[2] = 0x3c6ef372; + hh[3] = 0xa54ff53a; + hh[4] = 0x510e527f; + hh[5] = 0x9b05688c; + hh[6] = 0x1f83d9ab; + hh[7] = 0x5be0cd19; + + hl[0] = 0xf3bcc908; + hl[1] = 0x84caa73b; + hl[2] = 0xfe94f82b; + hl[3] = 0x5f1d36f1; + hl[4] = 0xade682d1; + hl[5] = 0x2b3e6c1f; + hl[6] = 0xfb41bd6b; + hl[7] = 0x137e2179; + + crypto_hashblocks_hl(hh, hl, m, n); + n %= 128; + + for (i = 0; i < n; i++) x[i] = m[b-n+i]; + x[n] = 128; + + n = 256-128*(n<112?1:0); + x[n-9] = 0; + ts64(x, n-8, (b / 0x20000000) | 0, b << 3); + crypto_hashblocks_hl(hh, hl, x, n); + + for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); + + return 0; } -function S(o, a) { - M(o, a, a); +function add(p, q) { + var a = gf(), b = gf(), c = gf(), + d = gf(), e = gf(), f = gf(), + g = gf(), h = gf(), t = gf(); + + Z(a, p[1], p[0]); + Z(t, q[1], q[0]); + M(a, a, t); + A(b, p[0], p[1]); + A(t, q[0], q[1]); + M(b, b, t); + M(c, p[3], q[3]); + M(c, c, D2); + M(d, p[2], q[2]); + A(d, d, d); + Z(e, b, a); + Z(f, d, c); + A(g, d, c); + A(h, b, a); + + M(p[0], e, f); + M(p[1], h, g); + M(p[2], g, f); + M(p[3], e, h); } -function inv25519(o, i) { - var c = gf(); - var a; - for (a = 0; a < 16; a++) c[a] = i[a]; - for (a = 253; a >= 0; a--) { - S(c, c); - if(a !== 2 && a !== 4) M(c, c, i); +function cswap(p, q, b) { + var i; + for (i = 0; i < 4; i++) { + sel25519(p[i], q[i], b); } - for (a = 0; a < 16; a++) o[a] = c[a]; } -function pow2523(o, i) { - var c = gf(); - var a; - for (a = 0; a < 16; a++) c[a] = i[a]; - for (a = 250; a >= 0; a--) { - S(c, c); - if(a !== 1) M(c, c, i); +function pack(r, p) { + var tx = gf(), ty = gf(), zi = gf(); + inv25519(zi, p[2]); + M(tx, p[0], zi); + M(ty, p[1], zi); + pack25519(r, ty); + r[31] ^= par25519(tx) << 7; +} + +function scalarmult(p, q, s) { + var b, i; + set25519(p[0], gf0); + set25519(p[1], gf1); + set25519(p[2], gf1); + set25519(p[3], gf0); + for (i = 255; i >= 0; --i) { + b = (s[(i/8)|0] >> (i&7)) & 1; + cswap(p, q, b); + add(q, p); + add(p, p); + cswap(p, q, b); } - for (a = 0; a < 16; a++) o[a] = c[a]; } -function crypto_scalarmult(q, n, p) { - var z = new Uint8Array(32); - var x = new Float64Array(80), r, i; - var a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(); - for (i = 0; i < 31; i++) z[i] = n[i]; - z[31]=(n[31]&127)|64; - z[0]&=248; - unpack25519(x,p); - for (i = 0; i < 16; i++) { - b[i]=x[i]; - d[i]=a[i]=c[i]=0; +function scalarbase(p, s) { + var q = [gf(), gf(), gf(), gf()]; + set25519(q[0], X); + set25519(q[1], Y); + set25519(q[2], gf1); + M(q[3], X, Y); + scalarmult(p, q, s); +} + +function crypto_sign_keypair(pk, sk, seeded) { + var d = new Uint8Array(64); + var p = [gf(), gf(), gf(), gf()]; + var i; + + if (!seeded) randombytes(sk, 32); + crypto_hash(d, sk, 32); + d[0] &= 248; + d[31] &= 127; + d[31] |= 64; + + scalarbase(p, d); + pack(pk, p); + + for (i = 0; i < 32; i++) sk[i+32] = pk[i]; + return 0; +} + +var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); + +function modL(r, x) { + var carry, i, j, k; + for (i = 63; i >= 32; --i) { + carry = 0; + for (j = i - 32, k = i - 12; j < k; ++j) { + x[j] += carry - 16 * x[i] * L[j - (i - 32)]; + carry = (x[j] + 128) >> 8; + x[j] -= carry * 256; + } + x[j] += carry; + x[i] = 0; } - a[0]=d[0]=1; - for (i=254; i>=0; --i) { - r=(z[i>>>3]>>>(i&7))&1; - sel25519(a,b,r); - sel25519(c,d,r); - A(e,a,c); - Z(a,a,c); - A(c,b,d); - Z(b,b,d); - S(d,e); - S(f,a); - M(a,c,a); - M(c,b,e); - A(e,a,c); - Z(a,a,c); - S(b,a); - Z(c,d,f); - M(a,c,_121665); - A(a,a,d); - M(c,c,a); - M(a,d,f); - M(d,b,x); - S(b,e); - sel25519(a,b,r); - sel25519(c,d,r); + carry = 0; + for (j = 0; j < 32; j++) { + x[j] += carry - (x[31] >> 4) * L[j]; + carry = x[j] >> 8; + x[j] &= 255; } - for (i = 0; i < 16; i++) { - x[i+16]=a[i]; - x[i+32]=c[i]; - x[i+48]=b[i]; - x[i+64]=d[i]; + for (j = 0; j < 32; j++) x[j] -= carry * L[j]; + for (i = 0; i < 32; i++) { + x[i+1] += x[i] >> 8; + r[i] = x[i] & 255; } - var x32 = x.subarray(32); - var x16 = x.subarray(16); - inv25519(x32,x32); - M(x16,x16,x32); - pack25519(q,x16); - return 0; } -function crypto_scalarmult_base(q, n) { - return crypto_scalarmult(q, n, _9); +function reduce(r) { + var x = new Float64Array(64), i; + for (i = 0; i < 64; i++) x[i] = r[i]; + for (i = 0; i < 64; i++) r[i] = 0; + modL(r, x); } -function crypto_box_keypair(y, x) { - randombytes(x, 32); - return crypto_scalarmult_base(y, x); -} +// Note: difference from C - smlen returned, not passed as argument. +function crypto_sign(sm, m, n, sk) { + var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); + var i, j, x = new Float64Array(64); + var p = [gf(), gf(), gf(), gf()]; -function crypto_box_beforenm(k, y, x) { - var s = new Uint8Array(32); - crypto_scalarmult(s, x, y); - return crypto_core_hsalsa20(k, _0, s, sigma); -} + crypto_hash(d, sk, 32); + d[0] &= 248; + d[31] &= 127; + d[31] |= 64; -var crypto_box_afternm = crypto_secretbox; -var crypto_box_open_afternm = crypto_secretbox_open; + var smlen = n + 64; + for (i = 0; i < n; i++) sm[64 + i] = m[i]; + for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]; -function crypto_box(c, m, d, n, y, x) { - var k = new Uint8Array(32); - crypto_box_beforenm(k, y, x); - return crypto_box_afternm(c, m, d, n, k); -} + crypto_hash(r, sm.subarray(32), n+32); + reduce(r); + scalarbase(p, r); + pack(sm, p); -function crypto_box_open(m, c, d, n, y, x) { - var k = new Uint8Array(32); - crypto_box_beforenm(k, y, x); - return crypto_box_open_afternm(m, c, d, n, k); + for (i = 32; i < 64; i++) sm[i] = sk[i]; + crypto_hash(h, sm, n + 64); + reduce(h); + + for (i = 0; i < 64; i++) x[i] = 0; + for (i = 0; i < 32; i++) x[i] = r[i]; + for (i = 0; i < 32; i++) { + for (j = 0; j < 32; j++) { + x[i+j] += h[i] * d[j]; + } + } + + modL(sm.subarray(32), x); + return smlen; } -var K = [ - 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, - 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, - 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, - 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, - 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, - 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, - 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, - 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, - 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, - 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, - 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, - 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, - 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, - 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, - 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, - 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, - 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, - 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, - 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, - 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, - 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, - 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, - 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, - 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, - 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, - 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, - 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, - 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, - 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, - 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, - 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, - 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, - 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, - 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, - 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, - 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, - 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, - 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, - 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, - 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 -]; +function unpackneg(r, p) { + var t = gf(), chk = gf(), num = gf(), + den = gf(), den2 = gf(), den4 = gf(), + den6 = gf(); -function crypto_hashblocks_hl(hh, hl, m, n) { - var wh = new Int32Array(16), wl = new Int32Array(16), - bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, - bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, - th, tl, i, j, h, l, a, b, c, d; + set25519(r[2], gf1); + unpack25519(r[1], p); + S(num, r[1]); + M(den, num, D); + Z(num, num, r[2]); + A(den, r[2], den); - var ah0 = hh[0], - ah1 = hh[1], - ah2 = hh[2], - ah3 = hh[3], - ah4 = hh[4], - ah5 = hh[5], - ah6 = hh[6], - ah7 = hh[7], + S(den2, den); + S(den4, den2); + M(den6, den4, den2); + M(t, den6, num); + M(t, t, den); - al0 = hl[0], - al1 = hl[1], - al2 = hl[2], - al3 = hl[3], - al4 = hl[4], - al5 = hl[5], - al6 = hl[6], - al7 = hl[7]; + pow2523(t, t); + M(t, t, num); + M(t, t, den); + M(t, t, den); + M(r[0], t, den); - var pos = 0; - while (n >= 128) { - for (i = 0; i < 16; i++) { - j = 8 * i + pos; - wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3]; - wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7]; - } - for (i = 0; i < 80; i++) { - bh0 = ah0; - bh1 = ah1; - bh2 = ah2; - bh3 = ah3; - bh4 = ah4; - bh5 = ah5; - bh6 = ah6; - bh7 = ah7; + S(chk, r[0]); + M(chk, chk, den); + if (neq25519(chk, num)) M(r[0], r[0], I); - bl0 = al0; - bl1 = al1; - bl2 = al2; - bl3 = al3; - bl4 = al4; - bl5 = al5; - bl6 = al6; - bl7 = al7; + S(chk, r[0]); + M(chk, chk, den); + if (neq25519(chk, num)) return -1; - // add - h = ah7; - l = al7; + if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]); - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + M(r[3], r[0], r[1]); + return 0; +} - // Sigma1 - h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32)))); - l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32)))); +function crypto_sign_open(m, sm, n, pk) { + var i, mlen; + var t = new Uint8Array(32), h = new Uint8Array(64); + var p = [gf(), gf(), gf(), gf()], + q = [gf(), gf(), gf(), gf()]; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + mlen = -1; + if (n < 64) return -1; - // Ch - h = (ah4 & ah5) ^ (~ah4 & ah6); - l = (al4 & al5) ^ (~al4 & al6); + if (unpackneg(q, pk)) return -1; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + for (i = 0; i < n; i++) m[i] = sm[i]; + for (i = 0; i < 32; i++) m[i+32] = pk[i]; + crypto_hash(h, m, n); + reduce(h); + scalarmult(p, q, h); - // K - h = K[i*2]; - l = K[i*2+1]; + scalarbase(q, sm.subarray(32)); + add(p, q); + pack(t, p); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + n -= 64; + if (crypto_verify_32(sm, 0, t, 0)) { + for (i = 0; i < n; i++) m[i] = 0; + return -1; + } - // w - h = wh[i%16]; - l = wl[i%16]; + for (i = 0; i < n; i++) m[i] = sm[i + 64]; + mlen = n; + return mlen; +} - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +var crypto_secretbox_KEYBYTES = 32, + crypto_secretbox_NONCEBYTES = 24, + crypto_secretbox_ZEROBYTES = 32, + crypto_secretbox_BOXZEROBYTES = 16, + crypto_scalarmult_BYTES = 32, + crypto_scalarmult_SCALARBYTES = 32, + crypto_box_PUBLICKEYBYTES = 32, + crypto_box_SECRETKEYBYTES = 32, + crypto_box_BEFORENMBYTES = 32, + crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, + crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, + crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, + crypto_sign_BYTES = 64, + crypto_sign_PUBLICKEYBYTES = 32, + crypto_sign_SECRETKEYBYTES = 64, + crypto_sign_SEEDBYTES = 32, + crypto_hash_BYTES = 64; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +nacl.lowlevel = { + crypto_core_hsalsa20: crypto_core_hsalsa20, + crypto_stream_xor: crypto_stream_xor, + crypto_stream: crypto_stream, + crypto_stream_salsa20_xor: crypto_stream_salsa20_xor, + crypto_stream_salsa20: crypto_stream_salsa20, + crypto_onetimeauth: crypto_onetimeauth, + crypto_onetimeauth_verify: crypto_onetimeauth_verify, + crypto_verify_16: crypto_verify_16, + crypto_verify_32: crypto_verify_32, + crypto_secretbox: crypto_secretbox, + crypto_secretbox_open: crypto_secretbox_open, + crypto_scalarmult: crypto_scalarmult, + crypto_scalarmult_base: crypto_scalarmult_base, + crypto_box_beforenm: crypto_box_beforenm, + crypto_box_afternm: crypto_box_afternm, + crypto_box: crypto_box, + crypto_box_open: crypto_box_open, + crypto_box_keypair: crypto_box_keypair, + crypto_hash: crypto_hash, + crypto_sign: crypto_sign, + crypto_sign_keypair: crypto_sign_keypair, + crypto_sign_open: crypto_sign_open, - th = c & 0xffff | d << 16; - tl = a & 0xffff | b << 16; + crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES, + crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES, + crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES, + crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES, + crypto_scalarmult_BYTES: crypto_scalarmult_BYTES, + crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES, + crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES, + crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES, + crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES, + crypto_box_NONCEBYTES: crypto_box_NONCEBYTES, + crypto_box_ZEROBYTES: crypto_box_ZEROBYTES, + crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES, + crypto_sign_BYTES: crypto_sign_BYTES, + crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES, + crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES, + crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES, + crypto_hash_BYTES: crypto_hash_BYTES +}; - // add - h = th; - l = tl; +/* High-level API */ - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +function checkLengths(k, n) { + if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size'); + if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size'); +} - // Sigma0 - h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32)))); - l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32)))); +function checkBoxLengths(pk, sk) { + if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size'); + if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size'); +} - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +function checkArrayTypes() { + for (var i = 0; i < arguments.length; i++) { + if (!(arguments[i] instanceof Uint8Array)) + throw new TypeError('unexpected type, use Uint8Array'); + } +} + +function cleanup(arr) { + for (var i = 0; i < arr.length; i++) arr[i] = 0; +} + +nacl.randomBytes = function(n) { + var b = new Uint8Array(n); + randombytes(b, n); + return b; +}; + +nacl.secretbox = function(msg, nonce, key) { + checkArrayTypes(msg, nonce, key); + checkLengths(key, nonce); + var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length); + var c = new Uint8Array(m.length); + for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i]; + crypto_secretbox(c, m, m.length, nonce, key); + return c.subarray(crypto_secretbox_BOXZEROBYTES); +}; + +nacl.secretbox.open = function(box, nonce, key) { + checkArrayTypes(box, nonce, key); + checkLengths(key, nonce); + var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length); + var m = new Uint8Array(c.length); + for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i]; + if (c.length < 32) return null; + if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null; + return m.subarray(crypto_secretbox_ZEROBYTES); +}; + +nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES; +nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES; +nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES; + +nacl.scalarMult = function(n, p) { + checkArrayTypes(n, p); + if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); + if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size'); + var q = new Uint8Array(crypto_scalarmult_BYTES); + crypto_scalarmult(q, n, p); + return q; +}; + +nacl.scalarMult.base = function(n) { + checkArrayTypes(n); + if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); + var q = new Uint8Array(crypto_scalarmult_BYTES); + crypto_scalarmult_base(q, n); + return q; +}; - // Maj - h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); - l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2); +nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES; +nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.box = function(msg, nonce, publicKey, secretKey) { + var k = nacl.box.before(publicKey, secretKey); + return nacl.secretbox(msg, nonce, k); +}; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +nacl.box.before = function(publicKey, secretKey) { + checkArrayTypes(publicKey, secretKey); + checkBoxLengths(publicKey, secretKey); + var k = new Uint8Array(crypto_box_BEFORENMBYTES); + crypto_box_beforenm(k, publicKey, secretKey); + return k; +}; - bh7 = (c & 0xffff) | (d << 16); - bl7 = (a & 0xffff) | (b << 16); +nacl.box.after = nacl.secretbox; - // add - h = bh3; - l = bl3; +nacl.box.open = function(msg, nonce, publicKey, secretKey) { + var k = nacl.box.before(publicKey, secretKey); + return nacl.secretbox.open(msg, nonce, k); +}; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +nacl.box.open.after = nacl.secretbox.open; - h = th; - l = tl; +nacl.box.keyPair = function() { + var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_box_SECRETKEYBYTES); + crypto_box_keypair(pk, sk); + return {publicKey: pk, secretKey: sk}; +}; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.box.keyPair.fromSecretKey = function(secretKey) { + checkArrayTypes(secretKey); + if (secretKey.length !== crypto_box_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); + crypto_scalarmult_base(pk, secretKey); + return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; +}; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES; +nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES; +nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES; +nacl.box.nonceLength = crypto_box_NONCEBYTES; +nacl.box.overheadLength = nacl.secretbox.overheadLength; - bh3 = (c & 0xffff) | (d << 16); - bl3 = (a & 0xffff) | (b << 16); +nacl.sign = function(msg, secretKey) { + checkArrayTypes(msg, secretKey); + if (secretKey.length !== crypto_sign_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length); + crypto_sign(signedMsg, msg, msg.length, secretKey); + return signedMsg; +}; - ah1 = bh0; - ah2 = bh1; - ah3 = bh2; - ah4 = bh3; - ah5 = bh4; - ah6 = bh5; - ah7 = bh6; - ah0 = bh7; +nacl.sign.open = function(signedMsg, publicKey) { + checkArrayTypes(signedMsg, publicKey); + if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) + throw new Error('bad public key size'); + var tmp = new Uint8Array(signedMsg.length); + var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey); + if (mlen < 0) return null; + var m = new Uint8Array(mlen); + for (var i = 0; i < m.length; i++) m[i] = tmp[i]; + return m; +}; - al1 = bl0; - al2 = bl1; - al3 = bl2; - al4 = bl3; - al5 = bl4; - al6 = bl5; - al7 = bl6; - al0 = bl7; +nacl.sign.detached = function(msg, secretKey) { + var signedMsg = nacl.sign(msg, secretKey); + var sig = new Uint8Array(crypto_sign_BYTES); + for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; + return sig; +}; - if (i%16 === 15) { - for (j = 0; j < 16; j++) { - // add - h = wh[j]; - l = wl[j]; +nacl.sign.detached.verify = function(msg, sig, publicKey) { + checkArrayTypes(msg, sig, publicKey); + if (sig.length !== crypto_sign_BYTES) + throw new Error('bad signature size'); + if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) + throw new Error('bad public key size'); + var sm = new Uint8Array(crypto_sign_BYTES + msg.length); + var m = new Uint8Array(crypto_sign_BYTES + msg.length); + var i; + for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]; + for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i]; + return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); +}; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +nacl.sign.keyPair = function() { + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); + crypto_sign_keypair(pk, sk); + return {publicKey: pk, secretKey: sk}; +}; - h = wh[(j+9)%16]; - l = wl[(j+9)%16]; +nacl.sign.keyPair.fromSecretKey = function(secretKey) { + checkArrayTypes(secretKey); + if (secretKey.length !== crypto_sign_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i]; + return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; +}; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.sign.keyPair.fromSeed = function(seed) { + checkArrayTypes(seed); + if (seed.length !== crypto_sign_SEEDBYTES) + throw new Error('bad seed size'); + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); + for (var i = 0; i < 32; i++) sk[i] = seed[i]; + crypto_sign_keypair(pk, sk, true); + return {publicKey: pk, secretKey: sk}; +}; - // sigma0 - th = wh[(j+1)%16]; - tl = wl[(j+1)%16]; - h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7); - l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7))); +nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; +nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; +nacl.sign.seedLength = crypto_sign_SEEDBYTES; +nacl.sign.signatureLength = crypto_sign_BYTES; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.hash = function(msg) { + checkArrayTypes(msg); + var h = new Uint8Array(crypto_hash_BYTES); + crypto_hash(h, msg, msg.length); + return h; +}; - // sigma1 - th = wh[(j+14)%16]; - tl = wl[(j+14)%16]; - h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6); - l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6))); +nacl.hash.hashLength = crypto_hash_BYTES; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.verify = function(x, y) { + checkArrayTypes(x, y); + // Zero length arguments are considered not equal. + if (x.length === 0 || y.length === 0) return false; + if (x.length !== y.length) return false; + return (vn(x, 0, y, 0, x.length) === 0) ? true : false; +}; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +nacl.setPRNG = function(fn) { + randombytes = fn; +}; - wh[j] = (c & 0xffff) | (d << 16); - wl[j] = (a & 0xffff) | (b << 16); - } +(function() { + // Initialize PRNG if environment provides CSPRNG. + // If not, methods calling randombytes will throw. + var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null; + if (crypto && crypto.getRandomValues) { + // Browsers. + var QUOTA = 65536; + nacl.setPRNG(function(x, n) { + var i, v = new Uint8Array(n); + for (i = 0; i < n; i += QUOTA) { + crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); } + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); + } else if (true) { + // Node.js. + crypto = __webpack_require__(3); + if (crypto && crypto.randomBytes) { + nacl.setPRNG(function(x, n) { + var i, v = crypto.randomBytes(n); + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); } + } +})(); - // add - h = ah0; - l = al0; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[0]; - l = hl[0]; +})( true && module.exports ? module.exports : (self.nacl = self.nacl || {})); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +/***/ }), +/* 1 */ +/***/ (function(module, exports, __webpack_require__) { - hh[0] = ah0 = (c & 0xffff) | (d << 16); - hl[0] = al0 = (a & 0xffff) | (b << 16); +// Written in 2014-2016 by Dmitry Chestnykh and Devi Mandiri. +// Public domain. +(function(root, f) { + 'use strict'; + if ( true && module.exports) module.exports = f(); + else if (root.nacl) root.nacl.util = f(); + else { + root.nacl = {}; + root.nacl.util = f(); + } +}(this, function() { + 'use strict'; - h = ah1; - l = al1; + var util = {}; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + function validateBase64(s) { + if (!(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(s))) { + throw new TypeError('invalid encoding'); + } + } - h = hh[1]; - l = hl[1]; + util.decodeUTF8 = function(s) { + if (typeof s !== 'string') throw new TypeError('expected string'); + var i, d = unescape(encodeURIComponent(s)), b = new Uint8Array(d.length); + for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); + return b; + }; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + util.encodeUTF8 = function(arr) { + var i, s = []; + for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i])); + return decodeURIComponent(escape(s.join(''))); + }; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + if (typeof atob === 'undefined') { + // Node.js - hh[1] = ah1 = (c & 0xffff) | (d << 16); - hl[1] = al1 = (a & 0xffff) | (b << 16); + if (typeof Buffer.from !== 'undefined') { + // Node v6 and later + util.encodeBase64 = function (arr) { // v6 and later + return Buffer.from(arr).toString('base64'); + }; - h = ah2; - l = al2; + util.decodeBase64 = function (s) { + validateBase64(s); + return new Uint8Array(Array.prototype.slice.call(Buffer.from(s, 'base64'), 0)); + }; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + } else { + // Node earlier than v6 + util.encodeBase64 = function (arr) { // v6 and later + return (new Buffer(arr)).toString('base64'); + }; - h = hh[2]; - l = hl[2]; + util.decodeBase64 = function(s) { + validateBase64(s); + return new Uint8Array(Array.prototype.slice.call(new Buffer(s, 'base64'), 0)); + }; + } - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + } else { + // Browsers - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + util.encodeBase64 = function(arr) { + var i, s = [], len = arr.length; + for (i = 0; i < len; i++) s.push(String.fromCharCode(arr[i])); + return btoa(s.join('')); + }; - hh[2] = ah2 = (c & 0xffff) | (d << 16); - hl[2] = al2 = (a & 0xffff) | (b << 16); + util.decodeBase64 = function(s) { + validateBase64(s); + var i, d = atob(s), b = new Uint8Array(d.length); + for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); + return b; + }; - h = ah3; - l = al3; + } - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + return util; - h = hh[3]; - l = hl[3]; +})); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +/***/ }), +/* 2 */ +/***/ (function(module, exports, __webpack_require__) { - hh[3] = ah3 = (c & 0xffff) | (d << 16); - hl[3] = al3 = (a & 0xffff) | (b << 16); +// required so we don't have to do require('pusher').default etc. +module.exports = __webpack_require__(4).default; - h = ah4; - l = al4; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +/***/ }), +/* 3 */ +/***/ (function(module, exports) { - h = hh[4]; - l = hl[4]; +/* (ignored) */ - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +/***/ }), +/* 4 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +"use strict"; +__webpack_require__.r(__webpack_exports__); - hh[4] = ah4 = (c & 0xffff) | (d << 16); - hl[4] = al4 = (a & 0xffff) | (b << 16); +// CONCATENATED MODULE: ./src/runtimes/web/dom/script_receiver_factory.ts +var ScriptReceiverFactory = (function () { + function ScriptReceiverFactory(prefix, name) { + this.lastId = 0; + this.prefix = prefix; + this.name = name; + } + ScriptReceiverFactory.prototype.create = function (callback) { + this.lastId++; + var number = this.lastId; + var id = this.prefix + number; + var name = this.name + "[" + number + "]"; + var called = false; + var callbackWrapper = function () { + if (!called) { + callback.apply(null, arguments); + called = true; + } + }; + this[number] = callbackWrapper; + return { number: number, id: id, name: name, callback: callbackWrapper }; + }; + ScriptReceiverFactory.prototype.remove = function (receiver) { + delete this[receiver.number]; + }; + return ScriptReceiverFactory; +}()); - h = ah5; - l = al5; +var ScriptReceivers = new ScriptReceiverFactory("_pusher_script_", "Pusher.ScriptReceivers"); - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +// CONCATENATED MODULE: ./src/core/defaults.ts +var Defaults = { + VERSION: "5.0.2", + PROTOCOL: 7, + host: 'ws.pusherapp.com', + ws_port: 80, + wss_port: 443, + ws_path: '', + sockjs_host: 'sockjs.pusher.com', + sockjs_http_port: 80, + sockjs_https_port: 443, + sockjs_path: '/pusher', + stats_host: 'stats.pusher.com', + channel_auth_endpoint: '/pusher/auth', + channel_auth_transport: 'ajax', + activity_timeout: 120000, + pong_timeout: 30000, + unavailable_timeout: 10000, + cdn_http: "http://js.pusher.com", + cdn_https: "https://js.pusher.com", + dependency_suffix: "" +}; +/* harmony default export */ var defaults = (Defaults); - h = hh[5]; - l = hl[5]; +// CONCATENATED MODULE: ./src/runtimes/web/dom/dependency_loader.ts - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +var dependency_loader_DependencyLoader = (function () { + function DependencyLoader(options) { + this.options = options; + this.receivers = options.receivers || ScriptReceivers; + this.loading = {}; + } + DependencyLoader.prototype.load = function (name, options, callback) { + var self = this; + if (self.loading[name] && self.loading[name].length > 0) { + self.loading[name].push(callback); + } + else { + self.loading[name] = [callback]; + var request = runtime.createScriptRequest(self.getPath(name, options)); + var receiver = self.receivers.create(function (error) { + self.receivers.remove(receiver); + if (self.loading[name]) { + var callbacks = self.loading[name]; + delete self.loading[name]; + var successCallback = function (wasSuccessful) { + if (!wasSuccessful) { + request.cleanup(); + } + }; + for (var i = 0; i < callbacks.length; i++) { + callbacks[i](error, successCallback); + } + } + }); + request.send(receiver); + } + }; + DependencyLoader.prototype.getRoot = function (options) { + var cdn; + var protocol = runtime.getDocument().location.protocol; + if ((options && options.useTLS) || protocol === "https:") { + cdn = this.options.cdn_https; + } + else { + cdn = this.options.cdn_http; + } + return cdn.replace(/\/*$/, "") + "/" + this.options.version; + }; + DependencyLoader.prototype.getPath = function (name, options) { + return this.getRoot(options) + '/' + name + this.options.suffix + '.js'; + }; + ; + return DependencyLoader; +}()); +/* harmony default export */ var dependency_loader = (dependency_loader_DependencyLoader); - hh[5] = ah5 = (c & 0xffff) | (d << 16); - hl[5] = al5 = (a & 0xffff) | (b << 16); +// CONCATENATED MODULE: ./src/runtimes/web/dom/dependencies.ts - h = ah6; - l = al6; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - h = hh[6]; - l = hl[6]; +var DependenciesReceivers = new ScriptReceiverFactory("_pusher_dependencies", "Pusher.DependenciesReceivers"); +var Dependencies = new dependency_loader({ + cdn_http: defaults.cdn_http, + cdn_https: defaults.cdn_https, + version: defaults.VERSION, + suffix: defaults.dependency_suffix, + receivers: DependenciesReceivers +}); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +// CONCATENATED MODULE: ./src/core/base64.ts +function encode(s) { + return btoa(utob(s)); +} +var fromCharCode = String.fromCharCode; +var b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; +var b64tab = {}; +for (var base64_i = 0, l = b64chars.length; base64_i < l; base64_i++) { + b64tab[b64chars.charAt(base64_i)] = base64_i; +} +var cb_utob = function (c) { + var cc = c.charCodeAt(0); + return cc < 0x80 + ? c + : cc < 0x800 + ? fromCharCode(0xc0 | (cc >>> 6)) + fromCharCode(0x80 | (cc & 0x3f)) + : fromCharCode(0xe0 | ((cc >>> 12) & 0x0f)) + + fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) + + fromCharCode(0x80 | (cc & 0x3f)); +}; +var utob = function (u) { + return u.replace(/[^\x00-\x7F]/g, cb_utob); +}; +var cb_encode = function (ccc) { + var padlen = [0, 2, 1][ccc.length % 3]; + var ord = (ccc.charCodeAt(0) << 16) | + ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8) | + (ccc.length > 2 ? ccc.charCodeAt(2) : 0); + var chars = [ + b64chars.charAt(ord >>> 18), + b64chars.charAt((ord >>> 12) & 63), + padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63), + padlen >= 1 ? '=' : b64chars.charAt(ord & 63) + ]; + return chars.join(''); +}; +var btoa = window.btoa || + function (b) { + return b.replace(/[\s\S]{1,3}/g, cb_encode); + }; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +// CONCATENATED MODULE: ./src/core/utils/timers/abstract_timer.ts +var Timer = (function () { + function Timer(set, clear, delay, callback) { + var _this = this; + this.clear = clear; + this.timer = set(function () { + if (_this.timer) { + _this.timer = callback(_this.timer); + } + }, delay); + } + Timer.prototype.isRunning = function () { + return this.timer !== null; + }; + Timer.prototype.ensureAborted = function () { + if (this.timer) { + this.clear(this.timer); + this.timer = null; + } + }; + return Timer; +}()); +/* harmony default export */ var abstract_timer = (Timer); - hh[6] = ah6 = (c & 0xffff) | (d << 16); - hl[6] = al6 = (a & 0xffff) | (b << 16); +// CONCATENATED MODULE: ./src/core/utils/timers/index.ts +var __extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); - h = ah7; - l = al7; +function timers_clearTimeout(timer) { + window.clearTimeout(timer); +} +function timers_clearInterval(timer) { + window.clearInterval(timer); +} +var OneOffTimer = (function (_super) { + __extends(OneOffTimer, _super); + function OneOffTimer(delay, callback) { + return _super.call(this, setTimeout, timers_clearTimeout, delay, function (timer) { + callback(); + return null; + }) || this; + } + return OneOffTimer; +}(abstract_timer)); - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +var PeriodicTimer = (function (_super) { + __extends(PeriodicTimer, _super); + function PeriodicTimer(delay, callback) { + return _super.call(this, setInterval, timers_clearInterval, delay, function (timer) { + callback(); + return timer; + }) || this; + } + return PeriodicTimer; +}(abstract_timer)); - h = hh[7]; - l = hl[7]; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +// CONCATENATED MODULE: ./src/core/util.ts - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +var Util = { + now: function () { + if (Date.now) { + return Date.now(); + } + else { + return new Date().valueOf(); + } + }, + defer: function (callback) { + return new OneOffTimer(0, callback); + }, + method: function (name) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + var boundArguments = Array.prototype.slice.call(arguments, 1); + return function (object) { + return object[name].apply(object, boundArguments.concat(arguments)); + }; + } +}; +/* harmony default export */ var util = (Util); - hh[7] = ah7 = (c & 0xffff) | (d << 16); - hl[7] = al7 = (a & 0xffff) | (b << 16); +// CONCATENATED MODULE: ./src/core/utils/collections.ts - pos += 128; - n -= 128; - } - return n; +function extend(target) { + var sources = []; + for (var _i = 1; _i < arguments.length; _i++) { + sources[_i - 1] = arguments[_i]; + } + for (var i = 0; i < sources.length; i++) { + var extensions = sources[i]; + for (var property in extensions) { + if (extensions[property] && extensions[property].constructor && + extensions[property].constructor === Object) { + target[property] = extend(target[property] || {}, extensions[property]); + } + else { + target[property] = extensions[property]; + } + } + } + return target; +} +function stringify() { + var m = ["Pusher"]; + for (var i = 0; i < arguments.length; i++) { + if (typeof arguments[i] === "string") { + m.push(arguments[i]); + } + else { + m.push(safeJSONStringify(arguments[i])); + } + } + return m.join(" : "); +} +function arrayIndexOf(array, item) { + var nativeIndexOf = Array.prototype.indexOf; + if (array === null) { + return -1; + } + if (nativeIndexOf && array.indexOf === nativeIndexOf) { + return array.indexOf(item); + } + for (var i = 0, l = array.length; i < l; i++) { + if (array[i] === item) { + return i; + } + } + return -1; +} +function objectApply(object, f) { + for (var key in object) { + if (Object.prototype.hasOwnProperty.call(object, key)) { + f(object[key], key, object); + } + } +} +function keys(object) { + var keys = []; + objectApply(object, function (_, key) { + keys.push(key); + }); + return keys; +} +function values(object) { + var values = []; + objectApply(object, function (value) { + values.push(value); + }); + return values; +} +function apply(array, f, context) { + for (var i = 0; i < array.length; i++) { + f.call(context || window, array[i], i, array); + } +} +function map(array, f) { + var result = []; + for (var i = 0; i < array.length; i++) { + result.push(f(array[i], i, array, result)); + } + return result; +} +function mapObject(object, f) { + var result = {}; + objectApply(object, function (value, key) { + result[key] = f(value); + }); + return result; +} +function filter(array, test) { + test = test || function (value) { return !!value; }; + var result = []; + for (var i = 0; i < array.length; i++) { + if (test(array[i], i, array, result)) { + result.push(array[i]); + } + } + return result; +} +function filterObject(object, test) { + var result = {}; + objectApply(object, function (value, key) { + if ((test && test(value, key, object, result)) || Boolean(value)) { + result[key] = value; + } + }); + return result; +} +function flatten(object) { + var result = []; + objectApply(object, function (value, key) { + result.push([key, value]); + }); + return result; +} +function any(array, test) { + for (var i = 0; i < array.length; i++) { + if (test(array[i], i, array)) { + return true; + } + } + return false; +} +function collections_all(array, test) { + for (var i = 0; i < array.length; i++) { + if (!test(array[i], i, array)) { + return false; + } + } + return true; +} +function encodeParamsObject(data) { + return mapObject(data, function (value) { + if (typeof value === "object") { + value = safeJSONStringify(value); + } + return encodeURIComponent(encode(value.toString())); + }); +} +function buildQueryString(data) { + var params = filterObject(data, function (value) { + return value !== undefined; + }); + var query = map(flatten(encodeParamsObject(params)), util.method("join", "=")).join("&"); + return query; +} +function decycleObject(object) { + var objects = [], paths = []; + return (function derez(value, path) { + var i, name, nu; + switch (typeof value) { + case 'object': + if (!value) { + return null; + } + for (i = 0; i < objects.length; i += 1) { + if (objects[i] === value) { + return { $ref: paths[i] }; + } + } + objects.push(value); + paths.push(path); + if (Object.prototype.toString.apply(value) === '[object Array]') { + nu = []; + for (i = 0; i < value.length; i += 1) { + nu[i] = derez(value[i], path + '[' + i + ']'); + } + } + else { + nu = {}; + for (name in value) { + if (Object.prototype.hasOwnProperty.call(value, name)) { + nu[name] = derez(value[name], path + '[' + JSON.stringify(name) + ']'); + } + } + } + return nu; + case 'number': + case 'string': + case 'boolean': + return value; + } + }(object, '$')); +} +function safeJSONStringify(source) { + try { + return JSON.stringify(source); + } + catch (e) { + return JSON.stringify(decycleObject(source)); + } } -function crypto_hash(out, m, n) { - var hh = new Int32Array(8), - hl = new Int32Array(8), - x = new Uint8Array(256), - i, b = n; - - hh[0] = 0x6a09e667; - hh[1] = 0xbb67ae85; - hh[2] = 0x3c6ef372; - hh[3] = 0xa54ff53a; - hh[4] = 0x510e527f; - hh[5] = 0x9b05688c; - hh[6] = 0x1f83d9ab; - hh[7] = 0x5be0cd19; - - hl[0] = 0xf3bcc908; - hl[1] = 0x84caa73b; - hl[2] = 0xfe94f82b; - hl[3] = 0x5f1d36f1; - hl[4] = 0xade682d1; - hl[5] = 0x2b3e6c1f; - hl[6] = 0xfb41bd6b; - hl[7] = 0x137e2179; +// CONCATENATED MODULE: ./src/core/logger.ts - crypto_hashblocks_hl(hh, hl, m, n); - n %= 128; - for (i = 0; i < n; i++) x[i] = m[b-n+i]; - x[n] = 128; +var Logger = { + debug: function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + if (!core_pusher.log) { + return; + } + core_pusher.log(stringify.apply(this, arguments)); + }, + warn: function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + var message = stringify.apply(this, arguments); + if (core_pusher.log) { + core_pusher.log(message); + } + else if (window.console) { + if (window.console.warn) { + window.console.warn(message); + } + else if (window.console.log) { + window.console.log(message); + } + } + } +}; +/* harmony default export */ var logger = (Logger); - n = 256-128*(n<112?1:0); - x[n-9] = 0; - ts64(x, n-8, (b / 0x20000000) | 0, b << 3); - crypto_hashblocks_hl(hh, hl, x, n); +// CONCATENATED MODULE: ./src/core/utils/url_store.ts +var urlStore = { + baseUrl: "https://pusher.com", + urls: { + authenticationEndpoint: { + path: "/docs/authenticating_users", + }, + javascriptQuickStart: { + path: "/docs/javascript_quick_start" + }, + triggeringClientEvents: { + path: "/docs/client_api_guide/client_events#trigger-events" + } + } +}; +var buildLogSuffix = function (key) { + var urlPrefix = "See:"; + var urlObj = urlStore.urls[key]; + if (!urlObj) + return ""; + var url; + if (urlObj.fullUrl) { + url = urlObj.fullUrl; + } + else if (urlObj.path) { + url = urlStore.baseUrl + urlObj.path; + } + if (!url) + return ""; + return urlPrefix + " " + url; +}; +/* harmony default export */ var url_store = ({ buildLogSuffix: buildLogSuffix }); - for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); +// CONCATENATED MODULE: ./src/runtimes/isomorphic/auth/xhr_auth.ts - return 0; -} -function add(p, q) { - var a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(), - g = gf(), h = gf(), t = gf(); - Z(a, p[1], p[0]); - Z(t, q[1], q[0]); - M(a, a, t); - A(b, p[0], p[1]); - A(t, q[0], q[1]); - M(b, b, t); - M(c, p[3], q[3]); - M(c, c, D2); - M(d, p[2], q[2]); - A(d, d, d); - Z(e, b, a); - Z(f, d, c); - A(g, d, c); - A(h, b, a); +var ajax = function (context, socketId, callback) { + var self = this, xhr; + xhr = runtime.createXHR(); + xhr.open("POST", self.options.authEndpoint, true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + for (var headerName in this.authOptions.headers) { + xhr.setRequestHeader(headerName, this.authOptions.headers[headerName]); + } + xhr.onreadystatechange = function () { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + var data, parsed = false; + try { + data = JSON.parse(xhr.responseText); + parsed = true; + } + catch (e) { + callback(true, 'JSON returned from webapp was invalid, yet status code was 200. Data was: ' + xhr.responseText); + } + if (parsed) { + callback(false, data); + } + } + else { + var suffix = url_store.buildLogSuffix("authenticationEndpoint"); + logger.warn('Unable to retrieve auth string from auth endpoint - ' + + ("received status " + xhr.status + " from " + self.options.authEndpoint + ". ") + + ("Clients must be authenticated to join private or presence channels. " + suffix)); + callback(true, xhr.status); + } + } + }; + xhr.send(this.composeQuery(socketId)); + return xhr; +}; +/* harmony default export */ var xhr_auth = (ajax); - M(p[0], e, f); - M(p[1], h, g); - M(p[2], g, f); - M(p[3], e, h); -} +// CONCATENATED MODULE: ./src/runtimes/web/auth/jsonp_auth.ts -function cswap(p, q, b) { - var i; - for (i = 0; i < 4; i++) { - sel25519(p[i], q[i], b); - } -} +var jsonp = function (context, socketId, callback) { + if (this.authOptions.headers !== undefined) { + logger.warn("Warn", "To send headers with the auth request, you must use AJAX, rather than JSONP."); + } + var callbackName = context.nextAuthCallbackID.toString(); + context.nextAuthCallbackID++; + var document = context.getDocument(); + var script = document.createElement("script"); + context.auth_callbacks[callbackName] = function (data) { + callback(false, data); + }; + var callback_name = "Pusher.auth_callbacks['" + callbackName + "']"; + script.src = this.options.authEndpoint + + '?callback=' + + encodeURIComponent(callback_name) + + '&' + + this.composeQuery(socketId); + var head = document.getElementsByTagName("head")[0] || document.documentElement; + head.insertBefore(script, head.firstChild); +}; +/* harmony default export */ var jsonp_auth = (jsonp); -function pack(r, p) { - var tx = gf(), ty = gf(), zi = gf(); - inv25519(zi, p[2]); - M(tx, p[0], zi); - M(ty, p[1], zi); - pack25519(r, ty); - r[31] ^= par25519(tx) << 7; -} +// CONCATENATED MODULE: ./src/runtimes/web/dom/script_request.ts +var ScriptRequest = (function () { + function ScriptRequest(src) { + this.src = src; + } + ScriptRequest.prototype.send = function (receiver) { + var self = this; + var errorString = "Error loading " + self.src; + self.script = document.createElement("script"); + self.script.id = receiver.id; + self.script.src = self.src; + self.script.type = "text/javascript"; + self.script.charset = "UTF-8"; + if (self.script.addEventListener) { + self.script.onerror = function () { + receiver.callback(errorString); + }; + self.script.onload = function () { + receiver.callback(null); + }; + } + else { + self.script.onreadystatechange = function () { + if (self.script.readyState === 'loaded' || + self.script.readyState === 'complete') { + receiver.callback(null); + } + }; + } + if (self.script.async === undefined && document.attachEvent && + /opera/i.test(navigator.userAgent)) { + self.errorScript = document.createElement("script"); + self.errorScript.id = receiver.id + "_error"; + self.errorScript.text = receiver.name + "('" + errorString + "');"; + self.script.async = self.errorScript.async = false; + } + else { + self.script.async = true; + } + var head = document.getElementsByTagName('head')[0]; + head.insertBefore(self.script, head.firstChild); + if (self.errorScript) { + head.insertBefore(self.errorScript, self.script.nextSibling); + } + }; + ScriptRequest.prototype.cleanup = function () { + if (this.script) { + this.script.onload = this.script.onerror = null; + this.script.onreadystatechange = null; + } + if (this.script && this.script.parentNode) { + this.script.parentNode.removeChild(this.script); + } + if (this.errorScript && this.errorScript.parentNode) { + this.errorScript.parentNode.removeChild(this.errorScript); + } + this.script = null; + this.errorScript = null; + }; + return ScriptRequest; +}()); +/* harmony default export */ var script_request = (ScriptRequest); -function scalarmult(p, q, s) { - var b, i; - set25519(p[0], gf0); - set25519(p[1], gf1); - set25519(p[2], gf1); - set25519(p[3], gf0); - for (i = 255; i >= 0; --i) { - b = (s[(i/8)|0] >> (i&7)) & 1; - cswap(p, q, b); - add(q, p); - add(p, p); - cswap(p, q, b); - } -} +// CONCATENATED MODULE: ./src/runtimes/web/dom/jsonp_request.ts -function scalarbase(p, s) { - var q = [gf(), gf(), gf(), gf()]; - set25519(q[0], X); - set25519(q[1], Y); - set25519(q[2], gf1); - M(q[3], X, Y); - scalarmult(p, q, s); -} -function crypto_sign_keypair(pk, sk, seeded) { - var d = new Uint8Array(64); - var p = [gf(), gf(), gf(), gf()]; - var i; +var jsonp_request_JSONPRequest = (function () { + function JSONPRequest(url, data) { + this.url = url; + this.data = data; + } + JSONPRequest.prototype.send = function (receiver) { + if (this.request) { + return; + } + var query = buildQueryString(this.data); + var url = this.url + "/" + receiver.number + "?" + query; + this.request = runtime.createScriptRequest(url); + this.request.send(receiver); + }; + JSONPRequest.prototype.cleanup = function () { + if (this.request) { + this.request.cleanup(); + } + }; + return JSONPRequest; +}()); +/* harmony default export */ var jsonp_request = (jsonp_request_JSONPRequest); - if (!seeded) randombytes(sk, 32); - crypto_hash(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; +// CONCATENATED MODULE: ./src/runtimes/web/timeline/jsonp_timeline.ts - scalarbase(p, d); - pack(pk, p); - for (i = 0; i < 32; i++) sk[i+32] = pk[i]; - return 0; -} +var getAgent = function (sender, useTLS) { + return function (data, callback) { + var scheme = "http" + (useTLS ? "s" : "") + "://"; + var url = scheme + (sender.host || sender.options.host) + sender.options.path; + var request = runtime.createJSONPRequest(url, data); + var receiver = runtime.ScriptReceivers.create(function (error, result) { + ScriptReceivers.remove(receiver); + request.cleanup(); + if (result && result.host) { + sender.host = result.host; + } + if (callback) { + callback(error, result); + } + }); + request.send(receiver); + }; +}; +var jsonp_timeline_jsonp = { + name: 'jsonp', + getAgent: getAgent +}; +/* harmony default export */ var jsonp_timeline = (jsonp_timeline_jsonp); -var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); +// CONCATENATED MODULE: ./src/core/transports/url_schemes.ts -function modL(r, x) { - var carry, i, j, k; - for (i = 63; i >= 32; --i) { - carry = 0; - for (j = i - 32, k = i - 12; j < k; ++j) { - x[j] += carry - 16 * x[i] * L[j - (i - 32)]; - carry = (x[j] + 128) >> 8; - x[j] -= carry * 256; - } - x[j] += carry; - x[i] = 0; - } - carry = 0; - for (j = 0; j < 32; j++) { - x[j] += carry - (x[31] >> 4) * L[j]; - carry = x[j] >> 8; - x[j] &= 255; - } - for (j = 0; j < 32; j++) x[j] -= carry * L[j]; - for (i = 0; i < 32; i++) { - x[i+1] += x[i] >> 8; - r[i] = x[i] & 255; - } +function getGenericURL(baseScheme, params, path) { + var scheme = baseScheme + (params.useTLS ? "s" : ""); + var host = params.useTLS ? params.hostTLS : params.hostNonTLS; + return scheme + "://" + host + path; } - -function reduce(r) { - var x = new Float64Array(64), i; - for (i = 0; i < 64; i++) x[i] = r[i]; - for (i = 0; i < 64; i++) r[i] = 0; - modL(r, x); +function getGenericPath(key, queryString) { + var path = "/app/" + key; + var query = "?protocol=" + defaults.PROTOCOL + + "&client=js" + + "&version=" + defaults.VERSION + + (queryString ? ("&" + queryString) : ""); + return path + query; } +var ws = { + getInitial: function (key, params) { + var path = (params.httpPath || "") + getGenericPath(key, "flash=false"); + return getGenericURL("ws", params, path); + } +}; +var http = { + getInitial: function (key, params) { + var path = (params.httpPath || "/pusher") + getGenericPath(key); + return getGenericURL("http", params, path); + } +}; +var sockjs = { + getInitial: function (key, params) { + return getGenericURL("http", params, params.httpPath || "/pusher"); + }, + getPath: function (key, params) { + return getGenericPath(key); + } +}; -// Note: difference from C - smlen returned, not passed as argument. -function crypto_sign(sm, m, n, sk) { - var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); - var i, j, x = new Float64Array(64); - var p = [gf(), gf(), gf(), gf()]; - - crypto_hash(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; - - var smlen = n + 64; - for (i = 0; i < n; i++) sm[64 + i] = m[i]; - for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]; - - crypto_hash(r, sm.subarray(32), n+32); - reduce(r); - scalarbase(p, r); - pack(sm, p); - - for (i = 32; i < 64; i++) sm[i] = sk[i]; - crypto_hash(h, sm, n + 64); - reduce(h); +// CONCATENATED MODULE: ./src/core/events/callback_registry.ts - for (i = 0; i < 64; i++) x[i] = 0; - for (i = 0; i < 32; i++) x[i] = r[i]; - for (i = 0; i < 32; i++) { - for (j = 0; j < 32; j++) { - x[i+j] += h[i] * d[j]; +var callback_registry_CallbackRegistry = (function () { + function CallbackRegistry() { + this._callbacks = {}; } - } - - modL(sm.subarray(32), x); - return smlen; + CallbackRegistry.prototype.get = function (name) { + return this._callbacks[prefix(name)]; + }; + CallbackRegistry.prototype.add = function (name, callback, context) { + var prefixedEventName = prefix(name); + this._callbacks[prefixedEventName] = this._callbacks[prefixedEventName] || []; + this._callbacks[prefixedEventName].push({ + fn: callback, + context: context + }); + }; + CallbackRegistry.prototype.remove = function (name, callback, context) { + if (!name && !callback && !context) { + this._callbacks = {}; + return; + } + var names = name ? [prefix(name)] : keys(this._callbacks); + if (callback || context) { + this.removeCallback(names, callback, context); + } + else { + this.removeAllCallbacks(names); + } + }; + CallbackRegistry.prototype.removeCallback = function (names, callback, context) { + apply(names, function (name) { + this._callbacks[name] = filter(this._callbacks[name] || [], function (binding) { + return (callback && callback !== binding.fn) || + (context && context !== binding.context); + }); + if (this._callbacks[name].length === 0) { + delete this._callbacks[name]; + } + }, this); + }; + CallbackRegistry.prototype.removeAllCallbacks = function (names) { + apply(names, function (name) { + delete this._callbacks[name]; + }, this); + }; + return CallbackRegistry; +}()); +/* harmony default export */ var callback_registry = (callback_registry_CallbackRegistry); +function prefix(name) { + return "_" + name; } -function unpackneg(r, p) { - var t = gf(), chk = gf(), num = gf(), - den = gf(), den2 = gf(), den4 = gf(), - den6 = gf(); - - set25519(r[2], gf1); - unpack25519(r[1], p); - S(num, r[1]); - M(den, num, D); - Z(num, num, r[2]); - A(den, r[2], den); - - S(den2, den); - S(den4, den2); - M(den6, den4, den2); - M(t, den6, num); - M(t, t, den); - - pow2523(t, t); - M(t, t, num); - M(t, t, den); - M(t, t, den); - M(r[0], t, den); +// CONCATENATED MODULE: ./src/core/events/dispatcher.ts - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) M(r[0], r[0], I); - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) return -1; +var dispatcher_Dispatcher = (function () { + function Dispatcher(failThrough) { + this.callbacks = new callback_registry(); + this.global_callbacks = []; + this.failThrough = failThrough; + } + Dispatcher.prototype.bind = function (eventName, callback, context) { + this.callbacks.add(eventName, callback, context); + return this; + }; + Dispatcher.prototype.bind_global = function (callback) { + this.global_callbacks.push(callback); + return this; + }; + Dispatcher.prototype.unbind = function (eventName, callback, context) { + this.callbacks.remove(eventName, callback, context); + return this; + }; + Dispatcher.prototype.unbind_global = function (callback) { + if (!callback) { + this.global_callbacks = []; + return this; + } + this.global_callbacks = filter(this.global_callbacks || [], function (c) { return c !== callback; }); + return this; + }; + Dispatcher.prototype.unbind_all = function () { + this.unbind(); + this.unbind_global(); + return this; + }; + Dispatcher.prototype.emit = function (eventName, data, metadata) { + for (var i = 0; i < this.global_callbacks.length; i++) { + this.global_callbacks[i](eventName, data); + } + var callbacks = this.callbacks.get(eventName); + var args = []; + if (metadata) { + args.push(data, metadata); + } + else if (data) { + args.push(data); + } + if (callbacks && callbacks.length > 0) { + for (var i = 0; i < callbacks.length; i++) { + callbacks[i].fn.apply(callbacks[i].context || window, args); + } + } + else if (this.failThrough) { + this.failThrough(eventName, data); + } + return this; + }; + return Dispatcher; +}()); +/* harmony default export */ var dispatcher = (dispatcher_Dispatcher); - if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]); +// CONCATENATED MODULE: ./src/core/transports/transport_connection.ts +var transport_connection_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); - M(r[3], r[0], r[1]); - return 0; -} -function crypto_sign_open(m, sm, n, pk) { - var i, mlen; - var t = new Uint8Array(32), h = new Uint8Array(64); - var p = [gf(), gf(), gf(), gf()], - q = [gf(), gf(), gf(), gf()]; - mlen = -1; - if (n < 64) return -1; - if (unpackneg(q, pk)) return -1; - for (i = 0; i < n; i++) m[i] = sm[i]; - for (i = 0; i < 32; i++) m[i+32] = pk[i]; - crypto_hash(h, m, n); - reduce(h); - scalarmult(p, q, h); +var transport_connection_TransportConnection = (function (_super) { + transport_connection_extends(TransportConnection, _super); + function TransportConnection(hooks, name, priority, key, options) { + var _this = _super.call(this) || this; + _this.initialize = runtime.transportConnectionInitializer; + _this.hooks = hooks; + _this.name = name; + _this.priority = priority; + _this.key = key; + _this.options = options; + _this.state = "new"; + _this.timeline = options.timeline; + _this.activityTimeout = options.activityTimeout; + _this.id = _this.timeline.generateUniqueID(); + return _this; + } + TransportConnection.prototype.handlesActivityChecks = function () { + return Boolean(this.hooks.handlesActivityChecks); + }; + TransportConnection.prototype.supportsPing = function () { + return Boolean(this.hooks.supportsPing); + }; + TransportConnection.prototype.connect = function () { + var _this = this; + if (this.socket || this.state !== "initialized") { + return false; + } + var url = this.hooks.urls.getInitial(this.key, this.options); + try { + this.socket = this.hooks.getSocket(url, this.options); + } + catch (e) { + util.defer(function () { + _this.onError(e); + _this.changeState("closed"); + }); + return false; + } + this.bindListeners(); + logger.debug("Connecting", { transport: this.name, url: url }); + this.changeState("connecting"); + return true; + }; + TransportConnection.prototype.close = function () { + if (this.socket) { + this.socket.close(); + return true; + } + else { + return false; + } + }; + TransportConnection.prototype.send = function (data) { + var _this = this; + if (this.state === "open") { + util.defer(function () { + if (_this.socket) { + _this.socket.send(data); + } + }); + return true; + } + else { + return false; + } + }; + TransportConnection.prototype.ping = function () { + if (this.state === "open" && this.supportsPing()) { + this.socket.ping(); + } + }; + TransportConnection.prototype.onOpen = function () { + if (this.hooks.beforeOpen) { + this.hooks.beforeOpen(this.socket, this.hooks.urls.getPath(this.key, this.options)); + } + this.changeState("open"); + this.socket.onopen = undefined; + }; + TransportConnection.prototype.onError = function (error) { + this.emit("error", { type: 'WebSocketError', error: error }); + this.timeline.error(this.buildTimelineMessage({ error: error.toString() })); + }; + TransportConnection.prototype.onClose = function (closeEvent) { + if (closeEvent) { + this.changeState("closed", { + code: closeEvent.code, + reason: closeEvent.reason, + wasClean: closeEvent.wasClean + }); + } + else { + this.changeState("closed"); + } + this.unbindListeners(); + this.socket = undefined; + }; + TransportConnection.prototype.onMessage = function (message) { + this.emit("message", message); + }; + TransportConnection.prototype.onActivity = function () { + this.emit("activity"); + }; + TransportConnection.prototype.bindListeners = function () { + var _this = this; + this.socket.onopen = function () { + _this.onOpen(); + }; + this.socket.onerror = function (error) { + _this.onError(error); + }; + this.socket.onclose = function (closeEvent) { + _this.onClose(closeEvent); + }; + this.socket.onmessage = function (message) { + _this.onMessage(message); + }; + if (this.supportsPing()) { + this.socket.onactivity = function () { _this.onActivity(); }; + } + }; + TransportConnection.prototype.unbindListeners = function () { + if (this.socket) { + this.socket.onopen = undefined; + this.socket.onerror = undefined; + this.socket.onclose = undefined; + this.socket.onmessage = undefined; + if (this.supportsPing()) { + this.socket.onactivity = undefined; + } + } + }; + TransportConnection.prototype.changeState = function (state, params) { + this.state = state; + this.timeline.info(this.buildTimelineMessage({ + state: state, + params: params + })); + this.emit(state, params); + }; + TransportConnection.prototype.buildTimelineMessage = function (message) { + return extend({ cid: this.id }, message); + }; + return TransportConnection; +}(dispatcher)); +/* harmony default export */ var transport_connection = (transport_connection_TransportConnection); - scalarbase(q, sm.subarray(32)); - add(p, q); - pack(t, p); +// CONCATENATED MODULE: ./src/core/transports/transport.ts - n -= 64; - if (crypto_verify_32(sm, 0, t, 0)) { - for (i = 0; i < n; i++) m[i] = 0; - return -1; - } +var transport_Transport = (function () { + function Transport(hooks) { + this.hooks = hooks; + } + Transport.prototype.isSupported = function (environment) { + return this.hooks.isSupported(environment); + }; + Transport.prototype.createConnection = function (name, priority, key, options) { + return new transport_connection(this.hooks, name, priority, key, options); + }; + return Transport; +}()); +/* harmony default export */ var transports_transport = (transport_Transport); - for (i = 0; i < n; i++) m[i] = sm[i + 64]; - mlen = n; - return mlen; -} +// CONCATENATED MODULE: ./src/runtimes/isomorphic/transports/transports.ts -var crypto_secretbox_KEYBYTES = 32, - crypto_secretbox_NONCEBYTES = 24, - crypto_secretbox_ZEROBYTES = 32, - crypto_secretbox_BOXZEROBYTES = 16, - crypto_scalarmult_BYTES = 32, - crypto_scalarmult_SCALARBYTES = 32, - crypto_box_PUBLICKEYBYTES = 32, - crypto_box_SECRETKEYBYTES = 32, - crypto_box_BEFORENMBYTES = 32, - crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, - crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, - crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, - crypto_sign_BYTES = 64, - crypto_sign_PUBLICKEYBYTES = 32, - crypto_sign_SECRETKEYBYTES = 64, - crypto_sign_SEEDBYTES = 32, - crypto_hash_BYTES = 64; -nacl.lowlevel = { - crypto_core_hsalsa20: crypto_core_hsalsa20, - crypto_stream_xor: crypto_stream_xor, - crypto_stream: crypto_stream, - crypto_stream_salsa20_xor: crypto_stream_salsa20_xor, - crypto_stream_salsa20: crypto_stream_salsa20, - crypto_onetimeauth: crypto_onetimeauth, - crypto_onetimeauth_verify: crypto_onetimeauth_verify, - crypto_verify_16: crypto_verify_16, - crypto_verify_32: crypto_verify_32, - crypto_secretbox: crypto_secretbox, - crypto_secretbox_open: crypto_secretbox_open, - crypto_scalarmult: crypto_scalarmult, - crypto_scalarmult_base: crypto_scalarmult_base, - crypto_box_beforenm: crypto_box_beforenm, - crypto_box_afternm: crypto_box_afternm, - crypto_box: crypto_box, - crypto_box_open: crypto_box_open, - crypto_box_keypair: crypto_box_keypair, - crypto_hash: crypto_hash, - crypto_sign: crypto_sign, - crypto_sign_keypair: crypto_sign_keypair, - crypto_sign_open: crypto_sign_open, - crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES, - crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES, - crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES, - crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES, - crypto_scalarmult_BYTES: crypto_scalarmult_BYTES, - crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES, - crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES, - crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES, - crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES, - crypto_box_NONCEBYTES: crypto_box_NONCEBYTES, - crypto_box_ZEROBYTES: crypto_box_ZEROBYTES, - crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES, - crypto_sign_BYTES: crypto_sign_BYTES, - crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES, - crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES, - crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES, - crypto_hash_BYTES: crypto_hash_BYTES + +var WSTransport = new transports_transport({ + urls: ws, + handlesActivityChecks: false, + supportsPing: false, + isInitialized: function () { + return Boolean(runtime.getWebSocketAPI()); + }, + isSupported: function () { + return Boolean(runtime.getWebSocketAPI()); + }, + getSocket: function (url) { + return runtime.createWebSocket(url); + } +}); +var httpConfiguration = { + urls: http, + handlesActivityChecks: false, + supportsPing: true, + isInitialized: function () { + return true; + } +}; +var streamingConfiguration = extend({ getSocket: function (url) { + return runtime.HTTPFactory.createStreamingSocket(url); + } +}, httpConfiguration); +var pollingConfiguration = extend({ getSocket: function (url) { + return runtime.HTTPFactory.createPollingSocket(url); + } +}, httpConfiguration); +var xhrConfiguration = { + isSupported: function () { + return runtime.isXHRSupported(); + } +}; +var XHRStreamingTransport = new transports_transport(extend({}, streamingConfiguration, xhrConfiguration)); +var XHRPollingTransport = new transports_transport(extend({}, pollingConfiguration, xhrConfiguration)); +var Transports = { + ws: WSTransport, + xhr_streaming: XHRStreamingTransport, + xhr_polling: XHRPollingTransport }; +/* harmony default export */ var transports = (Transports); -/* High-level API */ +// CONCATENATED MODULE: ./src/runtimes/web/transports/transports.ts -function checkLengths(k, n) { - if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size'); - if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size'); -} -function checkBoxLengths(pk, sk) { - if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size'); - if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size'); -} -function checkArrayTypes() { - for (var i = 0; i < arguments.length; i++) { - if (!(arguments[i] instanceof Uint8Array)) - throw new TypeError('unexpected type, use Uint8Array'); - } -} -function cleanup(arr) { - for (var i = 0; i < arr.length; i++) arr[i] = 0; -} -nacl.randomBytes = function(n) { - var b = new Uint8Array(n); - randombytes(b, n); - return b; -}; -nacl.secretbox = function(msg, nonce, key) { - checkArrayTypes(msg, nonce, key); - checkLengths(key, nonce); - var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length); - var c = new Uint8Array(m.length); - for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i]; - crypto_secretbox(c, m, m.length, nonce, key); - return c.subarray(crypto_secretbox_BOXZEROBYTES); +var SockJSTransport = new transports_transport({ + file: "sockjs", + urls: sockjs, + handlesActivityChecks: true, + supportsPing: false, + isSupported: function () { + return true; + }, + isInitialized: function () { + return window.SockJS !== undefined; + }, + getSocket: function (url, options) { + return new window.SockJS(url, null, { + js_path: Dependencies.getPath("sockjs", { + useTLS: options.useTLS + }), + ignore_null_origin: options.ignoreNullOrigin + }); + }, + beforeOpen: function (socket, path) { + socket.send(JSON.stringify({ + path: path + })); + } +}); +var xdrConfiguration = { + isSupported: function (environment) { + var yes = runtime.isXDRSupported(environment.useTLS); + return yes; + } }; +var XDRStreamingTransport = new transports_transport(extend({}, streamingConfiguration, xdrConfiguration)); +var XDRPollingTransport = new transports_transport(extend({}, pollingConfiguration, xdrConfiguration)); +transports.xdr_streaming = XDRStreamingTransport; +transports.xdr_polling = XDRPollingTransport; +transports.sockjs = SockJSTransport; +/* harmony default export */ var transports_transports = (transports); + +// CONCATENATED MODULE: ./src/runtimes/web/net_info.ts +var net_info_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); -nacl.secretbox.open = function(box, nonce, key) { - checkArrayTypes(box, nonce, key); - checkLengths(key, nonce); - var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length); - var m = new Uint8Array(c.length); - for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i]; - if (c.length < 32) return null; - if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null; - return m.subarray(crypto_secretbox_ZEROBYTES); -}; +var NetInfo = (function (_super) { + net_info_extends(NetInfo, _super); + function NetInfo() { + var _this = _super.call(this) || this; + var self = _this; + if (window.addEventListener !== undefined) { + window.addEventListener("online", function () { + self.emit('online'); + }, false); + window.addEventListener("offline", function () { + self.emit('offline'); + }, false); + } + return _this; + } + NetInfo.prototype.isOnline = function () { + if (window.navigator.onLine === undefined) { + return true; + } + else { + return window.navigator.onLine; + } + }; + return NetInfo; +}(dispatcher)); -nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES; -nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES; -nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES; +var net_info_Network = new NetInfo(); -nacl.scalarMult = function(n, p) { - checkArrayTypes(n, p); - if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); - if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size'); - var q = new Uint8Array(crypto_scalarmult_BYTES); - crypto_scalarmult(q, n, p); - return q; -}; +// CONCATENATED MODULE: ./src/core/transports/assistant_to_the_transport_manager.ts -nacl.scalarMult.base = function(n) { - checkArrayTypes(n); - if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); - var q = new Uint8Array(crypto_scalarmult_BYTES); - crypto_scalarmult_base(q, n); - return q; -}; -nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES; -nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES; +var assistant_to_the_transport_manager_AssistantToTheTransportManager = (function () { + function AssistantToTheTransportManager(manager, transport, options) { + this.manager = manager; + this.transport = transport; + this.minPingDelay = options.minPingDelay; + this.maxPingDelay = options.maxPingDelay; + this.pingDelay = undefined; + } + AssistantToTheTransportManager.prototype.createConnection = function (name, priority, key, options) { + var _this = this; + options = extend({}, options, { + activityTimeout: this.pingDelay + }); + var connection = this.transport.createConnection(name, priority, key, options); + var openTimestamp = null; + var onOpen = function () { + connection.unbind("open", onOpen); + connection.bind("closed", onClosed); + openTimestamp = util.now(); + }; + var onClosed = function (closeEvent) { + connection.unbind("closed", onClosed); + if (closeEvent.code === 1002 || closeEvent.code === 1003) { + _this.manager.reportDeath(); + } + else if (!closeEvent.wasClean && openTimestamp) { + var lifespan = util.now() - openTimestamp; + if (lifespan < 2 * _this.maxPingDelay) { + _this.manager.reportDeath(); + _this.pingDelay = Math.max(lifespan / 2, _this.minPingDelay); + } + } + }; + connection.bind("open", onOpen); + return connection; + }; + AssistantToTheTransportManager.prototype.isSupported = function (environment) { + return this.manager.isAlive() && this.transport.isSupported(environment); + }; + return AssistantToTheTransportManager; +}()); +/* harmony default export */ var assistant_to_the_transport_manager = (assistant_to_the_transport_manager_AssistantToTheTransportManager); -nacl.box = function(msg, nonce, publicKey, secretKey) { - var k = nacl.box.before(publicKey, secretKey); - return nacl.secretbox(msg, nonce, k); +// CONCATENATED MODULE: ./src/core/connection/protocol/protocol.ts +var Protocol = { + decodeMessage: function (messageEvent) { + try { + var messageData = JSON.parse(messageEvent.data); + var pusherEventData = messageData.data; + if (typeof pusherEventData === 'string') { + try { + pusherEventData = JSON.parse(messageData.data); + } + catch (e) { } + } + var pusherEvent = { + event: messageData.event, + channel: messageData.channel, + data: pusherEventData, + }; + if (messageData.user_id) { + pusherEvent.user_id = messageData.user_id; + } + return pusherEvent; + } + catch (e) { + throw { type: 'MessageParseError', error: e, data: messageEvent.data }; + } + }, + encodeMessage: function (event) { + return JSON.stringify(event); + }, + processHandshake: function (messageEvent) { + var message = Protocol.decodeMessage(messageEvent); + if (message.event === "pusher:connection_established") { + if (!message.data.activity_timeout) { + throw "No activity timeout specified in handshake"; + } + return { + action: "connected", + id: message.data.socket_id, + activityTimeout: message.data.activity_timeout * 1000 + }; + } + else if (message.event === "pusher:error") { + return { + action: this.getCloseAction(message.data), + error: this.getCloseError(message.data) + }; + } + else { + throw "Invalid handshake"; + } + }, + getCloseAction: function (closeEvent) { + if (closeEvent.code < 4000) { + if (closeEvent.code >= 1002 && closeEvent.code <= 1004) { + return "backoff"; + } + else { + return null; + } + } + else if (closeEvent.code === 4000) { + return "tls_only"; + } + else if (closeEvent.code < 4100) { + return "refused"; + } + else if (closeEvent.code < 4200) { + return "backoff"; + } + else if (closeEvent.code < 4300) { + return "retry"; + } + else { + return "refused"; + } + }, + getCloseError: function (closeEvent) { + if (closeEvent.code !== 1000 && closeEvent.code !== 1001) { + return { + type: 'PusherError', + data: { + code: closeEvent.code, + message: closeEvent.reason || closeEvent.message + } + }; + } + else { + return null; + } + } }; +/* harmony default export */ var protocol_protocol = (Protocol); -nacl.box.before = function(publicKey, secretKey) { - checkArrayTypes(publicKey, secretKey); - checkBoxLengths(publicKey, secretKey); - var k = new Uint8Array(crypto_box_BEFORENMBYTES); - crypto_box_beforenm(k, publicKey, secretKey); - return k; -}; +// CONCATENATED MODULE: ./src/core/connection/connection.ts +var connection_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); -nacl.box.after = nacl.secretbox; -nacl.box.open = function(msg, nonce, publicKey, secretKey) { - var k = nacl.box.before(publicKey, secretKey); - return nacl.secretbox.open(msg, nonce, k); -}; -nacl.box.open.after = nacl.secretbox.open; -nacl.box.keyPair = function() { - var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_box_SECRETKEYBYTES); - crypto_box_keypair(pk, sk); - return {publicKey: pk, secretKey: sk}; -}; +var connection_Connection = (function (_super) { + connection_extends(Connection, _super); + function Connection(id, transport) { + var _this = _super.call(this) || this; + _this.id = id; + _this.transport = transport; + _this.activityTimeout = transport.activityTimeout; + _this.bindListeners(); + return _this; + } + Connection.prototype.handlesActivityChecks = function () { + return this.transport.handlesActivityChecks(); + }; + Connection.prototype.send = function (data) { + return this.transport.send(data); + }; + Connection.prototype.send_event = function (name, data, channel) { + var event = { event: name, data: data }; + if (channel) { + event.channel = channel; + } + logger.debug('Event sent', event); + return this.send(protocol_protocol.encodeMessage(event)); + }; + Connection.prototype.ping = function () { + if (this.transport.supportsPing()) { + this.transport.ping(); + } + else { + this.send_event('pusher:ping', {}); + } + }; + Connection.prototype.close = function () { + this.transport.close(); + }; + Connection.prototype.bindListeners = function () { + var _this = this; + var listeners = { + message: function (messageEvent) { + var pusherEvent; + try { + pusherEvent = protocol_protocol.decodeMessage(messageEvent); + } + catch (e) { + _this.emit('error', { + type: 'MessageParseError', + error: e, + data: messageEvent.data + }); + } + if (pusherEvent !== undefined) { + logger.debug('Event recd', pusherEvent); + switch (pusherEvent.event) { + case 'pusher:error': + _this.emit('error', { type: 'PusherError', data: pusherEvent.data }); + break; + case 'pusher:ping': + _this.emit("ping"); + break; + case 'pusher:pong': + _this.emit("pong"); + break; + } + _this.emit('message', pusherEvent); + } + }, + activity: function () { + _this.emit("activity"); + }, + error: function (error) { + _this.emit("error", { type: "WebSocketError", error: error }); + }, + closed: function (closeEvent) { + unbindListeners(); + if (closeEvent && closeEvent.code) { + _this.handleCloseEvent(closeEvent); + } + _this.transport = null; + _this.emit("closed"); + } + }; + var unbindListeners = function () { + objectApply(listeners, function (listener, event) { + _this.transport.unbind(event, listener); + }); + }; + objectApply(listeners, function (listener, event) { + _this.transport.bind(event, listener); + }); + }; + Connection.prototype.handleCloseEvent = function (closeEvent) { + var action = protocol_protocol.getCloseAction(closeEvent); + var error = protocol_protocol.getCloseError(closeEvent); + if (error) { + this.emit('error', error); + } + if (action) { + this.emit(action, { action: action, error: error }); + } + }; + return Connection; +}(dispatcher)); +/* harmony default export */ var connection_connection = (connection_Connection); -nacl.box.keyPair.fromSecretKey = function(secretKey) { - checkArrayTypes(secretKey); - if (secretKey.length !== crypto_box_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); - crypto_scalarmult_base(pk, secretKey); - return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; -}; +// CONCATENATED MODULE: ./src/core/connection/handshake/index.ts -nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES; -nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES; -nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES; -nacl.box.nonceLength = crypto_box_NONCEBYTES; -nacl.box.overheadLength = nacl.secretbox.overheadLength; -nacl.sign = function(msg, secretKey) { - checkArrayTypes(msg, secretKey); - if (secretKey.length !== crypto_sign_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length); - crypto_sign(signedMsg, msg, msg.length, secretKey); - return signedMsg; -}; -nacl.sign.open = function(signedMsg, publicKey) { - checkArrayTypes(signedMsg, publicKey); - if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) - throw new Error('bad public key size'); - var tmp = new Uint8Array(signedMsg.length); - var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey); - if (mlen < 0) return null; - var m = new Uint8Array(mlen); - for (var i = 0; i < m.length; i++) m[i] = tmp[i]; - return m; -}; +var handshake_Handshake = (function () { + function Handshake(transport, callback) { + this.transport = transport; + this.callback = callback; + this.bindListeners(); + } + Handshake.prototype.close = function () { + this.unbindListeners(); + this.transport.close(); + }; + Handshake.prototype.bindListeners = function () { + var _this = this; + this.onMessage = function (m) { + _this.unbindListeners(); + var result; + try { + result = protocol_protocol.processHandshake(m); + } + catch (e) { + _this.finish("error", { error: e }); + _this.transport.close(); + return; + } + if (result.action === "connected") { + _this.finish("connected", { + connection: new connection_connection(result.id, _this.transport), + activityTimeout: result.activityTimeout + }); + } + else { + _this.finish(result.action, { error: result.error }); + _this.transport.close(); + } + }; + this.onClosed = function (closeEvent) { + _this.unbindListeners(); + var action = protocol_protocol.getCloseAction(closeEvent) || "backoff"; + var error = protocol_protocol.getCloseError(closeEvent); + _this.finish(action, { error: error }); + }; + this.transport.bind("message", this.onMessage); + this.transport.bind("closed", this.onClosed); + }; + Handshake.prototype.unbindListeners = function () { + this.transport.unbind("message", this.onMessage); + this.transport.unbind("closed", this.onClosed); + }; + Handshake.prototype.finish = function (action, params) { + this.callback(extend({ transport: this.transport, action: action }, params)); + }; + return Handshake; +}()); +/* harmony default export */ var connection_handshake = (handshake_Handshake); -nacl.sign.detached = function(msg, secretKey) { - var signedMsg = nacl.sign(msg, secretKey); - var sig = new Uint8Array(crypto_sign_BYTES); - for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; - return sig; -}; +// CONCATENATED MODULE: ./src/core/auth/pusher_authorizer.ts -nacl.sign.detached.verify = function(msg, sig, publicKey) { - checkArrayTypes(msg, sig, publicKey); - if (sig.length !== crypto_sign_BYTES) - throw new Error('bad signature size'); - if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) - throw new Error('bad public key size'); - var sm = new Uint8Array(crypto_sign_BYTES + msg.length); - var m = new Uint8Array(crypto_sign_BYTES + msg.length); - var i; - for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]; - for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i]; - return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); -}; +var pusher_authorizer_PusherAuthorizer = (function () { + function PusherAuthorizer(channel, options) { + this.channel = channel; + var authTransport = options.authTransport; + if (typeof runtime.getAuthorizers()[authTransport] === "undefined") { + throw "'" + authTransport + "' is not a recognized auth transport"; + } + this.type = authTransport; + this.options = options; + this.authOptions = (options || {}).auth || {}; + } + PusherAuthorizer.prototype.composeQuery = function (socketId) { + var query = 'socket_id=' + encodeURIComponent(socketId) + + '&channel_name=' + encodeURIComponent(this.channel.name); + for (var i in this.authOptions.params) { + query += "&" + encodeURIComponent(i) + "=" + encodeURIComponent(this.authOptions.params[i]); + } + return query; + }; + PusherAuthorizer.prototype.authorize = function (socketId, callback) { + PusherAuthorizer.authorizers = PusherAuthorizer.authorizers || runtime.getAuthorizers(); + return PusherAuthorizer.authorizers[this.type].call(this, runtime, socketId, callback); + }; + return PusherAuthorizer; +}()); +/* harmony default export */ var pusher_authorizer = (pusher_authorizer_PusherAuthorizer); -nacl.sign.keyPair = function() { - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); - crypto_sign_keypair(pk, sk); - return {publicKey: pk, secretKey: sk}; -}; +// CONCATENATED MODULE: ./src/core/timeline/timeline_sender.ts -nacl.sign.keyPair.fromSecretKey = function(secretKey) { - checkArrayTypes(secretKey); - if (secretKey.length !== crypto_sign_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i]; - return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; -}; +var timeline_sender_TimelineSender = (function () { + function TimelineSender(timeline, options) { + this.timeline = timeline; + this.options = options || {}; + } + TimelineSender.prototype.send = function (useTLS, callback) { + if (this.timeline.isEmpty()) { + return; + } + this.timeline.send(runtime.TimelineTransport.getAgent(this, useTLS), callback); + }; + return TimelineSender; +}()); +/* harmony default export */ var timeline_sender = (timeline_sender_TimelineSender); -nacl.sign.keyPair.fromSeed = function(seed) { - checkArrayTypes(seed); - if (seed.length !== crypto_sign_SEEDBYTES) - throw new Error('bad seed size'); - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); - for (var i = 0; i < 32; i++) sk[i] = seed[i]; - crypto_sign_keypair(pk, sk, true); - return {publicKey: pk, secretKey: sk}; -}; +// CONCATENATED MODULE: ./src/core/errors.ts +var errors_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var BadEventName = (function (_super) { + errors_extends(BadEventName, _super); + function BadEventName(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return BadEventName; +}(Error)); -nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; -nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; -nacl.sign.seedLength = crypto_sign_SEEDBYTES; -nacl.sign.signatureLength = crypto_sign_BYTES; +var RequestTimedOut = (function (_super) { + errors_extends(RequestTimedOut, _super); + function RequestTimedOut(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return RequestTimedOut; +}(Error)); -nacl.hash = function(msg) { - checkArrayTypes(msg); - var h = new Uint8Array(crypto_hash_BYTES); - crypto_hash(h, msg, msg.length); - return h; -}; +var TransportPriorityTooLow = (function (_super) { + errors_extends(TransportPriorityTooLow, _super); + function TransportPriorityTooLow(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return TransportPriorityTooLow; +}(Error)); -nacl.hash.hashLength = crypto_hash_BYTES; +var TransportClosed = (function (_super) { + errors_extends(TransportClosed, _super); + function TransportClosed(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return TransportClosed; +}(Error)); -nacl.verify = function(x, y) { - checkArrayTypes(x, y); - // Zero length arguments are considered not equal. - if (x.length === 0 || y.length === 0) return false; - if (x.length !== y.length) return false; - return (vn(x, 0, y, 0, x.length) === 0) ? true : false; -}; +var UnsupportedFeature = (function (_super) { + errors_extends(UnsupportedFeature, _super); + function UnsupportedFeature(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return UnsupportedFeature; +}(Error)); -nacl.setPRNG = function(fn) { - randombytes = fn; -}; +var UnsupportedTransport = (function (_super) { + errors_extends(UnsupportedTransport, _super); + function UnsupportedTransport(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return UnsupportedTransport; +}(Error)); -(function() { - // Initialize PRNG if environment provides CSPRNG. - // If not, methods calling randombytes will throw. - var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null; - if (crypto && crypto.getRandomValues) { - // Browsers. - var QUOTA = 65536; - nacl.setPRNG(function(x, n) { - var i, v = new Uint8Array(n); - for (i = 0; i < n; i += QUOTA) { - crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); - } - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); - } else if (true) { - // Node.js. - crypto = __webpack_require__(45); - if (crypto && crypto.randomBytes) { - nacl.setPRNG(function(x, n) { - var i, v = crypto.randomBytes(n); - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); +var UnsupportedStrategy = (function (_super) { + errors_extends(UnsupportedStrategy, _super); + function UnsupportedStrategy(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; } - } -})(); + return UnsupportedStrategy; +}(Error)); -})( true && module.exports ? module.exports : (self.nacl = self.nacl || {})); +// CONCATENATED MODULE: ./src/core/channels/channel.ts +var channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); -/***/ }), -/* 45 */ -/***/ (function(module, exports) { -/* (ignored) */ -/***/ }), -/* 46 */ -/***/ (function(module, exports, __webpack_require__) { -// Written in 2014-2016 by Dmitry Chestnykh and Devi Mandiri. -// Public domain. -(function(root, f) { - 'use strict'; - if ( true && module.exports) module.exports = f(); - else if (root.nacl) root.nacl.util = f(); - else { - root.nacl = {}; - root.nacl.util = f(); - } -}(this, function() { - 'use strict'; +var channel_Channel = (function (_super) { + channel_extends(Channel, _super); + function Channel(name, pusher) { + var _this = _super.call(this, function (event, data) { + logger.debug('No callbacks on ' + name + ' for ' + event); + }) || this; + _this.name = name; + _this.pusher = pusher; + _this.subscribed = false; + _this.subscriptionPending = false; + _this.subscriptionCancelled = false; + return _this; + } + Channel.prototype.authorize = function (socketId, callback) { + return callback(false, {}); + }; + Channel.prototype.trigger = function (event, data) { + if (event.indexOf("client-") !== 0) { + throw new BadEventName("Event '" + event + "' does not start with 'client-'"); + } + if (!this.subscribed) { + var suffix = url_store.buildLogSuffix("triggeringClientEvents"); + logger.warn("Client event triggered before channel 'subscription_succeeded' event . " + suffix); + } + return this.pusher.send_event(event, data, this.name); + }; + Channel.prototype.disconnect = function () { + this.subscribed = false; + this.subscriptionPending = false; + }; + Channel.prototype.handleEvent = function (event) { + var eventName = event.event; + var data = event.data; + if (eventName === "pusher_internal:subscription_succeeded") { + this.handleSubscriptionSucceededEvent(event); + } + else if (eventName.indexOf("pusher_internal:") !== 0) { + var metadata = {}; + this.emit(eventName, data, metadata); + } + }; + Channel.prototype.handleSubscriptionSucceededEvent = function (event) { + this.subscriptionPending = false; + this.subscribed = true; + if (this.subscriptionCancelled) { + this.pusher.unsubscribe(this.name); + } + else { + this.emit("pusher:subscription_succeeded", event.data); + } + }; + Channel.prototype.subscribe = function () { + var _this = this; + if (this.subscribed) { + return; + } + this.subscriptionPending = true; + this.subscriptionCancelled = false; + this.authorize(this.pusher.connection.socket_id, function (error, data) { + if (error) { + _this.emit('pusher:subscription_error', data); + } + else { + _this.pusher.send_event('pusher:subscribe', { + auth: data.auth, + channel_data: data.channel_data, + channel: _this.name + }); + } + }); + }; + Channel.prototype.unsubscribe = function () { + this.subscribed = false; + this.pusher.send_event('pusher:unsubscribe', { + channel: this.name + }); + }; + Channel.prototype.cancelSubscription = function () { + this.subscriptionCancelled = true; + }; + Channel.prototype.reinstateSubscription = function () { + this.subscriptionCancelled = false; + }; + return Channel; +}(dispatcher)); +/* harmony default export */ var channels_channel = (channel_Channel); - var util = {}; +// CONCATENATED MODULE: ./src/core/channels/private_channel.ts +var private_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); - function validateBase64(s) { - if (!(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(s))) { - throw new TypeError('invalid encoding'); + +var private_channel_PrivateChannel = (function (_super) { + private_channel_extends(PrivateChannel, _super); + function PrivateChannel() { + return _super !== null && _super.apply(this, arguments) || this; } - } + PrivateChannel.prototype.authorize = function (socketId, callback) { + var authorizer = factory.createAuthorizer(this, this.pusher.config); + return authorizer.authorize(socketId, callback); + }; + return PrivateChannel; +}(channels_channel)); +/* harmony default export */ var private_channel = (private_channel_PrivateChannel); - util.decodeUTF8 = function(s) { - if (typeof s !== 'string') throw new TypeError('expected string'); - var i, d = unescape(encodeURIComponent(s)), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; - }; +// CONCATENATED MODULE: ./src/core/channels/members.ts - util.encodeUTF8 = function(arr) { - var i, s = []; - for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i])); - return decodeURIComponent(escape(s.join(''))); - }; +var members_Members = (function () { + function Members() { + this.reset(); + } + Members.prototype.get = function (id) { + if (Object.prototype.hasOwnProperty.call(this.members, id)) { + return { + id: id, + info: this.members[id] + }; + } + else { + return null; + } + }; + Members.prototype.each = function (callback) { + var _this = this; + objectApply(this.members, function (member, id) { + callback(_this.get(id)); + }); + }; + Members.prototype.setMyID = function (id) { + this.myID = id; + }; + Members.prototype.onSubscription = function (subscriptionData) { + this.members = subscriptionData.presence.hash; + this.count = subscriptionData.presence.count; + this.me = this.get(this.myID); + }; + Members.prototype.addMember = function (memberData) { + if (this.get(memberData.user_id) === null) { + this.count++; + } + this.members[memberData.user_id] = memberData.user_info; + return this.get(memberData.user_id); + }; + Members.prototype.removeMember = function (memberData) { + var member = this.get(memberData.user_id); + if (member) { + delete this.members[memberData.user_id]; + this.count--; + } + return member; + }; + Members.prototype.reset = function () { + this.members = {}; + this.count = 0; + this.myID = null; + this.me = null; + }; + return Members; +}()); +/* harmony default export */ var members = (members_Members); - if (typeof atob === 'undefined') { - // Node.js +// CONCATENATED MODULE: ./src/core/channels/presence_channel.ts +var presence_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); - if (typeof Buffer.from !== 'undefined') { - // Node v6 and later - util.encodeBase64 = function (arr) { // v6 and later - return Buffer.from(arr).toString('base64'); - }; - util.decodeBase64 = function (s) { - validateBase64(s); - return new Uint8Array(Array.prototype.slice.call(Buffer.from(s, 'base64'), 0)); - }; - } else { - // Node earlier than v6 - util.encodeBase64 = function (arr) { // v6 and later - return (new Buffer(arr)).toString('base64'); - }; - util.decodeBase64 = function(s) { - validateBase64(s); - return new Uint8Array(Array.prototype.slice.call(new Buffer(s, 'base64'), 0)); - }; +var presence_channel_PresenceChannel = (function (_super) { + presence_channel_extends(PresenceChannel, _super); + function PresenceChannel(name, pusher) { + var _this = _super.call(this, name, pusher) || this; + _this.members = new members(); + return _this; } + PresenceChannel.prototype.authorize = function (socketId, callback) { + var _this = this; + _super.prototype.authorize.call(this, socketId, function (error, authData) { + if (!error) { + if (authData.channel_data === undefined) { + var suffix = url_store.buildLogSuffix("authenticationEndpoint"); + logger.warn("Invalid auth response for channel '" + _this.name + "'," + + ("expected 'channel_data' field. " + suffix)); + callback("Invalid auth response"); + return; + } + var channelData = JSON.parse(authData.channel_data); + _this.members.setMyID(channelData.user_id); + } + callback(error, authData); + }); + }; + PresenceChannel.prototype.handleEvent = function (event) { + var eventName = event.event; + if (eventName.indexOf("pusher_internal:") === 0) { + this.handleInternalEvent(event); + } + else { + var data = event.data; + var metadata = {}; + if (event.user_id) { + metadata.user_id = event.user_id; + } + this.emit(eventName, data, metadata); + } + }; + PresenceChannel.prototype.handleInternalEvent = function (event) { + var eventName = event.event; + var data = event.data; + switch (eventName) { + case "pusher_internal:subscription_succeeded": + this.handleSubscriptionSucceededEvent(event); + break; + case "pusher_internal:member_added": + var addedMember = this.members.addMember(data); + this.emit('pusher:member_added', addedMember); + break; + case "pusher_internal:member_removed": + var removedMember = this.members.removeMember(data); + if (removedMember) { + this.emit('pusher:member_removed', removedMember); + } + break; + } + }; + PresenceChannel.prototype.handleSubscriptionSucceededEvent = function (event) { + this.subscriptionPending = false; + this.subscribed = true; + if (this.subscriptionCancelled) { + this.pusher.unsubscribe(this.name); + } + else { + this.members.onSubscription(event.data); + this.emit("pusher:subscription_succeeded", this.members); + } + }; + PresenceChannel.prototype.disconnect = function () { + this.members.reset(); + _super.prototype.disconnect.call(this); + }; + return PresenceChannel; +}(private_channel)); +/* harmony default export */ var presence_channel = (presence_channel_PresenceChannel); - } else { - // Browsers +// EXTERNAL MODULE: ./node_modules/tweetnacl/nacl-fast.js +var nacl_fast = __webpack_require__(0); - util.encodeBase64 = function(arr) { - var i, s = [], len = arr.length; - for (i = 0; i < len; i++) s.push(String.fromCharCode(arr[i])); - return btoa(s.join('')); - }; +// EXTERNAL MODULE: ./node_modules/tweetnacl-util/nacl-util.js +var nacl_util = __webpack_require__(1); - util.decodeBase64 = function(s) { - validateBase64(s); - var i, d = atob(s), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; +// CONCATENATED MODULE: ./src/core/channels/encrypted_channel.ts +var encrypted_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); - } - - return util; -})); -/***/ }), -/* 47 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; +var encrypted_channel_EncryptedChannel = (function (_super) { + encrypted_channel_extends(EncryptedChannel, _super); + function EncryptedChannel() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.key = null; + return _this; + } + EncryptedChannel.prototype.authorize = function (socketId, callback) { + var _this = this; + _super.prototype.authorize.call(this, socketId, function (error, authData) { + if (error) { + callback(true, authData); + return; + } + var sharedSecret = authData["shared_secret"]; + if (!sharedSecret) { + var errorMsg = "No shared_secret key in auth payload for encrypted channel: " + _this.name; + callback(true, errorMsg); + logger.warn("Error: " + errorMsg); + return; + } + _this.key = Object(nacl_util["decodeBase64"])(sharedSecret); + delete authData["shared_secret"]; + callback(false, authData); + }); + }; + EncryptedChannel.prototype.trigger = function (event, data) { + throw new UnsupportedFeature('Client events are not currently supported for encrypted channels'); + }; + EncryptedChannel.prototype.handleEvent = function (event) { + var eventName = event.event; + var data = event.data; + if (eventName.indexOf("pusher_internal:") === 0 || eventName.indexOf("pusher:") === 0) { + _super.prototype.handleEvent.call(this, event); + return; + } + this.handleEncryptedEvent(eventName, data); + }; + EncryptedChannel.prototype.handleEncryptedEvent = function (event, data) { + var _this = this; + if (!this.key) { + logger.debug('Received encrypted event before key has been retrieved from the authEndpoint'); + return; + } + if (!data.ciphertext || !data.nonce) { + logger.warn('Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: ' + data); + return; + } + var cipherText = Object(nacl_util["decodeBase64"])(data.ciphertext); + if (cipherText.length < nacl_fast["secretbox"].overheadLength) { + logger.warn("Expected encrypted event ciphertext length to be " + nacl_fast["secretbox"].overheadLength + ", got: " + cipherText.length); + return; + } + var nonce = Object(nacl_util["decodeBase64"])(data.nonce); + if (nonce.length < nacl_fast["secretbox"].nonceLength) { + logger.warn("Expected encrypted event nonce length to be " + nacl_fast["secretbox"].nonceLength + ", got: " + nonce.length); + return; + } + var bytes = nacl_fast["secretbox"].open(cipherText, nonce, this.key); + if (bytes === null) { + logger.debug('Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint...'); + this.authorize(this.pusher.connection.socket_id, function (error, authData) { + if (error) { + logger.warn("Failed to make a request to the authEndpoint: " + authData + ". Unable to fetch new key, so dropping encrypted event"); + return; + } + bytes = nacl_fast["secretbox"].open(cipherText, nonce, _this.key); + if (bytes === null) { + logger.warn("Failed to decrypt event with new key. Dropping encrypted event"); + return; + } + _this.emitJSON(event, Object(nacl_util["encodeUTF8"])(bytes)); + return; + }); + return; + } + this.emitJSON(event, Object(nacl_util["encodeUTF8"])(bytes)); + }; + EncryptedChannel.prototype.emitJSON = function (eventName, data) { + try { + this.emit(eventName, JSON.parse(data)); + } + catch (e) { + this.emit(eventName, data); + } + return this; + }; + return EncryptedChannel; +}(private_channel)); +/* harmony default export */ var encrypted_channel = (encrypted_channel_EncryptedChannel); -var __extends = (this && this.__extends) || (function () { +// CONCATENATED MODULE: ./src/core/connection/connection_manager.ts +var connection_manager_extends = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || @@ -5534,14 +4630,13 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -exports.__esModule = true; -var dispatcher_1 = __webpack_require__(4); -var timers_1 = __webpack_require__(6); -var logger_1 = __webpack_require__(3); -var Collections = __webpack_require__(0); -var runtime_1 = __webpack_require__(1); -var ConnectionManager = (function (_super) { - __extends(ConnectionManager, _super); + + + + + +var connection_manager_ConnectionManager = (function (_super) { + connection_manager_extends(ConnectionManager, _super); function ConnectionManager(key, options) { var _this = _super.call(this) || this; _this.key = key; @@ -5553,7 +4648,7 @@ var ConnectionManager = (function (_super) { _this.errorCallbacks = _this.buildErrorCallbacks(); _this.connectionCallbacks = _this.buildConnectionCallbacks(_this.errorCallbacks); _this.handshakeCallbacks = _this.buildHandshakeCallbacks(_this.errorCallbacks); - var Network = runtime_1["default"].getNetwork(); + var Network = runtime.getNetwork(); Network.bind("online", function () { _this.timeline.info({ netinfo: "online" }); if (_this.state === "connecting" || _this.state === "unavailable") { @@ -5660,7 +4755,7 @@ var ConnectionManager = (function (_super) { if (delay > 0) { this.emit("connecting_in", Math.round(delay / 1000)); } - this.retryTimer = new timers_1.OneOffTimer(delay || 0, function () { + this.retryTimer = new OneOffTimer(delay || 0, function () { _this.disconnectInternally(); _this.connect(); }); @@ -5675,7 +4770,7 @@ var ConnectionManager = (function (_super) { ; ConnectionManager.prototype.setUnavailableTimer = function () { var _this = this; - this.unavailableTimer = new timers_1.OneOffTimer(this.options.unavailableTimeout, function () { + this.unavailableTimer = new OneOffTimer(this.options.unavailableTimeout, function () { _this.updateState("unavailable"); }); }; @@ -5690,7 +4785,7 @@ var ConnectionManager = (function (_super) { var _this = this; this.stopActivityCheck(); this.connection.ping(); - this.activityTimer = new timers_1.OneOffTimer(this.options.pongTimeout, function () { + this.activityTimer = new OneOffTimer(this.options.pongTimeout, function () { _this.timeline.error({ pong_timed_out: _this.options.pongTimeout }); _this.retryIn(0); }); @@ -5700,7 +4795,7 @@ var ConnectionManager = (function (_super) { var _this = this; this.stopActivityCheck(); if (this.connection && !this.connection.handlesActivityChecks()) { - this.activityTimer = new timers_1.OneOffTimer(this.activityTimeout, function () { + this.activityTimer = new OneOffTimer(this.activityTimeout, function () { _this.sendActivityCheck(); }); } @@ -5714,7 +4809,7 @@ var ConnectionManager = (function (_super) { ; ConnectionManager.prototype.buildConnectionCallbacks = function (errorCallbacks) { var _this = this; - return Collections.extend({}, errorCallbacks, { + return extend({}, errorCallbacks, { message: function (message) { _this.resetActivityCheck(); _this.emit('message', message); @@ -5739,7 +4834,7 @@ var ConnectionManager = (function (_super) { ; ConnectionManager.prototype.buildHandshakeCallbacks = function (errorCallbacks) { var _this = this; - return Collections.extend({}, errorCallbacks, { + return extend({}, errorCallbacks, { connected: function (handshake) { _this.activityTimeout = Math.min(_this.options.activityTimeout, handshake.activityTimeout, handshake.connection.activityTimeout || Infinity); _this.clearUnavailableTimer(); @@ -5806,7 +4901,7 @@ var ConnectionManager = (function (_super) { if (newStateDescription === "connected") { newStateDescription += " with new socket ID " + data.socket_id; } - logger_1["default"].debug('State changed', previousState + ' -> ' + newStateDescription); + logger.debug('State changed', previousState + ' -> ' + newStateDescription); this.timeline.info({ state: newState, params: data }); this.emit('state_change', { previous: previousState, current: newState }); this.emit(newState, data); @@ -5816,21 +4911,14 @@ var ConnectionManager = (function (_super) { return this.state === "connecting" || this.state === "connected"; }; return ConnectionManager; -}(dispatcher_1["default"])); -exports["default"] = ConnectionManager; +}(dispatcher)); +/* harmony default export */ var connection_manager = (connection_manager_ConnectionManager); +// CONCATENATED MODULE: ./src/core/channels/channels.ts -/***/ }), -/* 48 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var Collections = __webpack_require__(0); -var factory_1 = __webpack_require__(7); -var Errors = __webpack_require__(5); -var Channels = (function () { +var channels_Channels = (function () { function Channels() { this.channels = {}; } @@ -5841,7 +4929,7 @@ var Channels = (function () { return this.channels[name]; }; Channels.prototype.all = function () { - return Collections.values(this.channels); + return values(this.channels); }; Channels.prototype.find = function (name) { return this.channels[name]; @@ -5852,45 +4940,200 @@ var Channels = (function () { return channel; }; Channels.prototype.disconnect = function () { - Collections.objectApply(this.channels, function (channel) { + objectApply(this.channels, function (channel) { channel.disconnect(); }); }; return Channels; }()); -exports["default"] = Channels; +/* harmony default export */ var channels = (channels_Channels); function createChannel(name, pusher) { if (name.indexOf('private-encrypted-') === 0) { if (false) { var errorMsg; } - return factory_1["default"].createEncryptedChannel(name, pusher); + return factory.createEncryptedChannel(name, pusher); } else if (name.indexOf('private-') === 0) { - return factory_1["default"].createPrivateChannel(name, pusher); + return factory.createPrivateChannel(name, pusher); } else if (name.indexOf('presence-') === 0) { - return factory_1["default"].createPresenceChannel(name, pusher); + return factory.createPresenceChannel(name, pusher); } else { - return factory_1["default"].createChannel(name, pusher); + return factory.createChannel(name, pusher); } } +// CONCATENATED MODULE: ./src/core/utils/factory.ts -/***/ }), -/* 49 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var Collections = __webpack_require__(0); -var util_1 = __webpack_require__(2); -var BestConnectedEverStrategy = (function () { + + + + + + + +var Factory = { + createChannels: function () { + return new channels(); + }, + createConnectionManager: function (key, options) { + return new connection_manager(key, options); + }, + createChannel: function (name, pusher) { + return new channels_channel(name, pusher); + }, + createPrivateChannel: function (name, pusher) { + return new private_channel(name, pusher); + }, + createPresenceChannel: function (name, pusher) { + return new presence_channel(name, pusher); + }, + createEncryptedChannel: function (name, pusher) { + return new encrypted_channel(name, pusher); + }, + createTimelineSender: function (timeline, options) { + return new timeline_sender(timeline, options); + }, + createAuthorizer: function (channel, options) { + if (options.authorizer) { + return options.authorizer(channel, options); + } + return new pusher_authorizer(channel, options); + }, + createHandshake: function (transport, callback) { + return new connection_handshake(transport, callback); + }, + createAssistantToTheTransportManager: function (manager, transport, options) { + return new assistant_to_the_transport_manager(manager, transport, options); + } +}; +/* harmony default export */ var factory = (Factory); + +// CONCATENATED MODULE: ./src/core/transports/transport_manager.ts + +var transport_manager_TransportManager = (function () { + function TransportManager(options) { + this.options = options || {}; + this.livesLeft = this.options.lives || Infinity; + } + TransportManager.prototype.getAssistant = function (transport) { + return factory.createAssistantToTheTransportManager(this, transport, { + minPingDelay: this.options.minPingDelay, + maxPingDelay: this.options.maxPingDelay + }); + }; + TransportManager.prototype.isAlive = function () { + return this.livesLeft > 0; + }; + TransportManager.prototype.reportDeath = function () { + this.livesLeft -= 1; + }; + return TransportManager; +}()); +/* harmony default export */ var transport_manager = (transport_manager_TransportManager); + +// CONCATENATED MODULE: ./src/core/strategies/sequential_strategy.ts + + + +var sequential_strategy_SequentialStrategy = (function () { + function SequentialStrategy(strategies, options) { + this.strategies = strategies; + this.loop = Boolean(options.loop); + this.failFast = Boolean(options.failFast); + this.timeout = options.timeout; + this.timeoutLimit = options.timeoutLimit; + } + SequentialStrategy.prototype.isSupported = function () { + return any(this.strategies, util.method("isSupported")); + }; + SequentialStrategy.prototype.connect = function (minPriority, callback) { + var _this = this; + var strategies = this.strategies; + var current = 0; + var timeout = this.timeout; + var runner = null; + var tryNextStrategy = function (error, handshake) { + if (handshake) { + callback(null, handshake); + } + else { + current = current + 1; + if (_this.loop) { + current = current % strategies.length; + } + if (current < strategies.length) { + if (timeout) { + timeout = timeout * 2; + if (_this.timeoutLimit) { + timeout = Math.min(timeout, _this.timeoutLimit); + } + } + runner = _this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: _this.failFast }, tryNextStrategy); + } + else { + callback(true); + } + } + }; + runner = this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: this.failFast }, tryNextStrategy); + return { + abort: function () { + runner.abort(); + }, + forceMinPriority: function (p) { + minPriority = p; + if (runner) { + runner.forceMinPriority(p); + } + } + }; + }; + SequentialStrategy.prototype.tryStrategy = function (strategy, minPriority, options, callback) { + var timer = null; + var runner = null; + if (options.timeout > 0) { + timer = new OneOffTimer(options.timeout, function () { + runner.abort(); + callback(true); + }); + } + runner = strategy.connect(minPriority, function (error, handshake) { + if (error && timer && timer.isRunning() && !options.failFast) { + return; + } + if (timer) { + timer.ensureAborted(); + } + callback(error, handshake); + }); + return { + abort: function () { + if (timer) { + timer.ensureAborted(); + } + runner.abort(); + }, + forceMinPriority: function (p) { + runner.forceMinPriority(p); + } + }; + }; + return SequentialStrategy; +}()); +/* harmony default export */ var sequential_strategy = (sequential_strategy_SequentialStrategy); + +// CONCATENATED MODULE: ./src/core/strategies/best_connected_ever_strategy.ts + + +var best_connected_ever_strategy_BestConnectedEverStrategy = (function () { function BestConnectedEverStrategy(strategies) { this.strategies = strategies; } BestConnectedEverStrategy.prototype.isSupported = function () { - return Collections.any(this.strategies, util_1["default"].method("isSupported")); + return any(this.strategies, util.method("isSupported")); }; BestConnectedEverStrategy.prototype.connect = function (minPriority, callback) { return connect(this.strategies, minPriority, function (i, runners) { @@ -5902,7 +5145,7 @@ var BestConnectedEverStrategy = (function () { } return; } - Collections.apply(runners, function (runner) { + apply(runners, function (runner) { runner.forceMinPriority(handshake.transport.priority); }); callback(null, handshake); @@ -5911,24 +5154,24 @@ var BestConnectedEverStrategy = (function () { }; return BestConnectedEverStrategy; }()); -exports["default"] = BestConnectedEverStrategy; +/* harmony default export */ var best_connected_ever_strategy = (best_connected_ever_strategy_BestConnectedEverStrategy); function connect(strategies, minPriority, callbackBuilder) { - var runners = Collections.map(strategies, function (strategy, i, _, rs) { + var runners = map(strategies, function (strategy, i, _, rs) { return strategy.connect(minPriority, callbackBuilder(i, rs)); }); return { abort: function () { - Collections.apply(runners, abortRunner); + apply(runners, abortRunner); }, forceMinPriority: function (p) { - Collections.apply(runners, function (runner) { + apply(runners, function (runner) { runner.forceMinPriority(p); }); } }; } function allRunnersFailed(runners) { - return Collections.all(runners, function (runner) { + return collections_all(runners, function (runner) { return Boolean(runner.error); }); } @@ -5939,19 +5182,12 @@ function abortRunner(runner) { } } +// CONCATENATED MODULE: ./src/core/strategies/cached_strategy.ts -/***/ }), -/* 50 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var util_1 = __webpack_require__(2); -var runtime_1 = __webpack_require__(1); -var sequential_strategy_1 = __webpack_require__(18); -var Collections = __webpack_require__(0); -var CachedStrategy = (function () { + +var cached_strategy_CachedStrategy = (function () { function CachedStrategy(strategy, transports, options) { this.strategy = strategy; this.transports = transports; @@ -5966,7 +5202,7 @@ var CachedStrategy = (function () { var usingTLS = this.usingTLS; var info = fetchTransportCache(usingTLS); var strategies = [this.strategy]; - if (info && info.timestamp + this.ttl >= util_1["default"].now()) { + if (info && info.timestamp + this.ttl >= util.now()) { var transport = this.transports[info.transport]; if (transport) { this.timeline.info({ @@ -5974,18 +5210,18 @@ var CachedStrategy = (function () { transport: info.transport, latency: info.latency }); - strategies.push(new sequential_strategy_1["default"]([transport], { + strategies.push(new sequential_strategy([transport], { timeout: info.latency * 2 + 1000, failFast: true })); } } - var startTimestamp = util_1["default"].now(); + var startTimestamp = util.now(); var runner = strategies.pop().connect(minPriority, function cb(error, handshake) { if (error) { flushTransportCache(usingTLS); if (strategies.length > 0) { - startTimestamp = util_1["default"].now(); + startTimestamp = util.now(); runner = strategies.pop().connect(minPriority, cb); } else { @@ -5993,7 +5229,7 @@ var CachedStrategy = (function () { } } else { - storeTransportCache(usingTLS, handshake.transport.name, util_1["default"].now() - startTimestamp); + storeTransportCache(usingTLS, handshake.transport.name, util.now() - startTimestamp); callback(null, handshake); } }); @@ -6011,12 +5247,12 @@ var CachedStrategy = (function () { }; return CachedStrategy; }()); -exports["default"] = CachedStrategy; +/* harmony default export */ var cached_strategy = (cached_strategy_CachedStrategy); function getTransportCacheKey(usingTLS) { return "pusherTransport" + (usingTLS ? "TLS" : "NonTLS"); } function fetchTransportCache(usingTLS) { - var storage = runtime_1["default"].getLocalStorage(); + var storage = runtime.getLocalStorage(); if (storage) { try { var serializedCache = storage[getTransportCacheKey(usingTLS)]; @@ -6031,11 +5267,11 @@ function fetchTransportCache(usingTLS) { return null; } function storeTransportCache(usingTLS, transport, latency) { - var storage = runtime_1["default"].getLocalStorage(); + var storage = runtime.getLocalStorage(); if (storage) { try { - storage[getTransportCacheKey(usingTLS)] = Collections.safeJSONStringify({ - timestamp: util_1["default"].now(), + storage[getTransportCacheKey(usingTLS)] = safeJSONStringify({ + timestamp: util.now(), transport: transport, latency: latency }); @@ -6045,7 +5281,7 @@ function storeTransportCache(usingTLS, transport, latency) { } } function flushTransportCache(usingTLS) { - var storage = runtime_1["default"].getLocalStorage(); + var storage = runtime.getLocalStorage(); if (storage) { try { delete storage[getTransportCacheKey(usingTLS)]; @@ -6055,16 +5291,9 @@ function flushTransportCache(usingTLS) { } } +// CONCATENATED MODULE: ./src/core/strategies/delayed_strategy.ts -/***/ }), -/* 51 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var timers_1 = __webpack_require__(6); -var DelayedStrategy = (function () { +var delayed_strategy_DelayedStrategy = (function () { function DelayedStrategy(strategy, _a) { var number = _a.delay; this.strategy = strategy; @@ -6076,7 +5305,7 @@ var DelayedStrategy = (function () { DelayedStrategy.prototype.connect = function (minPriority, callback) { var strategy = this.strategy; var runner; - var timer = new timers_1.OneOffTimer(this.options.delay, function () { + var timer = new OneOffTimer(this.options.delay, function () { runner = strategy.connect(minPriority, callback); }); return { @@ -6096,16 +5325,9 @@ var DelayedStrategy = (function () { }; return DelayedStrategy; }()); -exports["default"] = DelayedStrategy; - - -/***/ }), -/* 52 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +/* harmony default export */ var delayed_strategy = (delayed_strategy_DelayedStrategy); -exports.__esModule = true; +// CONCATENATED MODULE: ./src/core/strategies/if_strategy.ts var IfStrategy = (function () { function IfStrategy(test, trueBranch, falseBranch) { this.test = test; @@ -6122,46 +5344,114 @@ var IfStrategy = (function () { }; return IfStrategy; }()); -exports["default"] = IfStrategy; +/* harmony default export */ var if_strategy = (IfStrategy); - -/***/ }), -/* 53 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; +// CONCATENATED MODULE: ./src/core/strategies/first_connected_strategy.ts var FirstConnectedStrategy = (function () { function FirstConnectedStrategy(strategy) { this.strategy = strategy; } - FirstConnectedStrategy.prototype.isSupported = function () { - return this.strategy.isSupported(); - }; - FirstConnectedStrategy.prototype.connect = function (minPriority, callback) { - var runner = this.strategy.connect(minPriority, function (error, handshake) { - if (handshake) { - runner.abort(); - } - callback(error, handshake); - }); - return runner; - }; - return FirstConnectedStrategy; -}()); -exports["default"] = FirstConnectedStrategy; - - -/***/ }), -/* 54 */ -/***/ (function(module, exports, __webpack_require__) { + FirstConnectedStrategy.prototype.isSupported = function () { + return this.strategy.isSupported(); + }; + FirstConnectedStrategy.prototype.connect = function (minPriority, callback) { + var runner = this.strategy.connect(minPriority, function (error, handshake) { + if (handshake) { + runner.abort(); + } + callback(error, handshake); + }); + return runner; + }; + return FirstConnectedStrategy; +}()); +/* harmony default export */ var first_connected_strategy = (FirstConnectedStrategy); + +// CONCATENATED MODULE: ./src/runtimes/web/default_strategy.ts + + + + + + + + +function testSupportsStrategy(strategy) { + return function () { + return strategy.isSupported(); + }; +} +var getDefaultStrategy = function (config, defineTransport) { + var definedTransports = {}; + function defineTransportStrategy(name, type, priority, options, manager) { + var transport = defineTransport(config, name, type, priority, options, manager); + definedTransports[name] = transport; + return transport; + } + var ws_options = { + hostNonTLS: config.wsHost + ":" + config.wsPort, + hostTLS: config.wsHost + ":" + config.wssPort, + httpPath: config.wsPath + }; + var wss_options = extend({}, ws_options, { + useTLS: true + }); + var sockjs_options = { + hostNonTLS: config.httpHost + ":" + config.httpPort, + hostTLS: config.httpHost + ":" + config.httpsPort, + httpPath: config.httpPath + }; + var timeouts = { + loop: true, + timeout: 15000, + timeoutLimit: 60000 + }; + var ws_manager = new transport_manager({ + lives: 2, + minPingDelay: 10000, + maxPingDelay: config.activity_timeout + }); + var streaming_manager = new transport_manager({ + lives: 2, + minPingDelay: 10000, + maxPingDelay: config.activity_timeout + }); + var ws_transport = defineTransportStrategy("ws", "ws", 3, ws_options, ws_manager); + var wss_transport = defineTransportStrategy("wss", "ws", 3, wss_options, ws_manager); + var sockjs_transport = defineTransportStrategy("sockjs", "sockjs", 1, sockjs_options); + var xhr_streaming_transport = defineTransportStrategy("xhr_streaming", "xhr_streaming", 1, sockjs_options, streaming_manager); + var xdr_streaming_transport = defineTransportStrategy("xdr_streaming", "xdr_streaming", 1, sockjs_options, streaming_manager); + var xhr_polling_transport = defineTransportStrategy("xhr_polling", "xhr_polling", 1, sockjs_options); + var xdr_polling_transport = defineTransportStrategy("xdr_polling", "xdr_polling", 1, sockjs_options); + var ws_loop = new sequential_strategy([ws_transport], timeouts); + var wss_loop = new sequential_strategy([wss_transport], timeouts); + var sockjs_loop = new sequential_strategy([sockjs_transport], timeouts); + var streaming_loop = new sequential_strategy([new if_strategy(testSupportsStrategy(xhr_streaming_transport), xhr_streaming_transport, xdr_streaming_transport)], timeouts); + var polling_loop = new sequential_strategy([new if_strategy(testSupportsStrategy(xhr_polling_transport), xhr_polling_transport, xdr_polling_transport)], timeouts); + var http_loop = new sequential_strategy([new if_strategy(testSupportsStrategy(streaming_loop), new best_connected_ever_strategy([streaming_loop, new delayed_strategy(polling_loop, { delay: 4000 })]), polling_loop)], timeouts); + var http_fallback_loop = new if_strategy(testSupportsStrategy(http_loop), http_loop, sockjs_loop); + var wsStrategy; + if (config.useTLS) { + wsStrategy = new best_connected_ever_strategy([ws_loop, new delayed_strategy(http_fallback_loop, { delay: 2000 })]); + } + else { + wsStrategy = new best_connected_ever_strategy([ + ws_loop, + new delayed_strategy(wss_loop, { delay: 2000 }), + new delayed_strategy(http_fallback_loop, { delay: 5000 }) + ]); + } + return new cached_strategy(new first_connected_strategy(new if_strategy(testSupportsStrategy(ws_transport), wsStrategy, http_fallback_loop)), definedTransports, { + ttl: 1800000, + timeline: config.timeline, + useTLS: config.useTLS + }); +}; +/* harmony default export */ var default_strategy = (getDefaultStrategy); -"use strict"; +// CONCATENATED MODULE: ./src/runtimes/web/transports/transport_connection_initializer.ts -exports.__esModule = true; -var dependencies_1 = __webpack_require__(11); -function default_1() { +/* harmony default export */ var transport_connection_initializer = (function () { var self = this; self.timeline.info(self.buildTimelineMessage({ transport: self.name + (self.options.useTLS ? "s" : "") @@ -6171,7 +5461,7 @@ function default_1() { } else if (self.hooks.file) { self.changeState("initializing"); - dependencies_1.Dependencies.load(self.hooks.file, { useTLS: self.options.useTLS }, function (error, callback) { + Dependencies.load(self.hooks.file, { useTLS: self.options.useTLS }, function (error, callback) { if (self.hooks.isInitialized()) { self.changeState("initialized"); callback(true); @@ -6188,38 +5478,15 @@ function default_1() { else { self.onClose(); } -} -exports["default"] = default_1; - - -/***/ }), -/* 55 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var http_xdomain_request_1 = __webpack_require__(56); -var http_1 = __webpack_require__(57); -http_1["default"].createXDR = function (method, url) { - return this.createRequest(http_xdomain_request_1["default"], method, url); -}; -exports["default"] = http_1["default"]; - - -/***/ }), -/* 56 */ -/***/ (function(module, exports, __webpack_require__) { +}); -"use strict"; +// CONCATENATED MODULE: ./src/runtimes/web/http/http_xdomain_request.ts -exports.__esModule = true; -var Errors = __webpack_require__(5); -var hooks = { +var http_xdomain_request_hooks = { getRequest: function (socket) { var xdr = new window.XDomainRequest(); xdr.ontimeout = function () { - socket.emit("error", new Errors.RequestTimedOut()); + socket.emit("error", new RequestTimedOut()); socket.close(); }; xdr.onerror = function (e) { @@ -6245,48 +5512,10 @@ var hooks = { xdr.abort(); } }; -exports["default"] = hooks; - - -/***/ }), -/* 57 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var http_request_1 = __webpack_require__(58); -var http_socket_1 = __webpack_require__(59); -var http_streaming_socket_1 = __webpack_require__(61); -var http_polling_socket_1 = __webpack_require__(62); -var http_xhr_request_1 = __webpack_require__(63); -var HTTP = { - createStreamingSocket: function (url) { - return this.createSocket(http_streaming_socket_1["default"], url); - }, - createPollingSocket: function (url) { - return this.createSocket(http_polling_socket_1["default"], url); - }, - createSocket: function (hooks, url) { - return new http_socket_1["default"](hooks, url); - }, - createXHR: function (method, url) { - return this.createRequest(http_xhr_request_1["default"], method, url); - }, - createRequest: function (hooks, method, url) { - return new http_request_1["default"](hooks, method, url); - } -}; -exports["default"] = HTTP; - - -/***/ }), -/* 58 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +/* harmony default export */ var http_xdomain_request = (http_xdomain_request_hooks); -var __extends = (this && this.__extends) || (function () { +// CONCATENATED MODULE: ./src/core/http/http_request.ts +var http_request_extends = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || @@ -6299,12 +5528,11 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var dispatcher_1 = __webpack_require__(4); + + var MAX_BUFFER_LENGTH = 256 * 1024; -var HTTPRequest = (function (_super) { - __extends(HTTPRequest, _super); +var http_request_HTTPRequest = (function (_super) { + http_request_extends(HTTPRequest, _super); function HTTPRequest(hooks, method, url) { var _this = _super.call(this) || this; _this.hooks = hooks; @@ -6319,7 +5547,7 @@ var HTTPRequest = (function (_super) { this.unloader = function () { _this.close(); }; - runtime_1["default"].addUnloadListener(this.unloader); + runtime.addUnloadListener(this.unloader); this.xhr.open(this.method, this.url, true); if (this.xhr.setRequestHeader) { this.xhr.setRequestHeader("Content-Type", "application/json"); @@ -6328,7 +5556,7 @@ var HTTPRequest = (function (_super) { }; HTTPRequest.prototype.close = function () { if (this.unloader) { - runtime_1["default"].removeUnloadListener(this.unloader); + runtime.removeUnloadListener(this.unloader); this.unloader = null; } if (this.xhr) { @@ -6365,27 +5593,29 @@ var HTTPRequest = (function (_super) { return this.position === buffer.length && buffer.length > MAX_BUFFER_LENGTH; }; return HTTPRequest; -}(dispatcher_1["default"])); -exports["default"] = HTTPRequest; +}(dispatcher)); +/* harmony default export */ var http_request = (http_request_HTTPRequest); + +// CONCATENATED MODULE: ./src/core/http/state.ts +var State; +(function (State) { + State[State["CONNECTING"] = 0] = "CONNECTING"; + State[State["OPEN"] = 1] = "OPEN"; + State[State["CLOSED"] = 3] = "CLOSED"; +})(State || (State = {})); +/* harmony default export */ var state = (State); +// CONCATENATED MODULE: ./src/core/http/http_socket.ts -/***/ }), -/* 59 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var state_1 = __webpack_require__(60); -var util_1 = __webpack_require__(2); -var runtime_1 = __webpack_require__(1); var autoIncrement = 1; -var HTTPSocket = (function () { +var http_socket_HTTPSocket = (function () { function HTTPSocket(hooks, url) { this.hooks = hooks; this.session = randomNumber(1000) + "/" + randomString(8); this.location = getLocation(url); - this.readyState = state_1["default"].CONNECTING; + this.readyState = state.CONNECTING; this.openStream(); } HTTPSocket.prototype.send = function (payload) { @@ -6398,9 +5628,9 @@ var HTTPSocket = (function () { this.onClose(code, reason, true); }; HTTPSocket.prototype.sendRaw = function (payload) { - if (this.readyState === state_1["default"].OPEN) { + if (this.readyState === state.OPEN) { try { - runtime_1["default"].createSocketRequest("POST", getUniqueURL(getSendURL(this.location, this.session))).start(payload); + runtime.createSocketRequest("POST", getUniqueURL(getSendURL(this.location, this.session))).start(payload); return true; } catch (e) { @@ -6418,7 +5648,7 @@ var HTTPSocket = (function () { ; HTTPSocket.prototype.onClose = function (code, reason, wasClean) { this.closeStream(); - this.readyState = state_1["default"].CLOSED; + this.readyState = state.CLOSED; if (this.onclose) { this.onclose({ code: code, @@ -6431,7 +5661,7 @@ var HTTPSocket = (function () { if (chunk.status !== 200) { return; } - if (this.readyState === state_1["default"].OPEN) { + if (this.readyState === state.OPEN) { this.onActivity(); } var payload; @@ -6461,11 +5691,11 @@ var HTTPSocket = (function () { } }; HTTPSocket.prototype.onOpen = function (options) { - if (this.readyState === state_1["default"].CONNECTING) { + if (this.readyState === state.CONNECTING) { if (options && options.hostname) { this.location.base = replaceHost(this.location.base, options.hostname); } - this.readyState = state_1["default"].OPEN; + this.readyState = state.OPEN; if (this.onopen) { this.onopen(); } @@ -6475,7 +5705,7 @@ var HTTPSocket = (function () { } }; HTTPSocket.prototype.onEvent = function (event) { - if (this.readyState === state_1["default"].OPEN && this.onmessage) { + if (this.readyState === state.OPEN && this.onmessage) { this.onmessage({ data: event }); } }; @@ -6491,7 +5721,7 @@ var HTTPSocket = (function () { }; HTTPSocket.prototype.openStream = function () { var _this = this; - this.stream = runtime_1["default"].createSocketRequest("POST", getUniqueURL(this.hooks.getReceiveURL(this.location, this.session))); + this.stream = runtime.createSocketRequest("POST", getUniqueURL(this.hooks.getReceiveURL(this.location, this.session))); this.stream.bind("chunk", function (chunk) { _this.onChunk(chunk); }); @@ -6505,7 +5735,7 @@ var HTTPSocket = (function () { this.stream.start(); } catch (error) { - util_1["default"].defer(function () { + util.defer(function () { _this.onError(error); _this.onClose(1006, "Could not start streaming", false); }); @@ -6548,33 +5778,10 @@ function randomString(length) { } return result.join(''); } -exports["default"] = HTTPSocket; - - -/***/ }), -/* 60 */ -/***/ (function(module, exports, __webpack_require__) { +/* harmony default export */ var http_socket = (http_socket_HTTPSocket); -"use strict"; - -exports.__esModule = true; -var State; -(function (State) { - State[State["CONNECTING"] = 0] = "CONNECTING"; - State[State["OPEN"] = 1] = "OPEN"; - State[State["CLOSED"] = 3] = "CLOSED"; -})(State || (State = {})); -exports["default"] = State; - - -/***/ }), -/* 61 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var hooks = { +// CONCATENATED MODULE: ./src/core/http/http_streaming_socket.ts +var http_streaming_socket_hooks = { getReceiveURL: function (url, session) { return url.base + "/" + session + "/xhr_streaming" + url.queryString; }, @@ -6588,17 +5795,10 @@ var hooks = { socket.onClose(1006, "Connection interrupted (" + status + ")", false); } }; -exports["default"] = hooks; - +/* harmony default export */ var http_streaming_socket = (http_streaming_socket_hooks); -/***/ }), -/* 62 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var hooks = { +// CONCATENATED MODULE: ./src/core/http/http_polling_socket.ts +var http_polling_socket_hooks = { getReceiveURL: function (url, session) { return url.base + "/" + session + "/xhr" + url.queryString; }, @@ -6616,20 +5816,13 @@ var hooks = { } } }; -exports["default"] = hooks; - - -/***/ }), -/* 63 */ -/***/ (function(module, exports, __webpack_require__) { +/* harmony default export */ var http_polling_socket = (http_polling_socket_hooks); -"use strict"; +// CONCATENATED MODULE: ./src/runtimes/isomorphic/http/http_xhr_request.ts -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var hooks = { +var http_xhr_request_hooks = { getRequest: function (socket) { - var Constructor = runtime_1["default"].getXHRAPI(); + var Constructor = runtime.getXHRAPI(); var xhr = new Constructor(); xhr.onreadystatechange = xhr.onprogress = function () { switch (xhr.readyState) { @@ -6654,20 +5847,192 @@ var hooks = { xhr.abort(); } }; -exports["default"] = hooks; +/* harmony default export */ var http_xhr_request = (http_xhr_request_hooks); + +// CONCATENATED MODULE: ./src/runtimes/isomorphic/http/http.ts + + + + + +var HTTP = { + createStreamingSocket: function (url) { + return this.createSocket(http_streaming_socket, url); + }, + createPollingSocket: function (url) { + return this.createSocket(http_polling_socket, url); + }, + createSocket: function (hooks, url) { + return new http_socket(hooks, url); + }, + createXHR: function (method, url) { + return this.createRequest(http_xhr_request, method, url); + }, + createRequest: function (hooks, method, url) { + return new http_request(hooks, method, url); + } +}; +/* harmony default export */ var http_http = (HTTP); + +// CONCATENATED MODULE: ./src/runtimes/web/http/http.ts + + +http_http.createXDR = function (method, url) { + return this.createRequest(http_xdomain_request, method, url); +}; +/* harmony default export */ var web_http_http = (http_http); + +// CONCATENATED MODULE: ./src/runtimes/web/runtime.ts + + + + + + + + + + + + +var Runtime = { + nextAuthCallbackID: 1, + auth_callbacks: {}, + ScriptReceivers: ScriptReceivers, + DependenciesReceivers: DependenciesReceivers, + getDefaultStrategy: default_strategy, + Transports: transports_transports, + transportConnectionInitializer: transport_connection_initializer, + HTTPFactory: web_http_http, + TimelineTransport: jsonp_timeline, + getXHRAPI: function () { + return window.XMLHttpRequest; + }, + getWebSocketAPI: function () { + return window.WebSocket || window.MozWebSocket; + }, + setup: function (PusherClass) { + var _this = this; + window.Pusher = PusherClass; + var initializeOnDocumentBody = function () { + _this.onDocumentBody(PusherClass.ready); + }; + if (!window.JSON) { + Dependencies.load("json2", {}, initializeOnDocumentBody); + } + else { + initializeOnDocumentBody(); + } + }, + getDocument: function () { + return document; + }, + getProtocol: function () { + return this.getDocument().location.protocol; + }, + getAuthorizers: function () { + return { ajax: xhr_auth, jsonp: jsonp_auth }; + }, + onDocumentBody: function (callback) { + var _this = this; + if (document.body) { + callback(); + } + else { + setTimeout(function () { + _this.onDocumentBody(callback); + }, 0); + } + }, + createJSONPRequest: function (url, data) { + return new jsonp_request(url, data); + }, + createScriptRequest: function (src) { + return new script_request(src); + }, + getLocalStorage: function () { + try { + return window.localStorage; + } + catch (e) { + return undefined; + } + }, + createXHR: function () { + if (this.getXHRAPI()) { + return this.createXMLHttpRequest(); + } + else { + return this.createMicrosoftXHR(); + } + }, + createXMLHttpRequest: function () { + var Constructor = this.getXHRAPI(); + return new Constructor(); + }, + createMicrosoftXHR: function () { + return new ActiveXObject("Microsoft.XMLHTTP"); + }, + getNetwork: function () { + return net_info_Network; + }, + createWebSocket: function (url) { + var Constructor = this.getWebSocketAPI(); + return new Constructor(url); + }, + createSocketRequest: function (method, url) { + if (this.isXHRSupported()) { + return this.HTTPFactory.createXHR(method, url); + } + else if (this.isXDRSupported(url.indexOf("https:") === 0)) { + return this.HTTPFactory.createXDR(method, url); + } + else { + throw "Cross-origin HTTP requests are not supported"; + } + }, + isXHRSupported: function () { + var Constructor = this.getXHRAPI(); + return Boolean(Constructor) && (new Constructor()).withCredentials !== undefined; + }, + isXDRSupported: function (useTLS) { + var protocol = useTLS ? "https:" : "http:"; + var documentProtocol = this.getProtocol(); + return Boolean((window['XDomainRequest'])) && documentProtocol === protocol; + }, + addUnloadListener: function (listener) { + if (window.addEventListener !== undefined) { + window.addEventListener("unload", listener, false); + } + else if (window.attachEvent !== undefined) { + window.attachEvent("onunload", listener); + } + }, + removeUnloadListener: function (listener) { + if (window.addEventListener !== undefined) { + window.removeEventListener("unload", listener, false); + } + else if (window.detachEvent !== undefined) { + window.detachEvent("onunload", listener); + } + } +}; +/* harmony default export */ var runtime = (Runtime); + +// CONCATENATED MODULE: ./src/core/timeline/level.ts +var TimelineLevel; +(function (TimelineLevel) { + TimelineLevel[TimelineLevel["ERROR"] = 3] = "ERROR"; + TimelineLevel[TimelineLevel["INFO"] = 6] = "INFO"; + TimelineLevel[TimelineLevel["DEBUG"] = 7] = "DEBUG"; +})(TimelineLevel || (TimelineLevel = {})); +/* harmony default export */ var timeline_level = (TimelineLevel); +// CONCATENATED MODULE: ./src/core/timeline/timeline.ts -/***/ }), -/* 64 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var Collections = __webpack_require__(0); -var util_1 = __webpack_require__(2); -var level_1 = __webpack_require__(19); -var Timeline = (function () { +var timeline_Timeline = (function () { function Timeline(key, session, options) { this.key = key; this.session = session; @@ -6678,27 +6043,27 @@ var Timeline = (function () { } Timeline.prototype.log = function (level, event) { if (level <= this.options.level) { - this.events.push(Collections.extend({}, event, { timestamp: util_1["default"].now() })); + this.events.push(extend({}, event, { timestamp: util.now() })); if (this.options.limit && this.events.length > this.options.limit) { this.events.shift(); } } }; Timeline.prototype.error = function (event) { - this.log(level_1["default"].ERROR, event); + this.log(timeline_level.ERROR, event); }; Timeline.prototype.info = function (event) { - this.log(level_1["default"].INFO, event); + this.log(timeline_level.INFO, event); }; Timeline.prototype.debug = function (event) { - this.log(level_1["default"].DEBUG, event); + this.log(timeline_level.DEBUG, event); }; Timeline.prototype.isEmpty = function () { return this.events.length === 0; }; Timeline.prototype.send = function (sendfn, callback) { var _this = this; - var data = Collections.extend({ + var data = extend({ session: this.session, bundle: this.sent + 1, key: this.key, @@ -6725,75 +6090,14 @@ var Timeline = (function () { }; return Timeline; }()); -exports["default"] = Timeline; - - -/***/ }), -/* 65 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +/* harmony default export */ var timeline_timeline = (timeline_Timeline); -exports.__esModule = true; -var Collections = __webpack_require__(0); -var util_1 = __webpack_require__(2); -var Errors = __webpack_require__(5); -var transport_strategy_1 = __webpack_require__(66); -var runtime_1 = __webpack_require__(1); -var Transports = runtime_1["default"].Transports; -exports.defineTransport = function (config, name, type, priority, options, manager) { - var transportClass = Transports[type]; - if (!transportClass) { - throw new Errors.UnsupportedTransport(type); - } - var enabled = (!config.enabledTransports || - Collections.arrayIndexOf(config.enabledTransports, name) !== -1) && - (!config.disabledTransports || - Collections.arrayIndexOf(config.disabledTransports, name) === -1); - var transport; - if (enabled) { - transport = new transport_strategy_1["default"](name, priority, manager ? manager.getAssistant(transportClass) : transportClass, Collections.extend({ - key: config.key, - useTLS: config.useTLS, - timeline: config.timeline, - ignoreNullOrigin: config.ignoreNullOrigin - }, options)); - } - else { - transport = UnsupportedStrategy; - } - return transport; -}; -var UnsupportedStrategy = { - isSupported: function () { - return false; - }, - connect: function (_, callback) { - var deferred = util_1["default"].defer(function () { - callback(new Errors.UnsupportedStrategy()); - }); - return { - abort: function () { - deferred.ensureAborted(); - }, - forceMinPriority: function () { } - }; - } -}; +// CONCATENATED MODULE: ./src/core/strategies/transport_strategy.ts -/***/ }), -/* 66 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var factory_1 = __webpack_require__(7); -var util_1 = __webpack_require__(2); -var Errors = __webpack_require__(5); -var Collections = __webpack_require__(0); -var TransportStrategy = (function () { +var transport_strategy_TransportStrategy = (function () { function TransportStrategy(name, priority, transport, options) { this.name = name; this.priority = priority; @@ -6808,10 +6112,10 @@ var TransportStrategy = (function () { TransportStrategy.prototype.connect = function (minPriority, callback) { var _this = this; if (!this.isSupported()) { - return failAttempt(new Errors.UnsupportedStrategy(), callback); + return failAttempt(new UnsupportedStrategy(), callback); } else if (this.priority < minPriority) { - return failAttempt(new Errors.TransportPriorityTooLow(), callback); + return failAttempt(new TransportPriorityTooLow(), callback); } var connected = false; var transport = this.transport.createConnection(this.name, this.priority, this.options.key, this.options); @@ -6821,7 +6125,7 @@ var TransportStrategy = (function () { transport.connect(); }; var onOpen = function () { - handshake = factory_1["default"].createHandshake(transport, function (result) { + handshake = factory.createHandshake(transport, function (result) { connected = true; unbindListeners(); callback(null, result); @@ -6834,8 +6138,8 @@ var TransportStrategy = (function () { var onClosed = function () { unbindListeners(); var serializedTransport; - serializedTransport = Collections.safeJSONStringify(transport); - callback(new Errors.TransportClosed(serializedTransport)); + serializedTransport = safeJSONStringify(transport); + callback(new TransportClosed(serializedTransport)); }; var unbindListeners = function () { transport.unbind("initialized", onInitialized); @@ -6878,9 +6182,9 @@ var TransportStrategy = (function () { }; return TransportStrategy; }()); -exports["default"] = TransportStrategy; +/* harmony default export */ var transport_strategy = (transport_strategy_TransportStrategy); function failAttempt(error, callback) { - util_1["default"].defer(function () { + util.defer(function () { callback(error); }); return { @@ -6889,40 +6193,289 @@ function failAttempt(error, callback) { }; } +// CONCATENATED MODULE: ./src/core/strategies/strategy_builder.ts -/***/ }), -/* 67 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var defaults_1 = __webpack_require__(9); -exports.getGlobalConfig = function () { + + +var strategy_builder_Transports = runtime.Transports; +var strategy_builder_defineTransport = function (config, name, type, priority, options, manager) { + var transportClass = strategy_builder_Transports[type]; + if (!transportClass) { + throw new UnsupportedTransport(type); + } + var enabled = (!config.enabledTransports || + arrayIndexOf(config.enabledTransports, name) !== -1) && + (!config.disabledTransports || + arrayIndexOf(config.disabledTransports, name) === -1); + var transport; + if (enabled) { + transport = new transport_strategy(name, priority, manager ? manager.getAssistant(transportClass) : transportClass, extend({ + key: config.key, + useTLS: config.useTLS, + timeline: config.timeline, + ignoreNullOrigin: config.ignoreNullOrigin + }, options)); + } + else { + transport = strategy_builder_UnsupportedStrategy; + } + return transport; +}; +var strategy_builder_UnsupportedStrategy = { + isSupported: function () { + return false; + }, + connect: function (_, callback) { + var deferred = util.defer(function () { + callback(new UnsupportedStrategy()); + }); + return { + abort: function () { + deferred.ensureAborted(); + }, + forceMinPriority: function () { } + }; + } +}; + +// CONCATENATED MODULE: ./src/core/config.ts + +var getGlobalConfig = function () { return { - wsHost: defaults_1["default"].host, - wsPort: defaults_1["default"].ws_port, - wssPort: defaults_1["default"].wss_port, - wsPath: defaults_1["default"].ws_path, - httpHost: defaults_1["default"].sockjs_host, - httpPort: defaults_1["default"].sockjs_http_port, - httpsPort: defaults_1["default"].sockjs_https_port, - httpPath: defaults_1["default"].sockjs_path, - statsHost: defaults_1["default"].stats_host, - authEndpoint: defaults_1["default"].channel_auth_endpoint, - authTransport: defaults_1["default"].channel_auth_transport, - activity_timeout: defaults_1["default"].activity_timeout, - pong_timeout: defaults_1["default"].pong_timeout, - unavailable_timeout: defaults_1["default"].unavailable_timeout + wsHost: defaults.host, + wsPort: defaults.ws_port, + wssPort: defaults.wss_port, + wsPath: defaults.ws_path, + httpHost: defaults.sockjs_host, + httpPort: defaults.sockjs_http_port, + httpsPort: defaults.sockjs_https_port, + httpPath: defaults.sockjs_path, + statsHost: defaults.stats_host, + authEndpoint: defaults.channel_auth_endpoint, + authTransport: defaults.channel_auth_transport, + activity_timeout: defaults.activity_timeout, + pong_timeout: defaults.pong_timeout, + unavailable_timeout: defaults.unavailable_timeout }; }; -exports.getClusterConfig = function (clusterName) { +var getClusterConfig = function (clusterName) { return { - wsHost: "ws-" + clusterName + ".pusher.com", - httpHost: "sockjs-" + clusterName + ".pusher.com" + wsHost: 'ws-' + clusterName + '.pusher.com', + httpHost: 'sockjs-' + clusterName + '.pusher.com' }; }; +// CONCATENATED MODULE: ./src/core/pusher.ts + + + + + + + + + + + + +var pusher_Pusher = (function () { + function Pusher(app_key, options) { + var _this = this; + checkAppKey(app_key); + options = options || {}; + if (!options.cluster && !(options.wsHost || options.httpHost)) { + var suffix = url_store.buildLogSuffix('javascriptQuickStart'); + logger.warn("You should always specify a cluster when connecting. " + suffix); + } + this.key = app_key; + this.config = extend(getGlobalConfig(), options.cluster ? getClusterConfig(options.cluster) : {}, options); + this.channels = factory.createChannels(); + this.global_emitter = new dispatcher(); + this.sessionID = Math.floor(Math.random() * 1000000000); + this.timeline = new timeline_timeline(this.key, this.sessionID, { + cluster: this.config.cluster, + features: Pusher.getClientFeatures(), + params: this.config.timelineParams || {}, + limit: 50, + level: timeline_level.INFO, + version: defaults.VERSION + }); + if (!this.config.disableStats) { + this.timelineSender = factory.createTimelineSender(this.timeline, { + host: this.config.statsHost, + path: '/timeline/v2/' + runtime.TimelineTransport.name + }); + } + var getStrategy = function (options) { + var config = extend({}, _this.config, options); + return runtime.getDefaultStrategy(config, strategy_builder_defineTransport); + }; + this.connection = factory.createConnectionManager(this.key, extend({ + getStrategy: getStrategy, + timeline: this.timeline, + activityTimeout: this.config.activity_timeout, + pongTimeout: this.config.pong_timeout, + unavailableTimeout: this.config.unavailable_timeout + }, this.config, { useTLS: this.shouldUseTLS() })); + this.connection.bind('connected', function () { + _this.subscribeAll(); + if (_this.timelineSender) { + _this.timelineSender.send(_this.connection.isUsingTLS()); + } + }); + this.connection.bind('message', function (event) { + var eventName = event.event; + var internal = eventName.indexOf('pusher_internal:') === 0; + if (event.channel) { + var channel = _this.channel(event.channel); + if (channel) { + channel.handleEvent(event); + } + } + if (!internal) { + _this.global_emitter.emit(event.event, event.data); + } + }); + this.connection.bind('connecting', function () { + _this.channels.disconnect(); + }); + this.connection.bind('disconnected', function () { + _this.channels.disconnect(); + }); + this.connection.bind('error', function (err) { + logger.warn('Error', err); + }); + Pusher.instances.push(this); + this.timeline.info({ instances: Pusher.instances.length }); + if (Pusher.isReady) { + this.connect(); + } + } + Pusher.ready = function () { + Pusher.isReady = true; + for (var i = 0, l = Pusher.instances.length; i < l; i++) { + Pusher.instances[i].connect(); + } + }; + Pusher.log = function (message) { + if (Pusher.logToConsole && window.console && window.console.log) { + window.console.log(message); + } + }; + Pusher.getClientFeatures = function () { + return keys(filterObject({ ws: runtime.Transports.ws }, function (t) { + return t.isSupported({}); + })); + }; + Pusher.prototype.channel = function (name) { + return this.channels.find(name); + }; + Pusher.prototype.allChannels = function () { + return this.channels.all(); + }; + Pusher.prototype.connect = function () { + this.connection.connect(); + if (this.timelineSender) { + if (!this.timelineSenderTimer) { + var usingTLS = this.connection.isUsingTLS(); + var timelineSender = this.timelineSender; + this.timelineSenderTimer = new PeriodicTimer(60000, function () { + timelineSender.send(usingTLS); + }); + } + } + }; + Pusher.prototype.disconnect = function () { + this.connection.disconnect(); + if (this.timelineSenderTimer) { + this.timelineSenderTimer.ensureAborted(); + this.timelineSenderTimer = null; + } + }; + Pusher.prototype.bind = function (event_name, callback, context) { + this.global_emitter.bind(event_name, callback, context); + return this; + }; + Pusher.prototype.unbind = function (event_name, callback, context) { + this.global_emitter.unbind(event_name, callback, context); + return this; + }; + Pusher.prototype.bind_global = function (callback) { + this.global_emitter.bind_global(callback); + return this; + }; + Pusher.prototype.unbind_global = function (callback) { + this.global_emitter.unbind_global(callback); + return this; + }; + Pusher.prototype.unbind_all = function (callback) { + this.global_emitter.unbind_all(); + return this; + }; + Pusher.prototype.subscribeAll = function () { + var channelName; + for (channelName in this.channels.channels) { + if (this.channels.channels.hasOwnProperty(channelName)) { + this.subscribe(channelName); + } + } + }; + Pusher.prototype.subscribe = function (channel_name) { + var channel = this.channels.add(channel_name, this); + if (channel.subscriptionPending && channel.subscriptionCancelled) { + channel.reinstateSubscription(); + } + else if (!channel.subscriptionPending && + this.connection.state === 'connected') { + channel.subscribe(); + } + return channel; + }; + Pusher.prototype.unsubscribe = function (channel_name) { + var channel = this.channels.find(channel_name); + if (channel && channel.subscriptionPending) { + channel.cancelSubscription(); + } + else { + channel = this.channels.remove(channel_name); + if (channel && this.connection.state === 'connected') { + channel.unsubscribe(); + } + } + }; + Pusher.prototype.send_event = function (event_name, data, channel) { + return this.connection.send_event(event_name, data, channel); + }; + Pusher.prototype.shouldUseTLS = function () { + if (runtime.getProtocol() === 'https:') { + return true; + } + else if (this.config.forceTLS === true) { + return true; + } + else { + return Boolean(this.config.encrypted); + } + }; + Pusher.instances = []; + Pusher.isReady = false; + Pusher.logToConsole = false; + Pusher.Runtime = runtime; + Pusher.ScriptReceivers = runtime.ScriptReceivers; + Pusher.DependenciesReceivers = runtime.DependenciesReceivers; + Pusher.auth_callbacks = runtime.auth_callbacks; + return Pusher; +}()); +/* harmony default export */ var core_pusher = __webpack_exports__["default"] = (pusher_Pusher); +function checkAppKey(key) { + if (key === null || key === undefined) { + throw 'You must pass your app key when you instantiate Pusher.'; + } +} +runtime.setup(pusher_Pusher); + /***/ }) /******/ ]); diff --git a/dist/web/pusher.min.js b/dist/web/pusher.min.js index 68001932d..d998c5e46 100644 --- a/dist/web/pusher.min.js +++ b/dist/web/pusher.min.js @@ -1,8 +1,8 @@ /*! - * Pusher JavaScript Library v5.0.1 + * Pusher JavaScript Library v5.0.2 * https://pusher.com/ * * Copyright 2017, Pusher * Released under the MIT licence. */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Pusher=e():t.Pusher=e()}(window,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=20)}([function(t,e,n){"use strict";e.__esModule=!0;var r=n(23),o=n(2);function i(t,e){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e(t[n],n,t)}function s(t,e){for(var n=[],r=0;r0)for(r=0;r=1002&&t.code<=1004?"backoff":null:4e3===t.code?"tls_only":t.code<4100?"refused":t.code<4200?"backoff":t.code<4300?"retry":"refused"},e.getCloseError=function(t){return 1e3!==t.code&&1001!==t.code?{type:"PusherError",data:{code:t.code,message:t.reason||t.message}}:null}},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var i=n(4),s=n(5),a=n(3),u=n(10),c=function(t){function e(e,n){var r=t.call(this,function(t,n){a.default.debug("No callbacks on "+e+" for "+t)})||this;return r.name=e,r.pusher=n,r.subscribed=!1,r.subscriptionPending=!1,r.subscriptionCancelled=!1,r}return o(e,t),e.prototype.authorize=function(t,e){return e(!1,{})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new s.BadEventName("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var n=u.default.buildLogSuffix("triggeringClientEvents");a.default.warn("Client event triggered before channel 'subscription_succeeded' event . "+n)}return this.pusher.send_event(t,e,this.name)},e.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},e.prototype.handleEvent=function(t){var e=t.event,n=t.data;if("pusher_internal:subscription_succeeded"===e)this.handleSubscriptionSucceededEvent(t);else if(0!==e.indexOf("pusher_internal:")){this.emit(e,n,{})}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",t.data)},e.prototype.subscribe=function(){var t=this;this.subscribed||(this.subscriptionPending=!0,this.subscriptionCancelled=!1,this.authorize(this.pusher.connection.socket_id,function(e,n){e?t.emit("pusher:subscription_error",n):t.pusher.send_event("pusher:subscribe",{auth:n.auth,channel_data:n.channel_data,channel:t.name})}))},e.prototype.unsubscribe=function(){this.subscribed=!1,this.pusher.send_event("pusher:unsubscribe",{channel:this.name})},e.prototype.cancelSubscription=function(){this.subscriptionCancelled=!0},e.prototype.reinstateSubscription=function(){this.subscriptionCancelled=!1},e}(i.default);e.default=c},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(2),i=n(6),s=function(){function t(t,e){this.strategies=t,this.loop=Boolean(e.loop),this.failFast=Boolean(e.failFast),this.timeout=e.timeout,this.timeoutLimit=e.timeoutLimit}return t.prototype.isSupported=function(){return r.any(this.strategies,o.default.method("isSupported"))},t.prototype.connect=function(t,e){var n=this,r=this.strategies,o=0,i=this.timeout,s=null,a=function(u,c){c?e(null,c):(o+=1,n.loop&&(o%=r.length),o0&&(o=new i.OneOffTimer(n.timeout,function(){s.abort(),r(!0)})),s=t.connect(e,function(t,e){t&&o&&o.isRunning()&&!n.failFast||(o&&o.ensureAborted(),r(t,e))}),{abort:function(){o&&o.ensureAborted(),s.abort()},forceMinPriority:function(t){s.forceMinPriority(t)}}},t}();e.default=s},function(t,e,n){"use strict";var r;e.__esModule=!0,function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(r||(r={})),e.default=r},function(t,e,n){"use strict";e.__esModule=!0;var r=n(13);t.exports=r.default},function(t,e,n){"use strict";e.__esModule=!0;var r=n(8),o=n(1),i=function(){function t(t){this.options=t,this.receivers=t.receivers||r.ScriptReceivers,this.loading={}}return t.prototype.load=function(t,e,n){var r=this;if(r.loading[t]&&r.loading[t].length>0)r.loading[t].push(n);else{r.loading[t]=[n];var i=o.default.createScriptRequest(r.getPath(t,e)),s=r.receivers.create(function(e){if(r.receivers.remove(s),r.loading[t]){var n=r.loading[t];delete r.loading[t];for(var o=function(t){t||i.cleanup()},a=0;a>>6)+r(128|63&e):r(224|e>>>12&15)+r(128|e>>>6&63)+r(128|63&e)},c=function(t){return t.replace(/[^\x00-\x7F]/g,u)},h=function(t){var e=[0,2,1][t.length%3],n=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[o.charAt(n>>>18),o.charAt(n>>>12&63),e>=2?"=":o.charAt(n>>>6&63),e>=1?"=":o.charAt(63&n)].join("")},f=window.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,h)}},function(t,e,n){"use strict";e.__esModule=!0;var r=function(){function t(t,e,n,r){var o=this;this.clear=e,this.timer=t(function(){o.timer&&(o.timer=r(o.timer))},n)}return t.prototype.isRunning=function(){return null!==this.timer},t.prototype.ensureAborted=function(){this.timer&&(this.clear(this.timer),this.timer=null)},t}();e.default=r},function(t,e,n){"use strict";e.__esModule=!0;var r=n(3);e.default=function(t,e,n){void 0!==this.authOptions.headers&&r.default.warn("Warn","To send headers with the auth request, you must use AJAX, rather than JSONP.");var o=t.nextAuthCallbackID.toString();t.nextAuthCallbackID++;var i=t.getDocument(),s=i.createElement("script");t.auth_callbacks[o]=function(t){n(!1,t)};var a="Pusher.auth_callbacks['"+o+"']";s.src=this.options.authEndpoint+"?callback="+encodeURIComponent(a)+"&"+this.composeQuery(e);var u=i.getElementsByTagName("head")[0]||i.documentElement;u.insertBefore(s,u.firstChild)}},function(t,e,n){"use strict";e.__esModule=!0;var r=function(){function t(t){this.src=t}return t.prototype.send=function(t){var e=this,n="Error loading "+e.src;e.script=document.createElement("script"),e.script.id=t.id,e.script.src=e.src,e.script.type="text/javascript",e.script.charset="UTF-8",e.script.addEventListener?(e.script.onerror=function(){t.callback(n)},e.script.onload=function(){t.callback(null)}):e.script.onreadystatechange=function(){"loaded"!==e.script.readyState&&"complete"!==e.script.readyState||t.callback(null)},void 0===e.script.async&&document.attachEvent&&/opera/i.test(navigator.userAgent)?(e.errorScript=document.createElement("script"),e.errorScript.id=t.id+"_error",e.errorScript.text=t.name+"('"+n+"');",e.script.async=e.errorScript.async=!1):e.script.async=!0;var r=document.getElementsByTagName("head")[0];r.insertBefore(e.script,r.firstChild),e.errorScript&&r.insertBefore(e.errorScript,e.script.nextSibling)},t.prototype.cleanup=function(){this.script&&(this.script.onload=this.script.onerror=null,this.script.onreadystatechange=null),this.script&&this.script.parentNode&&this.script.parentNode.removeChild(this.script),this.errorScript&&this.errorScript.parentNode&&this.errorScript.parentNode.removeChild(this.errorScript),this.script=null,this.errorScript=null},t}();e.default=r},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(1),i=function(){function t(t,e){this.url=t,this.data=e}return t.prototype.send=function(t){if(!this.request){var e=r.buildQueryString(this.data),n=this.url+"/"+t.number+"?"+e;this.request=o.default.createScriptRequest(n),this.request.send(t)}},t.prototype.cleanup=function(){this.request&&this.request.cleanup()},t}();e.default=i},function(t,e,n){"use strict";e.__esModule=!0;var r=n(1),o=n(8),i={name:"jsonp",getAgent:function(t,e){return function(n,i){var s="http"+(e?"s":"")+"://"+(t.host||t.options.host)+t.options.path,a=r.default.createJSONPRequest(s,n),u=r.default.ScriptReceivers.create(function(e,n){o.ScriptReceivers.remove(u),a.cleanup(),n&&n.host&&(t.host=n.host),i&&i(e,n)});a.send(u)}}};e.default=i},function(t,e,n){"use strict";e.__esModule=!0;var r=n(30),o=n(15),i=n(14),s=n(1),a=n(11),u=n(0),c=new o.default({file:"sockjs",urls:i.sockjs,handlesActivityChecks:!0,supportsPing:!1,isSupported:function(){return!0},isInitialized:function(){return void 0!==window.SockJS},getSocket:function(t,e){return new window.SockJS(t,null,{js_path:a.Dependencies.getPath("sockjs",{useTLS:e.useTLS}),ignore_null_origin:e.ignoreNullOrigin})},beforeOpen:function(t,e){t.send(JSON.stringify({path:e}))}}),h={isSupported:function(t){return s.default.isXDRSupported(t.useTLS)}},f=new o.default(u.extend({},r.streamingConfiguration,h)),l=new o.default(u.extend({},r.pollingConfiguration,h));r.default.xdr_streaming=f,r.default.xdr_polling=l,r.default.sockjs=c,e.default=r.default},function(t,e,n){"use strict";e.__esModule=!0;var r=n(14),o=n(15),i=n(0),s=n(1),a=new o.default({urls:r.ws,handlesActivityChecks:!1,supportsPing:!1,isInitialized:function(){return Boolean(s.default.getWebSocketAPI())},isSupported:function(){return Boolean(s.default.getWebSocketAPI())},getSocket:function(t){return s.default.createWebSocket(t)}}),u={urls:r.http,handlesActivityChecks:!1,supportsPing:!0,isInitialized:function(){return!0}};e.streamingConfiguration=i.extend({getSocket:function(t){return s.default.HTTPFactory.createStreamingSocket(t)}},u),e.pollingConfiguration=i.extend({getSocket:function(t){return s.default.HTTPFactory.createPollingSocket(t)}},u);var c={isSupported:function(){return s.default.isXHRSupported()}},h={ws:a,xhr_streaming:new o.default(i.extend({},e.streamingConfiguration,c)),xhr_polling:new o.default(i.extend({},e.pollingConfiguration,c))};e.default=h},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var i=n(2),s=n(0),a=n(4),u=n(3),c=n(1),h=function(t){function e(e,n,r,o,i){var s=t.call(this)||this;return s.initialize=c.default.transportConnectionInitializer,s.hooks=e,s.name=n,s.priority=r,s.key=o,s.options=i,s.state="new",s.timeline=i.timeline,s.activityTimeout=i.activityTimeout,s.id=s.timeline.generateUniqueID(),s}return o(e,t),e.prototype.handlesActivityChecks=function(){return Boolean(this.hooks.handlesActivityChecks)},e.prototype.supportsPing=function(){return Boolean(this.hooks.supportsPing)},e.prototype.connect=function(){var t=this;if(this.socket||"initialized"!==this.state)return!1;var e=this.hooks.urls.getInitial(this.key,this.options);try{this.socket=this.hooks.getSocket(e,this.options)}catch(e){return i.default.defer(function(){t.onError(e),t.changeState("closed")}),!1}return this.bindListeners(),u.default.debug("Connecting",{transport:this.name,url:e}),this.changeState("connecting"),!0},e.prototype.close=function(){return!!this.socket&&(this.socket.close(),!0)},e.prototype.send=function(t){var e=this;return"open"===this.state&&(i.default.defer(function(){e.socket&&e.socket.send(t)}),!0)},e.prototype.ping=function(){"open"===this.state&&this.supportsPing()&&this.socket.ping()},e.prototype.onOpen=function(){this.hooks.beforeOpen&&this.hooks.beforeOpen(this.socket,this.hooks.urls.getPath(this.key,this.options)),this.changeState("open"),this.socket.onopen=void 0},e.prototype.onError=function(t){this.emit("error",{type:"WebSocketError",error:t}),this.timeline.error(this.buildTimelineMessage({error:t.toString()}))},e.prototype.onClose=function(t){t?this.changeState("closed",{code:t.code,reason:t.reason,wasClean:t.wasClean}):this.changeState("closed"),this.unbindListeners(),this.socket=void 0},e.prototype.onMessage=function(t){this.emit("message",t)},e.prototype.onActivity=function(){this.emit("activity")},e.prototype.bindListeners=function(){var t=this;this.socket.onopen=function(){t.onOpen()},this.socket.onerror=function(e){t.onError(e)},this.socket.onclose=function(e){t.onClose(e)},this.socket.onmessage=function(e){t.onMessage(e)},this.supportsPing()&&(this.socket.onactivity=function(){t.onActivity()})},e.prototype.unbindListeners=function(){this.socket&&(this.socket.onopen=void 0,this.socket.onerror=void 0,this.socket.onclose=void 0,this.socket.onmessage=void 0,this.supportsPing()&&(this.socket.onactivity=void 0))},e.prototype.changeState=function(t,e){this.state=t,this.timeline.info(this.buildTimelineMessage({state:t,params:e})),this.emit(t,e)},e.prototype.buildTimelineMessage=function(t){return s.extend({cid:this.id},t)},e}(a.default);e.default=h},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=function(){function t(){this._callbacks={}}return t.prototype.get=function(t){return this._callbacks[i(t)]},t.prototype.add=function(t,e,n){var r=i(t);this._callbacks[r]=this._callbacks[r]||[],this._callbacks[r].push({fn:e,context:n})},t.prototype.remove=function(t,e,n){if(t||e||n){var o=t?[i(t)]:r.keys(this._callbacks);e||n?this.removeCallback(o,e,n):this.removeAllCallbacks(o)}else this._callbacks={}},t.prototype.removeCallback=function(t,e,n){r.apply(t,function(t){this._callbacks[t]=r.filter(this._callbacks[t]||[],function(t){return e&&e!==t.fn||n&&n!==t.context}),0===this._callbacks[t].length&&delete this._callbacks[t]},this)},t.prototype.removeAllCallbacks=function(t){r.apply(t,function(t){delete this._callbacks[t]},this)},t}();function i(t){return"_"+t}e.default=o},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var i=function(t){function e(){var e=t.call(this)||this,n=e;return void 0!==window.addEventListener&&(window.addEventListener("online",function(){n.emit("online")},!1),window.addEventListener("offline",function(){n.emit("offline")},!1)),e}return o(e,t),e.prototype.isOnline=function(){return void 0===window.navigator.onLine||window.navigator.onLine},e}(n(4).default);e.NetInfo=i,e.Network=new i},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(35),i=n(18),s=n(49),a=n(50),u=n(51),c=n(52),h=n(53);function f(t){return function(){return t.isSupported()}}e.default=function(t,e){var n={};function l(r,o,i,s,a){var u=e(t,r,o,i,s,a);return n[r]=u,u}var p,d={hostNonTLS:t.wsHost+":"+t.wsPort,hostTLS:t.wsHost+":"+t.wssPort,httpPath:t.wsPath},y=r.extend({},d,{useTLS:!0}),v={hostNonTLS:t.httpHost+":"+t.httpPort,hostTLS:t.httpHost+":"+t.httpsPort,httpPath:t.httpPath},g={loop:!0,timeout:15e3,timeoutLimit:6e4},b=new o.default({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),_=new o.default({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),m=l("ws","ws",3,d,b),w=l("wss","ws",3,y,b),S=l("sockjs","sockjs",1,v),k=l("xhr_streaming","xhr_streaming",1,v,_),T=l("xdr_streaming","xdr_streaming",1,v,_),O=l("xhr_polling","xhr_polling",1,v),x=l("xdr_polling","xdr_polling",1,v),C=new i.default([m],g),A=new i.default([w],g),P=new i.default([S],g),E=new i.default([new c.default(f(k),k,T)],g),M=new i.default([new c.default(f(O),O,x)],g),R=new i.default([new c.default(f(E),new s.default([E,new u.default(M,{delay:4e3})]),M)],g),L=new c.default(f(R),R,P);return p=t.useTLS?new s.default([C,new u.default(L,{delay:2e3})]):new s.default([C,new u.default(A,{delay:2e3}),new u.default(L,{delay:5e3})]),new a.default(new h.default(new c.default(f(m),p,L)),n,{ttl:18e5,timeline:t.timeline,useTLS:t.useTLS})}},function(t,e,n){"use strict";e.__esModule=!0;var r=n(7),o=function(){function t(t){this.options=t||{},this.livesLeft=this.options.lives||1/0}return t.prototype.getAssistant=function(t){return r.default.createAssistantToTheTransportManager(this,t,{minPingDelay:this.options.minPingDelay,maxPingDelay:this.options.maxPingDelay})},t.prototype.isAlive=function(){return this.livesLeft>0},t.prototype.reportDeath=function(){this.livesLeft-=1},t}();e.default=o},function(t,e,n){"use strict";e.__esModule=!0;var r=n(2),o=n(0),i=function(){function t(t,e,n){this.manager=t,this.transport=e,this.minPingDelay=n.minPingDelay,this.maxPingDelay=n.maxPingDelay,this.pingDelay=void 0}return t.prototype.createConnection=function(t,e,n,i){var s=this;i=o.extend({},i,{activityTimeout:this.pingDelay});var a=this.transport.createConnection(t,e,n,i),u=null,c=function(){a.unbind("open",c),a.bind("closed",h),u=r.default.now()},h=function(t){if(a.unbind("closed",h),1002===t.code||1003===t.code)s.manager.reportDeath();else if(!t.wasClean&&u){var e=r.default.now()-u;e<2*s.maxPingDelay&&(s.manager.reportDeath(),s.pingDelay=Math.max(e/2,s.minPingDelay))}};return a.bind("open",c),a},t.prototype.isSupported=function(t){return this.manager.isAlive()&&this.transport.isSupported(t)},t}();e.default=i},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(16),i=n(38),s=function(){function t(t,e){this.transport=t,this.callback=e,this.bindListeners()}return t.prototype.close=function(){this.unbindListeners(),this.transport.close()},t.prototype.bindListeners=function(){var t=this;this.onMessage=function(e){var n;t.unbindListeners();try{n=o.processHandshake(e)}catch(e){return t.finish("error",{error:e}),void t.transport.close()}"connected"===n.action?t.finish("connected",{connection:new i.default(n.id,t.transport),activityTimeout:n.activityTimeout}):(t.finish(n.action,{error:n.error}),t.transport.close())},this.onClosed=function(e){t.unbindListeners();var n=o.getCloseAction(e)||"backoff",r=o.getCloseError(e);t.finish(n,{error:r})},this.transport.bind("message",this.onMessage),this.transport.bind("closed",this.onClosed)},t.prototype.unbindListeners=function(){this.transport.unbind("message",this.onMessage),this.transport.unbind("closed",this.onClosed)},t.prototype.finish=function(t,e){this.callback(r.extend({transport:this.transport,action:t},e))},t}();e.default=s},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var i=n(0),s=n(4),a=n(16),u=n(3),c=function(t){function e(e,n){var r=t.call(this)||this;return r.id=e,r.transport=n,r.activityTimeout=n.activityTimeout,r.bindListeners(),r}return o(e,t),e.prototype.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()},e.prototype.send=function(t){return this.transport.send(t)},e.prototype.send_event=function(t,e,n){var r={event:t,data:e};return n&&(r.channel=n),u.default.debug("Event sent",r),this.send(a.encodeMessage(r))},e.prototype.ping=function(){this.transport.supportsPing()?this.transport.ping():this.send_event("pusher:ping",{})},e.prototype.close=function(){this.transport.close()},e.prototype.bindListeners=function(){var t=this,e={message:function(e){var n;try{n=a.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(u.default.debug("Event recd",n),n.event){case"pusher:error":t.emit("error",{type:"PusherError",data:n.data});break;case"pusher:ping":t.emit("ping");break;case"pusher:pong":t.emit("pong")}t.emit("message",n)}},activity:function(){t.emit("activity")},error:function(e){t.emit("error",{type:"WebSocketError",error:e})},closed:function(e){n(),e&&e.code&&t.handleCloseEvent(e),t.transport=null,t.emit("closed")}},n=function(){i.objectApply(e,function(e,n){t.transport.unbind(n,e)})};i.objectApply(e,function(e,n){t.transport.bind(n,e)})},e.prototype.handleCloseEvent=function(t){var e=a.getCloseAction(t),n=a.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(s.default);e.default=c},function(t,e,n){"use strict";e.__esModule=!0;var r=n(1),o=function(){function t(t,e){this.channel=t;var n=e.authTransport;if(void 0===r.default.getAuthorizers()[n])throw"'"+n+"' is not a recognized auth transport";this.type=n,this.options=e,this.authOptions=(e||{}).auth||{}}return t.prototype.composeQuery=function(t){var e="socket_id="+encodeURIComponent(t)+"&channel_name="+encodeURIComponent(this.channel.name);for(var n in this.authOptions.params)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(this.authOptions.params[n]);return e},t.prototype.authorize=function(e,n){return t.authorizers=t.authorizers||r.default.getAuthorizers(),t.authorizers[this.type].call(this,r.default,e,n)},t}();e.default=o},function(t,e,n){"use strict";e.__esModule=!0;var r=n(1),o=function(){function t(t,e){this.timeline=t,this.options=e||{}}return t.prototype.send=function(t,e){this.timeline.isEmpty()||this.timeline.send(r.default.TimelineTransport.getAgent(this,t),e)},t}();e.default=o},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var i=n(12),s=n(3),a=n(42),u=n(10),c=function(t){function e(e,n){var r=t.call(this,e,n)||this;return r.members=new a.default,r}return o(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,function(t,e){if(!t){if(void 0===e.channel_data){var o=u.default.buildLogSuffix("authenticationEndpoint");return s.default.warn("Invalid auth response for channel '"+r.name+"',expected 'channel_data' field. "+o),void n("Invalid auth response")}var i=JSON.parse(e.channel_data);r.members.setMyID(i.user_id)}n(t,e)})},e.prototype.handleEvent=function(t){var e=t.event;if(0===e.indexOf("pusher_internal:"))this.handleInternalEvent(t);else{var n=t.data,r={};t.user_id&&(r.user_id=t.user_id),this.emit(e,n,r)}},e.prototype.handleInternalEvent=function(t){var e=t.event,n=t.data;switch(e){case"pusher_internal:subscription_succeeded":this.handleSubscriptionSucceededEvent(t);break;case"pusher_internal:member_added":var r=this.members.addMember(n);this.emit("pusher:member_added",r);break;case"pusher_internal:member_removed":var o=this.members.removeMember(n);o&&this.emit("pusher:member_removed",o)}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(t.data),this.emit("pusher:subscription_succeeded",this.members))},e.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},e}(i.default);e.default=c},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=function(){function t(){this.reset()}return t.prototype.get=function(t){return Object.prototype.hasOwnProperty.call(this.members,t)?{id:t,info:this.members[t]}:null},t.prototype.each=function(t){var e=this;r.objectApply(this.members,function(n,r){t(e.get(r))})},t.prototype.setMyID=function(t){this.myID=t},t.prototype.onSubscription=function(t){this.members=t.presence.hash,this.count=t.presence.count,this.me=this.get(this.myID)},t.prototype.addMember=function(t){return null===this.get(t.user_id)&&this.count++,this.members[t.user_id]=t.user_info,this.get(t.user_id)},t.prototype.removeMember=function(t){var e=this.get(t.user_id);return e&&(delete this.members[t.user_id],this.count--),e},t.prototype.reset=function(){this.members={},this.count=0,this.myID=null,this.me=null},t}();e.default=o},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var i=n(12),s=n(5),a=n(3),u=n(44),c=n(46),h=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.key=null,e}return o(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,function(t,e){if(t)n(!0,e);else{var o=e.shared_secret;if(!o){var i="No shared_secret key in auth payload for encrypted channel: "+r.name;return n(!0,i),void a.default.warn("Error: "+i)}r.key=c.decodeBase64(o),delete e.shared_secret,n(!1,e)}})},e.prototype.trigger=function(t,e){throw new s.UnsupportedFeature("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e){var n=e.event,r=e.data;0!==n.indexOf("pusher_internal:")&&0!==n.indexOf("pusher:")?this.handleEncryptedEvent(n,r):t.prototype.handleEvent.call(this,e)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(this.key)if(e.ciphertext&&e.nonce){var r=c.decodeBase64(e.ciphertext);if(r.length>24&255,t[e+1]=n>>16&255,t[e+2]=n>>8&255,t[e+3]=255&n,t[e+4]=r>>24&255,t[e+5]=r>>16&255,t[e+6]=r>>8&255,t[e+7]=255&r}function y(t,e,n,r,o){var i,s=0;for(i=0;i>>8)-1}function v(t,e,n,r){return y(t,e,n,r,16)}function g(t,e,n,r){return y(t,e,n,r,32)}function b(t,e,n,r){!function(t,e,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,u=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,c=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,f=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,l=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,p=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,d=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,v=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,g=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,b=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,_=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,m=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=i,S=s,k=a,T=u,O=c,x=h,C=f,A=l,P=p,E=d,M=y,R=v,L=g,U=b,j=_,I=m,N=0;N<20;N+=2)w^=(o=(L^=(o=(P^=(o=(O^=(o=w+L|0)<<7|o>>>25)+w|0)<<9|o>>>23)+O|0)<<13|o>>>19)+P|0)<<18|o>>>14,x^=(o=(S^=(o=(U^=(o=(E^=(o=x+S|0)<<7|o>>>25)+x|0)<<9|o>>>23)+E|0)<<13|o>>>19)+U|0)<<18|o>>>14,M^=(o=(C^=(o=(k^=(o=(j^=(o=M+C|0)<<7|o>>>25)+M|0)<<9|o>>>23)+j|0)<<13|o>>>19)+k|0)<<18|o>>>14,I^=(o=(R^=(o=(A^=(o=(T^=(o=I+R|0)<<7|o>>>25)+I|0)<<9|o>>>23)+T|0)<<13|o>>>19)+A|0)<<18|o>>>14,w^=(o=(T^=(o=(k^=(o=(S^=(o=w+T|0)<<7|o>>>25)+w|0)<<9|o>>>23)+S|0)<<13|o>>>19)+k|0)<<18|o>>>14,x^=(o=(O^=(o=(A^=(o=(C^=(o=x+O|0)<<7|o>>>25)+x|0)<<9|o>>>23)+C|0)<<13|o>>>19)+A|0)<<18|o>>>14,M^=(o=(E^=(o=(P^=(o=(R^=(o=M+E|0)<<7|o>>>25)+M|0)<<9|o>>>23)+R|0)<<13|o>>>19)+P|0)<<18|o>>>14,I^=(o=(j^=(o=(U^=(o=(L^=(o=I+j|0)<<7|o>>>25)+I|0)<<9|o>>>23)+L|0)<<13|o>>>19)+U|0)<<18|o>>>14;w=w+i|0,S=S+s|0,k=k+a|0,T=T+u|0,O=O+c|0,x=x+h|0,C=C+f|0,A=A+l|0,P=P+p|0,E=E+d|0,M=M+y|0,R=R+v|0,L=L+g|0,U=U+b|0,j=j+_|0,I=I+m|0,t[0]=w>>>0&255,t[1]=w>>>8&255,t[2]=w>>>16&255,t[3]=w>>>24&255,t[4]=S>>>0&255,t[5]=S>>>8&255,t[6]=S>>>16&255,t[7]=S>>>24&255,t[8]=k>>>0&255,t[9]=k>>>8&255,t[10]=k>>>16&255,t[11]=k>>>24&255,t[12]=T>>>0&255,t[13]=T>>>8&255,t[14]=T>>>16&255,t[15]=T>>>24&255,t[16]=O>>>0&255,t[17]=O>>>8&255,t[18]=O>>>16&255,t[19]=O>>>24&255,t[20]=x>>>0&255,t[21]=x>>>8&255,t[22]=x>>>16&255,t[23]=x>>>24&255,t[24]=C>>>0&255,t[25]=C>>>8&255,t[26]=C>>>16&255,t[27]=C>>>24&255,t[28]=A>>>0&255,t[29]=A>>>8&255,t[30]=A>>>16&255,t[31]=A>>>24&255,t[32]=P>>>0&255,t[33]=P>>>8&255,t[34]=P>>>16&255,t[35]=P>>>24&255,t[36]=E>>>0&255,t[37]=E>>>8&255,t[38]=E>>>16&255,t[39]=E>>>24&255,t[40]=M>>>0&255,t[41]=M>>>8&255,t[42]=M>>>16&255,t[43]=M>>>24&255,t[44]=R>>>0&255,t[45]=R>>>8&255,t[46]=R>>>16&255,t[47]=R>>>24&255,t[48]=L>>>0&255,t[49]=L>>>8&255,t[50]=L>>>16&255,t[51]=L>>>24&255,t[52]=U>>>0&255,t[53]=U>>>8&255,t[54]=U>>>16&255,t[55]=U>>>24&255,t[56]=j>>>0&255,t[57]=j>>>8&255,t[58]=j>>>16&255,t[59]=j>>>24&255,t[60]=I>>>0&255,t[61]=I>>>8&255,t[62]=I>>>16&255,t[63]=I>>>24&255}(t,e,n,r)}function _(t,e,n,r){!function(t,e,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,u=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,c=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,f=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,l=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,p=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,d=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,v=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,g=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,b=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,_=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,m=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=0;w<20;w+=2)i^=(o=(g^=(o=(p^=(o=(c^=(o=i+g|0)<<7|o>>>25)+i|0)<<9|o>>>23)+c|0)<<13|o>>>19)+p|0)<<18|o>>>14,h^=(o=(s^=(o=(b^=(o=(d^=(o=h+s|0)<<7|o>>>25)+h|0)<<9|o>>>23)+d|0)<<13|o>>>19)+b|0)<<18|o>>>14,y^=(o=(f^=(o=(a^=(o=(_^=(o=y+f|0)<<7|o>>>25)+y|0)<<9|o>>>23)+_|0)<<13|o>>>19)+a|0)<<18|o>>>14,m^=(o=(v^=(o=(l^=(o=(u^=(o=m+v|0)<<7|o>>>25)+m|0)<<9|o>>>23)+u|0)<<13|o>>>19)+l|0)<<18|o>>>14,i^=(o=(u^=(o=(a^=(o=(s^=(o=i+u|0)<<7|o>>>25)+i|0)<<9|o>>>23)+s|0)<<13|o>>>19)+a|0)<<18|o>>>14,h^=(o=(c^=(o=(l^=(o=(f^=(o=h+c|0)<<7|o>>>25)+h|0)<<9|o>>>23)+f|0)<<13|o>>>19)+l|0)<<18|o>>>14,y^=(o=(d^=(o=(p^=(o=(v^=(o=y+d|0)<<7|o>>>25)+y|0)<<9|o>>>23)+v|0)<<13|o>>>19)+p|0)<<18|o>>>14,m^=(o=(_^=(o=(b^=(o=(g^=(o=m+_|0)<<7|o>>>25)+m|0)<<9|o>>>23)+g|0)<<13|o>>>19)+b|0)<<18|o>>>14;t[0]=i>>>0&255,t[1]=i>>>8&255,t[2]=i>>>16&255,t[3]=i>>>24&255,t[4]=h>>>0&255,t[5]=h>>>8&255,t[6]=h>>>16&255,t[7]=h>>>24&255,t[8]=y>>>0&255,t[9]=y>>>8&255,t[10]=y>>>16&255,t[11]=y>>>24&255,t[12]=m>>>0&255,t[13]=m>>>8&255,t[14]=m>>>16&255,t[15]=m>>>24&255,t[16]=f>>>0&255,t[17]=f>>>8&255,t[18]=f>>>16&255,t[19]=f>>>24&255,t[20]=l>>>0&255,t[21]=l>>>8&255,t[22]=l>>>16&255,t[23]=l>>>24&255,t[24]=p>>>0&255,t[25]=p>>>8&255,t[26]=p>>>16&255,t[27]=p>>>24&255,t[28]=d>>>0&255,t[29]=d>>>8&255,t[30]=d>>>16&255,t[31]=d>>>24&255}(t,e,n,r)}var m=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function w(t,e,n,r,o,i,s){var a,u,c=new Uint8Array(16),h=new Uint8Array(64);for(u=0;u<16;u++)c[u]=0;for(u=0;u<8;u++)c[u]=i[u];for(;o>=64;){for(b(h,c,s,m),u=0;u<64;u++)t[e+u]=n[r+u]^h[u];for(a=1,u=8;u<16;u++)a=a+(255&c[u])|0,c[u]=255&a,a>>>=8;o-=64,e+=64,r+=64}if(o>0)for(b(h,c,s,m),u=0;u=64;){for(b(u,a,o,m),s=0;s<64;s++)t[e+s]=u[s];for(i=1,s=8;s<16;s++)i=i+(255&a[s])|0,a[s]=255&i,i>>>=8;n-=64,e+=64}if(n>0)for(b(u,a,o,m),s=0;s>>13|n<<3),r=255&t[4]|(255&t[5])<<8,this.r[2]=7939&(n>>>10|r<<6),o=255&t[6]|(255&t[7])<<8,this.r[3]=8191&(r>>>7|o<<9),i=255&t[8]|(255&t[9])<<8,this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,s=255&t[10]|(255&t[11])<<8,this.r[6]=8191&(i>>>14|s<<2),a=255&t[12]|(255&t[13])<<8,this.r[7]=8065&(s>>>11|a<<5),u=255&t[14]|(255&t[15])<<8,this.r[8]=8191&(a>>>8|u<<8),this.r[9]=u>>>5&127,this.pad[0]=255&t[16]|(255&t[17])<<8,this.pad[1]=255&t[18]|(255&t[19])<<8,this.pad[2]=255&t[20]|(255&t[21])<<8,this.pad[3]=255&t[22]|(255&t[23])<<8,this.pad[4]=255&t[24]|(255&t[25])<<8,this.pad[5]=255&t[26]|(255&t[27])<<8,this.pad[6]=255&t[28]|(255&t[29])<<8,this.pad[7]=255&t[30]|(255&t[31])<<8};function x(t,e,n,r,o,i){var s=new O(i);return s.update(n,r,o),s.finish(t,e),0}function C(t,e,n,r,o,i){var s=new Uint8Array(16);return x(s,0,n,r,o,i),v(t,e,s,0)}function A(t,e,n,r,o){var i;if(n<32)return-1;for(T(t,0,e,0,n,r,o),x(t,16,t,32,n-32,t),i=0;i<16;i++)t[i]=0;return 0}function P(t,e,n,r,o){var i,s=new Uint8Array(32);if(n<32)return-1;if(k(s,0,32,r,o),0!==C(e,16,e,32,n-32,s))return-1;for(T(t,0,e,0,n,r,o),i=0;i<32;i++)t[i]=0;return 0}function E(t,e){var n;for(n=0;n<16;n++)t[n]=0|e[n]}function M(t){var e,n,r=1;for(e=0;e<16;e++)n=t[e]+r+65535,r=Math.floor(n/65536),t[e]=n-65536*r;t[0]+=r-1+37*(r-1)}function R(t,e,n){for(var r,o=~(n-1),i=0;i<16;i++)r=o&(t[i]^e[i]),t[i]^=r,e[i]^=r}function L(t,n){var r,o,i,s=e(),a=e();for(r=0;r<16;r++)a[r]=n[r];for(M(a),M(a),M(a),o=0;o<2;o++){for(s[0]=a[0]-65517,r=1;r<15;r++)s[r]=a[r]-65535-(s[r-1]>>16&1),s[r-1]&=65535;s[15]=a[15]-32767-(s[14]>>16&1),i=s[15]>>16&1,s[14]&=65535,R(a,s,1-i)}for(r=0;r<16;r++)t[2*r]=255&a[r],t[2*r+1]=a[r]>>8}function U(t,e){var n=new Uint8Array(32),r=new Uint8Array(32);return L(n,t),L(r,e),g(n,0,r,0)}function j(t){var e=new Uint8Array(32);return L(e,t),1&e[0]}function I(t,e){var n;for(n=0;n<16;n++)t[n]=e[2*n]+(e[2*n+1]<<8);t[15]&=32767}function N(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]+n[r]}function D(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]-n[r]}function B(t,e,n){var r,o,i=0,s=0,a=0,u=0,c=0,h=0,f=0,l=0,p=0,d=0,y=0,v=0,g=0,b=0,_=0,m=0,w=0,S=0,k=0,T=0,O=0,x=0,C=0,A=0,P=0,E=0,M=0,R=0,L=0,U=0,j=0,I=n[0],N=n[1],D=n[2],B=n[3],z=n[4],H=n[5],q=n[6],F=n[7],J=n[8],X=n[9],Y=n[10],K=n[11],G=n[12],W=n[13],Q=n[14],Z=n[15];i+=(r=e[0])*I,s+=r*N,a+=r*D,u+=r*B,c+=r*z,h+=r*H,f+=r*q,l+=r*F,p+=r*J,d+=r*X,y+=r*Y,v+=r*K,g+=r*G,b+=r*W,_+=r*Q,m+=r*Z,s+=(r=e[1])*I,a+=r*N,u+=r*D,c+=r*B,h+=r*z,f+=r*H,l+=r*q,p+=r*F,d+=r*J,y+=r*X,v+=r*Y,g+=r*K,b+=r*G,_+=r*W,m+=r*Q,w+=r*Z,a+=(r=e[2])*I,u+=r*N,c+=r*D,h+=r*B,f+=r*z,l+=r*H,p+=r*q,d+=r*F,y+=r*J,v+=r*X,g+=r*Y,b+=r*K,_+=r*G,m+=r*W,w+=r*Q,S+=r*Z,u+=(r=e[3])*I,c+=r*N,h+=r*D,f+=r*B,l+=r*z,p+=r*H,d+=r*q,y+=r*F,v+=r*J,g+=r*X,b+=r*Y,_+=r*K,m+=r*G,w+=r*W,S+=r*Q,k+=r*Z,c+=(r=e[4])*I,h+=r*N,f+=r*D,l+=r*B,p+=r*z,d+=r*H,y+=r*q,v+=r*F,g+=r*J,b+=r*X,_+=r*Y,m+=r*K,w+=r*G,S+=r*W,k+=r*Q,T+=r*Z,h+=(r=e[5])*I,f+=r*N,l+=r*D,p+=r*B,d+=r*z,y+=r*H,v+=r*q,g+=r*F,b+=r*J,_+=r*X,m+=r*Y,w+=r*K,S+=r*G,k+=r*W,T+=r*Q,O+=r*Z,f+=(r=e[6])*I,l+=r*N,p+=r*D,d+=r*B,y+=r*z,v+=r*H,g+=r*q,b+=r*F,_+=r*J,m+=r*X,w+=r*Y,S+=r*K,k+=r*G,T+=r*W,O+=r*Q,x+=r*Z,l+=(r=e[7])*I,p+=r*N,d+=r*D,y+=r*B,v+=r*z,g+=r*H,b+=r*q,_+=r*F,m+=r*J,w+=r*X,S+=r*Y,k+=r*K,T+=r*G,O+=r*W,x+=r*Q,C+=r*Z,p+=(r=e[8])*I,d+=r*N,y+=r*D,v+=r*B,g+=r*z,b+=r*H,_+=r*q,m+=r*F,w+=r*J,S+=r*X,k+=r*Y,T+=r*K,O+=r*G,x+=r*W,C+=r*Q,A+=r*Z,d+=(r=e[9])*I,y+=r*N,v+=r*D,g+=r*B,b+=r*z,_+=r*H,m+=r*q,w+=r*F,S+=r*J,k+=r*X,T+=r*Y,O+=r*K,x+=r*G,C+=r*W,A+=r*Q,P+=r*Z,y+=(r=e[10])*I,v+=r*N,g+=r*D,b+=r*B,_+=r*z,m+=r*H,w+=r*q,S+=r*F,k+=r*J,T+=r*X,O+=r*Y,x+=r*K,C+=r*G,A+=r*W,P+=r*Q,E+=r*Z,v+=(r=e[11])*I,g+=r*N,b+=r*D,_+=r*B,m+=r*z,w+=r*H,S+=r*q,k+=r*F,T+=r*J,O+=r*X,x+=r*Y,C+=r*K,A+=r*G,P+=r*W,E+=r*Q,M+=r*Z,g+=(r=e[12])*I,b+=r*N,_+=r*D,m+=r*B,w+=r*z,S+=r*H,k+=r*q,T+=r*F,O+=r*J,x+=r*X,C+=r*Y,A+=r*K,P+=r*G,E+=r*W,M+=r*Q,R+=r*Z,b+=(r=e[13])*I,_+=r*N,m+=r*D,w+=r*B,S+=r*z,k+=r*H,T+=r*q,O+=r*F,x+=r*J,C+=r*X,A+=r*Y,P+=r*K,E+=r*G,M+=r*W,R+=r*Q,L+=r*Z,_+=(r=e[14])*I,m+=r*N,w+=r*D,S+=r*B,k+=r*z,T+=r*H,O+=r*q,x+=r*F,C+=r*J,A+=r*X,P+=r*Y,E+=r*K,M+=r*G,R+=r*W,L+=r*Q,U+=r*Z,m+=(r=e[15])*I,s+=38*(S+=r*D),a+=38*(k+=r*B),u+=38*(T+=r*z),c+=38*(O+=r*H),h+=38*(x+=r*q),f+=38*(C+=r*F),l+=38*(A+=r*J),p+=38*(P+=r*X),d+=38*(E+=r*Y),y+=38*(M+=r*K),v+=38*(R+=r*G),g+=38*(L+=r*W),b+=38*(U+=r*Q),_+=38*(j+=r*Z),i=(r=(i+=38*(w+=r*N))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),_=(r=_+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),i=(r=(i+=o-1+37*(o-1))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),_=(r=_+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),i+=o-1+37*(o-1),t[0]=i,t[1]=s,t[2]=a,t[3]=u,t[4]=c,t[5]=h,t[6]=f,t[7]=l,t[8]=p,t[9]=d,t[10]=y,t[11]=v,t[12]=g,t[13]=b,t[14]=_,t[15]=m}function z(t,e){B(t,e,e)}function H(t,n){var r,o=e();for(r=0;r<16;r++)o[r]=n[r];for(r=253;r>=0;r--)z(o,o),2!==r&&4!==r&&B(o,o,n);for(r=0;r<16;r++)t[r]=o[r]}function q(t,n,r){var o,i,s=new Uint8Array(32),a=new Float64Array(80),c=e(),h=e(),f=e(),l=e(),p=e(),d=e();for(i=0;i<31;i++)s[i]=n[i];for(s[31]=127&n[31]|64,s[0]&=248,I(a,r),i=0;i<16;i++)h[i]=a[i],l[i]=c[i]=f[i]=0;for(c[0]=l[0]=1,i=254;i>=0;--i)R(c,h,o=s[i>>>3]>>>(7&i)&1),R(f,l,o),N(p,c,f),D(c,c,f),N(f,h,l),D(h,h,l),z(l,p),z(d,c),B(c,f,c),B(f,h,p),N(p,c,f),D(c,c,f),z(h,c),D(f,l,d),B(c,f,u),N(c,c,l),B(f,f,c),B(c,l,d),B(l,h,a),z(h,p),R(c,h,o),R(f,l,o);for(i=0;i<16;i++)a[i+16]=c[i],a[i+32]=f[i],a[i+48]=h[i],a[i+64]=l[i];var y=a.subarray(32),v=a.subarray(16);return H(y,y),B(v,v,y),L(t,v),0}function F(t,e){return q(t,e,i)}function J(t,e){return r(e,32),F(t,e)}function X(t,e,n){var r=new Uint8Array(32);return q(r,n,e),_(t,o,r,m)}O.prototype.blocks=function(t,e,n){for(var r,o,i,s,a,u,c,h,f,l,p,d,y,v,g,b,_,m,w,S=this.fin?0:2048,k=this.h[0],T=this.h[1],O=this.h[2],x=this.h[3],C=this.h[4],A=this.h[5],P=this.h[6],E=this.h[7],M=this.h[8],R=this.h[9],L=this.r[0],U=this.r[1],j=this.r[2],I=this.r[3],N=this.r[4],D=this.r[5],B=this.r[6],z=this.r[7],H=this.r[8],q=this.r[9];n>=16;)l=f=0,l+=(k+=8191&(r=255&t[e+0]|(255&t[e+1])<<8))*L,l+=(T+=8191&(r>>>13|(o=255&t[e+2]|(255&t[e+3])<<8)<<3))*(5*q),l+=(O+=8191&(o>>>10|(i=255&t[e+4]|(255&t[e+5])<<8)<<6))*(5*H),l+=(x+=8191&(i>>>7|(s=255&t[e+6]|(255&t[e+7])<<8)<<9))*(5*z),f=(l+=(C+=8191&(s>>>4|(a=255&t[e+8]|(255&t[e+9])<<8)<<12))*(5*B))>>>13,l&=8191,l+=(A+=a>>>1&8191)*(5*D),l+=(P+=8191&(a>>>14|(u=255&t[e+10]|(255&t[e+11])<<8)<<2))*(5*N),l+=(E+=8191&(u>>>11|(c=255&t[e+12]|(255&t[e+13])<<8)<<5))*(5*I),l+=(M+=8191&(c>>>8|(h=255&t[e+14]|(255&t[e+15])<<8)<<8))*(5*j),p=f+=(l+=(R+=h>>>5|S)*(5*U))>>>13,p+=k*U,p+=T*L,p+=O*(5*q),p+=x*(5*H),f=(p+=C*(5*z))>>>13,p&=8191,p+=A*(5*B),p+=P*(5*D),p+=E*(5*N),p+=M*(5*I),f+=(p+=R*(5*j))>>>13,p&=8191,d=f,d+=k*j,d+=T*U,d+=O*L,d+=x*(5*q),f=(d+=C*(5*H))>>>13,d&=8191,d+=A*(5*z),d+=P*(5*B),d+=E*(5*D),d+=M*(5*N),y=f+=(d+=R*(5*I))>>>13,y+=k*I,y+=T*j,y+=O*U,y+=x*L,f=(y+=C*(5*q))>>>13,y&=8191,y+=A*(5*H),y+=P*(5*z),y+=E*(5*B),y+=M*(5*D),v=f+=(y+=R*(5*N))>>>13,v+=k*N,v+=T*I,v+=O*j,v+=x*U,f=(v+=C*L)>>>13,v&=8191,v+=A*(5*q),v+=P*(5*H),v+=E*(5*z),v+=M*(5*B),g=f+=(v+=R*(5*D))>>>13,g+=k*D,g+=T*N,g+=O*I,g+=x*j,f=(g+=C*U)>>>13,g&=8191,g+=A*L,g+=P*(5*q),g+=E*(5*H),g+=M*(5*z),b=f+=(g+=R*(5*B))>>>13,b+=k*B,b+=T*D,b+=O*N,b+=x*I,f=(b+=C*j)>>>13,b&=8191,b+=A*U,b+=P*L,b+=E*(5*q),b+=M*(5*H),_=f+=(b+=R*(5*z))>>>13,_+=k*z,_+=T*B,_+=O*D,_+=x*N,f=(_+=C*I)>>>13,_&=8191,_+=A*j,_+=P*U,_+=E*L,_+=M*(5*q),m=f+=(_+=R*(5*H))>>>13,m+=k*H,m+=T*z,m+=O*B,m+=x*D,f=(m+=C*N)>>>13,m&=8191,m+=A*I,m+=P*j,m+=E*U,m+=M*L,w=f+=(m+=R*(5*q))>>>13,w+=k*q,w+=T*H,w+=O*z,w+=x*B,f=(w+=C*D)>>>13,w&=8191,w+=A*N,w+=P*I,w+=E*j,w+=M*U,k=l=8191&(f=(f=((f+=(w+=R*L)>>>13)<<2)+f|0)+(l&=8191)|0),T=p+=f>>>=13,O=d&=8191,x=y&=8191,C=v&=8191,A=g&=8191,P=b&=8191,E=_&=8191,M=m&=8191,R=w&=8191,e+=16,n-=16;this.h[0]=k,this.h[1]=T,this.h[2]=O,this.h[3]=x,this.h[4]=C,this.h[5]=A,this.h[6]=P,this.h[7]=E,this.h[8]=M,this.h[9]=R},O.prototype.finish=function(t,e){var n,r,o,i,s=new Uint16Array(10);if(this.leftover){for(i=this.leftover,this.buffer[i++]=1;i<16;i++)this.buffer[i]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,i=2;i<10;i++)this.h[i]+=n,n=this.h[i]>>>13,this.h[i]&=8191;for(this.h[0]+=5*n,n=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=n,n=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=n,s[0]=this.h[0]+5,n=s[0]>>>13,s[0]&=8191,i=1;i<10;i++)s[i]=this.h[i]+n,n=s[i]>>>13,s[i]&=8191;for(s[9]-=8192,r=(1^n)-1,i=0;i<10;i++)s[i]&=r;for(r=~r,i=0;i<10;i++)this.h[i]=this.h[i]&r|s[i];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),o=this.h[0]+this.pad[0],this.h[0]=65535&o,i=1;i<8;i++)o=(this.h[i]+this.pad[i]|0)+(o>>>16)|0,this.h[i]=65535&o;t[e+0]=this.h[0]>>>0&255,t[e+1]=this.h[0]>>>8&255,t[e+2]=this.h[1]>>>0&255,t[e+3]=this.h[1]>>>8&255,t[e+4]=this.h[2]>>>0&255,t[e+5]=this.h[2]>>>8&255,t[e+6]=this.h[3]>>>0&255,t[e+7]=this.h[3]>>>8&255,t[e+8]=this.h[4]>>>0&255,t[e+9]=this.h[4]>>>8&255,t[e+10]=this.h[5]>>>0&255,t[e+11]=this.h[5]>>>8&255,t[e+12]=this.h[6]>>>0&255,t[e+13]=this.h[6]>>>8&255,t[e+14]=this.h[7]>>>0&255,t[e+15]=this.h[7]>>>8&255},O.prototype.update=function(t,e,n){var r,o;if(this.leftover){for((o=16-this.leftover)>n&&(o=n),r=0;r=16&&(o=n-n%16,this.blocks(t,e,o),e+=o,n-=o),n){for(r=0;r=128;){for(S=0;S<16;S++)k=8*S+W,E[S]=n[k+0]<<24|n[k+1]<<16|n[k+2]<<8|n[k+3],M[S]=n[k+4]<<24|n[k+5]<<16|n[k+6]<<8|n[k+7];for(S=0;S<80;S++)if(o=R,i=L,s=U,a=j,u=I,c=N,h=D,B,l=z,p=H,d=q,y=F,v=J,g=X,b=Y,K,x=65535&(O=K),C=O>>>16,A=65535&(T=B),P=T>>>16,x+=65535&(O=(J>>>14|I<<18)^(J>>>18|I<<14)^(I>>>9|J<<23)),C+=O>>>16,A+=65535&(T=(I>>>14|J<<18)^(I>>>18|J<<14)^(J>>>9|I<<23)),P+=T>>>16,x+=65535&(O=J&X^~J&Y),C+=O>>>16,A+=65535&(T=I&N^~I&D),P+=T>>>16,T=G[2*S],x+=65535&(O=G[2*S+1]),C+=O>>>16,A+=65535&T,P+=T>>>16,T=E[S%16],C+=(O=M[S%16])>>>16,A+=65535&T,P+=T>>>16,A+=(C+=(x+=65535&O)>>>16)>>>16,x=65535&(O=w=65535&x|C<<16),C=O>>>16,A=65535&(T=m=65535&A|(P+=A>>>16)<<16),P=T>>>16,x+=65535&(O=(z>>>28|R<<4)^(R>>>2|z<<30)^(R>>>7|z<<25)),C+=O>>>16,A+=65535&(T=(R>>>28|z<<4)^(z>>>2|R<<30)^(z>>>7|R<<25)),P+=T>>>16,C+=(O=z&H^z&q^H&q)>>>16,A+=65535&(T=R&L^R&U^L&U),P+=T>>>16,f=65535&(A+=(C+=(x+=65535&O)>>>16)>>>16)|(P+=A>>>16)<<16,_=65535&x|C<<16,x=65535&(O=y),C=O>>>16,A=65535&(T=a),P=T>>>16,C+=(O=w)>>>16,A+=65535&(T=m),P+=T>>>16,L=o,U=i,j=s,I=a=65535&(A+=(C+=(x+=65535&O)>>>16)>>>16)|(P+=A>>>16)<<16,N=u,D=c,B=h,R=f,H=l,q=p,F=d,J=y=65535&x|C<<16,X=v,Y=g,K=b,z=_,S%16==15)for(k=0;k<16;k++)T=E[k],x=65535&(O=M[k]),C=O>>>16,A=65535&T,P=T>>>16,T=E[(k+9)%16],x+=65535&(O=M[(k+9)%16]),C+=O>>>16,A+=65535&T,P+=T>>>16,m=E[(k+1)%16],x+=65535&(O=((w=M[(k+1)%16])>>>1|m<<31)^(w>>>8|m<<24)^(w>>>7|m<<25)),C+=O>>>16,A+=65535&(T=(m>>>1|w<<31)^(m>>>8|w<<24)^m>>>7),P+=T>>>16,m=E[(k+14)%16],C+=(O=((w=M[(k+14)%16])>>>19|m<<13)^(m>>>29|w<<3)^(w>>>6|m<<26))>>>16,A+=65535&(T=(m>>>19|w<<13)^(w>>>29|m<<3)^m>>>6),P+=T>>>16,P+=(A+=(C+=(x+=65535&O)>>>16)>>>16)>>>16,E[k]=65535&A|P<<16,M[k]=65535&x|C<<16;x=65535&(O=z),C=O>>>16,A=65535&(T=R),P=T>>>16,T=t[0],C+=(O=e[0])>>>16,A+=65535&T,P+=T>>>16,P+=(A+=(C+=(x+=65535&O)>>>16)>>>16)>>>16,t[0]=R=65535&A|P<<16,e[0]=z=65535&x|C<<16,x=65535&(O=H),C=O>>>16,A=65535&(T=L),P=T>>>16,T=t[1],C+=(O=e[1])>>>16,A+=65535&T,P+=T>>>16,P+=(A+=(C+=(x+=65535&O)>>>16)>>>16)>>>16,t[1]=L=65535&A|P<<16,e[1]=H=65535&x|C<<16,x=65535&(O=q),C=O>>>16,A=65535&(T=U),P=T>>>16,T=t[2],C+=(O=e[2])>>>16,A+=65535&T,P+=T>>>16,P+=(A+=(C+=(x+=65535&O)>>>16)>>>16)>>>16,t[2]=U=65535&A|P<<16,e[2]=q=65535&x|C<<16,x=65535&(O=F),C=O>>>16,A=65535&(T=j),P=T>>>16,T=t[3],C+=(O=e[3])>>>16,A+=65535&T,P+=T>>>16,P+=(A+=(C+=(x+=65535&O)>>>16)>>>16)>>>16,t[3]=j=65535&A|P<<16,e[3]=F=65535&x|C<<16,x=65535&(O=J),C=O>>>16,A=65535&(T=I),P=T>>>16,T=t[4],C+=(O=e[4])>>>16,A+=65535&T,P+=T>>>16,P+=(A+=(C+=(x+=65535&O)>>>16)>>>16)>>>16,t[4]=I=65535&A|P<<16,e[4]=J=65535&x|C<<16,x=65535&(O=X),C=O>>>16,A=65535&(T=N),P=T>>>16,T=t[5],C+=(O=e[5])>>>16,A+=65535&T,P+=T>>>16,P+=(A+=(C+=(x+=65535&O)>>>16)>>>16)>>>16,t[5]=N=65535&A|P<<16,e[5]=X=65535&x|C<<16,x=65535&(O=Y),C=O>>>16,A=65535&(T=D),P=T>>>16,T=t[6],C+=(O=e[6])>>>16,A+=65535&T,P+=T>>>16,P+=(A+=(C+=(x+=65535&O)>>>16)>>>16)>>>16,t[6]=D=65535&A|P<<16,e[6]=Y=65535&x|C<<16,x=65535&(O=K),C=O>>>16,A=65535&(T=B),P=T>>>16,T=t[7],C+=(O=e[7])>>>16,A+=65535&T,P+=T>>>16,P+=(A+=(C+=(x+=65535&O)>>>16)>>>16)>>>16,t[7]=B=65535&A|P<<16,e[7]=K=65535&x|C<<16,W+=128,r-=128}return r}function Q(t,e,n){var r,o=new Int32Array(8),i=new Int32Array(8),s=new Uint8Array(256),a=n;for(o[0]=1779033703,o[1]=3144134277,o[2]=1013904242,o[3]=2773480762,o[4]=1359893119,o[5]=2600822924,o[6]=528734635,o[7]=1541459225,i[0]=4089235720,i[1]=2227873595,i[2]=4271175723,i[3]=1595750129,i[4]=2917565137,i[5]=725511199,i[6]=4215389547,i[7]=327033209,W(o,i,e,n),n%=128,r=0;r=0;--o)V(t,e,r=n[o/8|0]>>(7&o)&1),Z(e,t),Z(t,t),V(t,e,r)}function et(t,n){var r=[e(),e(),e(),e()];E(r[0],f),E(r[1],l),E(r[2],a),B(r[3],f,l),tt(t,r,n)}function nt(t,n,o){var i,s=new Uint8Array(64),a=[e(),e(),e(),e()];for(o||r(n,32),Q(s,n,32),s[0]&=248,s[31]&=127,s[31]|=64,et(a,s),$(t,a),i=0;i<32;i++)n[i+32]=t[i];return 0}var rt=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function ot(t,e){var n,r,o,i;for(r=63;r>=32;--r){for(n=0,o=r-32,i=r-12;o>8,e[o]-=256*n;e[o]+=n,e[r]=0}for(n=0,o=0;o<32;o++)e[o]+=n-(e[31]>>4)*rt[o],n=e[o]>>8,e[o]&=255;for(o=0;o<32;o++)e[o]-=n*rt[o];for(r=0;r<32;r++)e[r+1]+=e[r]>>8,t[r]=255&e[r]}function it(t){var e,n=new Float64Array(64);for(e=0;e<64;e++)n[e]=t[e];for(e=0;e<64;e++)t[e]=0;ot(t,n)}function st(t,n,r,o){var i,s,a=new Uint8Array(64),u=new Uint8Array(64),c=new Uint8Array(64),h=new Float64Array(64),f=[e(),e(),e(),e()];Q(a,o,32),a[0]&=248,a[31]&=127,a[31]|=64;var l=r+64;for(i=0;i=0;r--)z(o,o),1!==r&&B(o,o,n);for(r=0;r<16;r++)t[r]=o[r]}(r,r),B(r,r,i),B(r,r,u),B(r,r,u),B(t[0],r,u),z(o,t[0]),B(o,o,u),U(o,i)&&B(t[0],t[0],p),z(o,t[0]),B(o,o,u),U(o,i)?-1:(j(t[0])===n[31]>>7&&D(t[0],s,t[0]),B(t[3],t[0],t[1]),0)}function ut(t,n,r,o){var i,s=new Uint8Array(32),a=new Uint8Array(64),u=[e(),e(),e(),e()],c=[e(),e(),e(),e()];if(-1,r<64)return-1;if(at(c,o))return-1;for(i=0;i=0},t.sign.keyPair=function(){var t=new Uint8Array(32),e=new Uint8Array(64);return nt(t,e),{publicKey:t,secretKey:e}},t.sign.keyPair.fromSecretKey=function(t){if(yt(t),64!==t.length)throw new Error("bad secret key size");for(var e=new Uint8Array(32),n=0;n0&&this.emit("connecting_in",Math.round(t/1e3)),this.retryTimer=new s.OneOffTimer(t||0,function(){e.disconnectInternally(),e.connect()})},e.prototype.clearRetryTimer=function(){this.retryTimer&&(this.retryTimer.ensureAborted(),this.retryTimer=null)},e.prototype.setUnavailableTimer=function(){var t=this;this.unavailableTimer=new s.OneOffTimer(this.options.unavailableTimeout,function(){t.updateState("unavailable")})},e.prototype.clearUnavailableTimer=function(){this.unavailableTimer&&this.unavailableTimer.ensureAborted()},e.prototype.sendActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection.ping(),this.activityTimer=new s.OneOffTimer(this.options.pongTimeout,function(){t.timeline.error({pong_timed_out:t.options.pongTimeout}),t.retryIn(0)})},e.prototype.resetActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection&&!this.connection.handlesActivityChecks()&&(this.activityTimer=new s.OneOffTimer(this.activityTimeout,function(){t.sendActivityCheck()}))},e.prototype.stopActivityCheck=function(){this.activityTimer&&this.activityTimer.ensureAborted()},e.prototype.buildConnectionCallbacks=function(t){var e=this;return u.extend({},t,{message:function(t){e.resetActivityCheck(),e.emit("message",t)},ping:function(){e.send_event("pusher:pong",{})},activity:function(){e.resetActivityCheck()},error:function(t){e.emit("error",{type:"WebSocketError",error:t})},closed:function(){e.abandonConnection(),e.shouldRetry()&&e.retryIn(1e3)}})},e.prototype.buildHandshakeCallbacks=function(t){var e=this;return u.extend({},t,{connected:function(t){e.activityTimeout=Math.min(e.options.activityTimeout,t.activityTimeout,t.connection.activityTimeout||1/0),e.clearUnavailableTimer(),e.setConnection(t.connection),e.socket_id=e.connection.id,e.updateState("connected",{socket_id:e.socket_id})}})},e.prototype.buildErrorCallbacks=function(){var t=this,e=function(e){return function(n){n.error&&t.emit("error",{type:"WebSocketError",error:n.error}),e(n)}};return{tls_only:e(function(){t.usingTLS=!0,t.updateStrategy(),t.retryIn(0)}),refused:e(function(){t.disconnect()}),backoff:e(function(){t.retryIn(1e3)}),retry:e(function(){t.retryIn(0)})}},e.prototype.setConnection=function(t){for(var e in this.connection=t,this.connectionCallbacks)this.connection.bind(e,this.connectionCallbacks[e]);this.resetActivityCheck()},e.prototype.abandonConnection=function(){if(this.connection){for(var t in this.stopActivityCheck(),this.connectionCallbacks)this.connection.unbind(t,this.connectionCallbacks[t]);var e=this.connection;return this.connection=null,e}},e.prototype.updateState=function(t,e){var n=this.state;if(this.state=t,n!==t){var r=t;"connected"===r&&(r+=" with new socket ID "+e.socket_id),a.default.debug("State changed",n+" -> "+r),this.timeline.info({state:t,params:e}),this.emit("state_change",{previous:n,current:t}),this.emit(t,e)}},e.prototype.shouldRetry=function(){return"connecting"===this.state||"connected"===this.state},e}(i.default);e.default=h},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(7),i=(n(5),function(){function t(){this.channels={}}return t.prototype.add=function(t,e){return this.channels[t]||(this.channels[t]=function(t,e){return 0===t.indexOf("private-encrypted-")?o.default.createEncryptedChannel(t,e):0===t.indexOf("private-")?o.default.createPrivateChannel(t,e):0===t.indexOf("presence-")?o.default.createPresenceChannel(t,e):o.default.createChannel(t,e)}(t,e)),this.channels[t]},t.prototype.all=function(){return r.values(this.channels)},t.prototype.find=function(t){return this.channels[t]},t.prototype.remove=function(t){var e=this.channels[t];return delete this.channels[t],e},t.prototype.disconnect=function(){r.objectApply(this.channels,function(t){t.disconnect()})},t}());e.default=i},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(2),i=function(){function t(t){this.strategies=t}return t.prototype.isSupported=function(){return r.any(this.strategies,o.default.method("isSupported"))},t.prototype.connect=function(t,e){return function(t,e,n){var o=r.map(t,function(t,r,o,i){return t.connect(e,n(r,i))});return{abort:function(){r.apply(o,s)},forceMinPriority:function(t){r.apply(o,function(e){e.forceMinPriority(t)})}}}(this.strategies,t,function(t,n){return function(o,i){n[t].error=o,o?function(t){return r.all(t,function(t){return Boolean(t.error)})}(n)&&e(!0):(r.apply(n,function(t){t.forceMinPriority(i.transport.priority)}),e(null,i))}})},t}();function s(t){t.error||t.aborted||(t.abort(),t.aborted=!0)}e.default=i},function(t,e,n){"use strict";e.__esModule=!0;var r=n(2),o=n(1),i=n(18),s=n(0),a=function(){function t(t,e,n){this.strategy=t,this.transports=e,this.ttl=n.ttl||18e5,this.usingTLS=n.useTLS,this.timeline=n.timeline}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.usingTLS,a=function(t){var e=o.default.getLocalStorage();if(e)try{var n=e[u(t)];if(n)return JSON.parse(n)}catch(e){c(t)}return null}(n),h=[this.strategy];if(a&&a.timestamp+this.ttl>=r.default.now()){var f=this.transports[a.transport];f&&(this.timeline.info({cached:!0,transport:a.transport,latency:a.latency}),h.push(new i.default([f],{timeout:2*a.latency+1e3,failFast:!0})))}var l=r.default.now(),p=h.pop().connect(t,function i(a,f){a?(c(n),h.length>0?(l=r.default.now(),p=h.pop().connect(t,i)):e(a)):(!function(t,e,n){var i=o.default.getLocalStorage();if(i)try{i[u(t)]=s.safeJSONStringify({timestamp:r.default.now(),transport:e,latency:n})}catch(t){}}(n,f.transport.name,r.default.now()-l),e(null,f))});return{abort:function(){p.abort()},forceMinPriority:function(e){t=e,p&&p.forceMinPriority(e)}}},t}();function u(t){return"pusherTransport"+(t?"TLS":"NonTLS")}function c(t){var e=o.default.getLocalStorage();if(e)try{delete e[u(t)]}catch(t){}}e.default=a},function(t,e,n){"use strict";e.__esModule=!0;var r=n(6),o=function(){function t(t,e){var n=e.delay;this.strategy=t,this.options={delay:n}}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n,o=this.strategy,i=new r.OneOffTimer(this.options.delay,function(){n=o.connect(t,e)});return{abort:function(){i.ensureAborted(),n&&n.abort()},forceMinPriority:function(e){t=e,n&&n.forceMinPriority(e)}}},t}();e.default=o},function(t,e,n){"use strict";e.__esModule=!0;var r=function(){function t(t,e,n){this.test=t,this.trueBranch=e,this.falseBranch=n}return t.prototype.isSupported=function(){return(this.test()?this.trueBranch:this.falseBranch).isSupported()},t.prototype.connect=function(t,e){return(this.test()?this.trueBranch:this.falseBranch).connect(t,e)},t}();e.default=r},function(t,e,n){"use strict";e.__esModule=!0;var r=function(){function t(t){this.strategy=t}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.strategy.connect(t,function(t,r){r&&n.abort(),e(t,r)});return n},t}();e.default=r},function(t,e,n){"use strict";e.__esModule=!0;var r=n(11);e.default=function(){var t=this;t.timeline.info(t.buildTimelineMessage({transport:t.name+(t.options.useTLS?"s":"")})),t.hooks.isInitialized()?t.changeState("initialized"):t.hooks.file?(t.changeState("initializing"),r.Dependencies.load(t.hooks.file,{useTLS:t.options.useTLS},function(e,n){t.hooks.isInitialized()?(t.changeState("initialized"),n(!0)):(e&&t.onError(e),t.onClose(),n(!1))})):t.onClose()}},function(t,e,n){"use strict";e.__esModule=!0;var r=n(56),o=n(57);o.default.createXDR=function(t,e){return this.createRequest(r.default,t,e)},e.default=o.default},function(t,e,n){"use strict";e.__esModule=!0;var r=n(5),o={getRequest:function(t){var e=new window.XDomainRequest;return e.ontimeout=function(){t.emit("error",new r.RequestTimedOut),t.close()},e.onerror=function(e){t.emit("error",e),t.close()},e.onprogress=function(){e.responseText&&e.responseText.length>0&&t.onChunk(200,e.responseText)},e.onload=function(){e.responseText&&e.responseText.length>0&&t.onChunk(200,e.responseText),t.emit("finished",200),t.close()},e},abortRequest:function(t){t.ontimeout=t.onerror=t.onprogress=t.onload=null,t.abort()}};e.default=o},function(t,e,n){"use strict";e.__esModule=!0;var r=n(58),o=n(59),i=n(61),s=n(62),a=n(63),u={createStreamingSocket:function(t){return this.createSocket(i.default,t)},createPollingSocket:function(t){return this.createSocket(s.default,t)},createSocket:function(t,e){return new o.default(t,e)},createXHR:function(t,e){return this.createRequest(a.default,t,e)},createRequest:function(t,e,n){return new r.default(t,e,n)}};e.default=u},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var i=n(1),s=n(4),a=function(t){function e(e,n,r){var o=t.call(this)||this;return o.hooks=e,o.method=n,o.url=r,o}return o(e,t),e.prototype.start=function(t){var e=this;this.position=0,this.xhr=this.hooks.getRequest(this),this.unloader=function(){e.close()},i.default.addUnloadListener(this.unloader),this.xhr.open(this.method,this.url,!0),this.xhr.setRequestHeader&&this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.send(t)},e.prototype.close=function(){this.unloader&&(i.default.removeUnloadListener(this.unloader),this.unloader=null),this.xhr&&(this.hooks.abortRequest(this.xhr),this.xhr=null)},e.prototype.onChunk=function(t,e){for(;;){var n=this.advanceBuffer(e);if(!n)break;this.emit("chunk",{status:t,data:n})}this.isBufferTooLong(e)&&this.emit("buffer_too_long")},e.prototype.advanceBuffer=function(t){var e=t.slice(this.position),n=e.indexOf("\n");return-1!==n?(this.position+=n+1,e.slice(0,n)):null},e.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>262144},e}(s.default);e.default=a},function(t,e,n){"use strict";e.__esModule=!0;var r=n(60),o=n(2),i=n(1),s=1,a=function(){function t(t,e){this.hooks=t,this.session=c(1e3)+"/"+function(t){for(var e=[],n=0;n0&&t.onChunk(e.status,e.responseText);break;case 4:e.responseText&&e.responseText.length>0&&t.onChunk(e.status,e.responseText),t.emit("finished",e.status),t.close()}},e},abortRequest:function(t){t.onreadystatechange=null,t.abort()}};e.default=o},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(2),i=n(19),s=function(){function t(t,e,n){this.key=t,this.session=e,this.events=[],this.options=n||{},this.sent=0,this.uniqueID=0}return t.prototype.log=function(t,e){t<=this.options.level&&(this.events.push(r.extend({},e,{timestamp:o.default.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(i.default.ERROR,t)},t.prototype.info=function(t){this.log(i.default.INFO,t)},t.prototype.debug=function(t){this.log(i.default.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,o=r.extend({session:this.session,bundle:this.sent+1,key:this.key,lib:"js",version:this.options.version,cluster:this.options.cluster,features:this.options.features,timeline:this.events},this.options.params);return this.events=[],t(o,function(t,r){t||n.sent++,e&&e(t,r)}),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}();e.default=s},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(2),i=n(5),s=n(66),a=n(1).default.Transports;e.defineTransport=function(t,e,n,o,c,h){var f=a[n];if(!f)throw new i.UnsupportedTransport(n);return!(t.enabledTransports&&-1===r.arrayIndexOf(t.enabledTransports,e)||t.disabledTransports&&-1!==r.arrayIndexOf(t.disabledTransports,e))?new s.default(e,o,h?h.getAssistant(f):f,r.extend({key:t.key,useTLS:t.useTLS,timeline:t.timeline,ignoreNullOrigin:t.ignoreNullOrigin},c)):u};var u={isSupported:function(){return!1},connect:function(t,e){var n=o.default.defer(function(){e(new i.UnsupportedStrategy)});return{abort:function(){n.ensureAborted()},forceMinPriority:function(){}}}}},function(t,e,n){"use strict";e.__esModule=!0;var r=n(7),o=n(2),i=n(5),s=n(0),a=function(){function t(t,e,n,r){this.name=t,this.priority=e,this.transport=n,this.options=r||{}}return t.prototype.isSupported=function(){return this.transport.isSupported({useTLS:this.options.useTLS})},t.prototype.connect=function(t,e){var n=this;if(!this.isSupported())return u(new i.UnsupportedStrategy,e);if(this.priority>24&255,t[e+1]=n>>16&255,t[e+2]=n>>8&255,t[e+3]=255&n,t[e+4]=r>>24&255,t[e+5]=r>>16&255,t[e+6]=r>>8&255,t[e+7]=255&r}function y(t,e,n,r,o){var i,s=0;for(i=0;i>>8)-1}function v(t,e,n,r){return y(t,e,n,r,16)}function g(t,e,n,r){return y(t,e,n,r,32)}function b(t,e,n,r){!function(t,e,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,c=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,a=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,u=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,p=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,f=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,l=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,d=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,v=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,g=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,b=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,m=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,w=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,_=i,S=s,k=c,T=a,O=u,C=h,A=p,E=f,P=l,x=d,L=y,R=v,U=g,M=b,j=m,I=w,N=0;N<20;N+=2)_^=(o=(U^=(o=(P^=(o=(O^=(o=_+U|0)<<7|o>>>25)+_|0)<<9|o>>>23)+O|0)<<13|o>>>19)+P|0)<<18|o>>>14,C^=(o=(S^=(o=(M^=(o=(x^=(o=C+S|0)<<7|o>>>25)+C|0)<<9|o>>>23)+x|0)<<13|o>>>19)+M|0)<<18|o>>>14,L^=(o=(A^=(o=(k^=(o=(j^=(o=L+A|0)<<7|o>>>25)+L|0)<<9|o>>>23)+j|0)<<13|o>>>19)+k|0)<<18|o>>>14,I^=(o=(R^=(o=(E^=(o=(T^=(o=I+R|0)<<7|o>>>25)+I|0)<<9|o>>>23)+T|0)<<13|o>>>19)+E|0)<<18|o>>>14,_^=(o=(T^=(o=(k^=(o=(S^=(o=_+T|0)<<7|o>>>25)+_|0)<<9|o>>>23)+S|0)<<13|o>>>19)+k|0)<<18|o>>>14,C^=(o=(O^=(o=(E^=(o=(A^=(o=C+O|0)<<7|o>>>25)+C|0)<<9|o>>>23)+A|0)<<13|o>>>19)+E|0)<<18|o>>>14,L^=(o=(x^=(o=(P^=(o=(R^=(o=L+x|0)<<7|o>>>25)+L|0)<<9|o>>>23)+R|0)<<13|o>>>19)+P|0)<<18|o>>>14,I^=(o=(j^=(o=(M^=(o=(U^=(o=I+j|0)<<7|o>>>25)+I|0)<<9|o>>>23)+U|0)<<13|o>>>19)+M|0)<<18|o>>>14;_=_+i|0,S=S+s|0,k=k+c|0,T=T+a|0,O=O+u|0,C=C+h|0,A=A+p|0,E=E+f|0,P=P+l|0,x=x+d|0,L=L+y|0,R=R+v|0,U=U+g|0,M=M+b|0,j=j+m|0,I=I+w|0,t[0]=_>>>0&255,t[1]=_>>>8&255,t[2]=_>>>16&255,t[3]=_>>>24&255,t[4]=S>>>0&255,t[5]=S>>>8&255,t[6]=S>>>16&255,t[7]=S>>>24&255,t[8]=k>>>0&255,t[9]=k>>>8&255,t[10]=k>>>16&255,t[11]=k>>>24&255,t[12]=T>>>0&255,t[13]=T>>>8&255,t[14]=T>>>16&255,t[15]=T>>>24&255,t[16]=O>>>0&255,t[17]=O>>>8&255,t[18]=O>>>16&255,t[19]=O>>>24&255,t[20]=C>>>0&255,t[21]=C>>>8&255,t[22]=C>>>16&255,t[23]=C>>>24&255,t[24]=A>>>0&255,t[25]=A>>>8&255,t[26]=A>>>16&255,t[27]=A>>>24&255,t[28]=E>>>0&255,t[29]=E>>>8&255,t[30]=E>>>16&255,t[31]=E>>>24&255,t[32]=P>>>0&255,t[33]=P>>>8&255,t[34]=P>>>16&255,t[35]=P>>>24&255,t[36]=x>>>0&255,t[37]=x>>>8&255,t[38]=x>>>16&255,t[39]=x>>>24&255,t[40]=L>>>0&255,t[41]=L>>>8&255,t[42]=L>>>16&255,t[43]=L>>>24&255,t[44]=R>>>0&255,t[45]=R>>>8&255,t[46]=R>>>16&255,t[47]=R>>>24&255,t[48]=U>>>0&255,t[49]=U>>>8&255,t[50]=U>>>16&255,t[51]=U>>>24&255,t[52]=M>>>0&255,t[53]=M>>>8&255,t[54]=M>>>16&255,t[55]=M>>>24&255,t[56]=j>>>0&255,t[57]=j>>>8&255,t[58]=j>>>16&255,t[59]=j>>>24&255,t[60]=I>>>0&255,t[61]=I>>>8&255,t[62]=I>>>16&255,t[63]=I>>>24&255}(t,e,n,r)}function m(t,e,n,r){!function(t,e,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,c=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,a=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,u=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,p=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,f=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,l=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,d=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,v=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,g=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,b=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,m=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,w=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,_=0;_<20;_+=2)i^=(o=(g^=(o=(l^=(o=(u^=(o=i+g|0)<<7|o>>>25)+i|0)<<9|o>>>23)+u|0)<<13|o>>>19)+l|0)<<18|o>>>14,h^=(o=(s^=(o=(b^=(o=(d^=(o=h+s|0)<<7|o>>>25)+h|0)<<9|o>>>23)+d|0)<<13|o>>>19)+b|0)<<18|o>>>14,y^=(o=(p^=(o=(c^=(o=(m^=(o=y+p|0)<<7|o>>>25)+y|0)<<9|o>>>23)+m|0)<<13|o>>>19)+c|0)<<18|o>>>14,w^=(o=(v^=(o=(f^=(o=(a^=(o=w+v|0)<<7|o>>>25)+w|0)<<9|o>>>23)+a|0)<<13|o>>>19)+f|0)<<18|o>>>14,i^=(o=(a^=(o=(c^=(o=(s^=(o=i+a|0)<<7|o>>>25)+i|0)<<9|o>>>23)+s|0)<<13|o>>>19)+c|0)<<18|o>>>14,h^=(o=(u^=(o=(f^=(o=(p^=(o=h+u|0)<<7|o>>>25)+h|0)<<9|o>>>23)+p|0)<<13|o>>>19)+f|0)<<18|o>>>14,y^=(o=(d^=(o=(l^=(o=(v^=(o=y+d|0)<<7|o>>>25)+y|0)<<9|o>>>23)+v|0)<<13|o>>>19)+l|0)<<18|o>>>14,w^=(o=(m^=(o=(b^=(o=(g^=(o=w+m|0)<<7|o>>>25)+w|0)<<9|o>>>23)+g|0)<<13|o>>>19)+b|0)<<18|o>>>14;t[0]=i>>>0&255,t[1]=i>>>8&255,t[2]=i>>>16&255,t[3]=i>>>24&255,t[4]=h>>>0&255,t[5]=h>>>8&255,t[6]=h>>>16&255,t[7]=h>>>24&255,t[8]=y>>>0&255,t[9]=y>>>8&255,t[10]=y>>>16&255,t[11]=y>>>24&255,t[12]=w>>>0&255,t[13]=w>>>8&255,t[14]=w>>>16&255,t[15]=w>>>24&255,t[16]=p>>>0&255,t[17]=p>>>8&255,t[18]=p>>>16&255,t[19]=p>>>24&255,t[20]=f>>>0&255,t[21]=f>>>8&255,t[22]=f>>>16&255,t[23]=f>>>24&255,t[24]=l>>>0&255,t[25]=l>>>8&255,t[26]=l>>>16&255,t[27]=l>>>24&255,t[28]=d>>>0&255,t[29]=d>>>8&255,t[30]=d>>>16&255,t[31]=d>>>24&255}(t,e,n,r)}var w=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function _(t,e,n,r,o,i,s){var c,a,u=new Uint8Array(16),h=new Uint8Array(64);for(a=0;a<16;a++)u[a]=0;for(a=0;a<8;a++)u[a]=i[a];for(;o>=64;){for(b(h,u,s,w),a=0;a<64;a++)t[e+a]=n[r+a]^h[a];for(c=1,a=8;a<16;a++)c=c+(255&u[a])|0,u[a]=255&c,c>>>=8;o-=64,e+=64,r+=64}if(o>0)for(b(h,u,s,w),a=0;a=64;){for(b(a,c,o,w),s=0;s<64;s++)t[e+s]=a[s];for(i=1,s=8;s<16;s++)i=i+(255&c[s])|0,c[s]=255&i,i>>>=8;n-=64,e+=64}if(n>0)for(b(a,c,o,w),s=0;s>>13|n<<3),r=255&t[4]|(255&t[5])<<8,this.r[2]=7939&(n>>>10|r<<6),o=255&t[6]|(255&t[7])<<8,this.r[3]=8191&(r>>>7|o<<9),i=255&t[8]|(255&t[9])<<8,this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,s=255&t[10]|(255&t[11])<<8,this.r[6]=8191&(i>>>14|s<<2),c=255&t[12]|(255&t[13])<<8,this.r[7]=8065&(s>>>11|c<<5),a=255&t[14]|(255&t[15])<<8,this.r[8]=8191&(c>>>8|a<<8),this.r[9]=a>>>5&127,this.pad[0]=255&t[16]|(255&t[17])<<8,this.pad[1]=255&t[18]|(255&t[19])<<8,this.pad[2]=255&t[20]|(255&t[21])<<8,this.pad[3]=255&t[22]|(255&t[23])<<8,this.pad[4]=255&t[24]|(255&t[25])<<8,this.pad[5]=255&t[26]|(255&t[27])<<8,this.pad[6]=255&t[28]|(255&t[29])<<8,this.pad[7]=255&t[30]|(255&t[31])<<8};function C(t,e,n,r,o,i){var s=new O(i);return s.update(n,r,o),s.finish(t,e),0}function A(t,e,n,r,o,i){var s=new Uint8Array(16);return C(s,0,n,r,o,i),v(t,e,s,0)}function E(t,e,n,r,o){var i;if(n<32)return-1;for(T(t,0,e,0,n,r,o),C(t,16,t,32,n-32,t),i=0;i<16;i++)t[i]=0;return 0}function P(t,e,n,r,o){var i,s=new Uint8Array(32);if(n<32)return-1;if(k(s,0,32,r,o),0!==A(e,16,e,32,n-32,s))return-1;for(T(t,0,e,0,n,r,o),i=0;i<32;i++)t[i]=0;return 0}function x(t,e){var n;for(n=0;n<16;n++)t[n]=0|e[n]}function L(t){var e,n,r=1;for(e=0;e<16;e++)n=t[e]+r+65535,r=Math.floor(n/65536),t[e]=n-65536*r;t[0]+=r-1+37*(r-1)}function R(t,e,n){for(var r,o=~(n-1),i=0;i<16;i++)r=o&(t[i]^e[i]),t[i]^=r,e[i]^=r}function U(t,n){var r,o,i,s=e(),c=e();for(r=0;r<16;r++)c[r]=n[r];for(L(c),L(c),L(c),o=0;o<2;o++){for(s[0]=c[0]-65517,r=1;r<15;r++)s[r]=c[r]-65535-(s[r-1]>>16&1),s[r-1]&=65535;s[15]=c[15]-32767-(s[14]>>16&1),i=s[15]>>16&1,s[14]&=65535,R(c,s,1-i)}for(r=0;r<16;r++)t[2*r]=255&c[r],t[2*r+1]=c[r]>>8}function M(t,e){var n=new Uint8Array(32),r=new Uint8Array(32);return U(n,t),U(r,e),g(n,0,r,0)}function j(t){var e=new Uint8Array(32);return U(e,t),1&e[0]}function I(t,e){var n;for(n=0;n<16;n++)t[n]=e[2*n]+(e[2*n+1]<<8);t[15]&=32767}function N(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]+n[r]}function B(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]-n[r]}function D(t,e,n){var r,o,i=0,s=0,c=0,a=0,u=0,h=0,p=0,f=0,l=0,d=0,y=0,v=0,g=0,b=0,m=0,w=0,_=0,S=0,k=0,T=0,O=0,C=0,A=0,E=0,P=0,x=0,L=0,R=0,U=0,M=0,j=0,I=n[0],N=n[1],B=n[2],D=n[3],z=n[4],H=n[5],q=n[6],F=n[7],X=n[8],J=n[9],Y=n[10],K=n[11],W=n[12],G=n[13],Z=n[14],V=n[15];i+=(r=e[0])*I,s+=r*N,c+=r*B,a+=r*D,u+=r*z,h+=r*H,p+=r*q,f+=r*F,l+=r*X,d+=r*J,y+=r*Y,v+=r*K,g+=r*W,b+=r*G,m+=r*Z,w+=r*V,s+=(r=e[1])*I,c+=r*N,a+=r*B,u+=r*D,h+=r*z,p+=r*H,f+=r*q,l+=r*F,d+=r*X,y+=r*J,v+=r*Y,g+=r*K,b+=r*W,m+=r*G,w+=r*Z,_+=r*V,c+=(r=e[2])*I,a+=r*N,u+=r*B,h+=r*D,p+=r*z,f+=r*H,l+=r*q,d+=r*F,y+=r*X,v+=r*J,g+=r*Y,b+=r*K,m+=r*W,w+=r*G,_+=r*Z,S+=r*V,a+=(r=e[3])*I,u+=r*N,h+=r*B,p+=r*D,f+=r*z,l+=r*H,d+=r*q,y+=r*F,v+=r*X,g+=r*J,b+=r*Y,m+=r*K,w+=r*W,_+=r*G,S+=r*Z,k+=r*V,u+=(r=e[4])*I,h+=r*N,p+=r*B,f+=r*D,l+=r*z,d+=r*H,y+=r*q,v+=r*F,g+=r*X,b+=r*J,m+=r*Y,w+=r*K,_+=r*W,S+=r*G,k+=r*Z,T+=r*V,h+=(r=e[5])*I,p+=r*N,f+=r*B,l+=r*D,d+=r*z,y+=r*H,v+=r*q,g+=r*F,b+=r*X,m+=r*J,w+=r*Y,_+=r*K,S+=r*W,k+=r*G,T+=r*Z,O+=r*V,p+=(r=e[6])*I,f+=r*N,l+=r*B,d+=r*D,y+=r*z,v+=r*H,g+=r*q,b+=r*F,m+=r*X,w+=r*J,_+=r*Y,S+=r*K,k+=r*W,T+=r*G,O+=r*Z,C+=r*V,f+=(r=e[7])*I,l+=r*N,d+=r*B,y+=r*D,v+=r*z,g+=r*H,b+=r*q,m+=r*F,w+=r*X,_+=r*J,S+=r*Y,k+=r*K,T+=r*W,O+=r*G,C+=r*Z,A+=r*V,l+=(r=e[8])*I,d+=r*N,y+=r*B,v+=r*D,g+=r*z,b+=r*H,m+=r*q,w+=r*F,_+=r*X,S+=r*J,k+=r*Y,T+=r*K,O+=r*W,C+=r*G,A+=r*Z,E+=r*V,d+=(r=e[9])*I,y+=r*N,v+=r*B,g+=r*D,b+=r*z,m+=r*H,w+=r*q,_+=r*F,S+=r*X,k+=r*J,T+=r*Y,O+=r*K,C+=r*W,A+=r*G,E+=r*Z,P+=r*V,y+=(r=e[10])*I,v+=r*N,g+=r*B,b+=r*D,m+=r*z,w+=r*H,_+=r*q,S+=r*F,k+=r*X,T+=r*J,O+=r*Y,C+=r*K,A+=r*W,E+=r*G,P+=r*Z,x+=r*V,v+=(r=e[11])*I,g+=r*N,b+=r*B,m+=r*D,w+=r*z,_+=r*H,S+=r*q,k+=r*F,T+=r*X,O+=r*J,C+=r*Y,A+=r*K,E+=r*W,P+=r*G,x+=r*Z,L+=r*V,g+=(r=e[12])*I,b+=r*N,m+=r*B,w+=r*D,_+=r*z,S+=r*H,k+=r*q,T+=r*F,O+=r*X,C+=r*J,A+=r*Y,E+=r*K,P+=r*W,x+=r*G,L+=r*Z,R+=r*V,b+=(r=e[13])*I,m+=r*N,w+=r*B,_+=r*D,S+=r*z,k+=r*H,T+=r*q,O+=r*F,C+=r*X,A+=r*J,E+=r*Y,P+=r*K,x+=r*W,L+=r*G,R+=r*Z,U+=r*V,m+=(r=e[14])*I,w+=r*N,_+=r*B,S+=r*D,k+=r*z,T+=r*H,O+=r*q,C+=r*F,A+=r*X,E+=r*J,P+=r*Y,x+=r*K,L+=r*W,R+=r*G,U+=r*Z,M+=r*V,w+=(r=e[15])*I,s+=38*(S+=r*B),c+=38*(k+=r*D),a+=38*(T+=r*z),u+=38*(O+=r*H),h+=38*(C+=r*q),p+=38*(A+=r*F),f+=38*(E+=r*X),l+=38*(P+=r*J),d+=38*(x+=r*Y),y+=38*(L+=r*K),v+=38*(R+=r*W),g+=38*(U+=r*G),b+=38*(M+=r*Z),m+=38*(j+=r*V),i=(r=(i+=38*(_+=r*N))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),w=(r=w+o+65535)-65536*(o=Math.floor(r/65536)),i=(r=(i+=o-1+37*(o-1))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),w=(r=w+o+65535)-65536*(o=Math.floor(r/65536)),i+=o-1+37*(o-1),t[0]=i,t[1]=s,t[2]=c,t[3]=a,t[4]=u,t[5]=h,t[6]=p,t[7]=f,t[8]=l,t[9]=d,t[10]=y,t[11]=v,t[12]=g,t[13]=b,t[14]=m,t[15]=w}function z(t,e){D(t,e,e)}function H(t,n){var r,o=e();for(r=0;r<16;r++)o[r]=n[r];for(r=253;r>=0;r--)z(o,o),2!==r&&4!==r&&D(o,o,n);for(r=0;r<16;r++)t[r]=o[r]}function q(t,n,r){var o,i,s=new Uint8Array(32),c=new Float64Array(80),u=e(),h=e(),p=e(),f=e(),l=e(),d=e();for(i=0;i<31;i++)s[i]=n[i];for(s[31]=127&n[31]|64,s[0]&=248,I(c,r),i=0;i<16;i++)h[i]=c[i],f[i]=u[i]=p[i]=0;for(u[0]=f[0]=1,i=254;i>=0;--i)R(u,h,o=s[i>>>3]>>>(7&i)&1),R(p,f,o),N(l,u,p),B(u,u,p),N(p,h,f),B(h,h,f),z(f,l),z(d,u),D(u,p,u),D(p,h,l),N(l,u,p),B(u,u,p),z(h,u),B(p,f,d),D(u,p,a),N(u,u,f),D(p,p,u),D(u,f,d),D(f,h,c),z(h,l),R(u,h,o),R(p,f,o);for(i=0;i<16;i++)c[i+16]=u[i],c[i+32]=p[i],c[i+48]=h[i],c[i+64]=f[i];var y=c.subarray(32),v=c.subarray(16);return H(y,y),D(v,v,y),U(t,v),0}function F(t,e){return q(t,e,i)}function X(t,e){return r(e,32),F(t,e)}function J(t,e,n){var r=new Uint8Array(32);return q(r,n,e),m(t,o,r,w)}O.prototype.blocks=function(t,e,n){for(var r,o,i,s,c,a,u,h,p,f,l,d,y,v,g,b,m,w,_,S=this.fin?0:2048,k=this.h[0],T=this.h[1],O=this.h[2],C=this.h[3],A=this.h[4],E=this.h[5],P=this.h[6],x=this.h[7],L=this.h[8],R=this.h[9],U=this.r[0],M=this.r[1],j=this.r[2],I=this.r[3],N=this.r[4],B=this.r[5],D=this.r[6],z=this.r[7],H=this.r[8],q=this.r[9];n>=16;)f=p=0,f+=(k+=8191&(r=255&t[e+0]|(255&t[e+1])<<8))*U,f+=(T+=8191&(r>>>13|(o=255&t[e+2]|(255&t[e+3])<<8)<<3))*(5*q),f+=(O+=8191&(o>>>10|(i=255&t[e+4]|(255&t[e+5])<<8)<<6))*(5*H),f+=(C+=8191&(i>>>7|(s=255&t[e+6]|(255&t[e+7])<<8)<<9))*(5*z),p=(f+=(A+=8191&(s>>>4|(c=255&t[e+8]|(255&t[e+9])<<8)<<12))*(5*D))>>>13,f&=8191,f+=(E+=c>>>1&8191)*(5*B),f+=(P+=8191&(c>>>14|(a=255&t[e+10]|(255&t[e+11])<<8)<<2))*(5*N),f+=(x+=8191&(a>>>11|(u=255&t[e+12]|(255&t[e+13])<<8)<<5))*(5*I),f+=(L+=8191&(u>>>8|(h=255&t[e+14]|(255&t[e+15])<<8)<<8))*(5*j),l=p+=(f+=(R+=h>>>5|S)*(5*M))>>>13,l+=k*M,l+=T*U,l+=O*(5*q),l+=C*(5*H),p=(l+=A*(5*z))>>>13,l&=8191,l+=E*(5*D),l+=P*(5*B),l+=x*(5*N),l+=L*(5*I),p+=(l+=R*(5*j))>>>13,l&=8191,d=p,d+=k*j,d+=T*M,d+=O*U,d+=C*(5*q),p=(d+=A*(5*H))>>>13,d&=8191,d+=E*(5*z),d+=P*(5*D),d+=x*(5*B),d+=L*(5*N),y=p+=(d+=R*(5*I))>>>13,y+=k*I,y+=T*j,y+=O*M,y+=C*U,p=(y+=A*(5*q))>>>13,y&=8191,y+=E*(5*H),y+=P*(5*z),y+=x*(5*D),y+=L*(5*B),v=p+=(y+=R*(5*N))>>>13,v+=k*N,v+=T*I,v+=O*j,v+=C*M,p=(v+=A*U)>>>13,v&=8191,v+=E*(5*q),v+=P*(5*H),v+=x*(5*z),v+=L*(5*D),g=p+=(v+=R*(5*B))>>>13,g+=k*B,g+=T*N,g+=O*I,g+=C*j,p=(g+=A*M)>>>13,g&=8191,g+=E*U,g+=P*(5*q),g+=x*(5*H),g+=L*(5*z),b=p+=(g+=R*(5*D))>>>13,b+=k*D,b+=T*B,b+=O*N,b+=C*I,p=(b+=A*j)>>>13,b&=8191,b+=E*M,b+=P*U,b+=x*(5*q),b+=L*(5*H),m=p+=(b+=R*(5*z))>>>13,m+=k*z,m+=T*D,m+=O*B,m+=C*N,p=(m+=A*I)>>>13,m&=8191,m+=E*j,m+=P*M,m+=x*U,m+=L*(5*q),w=p+=(m+=R*(5*H))>>>13,w+=k*H,w+=T*z,w+=O*D,w+=C*B,p=(w+=A*N)>>>13,w&=8191,w+=E*I,w+=P*j,w+=x*M,w+=L*U,_=p+=(w+=R*(5*q))>>>13,_+=k*q,_+=T*H,_+=O*z,_+=C*D,p=(_+=A*B)>>>13,_&=8191,_+=E*N,_+=P*I,_+=x*j,_+=L*M,k=f=8191&(p=(p=((p+=(_+=R*U)>>>13)<<2)+p|0)+(f&=8191)|0),T=l+=p>>>=13,O=d&=8191,C=y&=8191,A=v&=8191,E=g&=8191,P=b&=8191,x=m&=8191,L=w&=8191,R=_&=8191,e+=16,n-=16;this.h[0]=k,this.h[1]=T,this.h[2]=O,this.h[3]=C,this.h[4]=A,this.h[5]=E,this.h[6]=P,this.h[7]=x,this.h[8]=L,this.h[9]=R},O.prototype.finish=function(t,e){var n,r,o,i,s=new Uint16Array(10);if(this.leftover){for(i=this.leftover,this.buffer[i++]=1;i<16;i++)this.buffer[i]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,i=2;i<10;i++)this.h[i]+=n,n=this.h[i]>>>13,this.h[i]&=8191;for(this.h[0]+=5*n,n=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=n,n=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=n,s[0]=this.h[0]+5,n=s[0]>>>13,s[0]&=8191,i=1;i<10;i++)s[i]=this.h[i]+n,n=s[i]>>>13,s[i]&=8191;for(s[9]-=8192,r=(1^n)-1,i=0;i<10;i++)s[i]&=r;for(r=~r,i=0;i<10;i++)this.h[i]=this.h[i]&r|s[i];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),o=this.h[0]+this.pad[0],this.h[0]=65535&o,i=1;i<8;i++)o=(this.h[i]+this.pad[i]|0)+(o>>>16)|0,this.h[i]=65535&o;t[e+0]=this.h[0]>>>0&255,t[e+1]=this.h[0]>>>8&255,t[e+2]=this.h[1]>>>0&255,t[e+3]=this.h[1]>>>8&255,t[e+4]=this.h[2]>>>0&255,t[e+5]=this.h[2]>>>8&255,t[e+6]=this.h[3]>>>0&255,t[e+7]=this.h[3]>>>8&255,t[e+8]=this.h[4]>>>0&255,t[e+9]=this.h[4]>>>8&255,t[e+10]=this.h[5]>>>0&255,t[e+11]=this.h[5]>>>8&255,t[e+12]=this.h[6]>>>0&255,t[e+13]=this.h[6]>>>8&255,t[e+14]=this.h[7]>>>0&255,t[e+15]=this.h[7]>>>8&255},O.prototype.update=function(t,e,n){var r,o;if(this.leftover){for((o=16-this.leftover)>n&&(o=n),r=0;r=16&&(o=n-n%16,this.blocks(t,e,o),e+=o,n-=o),n){for(r=0;r=128;){for(S=0;S<16;S++)k=8*S+G,x[S]=n[k+0]<<24|n[k+1]<<16|n[k+2]<<8|n[k+3],L[S]=n[k+4]<<24|n[k+5]<<16|n[k+6]<<8|n[k+7];for(S=0;S<80;S++)if(o=R,i=U,s=M,c=j,a=I,u=N,h=B,D,f=z,l=H,d=q,y=F,v=X,g=J,b=Y,K,C=65535&(O=K),A=O>>>16,E=65535&(T=D),P=T>>>16,C+=65535&(O=(X>>>14|I<<18)^(X>>>18|I<<14)^(I>>>9|X<<23)),A+=O>>>16,E+=65535&(T=(I>>>14|X<<18)^(I>>>18|X<<14)^(X>>>9|I<<23)),P+=T>>>16,C+=65535&(O=X&J^~X&Y),A+=O>>>16,E+=65535&(T=I&N^~I&B),P+=T>>>16,T=W[2*S],C+=65535&(O=W[2*S+1]),A+=O>>>16,E+=65535&T,P+=T>>>16,T=x[S%16],A+=(O=L[S%16])>>>16,E+=65535&T,P+=T>>>16,E+=(A+=(C+=65535&O)>>>16)>>>16,C=65535&(O=_=65535&C|A<<16),A=O>>>16,E=65535&(T=w=65535&E|(P+=E>>>16)<<16),P=T>>>16,C+=65535&(O=(z>>>28|R<<4)^(R>>>2|z<<30)^(R>>>7|z<<25)),A+=O>>>16,E+=65535&(T=(R>>>28|z<<4)^(z>>>2|R<<30)^(z>>>7|R<<25)),P+=T>>>16,A+=(O=z&H^z&q^H&q)>>>16,E+=65535&(T=R&U^R&M^U&M),P+=T>>>16,p=65535&(E+=(A+=(C+=65535&O)>>>16)>>>16)|(P+=E>>>16)<<16,m=65535&C|A<<16,C=65535&(O=y),A=O>>>16,E=65535&(T=c),P=T>>>16,A+=(O=_)>>>16,E+=65535&(T=w),P+=T>>>16,U=o,M=i,j=s,I=c=65535&(E+=(A+=(C+=65535&O)>>>16)>>>16)|(P+=E>>>16)<<16,N=a,B=u,D=h,R=p,H=f,q=l,F=d,X=y=65535&C|A<<16,J=v,Y=g,K=b,z=m,S%16==15)for(k=0;k<16;k++)T=x[k],C=65535&(O=L[k]),A=O>>>16,E=65535&T,P=T>>>16,T=x[(k+9)%16],C+=65535&(O=L[(k+9)%16]),A+=O>>>16,E+=65535&T,P+=T>>>16,w=x[(k+1)%16],C+=65535&(O=((_=L[(k+1)%16])>>>1|w<<31)^(_>>>8|w<<24)^(_>>>7|w<<25)),A+=O>>>16,E+=65535&(T=(w>>>1|_<<31)^(w>>>8|_<<24)^w>>>7),P+=T>>>16,w=x[(k+14)%16],A+=(O=((_=L[(k+14)%16])>>>19|w<<13)^(w>>>29|_<<3)^(_>>>6|w<<26))>>>16,E+=65535&(T=(w>>>19|_<<13)^(_>>>29|w<<3)^w>>>6),P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,x[k]=65535&E|P<<16,L[k]=65535&C|A<<16;C=65535&(O=z),A=O>>>16,E=65535&(T=R),P=T>>>16,T=t[0],A+=(O=e[0])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[0]=R=65535&E|P<<16,e[0]=z=65535&C|A<<16,C=65535&(O=H),A=O>>>16,E=65535&(T=U),P=T>>>16,T=t[1],A+=(O=e[1])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[1]=U=65535&E|P<<16,e[1]=H=65535&C|A<<16,C=65535&(O=q),A=O>>>16,E=65535&(T=M),P=T>>>16,T=t[2],A+=(O=e[2])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[2]=M=65535&E|P<<16,e[2]=q=65535&C|A<<16,C=65535&(O=F),A=O>>>16,E=65535&(T=j),P=T>>>16,T=t[3],A+=(O=e[3])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[3]=j=65535&E|P<<16,e[3]=F=65535&C|A<<16,C=65535&(O=X),A=O>>>16,E=65535&(T=I),P=T>>>16,T=t[4],A+=(O=e[4])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[4]=I=65535&E|P<<16,e[4]=X=65535&C|A<<16,C=65535&(O=J),A=O>>>16,E=65535&(T=N),P=T>>>16,T=t[5],A+=(O=e[5])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[5]=N=65535&E|P<<16,e[5]=J=65535&C|A<<16,C=65535&(O=Y),A=O>>>16,E=65535&(T=B),P=T>>>16,T=t[6],A+=(O=e[6])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[6]=B=65535&E|P<<16,e[6]=Y=65535&C|A<<16,C=65535&(O=K),A=O>>>16,E=65535&(T=D),P=T>>>16,T=t[7],A+=(O=e[7])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[7]=D=65535&E|P<<16,e[7]=K=65535&C|A<<16,G+=128,r-=128}return r}function Z(t,e,n){var r,o=new Int32Array(8),i=new Int32Array(8),s=new Uint8Array(256),c=n;for(o[0]=1779033703,o[1]=3144134277,o[2]=1013904242,o[3]=2773480762,o[4]=1359893119,o[5]=2600822924,o[6]=528734635,o[7]=1541459225,i[0]=4089235720,i[1]=2227873595,i[2]=4271175723,i[3]=1595750129,i[4]=2917565137,i[5]=725511199,i[6]=4215389547,i[7]=327033209,G(o,i,e,n),n%=128,r=0;r=0;--o)Q(t,e,r=n[o/8|0]>>(7&o)&1),V(e,t),V(t,t),Q(t,e,r)}function et(t,n){var r=[e(),e(),e(),e()];x(r[0],p),x(r[1],f),x(r[2],c),D(r[3],p,f),tt(t,r,n)}function nt(t,n,o){var i,s=new Uint8Array(64),c=[e(),e(),e(),e()];for(o||r(n,32),Z(s,n,32),s[0]&=248,s[31]&=127,s[31]|=64,et(c,s),$(t,c),i=0;i<32;i++)n[i+32]=t[i];return 0}var rt=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function ot(t,e){var n,r,o,i;for(r=63;r>=32;--r){for(n=0,o=r-32,i=r-12;o>8,e[o]-=256*n;e[o]+=n,e[r]=0}for(n=0,o=0;o<32;o++)e[o]+=n-(e[31]>>4)*rt[o],n=e[o]>>8,e[o]&=255;for(o=0;o<32;o++)e[o]-=n*rt[o];for(r=0;r<32;r++)e[r+1]+=e[r]>>8,t[r]=255&e[r]}function it(t){var e,n=new Float64Array(64);for(e=0;e<64;e++)n[e]=t[e];for(e=0;e<64;e++)t[e]=0;ot(t,n)}function st(t,n,r,o){var i,s,c=new Uint8Array(64),a=new Uint8Array(64),u=new Uint8Array(64),h=new Float64Array(64),p=[e(),e(),e(),e()];Z(c,o,32),c[0]&=248,c[31]&=127,c[31]|=64;var f=r+64;for(i=0;i=0;r--)z(o,o),1!==r&&D(o,o,n);for(r=0;r<16;r++)t[r]=o[r]}(r,r),D(r,r,i),D(r,r,a),D(r,r,a),D(t[0],r,a),z(o,t[0]),D(o,o,a),M(o,i)&&D(t[0],t[0],l),z(o,t[0]),D(o,o,a),M(o,i)?-1:(j(t[0])===n[31]>>7&&B(t[0],s,t[0]),D(t[3],t[0],t[1]),0)}function at(t,n,r,o){var i,s=new Uint8Array(32),c=new Uint8Array(64),a=[e(),e(),e(),e()],u=[e(),e(),e(),e()];if(-1,r<64)return-1;if(ct(u,o))return-1;for(i=0;i=0},t.sign.keyPair=function(){var t=new Uint8Array(32),e=new Uint8Array(64);return nt(t,e),{publicKey:t,secretKey:e}},t.sign.keyPair.fromSecretKey=function(t){if(yt(t),64!==t.length)throw new Error("bad secret key size");for(var e=new Uint8Array(32),n=0;n0)r.loading[t].push(n);else{r.loading[t]=[n];var o=we.createScriptRequest(r.getPath(t,e)),i=r.receivers.create(function(e){if(r.receivers.remove(i),r.loading[t]){var n=r.loading[t];delete r.loading[t];for(var s=function(t){t||o.cleanup()},c=0;c>>6)+u(128|63&e):u(224|e>>>12&15)+u(128|e>>>6&63)+u(128|63&e)},v=function(t){return t.replace(/[^\x00-\x7F]/g,y)},g=function(t){var e=[0,2,1][t.length%3],n=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[h.charAt(n>>>18),h.charAt(n>>>12&63),e>=2?"=":h.charAt(n>>>6&63),e>=1?"=":h.charAt(63&n)].join("")},b=window.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,g)},m=function(){function t(t,e,n,r){var o=this;this.clear=e,this.timer=t(function(){o.timer&&(o.timer=r(o.timer))},n)}return t.prototype.isRunning=function(){return null!==this.timer},t.prototype.ensureAborted=function(){this.timer&&(this.clear(this.timer),this.timer=null)},t}(),w=(d=function(t,e){return(d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}d(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});function _(t){window.clearTimeout(t)}function S(t){window.clearInterval(t)}var k=function(t){function e(e,n){return t.call(this,setTimeout,_,e,function(t){return n(),null})||this}return w(e,t),e}(m),T=function(t){function e(e,n){return t.call(this,setInterval,S,e,function(t){return n(),t})||this}return w(e,t),e}(m),O={now:function(){return Date.now?Date.now():(new Date).valueOf()},defer:function(t){return new k(0,t)},method:function(t){for(var e=[],n=1;n0)for(r=0;r=1002&&t.code<=1004?"backoff":null:4e3===t.code?"tls_only":t.code<4100?"refused":t.code<4200?"backoff":t.code<4300?"retry":"refused"},getCloseError:function(t){return 1e3!==t.code&&1001!==t.code?{type:"PusherError",data:{code:t.code,message:t.reason||t.message}}:null}},mt=bt,wt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),_t=function(t){function e(e,n){var r=t.call(this)||this;return r.id=e,r.transport=n,r.activityTimeout=n.activityTimeout,r.bindListeners(),r}return wt(e,t),e.prototype.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()},e.prototype.send=function(t){return this.transport.send(t)},e.prototype.send_event=function(t,e,n){var r={event:t,data:e};return n&&(r.channel=n),D.debug("Event sent",r),this.send(mt.encodeMessage(r))},e.prototype.ping=function(){this.transport.supportsPing()?this.transport.ping():this.send_event("pusher:ping",{})},e.prototype.close=function(){this.transport.close()},e.prototype.bindListeners=function(){var t=this,e={message:function(e){var n;try{n=mt.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(D.debug("Event recd",n),n.event){case"pusher:error":t.emit("error",{type:"PusherError",data:n.data});break;case"pusher:ping":t.emit("ping");break;case"pusher:pong":t.emit("pong")}t.emit("message",n)}},activity:function(){t.emit("activity")},error:function(e){t.emit("error",{type:"WebSocketError",error:e})},closed:function(e){n(),e&&e.code&&t.handleCloseEvent(e),t.transport=null,t.emit("closed")}},n=function(){P(e,function(e,n){t.transport.unbind(n,e)})};P(e,function(e,n){t.transport.bind(n,e)})},e.prototype.handleCloseEvent=function(t){var e=mt.getCloseAction(t),n=mt.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(tt),St=function(){function t(t,e){this.transport=t,this.callback=e,this.bindListeners()}return t.prototype.close=function(){this.unbindListeners(),this.transport.close()},t.prototype.bindListeners=function(){var t=this;this.onMessage=function(e){var n;t.unbindListeners();try{n=mt.processHandshake(e)}catch(e){return t.finish("error",{error:e}),void t.transport.close()}"connected"===n.action?t.finish("connected",{connection:new _t(n.id,t.transport),activityTimeout:n.activityTimeout}):(t.finish(n.action,{error:n.error}),t.transport.close())},this.onClosed=function(e){t.unbindListeners();var n=mt.getCloseAction(e)||"backoff",r=mt.getCloseError(e);t.finish(n,{error:r})},this.transport.bind("message",this.onMessage),this.transport.bind("closed",this.onClosed)},t.prototype.unbindListeners=function(){this.transport.unbind("message",this.onMessage),this.transport.unbind("closed",this.onClosed)},t.prototype.finish=function(t,e){this.callback(C({transport:this.transport,action:t},e))},t}(),kt=function(){function t(t,e){this.channel=t;var n=e.authTransport;if(void 0===we.getAuthorizers()[n])throw"'"+n+"' is not a recognized auth transport";this.type=n,this.options=e,this.authOptions=(e||{}).auth||{}}return t.prototype.composeQuery=function(t){var e="socket_id="+encodeURIComponent(t)+"&channel_name="+encodeURIComponent(this.channel.name);for(var n in this.authOptions.params)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(this.authOptions.params[n]);return e},t.prototype.authorize=function(e,n){return t.authorizers=t.authorizers||we.getAuthorizers(),t.authorizers[this.type].call(this,we,e,n)},t}(),Tt=function(){function t(t,e){this.timeline=t,this.options=e||{}}return t.prototype.send=function(t,e){this.timeline.isEmpty()||this.timeline.send(we.TimelineTransport.getAgent(this,t),e)},t}(),Ot=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Ct=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ot(e,t),e}(Error),At=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ot(e,t),e}(Error),Et=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ot(e,t),e}(Error),Pt=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ot(e,t),e}(Error),xt=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ot(e,t),e}(Error),Lt=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ot(e,t),e}(Error),Rt=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ot(e,t),e}(Error),Ut=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Mt=function(t){function e(e,n){var r=t.call(this,function(t,n){D.debug("No callbacks on "+e+" for "+t)})||this;return r.name=e,r.pusher=n,r.subscribed=!1,r.subscriptionPending=!1,r.subscriptionCancelled=!1,r}return Ut(e,t),e.prototype.authorize=function(t,e){return e(!1,{})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new Ct("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var n=H.buildLogSuffix("triggeringClientEvents");D.warn("Client event triggered before channel 'subscription_succeeded' event . "+n)}return this.pusher.send_event(t,e,this.name)},e.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},e.prototype.handleEvent=function(t){var e=t.event,n=t.data;if("pusher_internal:subscription_succeeded"===e)this.handleSubscriptionSucceededEvent(t);else if(0!==e.indexOf("pusher_internal:")){this.emit(e,n,{})}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",t.data)},e.prototype.subscribe=function(){var t=this;this.subscribed||(this.subscriptionPending=!0,this.subscriptionCancelled=!1,this.authorize(this.pusher.connection.socket_id,function(e,n){e?t.emit("pusher:subscription_error",n):t.pusher.send_event("pusher:subscribe",{auth:n.auth,channel_data:n.channel_data,channel:t.name})}))},e.prototype.unsubscribe=function(){this.subscribed=!1,this.pusher.send_event("pusher:unsubscribe",{channel:this.name})},e.prototype.cancelSubscription=function(){this.subscriptionCancelled=!0},e.prototype.reinstateSubscription=function(){this.subscriptionCancelled=!1},e}(tt),jt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),It=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return jt(e,t),e.prototype.authorize=function(t,e){return Kt.createAuthorizer(this,this.pusher.config).authorize(t,e)},e}(Mt),Nt=function(){function t(){this.reset()}return t.prototype.get=function(t){return Object.prototype.hasOwnProperty.call(this.members,t)?{id:t,info:this.members[t]}:null},t.prototype.each=function(t){var e=this;P(this.members,function(n,r){t(e.get(r))})},t.prototype.setMyID=function(t){this.myID=t},t.prototype.onSubscription=function(t){this.members=t.presence.hash,this.count=t.presence.count,this.me=this.get(this.myID)},t.prototype.addMember=function(t){return null===this.get(t.user_id)&&this.count++,this.members[t.user_id]=t.user_info,this.get(t.user_id)},t.prototype.removeMember=function(t){var e=this.get(t.user_id);return e&&(delete this.members[t.user_id],this.count--),e},t.prototype.reset=function(){this.members={},this.count=0,this.myID=null,this.me=null},t}(),Bt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Dt=function(t){function e(e,n){var r=t.call(this,e,n)||this;return r.members=new Nt,r}return Bt(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,function(t,e){if(!t){if(void 0===e.channel_data){var o=H.buildLogSuffix("authenticationEndpoint");return D.warn("Invalid auth response for channel '"+r.name+"',expected 'channel_data' field. "+o),void n("Invalid auth response")}var i=JSON.parse(e.channel_data);r.members.setMyID(i.user_id)}n(t,e)})},e.prototype.handleEvent=function(t){var e=t.event;if(0===e.indexOf("pusher_internal:"))this.handleInternalEvent(t);else{var n=t.data,r={};t.user_id&&(r.user_id=t.user_id),this.emit(e,n,r)}},e.prototype.handleInternalEvent=function(t){var e=t.event,n=t.data;switch(e){case"pusher_internal:subscription_succeeded":this.handleSubscriptionSucceededEvent(t);break;case"pusher_internal:member_added":var r=this.members.addMember(n);this.emit("pusher:member_added",r);break;case"pusher_internal:member_removed":var o=this.members.removeMember(n);o&&this.emit("pusher:member_removed",o)}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(t.data),this.emit("pusher:subscription_succeeded",this.members))},e.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},e}(It),zt=n(0),Ht=n(1),qt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Ft=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.key=null,e}return qt(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,function(t,e){if(t)n(!0,e);else{var o=e.shared_secret;if(!o){var i="No shared_secret key in auth payload for encrypted channel: "+r.name;return n(!0,i),void D.warn("Error: "+i)}r.key=Object(Ht.decodeBase64)(o),delete e.shared_secret,n(!1,e)}})},e.prototype.trigger=function(t,e){throw new xt("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e){var n=e.event,r=e.data;0!==n.indexOf("pusher_internal:")&&0!==n.indexOf("pusher:")?this.handleEncryptedEvent(n,r):t.prototype.handleEvent.call(this,e)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(this.key)if(e.ciphertext&&e.nonce){var r=Object(Ht.decodeBase64)(e.ciphertext);if(r.length0&&this.emit("connecting_in",Math.round(t/1e3)),this.retryTimer=new k(t||0,function(){e.disconnectInternally(),e.connect()})},e.prototype.clearRetryTimer=function(){this.retryTimer&&(this.retryTimer.ensureAborted(),this.retryTimer=null)},e.prototype.setUnavailableTimer=function(){var t=this;this.unavailableTimer=new k(this.options.unavailableTimeout,function(){t.updateState("unavailable")})},e.prototype.clearUnavailableTimer=function(){this.unavailableTimer&&this.unavailableTimer.ensureAborted()},e.prototype.sendActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection.ping(),this.activityTimer=new k(this.options.pongTimeout,function(){t.timeline.error({pong_timed_out:t.options.pongTimeout}),t.retryIn(0)})},e.prototype.resetActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection&&!this.connection.handlesActivityChecks()&&(this.activityTimer=new k(this.activityTimeout,function(){t.sendActivityCheck()}))},e.prototype.stopActivityCheck=function(){this.activityTimer&&this.activityTimer.ensureAborted()},e.prototype.buildConnectionCallbacks=function(t){var e=this;return C({},t,{message:function(t){e.resetActivityCheck(),e.emit("message",t)},ping:function(){e.send_event("pusher:pong",{})},activity:function(){e.resetActivityCheck()},error:function(t){e.emit("error",{type:"WebSocketError",error:t})},closed:function(){e.abandonConnection(),e.shouldRetry()&&e.retryIn(1e3)}})},e.prototype.buildHandshakeCallbacks=function(t){var e=this;return C({},t,{connected:function(t){e.activityTimeout=Math.min(e.options.activityTimeout,t.activityTimeout,t.connection.activityTimeout||1/0),e.clearUnavailableTimer(),e.setConnection(t.connection),e.socket_id=e.connection.id,e.updateState("connected",{socket_id:e.socket_id})}})},e.prototype.buildErrorCallbacks=function(){var t=this,e=function(e){return function(n){n.error&&t.emit("error",{type:"WebSocketError",error:n.error}),e(n)}};return{tls_only:e(function(){t.usingTLS=!0,t.updateStrategy(),t.retryIn(0)}),refused:e(function(){t.disconnect()}),backoff:e(function(){t.retryIn(1e3)}),retry:e(function(){t.retryIn(0)})}},e.prototype.setConnection=function(t){for(var e in this.connection=t,this.connectionCallbacks)this.connection.bind(e,this.connectionCallbacks[e]);this.resetActivityCheck()},e.prototype.abandonConnection=function(){if(this.connection){for(var t in this.stopActivityCheck(),this.connectionCallbacks)this.connection.unbind(t,this.connectionCallbacks[t]);var e=this.connection;return this.connection=null,e}},e.prototype.updateState=function(t,e){var n=this.state;if(this.state=t,n!==t){var r=t;"connected"===r&&(r+=" with new socket ID "+e.socket_id),D.debug("State changed",n+" -> "+r),this.timeline.info({state:t,params:e}),this.emit("state_change",{previous:n,current:t}),this.emit(t,e)}},e.prototype.shouldRetry=function(){return"connecting"===this.state||"connected"===this.state},e}(tt),Yt=function(){function t(){this.channels={}}return t.prototype.add=function(t,e){return this.channels[t]||(this.channels[t]=function(t,e){return 0===t.indexOf("private-encrypted-")?Kt.createEncryptedChannel(t,e):0===t.indexOf("private-")?Kt.createPrivateChannel(t,e):0===t.indexOf("presence-")?Kt.createPresenceChannel(t,e):Kt.createChannel(t,e)}(t,e)),this.channels[t]},t.prototype.all=function(){return function(t){var e=[];return P(t,function(t){e.push(t)}),e}(this.channels)},t.prototype.find=function(t){return this.channels[t]},t.prototype.remove=function(t){var e=this.channels[t];return delete this.channels[t],e},t.prototype.disconnect=function(){P(this.channels,function(t){t.disconnect()})},t}();var Kt={createChannels:function(){return new Yt},createConnectionManager:function(t,e){return new Jt(t,e)},createChannel:function(t,e){return new Mt(t,e)},createPrivateChannel:function(t,e){return new It(t,e)},createPresenceChannel:function(t,e){return new Dt(t,e)},createEncryptedChannel:function(t,e){return new Ft(t,e)},createTimelineSender:function(t,e){return new Tt(t,e)},createAuthorizer:function(t,e){return e.authorizer?e.authorizer(t,e):new kt(t,e)},createHandshake:function(t,e){return new St(t,e)},createAssistantToTheTransportManager:function(t,e,n){return new gt(t,e,n)}},Wt=function(){function t(t){this.options=t||{},this.livesLeft=this.options.lives||1/0}return t.prototype.getAssistant=function(t){return Kt.createAssistantToTheTransportManager(this,t,{minPingDelay:this.options.minPingDelay,maxPingDelay:this.options.maxPingDelay})},t.prototype.isAlive=function(){return this.livesLeft>0},t.prototype.reportDeath=function(){this.livesLeft-=1},t}(),Gt=function(){function t(t,e){this.strategies=t,this.loop=Boolean(e.loop),this.failFast=Boolean(e.failFast),this.timeout=e.timeout,this.timeoutLimit=e.timeoutLimit}return t.prototype.isSupported=function(){return j(this.strategies,O.method("isSupported"))},t.prototype.connect=function(t,e){var n=this,r=this.strategies,o=0,i=this.timeout,s=null,c=function(a,u){u?e(null,u):(o+=1,n.loop&&(o%=r.length),o0&&(o=new k(n.timeout,function(){i.abort(),r(!0)})),i=t.connect(e,function(t,e){t&&o&&o.isRunning()&&!n.failFast||(o&&o.ensureAborted(),r(t,e))}),{abort:function(){o&&o.ensureAborted(),i.abort()},forceMinPriority:function(t){i.forceMinPriority(t)}}},t}(),Zt=function(){function t(t){this.strategies=t}return t.prototype.isSupported=function(){return j(this.strategies,O.method("isSupported"))},t.prototype.connect=function(t,e){return function(t,e,n){var r=R(t,function(t,r,o,i){return t.connect(e,n(r,i))});return{abort:function(){L(r,Vt)},forceMinPriority:function(t){L(r,function(e){e.forceMinPriority(t)})}}}(this.strategies,t,function(t,n){return function(r,o){n[t].error=r,r?function(t){return function(t,e){for(var n=0;n=O.now()){var i=this.transports[r.transport];i&&(this.timeline.info({cached:!0,transport:r.transport,latency:r.latency}),o.push(new Gt([i],{timeout:2*r.latency+1e3,failFast:!0})))}var s=O.now(),c=o.pop().connect(t,function r(i,a){i?(te(n),o.length>0?(s=O.now(),c=o.pop().connect(t,r)):e(i)):(!function(t,e,n){var r=we.getLocalStorage();if(r)try{r[$t(t)]=B({timestamp:O.now(),transport:e,latency:n})}catch(t){}}(n,a.transport.name,O.now()-s),e(null,a))});return{abort:function(){c.abort()},forceMinPriority:function(e){t=e,c&&c.forceMinPriority(e)}}},t}();function $t(t){return"pusherTransport"+(t?"TLS":"NonTLS")}function te(t){var e=we.getLocalStorage();if(e)try{delete e[$t(t)]}catch(t){}}var ee=function(){function t(t,e){var n=e.delay;this.strategy=t,this.options={delay:n}}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n,r=this.strategy,o=new k(this.options.delay,function(){n=r.connect(t,e)});return{abort:function(){o.ensureAborted(),n&&n.abort()},forceMinPriority:function(e){t=e,n&&n.forceMinPriority(e)}}},t}(),ne=function(){function t(t,e,n){this.test=t,this.trueBranch=e,this.falseBranch=n}return t.prototype.isSupported=function(){return(this.test()?this.trueBranch:this.falseBranch).isSupported()},t.prototype.connect=function(t,e){return(this.test()?this.trueBranch:this.falseBranch).connect(t,e)},t}(),re=function(){function t(t){this.strategy=t}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.strategy.connect(t,function(t,r){r&&n.abort(),e(t,r)});return n},t}();function oe(t){return function(){return t.isSupported()}}var ie,se=function(t,e){var n={};function r(r,o,i,s,c){var a=e(t,r,o,i,s,c);return n[r]=a,a}var o,i={hostNonTLS:t.wsHost+":"+t.wsPort,hostTLS:t.wsHost+":"+t.wssPort,httpPath:t.wsPath},s=C({},i,{useTLS:!0}),c={hostNonTLS:t.httpHost+":"+t.httpPort,hostTLS:t.httpHost+":"+t.httpsPort,httpPath:t.httpPath},a={loop:!0,timeout:15e3,timeoutLimit:6e4},u=new Wt({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),h=new Wt({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),p=r("ws","ws",3,i,u),f=r("wss","ws",3,s,u),l=r("sockjs","sockjs",1,c),d=r("xhr_streaming","xhr_streaming",1,c,h),y=r("xdr_streaming","xdr_streaming",1,c,h),v=r("xhr_polling","xhr_polling",1,c),g=r("xdr_polling","xdr_polling",1,c),b=new Gt([p],a),m=new Gt([f],a),w=new Gt([l],a),_=new Gt([new ne(oe(d),d,y)],a),S=new Gt([new ne(oe(v),v,g)],a),k=new Gt([new ne(oe(_),new Zt([_,new ee(S,{delay:4e3})]),S)],a),T=new ne(oe(k),k,w);return o=t.useTLS?new Zt([b,new ee(T,{delay:2e3})]):new Zt([b,new ee(m,{delay:2e3}),new ee(T,{delay:5e3})]),new Qt(new re(new ne(oe(p),o,T)),n,{ttl:18e5,timeline:t.timeline,useTLS:t.useTLS})},ce={getRequest:function(t){var e=new window.XDomainRequest;return e.ontimeout=function(){t.emit("error",new At),t.close()},e.onerror=function(e){t.emit("error",e),t.close()},e.onprogress=function(){e.responseText&&e.responseText.length>0&&t.onChunk(200,e.responseText)},e.onload=function(){e.responseText&&e.responseText.length>0&&t.onChunk(200,e.responseText),t.emit("finished",200),t.close()},e},abortRequest:function(t){t.ontimeout=t.onerror=t.onprogress=t.onload=null,t.abort()}},ae=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),ue=function(t){function e(e,n,r){var o=t.call(this)||this;return o.hooks=e,o.method=n,o.url=r,o}return ae(e,t),e.prototype.start=function(t){var e=this;this.position=0,this.xhr=this.hooks.getRequest(this),this.unloader=function(){e.close()},we.addUnloadListener(this.unloader),this.xhr.open(this.method,this.url,!0),this.xhr.setRequestHeader&&this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.send(t)},e.prototype.close=function(){this.unloader&&(we.removeUnloadListener(this.unloader),this.unloader=null),this.xhr&&(this.hooks.abortRequest(this.xhr),this.xhr=null)},e.prototype.onChunk=function(t,e){for(;;){var n=this.advanceBuffer(e);if(!n)break;this.emit("chunk",{status:t,data:n})}this.isBufferTooLong(e)&&this.emit("buffer_too_long")},e.prototype.advanceBuffer=function(t){var e=t.slice(this.position),n=e.indexOf("\n");return-1!==n?(this.position+=n+1,e.slice(0,n)):null},e.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>262144},e}(tt);!function(t){t[t.CONNECTING=0]="CONNECTING",t[t.OPEN=1]="OPEN",t[t.CLOSED=3]="CLOSED"}(ie||(ie={}));var he=ie,pe=1;function fe(t){var e=-1===t.indexOf("?")?"?":"&";return t+e+"t="+ +new Date+"&n="+pe++}function le(t){return Math.floor(Math.random()*t)}var de,ye=function(){function t(t,e){this.hooks=t,this.session=le(1e3)+"/"+function(t){for(var e=[],n=0;n0&&t.onChunk(e.status,e.responseText);break;case 4:e.responseText&&e.responseText.length>0&&t.onChunk(e.status,e.responseText),t.emit("finished",e.status),t.close()}},e},abortRequest:function(t){t.onreadystatechange=null,t.abort()}},me={createStreamingSocket:function(t){return this.createSocket(ve,t)},createPollingSocket:function(t){return this.createSocket(ge,t)},createSocket:function(t,e){return new ye(t,e)},createXHR:function(t,e){return this.createRequest(be,t,e)},createRequest:function(t,e,n){return new ue(t,e,n)},createXDR:function(t,e){return this.createRequest(ce,t,e)}},we={nextAuthCallbackID:1,auth_callbacks:{},ScriptReceivers:o,DependenciesReceivers:c,getDefaultStrategy:se,Transports:dt,transportConnectionInitializer:function(){var t=this;t.timeline.info(t.buildTimelineMessage({transport:t.name+(t.options.useTLS?"s":"")})),t.hooks.isInitialized()?t.changeState("initialized"):t.hooks.file?(t.changeState("initializing"),a.load(t.hooks.file,{useTLS:t.options.useTLS},function(e,n){t.hooks.isInitialized()?(t.changeState("initialized"),n(!0)):(e&&t.onError(e),t.onClose(),n(!1))})):t.onClose()},HTTPFactory:me,TimelineTransport:Y,getXHRAPI:function(){return window.XMLHttpRequest},getWebSocketAPI:function(){return window.WebSocket||window.MozWebSocket},setup:function(t){var e=this;window.Pusher=t;var n=function(){e.onDocumentBody(t.ready)};window.JSON?n():a.load("json2",{},n)},getDocument:function(){return document},getProtocol:function(){return this.getDocument().location.protocol},getAuthorizers:function(){return{ajax:q,jsonp:F}},onDocumentBody:function(t){var e=this;document.body?t():setTimeout(function(){e.onDocumentBody(t)},0)},createJSONPRequest:function(t,e){return new J(t,e)},createScriptRequest:function(t){return new X(t)},getLocalStorage:function(){try{return window.localStorage}catch(t){return}},createXHR:function(){return this.getXHRAPI()?this.createXMLHttpRequest():this.createMicrosoftXHR()},createXMLHttpRequest:function(){return new(this.getXHRAPI())},createMicrosoftXHR:function(){return new ActiveXObject("Microsoft.XMLHTTP")},getNetwork:function(){return vt},createWebSocket:function(t){return new(this.getWebSocketAPI())(t)},createSocketRequest:function(t,e){if(this.isXHRSupported())return this.HTTPFactory.createXHR(t,e);if(this.isXDRSupported(0===e.indexOf("https:")))return this.HTTPFactory.createXDR(t,e);throw"Cross-origin HTTP requests are not supported"},isXHRSupported:function(){var t=this.getXHRAPI();return Boolean(t)&&void 0!==(new t).withCredentials},isXDRSupported:function(t){var e=t?"https:":"http:",n=this.getProtocol();return Boolean(window.XDomainRequest)&&n===e},addUnloadListener:function(t){void 0!==window.addEventListener?window.addEventListener("unload",t,!1):void 0!==window.attachEvent&&window.attachEvent("onunload",t)},removeUnloadListener:function(t){void 0!==window.addEventListener?window.removeEventListener("unload",t,!1):void 0!==window.detachEvent&&window.detachEvent("onunload",t)}};!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(de||(de={}));var _e=de,Se=function(){function t(t,e,n){this.key=t,this.session=e,this.events=[],this.options=n||{},this.sent=0,this.uniqueID=0}return t.prototype.log=function(t,e){t<=this.options.level&&(this.events.push(C({},e,{timestamp:O.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(_e.ERROR,t)},t.prototype.info=function(t){this.log(_e.INFO,t)},t.prototype.debug=function(t){this.log(_e.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,r=C({session:this.session,bundle:this.sent+1,key:this.key,lib:"js",version:this.options.version,cluster:this.options.cluster,features:this.options.features,timeline:this.events},this.options.params);return this.events=[],t(r,function(t,r){t||n.sent++,e&&e(t,r)}),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}(),ke=function(){function t(t,e,n,r){this.name=t,this.priority=e,this.transport=n,this.options=r||{}}return t.prototype.isSupported=function(){return this.transport.isSupported({useTLS:this.options.useTLS})},t.prototype.connect=function(t,e){var n=this;if(!this.isSupported())return Te(new Rt,e);if(this.priority> 24) & 0xff; + x[i+1] = (h >> 16) & 0xff; + x[i+2] = (h >> 8) & 0xff; + x[i+3] = h & 0xff; + x[i+4] = (l >> 24) & 0xff; + x[i+5] = (l >> 16) & 0xff; + x[i+6] = (l >> 8) & 0xff; + x[i+7] = l & 0xff; +} -/***/ }), -/* 2 */ -/***/ (function(module, exports, __webpack_require__) { +function vn(x, xi, y, yi, n) { + var i,d = 0; + for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i]; + return (1 & ((d - 1) >>> 8)) - 1; +} -"use strict"; - -exports.__esModule = true; -var timers_1 = __webpack_require__(5); -var Util = { - now: function () { - if (Date.now) { - return Date.now(); - } - else { - return new Date().valueOf(); - } - }, - defer: function (callback) { - return new timers_1.OneOffTimer(0, callback); - }, - method: function (name) { - var args = []; - for (var _i = 1; _i < arguments.length; _i++) { - args[_i - 1] = arguments[_i]; - } - var boundArguments = Array.prototype.slice.call(arguments, 1); - return function (object) { - return object[name].apply(object, boundArguments.concat(arguments)); - }; - } -}; -exports["default"] = Util; +function crypto_verify_16(x, xi, y, yi) { + return vn(x,xi,y,yi,16); +} +function crypto_verify_32(x, xi, y, yi) { + return vn(x,xi,y,yi,32); +} -/***/ }), -/* 3 */ -/***/ (function(module, exports, __webpack_require__) { +function core_salsa20(o, p, k, c) { + var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, + j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, + j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, + j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, + j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, + j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, + j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, + j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, + j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, + j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, + j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, + j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, + j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, + j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, + j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, + j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; -"use strict"; + var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, + x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, + x15 = j15, u; -exports.__esModule = true; -var collections_1 = __webpack_require__(0); -var pusher_1 = __webpack_require__(11); -var Logger = { - debug: function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - if (!pusher_1["default"].log) { - return; - } - pusher_1["default"].log(collections_1.stringify.apply(this, arguments)); - }, - warn: function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - var message = collections_1.stringify.apply(this, arguments); - if (pusher_1["default"].log) { - pusher_1["default"].log(message); - } - else if (self.console) { - if (self.console.warn) { - self.console.warn(message); - } - else if (self.console.log) { - self.console.log(message); - } - } - } -}; -exports["default"] = Logger; + for (var i = 0; i < 20; i += 2) { + u = x0 + x12 | 0; + x4 ^= u<<7 | u>>>(32-7); + u = x4 + x0 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x4 | 0; + x12 ^= u<<13 | u>>>(32-13); + u = x12 + x8 | 0; + x0 ^= u<<18 | u>>>(32-18); + u = x5 + x1 | 0; + x9 ^= u<<7 | u>>>(32-7); + u = x9 + x5 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x9 | 0; + x1 ^= u<<13 | u>>>(32-13); + u = x1 + x13 | 0; + x5 ^= u<<18 | u>>>(32-18); -/***/ }), -/* 4 */ -/***/ (function(module, exports, __webpack_require__) { + u = x10 + x6 | 0; + x14 ^= u<<7 | u>>>(32-7); + u = x14 + x10 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x14 | 0; + x6 ^= u<<13 | u>>>(32-13); + u = x6 + x2 | 0; + x10 ^= u<<18 | u>>>(32-18); -"use strict"; + u = x15 + x11 | 0; + x3 ^= u<<7 | u>>>(32-7); + u = x3 + x15 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x3 | 0; + x11 ^= u<<13 | u>>>(32-13); + u = x11 + x7 | 0; + x15 ^= u<<18 | u>>>(32-18); -exports.__esModule = true; -var Collections = __webpack_require__(0); -var callback_registry_1 = __webpack_require__(24); -var Dispatcher = (function () { - function Dispatcher(failThrough) { - this.callbacks = new callback_registry_1["default"](); - this.global_callbacks = []; - this.failThrough = failThrough; - } - Dispatcher.prototype.bind = function (eventName, callback, context) { - this.callbacks.add(eventName, callback, context); - return this; - }; - Dispatcher.prototype.bind_global = function (callback) { - this.global_callbacks.push(callback); - return this; - }; - Dispatcher.prototype.unbind = function (eventName, callback, context) { - this.callbacks.remove(eventName, callback, context); - return this; - }; - Dispatcher.prototype.unbind_global = function (callback) { - if (!callback) { - this.global_callbacks = []; - return this; - } - this.global_callbacks = Collections.filter(this.global_callbacks || [], function (c) { return c !== callback; }); - return this; - }; - Dispatcher.prototype.unbind_all = function () { - this.unbind(); - this.unbind_global(); - return this; - }; - Dispatcher.prototype.emit = function (eventName, data, metadata) { - for (var i = 0; i < this.global_callbacks.length; i++) { - this.global_callbacks[i](eventName, data); - } - var callbacks = this.callbacks.get(eventName); - var args = []; - if (metadata) { - args.push(data, metadata); - } - else if (data) { - args.push(data); - } - if (callbacks && callbacks.length > 0) { - for (var i = 0; i < callbacks.length; i++) { - callbacks[i].fn.apply(callbacks[i].context || self, args); - } - } - else if (this.failThrough) { - this.failThrough(eventName, data); - } - return this; - }; - return Dispatcher; -}()); -exports["default"] = Dispatcher; + u = x0 + x3 | 0; + x1 ^= u<<7 | u>>>(32-7); + u = x1 + x0 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x1 | 0; + x3 ^= u<<13 | u>>>(32-13); + u = x3 + x2 | 0; + x0 ^= u<<18 | u>>>(32-18); + u = x5 + x4 | 0; + x6 ^= u<<7 | u>>>(32-7); + u = x6 + x5 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x6 | 0; + x4 ^= u<<13 | u>>>(32-13); + u = x4 + x7 | 0; + x5 ^= u<<18 | u>>>(32-18); -/***/ }), -/* 5 */ -/***/ (function(module, exports, __webpack_require__) { + u = x10 + x9 | 0; + x11 ^= u<<7 | u>>>(32-7); + u = x11 + x10 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x11 | 0; + x9 ^= u<<13 | u>>>(32-13); + u = x9 + x8 | 0; + x10 ^= u<<18 | u>>>(32-18); -"use strict"; + u = x15 + x14 | 0; + x12 ^= u<<7 | u>>>(32-7); + u = x12 + x15 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x12 | 0; + x14 ^= u<<13 | u>>>(32-13); + u = x14 + x13 | 0; + x15 ^= u<<18 | u>>>(32-18); + } + x0 = x0 + j0 | 0; + x1 = x1 + j1 | 0; + x2 = x2 + j2 | 0; + x3 = x3 + j3 | 0; + x4 = x4 + j4 | 0; + x5 = x5 + j5 | 0; + x6 = x6 + j6 | 0; + x7 = x7 + j7 | 0; + x8 = x8 + j8 | 0; + x9 = x9 + j9 | 0; + x10 = x10 + j10 | 0; + x11 = x11 + j11 | 0; + x12 = x12 + j12 | 0; + x13 = x13 + j13 | 0; + x14 = x14 + j14 | 0; + x15 = x15 + j15 | 0; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var abstract_timer_1 = __webpack_require__(19); -function clearTimeout(timer) { - self.clearTimeout(timer); -} -function clearInterval(timer) { - self.clearInterval(timer); -} -var OneOffTimer = (function (_super) { - __extends(OneOffTimer, _super); - function OneOffTimer(delay, callback) { - return _super.call(this, setTimeout, clearTimeout, delay, function (timer) { - callback(); - return null; - }) || this; - } - return OneOffTimer; -}(abstract_timer_1["default"])); -exports.OneOffTimer = OneOffTimer; -var PeriodicTimer = (function (_super) { - __extends(PeriodicTimer, _super); - function PeriodicTimer(delay, callback) { - return _super.call(this, setInterval, clearInterval, delay, function (timer) { - callback(); - return timer; - }) || this; - } - return PeriodicTimer; -}(abstract_timer_1["default"])); -exports.PeriodicTimer = PeriodicTimer; + o[ 0] = x0 >>> 0 & 0xff; + o[ 1] = x0 >>> 8 & 0xff; + o[ 2] = x0 >>> 16 & 0xff; + o[ 3] = x0 >>> 24 & 0xff; + o[ 4] = x1 >>> 0 & 0xff; + o[ 5] = x1 >>> 8 & 0xff; + o[ 6] = x1 >>> 16 & 0xff; + o[ 7] = x1 >>> 24 & 0xff; -/***/ }), -/* 6 */ -/***/ (function(module, exports, __webpack_require__) { + o[ 8] = x2 >>> 0 & 0xff; + o[ 9] = x2 >>> 8 & 0xff; + o[10] = x2 >>> 16 & 0xff; + o[11] = x2 >>> 24 & 0xff; -"use strict"; + o[12] = x3 >>> 0 & 0xff; + o[13] = x3 >>> 8 & 0xff; + o[14] = x3 >>> 16 & 0xff; + o[15] = x3 >>> 24 & 0xff; -exports.__esModule = true; -var assistant_to_the_transport_manager_1 = __webpack_require__(27); -var handshake_1 = __webpack_require__(28); -var pusher_authorizer_1 = __webpack_require__(30); -var timeline_sender_1 = __webpack_require__(31); -var presence_channel_1 = __webpack_require__(32); -var private_channel_1 = __webpack_require__(9); -var encrypted_channel_1 = __webpack_require__(34); -var channel_1 = __webpack_require__(13); -var connection_manager_1 = __webpack_require__(38); -var channels_1 = __webpack_require__(39); -var Factory = { - createChannels: function () { - return new channels_1["default"](); - }, - createConnectionManager: function (key, options) { - return new connection_manager_1["default"](key, options); - }, - createChannel: function (name, pusher) { - return new channel_1["default"](name, pusher); - }, - createPrivateChannel: function (name, pusher) { - return new private_channel_1["default"](name, pusher); - }, - createPresenceChannel: function (name, pusher) { - return new presence_channel_1["default"](name, pusher); - }, - createEncryptedChannel: function (name, pusher) { - return new encrypted_channel_1["default"](name, pusher); - }, - createTimelineSender: function (timeline, options) { - return new timeline_sender_1["default"](timeline, options); - }, - createAuthorizer: function (channel, options) { - if (options.authorizer) { - return options.authorizer(channel, options); - } - return new pusher_authorizer_1["default"](channel, options); - }, - createHandshake: function (transport, callback) { - return new handshake_1["default"](transport, callback); - }, - createAssistantToTheTransportManager: function (manager, transport, options) { - return new assistant_to_the_transport_manager_1["default"](manager, transport, options); - } -}; -exports["default"] = Factory; + o[16] = x4 >>> 0 & 0xff; + o[17] = x4 >>> 8 & 0xff; + o[18] = x4 >>> 16 & 0xff; + o[19] = x4 >>> 24 & 0xff; + o[20] = x5 >>> 0 & 0xff; + o[21] = x5 >>> 8 & 0xff; + o[22] = x5 >>> 16 & 0xff; + o[23] = x5 >>> 24 & 0xff; -/***/ }), -/* 7 */ -/***/ (function(module, exports, __webpack_require__) { + o[24] = x6 >>> 0 & 0xff; + o[25] = x6 >>> 8 & 0xff; + o[26] = x6 >>> 16 & 0xff; + o[27] = x6 >>> 24 & 0xff; -"use strict"; + o[28] = x7 >>> 0 & 0xff; + o[29] = x7 >>> 8 & 0xff; + o[30] = x7 >>> 16 & 0xff; + o[31] = x7 >>> 24 & 0xff; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var BadEventName = (function (_super) { - __extends(BadEventName, _super); - function BadEventName(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return BadEventName; -}(Error)); -exports.BadEventName = BadEventName; -var RequestTimedOut = (function (_super) { - __extends(RequestTimedOut, _super); - function RequestTimedOut(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return RequestTimedOut; -}(Error)); -exports.RequestTimedOut = RequestTimedOut; -var TransportPriorityTooLow = (function (_super) { - __extends(TransportPriorityTooLow, _super); - function TransportPriorityTooLow(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return TransportPriorityTooLow; -}(Error)); -exports.TransportPriorityTooLow = TransportPriorityTooLow; -var TransportClosed = (function (_super) { - __extends(TransportClosed, _super); - function TransportClosed(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return TransportClosed; -}(Error)); -exports.TransportClosed = TransportClosed; -var UnsupportedFeature = (function (_super) { - __extends(UnsupportedFeature, _super); - function UnsupportedFeature(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return UnsupportedFeature; -}(Error)); -exports.UnsupportedFeature = UnsupportedFeature; -var UnsupportedTransport = (function (_super) { - __extends(UnsupportedTransport, _super); - function UnsupportedTransport(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return UnsupportedTransport; -}(Error)); -exports.UnsupportedTransport = UnsupportedTransport; -var UnsupportedStrategy = (function (_super) { - __extends(UnsupportedStrategy, _super); - function UnsupportedStrategy(msg) { - var _newTarget = this.constructor; - var _this = _super.call(this, msg) || this; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return UnsupportedStrategy; -}(Error)); -exports.UnsupportedStrategy = UnsupportedStrategy; + o[32] = x8 >>> 0 & 0xff; + o[33] = x8 >>> 8 & 0xff; + o[34] = x8 >>> 16 & 0xff; + o[35] = x8 >>> 24 & 0xff; + o[36] = x9 >>> 0 & 0xff; + o[37] = x9 >>> 8 & 0xff; + o[38] = x9 >>> 16 & 0xff; + o[39] = x9 >>> 24 & 0xff; -/***/ }), -/* 8 */ -/***/ (function(module, exports, __webpack_require__) { + o[40] = x10 >>> 0 & 0xff; + o[41] = x10 >>> 8 & 0xff; + o[42] = x10 >>> 16 & 0xff; + o[43] = x10 >>> 24 & 0xff; -"use strict"; + o[44] = x11 >>> 0 & 0xff; + o[45] = x11 >>> 8 & 0xff; + o[46] = x11 >>> 16 & 0xff; + o[47] = x11 >>> 24 & 0xff; -exports.__esModule = true; -var Defaults = { - VERSION: "5.0.1", - PROTOCOL: 7, - host: 'ws.pusherapp.com', - ws_port: 80, - wss_port: 443, - ws_path: '', - sockjs_host: 'sockjs.pusher.com', - sockjs_http_port: 80, - sockjs_https_port: 443, - sockjs_path: "/pusher", - stats_host: 'stats.pusher.com', - channel_auth_endpoint: '/pusher/auth', - channel_auth_transport: 'ajax', - activity_timeout: 120000, - pong_timeout: 30000, - unavailable_timeout: 10000, - cdn_http: "http://js.pusher.com", - cdn_https: "https://js.pusher.com", - dependency_suffix: "" -}; -exports["default"] = Defaults; + o[48] = x12 >>> 0 & 0xff; + o[49] = x12 >>> 8 & 0xff; + o[50] = x12 >>> 16 & 0xff; + o[51] = x12 >>> 24 & 0xff; + o[52] = x13 >>> 0 & 0xff; + o[53] = x13 >>> 8 & 0xff; + o[54] = x13 >>> 16 & 0xff; + o[55] = x13 >>> 24 & 0xff; -/***/ }), -/* 9 */ -/***/ (function(module, exports, __webpack_require__) { + o[56] = x14 >>> 0 & 0xff; + o[57] = x14 >>> 8 & 0xff; + o[58] = x14 >>> 16 & 0xff; + o[59] = x14 >>> 24 & 0xff; -"use strict"; + o[60] = x15 >>> 0 & 0xff; + o[61] = x15 >>> 8 & 0xff; + o[62] = x15 >>> 16 & 0xff; + o[63] = x15 >>> 24 & 0xff; +} -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var factory_1 = __webpack_require__(6); -var channel_1 = __webpack_require__(13); -var PrivateChannel = (function (_super) { - __extends(PrivateChannel, _super); - function PrivateChannel() { - return _super !== null && _super.apply(this, arguments) || this; - } - PrivateChannel.prototype.authorize = function (socketId, callback) { - var authorizer = factory_1["default"].createAuthorizer(this, this.pusher.config); - return authorizer.authorize(socketId, callback); - }; - return PrivateChannel; -}(channel_1["default"])); -exports["default"] = PrivateChannel; +function core_hsalsa20(o,p,k,c) { + var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, + j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, + j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, + j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, + j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, + j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, + j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, + j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, + j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, + j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, + j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, + j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, + j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, + j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, + j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, + j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; + var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, + x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, + x15 = j15, u; -/***/ }), -/* 10 */ -/***/ (function(module, exports, __webpack_require__) { + for (var i = 0; i < 20; i += 2) { + u = x0 + x12 | 0; + x4 ^= u<<7 | u>>>(32-7); + u = x4 + x0 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x4 | 0; + x12 ^= u<<13 | u>>>(32-13); + u = x12 + x8 | 0; + x0 ^= u<<18 | u>>>(32-18); -"use strict"; + u = x5 + x1 | 0; + x9 ^= u<<7 | u>>>(32-7); + u = x9 + x5 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x9 | 0; + x1 ^= u<<13 | u>>>(32-13); + u = x1 + x13 | 0; + x5 ^= u<<18 | u>>>(32-18); -exports.__esModule = true; -var urlStore = { - baseUrl: "https://pusher.com", - urls: { - authenticationEndpoint: { - path: "/docs/authenticating_users", - }, - javascriptQuickStart: { - path: "/docs/javascript_quick_start" - }, - triggeringClientEvents: { - path: "/docs/client_api_guide/client_events#trigger-events" - } - } -}; -var buildLogSuffix = function (key) { - var urlPrefix = "See:"; - var urlObj = urlStore.urls[key]; - if (!urlObj) - return ""; - var url; - if (urlObj.fullUrl) { - url = urlObj.fullUrl; - } - else if (urlObj.path) { - url = urlStore.baseUrl + urlObj.path; - } - if (!url) - return ""; - return urlPrefix + " " + url; -}; -exports["default"] = { buildLogSuffix: buildLogSuffix }; + u = x10 + x6 | 0; + x14 ^= u<<7 | u>>>(32-7); + u = x14 + x10 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x14 | 0; + x6 ^= u<<13 | u>>>(32-13); + u = x6 + x2 | 0; + x10 ^= u<<18 | u>>>(32-18); + u = x15 + x11 | 0; + x3 ^= u<<7 | u>>>(32-7); + u = x3 + x15 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x3 | 0; + x11 ^= u<<13 | u>>>(32-13); + u = x11 + x7 | 0; + x15 ^= u<<18 | u>>>(32-18); -/***/ }), -/* 11 */ -/***/ (function(module, exports, __webpack_require__) { + u = x0 + x3 | 0; + x1 ^= u<<7 | u>>>(32-7); + u = x1 + x0 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x1 | 0; + x3 ^= u<<13 | u>>>(32-13); + u = x3 + x2 | 0; + x0 ^= u<<18 | u>>>(32-18); -"use strict"; + u = x5 + x4 | 0; + x6 ^= u<<7 | u>>>(32-7); + u = x6 + x5 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x6 | 0; + x4 ^= u<<13 | u>>>(32-13); + u = x4 + x7 | 0; + x5 ^= u<<18 | u>>>(32-18); -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var Collections = __webpack_require__(0); -var dispatcher_1 = __webpack_require__(4); -var timeline_1 = __webpack_require__(56); -var level_1 = __webpack_require__(15); -var strategy_builder_1 = __webpack_require__(57); -var timers_1 = __webpack_require__(5); -var defaults_1 = __webpack_require__(8); -var DefaultConfig = __webpack_require__(59); -var logger_1 = __webpack_require__(3); -var factory_1 = __webpack_require__(6); -var url_store_1 = __webpack_require__(10); -var Pusher = (function () { - function Pusher(app_key, options) { - var _this = this; - checkAppKey(app_key); - options = options || {}; - if (!options.cluster && !(options.wsHost || options.httpHost)) { - var suffix = url_store_1["default"].buildLogSuffix("javascriptQuickStart"); - logger_1["default"].warn("You should always specify a cluster when connecting. " + suffix); - } - this.key = app_key; - this.config = Collections.extend(DefaultConfig.getGlobalConfig(), options.cluster ? DefaultConfig.getClusterConfig(options.cluster) : {}, options); - this.channels = factory_1["default"].createChannels(); - this.global_emitter = new dispatcher_1["default"](); - this.sessionID = Math.floor(Math.random() * 1000000000); - this.timeline = new timeline_1["default"](this.key, this.sessionID, { - cluster: this.config.cluster, - features: Pusher.getClientFeatures(), - params: this.config.timelineParams || {}, - limit: 50, - level: level_1["default"].INFO, - version: defaults_1["default"].VERSION - }); - if (!this.config.disableStats) { - this.timelineSender = factory_1["default"].createTimelineSender(this.timeline, { - host: this.config.statsHost, - path: "/timeline/v2/" + runtime_1["default"].TimelineTransport.name - }); - } - var getStrategy = function (options) { - var config = Collections.extend({}, _this.config, options); - return runtime_1["default"].getDefaultStrategy(config, strategy_builder_1.defineTransport); - }; - this.connection = factory_1["default"].createConnectionManager(this.key, Collections.extend({ getStrategy: getStrategy, - timeline: this.timeline, - activityTimeout: this.config.activity_timeout, - pongTimeout: this.config.pong_timeout, - unavailableTimeout: this.config.unavailable_timeout - }, this.config, { useTLS: this.shouldUseTLS() })); - this.connection.bind('connected', function () { - _this.subscribeAll(); - if (_this.timelineSender) { - _this.timelineSender.send(_this.connection.isUsingTLS()); - } - }); - this.connection.bind('message', function (event) { - var eventName = event.event; - var internal = (eventName.indexOf('pusher_internal:') === 0); - if (event.channel) { - var channel = _this.channel(event.channel); - if (channel) { - channel.handleEvent(event); - } - } - if (!internal) { - _this.global_emitter.emit(event.event, event.data); - } - }); - this.connection.bind('connecting', function () { - _this.channels.disconnect(); - }); - this.connection.bind('disconnected', function () { - _this.channels.disconnect(); - }); - this.connection.bind('error', function (err) { - logger_1["default"].warn('Error', err); - }); - Pusher.instances.push(this); - this.timeline.info({ instances: Pusher.instances.length }); - if (Pusher.isReady) { - this.connect(); - } - } - Pusher.ready = function () { - Pusher.isReady = true; - for (var i = 0, l = Pusher.instances.length; i < l; i++) { - Pusher.instances[i].connect(); - } - }; - Pusher.log = function (message) { - if (Pusher.logToConsole && self.console && self.console.log) { - self.console.log(message); - } - }; - Pusher.getClientFeatures = function () { - return Collections.keys(Collections.filterObject({ "ws": runtime_1["default"].Transports.ws }, function (t) { return t.isSupported({}); })); - }; - Pusher.prototype.channel = function (name) { - return this.channels.find(name); - }; - Pusher.prototype.allChannels = function () { - return this.channels.all(); - }; - Pusher.prototype.connect = function () { - this.connection.connect(); - if (this.timelineSender) { - if (!this.timelineSenderTimer) { - var usingTLS = this.connection.isUsingTLS(); - var timelineSender = this.timelineSender; - this.timelineSenderTimer = new timers_1.PeriodicTimer(60000, function () { - timelineSender.send(usingTLS); - }); - } - } - }; - Pusher.prototype.disconnect = function () { - this.connection.disconnect(); - if (this.timelineSenderTimer) { - this.timelineSenderTimer.ensureAborted(); - this.timelineSenderTimer = null; - } - }; - Pusher.prototype.bind = function (event_name, callback, context) { - this.global_emitter.bind(event_name, callback, context); - return this; - }; - Pusher.prototype.unbind = function (event_name, callback, context) { - this.global_emitter.unbind(event_name, callback, context); - return this; - }; - Pusher.prototype.bind_global = function (callback) { - this.global_emitter.bind_global(callback); - return this; - }; - Pusher.prototype.unbind_global = function (callback) { - this.global_emitter.unbind_global(callback); - return this; - }; - Pusher.prototype.unbind_all = function (callback) { - this.global_emitter.unbind_all(); - return this; - }; - Pusher.prototype.subscribeAll = function () { - var channelName; - for (channelName in this.channels.channels) { - if (this.channels.channels.hasOwnProperty(channelName)) { - this.subscribe(channelName); - } - } - }; - Pusher.prototype.subscribe = function (channel_name) { - var channel = this.channels.add(channel_name, this); - if (channel.subscriptionPending && channel.subscriptionCancelled) { - channel.reinstateSubscription(); - } - else if (!channel.subscriptionPending && this.connection.state === "connected") { - channel.subscribe(); - } - return channel; - }; - Pusher.prototype.unsubscribe = function (channel_name) { - var channel = this.channels.find(channel_name); - if (channel && channel.subscriptionPending) { - channel.cancelSubscription(); - } - else { - channel = this.channels.remove(channel_name); - if (channel && this.connection.state === "connected") { - channel.unsubscribe(); - } - } - }; - Pusher.prototype.send_event = function (event_name, data, channel) { - return this.connection.send_event(event_name, data, channel); - }; - Pusher.prototype.shouldUseTLS = function () { - if (runtime_1["default"].getProtocol() === "https:") { - return true; - } - else if (this.config.forceTLS === true) { - return true; - } - else { - return Boolean(this.config.encrypted); - } - }; - Pusher.instances = []; - Pusher.isReady = false; - Pusher.logToConsole = false; - Pusher.Runtime = runtime_1["default"]; - Pusher.ScriptReceivers = runtime_1["default"].ScriptReceivers; - Pusher.DependenciesReceivers = runtime_1["default"].DependenciesReceivers; - Pusher.auth_callbacks = runtime_1["default"].auth_callbacks; - return Pusher; -}()); -exports["default"] = Pusher; -function checkAppKey(key) { - if (key === null || key === undefined) { - throw "You must pass your app key when you instantiate Pusher."; - } -} -runtime_1["default"].setup(Pusher); + u = x10 + x9 | 0; + x11 ^= u<<7 | u>>>(32-7); + u = x11 + x10 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x11 | 0; + x9 ^= u<<13 | u>>>(32-13); + u = x9 + x8 | 0; + x10 ^= u<<18 | u>>>(32-18); + u = x15 + x14 | 0; + x12 ^= u<<7 | u>>>(32-7); + u = x12 + x15 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x12 | 0; + x14 ^= u<<13 | u>>>(32-13); + u = x14 + x13 | 0; + x15 ^= u<<18 | u>>>(32-18); + } -/***/ }), -/* 12 */ -/***/ (function(module, exports, __webpack_require__) { + o[ 0] = x0 >>> 0 & 0xff; + o[ 1] = x0 >>> 8 & 0xff; + o[ 2] = x0 >>> 16 & 0xff; + o[ 3] = x0 >>> 24 & 0xff; -"use strict"; + o[ 4] = x5 >>> 0 & 0xff; + o[ 5] = x5 >>> 8 & 0xff; + o[ 6] = x5 >>> 16 & 0xff; + o[ 7] = x5 >>> 24 & 0xff; -exports.__esModule = true; -exports.decodeMessage = function (messageEvent) { - try { - var messageData = JSON.parse(messageEvent.data); - var pusherEventData = messageData.data; - if (typeof pusherEventData === 'string') { - try { - pusherEventData = JSON.parse(messageData.data); - } - catch (e) { } - } - var pusherEvent = { - event: messageData.event, - channel: messageData.channel, - data: pusherEventData, - }; - if (messageData.user_id) { - pusherEvent.user_id = messageData.user_id; - } - return pusherEvent; - } - catch (e) { - throw { type: 'MessageParseError', error: e, data: messageEvent.data }; - } -}; -exports.encodeMessage = function (event) { - return JSON.stringify(event); -}; -exports.processHandshake = function (messageEvent) { - var message = exports.decodeMessage(messageEvent); - if (message.event === "pusher:connection_established") { - if (!message.data.activity_timeout) { - throw "No activity timeout specified in handshake"; - } - return { - action: "connected", - id: message.data.socket_id, - activityTimeout: message.data.activity_timeout * 1000 - }; - } - else if (message.event === "pusher:error") { - return { - action: this.getCloseAction(message.data), - error: this.getCloseError(message.data) - }; - } - else { - throw "Invalid handshake"; - } -}; -exports.getCloseAction = function (closeEvent) { - if (closeEvent.code < 4000) { - if (closeEvent.code >= 1002 && closeEvent.code <= 1004) { - return "backoff"; - } - else { - return null; - } - } - else if (closeEvent.code === 4000) { - return "tls_only"; - } - else if (closeEvent.code < 4100) { - return "refused"; - } - else if (closeEvent.code < 4200) { - return "backoff"; - } - else if (closeEvent.code < 4300) { - return "retry"; - } - else { - return "refused"; - } -}; -exports.getCloseError = function (closeEvent) { - if (closeEvent.code !== 1000 && closeEvent.code !== 1001) { - return { - type: 'PusherError', - data: { - code: closeEvent.code, - message: closeEvent.reason || closeEvent.message - } - }; - } - else { - return null; - } -}; - - -/***/ }), -/* 13 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; + o[ 8] = x10 >>> 0 & 0xff; + o[ 9] = x10 >>> 8 & 0xff; + o[10] = x10 >>> 16 & 0xff; + o[11] = x10 >>> 24 & 0xff; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var dispatcher_1 = __webpack_require__(4); -var Errors = __webpack_require__(7); -var logger_1 = __webpack_require__(3); -var url_store_1 = __webpack_require__(10); -var Channel = (function (_super) { - __extends(Channel, _super); - function Channel(name, pusher) { - var _this = _super.call(this, function (event, data) { - logger_1["default"].debug('No callbacks on ' + name + ' for ' + event); - }) || this; - _this.name = name; - _this.pusher = pusher; - _this.subscribed = false; - _this.subscriptionPending = false; - _this.subscriptionCancelled = false; - return _this; - } - Channel.prototype.authorize = function (socketId, callback) { - return callback(false, {}); - }; - Channel.prototype.trigger = function (event, data) { - if (event.indexOf("client-") !== 0) { - throw new Errors.BadEventName("Event '" + event + "' does not start with 'client-'"); - } - if (!this.subscribed) { - var suffix = url_store_1["default"].buildLogSuffix("triggeringClientEvents"); - logger_1["default"].warn("Client event triggered before channel 'subscription_succeeded' event . " + suffix); - } - return this.pusher.send_event(event, data, this.name); - }; - Channel.prototype.disconnect = function () { - this.subscribed = false; - this.subscriptionPending = false; - }; - Channel.prototype.handleEvent = function (event) { - var eventName = event.event; - var data = event.data; - if (eventName === "pusher_internal:subscription_succeeded") { - this.handleSubscriptionSucceededEvent(event); - } - else if (eventName.indexOf("pusher_internal:") !== 0) { - var metadata = {}; - this.emit(eventName, data, metadata); - } - }; - Channel.prototype.handleSubscriptionSucceededEvent = function (event) { - this.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } - else { - this.emit("pusher:subscription_succeeded", event.data); - } - }; - Channel.prototype.subscribe = function () { - var _this = this; - if (this.subscribed) { - return; - } - this.subscriptionPending = true; - this.subscriptionCancelled = false; - this.authorize(this.pusher.connection.socket_id, function (error, data) { - if (error) { - _this.emit('pusher:subscription_error', data); - } - else { - _this.pusher.send_event('pusher:subscribe', { - auth: data.auth, - channel_data: data.channel_data, - channel: _this.name - }); - } - }); - }; - Channel.prototype.unsubscribe = function () { - this.subscribed = false; - this.pusher.send_event('pusher:unsubscribe', { - channel: this.name - }); - }; - Channel.prototype.cancelSubscription = function () { - this.subscriptionCancelled = true; - }; - Channel.prototype.reinstateSubscription = function () { - this.subscriptionCancelled = false; - }; - return Channel; -}(dispatcher_1["default"])); -exports["default"] = Channel; + o[12] = x15 >>> 0 & 0xff; + o[13] = x15 >>> 8 & 0xff; + o[14] = x15 >>> 16 & 0xff; + o[15] = x15 >>> 24 & 0xff; + o[16] = x6 >>> 0 & 0xff; + o[17] = x6 >>> 8 & 0xff; + o[18] = x6 >>> 16 & 0xff; + o[19] = x6 >>> 24 & 0xff; -/***/ }), -/* 14 */ -/***/ (function(module, exports, __webpack_require__) { + o[20] = x7 >>> 0 & 0xff; + o[21] = x7 >>> 8 & 0xff; + o[22] = x7 >>> 16 & 0xff; + o[23] = x7 >>> 24 & 0xff; -"use strict"; + o[24] = x8 >>> 0 & 0xff; + o[25] = x8 >>> 8 & 0xff; + o[26] = x8 >>> 16 & 0xff; + o[27] = x8 >>> 24 & 0xff; -exports.__esModule = true; -var Collections = __webpack_require__(0); -var util_1 = __webpack_require__(2); -var timers_1 = __webpack_require__(5); -var SequentialStrategy = (function () { - function SequentialStrategy(strategies, options) { - this.strategies = strategies; - this.loop = Boolean(options.loop); - this.failFast = Boolean(options.failFast); - this.timeout = options.timeout; - this.timeoutLimit = options.timeoutLimit; - } - SequentialStrategy.prototype.isSupported = function () { - return Collections.any(this.strategies, util_1["default"].method("isSupported")); - }; - SequentialStrategy.prototype.connect = function (minPriority, callback) { - var _this = this; - var strategies = this.strategies; - var current = 0; - var timeout = this.timeout; - var runner = null; - var tryNextStrategy = function (error, handshake) { - if (handshake) { - callback(null, handshake); - } - else { - current = current + 1; - if (_this.loop) { - current = current % strategies.length; - } - if (current < strategies.length) { - if (timeout) { - timeout = timeout * 2; - if (_this.timeoutLimit) { - timeout = Math.min(timeout, _this.timeoutLimit); - } - } - runner = _this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: _this.failFast }, tryNextStrategy); - } - else { - callback(true); - } - } - }; - runner = this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: this.failFast }, tryNextStrategy); - return { - abort: function () { - runner.abort(); - }, - forceMinPriority: function (p) { - minPriority = p; - if (runner) { - runner.forceMinPriority(p); - } - } - }; - }; - SequentialStrategy.prototype.tryStrategy = function (strategy, minPriority, options, callback) { - var timer = null; - var runner = null; - if (options.timeout > 0) { - timer = new timers_1.OneOffTimer(options.timeout, function () { - runner.abort(); - callback(true); - }); - } - runner = strategy.connect(minPriority, function (error, handshake) { - if (error && timer && timer.isRunning() && !options.failFast) { - return; - } - if (timer) { - timer.ensureAborted(); - } - callback(error, handshake); - }); - return { - abort: function () { - if (timer) { - timer.ensureAborted(); - } - runner.abort(); - }, - forceMinPriority: function (p) { - runner.forceMinPriority(p); - } - }; - }; - return SequentialStrategy; -}()); -exports["default"] = SequentialStrategy; + o[28] = x9 >>> 0 & 0xff; + o[29] = x9 >>> 8 & 0xff; + o[30] = x9 >>> 16 & 0xff; + o[31] = x9 >>> 24 & 0xff; +} +function crypto_core_salsa20(out,inp,k,c) { + core_salsa20(out,inp,k,c); +} -/***/ }), -/* 15 */ -/***/ (function(module, exports, __webpack_require__) { +function crypto_core_hsalsa20(out,inp,k,c) { + core_hsalsa20(out,inp,k,c); +} -"use strict"; +var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]); + // "expand 32-byte k" -exports.__esModule = true; -var TimelineLevel; -(function (TimelineLevel) { - TimelineLevel[TimelineLevel["ERROR"] = 3] = "ERROR"; - TimelineLevel[TimelineLevel["INFO"] = 6] = "INFO"; - TimelineLevel[TimelineLevel["DEBUG"] = 7] = "DEBUG"; -})(TimelineLevel || (TimelineLevel = {})); -exports["default"] = TimelineLevel; +function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) { + var z = new Uint8Array(16), x = new Uint8Array(64); + var u, i; + for (i = 0; i < 16; i++) z[i] = 0; + for (i = 0; i < 8; i++) z[i] = n[i]; + while (b >= 64) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i]; + u = 1; + for (i = 8; i < 16; i++) { + u = u + (z[i] & 0xff) | 0; + z[i] = u & 0xff; + u >>>= 8; + } + b -= 64; + cpos += 64; + mpos += 64; + } + if (b > 0) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i]; + } + return 0; +} +function crypto_stream_salsa20(c,cpos,b,n,k) { + var z = new Uint8Array(16), x = new Uint8Array(64); + var u, i; + for (i = 0; i < 16; i++) z[i] = 0; + for (i = 0; i < 8; i++) z[i] = n[i]; + while (b >= 64) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < 64; i++) c[cpos+i] = x[i]; + u = 1; + for (i = 8; i < 16; i++) { + u = u + (z[i] & 0xff) | 0; + z[i] = u & 0xff; + u >>>= 8; + } + b -= 64; + cpos += 64; + } + if (b > 0) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < b; i++) c[cpos+i] = x[i]; + } + return 0; +} -/***/ }), -/* 16 */ -/***/ (function(module, exports, __webpack_require__) { +function crypto_stream(c,cpos,d,n,k) { + var s = new Uint8Array(32); + crypto_core_hsalsa20(s,n,k,sigma); + var sn = new Uint8Array(8); + for (var i = 0; i < 8; i++) sn[i] = n[i+16]; + return crypto_stream_salsa20(c,cpos,d,sn,s); +} -"use strict"; +function crypto_stream_xor(c,cpos,m,mpos,d,n,k) { + var s = new Uint8Array(32); + crypto_core_hsalsa20(s,n,k,sigma); + var sn = new Uint8Array(8); + for (var i = 0; i < 8; i++) sn[i] = n[i+16]; + return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s); +} -exports.__esModule = true; -var pusher_1 = __webpack_require__(11); -module.exports = pusher_1["default"]; +/* +* Port of Andrew Moon's Poly1305-donna-16. Public domain. +* https://github.com/floodyberry/poly1305-donna +*/ +var poly1305 = function(key) { + this.buffer = new Uint8Array(16); + this.r = new Uint16Array(10); + this.h = new Uint16Array(10); + this.pad = new Uint16Array(8); + this.leftover = 0; + this.fin = 0; -/***/ }), -/* 17 */ -/***/ (function(module, exports, __webpack_require__) { + var t0, t1, t2, t3, t4, t5, t6, t7; -"use strict"; + t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff; + t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff; + t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03; + t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff; + t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff; + this.r[5] = ((t4 >>> 1)) & 0x1ffe; + t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff; + t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81; + t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff; + this.r[9] = ((t7 >>> 5)) & 0x007f; -exports.__esModule = true; -var Collections = __webpack_require__(0); -var transports_1 = __webpack_require__(20); -var default_strategy_1 = __webpack_require__(25); -var transport_connection_initializer_1 = __webpack_require__(45); -var http_1 = __webpack_require__(46); -var Isomorphic = { - getDefaultStrategy: default_strategy_1["default"], - Transports: transports_1["default"], - transportConnectionInitializer: transport_connection_initializer_1["default"], - HTTPFactory: http_1["default"], - setup: function (PusherClass) { - PusherClass.ready(); - }, - getLocalStorage: function () { - return undefined; - }, - getClientFeatures: function () { - return Collections.keys(Collections.filterObject({ "ws": transports_1["default"].ws }, function (t) { return t.isSupported({}); })); - }, - getProtocol: function () { - return "http:"; - }, - isXHRSupported: function () { - return true; - }, - createSocketRequest: function (method, url) { - if (this.isXHRSupported()) { - return this.HTTPFactory.createXHR(method, url); - } - else { - throw "Cross-origin HTTP requests are not supported"; - } - }, - createXHR: function () { - var Constructor = this.getXHRAPI(); - return new Constructor(); - }, - createWebSocket: function (url) { - var Constructor = this.getWebSocketAPI(); - return new Constructor(url); - }, - addUnloadListener: function (listener) { }, - removeUnloadListener: function (listener) { } + this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8; + this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8; + this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8; + this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8; + this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8; + this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8; + this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8; + this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8; }; -exports["default"] = Isomorphic; - - -/***/ }), -/* 18 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -exports.__esModule = true; -function encode(s) { - return btoa(utob(s)); -} -exports["default"] = encode; -var fromCharCode = String.fromCharCode; -var b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; -var b64tab = {}; -for (var i = 0, l = b64chars.length; i < l; i++) { - b64tab[b64chars.charAt(i)] = i; -} -var cb_utob = function (c) { - var cc = c.charCodeAt(0); - return cc < 0x80 ? c - : cc < 0x800 ? fromCharCode(0xc0 | (cc >>> 6)) + - fromCharCode(0x80 | (cc & 0x3f)) - : fromCharCode(0xe0 | ((cc >>> 12) & 0x0f)) + - fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) + - fromCharCode(0x80 | (cc & 0x3f)); -}; -var utob = function (u) { - return u.replace(/[^\x00-\x7F]/g, cb_utob); -}; -var cb_encode = function (ccc) { - var padlen = [0, 2, 1][ccc.length % 3]; - var ord = ccc.charCodeAt(0) << 16 - | ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8) - | ((ccc.length > 2 ? ccc.charCodeAt(2) : 0)); - var chars = [ - b64chars.charAt(ord >>> 18), - b64chars.charAt((ord >>> 12) & 63), - padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63), - padlen >= 1 ? '=' : b64chars.charAt(ord & 63) - ]; - return chars.join(''); -}; -var btoa = self.btoa || function (b) { - return b.replace(/[\s\S]{1,3}/g, cb_encode); -}; +poly1305.prototype.blocks = function(m, mpos, bytes) { + var hibit = this.fin ? 0 : (1 << 11); + var t0, t1, t2, t3, t4, t5, t6, t7, c; + var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9; + var h0 = this.h[0], + h1 = this.h[1], + h2 = this.h[2], + h3 = this.h[3], + h4 = this.h[4], + h5 = this.h[5], + h6 = this.h[6], + h7 = this.h[7], + h8 = this.h[8], + h9 = this.h[9]; -/***/ }), -/* 19 */ -/***/ (function(module, exports, __webpack_require__) { + var r0 = this.r[0], + r1 = this.r[1], + r2 = this.r[2], + r3 = this.r[3], + r4 = this.r[4], + r5 = this.r[5], + r6 = this.r[6], + r7 = this.r[7], + r8 = this.r[8], + r9 = this.r[9]; -"use strict"; + while (bytes >= 16) { + t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff; + t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff; + t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff; + t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff; + t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff; + h5 += ((t4 >>> 1)) & 0x1fff; + t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff; + t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff; + t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff; + h9 += ((t7 >>> 5)) | hibit; -exports.__esModule = true; -var Timer = (function () { - function Timer(set, clear, delay, callback) { - var _this = this; - this.clear = clear; - this.timer = set(function () { - if (_this.timer) { - _this.timer = callback(_this.timer); - } - }, delay); - } - Timer.prototype.isRunning = function () { - return this.timer !== null; - }; - Timer.prototype.ensureAborted = function () { - if (this.timer) { - this.clear(this.timer); - this.timer = null; - } - }; - return Timer; -}()); -exports["default"] = Timer; + c = 0; + d0 = c; + d0 += h0 * r0; + d0 += h1 * (5 * r9); + d0 += h2 * (5 * r8); + d0 += h3 * (5 * r7); + d0 += h4 * (5 * r6); + c = (d0 >>> 13); d0 &= 0x1fff; + d0 += h5 * (5 * r5); + d0 += h6 * (5 * r4); + d0 += h7 * (5 * r3); + d0 += h8 * (5 * r2); + d0 += h9 * (5 * r1); + c += (d0 >>> 13); d0 &= 0x1fff; -/***/ }), -/* 20 */ -/***/ (function(module, exports, __webpack_require__) { + d1 = c; + d1 += h0 * r1; + d1 += h1 * r0; + d1 += h2 * (5 * r9); + d1 += h3 * (5 * r8); + d1 += h4 * (5 * r7); + c = (d1 >>> 13); d1 &= 0x1fff; + d1 += h5 * (5 * r6); + d1 += h6 * (5 * r5); + d1 += h7 * (5 * r4); + d1 += h8 * (5 * r3); + d1 += h9 * (5 * r2); + c += (d1 >>> 13); d1 &= 0x1fff; -"use strict"; + d2 = c; + d2 += h0 * r2; + d2 += h1 * r1; + d2 += h2 * r0; + d2 += h3 * (5 * r9); + d2 += h4 * (5 * r8); + c = (d2 >>> 13); d2 &= 0x1fff; + d2 += h5 * (5 * r7); + d2 += h6 * (5 * r6); + d2 += h7 * (5 * r5); + d2 += h8 * (5 * r4); + d2 += h9 * (5 * r3); + c += (d2 >>> 13); d2 &= 0x1fff; -exports.__esModule = true; -var URLSchemes = __webpack_require__(21); -var transport_1 = __webpack_require__(22); -var Collections = __webpack_require__(0); -var runtime_1 = __webpack_require__(1); -var WSTransport = new transport_1["default"]({ - urls: URLSchemes.ws, - handlesActivityChecks: false, - supportsPing: false, - isInitialized: function () { - return Boolean(runtime_1["default"].getWebSocketAPI()); - }, - isSupported: function () { - return Boolean(runtime_1["default"].getWebSocketAPI()); - }, - getSocket: function (url) { - return runtime_1["default"].createWebSocket(url); - } -}); -var httpConfiguration = { - urls: URLSchemes.http, - handlesActivityChecks: false, - supportsPing: true, - isInitialized: function () { - return true; - } -}; -exports.streamingConfiguration = Collections.extend({ getSocket: function (url) { - return runtime_1["default"].HTTPFactory.createStreamingSocket(url); - } -}, httpConfiguration); -exports.pollingConfiguration = Collections.extend({ getSocket: function (url) { - return runtime_1["default"].HTTPFactory.createPollingSocket(url); - } -}, httpConfiguration); -var xhrConfiguration = { - isSupported: function () { - return runtime_1["default"].isXHRSupported(); - } -}; -var XHRStreamingTransport = new transport_1["default"](Collections.extend({}, exports.streamingConfiguration, xhrConfiguration)); -var XHRPollingTransport = new transport_1["default"](Collections.extend({}, exports.pollingConfiguration, xhrConfiguration)); -var Transports = { - ws: WSTransport, - xhr_streaming: XHRStreamingTransport, - xhr_polling: XHRPollingTransport -}; -exports["default"] = Transports; + d3 = c; + d3 += h0 * r3; + d3 += h1 * r2; + d3 += h2 * r1; + d3 += h3 * r0; + d3 += h4 * (5 * r9); + c = (d3 >>> 13); d3 &= 0x1fff; + d3 += h5 * (5 * r8); + d3 += h6 * (5 * r7); + d3 += h7 * (5 * r6); + d3 += h8 * (5 * r5); + d3 += h9 * (5 * r4); + c += (d3 >>> 13); d3 &= 0x1fff; + d4 = c; + d4 += h0 * r4; + d4 += h1 * r3; + d4 += h2 * r2; + d4 += h3 * r1; + d4 += h4 * r0; + c = (d4 >>> 13); d4 &= 0x1fff; + d4 += h5 * (5 * r9); + d4 += h6 * (5 * r8); + d4 += h7 * (5 * r7); + d4 += h8 * (5 * r6); + d4 += h9 * (5 * r5); + c += (d4 >>> 13); d4 &= 0x1fff; -/***/ }), -/* 21 */ -/***/ (function(module, exports, __webpack_require__) { + d5 = c; + d5 += h0 * r5; + d5 += h1 * r4; + d5 += h2 * r3; + d5 += h3 * r2; + d5 += h4 * r1; + c = (d5 >>> 13); d5 &= 0x1fff; + d5 += h5 * r0; + d5 += h6 * (5 * r9); + d5 += h7 * (5 * r8); + d5 += h8 * (5 * r7); + d5 += h9 * (5 * r6); + c += (d5 >>> 13); d5 &= 0x1fff; -"use strict"; + d6 = c; + d6 += h0 * r6; + d6 += h1 * r5; + d6 += h2 * r4; + d6 += h3 * r3; + d6 += h4 * r2; + c = (d6 >>> 13); d6 &= 0x1fff; + d6 += h5 * r1; + d6 += h6 * r0; + d6 += h7 * (5 * r9); + d6 += h8 * (5 * r8); + d6 += h9 * (5 * r7); + c += (d6 >>> 13); d6 &= 0x1fff; -exports.__esModule = true; -var defaults_1 = __webpack_require__(8); -function getGenericURL(baseScheme, params, path) { - var scheme = baseScheme + (params.useTLS ? "s" : ""); - var host = params.useTLS ? params.hostTLS : params.hostNonTLS; - return scheme + "://" + host + path; -} -function getGenericPath(key, queryString) { - var path = "/app/" + key; - var query = "?protocol=" + defaults_1["default"].PROTOCOL + - "&client=js" + - "&version=" + defaults_1["default"].VERSION + - (queryString ? ("&" + queryString) : ""); - return path + query; -} -exports.ws = { - getInitial: function (key, params) { - var path = (params.httpPath || "") + getGenericPath(key, "flash=false"); - return getGenericURL("ws", params, path); - } -}; -exports.http = { - getInitial: function (key, params) { - var path = (params.httpPath || "/pusher") + getGenericPath(key); - return getGenericURL("http", params, path); - } -}; -exports.sockjs = { - getInitial: function (key, params) { - return getGenericURL("http", params, params.httpPath || "/pusher"); - }, - getPath: function (key, params) { - return getGenericPath(key); - } -}; + d7 = c; + d7 += h0 * r7; + d7 += h1 * r6; + d7 += h2 * r5; + d7 += h3 * r4; + d7 += h4 * r3; + c = (d7 >>> 13); d7 &= 0x1fff; + d7 += h5 * r2; + d7 += h6 * r1; + d7 += h7 * r0; + d7 += h8 * (5 * r9); + d7 += h9 * (5 * r8); + c += (d7 >>> 13); d7 &= 0x1fff; + d8 = c; + d8 += h0 * r8; + d8 += h1 * r7; + d8 += h2 * r6; + d8 += h3 * r5; + d8 += h4 * r4; + c = (d8 >>> 13); d8 &= 0x1fff; + d8 += h5 * r3; + d8 += h6 * r2; + d8 += h7 * r1; + d8 += h8 * r0; + d8 += h9 * (5 * r9); + c += (d8 >>> 13); d8 &= 0x1fff; -/***/ }), -/* 22 */ -/***/ (function(module, exports, __webpack_require__) { + d9 = c; + d9 += h0 * r9; + d9 += h1 * r8; + d9 += h2 * r7; + d9 += h3 * r6; + d9 += h4 * r5; + c = (d9 >>> 13); d9 &= 0x1fff; + d9 += h5 * r4; + d9 += h6 * r3; + d9 += h7 * r2; + d9 += h8 * r1; + d9 += h9 * r0; + c += (d9 >>> 13); d9 &= 0x1fff; -"use strict"; + c = (((c << 2) + c)) | 0; + c = (c + d0) | 0; + d0 = c & 0x1fff; + c = (c >>> 13); + d1 += c; -exports.__esModule = true; -var transport_connection_1 = __webpack_require__(23); -var Transport = (function () { - function Transport(hooks) { - this.hooks = hooks; - } - Transport.prototype.isSupported = function (environment) { - return this.hooks.isSupported(environment); - }; - Transport.prototype.createConnection = function (name, priority, key, options) { - return new transport_connection_1["default"](this.hooks, name, priority, key, options); - }; - return Transport; -}()); -exports["default"] = Transport; + h0 = d0; + h1 = d1; + h2 = d2; + h3 = d3; + h4 = d4; + h5 = d5; + h6 = d6; + h7 = d7; + h8 = d8; + h9 = d9; + mpos += 16; + bytes -= 16; + } + this.h[0] = h0; + this.h[1] = h1; + this.h[2] = h2; + this.h[3] = h3; + this.h[4] = h4; + this.h[5] = h5; + this.h[6] = h6; + this.h[7] = h7; + this.h[8] = h8; + this.h[9] = h9; +}; -/***/ }), -/* 23 */ -/***/ (function(module, exports, __webpack_require__) { +poly1305.prototype.finish = function(mac, macpos) { + var g = new Uint16Array(10); + var c, mask, f, i; -"use strict"; + if (this.leftover) { + i = this.leftover; + this.buffer[i++] = 1; + for (; i < 16; i++) this.buffer[i] = 0; + this.fin = 1; + this.blocks(this.buffer, 0, 16); + } -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var util_1 = __webpack_require__(2); -var Collections = __webpack_require__(0); -var dispatcher_1 = __webpack_require__(4); -var logger_1 = __webpack_require__(3); -var runtime_1 = __webpack_require__(1); -var TransportConnection = (function (_super) { - __extends(TransportConnection, _super); - function TransportConnection(hooks, name, priority, key, options) { - var _this = _super.call(this) || this; - _this.initialize = runtime_1["default"].transportConnectionInitializer; - _this.hooks = hooks; - _this.name = name; - _this.priority = priority; - _this.key = key; - _this.options = options; - _this.state = "new"; - _this.timeline = options.timeline; - _this.activityTimeout = options.activityTimeout; - _this.id = _this.timeline.generateUniqueID(); - return _this; - } - TransportConnection.prototype.handlesActivityChecks = function () { - return Boolean(this.hooks.handlesActivityChecks); - }; - TransportConnection.prototype.supportsPing = function () { - return Boolean(this.hooks.supportsPing); - }; - TransportConnection.prototype.connect = function () { - var _this = this; - if (this.socket || this.state !== "initialized") { - return false; - } - var url = this.hooks.urls.getInitial(this.key, this.options); - try { - this.socket = this.hooks.getSocket(url, this.options); - } - catch (e) { - util_1["default"].defer(function () { - _this.onError(e); - _this.changeState("closed"); - }); - return false; - } - this.bindListeners(); - logger_1["default"].debug("Connecting", { transport: this.name, url: url }); - this.changeState("connecting"); - return true; - }; - TransportConnection.prototype.close = function () { - if (this.socket) { - this.socket.close(); - return true; - } - else { - return false; - } - }; - TransportConnection.prototype.send = function (data) { - var _this = this; - if (this.state === "open") { - util_1["default"].defer(function () { - if (_this.socket) { - _this.socket.send(data); - } - }); - return true; - } - else { - return false; - } - }; - TransportConnection.prototype.ping = function () { - if (this.state === "open" && this.supportsPing()) { - this.socket.ping(); - } - }; - TransportConnection.prototype.onOpen = function () { - if (this.hooks.beforeOpen) { - this.hooks.beforeOpen(this.socket, this.hooks.urls.getPath(this.key, this.options)); - } - this.changeState("open"); - this.socket.onopen = undefined; - }; - TransportConnection.prototype.onError = function (error) { - this.emit("error", { type: 'WebSocketError', error: error }); - this.timeline.error(this.buildTimelineMessage({ error: error.toString() })); - }; - TransportConnection.prototype.onClose = function (closeEvent) { - if (closeEvent) { - this.changeState("closed", { - code: closeEvent.code, - reason: closeEvent.reason, - wasClean: closeEvent.wasClean - }); - } - else { - this.changeState("closed"); - } - this.unbindListeners(); - this.socket = undefined; - }; - TransportConnection.prototype.onMessage = function (message) { - this.emit("message", message); - }; - TransportConnection.prototype.onActivity = function () { - this.emit("activity"); - }; - TransportConnection.prototype.bindListeners = function () { - var _this = this; - this.socket.onopen = function () { - _this.onOpen(); - }; - this.socket.onerror = function (error) { - _this.onError(error); - }; - this.socket.onclose = function (closeEvent) { - _this.onClose(closeEvent); - }; - this.socket.onmessage = function (message) { - _this.onMessage(message); - }; - if (this.supportsPing()) { - this.socket.onactivity = function () { _this.onActivity(); }; - } - }; - TransportConnection.prototype.unbindListeners = function () { - if (this.socket) { - this.socket.onopen = undefined; - this.socket.onerror = undefined; - this.socket.onclose = undefined; - this.socket.onmessage = undefined; - if (this.supportsPing()) { - this.socket.onactivity = undefined; - } - } - }; - TransportConnection.prototype.changeState = function (state, params) { - this.state = state; - this.timeline.info(this.buildTimelineMessage({ - state: state, - params: params - })); - this.emit(state, params); - }; - TransportConnection.prototype.buildTimelineMessage = function (message) { - return Collections.extend({ cid: this.id }, message); - }; - return TransportConnection; -}(dispatcher_1["default"])); -exports["default"] = TransportConnection; + c = this.h[1] >>> 13; + this.h[1] &= 0x1fff; + for (i = 2; i < 10; i++) { + this.h[i] += c; + c = this.h[i] >>> 13; + this.h[i] &= 0x1fff; + } + this.h[0] += (c * 5); + c = this.h[0] >>> 13; + this.h[0] &= 0x1fff; + this.h[1] += c; + c = this.h[1] >>> 13; + this.h[1] &= 0x1fff; + this.h[2] += c; + g[0] = this.h[0] + 5; + c = g[0] >>> 13; + g[0] &= 0x1fff; + for (i = 1; i < 10; i++) { + g[i] = this.h[i] + c; + c = g[i] >>> 13; + g[i] &= 0x1fff; + } + g[9] -= (1 << 13); -/***/ }), -/* 24 */ -/***/ (function(module, exports, __webpack_require__) { + mask = (c ^ 1) - 1; + for (i = 0; i < 10; i++) g[i] &= mask; + mask = ~mask; + for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]; -"use strict"; + this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff; + this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff; + this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff; + this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff; + this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff; + this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff; + this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff; + this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff; -exports.__esModule = true; -var Collections = __webpack_require__(0); -var CallbackRegistry = (function () { - function CallbackRegistry() { - this._callbacks = {}; - } - CallbackRegistry.prototype.get = function (name) { - return this._callbacks[prefix(name)]; - }; - CallbackRegistry.prototype.add = function (name, callback, context) { - var prefixedEventName = prefix(name); - this._callbacks[prefixedEventName] = this._callbacks[prefixedEventName] || []; - this._callbacks[prefixedEventName].push({ - fn: callback, - context: context - }); - }; - CallbackRegistry.prototype.remove = function (name, callback, context) { - if (!name && !callback && !context) { - this._callbacks = {}; - return; - } - var names = name ? [prefix(name)] : Collections.keys(this._callbacks); - if (callback || context) { - this.removeCallback(names, callback, context); - } - else { - this.removeAllCallbacks(names); - } - }; - CallbackRegistry.prototype.removeCallback = function (names, callback, context) { - Collections.apply(names, function (name) { - this._callbacks[name] = Collections.filter(this._callbacks[name] || [], function (binding) { - return (callback && callback !== binding.fn) || - (context && context !== binding.context); - }); - if (this._callbacks[name].length === 0) { - delete this._callbacks[name]; - } - }, this); - }; - CallbackRegistry.prototype.removeAllCallbacks = function (names) { - Collections.apply(names, function (name) { - delete this._callbacks[name]; - }, this); - }; - return CallbackRegistry; -}()); -exports["default"] = CallbackRegistry; -function prefix(name) { - return "_" + name; -} + f = this.h[0] + this.pad[0]; + this.h[0] = f & 0xffff; + for (i = 1; i < 8; i++) { + f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0; + this.h[i] = f & 0xffff; + } + mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff; + mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff; + mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff; + mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff; + mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff; + mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff; + mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff; + mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff; + mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff; + mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff; + mac[macpos+10] = (this.h[5] >>> 0) & 0xff; + mac[macpos+11] = (this.h[5] >>> 8) & 0xff; + mac[macpos+12] = (this.h[6] >>> 0) & 0xff; + mac[macpos+13] = (this.h[6] >>> 8) & 0xff; + mac[macpos+14] = (this.h[7] >>> 0) & 0xff; + mac[macpos+15] = (this.h[7] >>> 8) & 0xff; +}; -/***/ }), -/* 25 */ -/***/ (function(module, exports, __webpack_require__) { +poly1305.prototype.update = function(m, mpos, bytes) { + var i, want; -"use strict"; + if (this.leftover) { + want = (16 - this.leftover); + if (want > bytes) + want = bytes; + for (i = 0; i < want; i++) + this.buffer[this.leftover + i] = m[mpos+i]; + bytes -= want; + mpos += want; + this.leftover += want; + if (this.leftover < 16) + return; + this.blocks(this.buffer, 0, 16); + this.leftover = 0; + } -exports.__esModule = true; -var Collections = __webpack_require__(0); -var transport_manager_1 = __webpack_require__(26); -var sequential_strategy_1 = __webpack_require__(14); -var best_connected_ever_strategy_1 = __webpack_require__(40); -var cached_strategy_1 = __webpack_require__(41); -var delayed_strategy_1 = __webpack_require__(42); -var if_strategy_1 = __webpack_require__(43); -var first_connected_strategy_1 = __webpack_require__(44); -function testSupportsStrategy(strategy) { - return function () { - return strategy.isSupported(); - }; -} -var getDefaultStrategy = function (config, defineTransport) { - var definedTransports = {}; - function defineTransportStrategy(name, type, priority, options, manager) { - var transport = defineTransport(config, name, type, priority, options, manager); - definedTransports[name] = transport; - return transport; - } - var ws_options = { - hostNonTLS: config.wsHost + ":" + config.wsPort, - hostTLS: config.wsHost + ":" + config.wssPort, - httpPath: config.wsPath - }; - var wss_options = Collections.extend({}, ws_options, { - useTLS: true - }); - var http_options = { - hostNonTLS: config.httpHost + ":" + config.httpPort, - hostTLS: config.httpHost + ":" + config.httpsPort, - httpPath: config.httpPath - }; - var timeouts = { - loop: true, - timeout: 15000, - timeoutLimit: 60000 - }; - var ws_manager = new transport_manager_1["default"]({ - lives: 2, - minPingDelay: 10000, - maxPingDelay: config.activity_timeout - }); - var streaming_manager = new transport_manager_1["default"]({ - lives: 2, - minPingDelay: 10000, - maxPingDelay: config.activity_timeout - }); - var ws_transport = defineTransportStrategy("ws", "ws", 3, ws_options, ws_manager); - var wss_transport = defineTransportStrategy("wss", "ws", 3, wss_options, ws_manager); - var xhr_streaming_transport = defineTransportStrategy("xhr_streaming", "xhr_streaming", 1, http_options, streaming_manager); - var xhr_polling_transport = defineTransportStrategy("xhr_polling", "xhr_polling", 1, http_options); - var ws_loop = new sequential_strategy_1["default"]([ws_transport], timeouts); - var wss_loop = new sequential_strategy_1["default"]([wss_transport], timeouts); - var streaming_loop = new sequential_strategy_1["default"]([xhr_streaming_transport], timeouts); - var polling_loop = new sequential_strategy_1["default"]([xhr_polling_transport], timeouts); - var http_loop = new sequential_strategy_1["default"]([new if_strategy_1["default"](testSupportsStrategy(streaming_loop), new best_connected_ever_strategy_1["default"]([streaming_loop, new delayed_strategy_1["default"](polling_loop, { delay: 4000 })]), polling_loop)], timeouts); - var wsStrategy; - if (config.useTLS) { - wsStrategy = new best_connected_ever_strategy_1["default"]([ws_loop, new delayed_strategy_1["default"](http_loop, { delay: 2000 })]); - } - else { - wsStrategy = new best_connected_ever_strategy_1["default"]([ - ws_loop, - new delayed_strategy_1["default"](wss_loop, { delay: 2000 }), - new delayed_strategy_1["default"](http_loop, { delay: 5000 }) - ]); - } - return new cached_strategy_1["default"](new first_connected_strategy_1["default"](new if_strategy_1["default"](testSupportsStrategy(ws_transport), wsStrategy, http_loop)), definedTransports, { - ttl: 1800000, - timeline: config.timeline, - useTLS: config.useTLS - }); + if (bytes >= 16) { + want = bytes - (bytes % 16); + this.blocks(m, mpos, want); + mpos += want; + bytes -= want; + } + + if (bytes) { + for (i = 0; i < bytes; i++) + this.buffer[this.leftover + i] = m[mpos+i]; + this.leftover += bytes; + } }; -exports["default"] = getDefaultStrategy; +function crypto_onetimeauth(out, outpos, m, mpos, n, k) { + var s = new poly1305(k); + s.update(m, mpos, n); + s.finish(out, outpos); + return 0; +} -/***/ }), -/* 26 */ -/***/ (function(module, exports, __webpack_require__) { +function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) { + var x = new Uint8Array(16); + crypto_onetimeauth(x,0,m,mpos,n,k); + return crypto_verify_16(h,hpos,x,0); +} -"use strict"; +function crypto_secretbox(c,m,d,n,k) { + var i; + if (d < 32) return -1; + crypto_stream_xor(c,0,m,0,d,n,k); + crypto_onetimeauth(c, 16, c, 32, d - 32, c); + for (i = 0; i < 16; i++) c[i] = 0; + return 0; +} -exports.__esModule = true; -var factory_1 = __webpack_require__(6); -var TransportManager = (function () { - function TransportManager(options) { - this.options = options || {}; - this.livesLeft = this.options.lives || Infinity; - } - TransportManager.prototype.getAssistant = function (transport) { - return factory_1["default"].createAssistantToTheTransportManager(this, transport, { - minPingDelay: this.options.minPingDelay, - maxPingDelay: this.options.maxPingDelay - }); - }; - TransportManager.prototype.isAlive = function () { - return this.livesLeft > 0; - }; - TransportManager.prototype.reportDeath = function () { - this.livesLeft -= 1; - }; - return TransportManager; -}()); -exports["default"] = TransportManager; +function crypto_secretbox_open(m,c,d,n,k) { + var i; + var x = new Uint8Array(32); + if (d < 32) return -1; + crypto_stream(x,0,32,n,k); + if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1; + crypto_stream_xor(m,0,c,0,d,n,k); + for (i = 0; i < 32; i++) m[i] = 0; + return 0; +} +function set25519(r, a) { + var i; + for (i = 0; i < 16; i++) r[i] = a[i]|0; +} -/***/ }), -/* 27 */ -/***/ (function(module, exports, __webpack_require__) { +function car25519(o) { + var i, v, c = 1; + for (i = 0; i < 16; i++) { + v = o[i] + c + 65535; + c = Math.floor(v / 65536); + o[i] = v - c * 65536; + } + o[0] += c-1 + 37 * (c-1); +} -"use strict"; +function sel25519(p, q, b) { + var t, c = ~(b-1); + for (var i = 0; i < 16; i++) { + t = c & (p[i] ^ q[i]); + p[i] ^= t; + q[i] ^= t; + } +} -exports.__esModule = true; -var util_1 = __webpack_require__(2); -var Collections = __webpack_require__(0); -var AssistantToTheTransportManager = (function () { - function AssistantToTheTransportManager(manager, transport, options) { - this.manager = manager; - this.transport = transport; - this.minPingDelay = options.minPingDelay; - this.maxPingDelay = options.maxPingDelay; - this.pingDelay = undefined; +function pack25519(o, n) { + var i, j, b; + var m = gf(), t = gf(); + for (i = 0; i < 16; i++) t[i] = n[i]; + car25519(t); + car25519(t); + car25519(t); + for (j = 0; j < 2; j++) { + m[0] = t[0] - 0xffed; + for (i = 1; i < 15; i++) { + m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1); + m[i-1] &= 0xffff; } - AssistantToTheTransportManager.prototype.createConnection = function (name, priority, key, options) { - var _this = this; - options = Collections.extend({}, options, { - activityTimeout: this.pingDelay - }); - var connection = this.transport.createConnection(name, priority, key, options); - var openTimestamp = null; - var onOpen = function () { - connection.unbind("open", onOpen); - connection.bind("closed", onClosed); - openTimestamp = util_1["default"].now(); - }; - var onClosed = function (closeEvent) { - connection.unbind("closed", onClosed); - if (closeEvent.code === 1002 || closeEvent.code === 1003) { - _this.manager.reportDeath(); - } - else if (!closeEvent.wasClean && openTimestamp) { - var lifespan = util_1["default"].now() - openTimestamp; - if (lifespan < 2 * _this.maxPingDelay) { - _this.manager.reportDeath(); - _this.pingDelay = Math.max(lifespan / 2, _this.minPingDelay); - } - } - }; - connection.bind("open", onOpen); - return connection; - }; - AssistantToTheTransportManager.prototype.isSupported = function (environment) { - return this.manager.isAlive() && this.transport.isSupported(environment); - }; - return AssistantToTheTransportManager; -}()); -exports["default"] = AssistantToTheTransportManager; - - -/***/ }), -/* 28 */ -/***/ (function(module, exports, __webpack_require__) { + m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1); + b = (m[15]>>16) & 1; + m[14] &= 0xffff; + sel25519(t, m, 1-b); + } + for (i = 0; i < 16; i++) { + o[2*i] = t[i] & 0xff; + o[2*i+1] = t[i]>>8; + } +} -"use strict"; +function neq25519(a, b) { + var c = new Uint8Array(32), d = new Uint8Array(32); + pack25519(c, a); + pack25519(d, b); + return crypto_verify_32(c, 0, d, 0); +} -exports.__esModule = true; -var Collections = __webpack_require__(0); -var Protocol = __webpack_require__(12); -var connection_1 = __webpack_require__(29); -var Handshake = (function () { - function Handshake(transport, callback) { - this.transport = transport; - this.callback = callback; - this.bindListeners(); - } - Handshake.prototype.close = function () { - this.unbindListeners(); - this.transport.close(); - }; - Handshake.prototype.bindListeners = function () { - var _this = this; - this.onMessage = function (m) { - _this.unbindListeners(); - var result; - try { - result = Protocol.processHandshake(m); - } - catch (e) { - _this.finish("error", { error: e }); - _this.transport.close(); - return; - } - if (result.action === "connected") { - _this.finish("connected", { - connection: new connection_1["default"](result.id, _this.transport), - activityTimeout: result.activityTimeout - }); - } - else { - _this.finish(result.action, { error: result.error }); - _this.transport.close(); - } - }; - this.onClosed = function (closeEvent) { - _this.unbindListeners(); - var action = Protocol.getCloseAction(closeEvent) || "backoff"; - var error = Protocol.getCloseError(closeEvent); - _this.finish(action, { error: error }); - }; - this.transport.bind("message", this.onMessage); - this.transport.bind("closed", this.onClosed); - }; - Handshake.prototype.unbindListeners = function () { - this.transport.unbind("message", this.onMessage); - this.transport.unbind("closed", this.onClosed); - }; - Handshake.prototype.finish = function (action, params) { - this.callback(Collections.extend({ transport: this.transport, action: action }, params)); - }; - return Handshake; -}()); -exports["default"] = Handshake; +function par25519(a) { + var d = new Uint8Array(32); + pack25519(d, a); + return d[0] & 1; +} +function unpack25519(o, n) { + var i; + for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8); + o[15] &= 0x7fff; +} -/***/ }), -/* 29 */ -/***/ (function(module, exports, __webpack_require__) { +function A(o, a, b) { + for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]; +} -"use strict"; +function Z(o, a, b) { + for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]; +} -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var Collections = __webpack_require__(0); -var dispatcher_1 = __webpack_require__(4); -var Protocol = __webpack_require__(12); -var logger_1 = __webpack_require__(3); -var Connection = (function (_super) { - __extends(Connection, _super); - function Connection(id, transport) { - var _this = _super.call(this) || this; - _this.id = id; - _this.transport = transport; - _this.activityTimeout = transport.activityTimeout; - _this.bindListeners(); - return _this; - } - Connection.prototype.handlesActivityChecks = function () { - return this.transport.handlesActivityChecks(); - }; - Connection.prototype.send = function (data) { - return this.transport.send(data); - }; - Connection.prototype.send_event = function (name, data, channel) { - var event = { event: name, data: data }; - if (channel) { - event.channel = channel; - } - logger_1["default"].debug('Event sent', event); - return this.send(Protocol.encodeMessage(event)); - }; - Connection.prototype.ping = function () { - if (this.transport.supportsPing()) { - this.transport.ping(); - } - else { - this.send_event('pusher:ping', {}); - } - }; - Connection.prototype.close = function () { - this.transport.close(); - }; - Connection.prototype.bindListeners = function () { - var _this = this; - var listeners = { - message: function (messageEvent) { - var pusherEvent; - try { - pusherEvent = Protocol.decodeMessage(messageEvent); - } - catch (e) { - _this.emit('error', { - type: 'MessageParseError', - error: e, - data: messageEvent.data - }); - } - if (pusherEvent !== undefined) { - logger_1["default"].debug('Event recd', pusherEvent); - switch (pusherEvent.event) { - case 'pusher:error': - _this.emit('error', { type: 'PusherError', data: pusherEvent.data }); - break; - case 'pusher:ping': - _this.emit("ping"); - break; - case 'pusher:pong': - _this.emit("pong"); - break; - } - _this.emit('message', pusherEvent); - } - }, - activity: function () { - _this.emit("activity"); - }, - error: function (error) { - _this.emit("error", { type: "WebSocketError", error: error }); - }, - closed: function (closeEvent) { - unbindListeners(); - if (closeEvent && closeEvent.code) { - _this.handleCloseEvent(closeEvent); - } - _this.transport = null; - _this.emit("closed"); - } - }; - var unbindListeners = function () { - Collections.objectApply(listeners, function (listener, event) { - _this.transport.unbind(event, listener); - }); - }; - Collections.objectApply(listeners, function (listener, event) { - _this.transport.bind(event, listener); - }); - }; - Connection.prototype.handleCloseEvent = function (closeEvent) { - var action = Protocol.getCloseAction(closeEvent); - var error = Protocol.getCloseError(closeEvent); - if (error) { - this.emit('error', error); - } - if (action) { - this.emit(action, { action: action, error: error }); - } - }; - return Connection; -}(dispatcher_1["default"])); -exports["default"] = Connection; - - -/***/ }), -/* 30 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var PusherAuthorizer = (function () { - function PusherAuthorizer(channel, options) { - this.channel = channel; - var authTransport = options.authTransport; - if (typeof runtime_1["default"].getAuthorizers()[authTransport] === "undefined") { - throw "'" + authTransport + "' is not a recognized auth transport"; - } - this.type = authTransport; - this.options = options; - this.authOptions = (options || {}).auth || {}; - } - PusherAuthorizer.prototype.composeQuery = function (socketId) { - var query = 'socket_id=' + encodeURIComponent(socketId) + - '&channel_name=' + encodeURIComponent(this.channel.name); - for (var i in this.authOptions.params) { - query += "&" + encodeURIComponent(i) + "=" + encodeURIComponent(this.authOptions.params[i]); - } - return query; - }; - PusherAuthorizer.prototype.authorize = function (socketId, callback) { - PusherAuthorizer.authorizers = PusherAuthorizer.authorizers || runtime_1["default"].getAuthorizers(); - return PusherAuthorizer.authorizers[this.type].call(this, runtime_1["default"], socketId, callback); - }; - return PusherAuthorizer; -}()); -exports["default"] = PusherAuthorizer; - - -/***/ }), -/* 31 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var TimelineSender = (function () { - function TimelineSender(timeline, options) { - this.timeline = timeline; - this.options = options || {}; - } - TimelineSender.prototype.send = function (useTLS, callback) { - if (this.timeline.isEmpty()) { - return; - } - this.timeline.send(runtime_1["default"].TimelineTransport.getAgent(this, useTLS), callback); - }; - return TimelineSender; -}()); -exports["default"] = TimelineSender; - - -/***/ }), -/* 32 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var private_channel_1 = __webpack_require__(9); -var logger_1 = __webpack_require__(3); -var members_1 = __webpack_require__(33); -var url_store_1 = __webpack_require__(10); -var PresenceChannel = (function (_super) { - __extends(PresenceChannel, _super); - function PresenceChannel(name, pusher) { - var _this = _super.call(this, name, pusher) || this; - _this.members = new members_1["default"](); - return _this; - } - PresenceChannel.prototype.authorize = function (socketId, callback) { - var _this = this; - _super.prototype.authorize.call(this, socketId, function (error, authData) { - if (!error) { - if (authData.channel_data === undefined) { - var suffix = url_store_1["default"].buildLogSuffix("authenticationEndpoint"); - logger_1["default"].warn("Invalid auth response for channel '" + _this.name + "'," + - ("expected 'channel_data' field. " + suffix)); - callback("Invalid auth response"); - return; - } - var channelData = JSON.parse(authData.channel_data); - _this.members.setMyID(channelData.user_id); - } - callback(error, authData); - }); - }; - PresenceChannel.prototype.handleEvent = function (event) { - var eventName = event.event; - if (eventName.indexOf("pusher_internal:") === 0) { - this.handleInternalEvent(event); - } - else { - var data = event.data; - var metadata = {}; - if (event.user_id) { - metadata.user_id = event.user_id; - } - this.emit(eventName, data, metadata); - } - }; - PresenceChannel.prototype.handleInternalEvent = function (event) { - var eventName = event.event; - var data = event.data; - switch (eventName) { - case "pusher_internal:subscription_succeeded": - this.handleSubscriptionSucceededEvent(event); - break; - case "pusher_internal:member_added": - var addedMember = this.members.addMember(data); - this.emit('pusher:member_added', addedMember); - break; - case "pusher_internal:member_removed": - var removedMember = this.members.removeMember(data); - if (removedMember) { - this.emit('pusher:member_removed', removedMember); - } - break; - } - }; - PresenceChannel.prototype.handleSubscriptionSucceededEvent = function (event) { - this.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } - else { - this.members.onSubscription(event.data); - this.emit("pusher:subscription_succeeded", this.members); - } - }; - PresenceChannel.prototype.disconnect = function () { - this.members.reset(); - _super.prototype.disconnect.call(this); - }; - return PresenceChannel; -}(private_channel_1["default"])); -exports["default"] = PresenceChannel; - - -/***/ }), -/* 33 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var Collections = __webpack_require__(0); -var Members = (function () { - function Members() { - this.reset(); - } - Members.prototype.get = function (id) { - if (Object.prototype.hasOwnProperty.call(this.members, id)) { - return { - id: id, - info: this.members[id] - }; - } - else { - return null; - } - }; - Members.prototype.each = function (callback) { - var _this = this; - Collections.objectApply(this.members, function (member, id) { - callback(_this.get(id)); - }); - }; - Members.prototype.setMyID = function (id) { - this.myID = id; - }; - Members.prototype.onSubscription = function (subscriptionData) { - this.members = subscriptionData.presence.hash; - this.count = subscriptionData.presence.count; - this.me = this.get(this.myID); - }; - Members.prototype.addMember = function (memberData) { - if (this.get(memberData.user_id) === null) { - this.count++; - } - this.members[memberData.user_id] = memberData.user_info; - return this.get(memberData.user_id); - }; - Members.prototype.removeMember = function (memberData) { - var member = this.get(memberData.user_id); - if (member) { - delete this.members[memberData.user_id]; - this.count--; - } - return member; - }; - Members.prototype.reset = function () { - this.members = {}; - this.count = 0; - this.myID = null; - this.me = null; - }; - return Members; -}()); -exports["default"] = Members; - - -/***/ }), -/* 34 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -exports.__esModule = true; -var private_channel_1 = __webpack_require__(9); -var Errors = __webpack_require__(7); -var logger_1 = __webpack_require__(3); -var tweetnacl_1 = __webpack_require__(35); -var tweetnacl_util_1 = __webpack_require__(37); -var EncryptedChannel = (function (_super) { - __extends(EncryptedChannel, _super); - function EncryptedChannel() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.key = null; - return _this; - } - EncryptedChannel.prototype.authorize = function (socketId, callback) { - var _this = this; - _super.prototype.authorize.call(this, socketId, function (error, authData) { - if (error) { - callback(true, authData); - return; - } - var sharedSecret = authData["shared_secret"]; - if (!sharedSecret) { - var errorMsg = "No shared_secret key in auth payload for encrypted channel: " + _this.name; - callback(true, errorMsg); - logger_1["default"].warn("Error: " + errorMsg); - return; - } - _this.key = tweetnacl_util_1.decodeBase64(sharedSecret); - delete authData["shared_secret"]; - callback(false, authData); - }); - }; - EncryptedChannel.prototype.trigger = function (event, data) { - throw new Errors.UnsupportedFeature('Client events are not currently supported for encrypted channels'); - }; - EncryptedChannel.prototype.handleEvent = function (event) { - var eventName = event.event; - var data = event.data; - if (eventName.indexOf("pusher_internal:") === 0 || eventName.indexOf("pusher:") === 0) { - _super.prototype.handleEvent.call(this, event); - return; - } - this.handleEncryptedEvent(eventName, data); - }; - EncryptedChannel.prototype.handleEncryptedEvent = function (event, data) { - var _this = this; - if (!this.key) { - logger_1["default"].debug('Received encrypted event before key has been retrieved from the authEndpoint'); - return; - } - if (!data.ciphertext || !data.nonce) { - logger_1["default"].warn('Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: ' + data); - return; - } - var cipherText = tweetnacl_util_1.decodeBase64(data.ciphertext); - if (cipherText.length < tweetnacl_1.secretbox.overheadLength) { - logger_1["default"].warn("Expected encrypted event ciphertext length to be " + tweetnacl_1.secretbox.overheadLength + ", got: " + cipherText.length); - return; - } - var nonce = tweetnacl_util_1.decodeBase64(data.nonce); - if (nonce.length < tweetnacl_1.secretbox.nonceLength) { - logger_1["default"].warn("Expected encrypted event nonce length to be " + tweetnacl_1.secretbox.nonceLength + ", got: " + nonce.length); - return; - } - var bytes = tweetnacl_1.secretbox.open(cipherText, nonce, this.key); - if (bytes === null) { - logger_1["default"].debug('Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint...'); - this.authorize(this.pusher.connection.socket_id, function (error, authData) { - if (error) { - logger_1["default"].warn("Failed to make a request to the authEndpoint: " + authData + ". Unable to fetch new key, so dropping encrypted event"); - return; - } - bytes = tweetnacl_1.secretbox.open(cipherText, nonce, _this.key); - if (bytes === null) { - logger_1["default"].warn("Failed to decrypt event with new key. Dropping encrypted event"); - return; - } - _this.emitJSON(event, tweetnacl_util_1.encodeUTF8(bytes)); - return; - }); - return; - } - this.emitJSON(event, tweetnacl_util_1.encodeUTF8(bytes)); - }; - EncryptedChannel.prototype.emitJSON = function (eventName, data) { - try { - this.emit(eventName, JSON.parse(data)); - } - catch (e) { - this.emit(eventName, data); - } - return this; - }; - return EncryptedChannel; -}(private_channel_1["default"])); -exports["default"] = EncryptedChannel; - - -/***/ }), -/* 35 */ -/***/ (function(module, exports, __webpack_require__) { - -(function(nacl) { -'use strict'; - -// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. -// Public domain. -// -// Implementation derived from TweetNaCl version 20140427. -// See for details: http://tweetnacl.cr.yp.to/ - -var gf = function(init) { - var i, r = new Float64Array(16); - if (init) for (i = 0; i < init.length; i++) r[i] = init[i]; - return r; -}; - -// Pluggable, initialized in high-level API below. -var randombytes = function(/* x, n */) { throw new Error('no PRNG'); }; - -var _0 = new Uint8Array(16); -var _9 = new Uint8Array(32); _9[0] = 9; - -var gf0 = gf(), - gf1 = gf([1]), - _121665 = gf([0xdb41, 1]), - D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]), - D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]), - X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]), - Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]), - I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]); - -function ts64(x, i, h, l) { - x[i] = (h >> 24) & 0xff; - x[i+1] = (h >> 16) & 0xff; - x[i+2] = (h >> 8) & 0xff; - x[i+3] = h & 0xff; - x[i+4] = (l >> 24) & 0xff; - x[i+5] = (l >> 16) & 0xff; - x[i+6] = (l >> 8) & 0xff; - x[i+7] = l & 0xff; -} - -function vn(x, xi, y, yi, n) { - var i,d = 0; - for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i]; - return (1 & ((d - 1) >>> 8)) - 1; -} - -function crypto_verify_16(x, xi, y, yi) { - return vn(x,xi,y,yi,16); -} - -function crypto_verify_32(x, xi, y, yi) { - return vn(x,xi,y,yi,32); -} - -function core_salsa20(o, p, k, c) { - var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, - j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, - j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, - j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, - j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, - j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, - j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, - j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, - j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, - j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, - j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, - j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, - j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, - j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, - j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, - j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; - - var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, - x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, - x15 = j15, u; - - for (var i = 0; i < 20; i += 2) { - u = x0 + x12 | 0; - x4 ^= u<<7 | u>>>(32-7); - u = x4 + x0 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x4 | 0; - x12 ^= u<<13 | u>>>(32-13); - u = x12 + x8 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x1 | 0; - x9 ^= u<<7 | u>>>(32-7); - u = x9 + x5 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x9 | 0; - x1 ^= u<<13 | u>>>(32-13); - u = x1 + x13 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x6 | 0; - x14 ^= u<<7 | u>>>(32-7); - u = x14 + x10 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x14 | 0; - x6 ^= u<<13 | u>>>(32-13); - u = x6 + x2 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x11 | 0; - x3 ^= u<<7 | u>>>(32-7); - u = x3 + x15 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x3 | 0; - x11 ^= u<<13 | u>>>(32-13); - u = x11 + x7 | 0; - x15 ^= u<<18 | u>>>(32-18); - - u = x0 + x3 | 0; - x1 ^= u<<7 | u>>>(32-7); - u = x1 + x0 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x1 | 0; - x3 ^= u<<13 | u>>>(32-13); - u = x3 + x2 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x4 | 0; - x6 ^= u<<7 | u>>>(32-7); - u = x6 + x5 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x6 | 0; - x4 ^= u<<13 | u>>>(32-13); - u = x4 + x7 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x9 | 0; - x11 ^= u<<7 | u>>>(32-7); - u = x11 + x10 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x11 | 0; - x9 ^= u<<13 | u>>>(32-13); - u = x9 + x8 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x14 | 0; - x12 ^= u<<7 | u>>>(32-7); - u = x12 + x15 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x12 | 0; - x14 ^= u<<13 | u>>>(32-13); - u = x14 + x13 | 0; - x15 ^= u<<18 | u>>>(32-18); - } - x0 = x0 + j0 | 0; - x1 = x1 + j1 | 0; - x2 = x2 + j2 | 0; - x3 = x3 + j3 | 0; - x4 = x4 + j4 | 0; - x5 = x5 + j5 | 0; - x6 = x6 + j6 | 0; - x7 = x7 + j7 | 0; - x8 = x8 + j8 | 0; - x9 = x9 + j9 | 0; - x10 = x10 + j10 | 0; - x11 = x11 + j11 | 0; - x12 = x12 + j12 | 0; - x13 = x13 + j13 | 0; - x14 = x14 + j14 | 0; - x15 = x15 + j15 | 0; - - o[ 0] = x0 >>> 0 & 0xff; - o[ 1] = x0 >>> 8 & 0xff; - o[ 2] = x0 >>> 16 & 0xff; - o[ 3] = x0 >>> 24 & 0xff; - - o[ 4] = x1 >>> 0 & 0xff; - o[ 5] = x1 >>> 8 & 0xff; - o[ 6] = x1 >>> 16 & 0xff; - o[ 7] = x1 >>> 24 & 0xff; - - o[ 8] = x2 >>> 0 & 0xff; - o[ 9] = x2 >>> 8 & 0xff; - o[10] = x2 >>> 16 & 0xff; - o[11] = x2 >>> 24 & 0xff; - - o[12] = x3 >>> 0 & 0xff; - o[13] = x3 >>> 8 & 0xff; - o[14] = x3 >>> 16 & 0xff; - o[15] = x3 >>> 24 & 0xff; - - o[16] = x4 >>> 0 & 0xff; - o[17] = x4 >>> 8 & 0xff; - o[18] = x4 >>> 16 & 0xff; - o[19] = x4 >>> 24 & 0xff; - - o[20] = x5 >>> 0 & 0xff; - o[21] = x5 >>> 8 & 0xff; - o[22] = x5 >>> 16 & 0xff; - o[23] = x5 >>> 24 & 0xff; - - o[24] = x6 >>> 0 & 0xff; - o[25] = x6 >>> 8 & 0xff; - o[26] = x6 >>> 16 & 0xff; - o[27] = x6 >>> 24 & 0xff; - - o[28] = x7 >>> 0 & 0xff; - o[29] = x7 >>> 8 & 0xff; - o[30] = x7 >>> 16 & 0xff; - o[31] = x7 >>> 24 & 0xff; - - o[32] = x8 >>> 0 & 0xff; - o[33] = x8 >>> 8 & 0xff; - o[34] = x8 >>> 16 & 0xff; - o[35] = x8 >>> 24 & 0xff; - - o[36] = x9 >>> 0 & 0xff; - o[37] = x9 >>> 8 & 0xff; - o[38] = x9 >>> 16 & 0xff; - o[39] = x9 >>> 24 & 0xff; - - o[40] = x10 >>> 0 & 0xff; - o[41] = x10 >>> 8 & 0xff; - o[42] = x10 >>> 16 & 0xff; - o[43] = x10 >>> 24 & 0xff; - - o[44] = x11 >>> 0 & 0xff; - o[45] = x11 >>> 8 & 0xff; - o[46] = x11 >>> 16 & 0xff; - o[47] = x11 >>> 24 & 0xff; - - o[48] = x12 >>> 0 & 0xff; - o[49] = x12 >>> 8 & 0xff; - o[50] = x12 >>> 16 & 0xff; - o[51] = x12 >>> 24 & 0xff; - - o[52] = x13 >>> 0 & 0xff; - o[53] = x13 >>> 8 & 0xff; - o[54] = x13 >>> 16 & 0xff; - o[55] = x13 >>> 24 & 0xff; - - o[56] = x14 >>> 0 & 0xff; - o[57] = x14 >>> 8 & 0xff; - o[58] = x14 >>> 16 & 0xff; - o[59] = x14 >>> 24 & 0xff; - - o[60] = x15 >>> 0 & 0xff; - o[61] = x15 >>> 8 & 0xff; - o[62] = x15 >>> 16 & 0xff; - o[63] = x15 >>> 24 & 0xff; -} - -function core_hsalsa20(o,p,k,c) { - var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, - j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, - j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, - j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, - j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, - j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, - j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, - j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, - j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, - j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, - j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, - j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, - j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, - j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, - j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, - j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; - - var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, - x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, - x15 = j15, u; - - for (var i = 0; i < 20; i += 2) { - u = x0 + x12 | 0; - x4 ^= u<<7 | u>>>(32-7); - u = x4 + x0 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x4 | 0; - x12 ^= u<<13 | u>>>(32-13); - u = x12 + x8 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x1 | 0; - x9 ^= u<<7 | u>>>(32-7); - u = x9 + x5 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x9 | 0; - x1 ^= u<<13 | u>>>(32-13); - u = x1 + x13 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x6 | 0; - x14 ^= u<<7 | u>>>(32-7); - u = x14 + x10 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x14 | 0; - x6 ^= u<<13 | u>>>(32-13); - u = x6 + x2 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x11 | 0; - x3 ^= u<<7 | u>>>(32-7); - u = x3 + x15 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x3 | 0; - x11 ^= u<<13 | u>>>(32-13); - u = x11 + x7 | 0; - x15 ^= u<<18 | u>>>(32-18); - - u = x0 + x3 | 0; - x1 ^= u<<7 | u>>>(32-7); - u = x1 + x0 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x1 | 0; - x3 ^= u<<13 | u>>>(32-13); - u = x3 + x2 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x4 | 0; - x6 ^= u<<7 | u>>>(32-7); - u = x6 + x5 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x6 | 0; - x4 ^= u<<13 | u>>>(32-13); - u = x4 + x7 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x9 | 0; - x11 ^= u<<7 | u>>>(32-7); - u = x11 + x10 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x11 | 0; - x9 ^= u<<13 | u>>>(32-13); - u = x9 + x8 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x14 | 0; - x12 ^= u<<7 | u>>>(32-7); - u = x12 + x15 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x12 | 0; - x14 ^= u<<13 | u>>>(32-13); - u = x14 + x13 | 0; - x15 ^= u<<18 | u>>>(32-18); - } - - o[ 0] = x0 >>> 0 & 0xff; - o[ 1] = x0 >>> 8 & 0xff; - o[ 2] = x0 >>> 16 & 0xff; - o[ 3] = x0 >>> 24 & 0xff; - - o[ 4] = x5 >>> 0 & 0xff; - o[ 5] = x5 >>> 8 & 0xff; - o[ 6] = x5 >>> 16 & 0xff; - o[ 7] = x5 >>> 24 & 0xff; - - o[ 8] = x10 >>> 0 & 0xff; - o[ 9] = x10 >>> 8 & 0xff; - o[10] = x10 >>> 16 & 0xff; - o[11] = x10 >>> 24 & 0xff; - - o[12] = x15 >>> 0 & 0xff; - o[13] = x15 >>> 8 & 0xff; - o[14] = x15 >>> 16 & 0xff; - o[15] = x15 >>> 24 & 0xff; - - o[16] = x6 >>> 0 & 0xff; - o[17] = x6 >>> 8 & 0xff; - o[18] = x6 >>> 16 & 0xff; - o[19] = x6 >>> 24 & 0xff; - - o[20] = x7 >>> 0 & 0xff; - o[21] = x7 >>> 8 & 0xff; - o[22] = x7 >>> 16 & 0xff; - o[23] = x7 >>> 24 & 0xff; - - o[24] = x8 >>> 0 & 0xff; - o[25] = x8 >>> 8 & 0xff; - o[26] = x8 >>> 16 & 0xff; - o[27] = x8 >>> 24 & 0xff; - - o[28] = x9 >>> 0 & 0xff; - o[29] = x9 >>> 8 & 0xff; - o[30] = x9 >>> 16 & 0xff; - o[31] = x9 >>> 24 & 0xff; -} - -function crypto_core_salsa20(out,inp,k,c) { - core_salsa20(out,inp,k,c); -} - -function crypto_core_hsalsa20(out,inp,k,c) { - core_hsalsa20(out,inp,k,c); -} - -var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]); - // "expand 32-byte k" - -function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) { - var z = new Uint8Array(16), x = new Uint8Array(64); - var u, i; - for (i = 0; i < 16; i++) z[i] = 0; - for (i = 0; i < 8; i++) z[i] = n[i]; - while (b >= 64) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i]; - u = 1; - for (i = 8; i < 16; i++) { - u = u + (z[i] & 0xff) | 0; - z[i] = u & 0xff; - u >>>= 8; - } - b -= 64; - cpos += 64; - mpos += 64; - } - if (b > 0) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i]; - } - return 0; -} - -function crypto_stream_salsa20(c,cpos,b,n,k) { - var z = new Uint8Array(16), x = new Uint8Array(64); - var u, i; - for (i = 0; i < 16; i++) z[i] = 0; - for (i = 0; i < 8; i++) z[i] = n[i]; - while (b >= 64) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < 64; i++) c[cpos+i] = x[i]; - u = 1; - for (i = 8; i < 16; i++) { - u = u + (z[i] & 0xff) | 0; - z[i] = u & 0xff; - u >>>= 8; - } - b -= 64; - cpos += 64; - } - if (b > 0) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < b; i++) c[cpos+i] = x[i]; - } - return 0; -} - -function crypto_stream(c,cpos,d,n,k) { - var s = new Uint8Array(32); - crypto_core_hsalsa20(s,n,k,sigma); - var sn = new Uint8Array(8); - for (var i = 0; i < 8; i++) sn[i] = n[i+16]; - return crypto_stream_salsa20(c,cpos,d,sn,s); -} - -function crypto_stream_xor(c,cpos,m,mpos,d,n,k) { - var s = new Uint8Array(32); - crypto_core_hsalsa20(s,n,k,sigma); - var sn = new Uint8Array(8); - for (var i = 0; i < 8; i++) sn[i] = n[i+16]; - return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s); -} - -/* -* Port of Andrew Moon's Poly1305-donna-16. Public domain. -* https://github.com/floodyberry/poly1305-donna -*/ - -var poly1305 = function(key) { - this.buffer = new Uint8Array(16); - this.r = new Uint16Array(10); - this.h = new Uint16Array(10); - this.pad = new Uint16Array(8); - this.leftover = 0; - this.fin = 0; - - var t0, t1, t2, t3, t4, t5, t6, t7; - - t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff; - t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff; - t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03; - t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff; - t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff; - this.r[5] = ((t4 >>> 1)) & 0x1ffe; - t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff; - t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81; - t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff; - this.r[9] = ((t7 >>> 5)) & 0x007f; - - this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8; - this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8; - this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8; - this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8; - this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8; - this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8; - this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8; - this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8; -}; - -poly1305.prototype.blocks = function(m, mpos, bytes) { - var hibit = this.fin ? 0 : (1 << 11); - var t0, t1, t2, t3, t4, t5, t6, t7, c; - var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9; - - var h0 = this.h[0], - h1 = this.h[1], - h2 = this.h[2], - h3 = this.h[3], - h4 = this.h[4], - h5 = this.h[5], - h6 = this.h[6], - h7 = this.h[7], - h8 = this.h[8], - h9 = this.h[9]; - - var r0 = this.r[0], - r1 = this.r[1], - r2 = this.r[2], - r3 = this.r[3], - r4 = this.r[4], - r5 = this.r[5], - r6 = this.r[6], - r7 = this.r[7], - r8 = this.r[8], - r9 = this.r[9]; - - while (bytes >= 16) { - t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff; - t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff; - t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff; - t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff; - t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff; - h5 += ((t4 >>> 1)) & 0x1fff; - t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff; - t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff; - t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff; - h9 += ((t7 >>> 5)) | hibit; - - c = 0; - - d0 = c; - d0 += h0 * r0; - d0 += h1 * (5 * r9); - d0 += h2 * (5 * r8); - d0 += h3 * (5 * r7); - d0 += h4 * (5 * r6); - c = (d0 >>> 13); d0 &= 0x1fff; - d0 += h5 * (5 * r5); - d0 += h6 * (5 * r4); - d0 += h7 * (5 * r3); - d0 += h8 * (5 * r2); - d0 += h9 * (5 * r1); - c += (d0 >>> 13); d0 &= 0x1fff; - - d1 = c; - d1 += h0 * r1; - d1 += h1 * r0; - d1 += h2 * (5 * r9); - d1 += h3 * (5 * r8); - d1 += h4 * (5 * r7); - c = (d1 >>> 13); d1 &= 0x1fff; - d1 += h5 * (5 * r6); - d1 += h6 * (5 * r5); - d1 += h7 * (5 * r4); - d1 += h8 * (5 * r3); - d1 += h9 * (5 * r2); - c += (d1 >>> 13); d1 &= 0x1fff; - - d2 = c; - d2 += h0 * r2; - d2 += h1 * r1; - d2 += h2 * r0; - d2 += h3 * (5 * r9); - d2 += h4 * (5 * r8); - c = (d2 >>> 13); d2 &= 0x1fff; - d2 += h5 * (5 * r7); - d2 += h6 * (5 * r6); - d2 += h7 * (5 * r5); - d2 += h8 * (5 * r4); - d2 += h9 * (5 * r3); - c += (d2 >>> 13); d2 &= 0x1fff; - - d3 = c; - d3 += h0 * r3; - d3 += h1 * r2; - d3 += h2 * r1; - d3 += h3 * r0; - d3 += h4 * (5 * r9); - c = (d3 >>> 13); d3 &= 0x1fff; - d3 += h5 * (5 * r8); - d3 += h6 * (5 * r7); - d3 += h7 * (5 * r6); - d3 += h8 * (5 * r5); - d3 += h9 * (5 * r4); - c += (d3 >>> 13); d3 &= 0x1fff; - - d4 = c; - d4 += h0 * r4; - d4 += h1 * r3; - d4 += h2 * r2; - d4 += h3 * r1; - d4 += h4 * r0; - c = (d4 >>> 13); d4 &= 0x1fff; - d4 += h5 * (5 * r9); - d4 += h6 * (5 * r8); - d4 += h7 * (5 * r7); - d4 += h8 * (5 * r6); - d4 += h9 * (5 * r5); - c += (d4 >>> 13); d4 &= 0x1fff; - - d5 = c; - d5 += h0 * r5; - d5 += h1 * r4; - d5 += h2 * r3; - d5 += h3 * r2; - d5 += h4 * r1; - c = (d5 >>> 13); d5 &= 0x1fff; - d5 += h5 * r0; - d5 += h6 * (5 * r9); - d5 += h7 * (5 * r8); - d5 += h8 * (5 * r7); - d5 += h9 * (5 * r6); - c += (d5 >>> 13); d5 &= 0x1fff; - - d6 = c; - d6 += h0 * r6; - d6 += h1 * r5; - d6 += h2 * r4; - d6 += h3 * r3; - d6 += h4 * r2; - c = (d6 >>> 13); d6 &= 0x1fff; - d6 += h5 * r1; - d6 += h6 * r0; - d6 += h7 * (5 * r9); - d6 += h8 * (5 * r8); - d6 += h9 * (5 * r7); - c += (d6 >>> 13); d6 &= 0x1fff; - - d7 = c; - d7 += h0 * r7; - d7 += h1 * r6; - d7 += h2 * r5; - d7 += h3 * r4; - d7 += h4 * r3; - c = (d7 >>> 13); d7 &= 0x1fff; - d7 += h5 * r2; - d7 += h6 * r1; - d7 += h7 * r0; - d7 += h8 * (5 * r9); - d7 += h9 * (5 * r8); - c += (d7 >>> 13); d7 &= 0x1fff; - - d8 = c; - d8 += h0 * r8; - d8 += h1 * r7; - d8 += h2 * r6; - d8 += h3 * r5; - d8 += h4 * r4; - c = (d8 >>> 13); d8 &= 0x1fff; - d8 += h5 * r3; - d8 += h6 * r2; - d8 += h7 * r1; - d8 += h8 * r0; - d8 += h9 * (5 * r9); - c += (d8 >>> 13); d8 &= 0x1fff; - - d9 = c; - d9 += h0 * r9; - d9 += h1 * r8; - d9 += h2 * r7; - d9 += h3 * r6; - d9 += h4 * r5; - c = (d9 >>> 13); d9 &= 0x1fff; - d9 += h5 * r4; - d9 += h6 * r3; - d9 += h7 * r2; - d9 += h8 * r1; - d9 += h9 * r0; - c += (d9 >>> 13); d9 &= 0x1fff; - - c = (((c << 2) + c)) | 0; - c = (c + d0) | 0; - d0 = c & 0x1fff; - c = (c >>> 13); - d1 += c; - - h0 = d0; - h1 = d1; - h2 = d2; - h3 = d3; - h4 = d4; - h5 = d5; - h6 = d6; - h7 = d7; - h8 = d8; - h9 = d9; - - mpos += 16; - bytes -= 16; - } - this.h[0] = h0; - this.h[1] = h1; - this.h[2] = h2; - this.h[3] = h3; - this.h[4] = h4; - this.h[5] = h5; - this.h[6] = h6; - this.h[7] = h7; - this.h[8] = h8; - this.h[9] = h9; -}; - -poly1305.prototype.finish = function(mac, macpos) { - var g = new Uint16Array(10); - var c, mask, f, i; - - if (this.leftover) { - i = this.leftover; - this.buffer[i++] = 1; - for (; i < 16; i++) this.buffer[i] = 0; - this.fin = 1; - this.blocks(this.buffer, 0, 16); - } - - c = this.h[1] >>> 13; - this.h[1] &= 0x1fff; - for (i = 2; i < 10; i++) { - this.h[i] += c; - c = this.h[i] >>> 13; - this.h[i] &= 0x1fff; - } - this.h[0] += (c * 5); - c = this.h[0] >>> 13; - this.h[0] &= 0x1fff; - this.h[1] += c; - c = this.h[1] >>> 13; - this.h[1] &= 0x1fff; - this.h[2] += c; - - g[0] = this.h[0] + 5; - c = g[0] >>> 13; - g[0] &= 0x1fff; - for (i = 1; i < 10; i++) { - g[i] = this.h[i] + c; - c = g[i] >>> 13; - g[i] &= 0x1fff; - } - g[9] -= (1 << 13); - - mask = (c ^ 1) - 1; - for (i = 0; i < 10; i++) g[i] &= mask; - mask = ~mask; - for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]; - - this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff; - this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff; - this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff; - this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff; - this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff; - this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff; - this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff; - this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff; - - f = this.h[0] + this.pad[0]; - this.h[0] = f & 0xffff; - for (i = 1; i < 8; i++) { - f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0; - this.h[i] = f & 0xffff; - } - - mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff; - mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff; - mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff; - mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff; - mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff; - mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff; - mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff; - mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff; - mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff; - mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff; - mac[macpos+10] = (this.h[5] >>> 0) & 0xff; - mac[macpos+11] = (this.h[5] >>> 8) & 0xff; - mac[macpos+12] = (this.h[6] >>> 0) & 0xff; - mac[macpos+13] = (this.h[6] >>> 8) & 0xff; - mac[macpos+14] = (this.h[7] >>> 0) & 0xff; - mac[macpos+15] = (this.h[7] >>> 8) & 0xff; -}; - -poly1305.prototype.update = function(m, mpos, bytes) { - var i, want; - - if (this.leftover) { - want = (16 - this.leftover); - if (want > bytes) - want = bytes; - for (i = 0; i < want; i++) - this.buffer[this.leftover + i] = m[mpos+i]; - bytes -= want; - mpos += want; - this.leftover += want; - if (this.leftover < 16) - return; - this.blocks(this.buffer, 0, 16); - this.leftover = 0; - } - - if (bytes >= 16) { - want = bytes - (bytes % 16); - this.blocks(m, mpos, want); - mpos += want; - bytes -= want; - } - - if (bytes) { - for (i = 0; i < bytes; i++) - this.buffer[this.leftover + i] = m[mpos+i]; - this.leftover += bytes; - } -}; - -function crypto_onetimeauth(out, outpos, m, mpos, n, k) { - var s = new poly1305(k); - s.update(m, mpos, n); - s.finish(out, outpos); - return 0; -} - -function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) { - var x = new Uint8Array(16); - crypto_onetimeauth(x,0,m,mpos,n,k); - return crypto_verify_16(h,hpos,x,0); -} - -function crypto_secretbox(c,m,d,n,k) { - var i; - if (d < 32) return -1; - crypto_stream_xor(c,0,m,0,d,n,k); - crypto_onetimeauth(c, 16, c, 32, d - 32, c); - for (i = 0; i < 16; i++) c[i] = 0; - return 0; -} - -function crypto_secretbox_open(m,c,d,n,k) { - var i; - var x = new Uint8Array(32); - if (d < 32) return -1; - crypto_stream(x,0,32,n,k); - if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1; - crypto_stream_xor(m,0,c,0,d,n,k); - for (i = 0; i < 32; i++) m[i] = 0; - return 0; -} - -function set25519(r, a) { - var i; - for (i = 0; i < 16; i++) r[i] = a[i]|0; -} - -function car25519(o) { - var i, v, c = 1; - for (i = 0; i < 16; i++) { - v = o[i] + c + 65535; - c = Math.floor(v / 65536); - o[i] = v - c * 65536; - } - o[0] += c-1 + 37 * (c-1); -} - -function sel25519(p, q, b) { - var t, c = ~(b-1); - for (var i = 0; i < 16; i++) { - t = c & (p[i] ^ q[i]); - p[i] ^= t; - q[i] ^= t; - } -} - -function pack25519(o, n) { - var i, j, b; - var m = gf(), t = gf(); - for (i = 0; i < 16; i++) t[i] = n[i]; - car25519(t); - car25519(t); - car25519(t); - for (j = 0; j < 2; j++) { - m[0] = t[0] - 0xffed; - for (i = 1; i < 15; i++) { - m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1); - m[i-1] &= 0xffff; - } - m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1); - b = (m[15]>>16) & 1; - m[14] &= 0xffff; - sel25519(t, m, 1-b); - } - for (i = 0; i < 16; i++) { - o[2*i] = t[i] & 0xff; - o[2*i+1] = t[i]>>8; - } -} - -function neq25519(a, b) { - var c = new Uint8Array(32), d = new Uint8Array(32); - pack25519(c, a); - pack25519(d, b); - return crypto_verify_32(c, 0, d, 0); -} - -function par25519(a) { - var d = new Uint8Array(32); - pack25519(d, a); - return d[0] & 1; -} - -function unpack25519(o, n) { - var i; - for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8); - o[15] &= 0x7fff; -} - -function A(o, a, b) { - for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]; -} - -function Z(o, a, b) { - for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]; -} - -function M(o, a, b) { - var v, c, - t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, - t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, - t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, - t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, - b0 = b[0], - b1 = b[1], - b2 = b[2], - b3 = b[3], - b4 = b[4], - b5 = b[5], - b6 = b[6], - b7 = b[7], - b8 = b[8], - b9 = b[9], - b10 = b[10], - b11 = b[11], - b12 = b[12], - b13 = b[13], - b14 = b[14], - b15 = b[15]; +function M(o, a, b) { + var v, c, + t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, + t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, + t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, + t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, + b0 = b[0], + b1 = b[1], + b2 = b[2], + b3 = b[3], + b4 = b[4], + b5 = b[5], + b6 = b[6], + b7 = b[7], + b8 = b[8], + b9 = b[9], + b10 = b[10], + b11 = b[11], + b12 = b[12], + b13 = b[13], + b14 = b[14], + b15 = b[15]; v = a[0]; t0 += v * b0; @@ -3769,1263 +1319,2930 @@ function M(o, a, b) { t29 += v * b14; t30 += v * b15; - t0 += 38 * t16; - t1 += 38 * t17; - t2 += 38 * t18; - t3 += 38 * t19; - t4 += 38 * t20; - t5 += 38 * t21; - t6 += 38 * t22; - t7 += 38 * t23; - t8 += 38 * t24; - t9 += 38 * t25; - t10 += 38 * t26; - t11 += 38 * t27; - t12 += 38 * t28; - t13 += 38 * t29; - t14 += 38 * t30; - // t15 left as is + t0 += 38 * t16; + t1 += 38 * t17; + t2 += 38 * t18; + t3 += 38 * t19; + t4 += 38 * t20; + t5 += 38 * t21; + t6 += 38 * t22; + t7 += 38 * t23; + t8 += 38 * t24; + t9 += 38 * t25; + t10 += 38 * t26; + t11 += 38 * t27; + t12 += 38 * t28; + t13 += 38 * t29; + t14 += 38 * t30; + // t15 left as is + + // first car + c = 1; + v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; + v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; + v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; + v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; + v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; + v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; + v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; + v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; + v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; + v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; + v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; + v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; + v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; + v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; + v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; + v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; + t0 += c-1 + 37 * (c-1); + + // second car + c = 1; + v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; + v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; + v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; + v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; + v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; + v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; + v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; + v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; + v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; + v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; + v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; + v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; + v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; + v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; + v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; + v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; + t0 += c-1 + 37 * (c-1); + + o[ 0] = t0; + o[ 1] = t1; + o[ 2] = t2; + o[ 3] = t3; + o[ 4] = t4; + o[ 5] = t5; + o[ 6] = t6; + o[ 7] = t7; + o[ 8] = t8; + o[ 9] = t9; + o[10] = t10; + o[11] = t11; + o[12] = t12; + o[13] = t13; + o[14] = t14; + o[15] = t15; +} + +function S(o, a) { + M(o, a, a); +} + +function inv25519(o, i) { + var c = gf(); + var a; + for (a = 0; a < 16; a++) c[a] = i[a]; + for (a = 253; a >= 0; a--) { + S(c, c); + if(a !== 2 && a !== 4) M(c, c, i); + } + for (a = 0; a < 16; a++) o[a] = c[a]; +} + +function pow2523(o, i) { + var c = gf(); + var a; + for (a = 0; a < 16; a++) c[a] = i[a]; + for (a = 250; a >= 0; a--) { + S(c, c); + if(a !== 1) M(c, c, i); + } + for (a = 0; a < 16; a++) o[a] = c[a]; +} + +function crypto_scalarmult(q, n, p) { + var z = new Uint8Array(32); + var x = new Float64Array(80), r, i; + var a = gf(), b = gf(), c = gf(), + d = gf(), e = gf(), f = gf(); + for (i = 0; i < 31; i++) z[i] = n[i]; + z[31]=(n[31]&127)|64; + z[0]&=248; + unpack25519(x,p); + for (i = 0; i < 16; i++) { + b[i]=x[i]; + d[i]=a[i]=c[i]=0; + } + a[0]=d[0]=1; + for (i=254; i>=0; --i) { + r=(z[i>>>3]>>>(i&7))&1; + sel25519(a,b,r); + sel25519(c,d,r); + A(e,a,c); + Z(a,a,c); + A(c,b,d); + Z(b,b,d); + S(d,e); + S(f,a); + M(a,c,a); + M(c,b,e); + A(e,a,c); + Z(a,a,c); + S(b,a); + Z(c,d,f); + M(a,c,_121665); + A(a,a,d); + M(c,c,a); + M(a,d,f); + M(d,b,x); + S(b,e); + sel25519(a,b,r); + sel25519(c,d,r); + } + for (i = 0; i < 16; i++) { + x[i+16]=a[i]; + x[i+32]=c[i]; + x[i+48]=b[i]; + x[i+64]=d[i]; + } + var x32 = x.subarray(32); + var x16 = x.subarray(16); + inv25519(x32,x32); + M(x16,x16,x32); + pack25519(q,x16); + return 0; +} + +function crypto_scalarmult_base(q, n) { + return crypto_scalarmult(q, n, _9); +} + +function crypto_box_keypair(y, x) { + randombytes(x, 32); + return crypto_scalarmult_base(y, x); +} + +function crypto_box_beforenm(k, y, x) { + var s = new Uint8Array(32); + crypto_scalarmult(s, x, y); + return crypto_core_hsalsa20(k, _0, s, sigma); +} + +var crypto_box_afternm = crypto_secretbox; +var crypto_box_open_afternm = crypto_secretbox_open; + +function crypto_box(c, m, d, n, y, x) { + var k = new Uint8Array(32); + crypto_box_beforenm(k, y, x); + return crypto_box_afternm(c, m, d, n, k); +} + +function crypto_box_open(m, c, d, n, y, x) { + var k = new Uint8Array(32); + crypto_box_beforenm(k, y, x); + return crypto_box_open_afternm(m, c, d, n, k); +} + +var K = [ + 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, + 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, + 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, + 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, + 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, + 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, + 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, + 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, + 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, + 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, + 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, + 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, + 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, + 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, + 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, + 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, + 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, + 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, + 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, + 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, + 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, + 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, + 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, + 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, + 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, + 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, + 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, + 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, + 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, + 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, + 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, + 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, + 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, + 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, + 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, + 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, + 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, + 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, + 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, + 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 +]; + +function crypto_hashblocks_hl(hh, hl, m, n) { + var wh = new Int32Array(16), wl = new Int32Array(16), + bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, + bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, + th, tl, i, j, h, l, a, b, c, d; + + var ah0 = hh[0], + ah1 = hh[1], + ah2 = hh[2], + ah3 = hh[3], + ah4 = hh[4], + ah5 = hh[5], + ah6 = hh[6], + ah7 = hh[7], + + al0 = hl[0], + al1 = hl[1], + al2 = hl[2], + al3 = hl[3], + al4 = hl[4], + al5 = hl[5], + al6 = hl[6], + al7 = hl[7]; + + var pos = 0; + while (n >= 128) { + for (i = 0; i < 16; i++) { + j = 8 * i + pos; + wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3]; + wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7]; + } + for (i = 0; i < 80; i++) { + bh0 = ah0; + bh1 = ah1; + bh2 = ah2; + bh3 = ah3; + bh4 = ah4; + bh5 = ah5; + bh6 = ah6; + bh7 = ah7; + + bl0 = al0; + bl1 = al1; + bl2 = al2; + bl3 = al3; + bl4 = al4; + bl5 = al5; + bl6 = al6; + bl7 = al7; + + // add + h = ah7; + l = al7; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + // Sigma1 + h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32)))); + l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32)))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // Ch + h = (ah4 & ah5) ^ (~ah4 & ah6); + l = (al4 & al5) ^ (~al4 & al6); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // K + h = K[i*2]; + l = K[i*2+1]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // w + h = wh[i%16]; + l = wl[i%16]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + th = c & 0xffff | d << 16; + tl = a & 0xffff | b << 16; + + // add + h = th; + l = tl; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + // Sigma0 + h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32)))); + l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32)))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // Maj + h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + bh7 = (c & 0xffff) | (d << 16); + bl7 = (a & 0xffff) | (b << 16); + + // add + h = bh3; + l = bl3; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = th; + l = tl; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + bh3 = (c & 0xffff) | (d << 16); + bl3 = (a & 0xffff) | (b << 16); + + ah1 = bh0; + ah2 = bh1; + ah3 = bh2; + ah4 = bh3; + ah5 = bh4; + ah6 = bh5; + ah7 = bh6; + ah0 = bh7; + + al1 = bl0; + al2 = bl1; + al3 = bl2; + al4 = bl3; + al5 = bl4; + al6 = bl5; + al7 = bl6; + al0 = bl7; + + if (i%16 === 15) { + for (j = 0; j < 16; j++) { + // add + h = wh[j]; + l = wl[j]; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = wh[(j+9)%16]; + l = wl[(j+9)%16]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // sigma0 + th = wh[(j+1)%16]; + tl = wl[(j+1)%16]; + h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7); + l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // sigma1 + th = wh[(j+14)%16]; + tl = wl[(j+14)%16]; + h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6); + l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + wh[j] = (c & 0xffff) | (d << 16); + wl[j] = (a & 0xffff) | (b << 16); + } + } + } + + // add + h = ah0; + l = al0; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[0]; + l = hl[0]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[0] = ah0 = (c & 0xffff) | (d << 16); + hl[0] = al0 = (a & 0xffff) | (b << 16); + + h = ah1; + l = al1; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[1]; + l = hl[1]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[1] = ah1 = (c & 0xffff) | (d << 16); + hl[1] = al1 = (a & 0xffff) | (b << 16); + + h = ah2; + l = al2; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[2]; + l = hl[2]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[2] = ah2 = (c & 0xffff) | (d << 16); + hl[2] = al2 = (a & 0xffff) | (b << 16); + + h = ah3; + l = al3; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[3]; + l = hl[3]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[3] = ah3 = (c & 0xffff) | (d << 16); + hl[3] = al3 = (a & 0xffff) | (b << 16); + + h = ah4; + l = al4; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[4]; + l = hl[4]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[4] = ah4 = (c & 0xffff) | (d << 16); + hl[4] = al4 = (a & 0xffff) | (b << 16); + + h = ah5; + l = al5; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[5]; + l = hl[5]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[5] = ah5 = (c & 0xffff) | (d << 16); + hl[5] = al5 = (a & 0xffff) | (b << 16); + + h = ah6; + l = al6; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[6]; + l = hl[6]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - // first car - c = 1; - v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; - v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; - v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; - v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; - v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; - v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; - v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; - v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; - v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; - v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; - v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; - v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; - v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; - v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; - v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; - v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; - t0 += c-1 + 37 * (c-1); + hh[6] = ah6 = (c & 0xffff) | (d << 16); + hl[6] = al6 = (a & 0xffff) | (b << 16); - // second car - c = 1; - v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; - v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; - v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; - v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; - v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; - v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; - v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; - v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; - v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; - v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; - v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; - v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; - v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; - v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; - v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; - v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; - t0 += c-1 + 37 * (c-1); + h = ah7; + l = al7; - o[ 0] = t0; - o[ 1] = t1; - o[ 2] = t2; - o[ 3] = t3; - o[ 4] = t4; - o[ 5] = t5; - o[ 6] = t6; - o[ 7] = t7; - o[ 8] = t8; - o[ 9] = t9; - o[10] = t10; - o[11] = t11; - o[12] = t12; - o[13] = t13; - o[14] = t14; - o[15] = t15; -} + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; -function S(o, a) { - M(o, a, a); -} + h = hh[7]; + l = hl[7]; -function inv25519(o, i) { - var c = gf(); - var a; - for (a = 0; a < 16; a++) c[a] = i[a]; - for (a = 253; a >= 0; a--) { - S(c, c); - if(a !== 2 && a !== 4) M(c, c, i); - } - for (a = 0; a < 16; a++) o[a] = c[a]; -} + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; -function pow2523(o, i) { - var c = gf(); - var a; - for (a = 0; a < 16; a++) c[a] = i[a]; - for (a = 250; a >= 0; a--) { - S(c, c); - if(a !== 1) M(c, c, i); + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[7] = ah7 = (c & 0xffff) | (d << 16); + hl[7] = al7 = (a & 0xffff) | (b << 16); + + pos += 128; + n -= 128; } - for (a = 0; a < 16; a++) o[a] = c[a]; + + return n; } -function crypto_scalarmult(q, n, p) { - var z = new Uint8Array(32); - var x = new Float64Array(80), r, i; - var a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(); - for (i = 0; i < 31; i++) z[i] = n[i]; - z[31]=(n[31]&127)|64; - z[0]&=248; - unpack25519(x,p); - for (i = 0; i < 16; i++) { - b[i]=x[i]; - d[i]=a[i]=c[i]=0; - } - a[0]=d[0]=1; - for (i=254; i>=0; --i) { - r=(z[i>>>3]>>>(i&7))&1; - sel25519(a,b,r); - sel25519(c,d,r); - A(e,a,c); - Z(a,a,c); - A(c,b,d); - Z(b,b,d); - S(d,e); - S(f,a); - M(a,c,a); - M(c,b,e); - A(e,a,c); - Z(a,a,c); - S(b,a); - Z(c,d,f); - M(a,c,_121665); - A(a,a,d); - M(c,c,a); - M(a,d,f); - M(d,b,x); - S(b,e); - sel25519(a,b,r); - sel25519(c,d,r); - } - for (i = 0; i < 16; i++) { - x[i+16]=a[i]; - x[i+32]=c[i]; - x[i+48]=b[i]; - x[i+64]=d[i]; - } - var x32 = x.subarray(32); - var x16 = x.subarray(16); - inv25519(x32,x32); - M(x16,x16,x32); - pack25519(q,x16); +function crypto_hash(out, m, n) { + var hh = new Int32Array(8), + hl = new Int32Array(8), + x = new Uint8Array(256), + i, b = n; + + hh[0] = 0x6a09e667; + hh[1] = 0xbb67ae85; + hh[2] = 0x3c6ef372; + hh[3] = 0xa54ff53a; + hh[4] = 0x510e527f; + hh[5] = 0x9b05688c; + hh[6] = 0x1f83d9ab; + hh[7] = 0x5be0cd19; + + hl[0] = 0xf3bcc908; + hl[1] = 0x84caa73b; + hl[2] = 0xfe94f82b; + hl[3] = 0x5f1d36f1; + hl[4] = 0xade682d1; + hl[5] = 0x2b3e6c1f; + hl[6] = 0xfb41bd6b; + hl[7] = 0x137e2179; + + crypto_hashblocks_hl(hh, hl, m, n); + n %= 128; + + for (i = 0; i < n; i++) x[i] = m[b-n+i]; + x[n] = 128; + + n = 256-128*(n<112?1:0); + x[n-9] = 0; + ts64(x, n-8, (b / 0x20000000) | 0, b << 3); + crypto_hashblocks_hl(hh, hl, x, n); + + for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); + return 0; } -function crypto_scalarmult_base(q, n) { - return crypto_scalarmult(q, n, _9); +function add(p, q) { + var a = gf(), b = gf(), c = gf(), + d = gf(), e = gf(), f = gf(), + g = gf(), h = gf(), t = gf(); + + Z(a, p[1], p[0]); + Z(t, q[1], q[0]); + M(a, a, t); + A(b, p[0], p[1]); + A(t, q[0], q[1]); + M(b, b, t); + M(c, p[3], q[3]); + M(c, c, D2); + M(d, p[2], q[2]); + A(d, d, d); + Z(e, b, a); + Z(f, d, c); + A(g, d, c); + A(h, b, a); + + M(p[0], e, f); + M(p[1], h, g); + M(p[2], g, f); + M(p[3], e, h); } -function crypto_box_keypair(y, x) { - randombytes(x, 32); - return crypto_scalarmult_base(y, x); +function cswap(p, q, b) { + var i; + for (i = 0; i < 4; i++) { + sel25519(p[i], q[i], b); + } } -function crypto_box_beforenm(k, y, x) { - var s = new Uint8Array(32); - crypto_scalarmult(s, x, y); - return crypto_core_hsalsa20(k, _0, s, sigma); +function pack(r, p) { + var tx = gf(), ty = gf(), zi = gf(); + inv25519(zi, p[2]); + M(tx, p[0], zi); + M(ty, p[1], zi); + pack25519(r, ty); + r[31] ^= par25519(tx) << 7; } -var crypto_box_afternm = crypto_secretbox; -var crypto_box_open_afternm = crypto_secretbox_open; +function scalarmult(p, q, s) { + var b, i; + set25519(p[0], gf0); + set25519(p[1], gf1); + set25519(p[2], gf1); + set25519(p[3], gf0); + for (i = 255; i >= 0; --i) { + b = (s[(i/8)|0] >> (i&7)) & 1; + cswap(p, q, b); + add(q, p); + add(p, p); + cswap(p, q, b); + } +} -function crypto_box(c, m, d, n, y, x) { - var k = new Uint8Array(32); - crypto_box_beforenm(k, y, x); - return crypto_box_afternm(c, m, d, n, k); +function scalarbase(p, s) { + var q = [gf(), gf(), gf(), gf()]; + set25519(q[0], X); + set25519(q[1], Y); + set25519(q[2], gf1); + M(q[3], X, Y); + scalarmult(p, q, s); } -function crypto_box_open(m, c, d, n, y, x) { - var k = new Uint8Array(32); - crypto_box_beforenm(k, y, x); - return crypto_box_open_afternm(m, c, d, n, k); -} +function crypto_sign_keypair(pk, sk, seeded) { + var d = new Uint8Array(64); + var p = [gf(), gf(), gf(), gf()]; + var i; -var K = [ - 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, - 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, - 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, - 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, - 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, - 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, - 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, - 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, - 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, - 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, - 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, - 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, - 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, - 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, - 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, - 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, - 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, - 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, - 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, - 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, - 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, - 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, - 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, - 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, - 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, - 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, - 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, - 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, - 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, - 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, - 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, - 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, - 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, - 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, - 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, - 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, - 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, - 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, - 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, - 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 -]; + if (!seeded) randombytes(sk, 32); + crypto_hash(d, sk, 32); + d[0] &= 248; + d[31] &= 127; + d[31] |= 64; -function crypto_hashblocks_hl(hh, hl, m, n) { - var wh = new Int32Array(16), wl = new Int32Array(16), - bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, - bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, - th, tl, i, j, h, l, a, b, c, d; + scalarbase(p, d); + pack(pk, p); - var ah0 = hh[0], - ah1 = hh[1], - ah2 = hh[2], - ah3 = hh[3], - ah4 = hh[4], - ah5 = hh[5], - ah6 = hh[6], - ah7 = hh[7], + for (i = 0; i < 32; i++) sk[i+32] = pk[i]; + return 0; +} - al0 = hl[0], - al1 = hl[1], - al2 = hl[2], - al3 = hl[3], - al4 = hl[4], - al5 = hl[5], - al6 = hl[6], - al7 = hl[7]; +var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); - var pos = 0; - while (n >= 128) { - for (i = 0; i < 16; i++) { - j = 8 * i + pos; - wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3]; - wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7]; +function modL(r, x) { + var carry, i, j, k; + for (i = 63; i >= 32; --i) { + carry = 0; + for (j = i - 32, k = i - 12; j < k; ++j) { + x[j] += carry - 16 * x[i] * L[j - (i - 32)]; + carry = (x[j] + 128) >> 8; + x[j] -= carry * 256; } - for (i = 0; i < 80; i++) { - bh0 = ah0; - bh1 = ah1; - bh2 = ah2; - bh3 = ah3; - bh4 = ah4; - bh5 = ah5; - bh6 = ah6; - bh7 = ah7; - - bl0 = al0; - bl1 = al1; - bl2 = al2; - bl3 = al3; - bl4 = al4; - bl5 = al5; - bl6 = al6; - bl7 = al7; - - // add - h = ah7; - l = al7; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + x[j] += carry; + x[i] = 0; + } + carry = 0; + for (j = 0; j < 32; j++) { + x[j] += carry - (x[31] >> 4) * L[j]; + carry = x[j] >> 8; + x[j] &= 255; + } + for (j = 0; j < 32; j++) x[j] -= carry * L[j]; + for (i = 0; i < 32; i++) { + x[i+1] += x[i] >> 8; + r[i] = x[i] & 255; + } +} - // Sigma1 - h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32)))); - l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32)))); +function reduce(r) { + var x = new Float64Array(64), i; + for (i = 0; i < 64; i++) x[i] = r[i]; + for (i = 0; i < 64; i++) r[i] = 0; + modL(r, x); +} - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +// Note: difference from C - smlen returned, not passed as argument. +function crypto_sign(sm, m, n, sk) { + var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); + var i, j, x = new Float64Array(64); + var p = [gf(), gf(), gf(), gf()]; - // Ch - h = (ah4 & ah5) ^ (~ah4 & ah6); - l = (al4 & al5) ^ (~al4 & al6); + crypto_hash(d, sk, 32); + d[0] &= 248; + d[31] &= 127; + d[31] |= 64; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + var smlen = n + 64; + for (i = 0; i < n; i++) sm[64 + i] = m[i]; + for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]; - // K - h = K[i*2]; - l = K[i*2+1]; + crypto_hash(r, sm.subarray(32), n+32); + reduce(r); + scalarbase(p, r); + pack(sm, p); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + for (i = 32; i < 64; i++) sm[i] = sk[i]; + crypto_hash(h, sm, n + 64); + reduce(h); - // w - h = wh[i%16]; - l = wl[i%16]; + for (i = 0; i < 64; i++) x[i] = 0; + for (i = 0; i < 32; i++) x[i] = r[i]; + for (i = 0; i < 32; i++) { + for (j = 0; j < 32; j++) { + x[i+j] += h[i] * d[j]; + } + } - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + modL(sm.subarray(32), x); + return smlen; +} - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +function unpackneg(r, p) { + var t = gf(), chk = gf(), num = gf(), + den = gf(), den2 = gf(), den4 = gf(), + den6 = gf(); - th = c & 0xffff | d << 16; - tl = a & 0xffff | b << 16; + set25519(r[2], gf1); + unpack25519(r[1], p); + S(num, r[1]); + M(den, num, D); + Z(num, num, r[2]); + A(den, r[2], den); - // add - h = th; - l = tl; + S(den2, den); + S(den4, den2); + M(den6, den4, den2); + M(t, den6, num); + M(t, t, den); - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + pow2523(t, t); + M(t, t, num); + M(t, t, den); + M(t, t, den); + M(r[0], t, den); - // Sigma0 - h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32)))); - l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32)))); + S(chk, r[0]); + M(chk, chk, den); + if (neq25519(chk, num)) M(r[0], r[0], I); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + S(chk, r[0]); + M(chk, chk, den); + if (neq25519(chk, num)) return -1; - // Maj - h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); - l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2); + if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + M(r[3], r[0], r[1]); + return 0; +} - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +function crypto_sign_open(m, sm, n, pk) { + var i, mlen; + var t = new Uint8Array(32), h = new Uint8Array(64); + var p = [gf(), gf(), gf(), gf()], + q = [gf(), gf(), gf(), gf()]; - bh7 = (c & 0xffff) | (d << 16); - bl7 = (a & 0xffff) | (b << 16); + mlen = -1; + if (n < 64) return -1; - // add - h = bh3; - l = bl3; + if (unpackneg(q, pk)) return -1; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + for (i = 0; i < n; i++) m[i] = sm[i]; + for (i = 0; i < 32; i++) m[i+32] = pk[i]; + crypto_hash(h, m, n); + reduce(h); + scalarmult(p, q, h); - h = th; - l = tl; + scalarbase(q, sm.subarray(32)); + add(p, q); + pack(t, p); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + n -= 64; + if (crypto_verify_32(sm, 0, t, 0)) { + for (i = 0; i < n; i++) m[i] = 0; + return -1; + } - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + for (i = 0; i < n; i++) m[i] = sm[i + 64]; + mlen = n; + return mlen; +} - bh3 = (c & 0xffff) | (d << 16); - bl3 = (a & 0xffff) | (b << 16); +var crypto_secretbox_KEYBYTES = 32, + crypto_secretbox_NONCEBYTES = 24, + crypto_secretbox_ZEROBYTES = 32, + crypto_secretbox_BOXZEROBYTES = 16, + crypto_scalarmult_BYTES = 32, + crypto_scalarmult_SCALARBYTES = 32, + crypto_box_PUBLICKEYBYTES = 32, + crypto_box_SECRETKEYBYTES = 32, + crypto_box_BEFORENMBYTES = 32, + crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, + crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, + crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, + crypto_sign_BYTES = 64, + crypto_sign_PUBLICKEYBYTES = 32, + crypto_sign_SECRETKEYBYTES = 64, + crypto_sign_SEEDBYTES = 32, + crypto_hash_BYTES = 64; - ah1 = bh0; - ah2 = bh1; - ah3 = bh2; - ah4 = bh3; - ah5 = bh4; - ah6 = bh5; - ah7 = bh6; - ah0 = bh7; +nacl.lowlevel = { + crypto_core_hsalsa20: crypto_core_hsalsa20, + crypto_stream_xor: crypto_stream_xor, + crypto_stream: crypto_stream, + crypto_stream_salsa20_xor: crypto_stream_salsa20_xor, + crypto_stream_salsa20: crypto_stream_salsa20, + crypto_onetimeauth: crypto_onetimeauth, + crypto_onetimeauth_verify: crypto_onetimeauth_verify, + crypto_verify_16: crypto_verify_16, + crypto_verify_32: crypto_verify_32, + crypto_secretbox: crypto_secretbox, + crypto_secretbox_open: crypto_secretbox_open, + crypto_scalarmult: crypto_scalarmult, + crypto_scalarmult_base: crypto_scalarmult_base, + crypto_box_beforenm: crypto_box_beforenm, + crypto_box_afternm: crypto_box_afternm, + crypto_box: crypto_box, + crypto_box_open: crypto_box_open, + crypto_box_keypair: crypto_box_keypair, + crypto_hash: crypto_hash, + crypto_sign: crypto_sign, + crypto_sign_keypair: crypto_sign_keypair, + crypto_sign_open: crypto_sign_open, - al1 = bl0; - al2 = bl1; - al3 = bl2; - al4 = bl3; - al5 = bl4; - al6 = bl5; - al7 = bl6; - al0 = bl7; + crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES, + crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES, + crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES, + crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES, + crypto_scalarmult_BYTES: crypto_scalarmult_BYTES, + crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES, + crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES, + crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES, + crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES, + crypto_box_NONCEBYTES: crypto_box_NONCEBYTES, + crypto_box_ZEROBYTES: crypto_box_ZEROBYTES, + crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES, + crypto_sign_BYTES: crypto_sign_BYTES, + crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES, + crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES, + crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES, + crypto_hash_BYTES: crypto_hash_BYTES +}; - if (i%16 === 15) { - for (j = 0; j < 16; j++) { - // add - h = wh[j]; - l = wl[j]; +/* High-level API */ - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +function checkLengths(k, n) { + if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size'); + if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size'); +} - h = wh[(j+9)%16]; - l = wl[(j+9)%16]; +function checkBoxLengths(pk, sk) { + if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size'); + if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size'); +} - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +function checkArrayTypes() { + for (var i = 0; i < arguments.length; i++) { + if (!(arguments[i] instanceof Uint8Array)) + throw new TypeError('unexpected type, use Uint8Array'); + } +} - // sigma0 - th = wh[(j+1)%16]; - tl = wl[(j+1)%16]; - h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7); - l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7))); +function cleanup(arr) { + for (var i = 0; i < arr.length; i++) arr[i] = 0; +} - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.randomBytes = function(n) { + var b = new Uint8Array(n); + randombytes(b, n); + return b; +}; - // sigma1 - th = wh[(j+14)%16]; - tl = wl[(j+14)%16]; - h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6); - l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6))); +nacl.secretbox = function(msg, nonce, key) { + checkArrayTypes(msg, nonce, key); + checkLengths(key, nonce); + var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length); + var c = new Uint8Array(m.length); + for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i]; + crypto_secretbox(c, m, m.length, nonce, key); + return c.subarray(crypto_secretbox_BOXZEROBYTES); +}; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.secretbox.open = function(box, nonce, key) { + checkArrayTypes(box, nonce, key); + checkLengths(key, nonce); + var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length); + var m = new Uint8Array(c.length); + for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i]; + if (c.length < 32) return null; + if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null; + return m.subarray(crypto_secretbox_ZEROBYTES); +}; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES; +nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES; +nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES; - wh[j] = (c & 0xffff) | (d << 16); - wl[j] = (a & 0xffff) | (b << 16); - } - } - } +nacl.scalarMult = function(n, p) { + checkArrayTypes(n, p); + if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); + if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size'); + var q = new Uint8Array(crypto_scalarmult_BYTES); + crypto_scalarmult(q, n, p); + return q; +}; - // add - h = ah0; - l = al0; +nacl.scalarMult.base = function(n) { + checkArrayTypes(n); + if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); + var q = new Uint8Array(crypto_scalarmult_BYTES); + crypto_scalarmult_base(q, n); + return q; +}; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES; +nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES; - h = hh[0]; - l = hl[0]; +nacl.box = function(msg, nonce, publicKey, secretKey) { + var k = nacl.box.before(publicKey, secretKey); + return nacl.secretbox(msg, nonce, k); +}; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.box.before = function(publicKey, secretKey) { + checkArrayTypes(publicKey, secretKey); + checkBoxLengths(publicKey, secretKey); + var k = new Uint8Array(crypto_box_BEFORENMBYTES); + crypto_box_beforenm(k, publicKey, secretKey); + return k; +}; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +nacl.box.after = nacl.secretbox; - hh[0] = ah0 = (c & 0xffff) | (d << 16); - hl[0] = al0 = (a & 0xffff) | (b << 16); +nacl.box.open = function(msg, nonce, publicKey, secretKey) { + var k = nacl.box.before(publicKey, secretKey); + return nacl.secretbox.open(msg, nonce, k); +}; - h = ah1; - l = al1; +nacl.box.open.after = nacl.secretbox.open; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +nacl.box.keyPair = function() { + var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_box_SECRETKEYBYTES); + crypto_box_keypair(pk, sk); + return {publicKey: pk, secretKey: sk}; +}; - h = hh[1]; - l = hl[1]; +nacl.box.keyPair.fromSecretKey = function(secretKey) { + checkArrayTypes(secretKey); + if (secretKey.length !== crypto_box_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); + crypto_scalarmult_base(pk, secretKey); + return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; +}; + +nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES; +nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES; +nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES; +nacl.box.nonceLength = crypto_box_NONCEBYTES; +nacl.box.overheadLength = nacl.secretbox.overheadLength; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.sign = function(msg, secretKey) { + checkArrayTypes(msg, secretKey); + if (secretKey.length !== crypto_sign_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length); + crypto_sign(signedMsg, msg, msg.length, secretKey); + return signedMsg; +}; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +nacl.sign.open = function(signedMsg, publicKey) { + checkArrayTypes(signedMsg, publicKey); + if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) + throw new Error('bad public key size'); + var tmp = new Uint8Array(signedMsg.length); + var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey); + if (mlen < 0) return null; + var m = new Uint8Array(mlen); + for (var i = 0; i < m.length; i++) m[i] = tmp[i]; + return m; +}; - hh[1] = ah1 = (c & 0xffff) | (d << 16); - hl[1] = al1 = (a & 0xffff) | (b << 16); +nacl.sign.detached = function(msg, secretKey) { + var signedMsg = nacl.sign(msg, secretKey); + var sig = new Uint8Array(crypto_sign_BYTES); + for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; + return sig; +}; - h = ah2; - l = al2; +nacl.sign.detached.verify = function(msg, sig, publicKey) { + checkArrayTypes(msg, sig, publicKey); + if (sig.length !== crypto_sign_BYTES) + throw new Error('bad signature size'); + if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) + throw new Error('bad public key size'); + var sm = new Uint8Array(crypto_sign_BYTES + msg.length); + var m = new Uint8Array(crypto_sign_BYTES + msg.length); + var i; + for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]; + for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i]; + return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); +}; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +nacl.sign.keyPair = function() { + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); + crypto_sign_keypair(pk, sk); + return {publicKey: pk, secretKey: sk}; +}; - h = hh[2]; - l = hl[2]; +nacl.sign.keyPair.fromSecretKey = function(secretKey) { + checkArrayTypes(secretKey); + if (secretKey.length !== crypto_sign_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i]; + return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; +}; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +nacl.sign.keyPair.fromSeed = function(seed) { + checkArrayTypes(seed); + if (seed.length !== crypto_sign_SEEDBYTES) + throw new Error('bad seed size'); + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); + for (var i = 0; i < 32; i++) sk[i] = seed[i]; + crypto_sign_keypair(pk, sk, true); + return {publicKey: pk, secretKey: sk}; +}; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; +nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; +nacl.sign.seedLength = crypto_sign_SEEDBYTES; +nacl.sign.signatureLength = crypto_sign_BYTES; - hh[2] = ah2 = (c & 0xffff) | (d << 16); - hl[2] = al2 = (a & 0xffff) | (b << 16); +nacl.hash = function(msg) { + checkArrayTypes(msg); + var h = new Uint8Array(crypto_hash_BYTES); + crypto_hash(h, msg, msg.length); + return h; +}; - h = ah3; - l = al3; +nacl.hash.hashLength = crypto_hash_BYTES; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +nacl.verify = function(x, y) { + checkArrayTypes(x, y); + // Zero length arguments are considered not equal. + if (x.length === 0 || y.length === 0) return false; + if (x.length !== y.length) return false; + return (vn(x, 0, y, 0, x.length) === 0) ? true : false; +}; - h = hh[3]; - l = hl[3]; +nacl.setPRNG = function(fn) { + randombytes = fn; +}; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +(function() { + // Initialize PRNG if environment provides CSPRNG. + // If not, methods calling randombytes will throw. + var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null; + if (crypto && crypto.getRandomValues) { + // Browsers. + var QUOTA = 65536; + nacl.setPRNG(function(x, n) { + var i, v = new Uint8Array(n); + for (i = 0; i < n; i += QUOTA) { + crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); + } + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); + } else if (true) { + // Node.js. + crypto = __webpack_require__(3); + if (crypto && crypto.randomBytes) { + nacl.setPRNG(function(x, n) { + var i, v = crypto.randomBytes(n); + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); + } + } +})(); - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +})( true && module.exports ? module.exports : (self.nacl = self.nacl || {})); - hh[3] = ah3 = (c & 0xffff) | (d << 16); - hl[3] = al3 = (a & 0xffff) | (b << 16); - h = ah4; - l = al4; +/***/ }), +/* 1 */ +/***/ (function(module, exports, __webpack_require__) { - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +// Written in 2014-2016 by Dmitry Chestnykh and Devi Mandiri. +// Public domain. +(function(root, f) { + 'use strict'; + if ( true && module.exports) module.exports = f(); + else if (root.nacl) root.nacl.util = f(); + else { + root.nacl = {}; + root.nacl.util = f(); + } +}(this, function() { + 'use strict'; - h = hh[4]; - l = hl[4]; + var util = {}; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + function validateBase64(s) { + if (!(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(s))) { + throw new TypeError('invalid encoding'); + } + } - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + util.decodeUTF8 = function(s) { + if (typeof s !== 'string') throw new TypeError('expected string'); + var i, d = unescape(encodeURIComponent(s)), b = new Uint8Array(d.length); + for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); + return b; + }; - hh[4] = ah4 = (c & 0xffff) | (d << 16); - hl[4] = al4 = (a & 0xffff) | (b << 16); + util.encodeUTF8 = function(arr) { + var i, s = []; + for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i])); + return decodeURIComponent(escape(s.join(''))); + }; - h = ah5; - l = al5; + if (typeof atob === 'undefined') { + // Node.js - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + if (typeof Buffer.from !== 'undefined') { + // Node v6 and later + util.encodeBase64 = function (arr) { // v6 and later + return Buffer.from(arr).toString('base64'); + }; - h = hh[5]; - l = hl[5]; + util.decodeBase64 = function (s) { + validateBase64(s); + return new Uint8Array(Array.prototype.slice.call(Buffer.from(s, 'base64'), 0)); + }; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + } else { + // Node earlier than v6 + util.encodeBase64 = function (arr) { // v6 and later + return (new Buffer(arr)).toString('base64'); + }; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + util.decodeBase64 = function(s) { + validateBase64(s); + return new Uint8Array(Array.prototype.slice.call(new Buffer(s, 'base64'), 0)); + }; + } - hh[5] = ah5 = (c & 0xffff) | (d << 16); - hl[5] = al5 = (a & 0xffff) | (b << 16); + } else { + // Browsers - h = ah6; - l = al6; + util.encodeBase64 = function(arr) { + var i, s = [], len = arr.length; + for (i = 0; i < len; i++) s.push(String.fromCharCode(arr[i])); + return btoa(s.join('')); + }; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + util.decodeBase64 = function(s) { + validateBase64(s); + var i, d = atob(s), b = new Uint8Array(d.length); + for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); + return b; + }; - h = hh[6]; - l = hl[6]; + } - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + return util; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +})); - hh[6] = ah6 = (c & 0xffff) | (d << 16); - hl[6] = al6 = (a & 0xffff) | (b << 16); - h = ah7; - l = al7; +/***/ }), +/* 2 */ +/***/ (function(module, exports, __webpack_require__) { - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +// required so we don't have to do require('pusher').default etc. +module.exports = __webpack_require__(4).default; - h = hh[7]; - l = hl[7]; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +/***/ }), +/* 3 */ +/***/ (function(module, exports) { - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +/* (ignored) */ - hh[7] = ah7 = (c & 0xffff) | (d << 16); - hl[7] = al7 = (a & 0xffff) | (b << 16); +/***/ }), +/* 4 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { - pos += 128; - n -= 128; - } +"use strict"; +__webpack_require__.r(__webpack_exports__); - return n; +// CONCATENATED MODULE: ./src/core/base64.ts +function encode(s) { + return btoa(utob(s)); } +var fromCharCode = String.fromCharCode; +var b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; +var b64tab = {}; +for (var base64_i = 0, l = b64chars.length; base64_i < l; base64_i++) { + b64tab[b64chars.charAt(base64_i)] = base64_i; +} +var cb_utob = function (c) { + var cc = c.charCodeAt(0); + return cc < 0x80 + ? c + : cc < 0x800 + ? fromCharCode(0xc0 | (cc >>> 6)) + fromCharCode(0x80 | (cc & 0x3f)) + : fromCharCode(0xe0 | ((cc >>> 12) & 0x0f)) + + fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) + + fromCharCode(0x80 | (cc & 0x3f)); +}; +var utob = function (u) { + return u.replace(/[^\x00-\x7F]/g, cb_utob); +}; +var cb_encode = function (ccc) { + var padlen = [0, 2, 1][ccc.length % 3]; + var ord = (ccc.charCodeAt(0) << 16) | + ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8) | + (ccc.length > 2 ? ccc.charCodeAt(2) : 0); + var chars = [ + b64chars.charAt(ord >>> 18), + b64chars.charAt((ord >>> 12) & 63), + padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63), + padlen >= 1 ? '=' : b64chars.charAt(ord & 63) + ]; + return chars.join(''); +}; +var btoa = self.btoa || + function (b) { + return b.replace(/[\s\S]{1,3}/g, cb_encode); + }; -function crypto_hash(out, m, n) { - var hh = new Int32Array(8), - hl = new Int32Array(8), - x = new Uint8Array(256), - i, b = n; - - hh[0] = 0x6a09e667; - hh[1] = 0xbb67ae85; - hh[2] = 0x3c6ef372; - hh[3] = 0xa54ff53a; - hh[4] = 0x510e527f; - hh[5] = 0x9b05688c; - hh[6] = 0x1f83d9ab; - hh[7] = 0x5be0cd19; +// CONCATENATED MODULE: ./src/core/utils/timers/abstract_timer.ts +var Timer = (function () { + function Timer(set, clear, delay, callback) { + var _this = this; + this.clear = clear; + this.timer = set(function () { + if (_this.timer) { + _this.timer = callback(_this.timer); + } + }, delay); + } + Timer.prototype.isRunning = function () { + return this.timer !== null; + }; + Timer.prototype.ensureAborted = function () { + if (this.timer) { + this.clear(this.timer); + this.timer = null; + } + }; + return Timer; +}()); +/* harmony default export */ var abstract_timer = (Timer); - hl[0] = 0xf3bcc908; - hl[1] = 0x84caa73b; - hl[2] = 0xfe94f82b; - hl[3] = 0x5f1d36f1; - hl[4] = 0xade682d1; - hl[5] = 0x2b3e6c1f; - hl[6] = 0xfb41bd6b; - hl[7] = 0x137e2179; +// CONCATENATED MODULE: ./src/core/utils/timers/index.ts +var __extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); - crypto_hashblocks_hl(hh, hl, m, n); - n %= 128; +function timers_clearTimeout(timer) { + self.clearTimeout(timer); +} +function timers_clearInterval(timer) { + self.clearInterval(timer); +} +var OneOffTimer = (function (_super) { + __extends(OneOffTimer, _super); + function OneOffTimer(delay, callback) { + return _super.call(this, setTimeout, timers_clearTimeout, delay, function (timer) { + callback(); + return null; + }) || this; + } + return OneOffTimer; +}(abstract_timer)); - for (i = 0; i < n; i++) x[i] = m[b-n+i]; - x[n] = 128; +var PeriodicTimer = (function (_super) { + __extends(PeriodicTimer, _super); + function PeriodicTimer(delay, callback) { + return _super.call(this, setInterval, timers_clearInterval, delay, function (timer) { + callback(); + return timer; + }) || this; + } + return PeriodicTimer; +}(abstract_timer)); - n = 256-128*(n<112?1:0); - x[n-9] = 0; - ts64(x, n-8, (b / 0x20000000) | 0, b << 3); - crypto_hashblocks_hl(hh, hl, x, n); - for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); +// CONCATENATED MODULE: ./src/core/util.ts - return 0; -} +var Util = { + now: function () { + if (Date.now) { + return Date.now(); + } + else { + return new Date().valueOf(); + } + }, + defer: function (callback) { + return new OneOffTimer(0, callback); + }, + method: function (name) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + var boundArguments = Array.prototype.slice.call(arguments, 1); + return function (object) { + return object[name].apply(object, boundArguments.concat(arguments)); + }; + } +}; +/* harmony default export */ var util = (Util); -function add(p, q) { - var a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(), - g = gf(), h = gf(), t = gf(); +// CONCATENATED MODULE: ./src/core/utils/collections.ts - Z(a, p[1], p[0]); - Z(t, q[1], q[0]); - M(a, a, t); - A(b, p[0], p[1]); - A(t, q[0], q[1]); - M(b, b, t); - M(c, p[3], q[3]); - M(c, c, D2); - M(d, p[2], q[2]); - A(d, d, d); - Z(e, b, a); - Z(f, d, c); - A(g, d, c); - A(h, b, a); - M(p[0], e, f); - M(p[1], h, g); - M(p[2], g, f); - M(p[3], e, h); +function extend(target) { + var sources = []; + for (var _i = 1; _i < arguments.length; _i++) { + sources[_i - 1] = arguments[_i]; + } + for (var i = 0; i < sources.length; i++) { + var extensions = sources[i]; + for (var property in extensions) { + if (extensions[property] && extensions[property].constructor && + extensions[property].constructor === Object) { + target[property] = extend(target[property] || {}, extensions[property]); + } + else { + target[property] = extensions[property]; + } + } + } + return target; +} +function stringify() { + var m = ["Pusher"]; + for (var i = 0; i < arguments.length; i++) { + if (typeof arguments[i] === "string") { + m.push(arguments[i]); + } + else { + m.push(safeJSONStringify(arguments[i])); + } + } + return m.join(" : "); +} +function arrayIndexOf(array, item) { + var nativeIndexOf = Array.prototype.indexOf; + if (array === null) { + return -1; + } + if (nativeIndexOf && array.indexOf === nativeIndexOf) { + return array.indexOf(item); + } + for (var i = 0, l = array.length; i < l; i++) { + if (array[i] === item) { + return i; + } + } + return -1; +} +function objectApply(object, f) { + for (var key in object) { + if (Object.prototype.hasOwnProperty.call(object, key)) { + f(object[key], key, object); + } + } +} +function keys(object) { + var keys = []; + objectApply(object, function (_, key) { + keys.push(key); + }); + return keys; +} +function values(object) { + var values = []; + objectApply(object, function (value) { + values.push(value); + }); + return values; +} +function apply(array, f, context) { + for (var i = 0; i < array.length; i++) { + f.call(context || self, array[i], i, array); + } +} +function map(array, f) { + var result = []; + for (var i = 0; i < array.length; i++) { + result.push(f(array[i], i, array, result)); + } + return result; } - -function cswap(p, q, b) { - var i; - for (i = 0; i < 4; i++) { - sel25519(p[i], q[i], b); - } +function mapObject(object, f) { + var result = {}; + objectApply(object, function (value, key) { + result[key] = f(value); + }); + return result; } - -function pack(r, p) { - var tx = gf(), ty = gf(), zi = gf(); - inv25519(zi, p[2]); - M(tx, p[0], zi); - M(ty, p[1], zi); - pack25519(r, ty); - r[31] ^= par25519(tx) << 7; +function filter(array, test) { + test = test || function (value) { return !!value; }; + var result = []; + for (var i = 0; i < array.length; i++) { + if (test(array[i], i, array, result)) { + result.push(array[i]); + } + } + return result; } - -function scalarmult(p, q, s) { - var b, i; - set25519(p[0], gf0); - set25519(p[1], gf1); - set25519(p[2], gf1); - set25519(p[3], gf0); - for (i = 255; i >= 0; --i) { - b = (s[(i/8)|0] >> (i&7)) & 1; - cswap(p, q, b); - add(q, p); - add(p, p); - cswap(p, q, b); - } +function filterObject(object, test) { + var result = {}; + objectApply(object, function (value, key) { + if ((test && test(value, key, object, result)) || Boolean(value)) { + result[key] = value; + } + }); + return result; } - -function scalarbase(p, s) { - var q = [gf(), gf(), gf(), gf()]; - set25519(q[0], X); - set25519(q[1], Y); - set25519(q[2], gf1); - M(q[3], X, Y); - scalarmult(p, q, s); +function flatten(object) { + var result = []; + objectApply(object, function (value, key) { + result.push([key, value]); + }); + return result; } - -function crypto_sign_keypair(pk, sk, seeded) { - var d = new Uint8Array(64); - var p = [gf(), gf(), gf(), gf()]; - var i; - - if (!seeded) randombytes(sk, 32); - crypto_hash(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; - - scalarbase(p, d); - pack(pk, p); - - for (i = 0; i < 32; i++) sk[i+32] = pk[i]; - return 0; +function any(array, test) { + for (var i = 0; i < array.length; i++) { + if (test(array[i], i, array)) { + return true; + } + } + return false; } - -var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); - -function modL(r, x) { - var carry, i, j, k; - for (i = 63; i >= 32; --i) { - carry = 0; - for (j = i - 32, k = i - 12; j < k; ++j) { - x[j] += carry - 16 * x[i] * L[j - (i - 32)]; - carry = (x[j] + 128) >> 8; - x[j] -= carry * 256; +function collections_all(array, test) { + for (var i = 0; i < array.length; i++) { + if (!test(array[i], i, array)) { + return false; + } } - x[j] += carry; - x[i] = 0; - } - carry = 0; - for (j = 0; j < 32; j++) { - x[j] += carry - (x[31] >> 4) * L[j]; - carry = x[j] >> 8; - x[j] &= 255; - } - for (j = 0; j < 32; j++) x[j] -= carry * L[j]; - for (i = 0; i < 32; i++) { - x[i+1] += x[i] >> 8; - r[i] = x[i] & 255; - } + return true; } - -function reduce(r) { - var x = new Float64Array(64), i; - for (i = 0; i < 64; i++) x[i] = r[i]; - for (i = 0; i < 64; i++) r[i] = 0; - modL(r, x); +function encodeParamsObject(data) { + return mapObject(data, function (value) { + if (typeof value === "object") { + value = safeJSONStringify(value); + } + return encodeURIComponent(encode(value.toString())); + }); +} +function buildQueryString(data) { + var params = filterObject(data, function (value) { + return value !== undefined; + }); + var query = map(flatten(encodeParamsObject(params)), util.method("join", "=")).join("&"); + return query; +} +function decycleObject(object) { + var objects = [], paths = []; + return (function derez(value, path) { + var i, name, nu; + switch (typeof value) { + case 'object': + if (!value) { + return null; + } + for (i = 0; i < objects.length; i += 1) { + if (objects[i] === value) { + return { $ref: paths[i] }; + } + } + objects.push(value); + paths.push(path); + if (Object.prototype.toString.apply(value) === '[object Array]') { + nu = []; + for (i = 0; i < value.length; i += 1) { + nu[i] = derez(value[i], path + '[' + i + ']'); + } + } + else { + nu = {}; + for (name in value) { + if (Object.prototype.hasOwnProperty.call(value, name)) { + nu[name] = derez(value[name], path + '[' + JSON.stringify(name) + ']'); + } + } + } + return nu; + case 'number': + case 'string': + case 'boolean': + return value; + } + }(object, '$')); +} +function safeJSONStringify(source) { + try { + return JSON.stringify(source); + } + catch (e) { + return JSON.stringify(decycleObject(source)); + } } -// Note: difference from C - smlen returned, not passed as argument. -function crypto_sign(sm, m, n, sk) { - var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); - var i, j, x = new Float64Array(64); - var p = [gf(), gf(), gf(), gf()]; - - crypto_hash(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; - - var smlen = n + 64; - for (i = 0; i < n; i++) sm[64 + i] = m[i]; - for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]; - - crypto_hash(r, sm.subarray(32), n+32); - reduce(r); - scalarbase(p, r); - pack(sm, p); +// CONCATENATED MODULE: ./src/core/defaults.ts +var Defaults = { + VERSION: "5.0.2", + PROTOCOL: 7, + host: 'ws.pusherapp.com', + ws_port: 80, + wss_port: 443, + ws_path: '', + sockjs_host: 'sockjs.pusher.com', + sockjs_http_port: 80, + sockjs_https_port: 443, + sockjs_path: '/pusher', + stats_host: 'stats.pusher.com', + channel_auth_endpoint: '/pusher/auth', + channel_auth_transport: 'ajax', + activity_timeout: 120000, + pong_timeout: 30000, + unavailable_timeout: 10000, + cdn_http: "http://js.pusher.com", + cdn_https: "https://js.pusher.com", + dependency_suffix: "" +}; +/* harmony default export */ var defaults = (Defaults); - for (i = 32; i < 64; i++) sm[i] = sk[i]; - crypto_hash(h, sm, n + 64); - reduce(h); +// CONCATENATED MODULE: ./src/core/transports/url_schemes.ts - for (i = 0; i < 64; i++) x[i] = 0; - for (i = 0; i < 32; i++) x[i] = r[i]; - for (i = 0; i < 32; i++) { - for (j = 0; j < 32; j++) { - x[i+j] += h[i] * d[j]; +function getGenericURL(baseScheme, params, path) { + var scheme = baseScheme + (params.useTLS ? "s" : ""); + var host = params.useTLS ? params.hostTLS : params.hostNonTLS; + return scheme + "://" + host + path; +} +function getGenericPath(key, queryString) { + var path = "/app/" + key; + var query = "?protocol=" + defaults.PROTOCOL + + "&client=js" + + "&version=" + defaults.VERSION + + (queryString ? ("&" + queryString) : ""); + return path + query; +} +var ws = { + getInitial: function (key, params) { + var path = (params.httpPath || "") + getGenericPath(key, "flash=false"); + return getGenericURL("ws", params, path); + } +}; +var http = { + getInitial: function (key, params) { + var path = (params.httpPath || "/pusher") + getGenericPath(key); + return getGenericURL("http", params, path); + } +}; +var sockjs = { + getInitial: function (key, params) { + return getGenericURL("http", params, params.httpPath || "/pusher"); + }, + getPath: function (key, params) { + return getGenericPath(key); } - } +}; - modL(sm.subarray(32), x); - return smlen; +// CONCATENATED MODULE: ./src/core/events/callback_registry.ts + +var callback_registry_CallbackRegistry = (function () { + function CallbackRegistry() { + this._callbacks = {}; + } + CallbackRegistry.prototype.get = function (name) { + return this._callbacks[prefix(name)]; + }; + CallbackRegistry.prototype.add = function (name, callback, context) { + var prefixedEventName = prefix(name); + this._callbacks[prefixedEventName] = this._callbacks[prefixedEventName] || []; + this._callbacks[prefixedEventName].push({ + fn: callback, + context: context + }); + }; + CallbackRegistry.prototype.remove = function (name, callback, context) { + if (!name && !callback && !context) { + this._callbacks = {}; + return; + } + var names = name ? [prefix(name)] : keys(this._callbacks); + if (callback || context) { + this.removeCallback(names, callback, context); + } + else { + this.removeAllCallbacks(names); + } + }; + CallbackRegistry.prototype.removeCallback = function (names, callback, context) { + apply(names, function (name) { + this._callbacks[name] = filter(this._callbacks[name] || [], function (binding) { + return (callback && callback !== binding.fn) || + (context && context !== binding.context); + }); + if (this._callbacks[name].length === 0) { + delete this._callbacks[name]; + } + }, this); + }; + CallbackRegistry.prototype.removeAllCallbacks = function (names) { + apply(names, function (name) { + delete this._callbacks[name]; + }, this); + }; + return CallbackRegistry; +}()); +/* harmony default export */ var callback_registry = (callback_registry_CallbackRegistry); +function prefix(name) { + return "_" + name; } -function unpackneg(r, p) { - var t = gf(), chk = gf(), num = gf(), - den = gf(), den2 = gf(), den4 = gf(), - den6 = gf(); +// CONCATENATED MODULE: ./src/core/events/dispatcher.ts - set25519(r[2], gf1); - unpack25519(r[1], p); - S(num, r[1]); - M(den, num, D); - Z(num, num, r[2]); - A(den, r[2], den); - S(den2, den); - S(den4, den2); - M(den6, den4, den2); - M(t, den6, num); - M(t, t, den); +var dispatcher_Dispatcher = (function () { + function Dispatcher(failThrough) { + this.callbacks = new callback_registry(); + this.global_callbacks = []; + this.failThrough = failThrough; + } + Dispatcher.prototype.bind = function (eventName, callback, context) { + this.callbacks.add(eventName, callback, context); + return this; + }; + Dispatcher.prototype.bind_global = function (callback) { + this.global_callbacks.push(callback); + return this; + }; + Dispatcher.prototype.unbind = function (eventName, callback, context) { + this.callbacks.remove(eventName, callback, context); + return this; + }; + Dispatcher.prototype.unbind_global = function (callback) { + if (!callback) { + this.global_callbacks = []; + return this; + } + this.global_callbacks = filter(this.global_callbacks || [], function (c) { return c !== callback; }); + return this; + }; + Dispatcher.prototype.unbind_all = function () { + this.unbind(); + this.unbind_global(); + return this; + }; + Dispatcher.prototype.emit = function (eventName, data, metadata) { + for (var i = 0; i < this.global_callbacks.length; i++) { + this.global_callbacks[i](eventName, data); + } + var callbacks = this.callbacks.get(eventName); + var args = []; + if (metadata) { + args.push(data, metadata); + } + else if (data) { + args.push(data); + } + if (callbacks && callbacks.length > 0) { + for (var i = 0; i < callbacks.length; i++) { + callbacks[i].fn.apply(callbacks[i].context || self, args); + } + } + else if (this.failThrough) { + this.failThrough(eventName, data); + } + return this; + }; + return Dispatcher; +}()); +/* harmony default export */ var dispatcher = (dispatcher_Dispatcher); - pow2523(t, t); - M(t, t, num); - M(t, t, den); - M(t, t, den); - M(r[0], t, den); +// CONCATENATED MODULE: ./src/core/logger.ts - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) M(r[0], r[0], I); - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) return -1; +var Logger = { + debug: function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + if (!core_pusher.log) { + return; + } + core_pusher.log(stringify.apply(this, arguments)); + }, + warn: function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + var message = stringify.apply(this, arguments); + if (core_pusher.log) { + core_pusher.log(message); + } + else if (self.console) { + if (self.console.warn) { + self.console.warn(message); + } + else if (self.console.log) { + self.console.log(message); + } + } + } +}; +/* harmony default export */ var logger = (Logger); - if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]); +// CONCATENATED MODULE: ./src/core/transports/transport_connection.ts +var transport_connection_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); - M(r[3], r[0], r[1]); - return 0; -} -function crypto_sign_open(m, sm, n, pk) { - var i, mlen; - var t = new Uint8Array(32), h = new Uint8Array(64); - var p = [gf(), gf(), gf(), gf()], - q = [gf(), gf(), gf(), gf()]; - mlen = -1; - if (n < 64) return -1; - if (unpackneg(q, pk)) return -1; - for (i = 0; i < n; i++) m[i] = sm[i]; - for (i = 0; i < 32; i++) m[i+32] = pk[i]; - crypto_hash(h, m, n); - reduce(h); - scalarmult(p, q, h); +var transport_connection_TransportConnection = (function (_super) { + transport_connection_extends(TransportConnection, _super); + function TransportConnection(hooks, name, priority, key, options) { + var _this = _super.call(this) || this; + _this.initialize = worker_runtime.transportConnectionInitializer; + _this.hooks = hooks; + _this.name = name; + _this.priority = priority; + _this.key = key; + _this.options = options; + _this.state = "new"; + _this.timeline = options.timeline; + _this.activityTimeout = options.activityTimeout; + _this.id = _this.timeline.generateUniqueID(); + return _this; + } + TransportConnection.prototype.handlesActivityChecks = function () { + return Boolean(this.hooks.handlesActivityChecks); + }; + TransportConnection.prototype.supportsPing = function () { + return Boolean(this.hooks.supportsPing); + }; + TransportConnection.prototype.connect = function () { + var _this = this; + if (this.socket || this.state !== "initialized") { + return false; + } + var url = this.hooks.urls.getInitial(this.key, this.options); + try { + this.socket = this.hooks.getSocket(url, this.options); + } + catch (e) { + util.defer(function () { + _this.onError(e); + _this.changeState("closed"); + }); + return false; + } + this.bindListeners(); + logger.debug("Connecting", { transport: this.name, url: url }); + this.changeState("connecting"); + return true; + }; + TransportConnection.prototype.close = function () { + if (this.socket) { + this.socket.close(); + return true; + } + else { + return false; + } + }; + TransportConnection.prototype.send = function (data) { + var _this = this; + if (this.state === "open") { + util.defer(function () { + if (_this.socket) { + _this.socket.send(data); + } + }); + return true; + } + else { + return false; + } + }; + TransportConnection.prototype.ping = function () { + if (this.state === "open" && this.supportsPing()) { + this.socket.ping(); + } + }; + TransportConnection.prototype.onOpen = function () { + if (this.hooks.beforeOpen) { + this.hooks.beforeOpen(this.socket, this.hooks.urls.getPath(this.key, this.options)); + } + this.changeState("open"); + this.socket.onopen = undefined; + }; + TransportConnection.prototype.onError = function (error) { + this.emit("error", { type: 'WebSocketError', error: error }); + this.timeline.error(this.buildTimelineMessage({ error: error.toString() })); + }; + TransportConnection.prototype.onClose = function (closeEvent) { + if (closeEvent) { + this.changeState("closed", { + code: closeEvent.code, + reason: closeEvent.reason, + wasClean: closeEvent.wasClean + }); + } + else { + this.changeState("closed"); + } + this.unbindListeners(); + this.socket = undefined; + }; + TransportConnection.prototype.onMessage = function (message) { + this.emit("message", message); + }; + TransportConnection.prototype.onActivity = function () { + this.emit("activity"); + }; + TransportConnection.prototype.bindListeners = function () { + var _this = this; + this.socket.onopen = function () { + _this.onOpen(); + }; + this.socket.onerror = function (error) { + _this.onError(error); + }; + this.socket.onclose = function (closeEvent) { + _this.onClose(closeEvent); + }; + this.socket.onmessage = function (message) { + _this.onMessage(message); + }; + if (this.supportsPing()) { + this.socket.onactivity = function () { _this.onActivity(); }; + } + }; + TransportConnection.prototype.unbindListeners = function () { + if (this.socket) { + this.socket.onopen = undefined; + this.socket.onerror = undefined; + this.socket.onclose = undefined; + this.socket.onmessage = undefined; + if (this.supportsPing()) { + this.socket.onactivity = undefined; + } + } + }; + TransportConnection.prototype.changeState = function (state, params) { + this.state = state; + this.timeline.info(this.buildTimelineMessage({ + state: state, + params: params + })); + this.emit(state, params); + }; + TransportConnection.prototype.buildTimelineMessage = function (message) { + return extend({ cid: this.id }, message); + }; + return TransportConnection; +}(dispatcher)); +/* harmony default export */ var transport_connection = (transport_connection_TransportConnection); + +// CONCATENATED MODULE: ./src/core/transports/transport.ts - scalarbase(q, sm.subarray(32)); - add(p, q); - pack(t, p); +var transport_Transport = (function () { + function Transport(hooks) { + this.hooks = hooks; + } + Transport.prototype.isSupported = function (environment) { + return this.hooks.isSupported(environment); + }; + Transport.prototype.createConnection = function (name, priority, key, options) { + return new transport_connection(this.hooks, name, priority, key, options); + }; + return Transport; +}()); +/* harmony default export */ var transports_transport = (transport_Transport); - n -= 64; - if (crypto_verify_32(sm, 0, t, 0)) { - for (i = 0; i < n; i++) m[i] = 0; - return -1; - } +// CONCATENATED MODULE: ./src/runtimes/isomorphic/transports/transports.ts - for (i = 0; i < n; i++) m[i] = sm[i + 64]; - mlen = n; - return mlen; -} -var crypto_secretbox_KEYBYTES = 32, - crypto_secretbox_NONCEBYTES = 24, - crypto_secretbox_ZEROBYTES = 32, - crypto_secretbox_BOXZEROBYTES = 16, - crypto_scalarmult_BYTES = 32, - crypto_scalarmult_SCALARBYTES = 32, - crypto_box_PUBLICKEYBYTES = 32, - crypto_box_SECRETKEYBYTES = 32, - crypto_box_BEFORENMBYTES = 32, - crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, - crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, - crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, - crypto_sign_BYTES = 64, - crypto_sign_PUBLICKEYBYTES = 32, - crypto_sign_SECRETKEYBYTES = 64, - crypto_sign_SEEDBYTES = 32, - crypto_hash_BYTES = 64; -nacl.lowlevel = { - crypto_core_hsalsa20: crypto_core_hsalsa20, - crypto_stream_xor: crypto_stream_xor, - crypto_stream: crypto_stream, - crypto_stream_salsa20_xor: crypto_stream_salsa20_xor, - crypto_stream_salsa20: crypto_stream_salsa20, - crypto_onetimeauth: crypto_onetimeauth, - crypto_onetimeauth_verify: crypto_onetimeauth_verify, - crypto_verify_16: crypto_verify_16, - crypto_verify_32: crypto_verify_32, - crypto_secretbox: crypto_secretbox, - crypto_secretbox_open: crypto_secretbox_open, - crypto_scalarmult: crypto_scalarmult, - crypto_scalarmult_base: crypto_scalarmult_base, - crypto_box_beforenm: crypto_box_beforenm, - crypto_box_afternm: crypto_box_afternm, - crypto_box: crypto_box, - crypto_box_open: crypto_box_open, - crypto_box_keypair: crypto_box_keypair, - crypto_hash: crypto_hash, - crypto_sign: crypto_sign, - crypto_sign_keypair: crypto_sign_keypair, - crypto_sign_open: crypto_sign_open, - crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES, - crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES, - crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES, - crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES, - crypto_scalarmult_BYTES: crypto_scalarmult_BYTES, - crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES, - crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES, - crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES, - crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES, - crypto_box_NONCEBYTES: crypto_box_NONCEBYTES, - crypto_box_ZEROBYTES: crypto_box_ZEROBYTES, - crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES, - crypto_sign_BYTES: crypto_sign_BYTES, - crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES, - crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES, - crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES, - crypto_hash_BYTES: crypto_hash_BYTES +var WSTransport = new transports_transport({ + urls: ws, + handlesActivityChecks: false, + supportsPing: false, + isInitialized: function () { + return Boolean(worker_runtime.getWebSocketAPI()); + }, + isSupported: function () { + return Boolean(worker_runtime.getWebSocketAPI()); + }, + getSocket: function (url) { + return worker_runtime.createWebSocket(url); + } +}); +var httpConfiguration = { + urls: http, + handlesActivityChecks: false, + supportsPing: true, + isInitialized: function () { + return true; + } }; +var streamingConfiguration = extend({ getSocket: function (url) { + return worker_runtime.HTTPFactory.createStreamingSocket(url); + } +}, httpConfiguration); +var pollingConfiguration = extend({ getSocket: function (url) { + return worker_runtime.HTTPFactory.createPollingSocket(url); + } +}, httpConfiguration); +var xhrConfiguration = { + isSupported: function () { + return worker_runtime.isXHRSupported(); + } +}; +var XHRStreamingTransport = new transports_transport(extend({}, streamingConfiguration, xhrConfiguration)); +var XHRPollingTransport = new transports_transport(extend({}, pollingConfiguration, xhrConfiguration)); +var Transports = { + ws: WSTransport, + xhr_streaming: XHRStreamingTransport, + xhr_polling: XHRPollingTransport +}; +/* harmony default export */ var transports = (Transports); -/* High-level API */ - -function checkLengths(k, n) { - if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size'); - if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size'); -} - -function checkBoxLengths(pk, sk) { - if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size'); - if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size'); -} +// CONCATENATED MODULE: ./src/core/transports/assistant_to_the_transport_manager.ts -function checkArrayTypes() { - for (var i = 0; i < arguments.length; i++) { - if (!(arguments[i] instanceof Uint8Array)) - throw new TypeError('unexpected type, use Uint8Array'); - } -} -function cleanup(arr) { - for (var i = 0; i < arr.length; i++) arr[i] = 0; -} +var assistant_to_the_transport_manager_AssistantToTheTransportManager = (function () { + function AssistantToTheTransportManager(manager, transport, options) { + this.manager = manager; + this.transport = transport; + this.minPingDelay = options.minPingDelay; + this.maxPingDelay = options.maxPingDelay; + this.pingDelay = undefined; + } + AssistantToTheTransportManager.prototype.createConnection = function (name, priority, key, options) { + var _this = this; + options = extend({}, options, { + activityTimeout: this.pingDelay + }); + var connection = this.transport.createConnection(name, priority, key, options); + var openTimestamp = null; + var onOpen = function () { + connection.unbind("open", onOpen); + connection.bind("closed", onClosed); + openTimestamp = util.now(); + }; + var onClosed = function (closeEvent) { + connection.unbind("closed", onClosed); + if (closeEvent.code === 1002 || closeEvent.code === 1003) { + _this.manager.reportDeath(); + } + else if (!closeEvent.wasClean && openTimestamp) { + var lifespan = util.now() - openTimestamp; + if (lifespan < 2 * _this.maxPingDelay) { + _this.manager.reportDeath(); + _this.pingDelay = Math.max(lifespan / 2, _this.minPingDelay); + } + } + }; + connection.bind("open", onOpen); + return connection; + }; + AssistantToTheTransportManager.prototype.isSupported = function (environment) { + return this.manager.isAlive() && this.transport.isSupported(environment); + }; + return AssistantToTheTransportManager; +}()); +/* harmony default export */ var assistant_to_the_transport_manager = (assistant_to_the_transport_manager_AssistantToTheTransportManager); -nacl.randomBytes = function(n) { - var b = new Uint8Array(n); - randombytes(b, n); - return b; +// CONCATENATED MODULE: ./src/core/connection/protocol/protocol.ts +var Protocol = { + decodeMessage: function (messageEvent) { + try { + var messageData = JSON.parse(messageEvent.data); + var pusherEventData = messageData.data; + if (typeof pusherEventData === 'string') { + try { + pusherEventData = JSON.parse(messageData.data); + } + catch (e) { } + } + var pusherEvent = { + event: messageData.event, + channel: messageData.channel, + data: pusherEventData, + }; + if (messageData.user_id) { + pusherEvent.user_id = messageData.user_id; + } + return pusherEvent; + } + catch (e) { + throw { type: 'MessageParseError', error: e, data: messageEvent.data }; + } + }, + encodeMessage: function (event) { + return JSON.stringify(event); + }, + processHandshake: function (messageEvent) { + var message = Protocol.decodeMessage(messageEvent); + if (message.event === "pusher:connection_established") { + if (!message.data.activity_timeout) { + throw "No activity timeout specified in handshake"; + } + return { + action: "connected", + id: message.data.socket_id, + activityTimeout: message.data.activity_timeout * 1000 + }; + } + else if (message.event === "pusher:error") { + return { + action: this.getCloseAction(message.data), + error: this.getCloseError(message.data) + }; + } + else { + throw "Invalid handshake"; + } + }, + getCloseAction: function (closeEvent) { + if (closeEvent.code < 4000) { + if (closeEvent.code >= 1002 && closeEvent.code <= 1004) { + return "backoff"; + } + else { + return null; + } + } + else if (closeEvent.code === 4000) { + return "tls_only"; + } + else if (closeEvent.code < 4100) { + return "refused"; + } + else if (closeEvent.code < 4200) { + return "backoff"; + } + else if (closeEvent.code < 4300) { + return "retry"; + } + else { + return "refused"; + } + }, + getCloseError: function (closeEvent) { + if (closeEvent.code !== 1000 && closeEvent.code !== 1001) { + return { + type: 'PusherError', + data: { + code: closeEvent.code, + message: closeEvent.reason || closeEvent.message + } + }; + } + else { + return null; + } + } }; +/* harmony default export */ var protocol = (Protocol); -nacl.secretbox = function(msg, nonce, key) { - checkArrayTypes(msg, nonce, key); - checkLengths(key, nonce); - var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length); - var c = new Uint8Array(m.length); - for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i]; - crypto_secretbox(c, m, m.length, nonce, key); - return c.subarray(crypto_secretbox_BOXZEROBYTES); -}; +// CONCATENATED MODULE: ./src/core/connection/connection.ts +var connection_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); -nacl.secretbox.open = function(box, nonce, key) { - checkArrayTypes(box, nonce, key); - checkLengths(key, nonce); - var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length); - var m = new Uint8Array(c.length); - for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i]; - if (c.length < 32) return null; - if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null; - return m.subarray(crypto_secretbox_ZEROBYTES); -}; -nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES; -nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES; -nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES; -nacl.scalarMult = function(n, p) { - checkArrayTypes(n, p); - if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); - if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size'); - var q = new Uint8Array(crypto_scalarmult_BYTES); - crypto_scalarmult(q, n, p); - return q; -}; -nacl.scalarMult.base = function(n) { - checkArrayTypes(n); - if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); - var q = new Uint8Array(crypto_scalarmult_BYTES); - crypto_scalarmult_base(q, n); - return q; -}; +var connection_Connection = (function (_super) { + connection_extends(Connection, _super); + function Connection(id, transport) { + var _this = _super.call(this) || this; + _this.id = id; + _this.transport = transport; + _this.activityTimeout = transport.activityTimeout; + _this.bindListeners(); + return _this; + } + Connection.prototype.handlesActivityChecks = function () { + return this.transport.handlesActivityChecks(); + }; + Connection.prototype.send = function (data) { + return this.transport.send(data); + }; + Connection.prototype.send_event = function (name, data, channel) { + var event = { event: name, data: data }; + if (channel) { + event.channel = channel; + } + logger.debug('Event sent', event); + return this.send(protocol.encodeMessage(event)); + }; + Connection.prototype.ping = function () { + if (this.transport.supportsPing()) { + this.transport.ping(); + } + else { + this.send_event('pusher:ping', {}); + } + }; + Connection.prototype.close = function () { + this.transport.close(); + }; + Connection.prototype.bindListeners = function () { + var _this = this; + var listeners = { + message: function (messageEvent) { + var pusherEvent; + try { + pusherEvent = protocol.decodeMessage(messageEvent); + } + catch (e) { + _this.emit('error', { + type: 'MessageParseError', + error: e, + data: messageEvent.data + }); + } + if (pusherEvent !== undefined) { + logger.debug('Event recd', pusherEvent); + switch (pusherEvent.event) { + case 'pusher:error': + _this.emit('error', { type: 'PusherError', data: pusherEvent.data }); + break; + case 'pusher:ping': + _this.emit("ping"); + break; + case 'pusher:pong': + _this.emit("pong"); + break; + } + _this.emit('message', pusherEvent); + } + }, + activity: function () { + _this.emit("activity"); + }, + error: function (error) { + _this.emit("error", { type: "WebSocketError", error: error }); + }, + closed: function (closeEvent) { + unbindListeners(); + if (closeEvent && closeEvent.code) { + _this.handleCloseEvent(closeEvent); + } + _this.transport = null; + _this.emit("closed"); + } + }; + var unbindListeners = function () { + objectApply(listeners, function (listener, event) { + _this.transport.unbind(event, listener); + }); + }; + objectApply(listeners, function (listener, event) { + _this.transport.bind(event, listener); + }); + }; + Connection.prototype.handleCloseEvent = function (closeEvent) { + var action = protocol.getCloseAction(closeEvent); + var error = protocol.getCloseError(closeEvent); + if (error) { + this.emit('error', error); + } + if (action) { + this.emit(action, { action: action, error: error }); + } + }; + return Connection; +}(dispatcher)); +/* harmony default export */ var connection_connection = (connection_Connection); -nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES; -nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES; +// CONCATENATED MODULE: ./src/core/connection/handshake/index.ts -nacl.box = function(msg, nonce, publicKey, secretKey) { - var k = nacl.box.before(publicKey, secretKey); - return nacl.secretbox(msg, nonce, k); -}; -nacl.box.before = function(publicKey, secretKey) { - checkArrayTypes(publicKey, secretKey); - checkBoxLengths(publicKey, secretKey); - var k = new Uint8Array(crypto_box_BEFORENMBYTES); - crypto_box_beforenm(k, publicKey, secretKey); - return k; -}; -nacl.box.after = nacl.secretbox; +var handshake_Handshake = (function () { + function Handshake(transport, callback) { + this.transport = transport; + this.callback = callback; + this.bindListeners(); + } + Handshake.prototype.close = function () { + this.unbindListeners(); + this.transport.close(); + }; + Handshake.prototype.bindListeners = function () { + var _this = this; + this.onMessage = function (m) { + _this.unbindListeners(); + var result; + try { + result = protocol.processHandshake(m); + } + catch (e) { + _this.finish("error", { error: e }); + _this.transport.close(); + return; + } + if (result.action === "connected") { + _this.finish("connected", { + connection: new connection_connection(result.id, _this.transport), + activityTimeout: result.activityTimeout + }); + } + else { + _this.finish(result.action, { error: result.error }); + _this.transport.close(); + } + }; + this.onClosed = function (closeEvent) { + _this.unbindListeners(); + var action = protocol.getCloseAction(closeEvent) || "backoff"; + var error = protocol.getCloseError(closeEvent); + _this.finish(action, { error: error }); + }; + this.transport.bind("message", this.onMessage); + this.transport.bind("closed", this.onClosed); + }; + Handshake.prototype.unbindListeners = function () { + this.transport.unbind("message", this.onMessage); + this.transport.unbind("closed", this.onClosed); + }; + Handshake.prototype.finish = function (action, params) { + this.callback(extend({ transport: this.transport, action: action }, params)); + }; + return Handshake; +}()); +/* harmony default export */ var connection_handshake = (handshake_Handshake); -nacl.box.open = function(msg, nonce, publicKey, secretKey) { - var k = nacl.box.before(publicKey, secretKey); - return nacl.secretbox.open(msg, nonce, k); -}; +// CONCATENATED MODULE: ./src/core/auth/pusher_authorizer.ts -nacl.box.open.after = nacl.secretbox.open; +var pusher_authorizer_PusherAuthorizer = (function () { + function PusherAuthorizer(channel, options) { + this.channel = channel; + var authTransport = options.authTransport; + if (typeof worker_runtime.getAuthorizers()[authTransport] === "undefined") { + throw "'" + authTransport + "' is not a recognized auth transport"; + } + this.type = authTransport; + this.options = options; + this.authOptions = (options || {}).auth || {}; + } + PusherAuthorizer.prototype.composeQuery = function (socketId) { + var query = 'socket_id=' + encodeURIComponent(socketId) + + '&channel_name=' + encodeURIComponent(this.channel.name); + for (var i in this.authOptions.params) { + query += "&" + encodeURIComponent(i) + "=" + encodeURIComponent(this.authOptions.params[i]); + } + return query; + }; + PusherAuthorizer.prototype.authorize = function (socketId, callback) { + PusherAuthorizer.authorizers = PusherAuthorizer.authorizers || worker_runtime.getAuthorizers(); + return PusherAuthorizer.authorizers[this.type].call(this, worker_runtime, socketId, callback); + }; + return PusherAuthorizer; +}()); +/* harmony default export */ var pusher_authorizer = (pusher_authorizer_PusherAuthorizer); -nacl.box.keyPair = function() { - var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_box_SECRETKEYBYTES); - crypto_box_keypair(pk, sk); - return {publicKey: pk, secretKey: sk}; -}; +// CONCATENATED MODULE: ./src/core/timeline/timeline_sender.ts + +var timeline_sender_TimelineSender = (function () { + function TimelineSender(timeline, options) { + this.timeline = timeline; + this.options = options || {}; + } + TimelineSender.prototype.send = function (useTLS, callback) { + if (this.timeline.isEmpty()) { + return; + } + this.timeline.send(worker_runtime.TimelineTransport.getAgent(this, useTLS), callback); + }; + return TimelineSender; +}()); +/* harmony default export */ var timeline_sender = (timeline_sender_TimelineSender); -nacl.box.keyPair.fromSecretKey = function(secretKey) { - checkArrayTypes(secretKey); - if (secretKey.length !== crypto_box_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); - crypto_scalarmult_base(pk, secretKey); - return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; -}; +// CONCATENATED MODULE: ./src/core/errors.ts +var errors_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var BadEventName = (function (_super) { + errors_extends(BadEventName, _super); + function BadEventName(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return BadEventName; +}(Error)); -nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES; -nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES; -nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES; -nacl.box.nonceLength = crypto_box_NONCEBYTES; -nacl.box.overheadLength = nacl.secretbox.overheadLength; +var RequestTimedOut = (function (_super) { + errors_extends(RequestTimedOut, _super); + function RequestTimedOut(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return RequestTimedOut; +}(Error)); -nacl.sign = function(msg, secretKey) { - checkArrayTypes(msg, secretKey); - if (secretKey.length !== crypto_sign_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length); - crypto_sign(signedMsg, msg, msg.length, secretKey); - return signedMsg; -}; +var TransportPriorityTooLow = (function (_super) { + errors_extends(TransportPriorityTooLow, _super); + function TransportPriorityTooLow(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return TransportPriorityTooLow; +}(Error)); -nacl.sign.open = function(signedMsg, publicKey) { - checkArrayTypes(signedMsg, publicKey); - if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) - throw new Error('bad public key size'); - var tmp = new Uint8Array(signedMsg.length); - var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey); - if (mlen < 0) return null; - var m = new Uint8Array(mlen); - for (var i = 0; i < m.length; i++) m[i] = tmp[i]; - return m; -}; +var TransportClosed = (function (_super) { + errors_extends(TransportClosed, _super); + function TransportClosed(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return TransportClosed; +}(Error)); -nacl.sign.detached = function(msg, secretKey) { - var signedMsg = nacl.sign(msg, secretKey); - var sig = new Uint8Array(crypto_sign_BYTES); - for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; - return sig; -}; +var UnsupportedFeature = (function (_super) { + errors_extends(UnsupportedFeature, _super); + function UnsupportedFeature(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return UnsupportedFeature; +}(Error)); -nacl.sign.detached.verify = function(msg, sig, publicKey) { - checkArrayTypes(msg, sig, publicKey); - if (sig.length !== crypto_sign_BYTES) - throw new Error('bad signature size'); - if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) - throw new Error('bad public key size'); - var sm = new Uint8Array(crypto_sign_BYTES + msg.length); - var m = new Uint8Array(crypto_sign_BYTES + msg.length); - var i; - for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]; - for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i]; - return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); -}; +var UnsupportedTransport = (function (_super) { + errors_extends(UnsupportedTransport, _super); + function UnsupportedTransport(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return UnsupportedTransport; +}(Error)); -nacl.sign.keyPair = function() { - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); - crypto_sign_keypair(pk, sk); - return {publicKey: pk, secretKey: sk}; -}; +var UnsupportedStrategy = (function (_super) { + errors_extends(UnsupportedStrategy, _super); + function UnsupportedStrategy(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return UnsupportedStrategy; +}(Error)); -nacl.sign.keyPair.fromSecretKey = function(secretKey) { - checkArrayTypes(secretKey); - if (secretKey.length !== crypto_sign_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i]; - return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; -}; -nacl.sign.keyPair.fromSeed = function(seed) { - checkArrayTypes(seed); - if (seed.length !== crypto_sign_SEEDBYTES) - throw new Error('bad seed size'); - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); - for (var i = 0; i < 32; i++) sk[i] = seed[i]; - crypto_sign_keypair(pk, sk, true); - return {publicKey: pk, secretKey: sk}; +// CONCATENATED MODULE: ./src/core/utils/url_store.ts +var urlStore = { + baseUrl: "https://pusher.com", + urls: { + authenticationEndpoint: { + path: "/docs/authenticating_users", + }, + javascriptQuickStart: { + path: "/docs/javascript_quick_start" + }, + triggeringClientEvents: { + path: "/docs/client_api_guide/client_events#trigger-events" + } + } +}; +var buildLogSuffix = function (key) { + var urlPrefix = "See:"; + var urlObj = urlStore.urls[key]; + if (!urlObj) + return ""; + var url; + if (urlObj.fullUrl) { + url = urlObj.fullUrl; + } + else if (urlObj.path) { + url = urlStore.baseUrl + urlObj.path; + } + if (!url) + return ""; + return urlPrefix + " " + url; }; +/* harmony default export */ var url_store = ({ buildLogSuffix: buildLogSuffix }); -nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; -nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; -nacl.sign.seedLength = crypto_sign_SEEDBYTES; -nacl.sign.signatureLength = crypto_sign_BYTES; +// CONCATENATED MODULE: ./src/core/channels/channel.ts +var channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); -nacl.hash = function(msg) { - checkArrayTypes(msg); - var h = new Uint8Array(crypto_hash_BYTES); - crypto_hash(h, msg, msg.length); - return h; -}; -nacl.hash.hashLength = crypto_hash_BYTES; -nacl.verify = function(x, y) { - checkArrayTypes(x, y); - // Zero length arguments are considered not equal. - if (x.length === 0 || y.length === 0) return false; - if (x.length !== y.length) return false; - return (vn(x, 0, y, 0, x.length) === 0) ? true : false; -}; -nacl.setPRNG = function(fn) { - randombytes = fn; -}; +var channel_Channel = (function (_super) { + channel_extends(Channel, _super); + function Channel(name, pusher) { + var _this = _super.call(this, function (event, data) { + logger.debug('No callbacks on ' + name + ' for ' + event); + }) || this; + _this.name = name; + _this.pusher = pusher; + _this.subscribed = false; + _this.subscriptionPending = false; + _this.subscriptionCancelled = false; + return _this; + } + Channel.prototype.authorize = function (socketId, callback) { + return callback(false, {}); + }; + Channel.prototype.trigger = function (event, data) { + if (event.indexOf("client-") !== 0) { + throw new BadEventName("Event '" + event + "' does not start with 'client-'"); + } + if (!this.subscribed) { + var suffix = url_store.buildLogSuffix("triggeringClientEvents"); + logger.warn("Client event triggered before channel 'subscription_succeeded' event . " + suffix); + } + return this.pusher.send_event(event, data, this.name); + }; + Channel.prototype.disconnect = function () { + this.subscribed = false; + this.subscriptionPending = false; + }; + Channel.prototype.handleEvent = function (event) { + var eventName = event.event; + var data = event.data; + if (eventName === "pusher_internal:subscription_succeeded") { + this.handleSubscriptionSucceededEvent(event); + } + else if (eventName.indexOf("pusher_internal:") !== 0) { + var metadata = {}; + this.emit(eventName, data, metadata); + } + }; + Channel.prototype.handleSubscriptionSucceededEvent = function (event) { + this.subscriptionPending = false; + this.subscribed = true; + if (this.subscriptionCancelled) { + this.pusher.unsubscribe(this.name); + } + else { + this.emit("pusher:subscription_succeeded", event.data); + } + }; + Channel.prototype.subscribe = function () { + var _this = this; + if (this.subscribed) { + return; + } + this.subscriptionPending = true; + this.subscriptionCancelled = false; + this.authorize(this.pusher.connection.socket_id, function (error, data) { + if (error) { + _this.emit('pusher:subscription_error', data); + } + else { + _this.pusher.send_event('pusher:subscribe', { + auth: data.auth, + channel_data: data.channel_data, + channel: _this.name + }); + } + }); + }; + Channel.prototype.unsubscribe = function () { + this.subscribed = false; + this.pusher.send_event('pusher:unsubscribe', { + channel: this.name + }); + }; + Channel.prototype.cancelSubscription = function () { + this.subscriptionCancelled = true; + }; + Channel.prototype.reinstateSubscription = function () { + this.subscriptionCancelled = false; + }; + return Channel; +}(dispatcher)); +/* harmony default export */ var channels_channel = (channel_Channel); -(function() { - // Initialize PRNG if environment provides CSPRNG. - // If not, methods calling randombytes will throw. - var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null; - if (crypto && crypto.getRandomValues) { - // Browsers. - var QUOTA = 65536; - nacl.setPRNG(function(x, n) { - var i, v = new Uint8Array(n); - for (i = 0; i < n; i += QUOTA) { - crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); - } - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); - } else if (true) { - // Node.js. - crypto = __webpack_require__(36); - if (crypto && crypto.randomBytes) { - nacl.setPRNG(function(x, n) { - var i, v = crypto.randomBytes(n); - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); - } - } +// CONCATENATED MODULE: ./src/core/channels/private_channel.ts +var private_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; })(); -})( true && module.exports ? module.exports : (self.nacl = self.nacl || {})); - - -/***/ }), -/* 36 */ -/***/ (function(module, exports) { - -/* (ignored) */ - -/***/ }), -/* 37 */ -/***/ (function(module, exports, __webpack_require__) { -// Written in 2014-2016 by Dmitry Chestnykh and Devi Mandiri. -// Public domain. -(function(root, f) { - 'use strict'; - if ( true && module.exports) module.exports = f(); - else if (root.nacl) root.nacl.util = f(); - else { - root.nacl = {}; - root.nacl.util = f(); - } -}(this, function() { - 'use strict'; +var private_channel_PrivateChannel = (function (_super) { + private_channel_extends(PrivateChannel, _super); + function PrivateChannel() { + return _super !== null && _super.apply(this, arguments) || this; + } + PrivateChannel.prototype.authorize = function (socketId, callback) { + var authorizer = factory.createAuthorizer(this, this.pusher.config); + return authorizer.authorize(socketId, callback); + }; + return PrivateChannel; +}(channels_channel)); +/* harmony default export */ var private_channel = (private_channel_PrivateChannel); - var util = {}; +// CONCATENATED MODULE: ./src/core/channels/members.ts - function validateBase64(s) { - if (!(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(s))) { - throw new TypeError('invalid encoding'); +var members_Members = (function () { + function Members() { + this.reset(); } - } - - util.decodeUTF8 = function(s) { - if (typeof s !== 'string') throw new TypeError('expected string'); - var i, d = unescape(encodeURIComponent(s)), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; - }; + Members.prototype.get = function (id) { + if (Object.prototype.hasOwnProperty.call(this.members, id)) { + return { + id: id, + info: this.members[id] + }; + } + else { + return null; + } + }; + Members.prototype.each = function (callback) { + var _this = this; + objectApply(this.members, function (member, id) { + callback(_this.get(id)); + }); + }; + Members.prototype.setMyID = function (id) { + this.myID = id; + }; + Members.prototype.onSubscription = function (subscriptionData) { + this.members = subscriptionData.presence.hash; + this.count = subscriptionData.presence.count; + this.me = this.get(this.myID); + }; + Members.prototype.addMember = function (memberData) { + if (this.get(memberData.user_id) === null) { + this.count++; + } + this.members[memberData.user_id] = memberData.user_info; + return this.get(memberData.user_id); + }; + Members.prototype.removeMember = function (memberData) { + var member = this.get(memberData.user_id); + if (member) { + delete this.members[memberData.user_id]; + this.count--; + } + return member; + }; + Members.prototype.reset = function () { + this.members = {}; + this.count = 0; + this.myID = null; + this.me = null; + }; + return Members; +}()); +/* harmony default export */ var members = (members_Members); - util.encodeUTF8 = function(arr) { - var i, s = []; - for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i])); - return decodeURIComponent(escape(s.join(''))); - }; +// CONCATENATED MODULE: ./src/core/channels/presence_channel.ts +var presence_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); - if (typeof atob === 'undefined') { - // Node.js - if (typeof Buffer.from !== 'undefined') { - // Node v6 and later - util.encodeBase64 = function (arr) { // v6 and later - return Buffer.from(arr).toString('base64'); - }; - util.decodeBase64 = function (s) { - validateBase64(s); - return new Uint8Array(Array.prototype.slice.call(Buffer.from(s, 'base64'), 0)); - }; - } else { - // Node earlier than v6 - util.encodeBase64 = function (arr) { // v6 and later - return (new Buffer(arr)).toString('base64'); - }; +var presence_channel_PresenceChannel = (function (_super) { + presence_channel_extends(PresenceChannel, _super); + function PresenceChannel(name, pusher) { + var _this = _super.call(this, name, pusher) || this; + _this.members = new members(); + return _this; + } + PresenceChannel.prototype.authorize = function (socketId, callback) { + var _this = this; + _super.prototype.authorize.call(this, socketId, function (error, authData) { + if (!error) { + if (authData.channel_data === undefined) { + var suffix = url_store.buildLogSuffix("authenticationEndpoint"); + logger.warn("Invalid auth response for channel '" + _this.name + "'," + + ("expected 'channel_data' field. " + suffix)); + callback("Invalid auth response"); + return; + } + var channelData = JSON.parse(authData.channel_data); + _this.members.setMyID(channelData.user_id); + } + callback(error, authData); + }); + }; + PresenceChannel.prototype.handleEvent = function (event) { + var eventName = event.event; + if (eventName.indexOf("pusher_internal:") === 0) { + this.handleInternalEvent(event); + } + else { + var data = event.data; + var metadata = {}; + if (event.user_id) { + metadata.user_id = event.user_id; + } + this.emit(eventName, data, metadata); + } + }; + PresenceChannel.prototype.handleInternalEvent = function (event) { + var eventName = event.event; + var data = event.data; + switch (eventName) { + case "pusher_internal:subscription_succeeded": + this.handleSubscriptionSucceededEvent(event); + break; + case "pusher_internal:member_added": + var addedMember = this.members.addMember(data); + this.emit('pusher:member_added', addedMember); + break; + case "pusher_internal:member_removed": + var removedMember = this.members.removeMember(data); + if (removedMember) { + this.emit('pusher:member_removed', removedMember); + } + break; + } + }; + PresenceChannel.prototype.handleSubscriptionSucceededEvent = function (event) { + this.subscriptionPending = false; + this.subscribed = true; + if (this.subscriptionCancelled) { + this.pusher.unsubscribe(this.name); + } + else { + this.members.onSubscription(event.data); + this.emit("pusher:subscription_succeeded", this.members); + } + }; + PresenceChannel.prototype.disconnect = function () { + this.members.reset(); + _super.prototype.disconnect.call(this); + }; + return PresenceChannel; +}(private_channel)); +/* harmony default export */ var presence_channel = (presence_channel_PresenceChannel); - util.decodeBase64 = function(s) { - validateBase64(s); - return new Uint8Array(Array.prototype.slice.call(new Buffer(s, 'base64'), 0)); - }; - } +// EXTERNAL MODULE: ./node_modules/tweetnacl/nacl-fast.js +var nacl_fast = __webpack_require__(0); - } else { - // Browsers +// EXTERNAL MODULE: ./node_modules/tweetnacl-util/nacl-util.js +var nacl_util = __webpack_require__(1); - util.encodeBase64 = function(arr) { - var i, s = [], len = arr.length; - for (i = 0; i < len; i++) s.push(String.fromCharCode(arr[i])); - return btoa(s.join('')); +// CONCATENATED MODULE: ./src/core/channels/encrypted_channel.ts +var encrypted_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); }; - - util.decodeBase64 = function(s) { - validateBase64(s); - var i, d = atob(s), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; +})(); - } - - return util; -})); -/***/ }), -/* 38 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; +var encrypted_channel_EncryptedChannel = (function (_super) { + encrypted_channel_extends(EncryptedChannel, _super); + function EncryptedChannel() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.key = null; + return _this; + } + EncryptedChannel.prototype.authorize = function (socketId, callback) { + var _this = this; + _super.prototype.authorize.call(this, socketId, function (error, authData) { + if (error) { + callback(true, authData); + return; + } + var sharedSecret = authData["shared_secret"]; + if (!sharedSecret) { + var errorMsg = "No shared_secret key in auth payload for encrypted channel: " + _this.name; + callback(true, errorMsg); + logger.warn("Error: " + errorMsg); + return; + } + _this.key = Object(nacl_util["decodeBase64"])(sharedSecret); + delete authData["shared_secret"]; + callback(false, authData); + }); + }; + EncryptedChannel.prototype.trigger = function (event, data) { + throw new UnsupportedFeature('Client events are not currently supported for encrypted channels'); + }; + EncryptedChannel.prototype.handleEvent = function (event) { + var eventName = event.event; + var data = event.data; + if (eventName.indexOf("pusher_internal:") === 0 || eventName.indexOf("pusher:") === 0) { + _super.prototype.handleEvent.call(this, event); + return; + } + this.handleEncryptedEvent(eventName, data); + }; + EncryptedChannel.prototype.handleEncryptedEvent = function (event, data) { + var _this = this; + if (!this.key) { + logger.debug('Received encrypted event before key has been retrieved from the authEndpoint'); + return; + } + if (!data.ciphertext || !data.nonce) { + logger.warn('Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: ' + data); + return; + } + var cipherText = Object(nacl_util["decodeBase64"])(data.ciphertext); + if (cipherText.length < nacl_fast["secretbox"].overheadLength) { + logger.warn("Expected encrypted event ciphertext length to be " + nacl_fast["secretbox"].overheadLength + ", got: " + cipherText.length); + return; + } + var nonce = Object(nacl_util["decodeBase64"])(data.nonce); + if (nonce.length < nacl_fast["secretbox"].nonceLength) { + logger.warn("Expected encrypted event nonce length to be " + nacl_fast["secretbox"].nonceLength + ", got: " + nonce.length); + return; + } + var bytes = nacl_fast["secretbox"].open(cipherText, nonce, this.key); + if (bytes === null) { + logger.debug('Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint...'); + this.authorize(this.pusher.connection.socket_id, function (error, authData) { + if (error) { + logger.warn("Failed to make a request to the authEndpoint: " + authData + ". Unable to fetch new key, so dropping encrypted event"); + return; + } + bytes = nacl_fast["secretbox"].open(cipherText, nonce, _this.key); + if (bytes === null) { + logger.warn("Failed to decrypt event with new key. Dropping encrypted event"); + return; + } + _this.emitJSON(event, Object(nacl_util["encodeUTF8"])(bytes)); + return; + }); + return; + } + this.emitJSON(event, Object(nacl_util["encodeUTF8"])(bytes)); + }; + EncryptedChannel.prototype.emitJSON = function (eventName, data) { + try { + this.emit(eventName, JSON.parse(data)); + } + catch (e) { + this.emit(eventName, data); + } + return this; + }; + return EncryptedChannel; +}(private_channel)); +/* harmony default export */ var encrypted_channel = (encrypted_channel_EncryptedChannel); -var __extends = (this && this.__extends) || (function () { +// CONCATENATED MODULE: ./src/core/connection/connection_manager.ts +var connection_manager_extends = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || @@ -5038,14 +4255,13 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -exports.__esModule = true; -var dispatcher_1 = __webpack_require__(4); -var timers_1 = __webpack_require__(5); -var logger_1 = __webpack_require__(3); -var Collections = __webpack_require__(0); -var runtime_1 = __webpack_require__(1); -var ConnectionManager = (function (_super) { - __extends(ConnectionManager, _super); + + + + + +var connection_manager_ConnectionManager = (function (_super) { + connection_manager_extends(ConnectionManager, _super); function ConnectionManager(key, options) { var _this = _super.call(this) || this; _this.key = key; @@ -5057,7 +4273,7 @@ var ConnectionManager = (function (_super) { _this.errorCallbacks = _this.buildErrorCallbacks(); _this.connectionCallbacks = _this.buildConnectionCallbacks(_this.errorCallbacks); _this.handshakeCallbacks = _this.buildHandshakeCallbacks(_this.errorCallbacks); - var Network = runtime_1["default"].getNetwork(); + var Network = worker_runtime.getNetwork(); Network.bind("online", function () { _this.timeline.info({ netinfo: "online" }); if (_this.state === "connecting" || _this.state === "unavailable") { @@ -5164,7 +4380,7 @@ var ConnectionManager = (function (_super) { if (delay > 0) { this.emit("connecting_in", Math.round(delay / 1000)); } - this.retryTimer = new timers_1.OneOffTimer(delay || 0, function () { + this.retryTimer = new OneOffTimer(delay || 0, function () { _this.disconnectInternally(); _this.connect(); }); @@ -5179,7 +4395,7 @@ var ConnectionManager = (function (_super) { ; ConnectionManager.prototype.setUnavailableTimer = function () { var _this = this; - this.unavailableTimer = new timers_1.OneOffTimer(this.options.unavailableTimeout, function () { + this.unavailableTimer = new OneOffTimer(this.options.unavailableTimeout, function () { _this.updateState("unavailable"); }); }; @@ -5194,7 +4410,7 @@ var ConnectionManager = (function (_super) { var _this = this; this.stopActivityCheck(); this.connection.ping(); - this.activityTimer = new timers_1.OneOffTimer(this.options.pongTimeout, function () { + this.activityTimer = new OneOffTimer(this.options.pongTimeout, function () { _this.timeline.error({ pong_timed_out: _this.options.pongTimeout }); _this.retryIn(0); }); @@ -5204,7 +4420,7 @@ var ConnectionManager = (function (_super) { var _this = this; this.stopActivityCheck(); if (this.connection && !this.connection.handlesActivityChecks()) { - this.activityTimer = new timers_1.OneOffTimer(this.activityTimeout, function () { + this.activityTimer = new OneOffTimer(this.activityTimeout, function () { _this.sendActivityCheck(); }); } @@ -5218,7 +4434,7 @@ var ConnectionManager = (function (_super) { ; ConnectionManager.prototype.buildConnectionCallbacks = function (errorCallbacks) { var _this = this; - return Collections.extend({}, errorCallbacks, { + return extend({}, errorCallbacks, { message: function (message) { _this.resetActivityCheck(); _this.emit('message', message); @@ -5243,7 +4459,7 @@ var ConnectionManager = (function (_super) { ; ConnectionManager.prototype.buildHandshakeCallbacks = function (errorCallbacks) { var _this = this; - return Collections.extend({}, errorCallbacks, { + return extend({}, errorCallbacks, { connected: function (handshake) { _this.activityTimeout = Math.min(_this.options.activityTimeout, handshake.activityTimeout, handshake.connection.activityTimeout || Infinity); _this.clearUnavailableTimer(); @@ -5310,7 +4526,7 @@ var ConnectionManager = (function (_super) { if (newStateDescription === "connected") { newStateDescription += " with new socket ID " + data.socket_id; } - logger_1["default"].debug('State changed', previousState + ' -> ' + newStateDescription); + logger.debug('State changed', previousState + ' -> ' + newStateDescription); this.timeline.info({ state: newState, params: data }); this.emit('state_change', { previous: previousState, current: newState }); this.emit(newState, data); @@ -5320,21 +4536,14 @@ var ConnectionManager = (function (_super) { return this.state === "connecting" || this.state === "connected"; }; return ConnectionManager; -}(dispatcher_1["default"])); -exports["default"] = ConnectionManager; +}(dispatcher)); +/* harmony default export */ var connection_manager = (connection_manager_ConnectionManager); +// CONCATENATED MODULE: ./src/core/channels/channels.ts -/***/ }), -/* 39 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var Collections = __webpack_require__(0); -var factory_1 = __webpack_require__(6); -var Errors = __webpack_require__(7); -var Channels = (function () { +var channels_Channels = (function () { function Channels() { this.channels = {}; } @@ -5345,7 +4554,7 @@ var Channels = (function () { return this.channels[name]; }; Channels.prototype.all = function () { - return Collections.values(this.channels); + return values(this.channels); }; Channels.prototype.find = function (name) { return this.channels[name]; @@ -5356,45 +4565,200 @@ var Channels = (function () { return channel; }; Channels.prototype.disconnect = function () { - Collections.objectApply(this.channels, function (channel) { + objectApply(this.channels, function (channel) { channel.disconnect(); }); }; return Channels; }()); -exports["default"] = Channels; +/* harmony default export */ var channels = (channels_Channels); function createChannel(name, pusher) { if (name.indexOf('private-encrypted-') === 0) { if (false) { var errorMsg; } - return factory_1["default"].createEncryptedChannel(name, pusher); + return factory.createEncryptedChannel(name, pusher); } else if (name.indexOf('private-') === 0) { - return factory_1["default"].createPrivateChannel(name, pusher); + return factory.createPrivateChannel(name, pusher); } else if (name.indexOf('presence-') === 0) { - return factory_1["default"].createPresenceChannel(name, pusher); + return factory.createPresenceChannel(name, pusher); } else { - return factory_1["default"].createChannel(name, pusher); + return factory.createChannel(name, pusher); } } +// CONCATENATED MODULE: ./src/core/utils/factory.ts + + + + + + + + + + +var Factory = { + createChannels: function () { + return new channels(); + }, + createConnectionManager: function (key, options) { + return new connection_manager(key, options); + }, + createChannel: function (name, pusher) { + return new channels_channel(name, pusher); + }, + createPrivateChannel: function (name, pusher) { + return new private_channel(name, pusher); + }, + createPresenceChannel: function (name, pusher) { + return new presence_channel(name, pusher); + }, + createEncryptedChannel: function (name, pusher) { + return new encrypted_channel(name, pusher); + }, + createTimelineSender: function (timeline, options) { + return new timeline_sender(timeline, options); + }, + createAuthorizer: function (channel, options) { + if (options.authorizer) { + return options.authorizer(channel, options); + } + return new pusher_authorizer(channel, options); + }, + createHandshake: function (transport, callback) { + return new connection_handshake(transport, callback); + }, + createAssistantToTheTransportManager: function (manager, transport, options) { + return new assistant_to_the_transport_manager(manager, transport, options); + } +}; +/* harmony default export */ var factory = (Factory); + +// CONCATENATED MODULE: ./src/core/transports/transport_manager.ts + +var transport_manager_TransportManager = (function () { + function TransportManager(options) { + this.options = options || {}; + this.livesLeft = this.options.lives || Infinity; + } + TransportManager.prototype.getAssistant = function (transport) { + return factory.createAssistantToTheTransportManager(this, transport, { + minPingDelay: this.options.minPingDelay, + maxPingDelay: this.options.maxPingDelay + }); + }; + TransportManager.prototype.isAlive = function () { + return this.livesLeft > 0; + }; + TransportManager.prototype.reportDeath = function () { + this.livesLeft -= 1; + }; + return TransportManager; +}()); +/* harmony default export */ var transport_manager = (transport_manager_TransportManager); + +// CONCATENATED MODULE: ./src/core/strategies/sequential_strategy.ts + + + +var sequential_strategy_SequentialStrategy = (function () { + function SequentialStrategy(strategies, options) { + this.strategies = strategies; + this.loop = Boolean(options.loop); + this.failFast = Boolean(options.failFast); + this.timeout = options.timeout; + this.timeoutLimit = options.timeoutLimit; + } + SequentialStrategy.prototype.isSupported = function () { + return any(this.strategies, util.method("isSupported")); + }; + SequentialStrategy.prototype.connect = function (minPriority, callback) { + var _this = this; + var strategies = this.strategies; + var current = 0; + var timeout = this.timeout; + var runner = null; + var tryNextStrategy = function (error, handshake) { + if (handshake) { + callback(null, handshake); + } + else { + current = current + 1; + if (_this.loop) { + current = current % strategies.length; + } + if (current < strategies.length) { + if (timeout) { + timeout = timeout * 2; + if (_this.timeoutLimit) { + timeout = Math.min(timeout, _this.timeoutLimit); + } + } + runner = _this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: _this.failFast }, tryNextStrategy); + } + else { + callback(true); + } + } + }; + runner = this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: this.failFast }, tryNextStrategy); + return { + abort: function () { + runner.abort(); + }, + forceMinPriority: function (p) { + minPriority = p; + if (runner) { + runner.forceMinPriority(p); + } + } + }; + }; + SequentialStrategy.prototype.tryStrategy = function (strategy, minPriority, options, callback) { + var timer = null; + var runner = null; + if (options.timeout > 0) { + timer = new OneOffTimer(options.timeout, function () { + runner.abort(); + callback(true); + }); + } + runner = strategy.connect(minPriority, function (error, handshake) { + if (error && timer && timer.isRunning() && !options.failFast) { + return; + } + if (timer) { + timer.ensureAborted(); + } + callback(error, handshake); + }); + return { + abort: function () { + if (timer) { + timer.ensureAborted(); + } + runner.abort(); + }, + forceMinPriority: function (p) { + runner.forceMinPriority(p); + } + }; + }; + return SequentialStrategy; +}()); +/* harmony default export */ var sequential_strategy = (sequential_strategy_SequentialStrategy); -/***/ }), -/* 40 */ -/***/ (function(module, exports, __webpack_require__) { +// CONCATENATED MODULE: ./src/core/strategies/best_connected_ever_strategy.ts -"use strict"; -exports.__esModule = true; -var Collections = __webpack_require__(0); -var util_1 = __webpack_require__(2); -var BestConnectedEverStrategy = (function () { +var best_connected_ever_strategy_BestConnectedEverStrategy = (function () { function BestConnectedEverStrategy(strategies) { this.strategies = strategies; } BestConnectedEverStrategy.prototype.isSupported = function () { - return Collections.any(this.strategies, util_1["default"].method("isSupported")); + return any(this.strategies, util.method("isSupported")); }; BestConnectedEverStrategy.prototype.connect = function (minPriority, callback) { return connect(this.strategies, minPriority, function (i, runners) { @@ -5406,7 +4770,7 @@ var BestConnectedEverStrategy = (function () { } return; } - Collections.apply(runners, function (runner) { + apply(runners, function (runner) { runner.forceMinPriority(handshake.transport.priority); }); callback(null, handshake); @@ -5415,24 +4779,24 @@ var BestConnectedEverStrategy = (function () { }; return BestConnectedEverStrategy; }()); -exports["default"] = BestConnectedEverStrategy; +/* harmony default export */ var best_connected_ever_strategy = (best_connected_ever_strategy_BestConnectedEverStrategy); function connect(strategies, minPriority, callbackBuilder) { - var runners = Collections.map(strategies, function (strategy, i, _, rs) { + var runners = map(strategies, function (strategy, i, _, rs) { return strategy.connect(minPriority, callbackBuilder(i, rs)); }); return { abort: function () { - Collections.apply(runners, abortRunner); + apply(runners, abortRunner); }, forceMinPriority: function (p) { - Collections.apply(runners, function (runner) { + apply(runners, function (runner) { runner.forceMinPriority(p); }); } }; } function allRunnersFailed(runners) { - return Collections.all(runners, function (runner) { + return collections_all(runners, function (runner) { return Boolean(runner.error); }); } @@ -5443,19 +4807,12 @@ function abortRunner(runner) { } } +// CONCATENATED MODULE: ./src/core/strategies/cached_strategy.ts + -/***/ }), -/* 41 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var util_1 = __webpack_require__(2); -var runtime_1 = __webpack_require__(1); -var sequential_strategy_1 = __webpack_require__(14); -var Collections = __webpack_require__(0); -var CachedStrategy = (function () { +var cached_strategy_CachedStrategy = (function () { function CachedStrategy(strategy, transports, options) { this.strategy = strategy; this.transports = transports; @@ -5470,7 +4827,7 @@ var CachedStrategy = (function () { var usingTLS = this.usingTLS; var info = fetchTransportCache(usingTLS); var strategies = [this.strategy]; - if (info && info.timestamp + this.ttl >= util_1["default"].now()) { + if (info && info.timestamp + this.ttl >= util.now()) { var transport = this.transports[info.transport]; if (transport) { this.timeline.info({ @@ -5478,18 +4835,18 @@ var CachedStrategy = (function () { transport: info.transport, latency: info.latency }); - strategies.push(new sequential_strategy_1["default"]([transport], { + strategies.push(new sequential_strategy([transport], { timeout: info.latency * 2 + 1000, failFast: true })); } } - var startTimestamp = util_1["default"].now(); + var startTimestamp = util.now(); var runner = strategies.pop().connect(minPriority, function cb(error, handshake) { if (error) { flushTransportCache(usingTLS); if (strategies.length > 0) { - startTimestamp = util_1["default"].now(); + startTimestamp = util.now(); runner = strategies.pop().connect(minPriority, cb); } else { @@ -5497,7 +4854,7 @@ var CachedStrategy = (function () { } } else { - storeTransportCache(usingTLS, handshake.transport.name, util_1["default"].now() - startTimestamp); + storeTransportCache(usingTLS, handshake.transport.name, util.now() - startTimestamp); callback(null, handshake); } }); @@ -5515,12 +4872,12 @@ var CachedStrategy = (function () { }; return CachedStrategy; }()); -exports["default"] = CachedStrategy; +/* harmony default export */ var cached_strategy = (cached_strategy_CachedStrategy); function getTransportCacheKey(usingTLS) { return "pusherTransport" + (usingTLS ? "TLS" : "NonTLS"); } function fetchTransportCache(usingTLS) { - var storage = runtime_1["default"].getLocalStorage(); + var storage = worker_runtime.getLocalStorage(); if (storage) { try { var serializedCache = storage[getTransportCacheKey(usingTLS)]; @@ -5535,11 +4892,11 @@ function fetchTransportCache(usingTLS) { return null; } function storeTransportCache(usingTLS, transport, latency) { - var storage = runtime_1["default"].getLocalStorage(); + var storage = worker_runtime.getLocalStorage(); if (storage) { try { - storage[getTransportCacheKey(usingTLS)] = Collections.safeJSONStringify({ - timestamp: util_1["default"].now(), + storage[getTransportCacheKey(usingTLS)] = safeJSONStringify({ + timestamp: util.now(), transport: transport, latency: latency }); @@ -5549,7 +4906,7 @@ function storeTransportCache(usingTLS, transport, latency) { } } function flushTransportCache(usingTLS) { - var storage = runtime_1["default"].getLocalStorage(); + var storage = worker_runtime.getLocalStorage(); if (storage) { try { delete storage[getTransportCacheKey(usingTLS)]; @@ -5559,16 +4916,9 @@ function flushTransportCache(usingTLS) { } } +// CONCATENATED MODULE: ./src/core/strategies/delayed_strategy.ts -/***/ }), -/* 42 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var timers_1 = __webpack_require__(5); -var DelayedStrategy = (function () { +var delayed_strategy_DelayedStrategy = (function () { function DelayedStrategy(strategy, _a) { var number = _a.delay; this.strategy = strategy; @@ -5580,7 +4930,7 @@ var DelayedStrategy = (function () { DelayedStrategy.prototype.connect = function (minPriority, callback) { var strategy = this.strategy; var runner; - var timer = new timers_1.OneOffTimer(this.options.delay, function () { + var timer = new OneOffTimer(this.options.delay, function () { runner = strategy.connect(minPriority, callback); }); return { @@ -5600,16 +4950,9 @@ var DelayedStrategy = (function () { }; return DelayedStrategy; }()); -exports["default"] = DelayedStrategy; - - -/***/ }), -/* 43 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +/* harmony default export */ var delayed_strategy = (delayed_strategy_DelayedStrategy); -exports.__esModule = true; +// CONCATENATED MODULE: ./src/core/strategies/if_strategy.ts var IfStrategy = (function () { function IfStrategy(test, trueBranch, falseBranch) { this.test = test; @@ -5626,16 +4969,9 @@ var IfStrategy = (function () { }; return IfStrategy; }()); -exports["default"] = IfStrategy; - - -/***/ }), -/* 44 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +/* harmony default export */ var if_strategy = (IfStrategy); -exports.__esModule = true; +// CONCATENATED MODULE: ./src/core/strategies/first_connected_strategy.ts var FirstConnectedStrategy = (function () { function FirstConnectedStrategy(strategy) { this.strategy = strategy; @@ -5654,17 +4990,87 @@ var FirstConnectedStrategy = (function () { }; return FirstConnectedStrategy; }()); -exports["default"] = FirstConnectedStrategy; +/* harmony default export */ var first_connected_strategy = (FirstConnectedStrategy); +// CONCATENATED MODULE: ./src/runtimes/isomorphic/default_strategy.ts -/***/ }), -/* 45 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -function default_1() { + + + + + +function testSupportsStrategy(strategy) { + return function () { + return strategy.isSupported(); + }; +} +var getDefaultStrategy = function (config, defineTransport) { + var definedTransports = {}; + function defineTransportStrategy(name, type, priority, options, manager) { + var transport = defineTransport(config, name, type, priority, options, manager); + definedTransports[name] = transport; + return transport; + } + var ws_options = { + hostNonTLS: config.wsHost + ":" + config.wsPort, + hostTLS: config.wsHost + ":" + config.wssPort, + httpPath: config.wsPath + }; + var wss_options = extend({}, ws_options, { + useTLS: true + }); + var http_options = { + hostNonTLS: config.httpHost + ":" + config.httpPort, + hostTLS: config.httpHost + ":" + config.httpsPort, + httpPath: config.httpPath + }; + var timeouts = { + loop: true, + timeout: 15000, + timeoutLimit: 60000 + }; + var ws_manager = new transport_manager({ + lives: 2, + minPingDelay: 10000, + maxPingDelay: config.activity_timeout + }); + var streaming_manager = new transport_manager({ + lives: 2, + minPingDelay: 10000, + maxPingDelay: config.activity_timeout + }); + var ws_transport = defineTransportStrategy("ws", "ws", 3, ws_options, ws_manager); + var wss_transport = defineTransportStrategy("wss", "ws", 3, wss_options, ws_manager); + var xhr_streaming_transport = defineTransportStrategy("xhr_streaming", "xhr_streaming", 1, http_options, streaming_manager); + var xhr_polling_transport = defineTransportStrategy("xhr_polling", "xhr_polling", 1, http_options); + var ws_loop = new sequential_strategy([ws_transport], timeouts); + var wss_loop = new sequential_strategy([wss_transport], timeouts); + var streaming_loop = new sequential_strategy([xhr_streaming_transport], timeouts); + var polling_loop = new sequential_strategy([xhr_polling_transport], timeouts); + var http_loop = new sequential_strategy([new if_strategy(testSupportsStrategy(streaming_loop), new best_connected_ever_strategy([streaming_loop, new delayed_strategy(polling_loop, { delay: 4000 })]), polling_loop)], timeouts); + var wsStrategy; + if (config.useTLS) { + wsStrategy = new best_connected_ever_strategy([ws_loop, new delayed_strategy(http_loop, { delay: 2000 })]); + } + else { + wsStrategy = new best_connected_ever_strategy([ + ws_loop, + new delayed_strategy(wss_loop, { delay: 2000 }), + new delayed_strategy(http_loop, { delay: 5000 }) + ]); + } + return new cached_strategy(new first_connected_strategy(new if_strategy(testSupportsStrategy(ws_transport), wsStrategy, http_loop)), definedTransports, { + ttl: 1800000, + timeline: config.timeline, + useTLS: config.useTLS + }); +}; +/* harmony default export */ var default_strategy = (getDefaultStrategy); + +// CONCATENATED MODULE: ./src/runtimes/isomorphic/transports/transport_connection_initializer.ts +/* harmony default export */ var transport_connection_initializer = (function () { var self = this; self.timeline.info(self.buildTimelineMessage({ transport: self.name + (self.options.useTLS ? "s" : "") @@ -5675,49 +5081,10 @@ function default_1() { else { self.onClose(); } -} -exports["default"] = default_1; - - -/***/ }), -/* 46 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var http_request_1 = __webpack_require__(47); -var http_socket_1 = __webpack_require__(48); -var http_streaming_socket_1 = __webpack_require__(50); -var http_polling_socket_1 = __webpack_require__(51); -var http_xhr_request_1 = __webpack_require__(52); -var HTTP = { - createStreamingSocket: function (url) { - return this.createSocket(http_streaming_socket_1["default"], url); - }, - createPollingSocket: function (url) { - return this.createSocket(http_polling_socket_1["default"], url); - }, - createSocket: function (hooks, url) { - return new http_socket_1["default"](hooks, url); - }, - createXHR: function (method, url) { - return this.createRequest(http_xhr_request_1["default"], method, url); - }, - createRequest: function (hooks, method, url) { - return new http_request_1["default"](hooks, method, url); - } -}; -exports["default"] = HTTP; - - -/***/ }), -/* 47 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +}); -var __extends = (this && this.__extends) || (function () { +// CONCATENATED MODULE: ./src/core/http/http_request.ts +var http_request_extends = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || @@ -5730,12 +5097,11 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var dispatcher_1 = __webpack_require__(4); + + var MAX_BUFFER_LENGTH = 256 * 1024; -var HTTPRequest = (function (_super) { - __extends(HTTPRequest, _super); +var http_request_HTTPRequest = (function (_super) { + http_request_extends(HTTPRequest, _super); function HTTPRequest(hooks, method, url) { var _this = _super.call(this) || this; _this.hooks = hooks; @@ -5750,7 +5116,7 @@ var HTTPRequest = (function (_super) { this.unloader = function () { _this.close(); }; - runtime_1["default"].addUnloadListener(this.unloader); + worker_runtime.addUnloadListener(this.unloader); this.xhr.open(this.method, this.url, true); if (this.xhr.setRequestHeader) { this.xhr.setRequestHeader("Content-Type", "application/json"); @@ -5759,7 +5125,7 @@ var HTTPRequest = (function (_super) { }; HTTPRequest.prototype.close = function () { if (this.unloader) { - runtime_1["default"].removeUnloadListener(this.unloader); + worker_runtime.removeUnloadListener(this.unloader); this.unloader = null; } if (this.xhr) { @@ -5796,27 +5162,29 @@ var HTTPRequest = (function (_super) { return this.position === buffer.length && buffer.length > MAX_BUFFER_LENGTH; }; return HTTPRequest; -}(dispatcher_1["default"])); -exports["default"] = HTTPRequest; +}(dispatcher)); +/* harmony default export */ var http_request = (http_request_HTTPRequest); + +// CONCATENATED MODULE: ./src/core/http/state.ts +var State; +(function (State) { + State[State["CONNECTING"] = 0] = "CONNECTING"; + State[State["OPEN"] = 1] = "OPEN"; + State[State["CLOSED"] = 3] = "CLOSED"; +})(State || (State = {})); +/* harmony default export */ var state = (State); +// CONCATENATED MODULE: ./src/core/http/http_socket.ts -/***/ }), -/* 48 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var state_1 = __webpack_require__(49); -var util_1 = __webpack_require__(2); -var runtime_1 = __webpack_require__(1); var autoIncrement = 1; -var HTTPSocket = (function () { +var http_socket_HTTPSocket = (function () { function HTTPSocket(hooks, url) { this.hooks = hooks; this.session = randomNumber(1000) + "/" + randomString(8); this.location = getLocation(url); - this.readyState = state_1["default"].CONNECTING; + this.readyState = state.CONNECTING; this.openStream(); } HTTPSocket.prototype.send = function (payload) { @@ -5829,9 +5197,9 @@ var HTTPSocket = (function () { this.onClose(code, reason, true); }; HTTPSocket.prototype.sendRaw = function (payload) { - if (this.readyState === state_1["default"].OPEN) { + if (this.readyState === state.OPEN) { try { - runtime_1["default"].createSocketRequest("POST", getUniqueURL(getSendURL(this.location, this.session))).start(payload); + worker_runtime.createSocketRequest("POST", getUniqueURL(getSendURL(this.location, this.session))).start(payload); return true; } catch (e) { @@ -5849,7 +5217,7 @@ var HTTPSocket = (function () { ; HTTPSocket.prototype.onClose = function (code, reason, wasClean) { this.closeStream(); - this.readyState = state_1["default"].CLOSED; + this.readyState = state.CLOSED; if (this.onclose) { this.onclose({ code: code, @@ -5862,7 +5230,7 @@ var HTTPSocket = (function () { if (chunk.status !== 200) { return; } - if (this.readyState === state_1["default"].OPEN) { + if (this.readyState === state.OPEN) { this.onActivity(); } var payload; @@ -5892,11 +5260,11 @@ var HTTPSocket = (function () { } }; HTTPSocket.prototype.onOpen = function (options) { - if (this.readyState === state_1["default"].CONNECTING) { + if (this.readyState === state.CONNECTING) { if (options && options.hostname) { this.location.base = replaceHost(this.location.base, options.hostname); } - this.readyState = state_1["default"].OPEN; + this.readyState = state.OPEN; if (this.onopen) { this.onopen(); } @@ -5906,7 +5274,7 @@ var HTTPSocket = (function () { } }; HTTPSocket.prototype.onEvent = function (event) { - if (this.readyState === state_1["default"].OPEN && this.onmessage) { + if (this.readyState === state.OPEN && this.onmessage) { this.onmessage({ data: event }); } }; @@ -5922,7 +5290,7 @@ var HTTPSocket = (function () { }; HTTPSocket.prototype.openStream = function () { var _this = this; - this.stream = runtime_1["default"].createSocketRequest("POST", getUniqueURL(this.hooks.getReceiveURL(this.location, this.session))); + this.stream = worker_runtime.createSocketRequest("POST", getUniqueURL(this.hooks.getReceiveURL(this.location, this.session))); this.stream.bind("chunk", function (chunk) { _this.onChunk(chunk); }); @@ -5936,7 +5304,7 @@ var HTTPSocket = (function () { this.stream.start(); } catch (error) { - util_1["default"].defer(function () { + util.defer(function () { _this.onError(error); _this.onClose(1006, "Could not start streaming", false); }); @@ -5979,33 +5347,10 @@ function randomString(length) { } return result.join(''); } -exports["default"] = HTTPSocket; - - -/***/ }), -/* 49 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - -exports.__esModule = true; -var State; -(function (State) { - State[State["CONNECTING"] = 0] = "CONNECTING"; - State[State["OPEN"] = 1] = "OPEN"; - State[State["CLOSED"] = 3] = "CLOSED"; -})(State || (State = {})); -exports["default"] = State; - - -/***/ }), -/* 50 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +/* harmony default export */ var http_socket = (http_socket_HTTPSocket); -exports.__esModule = true; -var hooks = { +// CONCATENATED MODULE: ./src/core/http/http_streaming_socket.ts +var http_streaming_socket_hooks = { getReceiveURL: function (url, session) { return url.base + "/" + session + "/xhr_streaming" + url.queryString; }, @@ -6019,17 +5364,10 @@ var hooks = { socket.onClose(1006, "Connection interrupted (" + status + ")", false); } }; -exports["default"] = hooks; - - -/***/ }), -/* 51 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +/* harmony default export */ var http_streaming_socket = (http_streaming_socket_hooks); -exports.__esModule = true; -var hooks = { +// CONCATENATED MODULE: ./src/core/http/http_polling_socket.ts +var http_polling_socket_hooks = { getReceiveURL: function (url, session) { return url.base + "/" + session + "/xhr" + url.queryString; }, @@ -6047,20 +5385,13 @@ var hooks = { } } }; -exports["default"] = hooks; - +/* harmony default export */ var http_polling_socket = (http_polling_socket_hooks); -/***/ }), -/* 52 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +// CONCATENATED MODULE: ./src/runtimes/isomorphic/http/http_xhr_request.ts -exports.__esModule = true; -var runtime_1 = __webpack_require__(1); -var hooks = { +var http_xhr_request_hooks = { getRequest: function (socket) { - var Constructor = runtime_1["default"].getXHRAPI(); + var Constructor = worker_runtime.getXHRAPI(); var xhr = new Constructor(); xhr.onreadystatechange = xhr.onprogress = function () { switch (xhr.readyState) { @@ -6085,16 +5416,82 @@ var hooks = { xhr.abort(); } }; -exports["default"] = hooks; +/* harmony default export */ var http_xhr_request = (http_xhr_request_hooks); +// CONCATENATED MODULE: ./src/runtimes/isomorphic/http/http.ts -/***/ }), -/* 53 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -var __extends = (this && this.__extends) || (function () { + + +var HTTP = { + createStreamingSocket: function (url) { + return this.createSocket(http_streaming_socket, url); + }, + createPollingSocket: function (url) { + return this.createSocket(http_polling_socket, url); + }, + createSocket: function (hooks, url) { + return new http_socket(hooks, url); + }, + createXHR: function (method, url) { + return this.createRequest(http_xhr_request, method, url); + }, + createRequest: function (hooks, method, url) { + return new http_request(hooks, method, url); + } +}; +/* harmony default export */ var http_http = (HTTP); + +// CONCATENATED MODULE: ./src/runtimes/isomorphic/runtime.ts + + + + + +var Isomorphic = { + getDefaultStrategy: default_strategy, + Transports: transports, + transportConnectionInitializer: transport_connection_initializer, + HTTPFactory: http_http, + setup: function (PusherClass) { + PusherClass.ready(); + }, + getLocalStorage: function () { + return undefined; + }, + getClientFeatures: function () { + return keys(filterObject({ "ws": transports.ws }, function (t) { return t.isSupported({}); })); + }, + getProtocol: function () { + return "http:"; + }, + isXHRSupported: function () { + return true; + }, + createSocketRequest: function (method, url) { + if (this.isXHRSupported()) { + return this.HTTPFactory.createXHR(method, url); + } + else { + throw "Cross-origin HTTP requests are not supported"; + } + }, + createXHR: function () { + var Constructor = this.getXHRAPI(); + return new Constructor(); + }, + createWebSocket: function (url) { + var Constructor = this.getWebSocketAPI(); + return new Constructor(url); + }, + addUnloadListener: function (listener) { }, + removeUnloadListener: function (listener) { } +}; +/* harmony default export */ var runtime = (Isomorphic); + +// CONCATENATED MODULE: ./src/runtimes/worker/net_info.ts +var net_info_extends = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || @@ -6107,10 +5504,9 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -exports.__esModule = true; -var dispatcher_1 = __webpack_require__(4); + var NetInfo = (function (_super) { - __extends(NetInfo, _super); + net_info_extends(NetInfo, _super); function NetInfo() { return _super !== null && _super.apply(this, arguments) || this; } @@ -6118,19 +5514,12 @@ var NetInfo = (function (_super) { return true; }; return NetInfo; -}(dispatcher_1["default"])); -exports.NetInfo = NetInfo; -exports.Network = new NetInfo(); - +}(dispatcher)); -/***/ }), -/* 54 */ -/***/ (function(module, exports, __webpack_require__) { +var net_info_Network = new NetInfo(); -"use strict"; +// CONCATENATED MODULE: ./src/runtimes/worker/auth/fetch_auth.ts -exports.__esModule = true; -var logger_1 = __webpack_require__(3); var fetchAuth = function (context, socketId, callback) { var headers = new Headers(); headers.set("Content-Type", "application/x-www-form-urlencoded"); @@ -6150,7 +5539,7 @@ var fetchAuth = function (context, socketId, callback) { return response.text(); } else { - logger_1["default"].warn("Couldn't get auth info from your webapp", status); + logger.warn("Couldn't get auth info from your webapp", status); throw status; } }).then(function (data) { @@ -6159,7 +5548,7 @@ var fetchAuth = function (context, socketId, callback) { } catch (e) { var message = 'JSON returned from webapp was invalid, yet status code was 200. Data was: ' + data; - logger_1["default"].warn(message); + logger.warn(message); throw message; } callback(false, data); @@ -6167,23 +5556,16 @@ var fetchAuth = function (context, socketId, callback) { callback(true, err); }); }; -exports["default"] = fetchAuth; - +/* harmony default export */ var fetch_auth = (fetchAuth); -/***/ }), -/* 55 */ -/***/ (function(module, exports, __webpack_require__) { +// CONCATENATED MODULE: ./src/runtimes/worker/timeline/fetch_timeline.ts -"use strict"; -exports.__esModule = true; -var logger_1 = __webpack_require__(3); -var Collections = __webpack_require__(0); var getAgent = function (sender, useTLS) { return function (data, callback) { var scheme = "http" + (useTLS ? "s" : "") + "://"; var url = scheme + (sender.host || sender.options.host) + sender.options.path; - var query = Collections.buildQueryString(data); + var query = buildQueryString(data); url += ("/" + 2 + "?" + query); fetch(url). then(function (response) { @@ -6197,7 +5579,7 @@ var getAgent = function (sender, useTLS) { sender.host = host; } })["catch"](function (err) { - logger_1["default"].debug("TimelineSender Error: ", err); + logger.debug("TimelineSender Error: ", err); }); }; }; @@ -6205,20 +5587,58 @@ var fetchTimeline = { name: 'xhr', getAgent: getAgent }; -exports["default"] = fetchTimeline; +/* harmony default export */ var fetch_timeline = (fetchTimeline); + +// CONCATENATED MODULE: ./src/runtimes/worker/runtime.ts + + + + +var runtime_getDefaultStrategy = runtime.getDefaultStrategy, runtime_Transports = runtime.Transports, setup = runtime.setup, getProtocol = runtime.getProtocol, isXHRSupported = runtime.isXHRSupported, getLocalStorage = runtime.getLocalStorage, createXHR = runtime.createXHR, createWebSocket = runtime.createWebSocket, addUnloadListener = runtime.addUnloadListener, removeUnloadListener = runtime.removeUnloadListener, transportConnectionInitializer = runtime.transportConnectionInitializer, createSocketRequest = runtime.createSocketRequest, HTTPFactory = runtime.HTTPFactory; +var Worker = { + getDefaultStrategy: runtime_getDefaultStrategy, + Transports: runtime_Transports, + setup: setup, + getProtocol: getProtocol, + isXHRSupported: isXHRSupported, + getLocalStorage: getLocalStorage, + createXHR: createXHR, + createWebSocket: createWebSocket, + addUnloadListener: addUnloadListener, + removeUnloadListener: removeUnloadListener, + transportConnectionInitializer: transportConnectionInitializer, + createSocketRequest: createSocketRequest, + HTTPFactory: HTTPFactory, + TimelineTransport: fetch_timeline, + getAuthorizers: function () { + return { ajax: fetch_auth }; + }, + getWebSocketAPI: function () { + return WebSocket; + }, + getXHRAPI: function () { + return XMLHttpRequest; + }, + getNetwork: function () { + return net_info_Network; + } +}; +/* harmony default export */ var worker_runtime = (Worker); + +// CONCATENATED MODULE: ./src/core/timeline/level.ts +var TimelineLevel; +(function (TimelineLevel) { + TimelineLevel[TimelineLevel["ERROR"] = 3] = "ERROR"; + TimelineLevel[TimelineLevel["INFO"] = 6] = "INFO"; + TimelineLevel[TimelineLevel["DEBUG"] = 7] = "DEBUG"; +})(TimelineLevel || (TimelineLevel = {})); +/* harmony default export */ var timeline_level = (TimelineLevel); +// CONCATENATED MODULE: ./src/core/timeline/timeline.ts -/***/ }), -/* 56 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var Collections = __webpack_require__(0); -var util_1 = __webpack_require__(2); -var level_1 = __webpack_require__(15); -var Timeline = (function () { +var timeline_Timeline = (function () { function Timeline(key, session, options) { this.key = key; this.session = session; @@ -6229,27 +5649,27 @@ var Timeline = (function () { } Timeline.prototype.log = function (level, event) { if (level <= this.options.level) { - this.events.push(Collections.extend({}, event, { timestamp: util_1["default"].now() })); + this.events.push(extend({}, event, { timestamp: util.now() })); if (this.options.limit && this.events.length > this.options.limit) { this.events.shift(); } } }; Timeline.prototype.error = function (event) { - this.log(level_1["default"].ERROR, event); + this.log(timeline_level.ERROR, event); }; Timeline.prototype.info = function (event) { - this.log(level_1["default"].INFO, event); + this.log(timeline_level.INFO, event); }; Timeline.prototype.debug = function (event) { - this.log(level_1["default"].DEBUG, event); + this.log(timeline_level.DEBUG, event); }; Timeline.prototype.isEmpty = function () { return this.events.length === 0; }; Timeline.prototype.send = function (sendfn, callback) { var _this = this; - var data = Collections.extend({ + var data = extend({ session: this.session, bundle: this.sent + 1, key: this.key, @@ -6276,75 +5696,14 @@ var Timeline = (function () { }; return Timeline; }()); -exports["default"] = Timeline; - - -/***/ }), -/* 57 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +/* harmony default export */ var timeline_timeline = (timeline_Timeline); -exports.__esModule = true; -var Collections = __webpack_require__(0); -var util_1 = __webpack_require__(2); -var Errors = __webpack_require__(7); -var transport_strategy_1 = __webpack_require__(58); -var runtime_1 = __webpack_require__(1); -var Transports = runtime_1["default"].Transports; -exports.defineTransport = function (config, name, type, priority, options, manager) { - var transportClass = Transports[type]; - if (!transportClass) { - throw new Errors.UnsupportedTransport(type); - } - var enabled = (!config.enabledTransports || - Collections.arrayIndexOf(config.enabledTransports, name) !== -1) && - (!config.disabledTransports || - Collections.arrayIndexOf(config.disabledTransports, name) === -1); - var transport; - if (enabled) { - transport = new transport_strategy_1["default"](name, priority, manager ? manager.getAssistant(transportClass) : transportClass, Collections.extend({ - key: config.key, - useTLS: config.useTLS, - timeline: config.timeline, - ignoreNullOrigin: config.ignoreNullOrigin - }, options)); - } - else { - transport = UnsupportedStrategy; - } - return transport; -}; -var UnsupportedStrategy = { - isSupported: function () { - return false; - }, - connect: function (_, callback) { - var deferred = util_1["default"].defer(function () { - callback(new Errors.UnsupportedStrategy()); - }); - return { - abort: function () { - deferred.ensureAborted(); - }, - forceMinPriority: function () { } - }; - } -}; +// CONCATENATED MODULE: ./src/core/strategies/transport_strategy.ts -/***/ }), -/* 58 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var factory_1 = __webpack_require__(6); -var util_1 = __webpack_require__(2); -var Errors = __webpack_require__(7); -var Collections = __webpack_require__(0); -var TransportStrategy = (function () { +var transport_strategy_TransportStrategy = (function () { function TransportStrategy(name, priority, transport, options) { this.name = name; this.priority = priority; @@ -6359,10 +5718,10 @@ var TransportStrategy = (function () { TransportStrategy.prototype.connect = function (minPriority, callback) { var _this = this; if (!this.isSupported()) { - return failAttempt(new Errors.UnsupportedStrategy(), callback); + return failAttempt(new UnsupportedStrategy(), callback); } else if (this.priority < minPriority) { - return failAttempt(new Errors.TransportPriorityTooLow(), callback); + return failAttempt(new TransportPriorityTooLow(), callback); } var connected = false; var transport = this.transport.createConnection(this.name, this.priority, this.options.key, this.options); @@ -6372,7 +5731,7 @@ var TransportStrategy = (function () { transport.connect(); }; var onOpen = function () { - handshake = factory_1["default"].createHandshake(transport, function (result) { + handshake = factory.createHandshake(transport, function (result) { connected = true; unbindListeners(); callback(null, result); @@ -6385,8 +5744,8 @@ var TransportStrategy = (function () { var onClosed = function () { unbindListeners(); var serializedTransport; - serializedTransport = Collections.safeJSONStringify(transport); - callback(new Errors.TransportClosed(serializedTransport)); + serializedTransport = safeJSONStringify(transport); + callback(new TransportClosed(serializedTransport)); }; var unbindListeners = function () { transport.unbind("initialized", onInitialized); @@ -6429,9 +5788,9 @@ var TransportStrategy = (function () { }; return TransportStrategy; }()); -exports["default"] = TransportStrategy; +/* harmony default export */ var transport_strategy = (transport_strategy_TransportStrategy); function failAttempt(error, callback) { - util_1["default"].defer(function () { + util.defer(function () { callback(error); }); return { @@ -6440,40 +5799,289 @@ function failAttempt(error, callback) { }; } +// CONCATENATED MODULE: ./src/core/strategies/strategy_builder.ts -/***/ }), -/* 59 */ -/***/ (function(module, exports, __webpack_require__) { -"use strict"; -exports.__esModule = true; -var defaults_1 = __webpack_require__(8); -exports.getGlobalConfig = function () { + + +var strategy_builder_Transports = worker_runtime.Transports; +var strategy_builder_defineTransport = function (config, name, type, priority, options, manager) { + var transportClass = strategy_builder_Transports[type]; + if (!transportClass) { + throw new UnsupportedTransport(type); + } + var enabled = (!config.enabledTransports || + arrayIndexOf(config.enabledTransports, name) !== -1) && + (!config.disabledTransports || + arrayIndexOf(config.disabledTransports, name) === -1); + var transport; + if (enabled) { + transport = new transport_strategy(name, priority, manager ? manager.getAssistant(transportClass) : transportClass, extend({ + key: config.key, + useTLS: config.useTLS, + timeline: config.timeline, + ignoreNullOrigin: config.ignoreNullOrigin + }, options)); + } + else { + transport = strategy_builder_UnsupportedStrategy; + } + return transport; +}; +var strategy_builder_UnsupportedStrategy = { + isSupported: function () { + return false; + }, + connect: function (_, callback) { + var deferred = util.defer(function () { + callback(new UnsupportedStrategy()); + }); + return { + abort: function () { + deferred.ensureAborted(); + }, + forceMinPriority: function () { } + }; + } +}; + +// CONCATENATED MODULE: ./src/core/config.ts + +var getGlobalConfig = function () { return { - wsHost: defaults_1["default"].host, - wsPort: defaults_1["default"].ws_port, - wssPort: defaults_1["default"].wss_port, - wsPath: defaults_1["default"].ws_path, - httpHost: defaults_1["default"].sockjs_host, - httpPort: defaults_1["default"].sockjs_http_port, - httpsPort: defaults_1["default"].sockjs_https_port, - httpPath: defaults_1["default"].sockjs_path, - statsHost: defaults_1["default"].stats_host, - authEndpoint: defaults_1["default"].channel_auth_endpoint, - authTransport: defaults_1["default"].channel_auth_transport, - activity_timeout: defaults_1["default"].activity_timeout, - pong_timeout: defaults_1["default"].pong_timeout, - unavailable_timeout: defaults_1["default"].unavailable_timeout + wsHost: defaults.host, + wsPort: defaults.ws_port, + wssPort: defaults.wss_port, + wsPath: defaults.ws_path, + httpHost: defaults.sockjs_host, + httpPort: defaults.sockjs_http_port, + httpsPort: defaults.sockjs_https_port, + httpPath: defaults.sockjs_path, + statsHost: defaults.stats_host, + authEndpoint: defaults.channel_auth_endpoint, + authTransport: defaults.channel_auth_transport, + activity_timeout: defaults.activity_timeout, + pong_timeout: defaults.pong_timeout, + unavailable_timeout: defaults.unavailable_timeout }; }; -exports.getClusterConfig = function (clusterName) { +var getClusterConfig = function (clusterName) { return { - wsHost: "ws-" + clusterName + ".pusher.com", - httpHost: "sockjs-" + clusterName + ".pusher.com" + wsHost: 'ws-' + clusterName + '.pusher.com', + httpHost: 'sockjs-' + clusterName + '.pusher.com' }; }; +// CONCATENATED MODULE: ./src/core/pusher.ts + + + + + + + + + + + + +var pusher_Pusher = (function () { + function Pusher(app_key, options) { + var _this = this; + checkAppKey(app_key); + options = options || {}; + if (!options.cluster && !(options.wsHost || options.httpHost)) { + var suffix = url_store.buildLogSuffix('javascriptQuickStart'); + logger.warn("You should always specify a cluster when connecting. " + suffix); + } + this.key = app_key; + this.config = extend(getGlobalConfig(), options.cluster ? getClusterConfig(options.cluster) : {}, options); + this.channels = factory.createChannels(); + this.global_emitter = new dispatcher(); + this.sessionID = Math.floor(Math.random() * 1000000000); + this.timeline = new timeline_timeline(this.key, this.sessionID, { + cluster: this.config.cluster, + features: Pusher.getClientFeatures(), + params: this.config.timelineParams || {}, + limit: 50, + level: timeline_level.INFO, + version: defaults.VERSION + }); + if (!this.config.disableStats) { + this.timelineSender = factory.createTimelineSender(this.timeline, { + host: this.config.statsHost, + path: '/timeline/v2/' + worker_runtime.TimelineTransport.name + }); + } + var getStrategy = function (options) { + var config = extend({}, _this.config, options); + return worker_runtime.getDefaultStrategy(config, strategy_builder_defineTransport); + }; + this.connection = factory.createConnectionManager(this.key, extend({ + getStrategy: getStrategy, + timeline: this.timeline, + activityTimeout: this.config.activity_timeout, + pongTimeout: this.config.pong_timeout, + unavailableTimeout: this.config.unavailable_timeout + }, this.config, { useTLS: this.shouldUseTLS() })); + this.connection.bind('connected', function () { + _this.subscribeAll(); + if (_this.timelineSender) { + _this.timelineSender.send(_this.connection.isUsingTLS()); + } + }); + this.connection.bind('message', function (event) { + var eventName = event.event; + var internal = eventName.indexOf('pusher_internal:') === 0; + if (event.channel) { + var channel = _this.channel(event.channel); + if (channel) { + channel.handleEvent(event); + } + } + if (!internal) { + _this.global_emitter.emit(event.event, event.data); + } + }); + this.connection.bind('connecting', function () { + _this.channels.disconnect(); + }); + this.connection.bind('disconnected', function () { + _this.channels.disconnect(); + }); + this.connection.bind('error', function (err) { + logger.warn('Error', err); + }); + Pusher.instances.push(this); + this.timeline.info({ instances: Pusher.instances.length }); + if (Pusher.isReady) { + this.connect(); + } + } + Pusher.ready = function () { + Pusher.isReady = true; + for (var i = 0, l = Pusher.instances.length; i < l; i++) { + Pusher.instances[i].connect(); + } + }; + Pusher.log = function (message) { + if (Pusher.logToConsole && self.console && self.console.log) { + self.console.log(message); + } + }; + Pusher.getClientFeatures = function () { + return keys(filterObject({ ws: worker_runtime.Transports.ws }, function (t) { + return t.isSupported({}); + })); + }; + Pusher.prototype.channel = function (name) { + return this.channels.find(name); + }; + Pusher.prototype.allChannels = function () { + return this.channels.all(); + }; + Pusher.prototype.connect = function () { + this.connection.connect(); + if (this.timelineSender) { + if (!this.timelineSenderTimer) { + var usingTLS = this.connection.isUsingTLS(); + var timelineSender = this.timelineSender; + this.timelineSenderTimer = new PeriodicTimer(60000, function () { + timelineSender.send(usingTLS); + }); + } + } + }; + Pusher.prototype.disconnect = function () { + this.connection.disconnect(); + if (this.timelineSenderTimer) { + this.timelineSenderTimer.ensureAborted(); + this.timelineSenderTimer = null; + } + }; + Pusher.prototype.bind = function (event_name, callback, context) { + this.global_emitter.bind(event_name, callback, context); + return this; + }; + Pusher.prototype.unbind = function (event_name, callback, context) { + this.global_emitter.unbind(event_name, callback, context); + return this; + }; + Pusher.prototype.bind_global = function (callback) { + this.global_emitter.bind_global(callback); + return this; + }; + Pusher.prototype.unbind_global = function (callback) { + this.global_emitter.unbind_global(callback); + return this; + }; + Pusher.prototype.unbind_all = function (callback) { + this.global_emitter.unbind_all(); + return this; + }; + Pusher.prototype.subscribeAll = function () { + var channelName; + for (channelName in this.channels.channels) { + if (this.channels.channels.hasOwnProperty(channelName)) { + this.subscribe(channelName); + } + } + }; + Pusher.prototype.subscribe = function (channel_name) { + var channel = this.channels.add(channel_name, this); + if (channel.subscriptionPending && channel.subscriptionCancelled) { + channel.reinstateSubscription(); + } + else if (!channel.subscriptionPending && + this.connection.state === 'connected') { + channel.subscribe(); + } + return channel; + }; + Pusher.prototype.unsubscribe = function (channel_name) { + var channel = this.channels.find(channel_name); + if (channel && channel.subscriptionPending) { + channel.cancelSubscription(); + } + else { + channel = this.channels.remove(channel_name); + if (channel && this.connection.state === 'connected') { + channel.unsubscribe(); + } + } + }; + Pusher.prototype.send_event = function (event_name, data, channel) { + return this.connection.send_event(event_name, data, channel); + }; + Pusher.prototype.shouldUseTLS = function () { + if (worker_runtime.getProtocol() === 'https:') { + return true; + } + else if (this.config.forceTLS === true) { + return true; + } + else { + return Boolean(this.config.encrypted); + } + }; + Pusher.instances = []; + Pusher.isReady = false; + Pusher.logToConsole = false; + Pusher.Runtime = worker_runtime; + Pusher.ScriptReceivers = worker_runtime.ScriptReceivers; + Pusher.DependenciesReceivers = worker_runtime.DependenciesReceivers; + Pusher.auth_callbacks = worker_runtime.auth_callbacks; + return Pusher; +}()); +/* harmony default export */ var core_pusher = __webpack_exports__["default"] = (pusher_Pusher); +function checkAppKey(key) { + if (key === null || key === undefined) { + throw 'You must pass your app key when you instantiate Pusher.'; + } +} +worker_runtime.setup(pusher_Pusher); + /***/ }) /******/ ]); \ No newline at end of file diff --git a/dist/worker/pusher.worker.min.js b/dist/worker/pusher.worker.min.js index fab7cdc14..57d69b616 100644 --- a/dist/worker/pusher.worker.min.js +++ b/dist/worker/pusher.worker.min.js @@ -1,8 +1,8 @@ /*! - * Pusher JavaScript Library v5.0.1 + * Pusher JavaScript Library v5.0.2 * https://pusher.com/ * * Copyright 2017, Pusher * Released under the MIT licence. */ -var Pusher=function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=16)}([function(t,e,n){"use strict";e.__esModule=!0;var r=n(18),o=n(2);function i(t,e){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e(t[n],n,t)}function s(t,e){for(var n=[],r=0;r0)for(r=0;r=1002&&t.code<=1004?"backoff":null:4e3===t.code?"tls_only":t.code<4100?"refused":t.code<4200?"backoff":t.code<4300?"retry":"refused"},e.getCloseError=function(t){return 1e3!==t.code&&1001!==t.code?{type:"PusherError",data:{code:t.code,message:t.reason||t.message}}:null}},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var i=n(4),s=n(7),a=n(3),u=n(10),c=function(t){function e(e,n){var r=t.call(this,function(t,n){a.default.debug("No callbacks on "+e+" for "+t)})||this;return r.name=e,r.pusher=n,r.subscribed=!1,r.subscriptionPending=!1,r.subscriptionCancelled=!1,r}return o(e,t),e.prototype.authorize=function(t,e){return e(!1,{})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new s.BadEventName("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var n=u.default.buildLogSuffix("triggeringClientEvents");a.default.warn("Client event triggered before channel 'subscription_succeeded' event . "+n)}return this.pusher.send_event(t,e,this.name)},e.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},e.prototype.handleEvent=function(t){var e=t.event,n=t.data;if("pusher_internal:subscription_succeeded"===e)this.handleSubscriptionSucceededEvent(t);else if(0!==e.indexOf("pusher_internal:")){this.emit(e,n,{})}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",t.data)},e.prototype.subscribe=function(){var t=this;this.subscribed||(this.subscriptionPending=!0,this.subscriptionCancelled=!1,this.authorize(this.pusher.connection.socket_id,function(e,n){e?t.emit("pusher:subscription_error",n):t.pusher.send_event("pusher:subscribe",{auth:n.auth,channel_data:n.channel_data,channel:t.name})}))},e.prototype.unsubscribe=function(){this.subscribed=!1,this.pusher.send_event("pusher:unsubscribe",{channel:this.name})},e.prototype.cancelSubscription=function(){this.subscriptionCancelled=!0},e.prototype.reinstateSubscription=function(){this.subscriptionCancelled=!1},e}(i.default);e.default=c},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(2),i=n(5),s=function(){function t(t,e){this.strategies=t,this.loop=Boolean(e.loop),this.failFast=Boolean(e.failFast),this.timeout=e.timeout,this.timeoutLimit=e.timeoutLimit}return t.prototype.isSupported=function(){return r.any(this.strategies,o.default.method("isSupported"))},t.prototype.connect=function(t,e){var n=this,r=this.strategies,o=0,i=this.timeout,s=null,a=function(u,c){c?e(null,c):(o+=1,n.loop&&(o%=r.length),o0&&(o=new i.OneOffTimer(n.timeout,function(){s.abort(),r(!0)})),s=t.connect(e,function(t,e){t&&o&&o.isRunning()&&!n.failFast||(o&&o.ensureAborted(),r(t,e))}),{abort:function(){o&&o.ensureAborted(),s.abort()},forceMinPriority:function(t){s.forceMinPriority(t)}}},t}();e.default=s},function(t,e,n){"use strict";var r;e.__esModule=!0,function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(r||(r={})),e.default=r},function(t,e,n){"use strict";e.__esModule=!0;var r=n(11);t.exports=r.default},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(20),i=n(25),s=n(45),a=n(46),u={getDefaultStrategy:i.default,Transports:o.default,transportConnectionInitializer:s.default,HTTPFactory:a.default,setup:function(t){t.ready()},getLocalStorage:function(){},getClientFeatures:function(){return r.keys(r.filterObject({ws:o.default.ws},function(t){return t.isSupported({})}))},getProtocol:function(){return"http:"},isXHRSupported:function(){return!0},createSocketRequest:function(t,e){if(this.isXHRSupported())return this.HTTPFactory.createXHR(t,e);throw"Cross-origin HTTP requests are not supported"},createXHR:function(){return new(this.getXHRAPI())},createWebSocket:function(t){return new(this.getWebSocketAPI())(t)},addUnloadListener:function(t){},removeUnloadListener:function(t){}};e.default=u},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(t){return f(c(t))};for(var r=String.fromCharCode,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i={},s=0,a=o.length;s>>6)+r(128|63&e):r(224|e>>>12&15)+r(128|e>>>6&63)+r(128|63&e)},c=function(t){return t.replace(/[^\x00-\x7F]/g,u)},h=function(t){var e=[0,2,1][t.length%3],n=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[o.charAt(n>>>18),o.charAt(n>>>12&63),e>=2?"=":o.charAt(n>>>6&63),e>=1?"=":o.charAt(63&n)].join("")},f=self.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,h)}},function(t,e,n){"use strict";e.__esModule=!0;var r=function(){function t(t,e,n,r){var o=this;this.clear=e,this.timer=t(function(){o.timer&&(o.timer=r(o.timer))},n)}return t.prototype.isRunning=function(){return null!==this.timer},t.prototype.ensureAborted=function(){this.timer&&(this.clear(this.timer),this.timer=null)},t}();e.default=r},function(t,e,n){"use strict";e.__esModule=!0;var r=n(21),o=n(22),i=n(0),s=n(1),a=new o.default({urls:r.ws,handlesActivityChecks:!1,supportsPing:!1,isInitialized:function(){return Boolean(s.default.getWebSocketAPI())},isSupported:function(){return Boolean(s.default.getWebSocketAPI())},getSocket:function(t){return s.default.createWebSocket(t)}}),u={urls:r.http,handlesActivityChecks:!1,supportsPing:!0,isInitialized:function(){return!0}};e.streamingConfiguration=i.extend({getSocket:function(t){return s.default.HTTPFactory.createStreamingSocket(t)}},u),e.pollingConfiguration=i.extend({getSocket:function(t){return s.default.HTTPFactory.createPollingSocket(t)}},u);var c={isSupported:function(){return s.default.isXHRSupported()}},h={ws:a,xhr_streaming:new o.default(i.extend({},e.streamingConfiguration,c)),xhr_polling:new o.default(i.extend({},e.pollingConfiguration,c))};e.default=h},function(t,e,n){"use strict";e.__esModule=!0;var r=n(8);function o(t,e,n){return t+(e.useTLS?"s":"")+"://"+(e.useTLS?e.hostTLS:e.hostNonTLS)+n}function i(t,e){return"/app/"+t+("?protocol="+r.default.PROTOCOL+"&client=js&version="+r.default.VERSION+(e?"&"+e:""))}e.ws={getInitial:function(t,e){return o("ws",e,(e.httpPath||"")+i(t,"flash=false"))}},e.http={getInitial:function(t,e){return o("http",e,(e.httpPath||"/pusher")+i(t))}},e.sockjs={getInitial:function(t,e){return o("http",e,e.httpPath||"/pusher")},getPath:function(t,e){return i(t)}}},function(t,e,n){"use strict";e.__esModule=!0;var r=n(23),o=function(){function t(t){this.hooks=t}return t.prototype.isSupported=function(t){return this.hooks.isSupported(t)},t.prototype.createConnection=function(t,e,n,o){return new r.default(this.hooks,t,e,n,o)},t}();e.default=o},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var i=n(2),s=n(0),a=n(4),u=n(3),c=n(1),h=function(t){function e(e,n,r,o,i){var s=t.call(this)||this;return s.initialize=c.default.transportConnectionInitializer,s.hooks=e,s.name=n,s.priority=r,s.key=o,s.options=i,s.state="new",s.timeline=i.timeline,s.activityTimeout=i.activityTimeout,s.id=s.timeline.generateUniqueID(),s}return o(e,t),e.prototype.handlesActivityChecks=function(){return Boolean(this.hooks.handlesActivityChecks)},e.prototype.supportsPing=function(){return Boolean(this.hooks.supportsPing)},e.prototype.connect=function(){var t=this;if(this.socket||"initialized"!==this.state)return!1;var e=this.hooks.urls.getInitial(this.key,this.options);try{this.socket=this.hooks.getSocket(e,this.options)}catch(e){return i.default.defer(function(){t.onError(e),t.changeState("closed")}),!1}return this.bindListeners(),u.default.debug("Connecting",{transport:this.name,url:e}),this.changeState("connecting"),!0},e.prototype.close=function(){return!!this.socket&&(this.socket.close(),!0)},e.prototype.send=function(t){var e=this;return"open"===this.state&&(i.default.defer(function(){e.socket&&e.socket.send(t)}),!0)},e.prototype.ping=function(){"open"===this.state&&this.supportsPing()&&this.socket.ping()},e.prototype.onOpen=function(){this.hooks.beforeOpen&&this.hooks.beforeOpen(this.socket,this.hooks.urls.getPath(this.key,this.options)),this.changeState("open"),this.socket.onopen=void 0},e.prototype.onError=function(t){this.emit("error",{type:"WebSocketError",error:t}),this.timeline.error(this.buildTimelineMessage({error:t.toString()}))},e.prototype.onClose=function(t){t?this.changeState("closed",{code:t.code,reason:t.reason,wasClean:t.wasClean}):this.changeState("closed"),this.unbindListeners(),this.socket=void 0},e.prototype.onMessage=function(t){this.emit("message",t)},e.prototype.onActivity=function(){this.emit("activity")},e.prototype.bindListeners=function(){var t=this;this.socket.onopen=function(){t.onOpen()},this.socket.onerror=function(e){t.onError(e)},this.socket.onclose=function(e){t.onClose(e)},this.socket.onmessage=function(e){t.onMessage(e)},this.supportsPing()&&(this.socket.onactivity=function(){t.onActivity()})},e.prototype.unbindListeners=function(){this.socket&&(this.socket.onopen=void 0,this.socket.onerror=void 0,this.socket.onclose=void 0,this.socket.onmessage=void 0,this.supportsPing()&&(this.socket.onactivity=void 0))},e.prototype.changeState=function(t,e){this.state=t,this.timeline.info(this.buildTimelineMessage({state:t,params:e})),this.emit(t,e)},e.prototype.buildTimelineMessage=function(t){return s.extend({cid:this.id},t)},e}(a.default);e.default=h},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=function(){function t(){this._callbacks={}}return t.prototype.get=function(t){return this._callbacks[i(t)]},t.prototype.add=function(t,e,n){var r=i(t);this._callbacks[r]=this._callbacks[r]||[],this._callbacks[r].push({fn:e,context:n})},t.prototype.remove=function(t,e,n){if(t||e||n){var o=t?[i(t)]:r.keys(this._callbacks);e||n?this.removeCallback(o,e,n):this.removeAllCallbacks(o)}else this._callbacks={}},t.prototype.removeCallback=function(t,e,n){r.apply(t,function(t){this._callbacks[t]=r.filter(this._callbacks[t]||[],function(t){return e&&e!==t.fn||n&&n!==t.context}),0===this._callbacks[t].length&&delete this._callbacks[t]},this)},t.prototype.removeAllCallbacks=function(t){r.apply(t,function(t){delete this._callbacks[t]},this)},t}();function i(t){return"_"+t}e.default=o},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(26),i=n(14),s=n(40),a=n(41),u=n(42),c=n(43),h=n(44);function f(t){return function(){return t.isSupported()}}e.default=function(t,e){var n={};function l(r,o,i,s,a){var u=e(t,r,o,i,s,a);return n[r]=u,u}var p,d={hostNonTLS:t.wsHost+":"+t.wsPort,hostTLS:t.wsHost+":"+t.wssPort,httpPath:t.wsPath},y=r.extend({},d,{useTLS:!0}),v={hostNonTLS:t.httpHost+":"+t.httpPort,hostTLS:t.httpHost+":"+t.httpsPort,httpPath:t.httpPath},g={loop:!0,timeout:15e3,timeoutLimit:6e4},b=new o.default({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),_=new o.default({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),m=l("ws","ws",3,d,b),w=l("wss","ws",3,y,b),S=l("xhr_streaming","xhr_streaming",1,v,_),k=l("xhr_polling","xhr_polling",1,v),T=new i.default([m],g),O=new i.default([w],g),C=new i.default([S],g),A=new i.default([k],g),x=new i.default([new c.default(f(C),new s.default([C,new u.default(A,{delay:4e3})]),A)],g);return p=t.useTLS?new s.default([T,new u.default(x,{delay:2e3})]):new s.default([T,new u.default(O,{delay:2e3}),new u.default(x,{delay:5e3})]),new a.default(new h.default(new c.default(f(m),p,x)),n,{ttl:18e5,timeline:t.timeline,useTLS:t.useTLS})}},function(t,e,n){"use strict";e.__esModule=!0;var r=n(6),o=function(){function t(t){this.options=t||{},this.livesLeft=this.options.lives||1/0}return t.prototype.getAssistant=function(t){return r.default.createAssistantToTheTransportManager(this,t,{minPingDelay:this.options.minPingDelay,maxPingDelay:this.options.maxPingDelay})},t.prototype.isAlive=function(){return this.livesLeft>0},t.prototype.reportDeath=function(){this.livesLeft-=1},t}();e.default=o},function(t,e,n){"use strict";e.__esModule=!0;var r=n(2),o=n(0),i=function(){function t(t,e,n){this.manager=t,this.transport=e,this.minPingDelay=n.minPingDelay,this.maxPingDelay=n.maxPingDelay,this.pingDelay=void 0}return t.prototype.createConnection=function(t,e,n,i){var s=this;i=o.extend({},i,{activityTimeout:this.pingDelay});var a=this.transport.createConnection(t,e,n,i),u=null,c=function(){a.unbind("open",c),a.bind("closed",h),u=r.default.now()},h=function(t){if(a.unbind("closed",h),1002===t.code||1003===t.code)s.manager.reportDeath();else if(!t.wasClean&&u){var e=r.default.now()-u;e<2*s.maxPingDelay&&(s.manager.reportDeath(),s.pingDelay=Math.max(e/2,s.minPingDelay))}};return a.bind("open",c),a},t.prototype.isSupported=function(t){return this.manager.isAlive()&&this.transport.isSupported(t)},t}();e.default=i},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(12),i=n(29),s=function(){function t(t,e){this.transport=t,this.callback=e,this.bindListeners()}return t.prototype.close=function(){this.unbindListeners(),this.transport.close()},t.prototype.bindListeners=function(){var t=this;this.onMessage=function(e){var n;t.unbindListeners();try{n=o.processHandshake(e)}catch(e){return t.finish("error",{error:e}),void t.transport.close()}"connected"===n.action?t.finish("connected",{connection:new i.default(n.id,t.transport),activityTimeout:n.activityTimeout}):(t.finish(n.action,{error:n.error}),t.transport.close())},this.onClosed=function(e){t.unbindListeners();var n=o.getCloseAction(e)||"backoff",r=o.getCloseError(e);t.finish(n,{error:r})},this.transport.bind("message",this.onMessage),this.transport.bind("closed",this.onClosed)},t.prototype.unbindListeners=function(){this.transport.unbind("message",this.onMessage),this.transport.unbind("closed",this.onClosed)},t.prototype.finish=function(t,e){this.callback(r.extend({transport:this.transport,action:t},e))},t}();e.default=s},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var i=n(0),s=n(4),a=n(12),u=n(3),c=function(t){function e(e,n){var r=t.call(this)||this;return r.id=e,r.transport=n,r.activityTimeout=n.activityTimeout,r.bindListeners(),r}return o(e,t),e.prototype.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()},e.prototype.send=function(t){return this.transport.send(t)},e.prototype.send_event=function(t,e,n){var r={event:t,data:e};return n&&(r.channel=n),u.default.debug("Event sent",r),this.send(a.encodeMessage(r))},e.prototype.ping=function(){this.transport.supportsPing()?this.transport.ping():this.send_event("pusher:ping",{})},e.prototype.close=function(){this.transport.close()},e.prototype.bindListeners=function(){var t=this,e={message:function(e){var n;try{n=a.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(u.default.debug("Event recd",n),n.event){case"pusher:error":t.emit("error",{type:"PusherError",data:n.data});break;case"pusher:ping":t.emit("ping");break;case"pusher:pong":t.emit("pong")}t.emit("message",n)}},activity:function(){t.emit("activity")},error:function(e){t.emit("error",{type:"WebSocketError",error:e})},closed:function(e){n(),e&&e.code&&t.handleCloseEvent(e),t.transport=null,t.emit("closed")}},n=function(){i.objectApply(e,function(e,n){t.transport.unbind(n,e)})};i.objectApply(e,function(e,n){t.transport.bind(n,e)})},e.prototype.handleCloseEvent=function(t){var e=a.getCloseAction(t),n=a.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(s.default);e.default=c},function(t,e,n){"use strict";e.__esModule=!0;var r=n(1),o=function(){function t(t,e){this.channel=t;var n=e.authTransport;if(void 0===r.default.getAuthorizers()[n])throw"'"+n+"' is not a recognized auth transport";this.type=n,this.options=e,this.authOptions=(e||{}).auth||{}}return t.prototype.composeQuery=function(t){var e="socket_id="+encodeURIComponent(t)+"&channel_name="+encodeURIComponent(this.channel.name);for(var n in this.authOptions.params)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(this.authOptions.params[n]);return e},t.prototype.authorize=function(e,n){return t.authorizers=t.authorizers||r.default.getAuthorizers(),t.authorizers[this.type].call(this,r.default,e,n)},t}();e.default=o},function(t,e,n){"use strict";e.__esModule=!0;var r=n(1),o=function(){function t(t,e){this.timeline=t,this.options=e||{}}return t.prototype.send=function(t,e){this.timeline.isEmpty()||this.timeline.send(r.default.TimelineTransport.getAgent(this,t),e)},t}();e.default=o},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var i=n(9),s=n(3),a=n(33),u=n(10),c=function(t){function e(e,n){var r=t.call(this,e,n)||this;return r.members=new a.default,r}return o(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,function(t,e){if(!t){if(void 0===e.channel_data){var o=u.default.buildLogSuffix("authenticationEndpoint");return s.default.warn("Invalid auth response for channel '"+r.name+"',expected 'channel_data' field. "+o),void n("Invalid auth response")}var i=JSON.parse(e.channel_data);r.members.setMyID(i.user_id)}n(t,e)})},e.prototype.handleEvent=function(t){var e=t.event;if(0===e.indexOf("pusher_internal:"))this.handleInternalEvent(t);else{var n=t.data,r={};t.user_id&&(r.user_id=t.user_id),this.emit(e,n,r)}},e.prototype.handleInternalEvent=function(t){var e=t.event,n=t.data;switch(e){case"pusher_internal:subscription_succeeded":this.handleSubscriptionSucceededEvent(t);break;case"pusher_internal:member_added":var r=this.members.addMember(n);this.emit("pusher:member_added",r);break;case"pusher_internal:member_removed":var o=this.members.removeMember(n);o&&this.emit("pusher:member_removed",o)}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(t.data),this.emit("pusher:subscription_succeeded",this.members))},e.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},e}(i.default);e.default=c},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=function(){function t(){this.reset()}return t.prototype.get=function(t){return Object.prototype.hasOwnProperty.call(this.members,t)?{id:t,info:this.members[t]}:null},t.prototype.each=function(t){var e=this;r.objectApply(this.members,function(n,r){t(e.get(r))})},t.prototype.setMyID=function(t){this.myID=t},t.prototype.onSubscription=function(t){this.members=t.presence.hash,this.count=t.presence.count,this.me=this.get(this.myID)},t.prototype.addMember=function(t){return null===this.get(t.user_id)&&this.count++,this.members[t.user_id]=t.user_info,this.get(t.user_id)},t.prototype.removeMember=function(t){var e=this.get(t.user_id);return e&&(delete this.members[t.user_id],this.count--),e},t.prototype.reset=function(){this.members={},this.count=0,this.myID=null,this.me=null},t}();e.default=o},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var i=n(9),s=n(7),a=n(3),u=n(35),c=n(37),h=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.key=null,e}return o(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,function(t,e){if(t)n(!0,e);else{var o=e.shared_secret;if(!o){var i="No shared_secret key in auth payload for encrypted channel: "+r.name;return n(!0,i),void a.default.warn("Error: "+i)}r.key=c.decodeBase64(o),delete e.shared_secret,n(!1,e)}})},e.prototype.trigger=function(t,e){throw new s.UnsupportedFeature("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e){var n=e.event,r=e.data;0!==n.indexOf("pusher_internal:")&&0!==n.indexOf("pusher:")?this.handleEncryptedEvent(n,r):t.prototype.handleEvent.call(this,e)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(this.key)if(e.ciphertext&&e.nonce){var r=c.decodeBase64(e.ciphertext);if(r.length>24&255,t[e+1]=n>>16&255,t[e+2]=n>>8&255,t[e+3]=255&n,t[e+4]=r>>24&255,t[e+5]=r>>16&255,t[e+6]=r>>8&255,t[e+7]=255&r}function y(t,e,n,r,o){var i,s=0;for(i=0;i>>8)-1}function v(t,e,n,r){return y(t,e,n,r,16)}function g(t,e,n,r){return y(t,e,n,r,32)}function b(t,e,n,r){!function(t,e,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,u=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,c=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,f=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,l=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,p=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,d=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,v=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,g=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,b=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,_=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,m=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=i,S=s,k=a,T=u,O=c,C=h,A=f,x=l,P=p,M=d,E=y,U=v,L=g,R=b,j=_,I=m,N=0;N<20;N+=2)w^=(o=(L^=(o=(P^=(o=(O^=(o=w+L|0)<<7|o>>>25)+w|0)<<9|o>>>23)+O|0)<<13|o>>>19)+P|0)<<18|o>>>14,C^=(o=(S^=(o=(R^=(o=(M^=(o=C+S|0)<<7|o>>>25)+C|0)<<9|o>>>23)+M|0)<<13|o>>>19)+R|0)<<18|o>>>14,E^=(o=(A^=(o=(k^=(o=(j^=(o=E+A|0)<<7|o>>>25)+E|0)<<9|o>>>23)+j|0)<<13|o>>>19)+k|0)<<18|o>>>14,I^=(o=(U^=(o=(x^=(o=(T^=(o=I+U|0)<<7|o>>>25)+I|0)<<9|o>>>23)+T|0)<<13|o>>>19)+x|0)<<18|o>>>14,w^=(o=(T^=(o=(k^=(o=(S^=(o=w+T|0)<<7|o>>>25)+w|0)<<9|o>>>23)+S|0)<<13|o>>>19)+k|0)<<18|o>>>14,C^=(o=(O^=(o=(x^=(o=(A^=(o=C+O|0)<<7|o>>>25)+C|0)<<9|o>>>23)+A|0)<<13|o>>>19)+x|0)<<18|o>>>14,E^=(o=(M^=(o=(P^=(o=(U^=(o=E+M|0)<<7|o>>>25)+E|0)<<9|o>>>23)+U|0)<<13|o>>>19)+P|0)<<18|o>>>14,I^=(o=(j^=(o=(R^=(o=(L^=(o=I+j|0)<<7|o>>>25)+I|0)<<9|o>>>23)+L|0)<<13|o>>>19)+R|0)<<18|o>>>14;w=w+i|0,S=S+s|0,k=k+a|0,T=T+u|0,O=O+c|0,C=C+h|0,A=A+f|0,x=x+l|0,P=P+p|0,M=M+d|0,E=E+y|0,U=U+v|0,L=L+g|0,R=R+b|0,j=j+_|0,I=I+m|0,t[0]=w>>>0&255,t[1]=w>>>8&255,t[2]=w>>>16&255,t[3]=w>>>24&255,t[4]=S>>>0&255,t[5]=S>>>8&255,t[6]=S>>>16&255,t[7]=S>>>24&255,t[8]=k>>>0&255,t[9]=k>>>8&255,t[10]=k>>>16&255,t[11]=k>>>24&255,t[12]=T>>>0&255,t[13]=T>>>8&255,t[14]=T>>>16&255,t[15]=T>>>24&255,t[16]=O>>>0&255,t[17]=O>>>8&255,t[18]=O>>>16&255,t[19]=O>>>24&255,t[20]=C>>>0&255,t[21]=C>>>8&255,t[22]=C>>>16&255,t[23]=C>>>24&255,t[24]=A>>>0&255,t[25]=A>>>8&255,t[26]=A>>>16&255,t[27]=A>>>24&255,t[28]=x>>>0&255,t[29]=x>>>8&255,t[30]=x>>>16&255,t[31]=x>>>24&255,t[32]=P>>>0&255,t[33]=P>>>8&255,t[34]=P>>>16&255,t[35]=P>>>24&255,t[36]=M>>>0&255,t[37]=M>>>8&255,t[38]=M>>>16&255,t[39]=M>>>24&255,t[40]=E>>>0&255,t[41]=E>>>8&255,t[42]=E>>>16&255,t[43]=E>>>24&255,t[44]=U>>>0&255,t[45]=U>>>8&255,t[46]=U>>>16&255,t[47]=U>>>24&255,t[48]=L>>>0&255,t[49]=L>>>8&255,t[50]=L>>>16&255,t[51]=L>>>24&255,t[52]=R>>>0&255,t[53]=R>>>8&255,t[54]=R>>>16&255,t[55]=R>>>24&255,t[56]=j>>>0&255,t[57]=j>>>8&255,t[58]=j>>>16&255,t[59]=j>>>24&255,t[60]=I>>>0&255,t[61]=I>>>8&255,t[62]=I>>>16&255,t[63]=I>>>24&255}(t,e,n,r)}function _(t,e,n,r){!function(t,e,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,u=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,c=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,f=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,l=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,p=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,d=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,v=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,g=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,b=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,_=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,m=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=0;w<20;w+=2)i^=(o=(g^=(o=(p^=(o=(c^=(o=i+g|0)<<7|o>>>25)+i|0)<<9|o>>>23)+c|0)<<13|o>>>19)+p|0)<<18|o>>>14,h^=(o=(s^=(o=(b^=(o=(d^=(o=h+s|0)<<7|o>>>25)+h|0)<<9|o>>>23)+d|0)<<13|o>>>19)+b|0)<<18|o>>>14,y^=(o=(f^=(o=(a^=(o=(_^=(o=y+f|0)<<7|o>>>25)+y|0)<<9|o>>>23)+_|0)<<13|o>>>19)+a|0)<<18|o>>>14,m^=(o=(v^=(o=(l^=(o=(u^=(o=m+v|0)<<7|o>>>25)+m|0)<<9|o>>>23)+u|0)<<13|o>>>19)+l|0)<<18|o>>>14,i^=(o=(u^=(o=(a^=(o=(s^=(o=i+u|0)<<7|o>>>25)+i|0)<<9|o>>>23)+s|0)<<13|o>>>19)+a|0)<<18|o>>>14,h^=(o=(c^=(o=(l^=(o=(f^=(o=h+c|0)<<7|o>>>25)+h|0)<<9|o>>>23)+f|0)<<13|o>>>19)+l|0)<<18|o>>>14,y^=(o=(d^=(o=(p^=(o=(v^=(o=y+d|0)<<7|o>>>25)+y|0)<<9|o>>>23)+v|0)<<13|o>>>19)+p|0)<<18|o>>>14,m^=(o=(_^=(o=(b^=(o=(g^=(o=m+_|0)<<7|o>>>25)+m|0)<<9|o>>>23)+g|0)<<13|o>>>19)+b|0)<<18|o>>>14;t[0]=i>>>0&255,t[1]=i>>>8&255,t[2]=i>>>16&255,t[3]=i>>>24&255,t[4]=h>>>0&255,t[5]=h>>>8&255,t[6]=h>>>16&255,t[7]=h>>>24&255,t[8]=y>>>0&255,t[9]=y>>>8&255,t[10]=y>>>16&255,t[11]=y>>>24&255,t[12]=m>>>0&255,t[13]=m>>>8&255,t[14]=m>>>16&255,t[15]=m>>>24&255,t[16]=f>>>0&255,t[17]=f>>>8&255,t[18]=f>>>16&255,t[19]=f>>>24&255,t[20]=l>>>0&255,t[21]=l>>>8&255,t[22]=l>>>16&255,t[23]=l>>>24&255,t[24]=p>>>0&255,t[25]=p>>>8&255,t[26]=p>>>16&255,t[27]=p>>>24&255,t[28]=d>>>0&255,t[29]=d>>>8&255,t[30]=d>>>16&255,t[31]=d>>>24&255}(t,e,n,r)}var m=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function w(t,e,n,r,o,i,s){var a,u,c=new Uint8Array(16),h=new Uint8Array(64);for(u=0;u<16;u++)c[u]=0;for(u=0;u<8;u++)c[u]=i[u];for(;o>=64;){for(b(h,c,s,m),u=0;u<64;u++)t[e+u]=n[r+u]^h[u];for(a=1,u=8;u<16;u++)a=a+(255&c[u])|0,c[u]=255&a,a>>>=8;o-=64,e+=64,r+=64}if(o>0)for(b(h,c,s,m),u=0;u=64;){for(b(u,a,o,m),s=0;s<64;s++)t[e+s]=u[s];for(i=1,s=8;s<16;s++)i=i+(255&a[s])|0,a[s]=255&i,i>>>=8;n-=64,e+=64}if(n>0)for(b(u,a,o,m),s=0;s>>13|n<<3),r=255&t[4]|(255&t[5])<<8,this.r[2]=7939&(n>>>10|r<<6),o=255&t[6]|(255&t[7])<<8,this.r[3]=8191&(r>>>7|o<<9),i=255&t[8]|(255&t[9])<<8,this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,s=255&t[10]|(255&t[11])<<8,this.r[6]=8191&(i>>>14|s<<2),a=255&t[12]|(255&t[13])<<8,this.r[7]=8065&(s>>>11|a<<5),u=255&t[14]|(255&t[15])<<8,this.r[8]=8191&(a>>>8|u<<8),this.r[9]=u>>>5&127,this.pad[0]=255&t[16]|(255&t[17])<<8,this.pad[1]=255&t[18]|(255&t[19])<<8,this.pad[2]=255&t[20]|(255&t[21])<<8,this.pad[3]=255&t[22]|(255&t[23])<<8,this.pad[4]=255&t[24]|(255&t[25])<<8,this.pad[5]=255&t[26]|(255&t[27])<<8,this.pad[6]=255&t[28]|(255&t[29])<<8,this.pad[7]=255&t[30]|(255&t[31])<<8};function C(t,e,n,r,o,i){var s=new O(i);return s.update(n,r,o),s.finish(t,e),0}function A(t,e,n,r,o,i){var s=new Uint8Array(16);return C(s,0,n,r,o,i),v(t,e,s,0)}function x(t,e,n,r,o){var i;if(n<32)return-1;for(T(t,0,e,0,n,r,o),C(t,16,t,32,n-32,t),i=0;i<16;i++)t[i]=0;return 0}function P(t,e,n,r,o){var i,s=new Uint8Array(32);if(n<32)return-1;if(k(s,0,32,r,o),0!==A(e,16,e,32,n-32,s))return-1;for(T(t,0,e,0,n,r,o),i=0;i<32;i++)t[i]=0;return 0}function M(t,e){var n;for(n=0;n<16;n++)t[n]=0|e[n]}function E(t){var e,n,r=1;for(e=0;e<16;e++)n=t[e]+r+65535,r=Math.floor(n/65536),t[e]=n-65536*r;t[0]+=r-1+37*(r-1)}function U(t,e,n){for(var r,o=~(n-1),i=0;i<16;i++)r=o&(t[i]^e[i]),t[i]^=r,e[i]^=r}function L(t,n){var r,o,i,s=e(),a=e();for(r=0;r<16;r++)a[r]=n[r];for(E(a),E(a),E(a),o=0;o<2;o++){for(s[0]=a[0]-65517,r=1;r<15;r++)s[r]=a[r]-65535-(s[r-1]>>16&1),s[r-1]&=65535;s[15]=a[15]-32767-(s[14]>>16&1),i=s[15]>>16&1,s[14]&=65535,U(a,s,1-i)}for(r=0;r<16;r++)t[2*r]=255&a[r],t[2*r+1]=a[r]>>8}function R(t,e){var n=new Uint8Array(32),r=new Uint8Array(32);return L(n,t),L(r,e),g(n,0,r,0)}function j(t){var e=new Uint8Array(32);return L(e,t),1&e[0]}function I(t,e){var n;for(n=0;n<16;n++)t[n]=e[2*n]+(e[2*n+1]<<8);t[15]&=32767}function N(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]+n[r]}function B(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]-n[r]}function z(t,e,n){var r,o,i=0,s=0,a=0,u=0,c=0,h=0,f=0,l=0,p=0,d=0,y=0,v=0,g=0,b=0,_=0,m=0,w=0,S=0,k=0,T=0,O=0,C=0,A=0,x=0,P=0,M=0,E=0,U=0,L=0,R=0,j=0,I=n[0],N=n[1],B=n[2],z=n[3],D=n[4],H=n[5],F=n[6],q=n[7],Y=n[8],J=n[9],K=n[10],X=n[11],G=n[12],W=n[13],Z=n[14],Q=n[15];i+=(r=e[0])*I,s+=r*N,a+=r*B,u+=r*z,c+=r*D,h+=r*H,f+=r*F,l+=r*q,p+=r*Y,d+=r*J,y+=r*K,v+=r*X,g+=r*G,b+=r*W,_+=r*Z,m+=r*Q,s+=(r=e[1])*I,a+=r*N,u+=r*B,c+=r*z,h+=r*D,f+=r*H,l+=r*F,p+=r*q,d+=r*Y,y+=r*J,v+=r*K,g+=r*X,b+=r*G,_+=r*W,m+=r*Z,w+=r*Q,a+=(r=e[2])*I,u+=r*N,c+=r*B,h+=r*z,f+=r*D,l+=r*H,p+=r*F,d+=r*q,y+=r*Y,v+=r*J,g+=r*K,b+=r*X,_+=r*G,m+=r*W,w+=r*Z,S+=r*Q,u+=(r=e[3])*I,c+=r*N,h+=r*B,f+=r*z,l+=r*D,p+=r*H,d+=r*F,y+=r*q,v+=r*Y,g+=r*J,b+=r*K,_+=r*X,m+=r*G,w+=r*W,S+=r*Z,k+=r*Q,c+=(r=e[4])*I,h+=r*N,f+=r*B,l+=r*z,p+=r*D,d+=r*H,y+=r*F,v+=r*q,g+=r*Y,b+=r*J,_+=r*K,m+=r*X,w+=r*G,S+=r*W,k+=r*Z,T+=r*Q,h+=(r=e[5])*I,f+=r*N,l+=r*B,p+=r*z,d+=r*D,y+=r*H,v+=r*F,g+=r*q,b+=r*Y,_+=r*J,m+=r*K,w+=r*X,S+=r*G,k+=r*W,T+=r*Z,O+=r*Q,f+=(r=e[6])*I,l+=r*N,p+=r*B,d+=r*z,y+=r*D,v+=r*H,g+=r*F,b+=r*q,_+=r*Y,m+=r*J,w+=r*K,S+=r*X,k+=r*G,T+=r*W,O+=r*Z,C+=r*Q,l+=(r=e[7])*I,p+=r*N,d+=r*B,y+=r*z,v+=r*D,g+=r*H,b+=r*F,_+=r*q,m+=r*Y,w+=r*J,S+=r*K,k+=r*X,T+=r*G,O+=r*W,C+=r*Z,A+=r*Q,p+=(r=e[8])*I,d+=r*N,y+=r*B,v+=r*z,g+=r*D,b+=r*H,_+=r*F,m+=r*q,w+=r*Y,S+=r*J,k+=r*K,T+=r*X,O+=r*G,C+=r*W,A+=r*Z,x+=r*Q,d+=(r=e[9])*I,y+=r*N,v+=r*B,g+=r*z,b+=r*D,_+=r*H,m+=r*F,w+=r*q,S+=r*Y,k+=r*J,T+=r*K,O+=r*X,C+=r*G,A+=r*W,x+=r*Z,P+=r*Q,y+=(r=e[10])*I,v+=r*N,g+=r*B,b+=r*z,_+=r*D,m+=r*H,w+=r*F,S+=r*q,k+=r*Y,T+=r*J,O+=r*K,C+=r*X,A+=r*G,x+=r*W,P+=r*Z,M+=r*Q,v+=(r=e[11])*I,g+=r*N,b+=r*B,_+=r*z,m+=r*D,w+=r*H,S+=r*F,k+=r*q,T+=r*Y,O+=r*J,C+=r*K,A+=r*X,x+=r*G,P+=r*W,M+=r*Z,E+=r*Q,g+=(r=e[12])*I,b+=r*N,_+=r*B,m+=r*z,w+=r*D,S+=r*H,k+=r*F,T+=r*q,O+=r*Y,C+=r*J,A+=r*K,x+=r*X,P+=r*G,M+=r*W,E+=r*Z,U+=r*Q,b+=(r=e[13])*I,_+=r*N,m+=r*B,w+=r*z,S+=r*D,k+=r*H,T+=r*F,O+=r*q,C+=r*Y,A+=r*J,x+=r*K,P+=r*X,M+=r*G,E+=r*W,U+=r*Z,L+=r*Q,_+=(r=e[14])*I,m+=r*N,w+=r*B,S+=r*z,k+=r*D,T+=r*H,O+=r*F,C+=r*q,A+=r*Y,x+=r*J,P+=r*K,M+=r*X,E+=r*G,U+=r*W,L+=r*Z,R+=r*Q,m+=(r=e[15])*I,s+=38*(S+=r*B),a+=38*(k+=r*z),u+=38*(T+=r*D),c+=38*(O+=r*H),h+=38*(C+=r*F),f+=38*(A+=r*q),l+=38*(x+=r*Y),p+=38*(P+=r*J),d+=38*(M+=r*K),y+=38*(E+=r*X),v+=38*(U+=r*G),g+=38*(L+=r*W),b+=38*(R+=r*Z),_+=38*(j+=r*Q),i=(r=(i+=38*(w+=r*N))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),_=(r=_+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),i=(r=(i+=o-1+37*(o-1))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),_=(r=_+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),i+=o-1+37*(o-1),t[0]=i,t[1]=s,t[2]=a,t[3]=u,t[4]=c,t[5]=h,t[6]=f,t[7]=l,t[8]=p,t[9]=d,t[10]=y,t[11]=v,t[12]=g,t[13]=b,t[14]=_,t[15]=m}function D(t,e){z(t,e,e)}function H(t,n){var r,o=e();for(r=0;r<16;r++)o[r]=n[r];for(r=253;r>=0;r--)D(o,o),2!==r&&4!==r&&z(o,o,n);for(r=0;r<16;r++)t[r]=o[r]}function F(t,n,r){var o,i,s=new Uint8Array(32),a=new Float64Array(80),c=e(),h=e(),f=e(),l=e(),p=e(),d=e();for(i=0;i<31;i++)s[i]=n[i];for(s[31]=127&n[31]|64,s[0]&=248,I(a,r),i=0;i<16;i++)h[i]=a[i],l[i]=c[i]=f[i]=0;for(c[0]=l[0]=1,i=254;i>=0;--i)U(c,h,o=s[i>>>3]>>>(7&i)&1),U(f,l,o),N(p,c,f),B(c,c,f),N(f,h,l),B(h,h,l),D(l,p),D(d,c),z(c,f,c),z(f,h,p),N(p,c,f),B(c,c,f),D(h,c),B(f,l,d),z(c,f,u),N(c,c,l),z(f,f,c),z(c,l,d),z(l,h,a),D(h,p),U(c,h,o),U(f,l,o);for(i=0;i<16;i++)a[i+16]=c[i],a[i+32]=f[i],a[i+48]=h[i],a[i+64]=l[i];var y=a.subarray(32),v=a.subarray(16);return H(y,y),z(v,v,y),L(t,v),0}function q(t,e){return F(t,e,i)}function Y(t,e){return r(e,32),q(t,e)}function J(t,e,n){var r=new Uint8Array(32);return F(r,n,e),_(t,o,r,m)}O.prototype.blocks=function(t,e,n){for(var r,o,i,s,a,u,c,h,f,l,p,d,y,v,g,b,_,m,w,S=this.fin?0:2048,k=this.h[0],T=this.h[1],O=this.h[2],C=this.h[3],A=this.h[4],x=this.h[5],P=this.h[6],M=this.h[7],E=this.h[8],U=this.h[9],L=this.r[0],R=this.r[1],j=this.r[2],I=this.r[3],N=this.r[4],B=this.r[5],z=this.r[6],D=this.r[7],H=this.r[8],F=this.r[9];n>=16;)l=f=0,l+=(k+=8191&(r=255&t[e+0]|(255&t[e+1])<<8))*L,l+=(T+=8191&(r>>>13|(o=255&t[e+2]|(255&t[e+3])<<8)<<3))*(5*F),l+=(O+=8191&(o>>>10|(i=255&t[e+4]|(255&t[e+5])<<8)<<6))*(5*H),l+=(C+=8191&(i>>>7|(s=255&t[e+6]|(255&t[e+7])<<8)<<9))*(5*D),f=(l+=(A+=8191&(s>>>4|(a=255&t[e+8]|(255&t[e+9])<<8)<<12))*(5*z))>>>13,l&=8191,l+=(x+=a>>>1&8191)*(5*B),l+=(P+=8191&(a>>>14|(u=255&t[e+10]|(255&t[e+11])<<8)<<2))*(5*N),l+=(M+=8191&(u>>>11|(c=255&t[e+12]|(255&t[e+13])<<8)<<5))*(5*I),l+=(E+=8191&(c>>>8|(h=255&t[e+14]|(255&t[e+15])<<8)<<8))*(5*j),p=f+=(l+=(U+=h>>>5|S)*(5*R))>>>13,p+=k*R,p+=T*L,p+=O*(5*F),p+=C*(5*H),f=(p+=A*(5*D))>>>13,p&=8191,p+=x*(5*z),p+=P*(5*B),p+=M*(5*N),p+=E*(5*I),f+=(p+=U*(5*j))>>>13,p&=8191,d=f,d+=k*j,d+=T*R,d+=O*L,d+=C*(5*F),f=(d+=A*(5*H))>>>13,d&=8191,d+=x*(5*D),d+=P*(5*z),d+=M*(5*B),d+=E*(5*N),y=f+=(d+=U*(5*I))>>>13,y+=k*I,y+=T*j,y+=O*R,y+=C*L,f=(y+=A*(5*F))>>>13,y&=8191,y+=x*(5*H),y+=P*(5*D),y+=M*(5*z),y+=E*(5*B),v=f+=(y+=U*(5*N))>>>13,v+=k*N,v+=T*I,v+=O*j,v+=C*R,f=(v+=A*L)>>>13,v&=8191,v+=x*(5*F),v+=P*(5*H),v+=M*(5*D),v+=E*(5*z),g=f+=(v+=U*(5*B))>>>13,g+=k*B,g+=T*N,g+=O*I,g+=C*j,f=(g+=A*R)>>>13,g&=8191,g+=x*L,g+=P*(5*F),g+=M*(5*H),g+=E*(5*D),b=f+=(g+=U*(5*z))>>>13,b+=k*z,b+=T*B,b+=O*N,b+=C*I,f=(b+=A*j)>>>13,b&=8191,b+=x*R,b+=P*L,b+=M*(5*F),b+=E*(5*H),_=f+=(b+=U*(5*D))>>>13,_+=k*D,_+=T*z,_+=O*B,_+=C*N,f=(_+=A*I)>>>13,_&=8191,_+=x*j,_+=P*R,_+=M*L,_+=E*(5*F),m=f+=(_+=U*(5*H))>>>13,m+=k*H,m+=T*D,m+=O*z,m+=C*B,f=(m+=A*N)>>>13,m&=8191,m+=x*I,m+=P*j,m+=M*R,m+=E*L,w=f+=(m+=U*(5*F))>>>13,w+=k*F,w+=T*H,w+=O*D,w+=C*z,f=(w+=A*B)>>>13,w&=8191,w+=x*N,w+=P*I,w+=M*j,w+=E*R,k=l=8191&(f=(f=((f+=(w+=U*L)>>>13)<<2)+f|0)+(l&=8191)|0),T=p+=f>>>=13,O=d&=8191,C=y&=8191,A=v&=8191,x=g&=8191,P=b&=8191,M=_&=8191,E=m&=8191,U=w&=8191,e+=16,n-=16;this.h[0]=k,this.h[1]=T,this.h[2]=O,this.h[3]=C,this.h[4]=A,this.h[5]=x,this.h[6]=P,this.h[7]=M,this.h[8]=E,this.h[9]=U},O.prototype.finish=function(t,e){var n,r,o,i,s=new Uint16Array(10);if(this.leftover){for(i=this.leftover,this.buffer[i++]=1;i<16;i++)this.buffer[i]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,i=2;i<10;i++)this.h[i]+=n,n=this.h[i]>>>13,this.h[i]&=8191;for(this.h[0]+=5*n,n=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=n,n=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=n,s[0]=this.h[0]+5,n=s[0]>>>13,s[0]&=8191,i=1;i<10;i++)s[i]=this.h[i]+n,n=s[i]>>>13,s[i]&=8191;for(s[9]-=8192,r=(1^n)-1,i=0;i<10;i++)s[i]&=r;for(r=~r,i=0;i<10;i++)this.h[i]=this.h[i]&r|s[i];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),o=this.h[0]+this.pad[0],this.h[0]=65535&o,i=1;i<8;i++)o=(this.h[i]+this.pad[i]|0)+(o>>>16)|0,this.h[i]=65535&o;t[e+0]=this.h[0]>>>0&255,t[e+1]=this.h[0]>>>8&255,t[e+2]=this.h[1]>>>0&255,t[e+3]=this.h[1]>>>8&255,t[e+4]=this.h[2]>>>0&255,t[e+5]=this.h[2]>>>8&255,t[e+6]=this.h[3]>>>0&255,t[e+7]=this.h[3]>>>8&255,t[e+8]=this.h[4]>>>0&255,t[e+9]=this.h[4]>>>8&255,t[e+10]=this.h[5]>>>0&255,t[e+11]=this.h[5]>>>8&255,t[e+12]=this.h[6]>>>0&255,t[e+13]=this.h[6]>>>8&255,t[e+14]=this.h[7]>>>0&255,t[e+15]=this.h[7]>>>8&255},O.prototype.update=function(t,e,n){var r,o;if(this.leftover){for((o=16-this.leftover)>n&&(o=n),r=0;r=16&&(o=n-n%16,this.blocks(t,e,o),e+=o,n-=o),n){for(r=0;r=128;){for(S=0;S<16;S++)k=8*S+W,M[S]=n[k+0]<<24|n[k+1]<<16|n[k+2]<<8|n[k+3],E[S]=n[k+4]<<24|n[k+5]<<16|n[k+6]<<8|n[k+7];for(S=0;S<80;S++)if(o=U,i=L,s=R,a=j,u=I,c=N,h=B,z,l=D,p=H,d=F,y=q,v=Y,g=J,b=K,X,C=65535&(O=X),A=O>>>16,x=65535&(T=z),P=T>>>16,C+=65535&(O=(Y>>>14|I<<18)^(Y>>>18|I<<14)^(I>>>9|Y<<23)),A+=O>>>16,x+=65535&(T=(I>>>14|Y<<18)^(I>>>18|Y<<14)^(Y>>>9|I<<23)),P+=T>>>16,C+=65535&(O=Y&J^~Y&K),A+=O>>>16,x+=65535&(T=I&N^~I&B),P+=T>>>16,T=G[2*S],C+=65535&(O=G[2*S+1]),A+=O>>>16,x+=65535&T,P+=T>>>16,T=M[S%16],A+=(O=E[S%16])>>>16,x+=65535&T,P+=T>>>16,x+=(A+=(C+=65535&O)>>>16)>>>16,C=65535&(O=w=65535&C|A<<16),A=O>>>16,x=65535&(T=m=65535&x|(P+=x>>>16)<<16),P=T>>>16,C+=65535&(O=(D>>>28|U<<4)^(U>>>2|D<<30)^(U>>>7|D<<25)),A+=O>>>16,x+=65535&(T=(U>>>28|D<<4)^(D>>>2|U<<30)^(D>>>7|U<<25)),P+=T>>>16,A+=(O=D&H^D&F^H&F)>>>16,x+=65535&(T=U&L^U&R^L&R),P+=T>>>16,f=65535&(x+=(A+=(C+=65535&O)>>>16)>>>16)|(P+=x>>>16)<<16,_=65535&C|A<<16,C=65535&(O=y),A=O>>>16,x=65535&(T=a),P=T>>>16,A+=(O=w)>>>16,x+=65535&(T=m),P+=T>>>16,L=o,R=i,j=s,I=a=65535&(x+=(A+=(C+=65535&O)>>>16)>>>16)|(P+=x>>>16)<<16,N=u,B=c,z=h,U=f,H=l,F=p,q=d,Y=y=65535&C|A<<16,J=v,K=g,X=b,D=_,S%16==15)for(k=0;k<16;k++)T=M[k],C=65535&(O=E[k]),A=O>>>16,x=65535&T,P=T>>>16,T=M[(k+9)%16],C+=65535&(O=E[(k+9)%16]),A+=O>>>16,x+=65535&T,P+=T>>>16,m=M[(k+1)%16],C+=65535&(O=((w=E[(k+1)%16])>>>1|m<<31)^(w>>>8|m<<24)^(w>>>7|m<<25)),A+=O>>>16,x+=65535&(T=(m>>>1|w<<31)^(m>>>8|w<<24)^m>>>7),P+=T>>>16,m=M[(k+14)%16],A+=(O=((w=E[(k+14)%16])>>>19|m<<13)^(m>>>29|w<<3)^(w>>>6|m<<26))>>>16,x+=65535&(T=(m>>>19|w<<13)^(w>>>29|m<<3)^m>>>6),P+=T>>>16,P+=(x+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,M[k]=65535&x|P<<16,E[k]=65535&C|A<<16;C=65535&(O=D),A=O>>>16,x=65535&(T=U),P=T>>>16,T=t[0],A+=(O=e[0])>>>16,x+=65535&T,P+=T>>>16,P+=(x+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[0]=U=65535&x|P<<16,e[0]=D=65535&C|A<<16,C=65535&(O=H),A=O>>>16,x=65535&(T=L),P=T>>>16,T=t[1],A+=(O=e[1])>>>16,x+=65535&T,P+=T>>>16,P+=(x+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[1]=L=65535&x|P<<16,e[1]=H=65535&C|A<<16,C=65535&(O=F),A=O>>>16,x=65535&(T=R),P=T>>>16,T=t[2],A+=(O=e[2])>>>16,x+=65535&T,P+=T>>>16,P+=(x+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[2]=R=65535&x|P<<16,e[2]=F=65535&C|A<<16,C=65535&(O=q),A=O>>>16,x=65535&(T=j),P=T>>>16,T=t[3],A+=(O=e[3])>>>16,x+=65535&T,P+=T>>>16,P+=(x+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[3]=j=65535&x|P<<16,e[3]=q=65535&C|A<<16,C=65535&(O=Y),A=O>>>16,x=65535&(T=I),P=T>>>16,T=t[4],A+=(O=e[4])>>>16,x+=65535&T,P+=T>>>16,P+=(x+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[4]=I=65535&x|P<<16,e[4]=Y=65535&C|A<<16,C=65535&(O=J),A=O>>>16,x=65535&(T=N),P=T>>>16,T=t[5],A+=(O=e[5])>>>16,x+=65535&T,P+=T>>>16,P+=(x+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[5]=N=65535&x|P<<16,e[5]=J=65535&C|A<<16,C=65535&(O=K),A=O>>>16,x=65535&(T=B),P=T>>>16,T=t[6],A+=(O=e[6])>>>16,x+=65535&T,P+=T>>>16,P+=(x+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[6]=B=65535&x|P<<16,e[6]=K=65535&C|A<<16,C=65535&(O=X),A=O>>>16,x=65535&(T=z),P=T>>>16,T=t[7],A+=(O=e[7])>>>16,x+=65535&T,P+=T>>>16,P+=(x+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[7]=z=65535&x|P<<16,e[7]=X=65535&C|A<<16,W+=128,r-=128}return r}function Z(t,e,n){var r,o=new Int32Array(8),i=new Int32Array(8),s=new Uint8Array(256),a=n;for(o[0]=1779033703,o[1]=3144134277,o[2]=1013904242,o[3]=2773480762,o[4]=1359893119,o[5]=2600822924,o[6]=528734635,o[7]=1541459225,i[0]=4089235720,i[1]=2227873595,i[2]=4271175723,i[3]=1595750129,i[4]=2917565137,i[5]=725511199,i[6]=4215389547,i[7]=327033209,W(o,i,e,n),n%=128,r=0;r=0;--o)V(t,e,r=n[o/8|0]>>(7&o)&1),Q(e,t),Q(t,t),V(t,e,r)}function et(t,n){var r=[e(),e(),e(),e()];M(r[0],f),M(r[1],l),M(r[2],a),z(r[3],f,l),tt(t,r,n)}function nt(t,n,o){var i,s=new Uint8Array(64),a=[e(),e(),e(),e()];for(o||r(n,32),Z(s,n,32),s[0]&=248,s[31]&=127,s[31]|=64,et(a,s),$(t,a),i=0;i<32;i++)n[i+32]=t[i];return 0}var rt=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function ot(t,e){var n,r,o,i;for(r=63;r>=32;--r){for(n=0,o=r-32,i=r-12;o>8,e[o]-=256*n;e[o]+=n,e[r]=0}for(n=0,o=0;o<32;o++)e[o]+=n-(e[31]>>4)*rt[o],n=e[o]>>8,e[o]&=255;for(o=0;o<32;o++)e[o]-=n*rt[o];for(r=0;r<32;r++)e[r+1]+=e[r]>>8,t[r]=255&e[r]}function it(t){var e,n=new Float64Array(64);for(e=0;e<64;e++)n[e]=t[e];for(e=0;e<64;e++)t[e]=0;ot(t,n)}function st(t,n,r,o){var i,s,a=new Uint8Array(64),u=new Uint8Array(64),c=new Uint8Array(64),h=new Float64Array(64),f=[e(),e(),e(),e()];Z(a,o,32),a[0]&=248,a[31]&=127,a[31]|=64;var l=r+64;for(i=0;i=0;r--)D(o,o),1!==r&&z(o,o,n);for(r=0;r<16;r++)t[r]=o[r]}(r,r),z(r,r,i),z(r,r,u),z(r,r,u),z(t[0],r,u),D(o,t[0]),z(o,o,u),R(o,i)&&z(t[0],t[0],p),D(o,t[0]),z(o,o,u),R(o,i)?-1:(j(t[0])===n[31]>>7&&B(t[0],s,t[0]),z(t[3],t[0],t[1]),0)}function ut(t,n,r,o){var i,s=new Uint8Array(32),a=new Uint8Array(64),u=[e(),e(),e(),e()],c=[e(),e(),e(),e()];if(-1,r<64)return-1;if(at(c,o))return-1;for(i=0;i=0},t.sign.keyPair=function(){var t=new Uint8Array(32),e=new Uint8Array(64);return nt(t,e),{publicKey:t,secretKey:e}},t.sign.keyPair.fromSecretKey=function(t){if(yt(t),64!==t.length)throw new Error("bad secret key size");for(var e=new Uint8Array(32),n=0;n0&&this.emit("connecting_in",Math.round(t/1e3)),this.retryTimer=new s.OneOffTimer(t||0,function(){e.disconnectInternally(),e.connect()})},e.prototype.clearRetryTimer=function(){this.retryTimer&&(this.retryTimer.ensureAborted(),this.retryTimer=null)},e.prototype.setUnavailableTimer=function(){var t=this;this.unavailableTimer=new s.OneOffTimer(this.options.unavailableTimeout,function(){t.updateState("unavailable")})},e.prototype.clearUnavailableTimer=function(){this.unavailableTimer&&this.unavailableTimer.ensureAborted()},e.prototype.sendActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection.ping(),this.activityTimer=new s.OneOffTimer(this.options.pongTimeout,function(){t.timeline.error({pong_timed_out:t.options.pongTimeout}),t.retryIn(0)})},e.prototype.resetActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection&&!this.connection.handlesActivityChecks()&&(this.activityTimer=new s.OneOffTimer(this.activityTimeout,function(){t.sendActivityCheck()}))},e.prototype.stopActivityCheck=function(){this.activityTimer&&this.activityTimer.ensureAborted()},e.prototype.buildConnectionCallbacks=function(t){var e=this;return u.extend({},t,{message:function(t){e.resetActivityCheck(),e.emit("message",t)},ping:function(){e.send_event("pusher:pong",{})},activity:function(){e.resetActivityCheck()},error:function(t){e.emit("error",{type:"WebSocketError",error:t})},closed:function(){e.abandonConnection(),e.shouldRetry()&&e.retryIn(1e3)}})},e.prototype.buildHandshakeCallbacks=function(t){var e=this;return u.extend({},t,{connected:function(t){e.activityTimeout=Math.min(e.options.activityTimeout,t.activityTimeout,t.connection.activityTimeout||1/0),e.clearUnavailableTimer(),e.setConnection(t.connection),e.socket_id=e.connection.id,e.updateState("connected",{socket_id:e.socket_id})}})},e.prototype.buildErrorCallbacks=function(){var t=this,e=function(e){return function(n){n.error&&t.emit("error",{type:"WebSocketError",error:n.error}),e(n)}};return{tls_only:e(function(){t.usingTLS=!0,t.updateStrategy(),t.retryIn(0)}),refused:e(function(){t.disconnect()}),backoff:e(function(){t.retryIn(1e3)}),retry:e(function(){t.retryIn(0)})}},e.prototype.setConnection=function(t){for(var e in this.connection=t,this.connectionCallbacks)this.connection.bind(e,this.connectionCallbacks[e]);this.resetActivityCheck()},e.prototype.abandonConnection=function(){if(this.connection){for(var t in this.stopActivityCheck(),this.connectionCallbacks)this.connection.unbind(t,this.connectionCallbacks[t]);var e=this.connection;return this.connection=null,e}},e.prototype.updateState=function(t,e){var n=this.state;if(this.state=t,n!==t){var r=t;"connected"===r&&(r+=" with new socket ID "+e.socket_id),a.default.debug("State changed",n+" -> "+r),this.timeline.info({state:t,params:e}),this.emit("state_change",{previous:n,current:t}),this.emit(t,e)}},e.prototype.shouldRetry=function(){return"connecting"===this.state||"connected"===this.state},e}(i.default);e.default=h},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(6),i=(n(7),function(){function t(){this.channels={}}return t.prototype.add=function(t,e){return this.channels[t]||(this.channels[t]=function(t,e){return 0===t.indexOf("private-encrypted-")?o.default.createEncryptedChannel(t,e):0===t.indexOf("private-")?o.default.createPrivateChannel(t,e):0===t.indexOf("presence-")?o.default.createPresenceChannel(t,e):o.default.createChannel(t,e)}(t,e)),this.channels[t]},t.prototype.all=function(){return r.values(this.channels)},t.prototype.find=function(t){return this.channels[t]},t.prototype.remove=function(t){var e=this.channels[t];return delete this.channels[t],e},t.prototype.disconnect=function(){r.objectApply(this.channels,function(t){t.disconnect()})},t}());e.default=i},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(2),i=function(){function t(t){this.strategies=t}return t.prototype.isSupported=function(){return r.any(this.strategies,o.default.method("isSupported"))},t.prototype.connect=function(t,e){return function(t,e,n){var o=r.map(t,function(t,r,o,i){return t.connect(e,n(r,i))});return{abort:function(){r.apply(o,s)},forceMinPriority:function(t){r.apply(o,function(e){e.forceMinPriority(t)})}}}(this.strategies,t,function(t,n){return function(o,i){n[t].error=o,o?function(t){return r.all(t,function(t){return Boolean(t.error)})}(n)&&e(!0):(r.apply(n,function(t){t.forceMinPriority(i.transport.priority)}),e(null,i))}})},t}();function s(t){t.error||t.aborted||(t.abort(),t.aborted=!0)}e.default=i},function(t,e,n){"use strict";e.__esModule=!0;var r=n(2),o=n(1),i=n(14),s=n(0),a=function(){function t(t,e,n){this.strategy=t,this.transports=e,this.ttl=n.ttl||18e5,this.usingTLS=n.useTLS,this.timeline=n.timeline}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.usingTLS,a=function(t){var e=o.default.getLocalStorage();if(e)try{var n=e[u(t)];if(n)return JSON.parse(n)}catch(e){c(t)}return null}(n),h=[this.strategy];if(a&&a.timestamp+this.ttl>=r.default.now()){var f=this.transports[a.transport];f&&(this.timeline.info({cached:!0,transport:a.transport,latency:a.latency}),h.push(new i.default([f],{timeout:2*a.latency+1e3,failFast:!0})))}var l=r.default.now(),p=h.pop().connect(t,function i(a,f){a?(c(n),h.length>0?(l=r.default.now(),p=h.pop().connect(t,i)):e(a)):(!function(t,e,n){var i=o.default.getLocalStorage();if(i)try{i[u(t)]=s.safeJSONStringify({timestamp:r.default.now(),transport:e,latency:n})}catch(t){}}(n,f.transport.name,r.default.now()-l),e(null,f))});return{abort:function(){p.abort()},forceMinPriority:function(e){t=e,p&&p.forceMinPriority(e)}}},t}();function u(t){return"pusherTransport"+(t?"TLS":"NonTLS")}function c(t){var e=o.default.getLocalStorage();if(e)try{delete e[u(t)]}catch(t){}}e.default=a},function(t,e,n){"use strict";e.__esModule=!0;var r=n(5),o=function(){function t(t,e){var n=e.delay;this.strategy=t,this.options={delay:n}}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n,o=this.strategy,i=new r.OneOffTimer(this.options.delay,function(){n=o.connect(t,e)});return{abort:function(){i.ensureAborted(),n&&n.abort()},forceMinPriority:function(e){t=e,n&&n.forceMinPriority(e)}}},t}();e.default=o},function(t,e,n){"use strict";e.__esModule=!0;var r=function(){function t(t,e,n){this.test=t,this.trueBranch=e,this.falseBranch=n}return t.prototype.isSupported=function(){return(this.test()?this.trueBranch:this.falseBranch).isSupported()},t.prototype.connect=function(t,e){return(this.test()?this.trueBranch:this.falseBranch).connect(t,e)},t}();e.default=r},function(t,e,n){"use strict";e.__esModule=!0;var r=function(){function t(t){this.strategy=t}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.strategy.connect(t,function(t,r){r&&n.abort(),e(t,r)});return n},t}();e.default=r},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(){this.timeline.info(this.buildTimelineMessage({transport:this.name+(this.options.useTLS?"s":"")})),this.hooks.isInitialized()?this.changeState("initialized"):this.onClose()}},function(t,e,n){"use strict";e.__esModule=!0;var r=n(47),o=n(48),i=n(50),s=n(51),a=n(52),u={createStreamingSocket:function(t){return this.createSocket(i.default,t)},createPollingSocket:function(t){return this.createSocket(s.default,t)},createSocket:function(t,e){return new o.default(t,e)},createXHR:function(t,e){return this.createRequest(a.default,t,e)},createRequest:function(t,e,n){return new r.default(t,e,n)}};e.default=u},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var i=n(1),s=n(4),a=function(t){function e(e,n,r){var o=t.call(this)||this;return o.hooks=e,o.method=n,o.url=r,o}return o(e,t),e.prototype.start=function(t){var e=this;this.position=0,this.xhr=this.hooks.getRequest(this),this.unloader=function(){e.close()},i.default.addUnloadListener(this.unloader),this.xhr.open(this.method,this.url,!0),this.xhr.setRequestHeader&&this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.send(t)},e.prototype.close=function(){this.unloader&&(i.default.removeUnloadListener(this.unloader),this.unloader=null),this.xhr&&(this.hooks.abortRequest(this.xhr),this.xhr=null)},e.prototype.onChunk=function(t,e){for(;;){var n=this.advanceBuffer(e);if(!n)break;this.emit("chunk",{status:t,data:n})}this.isBufferTooLong(e)&&this.emit("buffer_too_long")},e.prototype.advanceBuffer=function(t){var e=t.slice(this.position),n=e.indexOf("\n");return-1!==n?(this.position+=n+1,e.slice(0,n)):null},e.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>262144},e}(s.default);e.default=a},function(t,e,n){"use strict";e.__esModule=!0;var r=n(49),o=n(2),i=n(1),s=1,a=function(){function t(t,e){this.hooks=t,this.session=c(1e3)+"/"+function(t){for(var e=[],n=0;n0&&t.onChunk(e.status,e.responseText);break;case 4:e.responseText&&e.responseText.length>0&&t.onChunk(e.status,e.responseText),t.emit("finished",e.status),t.close()}},e},abortRequest:function(t){t.onreadystatechange=null,t.abort()}};e.default=o},function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});e.__esModule=!0;var i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype.isOnline=function(){return!0},e}(n(4).default);e.NetInfo=i,e.Network=new i},function(t,e,n){"use strict";e.__esModule=!0;var r=n(3);e.default=function(t,e,n){var o=new Headers;for(var i in o.set("Content-Type","application/x-www-form-urlencoded"),this.authOptions.headers)o.set(i,this.authOptions.headers[i]);var s=this.composeQuery(e),a=new Request(this.options.authEndpoint,{headers:o,body:s,credentials:"same-origin",method:"POST"});return fetch(a).then(function(t){var e=t.status;if(200===e)return t.text();throw r.default.warn("Couldn't get auth info from your webapp",e),e}).then(function(t){try{t=JSON.parse(t)}catch(n){var e="JSON returned from webapp was invalid, yet status code was 200. Data was: "+t;throw r.default.warn(e),e}n(!1,t)}).catch(function(t){n(!0,t)})}},function(t,e,n){"use strict";e.__esModule=!0;var r=n(3),o=n(0),i={name:"xhr",getAgent:function(t,e){return function(n,i){var s="http"+(e?"s":"")+"://"+(t.host||t.options.host)+t.options.path,a=o.buildQueryString(n);fetch(s+="/2?"+a).then(function(t){if(200!==t.status)throw"received "+t.status+" from stats.pusher.com";return t.json()}).then(function(e){var n=e.host;n&&(t.host=n)}).catch(function(t){r.default.debug("TimelineSender Error: ",t)})}}};e.default=i},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(2),i=n(15),s=function(){function t(t,e,n){this.key=t,this.session=e,this.events=[],this.options=n||{},this.sent=0,this.uniqueID=0}return t.prototype.log=function(t,e){t<=this.options.level&&(this.events.push(r.extend({},e,{timestamp:o.default.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(i.default.ERROR,t)},t.prototype.info=function(t){this.log(i.default.INFO,t)},t.prototype.debug=function(t){this.log(i.default.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,o=r.extend({session:this.session,bundle:this.sent+1,key:this.key,lib:"js",version:this.options.version,cluster:this.options.cluster,features:this.options.features,timeline:this.events},this.options.params);return this.events=[],t(o,function(t,r){t||n.sent++,e&&e(t,r)}),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}();e.default=s},function(t,e,n){"use strict";e.__esModule=!0;var r=n(0),o=n(2),i=n(7),s=n(58),a=n(1).default.Transports;e.defineTransport=function(t,e,n,o,c,h){var f=a[n];if(!f)throw new i.UnsupportedTransport(n);return!(t.enabledTransports&&-1===r.arrayIndexOf(t.enabledTransports,e)||t.disabledTransports&&-1!==r.arrayIndexOf(t.disabledTransports,e))?new s.default(e,o,h?h.getAssistant(f):f,r.extend({key:t.key,useTLS:t.useTLS,timeline:t.timeline,ignoreNullOrigin:t.ignoreNullOrigin},c)):u};var u={isSupported:function(){return!1},connect:function(t,e){var n=o.default.defer(function(){e(new i.UnsupportedStrategy)});return{abort:function(){n.ensureAborted()},forceMinPriority:function(){}}}}},function(t,e,n){"use strict";e.__esModule=!0;var r=n(6),o=n(2),i=n(7),s=n(0),a=function(){function t(t,e,n,r){this.name=t,this.priority=e,this.transport=n,this.options=r||{}}return t.prototype.isSupported=function(){return this.transport.isSupported({useTLS:this.options.useTLS})},t.prototype.connect=function(t,e){var n=this;if(!this.isSupported())return u(new i.UnsupportedStrategy,e);if(this.priority>24&255,t[n+1]=e>>16&255,t[n+2]=e>>8&255,t[n+3]=255&e,t[n+4]=r>>24&255,t[n+5]=r>>16&255,t[n+6]=r>>8&255,t[n+7]=255&r}function y(t,n,e,r,o){var i,s=0;for(i=0;i>>8)-1}function b(t,n,e,r){return y(t,n,e,r,16)}function v(t,n,e,r){return y(t,n,e,r,32)}function g(t,n,e,r){!function(t,n,e,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,c=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,a=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,u=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,f=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,p=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,l=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,d=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,b=255&e[16]|(255&e[17])<<8|(255&e[18])<<16|(255&e[19])<<24,v=255&e[20]|(255&e[21])<<8|(255&e[22])<<16|(255&e[23])<<24,g=255&e[24]|(255&e[25])<<8|(255&e[26])<<16|(255&e[27])<<24,m=255&e[28]|(255&e[29])<<8|(255&e[30])<<16|(255&e[31])<<24,_=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=i,S=s,k=c,T=a,O=u,C=h,A=f,P=p,E=l,x=d,U=y,L=b,M=v,R=g,j=m,I=_,N=0;N<20;N+=2)w^=(o=(M^=(o=(E^=(o=(O^=(o=w+M|0)<<7|o>>>25)+w|0)<<9|o>>>23)+O|0)<<13|o>>>19)+E|0)<<18|o>>>14,C^=(o=(S^=(o=(R^=(o=(x^=(o=C+S|0)<<7|o>>>25)+C|0)<<9|o>>>23)+x|0)<<13|o>>>19)+R|0)<<18|o>>>14,U^=(o=(A^=(o=(k^=(o=(j^=(o=U+A|0)<<7|o>>>25)+U|0)<<9|o>>>23)+j|0)<<13|o>>>19)+k|0)<<18|o>>>14,I^=(o=(L^=(o=(P^=(o=(T^=(o=I+L|0)<<7|o>>>25)+I|0)<<9|o>>>23)+T|0)<<13|o>>>19)+P|0)<<18|o>>>14,w^=(o=(T^=(o=(k^=(o=(S^=(o=w+T|0)<<7|o>>>25)+w|0)<<9|o>>>23)+S|0)<<13|o>>>19)+k|0)<<18|o>>>14,C^=(o=(O^=(o=(P^=(o=(A^=(o=C+O|0)<<7|o>>>25)+C|0)<<9|o>>>23)+A|0)<<13|o>>>19)+P|0)<<18|o>>>14,U^=(o=(x^=(o=(E^=(o=(L^=(o=U+x|0)<<7|o>>>25)+U|0)<<9|o>>>23)+L|0)<<13|o>>>19)+E|0)<<18|o>>>14,I^=(o=(j^=(o=(R^=(o=(M^=(o=I+j|0)<<7|o>>>25)+I|0)<<9|o>>>23)+M|0)<<13|o>>>19)+R|0)<<18|o>>>14;w=w+i|0,S=S+s|0,k=k+c|0,T=T+a|0,O=O+u|0,C=C+h|0,A=A+f|0,P=P+p|0,E=E+l|0,x=x+d|0,U=U+y|0,L=L+b|0,M=M+v|0,R=R+g|0,j=j+m|0,I=I+_|0,t[0]=w>>>0&255,t[1]=w>>>8&255,t[2]=w>>>16&255,t[3]=w>>>24&255,t[4]=S>>>0&255,t[5]=S>>>8&255,t[6]=S>>>16&255,t[7]=S>>>24&255,t[8]=k>>>0&255,t[9]=k>>>8&255,t[10]=k>>>16&255,t[11]=k>>>24&255,t[12]=T>>>0&255,t[13]=T>>>8&255,t[14]=T>>>16&255,t[15]=T>>>24&255,t[16]=O>>>0&255,t[17]=O>>>8&255,t[18]=O>>>16&255,t[19]=O>>>24&255,t[20]=C>>>0&255,t[21]=C>>>8&255,t[22]=C>>>16&255,t[23]=C>>>24&255,t[24]=A>>>0&255,t[25]=A>>>8&255,t[26]=A>>>16&255,t[27]=A>>>24&255,t[28]=P>>>0&255,t[29]=P>>>8&255,t[30]=P>>>16&255,t[31]=P>>>24&255,t[32]=E>>>0&255,t[33]=E>>>8&255,t[34]=E>>>16&255,t[35]=E>>>24&255,t[36]=x>>>0&255,t[37]=x>>>8&255,t[38]=x>>>16&255,t[39]=x>>>24&255,t[40]=U>>>0&255,t[41]=U>>>8&255,t[42]=U>>>16&255,t[43]=U>>>24&255,t[44]=L>>>0&255,t[45]=L>>>8&255,t[46]=L>>>16&255,t[47]=L>>>24&255,t[48]=M>>>0&255,t[49]=M>>>8&255,t[50]=M>>>16&255,t[51]=M>>>24&255,t[52]=R>>>0&255,t[53]=R>>>8&255,t[54]=R>>>16&255,t[55]=R>>>24&255,t[56]=j>>>0&255,t[57]=j>>>8&255,t[58]=j>>>16&255,t[59]=j>>>24&255,t[60]=I>>>0&255,t[61]=I>>>8&255,t[62]=I>>>16&255,t[63]=I>>>24&255}(t,n,e,r)}function m(t,n,e,r){!function(t,n,e,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,c=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,a=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,u=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,f=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,p=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,l=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,d=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,b=255&e[16]|(255&e[17])<<8|(255&e[18])<<16|(255&e[19])<<24,v=255&e[20]|(255&e[21])<<8|(255&e[22])<<16|(255&e[23])<<24,g=255&e[24]|(255&e[25])<<8|(255&e[26])<<16|(255&e[27])<<24,m=255&e[28]|(255&e[29])<<8|(255&e[30])<<16|(255&e[31])<<24,_=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=0;w<20;w+=2)i^=(o=(v^=(o=(l^=(o=(u^=(o=i+v|0)<<7|o>>>25)+i|0)<<9|o>>>23)+u|0)<<13|o>>>19)+l|0)<<18|o>>>14,h^=(o=(s^=(o=(g^=(o=(d^=(o=h+s|0)<<7|o>>>25)+h|0)<<9|o>>>23)+d|0)<<13|o>>>19)+g|0)<<18|o>>>14,y^=(o=(f^=(o=(c^=(o=(m^=(o=y+f|0)<<7|o>>>25)+y|0)<<9|o>>>23)+m|0)<<13|o>>>19)+c|0)<<18|o>>>14,_^=(o=(b^=(o=(p^=(o=(a^=(o=_+b|0)<<7|o>>>25)+_|0)<<9|o>>>23)+a|0)<<13|o>>>19)+p|0)<<18|o>>>14,i^=(o=(a^=(o=(c^=(o=(s^=(o=i+a|0)<<7|o>>>25)+i|0)<<9|o>>>23)+s|0)<<13|o>>>19)+c|0)<<18|o>>>14,h^=(o=(u^=(o=(p^=(o=(f^=(o=h+u|0)<<7|o>>>25)+h|0)<<9|o>>>23)+f|0)<<13|o>>>19)+p|0)<<18|o>>>14,y^=(o=(d^=(o=(l^=(o=(b^=(o=y+d|0)<<7|o>>>25)+y|0)<<9|o>>>23)+b|0)<<13|o>>>19)+l|0)<<18|o>>>14,_^=(o=(m^=(o=(g^=(o=(v^=(o=_+m|0)<<7|o>>>25)+_|0)<<9|o>>>23)+v|0)<<13|o>>>19)+g|0)<<18|o>>>14;t[0]=i>>>0&255,t[1]=i>>>8&255,t[2]=i>>>16&255,t[3]=i>>>24&255,t[4]=h>>>0&255,t[5]=h>>>8&255,t[6]=h>>>16&255,t[7]=h>>>24&255,t[8]=y>>>0&255,t[9]=y>>>8&255,t[10]=y>>>16&255,t[11]=y>>>24&255,t[12]=_>>>0&255,t[13]=_>>>8&255,t[14]=_>>>16&255,t[15]=_>>>24&255,t[16]=f>>>0&255,t[17]=f>>>8&255,t[18]=f>>>16&255,t[19]=f>>>24&255,t[20]=p>>>0&255,t[21]=p>>>8&255,t[22]=p>>>16&255,t[23]=p>>>24&255,t[24]=l>>>0&255,t[25]=l>>>8&255,t[26]=l>>>16&255,t[27]=l>>>24&255,t[28]=d>>>0&255,t[29]=d>>>8&255,t[30]=d>>>16&255,t[31]=d>>>24&255}(t,n,e,r)}var _=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function w(t,n,e,r,o,i,s){var c,a,u=new Uint8Array(16),h=new Uint8Array(64);for(a=0;a<16;a++)u[a]=0;for(a=0;a<8;a++)u[a]=i[a];for(;o>=64;){for(g(h,u,s,_),a=0;a<64;a++)t[n+a]=e[r+a]^h[a];for(c=1,a=8;a<16;a++)c=c+(255&u[a])|0,u[a]=255&c,c>>>=8;o-=64,n+=64,r+=64}if(o>0)for(g(h,u,s,_),a=0;a=64;){for(g(a,c,o,_),s=0;s<64;s++)t[n+s]=a[s];for(i=1,s=8;s<16;s++)i=i+(255&c[s])|0,c[s]=255&i,i>>>=8;e-=64,n+=64}if(e>0)for(g(a,c,o,_),s=0;s>>13|e<<3),r=255&t[4]|(255&t[5])<<8,this.r[2]=7939&(e>>>10|r<<6),o=255&t[6]|(255&t[7])<<8,this.r[3]=8191&(r>>>7|o<<9),i=255&t[8]|(255&t[9])<<8,this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,s=255&t[10]|(255&t[11])<<8,this.r[6]=8191&(i>>>14|s<<2),c=255&t[12]|(255&t[13])<<8,this.r[7]=8065&(s>>>11|c<<5),a=255&t[14]|(255&t[15])<<8,this.r[8]=8191&(c>>>8|a<<8),this.r[9]=a>>>5&127,this.pad[0]=255&t[16]|(255&t[17])<<8,this.pad[1]=255&t[18]|(255&t[19])<<8,this.pad[2]=255&t[20]|(255&t[21])<<8,this.pad[3]=255&t[22]|(255&t[23])<<8,this.pad[4]=255&t[24]|(255&t[25])<<8,this.pad[5]=255&t[26]|(255&t[27])<<8,this.pad[6]=255&t[28]|(255&t[29])<<8,this.pad[7]=255&t[30]|(255&t[31])<<8};function C(t,n,e,r,o,i){var s=new O(i);return s.update(e,r,o),s.finish(t,n),0}function A(t,n,e,r,o,i){var s=new Uint8Array(16);return C(s,0,e,r,o,i),b(t,n,s,0)}function P(t,n,e,r,o){var i;if(e<32)return-1;for(T(t,0,n,0,e,r,o),C(t,16,t,32,e-32,t),i=0;i<16;i++)t[i]=0;return 0}function E(t,n,e,r,o){var i,s=new Uint8Array(32);if(e<32)return-1;if(k(s,0,32,r,o),0!==A(n,16,n,32,e-32,s))return-1;for(T(t,0,n,0,e,r,o),i=0;i<32;i++)t[i]=0;return 0}function x(t,n){var e;for(e=0;e<16;e++)t[e]=0|n[e]}function U(t){var n,e,r=1;for(n=0;n<16;n++)e=t[n]+r+65535,r=Math.floor(e/65536),t[n]=e-65536*r;t[0]+=r-1+37*(r-1)}function L(t,n,e){for(var r,o=~(e-1),i=0;i<16;i++)r=o&(t[i]^n[i]),t[i]^=r,n[i]^=r}function M(t,e){var r,o,i,s=n(),c=n();for(r=0;r<16;r++)c[r]=e[r];for(U(c),U(c),U(c),o=0;o<2;o++){for(s[0]=c[0]-65517,r=1;r<15;r++)s[r]=c[r]-65535-(s[r-1]>>16&1),s[r-1]&=65535;s[15]=c[15]-32767-(s[14]>>16&1),i=s[15]>>16&1,s[14]&=65535,L(c,s,1-i)}for(r=0;r<16;r++)t[2*r]=255&c[r],t[2*r+1]=c[r]>>8}function R(t,n){var e=new Uint8Array(32),r=new Uint8Array(32);return M(e,t),M(r,n),v(e,0,r,0)}function j(t){var n=new Uint8Array(32);return M(n,t),1&n[0]}function I(t,n){var e;for(e=0;e<16;e++)t[e]=n[2*e]+(n[2*e+1]<<8);t[15]&=32767}function N(t,n,e){for(var r=0;r<16;r++)t[r]=n[r]+e[r]}function B(t,n,e){for(var r=0;r<16;r++)t[r]=n[r]-e[r]}function z(t,n,e){var r,o,i=0,s=0,c=0,a=0,u=0,h=0,f=0,p=0,l=0,d=0,y=0,b=0,v=0,g=0,m=0,_=0,w=0,S=0,k=0,T=0,O=0,C=0,A=0,P=0,E=0,x=0,U=0,L=0,M=0,R=0,j=0,I=e[0],N=e[1],B=e[2],z=e[3],D=e[4],H=e[5],F=e[6],q=e[7],Y=e[8],K=e[9],J=e[10],X=e[11],W=e[12],G=e[13],Z=e[14],V=e[15];i+=(r=n[0])*I,s+=r*N,c+=r*B,a+=r*z,u+=r*D,h+=r*H,f+=r*F,p+=r*q,l+=r*Y,d+=r*K,y+=r*J,b+=r*X,v+=r*W,g+=r*G,m+=r*Z,_+=r*V,s+=(r=n[1])*I,c+=r*N,a+=r*B,u+=r*z,h+=r*D,f+=r*H,p+=r*F,l+=r*q,d+=r*Y,y+=r*K,b+=r*J,v+=r*X,g+=r*W,m+=r*G,_+=r*Z,w+=r*V,c+=(r=n[2])*I,a+=r*N,u+=r*B,h+=r*z,f+=r*D,p+=r*H,l+=r*F,d+=r*q,y+=r*Y,b+=r*K,v+=r*J,g+=r*X,m+=r*W,_+=r*G,w+=r*Z,S+=r*V,a+=(r=n[3])*I,u+=r*N,h+=r*B,f+=r*z,p+=r*D,l+=r*H,d+=r*F,y+=r*q,b+=r*Y,v+=r*K,g+=r*J,m+=r*X,_+=r*W,w+=r*G,S+=r*Z,k+=r*V,u+=(r=n[4])*I,h+=r*N,f+=r*B,p+=r*z,l+=r*D,d+=r*H,y+=r*F,b+=r*q,v+=r*Y,g+=r*K,m+=r*J,_+=r*X,w+=r*W,S+=r*G,k+=r*Z,T+=r*V,h+=(r=n[5])*I,f+=r*N,p+=r*B,l+=r*z,d+=r*D,y+=r*H,b+=r*F,v+=r*q,g+=r*Y,m+=r*K,_+=r*J,w+=r*X,S+=r*W,k+=r*G,T+=r*Z,O+=r*V,f+=(r=n[6])*I,p+=r*N,l+=r*B,d+=r*z,y+=r*D,b+=r*H,v+=r*F,g+=r*q,m+=r*Y,_+=r*K,w+=r*J,S+=r*X,k+=r*W,T+=r*G,O+=r*Z,C+=r*V,p+=(r=n[7])*I,l+=r*N,d+=r*B,y+=r*z,b+=r*D,v+=r*H,g+=r*F,m+=r*q,_+=r*Y,w+=r*K,S+=r*J,k+=r*X,T+=r*W,O+=r*G,C+=r*Z,A+=r*V,l+=(r=n[8])*I,d+=r*N,y+=r*B,b+=r*z,v+=r*D,g+=r*H,m+=r*F,_+=r*q,w+=r*Y,S+=r*K,k+=r*J,T+=r*X,O+=r*W,C+=r*G,A+=r*Z,P+=r*V,d+=(r=n[9])*I,y+=r*N,b+=r*B,v+=r*z,g+=r*D,m+=r*H,_+=r*F,w+=r*q,S+=r*Y,k+=r*K,T+=r*J,O+=r*X,C+=r*W,A+=r*G,P+=r*Z,E+=r*V,y+=(r=n[10])*I,b+=r*N,v+=r*B,g+=r*z,m+=r*D,_+=r*H,w+=r*F,S+=r*q,k+=r*Y,T+=r*K,O+=r*J,C+=r*X,A+=r*W,P+=r*G,E+=r*Z,x+=r*V,b+=(r=n[11])*I,v+=r*N,g+=r*B,m+=r*z,_+=r*D,w+=r*H,S+=r*F,k+=r*q,T+=r*Y,O+=r*K,C+=r*J,A+=r*X,P+=r*W,E+=r*G,x+=r*Z,U+=r*V,v+=(r=n[12])*I,g+=r*N,m+=r*B,_+=r*z,w+=r*D,S+=r*H,k+=r*F,T+=r*q,O+=r*Y,C+=r*K,A+=r*J,P+=r*X,E+=r*W,x+=r*G,U+=r*Z,L+=r*V,g+=(r=n[13])*I,m+=r*N,_+=r*B,w+=r*z,S+=r*D,k+=r*H,T+=r*F,O+=r*q,C+=r*Y,A+=r*K,P+=r*J,E+=r*X,x+=r*W,U+=r*G,L+=r*Z,M+=r*V,m+=(r=n[14])*I,_+=r*N,w+=r*B,S+=r*z,k+=r*D,T+=r*H,O+=r*F,C+=r*q,A+=r*Y,P+=r*K,E+=r*J,x+=r*X,U+=r*W,L+=r*G,M+=r*Z,R+=r*V,_+=(r=n[15])*I,s+=38*(S+=r*B),c+=38*(k+=r*z),a+=38*(T+=r*D),u+=38*(O+=r*H),h+=38*(C+=r*F),f+=38*(A+=r*q),p+=38*(P+=r*Y),l+=38*(E+=r*K),d+=38*(x+=r*J),y+=38*(U+=r*X),b+=38*(L+=r*W),v+=38*(M+=r*G),g+=38*(R+=r*Z),m+=38*(j+=r*V),i=(r=(i+=38*(w+=r*N))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),_=(r=_+o+65535)-65536*(o=Math.floor(r/65536)),i=(r=(i+=o-1+37*(o-1))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),_=(r=_+o+65535)-65536*(o=Math.floor(r/65536)),i+=o-1+37*(o-1),t[0]=i,t[1]=s,t[2]=c,t[3]=a,t[4]=u,t[5]=h,t[6]=f,t[7]=p,t[8]=l,t[9]=d,t[10]=y,t[11]=b,t[12]=v,t[13]=g,t[14]=m,t[15]=_}function D(t,n){z(t,n,n)}function H(t,e){var r,o=n();for(r=0;r<16;r++)o[r]=e[r];for(r=253;r>=0;r--)D(o,o),2!==r&&4!==r&&z(o,o,e);for(r=0;r<16;r++)t[r]=o[r]}function F(t,e,r){var o,i,s=new Uint8Array(32),c=new Float64Array(80),u=n(),h=n(),f=n(),p=n(),l=n(),d=n();for(i=0;i<31;i++)s[i]=e[i];for(s[31]=127&e[31]|64,s[0]&=248,I(c,r),i=0;i<16;i++)h[i]=c[i],p[i]=u[i]=f[i]=0;for(u[0]=p[0]=1,i=254;i>=0;--i)L(u,h,o=s[i>>>3]>>>(7&i)&1),L(f,p,o),N(l,u,f),B(u,u,f),N(f,h,p),B(h,h,p),D(p,l),D(d,u),z(u,f,u),z(f,h,l),N(l,u,f),B(u,u,f),D(h,u),B(f,p,d),z(u,f,a),N(u,u,p),z(f,f,u),z(u,p,d),z(p,h,c),D(h,l),L(u,h,o),L(f,p,o);for(i=0;i<16;i++)c[i+16]=u[i],c[i+32]=f[i],c[i+48]=h[i],c[i+64]=p[i];var y=c.subarray(32),b=c.subarray(16);return H(y,y),z(b,b,y),M(t,b),0}function q(t,n){return F(t,n,i)}function Y(t,n){return r(n,32),q(t,n)}function K(t,n,e){var r=new Uint8Array(32);return F(r,e,n),m(t,o,r,_)}O.prototype.blocks=function(t,n,e){for(var r,o,i,s,c,a,u,h,f,p,l,d,y,b,v,g,m,_,w,S=this.fin?0:2048,k=this.h[0],T=this.h[1],O=this.h[2],C=this.h[3],A=this.h[4],P=this.h[5],E=this.h[6],x=this.h[7],U=this.h[8],L=this.h[9],M=this.r[0],R=this.r[1],j=this.r[2],I=this.r[3],N=this.r[4],B=this.r[5],z=this.r[6],D=this.r[7],H=this.r[8],F=this.r[9];e>=16;)p=f=0,p+=(k+=8191&(r=255&t[n+0]|(255&t[n+1])<<8))*M,p+=(T+=8191&(r>>>13|(o=255&t[n+2]|(255&t[n+3])<<8)<<3))*(5*F),p+=(O+=8191&(o>>>10|(i=255&t[n+4]|(255&t[n+5])<<8)<<6))*(5*H),p+=(C+=8191&(i>>>7|(s=255&t[n+6]|(255&t[n+7])<<8)<<9))*(5*D),f=(p+=(A+=8191&(s>>>4|(c=255&t[n+8]|(255&t[n+9])<<8)<<12))*(5*z))>>>13,p&=8191,p+=(P+=c>>>1&8191)*(5*B),p+=(E+=8191&(c>>>14|(a=255&t[n+10]|(255&t[n+11])<<8)<<2))*(5*N),p+=(x+=8191&(a>>>11|(u=255&t[n+12]|(255&t[n+13])<<8)<<5))*(5*I),p+=(U+=8191&(u>>>8|(h=255&t[n+14]|(255&t[n+15])<<8)<<8))*(5*j),l=f+=(p+=(L+=h>>>5|S)*(5*R))>>>13,l+=k*R,l+=T*M,l+=O*(5*F),l+=C*(5*H),f=(l+=A*(5*D))>>>13,l&=8191,l+=P*(5*z),l+=E*(5*B),l+=x*(5*N),l+=U*(5*I),f+=(l+=L*(5*j))>>>13,l&=8191,d=f,d+=k*j,d+=T*R,d+=O*M,d+=C*(5*F),f=(d+=A*(5*H))>>>13,d&=8191,d+=P*(5*D),d+=E*(5*z),d+=x*(5*B),d+=U*(5*N),y=f+=(d+=L*(5*I))>>>13,y+=k*I,y+=T*j,y+=O*R,y+=C*M,f=(y+=A*(5*F))>>>13,y&=8191,y+=P*(5*H),y+=E*(5*D),y+=x*(5*z),y+=U*(5*B),b=f+=(y+=L*(5*N))>>>13,b+=k*N,b+=T*I,b+=O*j,b+=C*R,f=(b+=A*M)>>>13,b&=8191,b+=P*(5*F),b+=E*(5*H),b+=x*(5*D),b+=U*(5*z),v=f+=(b+=L*(5*B))>>>13,v+=k*B,v+=T*N,v+=O*I,v+=C*j,f=(v+=A*R)>>>13,v&=8191,v+=P*M,v+=E*(5*F),v+=x*(5*H),v+=U*(5*D),g=f+=(v+=L*(5*z))>>>13,g+=k*z,g+=T*B,g+=O*N,g+=C*I,f=(g+=A*j)>>>13,g&=8191,g+=P*R,g+=E*M,g+=x*(5*F),g+=U*(5*H),m=f+=(g+=L*(5*D))>>>13,m+=k*D,m+=T*z,m+=O*B,m+=C*N,f=(m+=A*I)>>>13,m&=8191,m+=P*j,m+=E*R,m+=x*M,m+=U*(5*F),_=f+=(m+=L*(5*H))>>>13,_+=k*H,_+=T*D,_+=O*z,_+=C*B,f=(_+=A*N)>>>13,_&=8191,_+=P*I,_+=E*j,_+=x*R,_+=U*M,w=f+=(_+=L*(5*F))>>>13,w+=k*F,w+=T*H,w+=O*D,w+=C*z,f=(w+=A*B)>>>13,w&=8191,w+=P*N,w+=E*I,w+=x*j,w+=U*R,k=p=8191&(f=(f=((f+=(w+=L*M)>>>13)<<2)+f|0)+(p&=8191)|0),T=l+=f>>>=13,O=d&=8191,C=y&=8191,A=b&=8191,P=v&=8191,E=g&=8191,x=m&=8191,U=_&=8191,L=w&=8191,n+=16,e-=16;this.h[0]=k,this.h[1]=T,this.h[2]=O,this.h[3]=C,this.h[4]=A,this.h[5]=P,this.h[6]=E,this.h[7]=x,this.h[8]=U,this.h[9]=L},O.prototype.finish=function(t,n){var e,r,o,i,s=new Uint16Array(10);if(this.leftover){for(i=this.leftover,this.buffer[i++]=1;i<16;i++)this.buffer[i]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(e=this.h[1]>>>13,this.h[1]&=8191,i=2;i<10;i++)this.h[i]+=e,e=this.h[i]>>>13,this.h[i]&=8191;for(this.h[0]+=5*e,e=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=e,e=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=e,s[0]=this.h[0]+5,e=s[0]>>>13,s[0]&=8191,i=1;i<10;i++)s[i]=this.h[i]+e,e=s[i]>>>13,s[i]&=8191;for(s[9]-=8192,r=(1^e)-1,i=0;i<10;i++)s[i]&=r;for(r=~r,i=0;i<10;i++)this.h[i]=this.h[i]&r|s[i];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),o=this.h[0]+this.pad[0],this.h[0]=65535&o,i=1;i<8;i++)o=(this.h[i]+this.pad[i]|0)+(o>>>16)|0,this.h[i]=65535&o;t[n+0]=this.h[0]>>>0&255,t[n+1]=this.h[0]>>>8&255,t[n+2]=this.h[1]>>>0&255,t[n+3]=this.h[1]>>>8&255,t[n+4]=this.h[2]>>>0&255,t[n+5]=this.h[2]>>>8&255,t[n+6]=this.h[3]>>>0&255,t[n+7]=this.h[3]>>>8&255,t[n+8]=this.h[4]>>>0&255,t[n+9]=this.h[4]>>>8&255,t[n+10]=this.h[5]>>>0&255,t[n+11]=this.h[5]>>>8&255,t[n+12]=this.h[6]>>>0&255,t[n+13]=this.h[6]>>>8&255,t[n+14]=this.h[7]>>>0&255,t[n+15]=this.h[7]>>>8&255},O.prototype.update=function(t,n,e){var r,o;if(this.leftover){for((o=16-this.leftover)>e&&(o=e),r=0;r=16&&(o=e-e%16,this.blocks(t,n,o),n+=o,e-=o),e){for(r=0;r=128;){for(S=0;S<16;S++)k=8*S+G,x[S]=e[k+0]<<24|e[k+1]<<16|e[k+2]<<8|e[k+3],U[S]=e[k+4]<<24|e[k+5]<<16|e[k+6]<<8|e[k+7];for(S=0;S<80;S++)if(o=L,i=M,s=R,c=j,a=I,u=N,h=B,z,p=D,l=H,d=F,y=q,b=Y,v=K,g=J,X,C=65535&(O=X),A=O>>>16,P=65535&(T=z),E=T>>>16,C+=65535&(O=(Y>>>14|I<<18)^(Y>>>18|I<<14)^(I>>>9|Y<<23)),A+=O>>>16,P+=65535&(T=(I>>>14|Y<<18)^(I>>>18|Y<<14)^(Y>>>9|I<<23)),E+=T>>>16,C+=65535&(O=Y&K^~Y&J),A+=O>>>16,P+=65535&(T=I&N^~I&B),E+=T>>>16,T=W[2*S],C+=65535&(O=W[2*S+1]),A+=O>>>16,P+=65535&T,E+=T>>>16,T=x[S%16],A+=(O=U[S%16])>>>16,P+=65535&T,E+=T>>>16,P+=(A+=(C+=65535&O)>>>16)>>>16,C=65535&(O=w=65535&C|A<<16),A=O>>>16,P=65535&(T=_=65535&P|(E+=P>>>16)<<16),E=T>>>16,C+=65535&(O=(D>>>28|L<<4)^(L>>>2|D<<30)^(L>>>7|D<<25)),A+=O>>>16,P+=65535&(T=(L>>>28|D<<4)^(D>>>2|L<<30)^(D>>>7|L<<25)),E+=T>>>16,A+=(O=D&H^D&F^H&F)>>>16,P+=65535&(T=L&M^L&R^M&R),E+=T>>>16,f=65535&(P+=(A+=(C+=65535&O)>>>16)>>>16)|(E+=P>>>16)<<16,m=65535&C|A<<16,C=65535&(O=y),A=O>>>16,P=65535&(T=c),E=T>>>16,A+=(O=w)>>>16,P+=65535&(T=_),E+=T>>>16,M=o,R=i,j=s,I=c=65535&(P+=(A+=(C+=65535&O)>>>16)>>>16)|(E+=P>>>16)<<16,N=a,B=u,z=h,L=f,H=p,F=l,q=d,Y=y=65535&C|A<<16,K=b,J=v,X=g,D=m,S%16==15)for(k=0;k<16;k++)T=x[k],C=65535&(O=U[k]),A=O>>>16,P=65535&T,E=T>>>16,T=x[(k+9)%16],C+=65535&(O=U[(k+9)%16]),A+=O>>>16,P+=65535&T,E+=T>>>16,_=x[(k+1)%16],C+=65535&(O=((w=U[(k+1)%16])>>>1|_<<31)^(w>>>8|_<<24)^(w>>>7|_<<25)),A+=O>>>16,P+=65535&(T=(_>>>1|w<<31)^(_>>>8|w<<24)^_>>>7),E+=T>>>16,_=x[(k+14)%16],A+=(O=((w=U[(k+14)%16])>>>19|_<<13)^(_>>>29|w<<3)^(w>>>6|_<<26))>>>16,P+=65535&(T=(_>>>19|w<<13)^(w>>>29|_<<3)^_>>>6),E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,x[k]=65535&P|E<<16,U[k]=65535&C|A<<16;C=65535&(O=D),A=O>>>16,P=65535&(T=L),E=T>>>16,T=t[0],A+=(O=n[0])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[0]=L=65535&P|E<<16,n[0]=D=65535&C|A<<16,C=65535&(O=H),A=O>>>16,P=65535&(T=M),E=T>>>16,T=t[1],A+=(O=n[1])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[1]=M=65535&P|E<<16,n[1]=H=65535&C|A<<16,C=65535&(O=F),A=O>>>16,P=65535&(T=R),E=T>>>16,T=t[2],A+=(O=n[2])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[2]=R=65535&P|E<<16,n[2]=F=65535&C|A<<16,C=65535&(O=q),A=O>>>16,P=65535&(T=j),E=T>>>16,T=t[3],A+=(O=n[3])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[3]=j=65535&P|E<<16,n[3]=q=65535&C|A<<16,C=65535&(O=Y),A=O>>>16,P=65535&(T=I),E=T>>>16,T=t[4],A+=(O=n[4])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[4]=I=65535&P|E<<16,n[4]=Y=65535&C|A<<16,C=65535&(O=K),A=O>>>16,P=65535&(T=N),E=T>>>16,T=t[5],A+=(O=n[5])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[5]=N=65535&P|E<<16,n[5]=K=65535&C|A<<16,C=65535&(O=J),A=O>>>16,P=65535&(T=B),E=T>>>16,T=t[6],A+=(O=n[6])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[6]=B=65535&P|E<<16,n[6]=J=65535&C|A<<16,C=65535&(O=X),A=O>>>16,P=65535&(T=z),E=T>>>16,T=t[7],A+=(O=n[7])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[7]=z=65535&P|E<<16,n[7]=X=65535&C|A<<16,G+=128,r-=128}return r}function Z(t,n,e){var r,o=new Int32Array(8),i=new Int32Array(8),s=new Uint8Array(256),c=e;for(o[0]=1779033703,o[1]=3144134277,o[2]=1013904242,o[3]=2773480762,o[4]=1359893119,o[5]=2600822924,o[6]=528734635,o[7]=1541459225,i[0]=4089235720,i[1]=2227873595,i[2]=4271175723,i[3]=1595750129,i[4]=2917565137,i[5]=725511199,i[6]=4215389547,i[7]=327033209,G(o,i,n,e),e%=128,r=0;r=0;--o)Q(t,n,r=e[o/8|0]>>(7&o)&1),V(n,t),V(t,t),Q(t,n,r)}function nt(t,e){var r=[n(),n(),n(),n()];x(r[0],f),x(r[1],p),x(r[2],c),z(r[3],f,p),tt(t,r,e)}function et(t,e,o){var i,s=new Uint8Array(64),c=[n(),n(),n(),n()];for(o||r(e,32),Z(s,e,32),s[0]&=248,s[31]&=127,s[31]|=64,nt(c,s),$(t,c),i=0;i<32;i++)e[i+32]=t[i];return 0}var rt=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function ot(t,n){var e,r,o,i;for(r=63;r>=32;--r){for(e=0,o=r-32,i=r-12;o>8,n[o]-=256*e;n[o]+=e,n[r]=0}for(e=0,o=0;o<32;o++)n[o]+=e-(n[31]>>4)*rt[o],e=n[o]>>8,n[o]&=255;for(o=0;o<32;o++)n[o]-=e*rt[o];for(r=0;r<32;r++)n[r+1]+=n[r]>>8,t[r]=255&n[r]}function it(t){var n,e=new Float64Array(64);for(n=0;n<64;n++)e[n]=t[n];for(n=0;n<64;n++)t[n]=0;ot(t,e)}function st(t,e,r,o){var i,s,c=new Uint8Array(64),a=new Uint8Array(64),u=new Uint8Array(64),h=new Float64Array(64),f=[n(),n(),n(),n()];Z(c,o,32),c[0]&=248,c[31]&=127,c[31]|=64;var p=r+64;for(i=0;i=0;r--)D(o,o),1!==r&&z(o,o,e);for(r=0;r<16;r++)t[r]=o[r]}(r,r),z(r,r,i),z(r,r,a),z(r,r,a),z(t[0],r,a),D(o,t[0]),z(o,o,a),R(o,i)&&z(t[0],t[0],l),D(o,t[0]),z(o,o,a),R(o,i)?-1:(j(t[0])===e[31]>>7&&B(t[0],s,t[0]),z(t[3],t[0],t[1]),0)}function at(t,e,r,o){var i,s=new Uint8Array(32),c=new Uint8Array(64),a=[n(),n(),n(),n()],u=[n(),n(),n(),n()];if(-1,r<64)return-1;if(ct(u,o))return-1;for(i=0;i=0},t.sign.keyPair=function(){var t=new Uint8Array(32),n=new Uint8Array(64);return et(t,n),{publicKey:t,secretKey:n}},t.sign.keyPair.fromSecretKey=function(t){if(yt(t),64!==t.length)throw new Error("bad secret key size");for(var n=new Uint8Array(32),e=0;e>>6)+r(128|63&n):r(224|n>>>12&15)+r(128|n>>>6&63)+r(128|63&n)},h=function(t){return t.replace(/[^\x00-\x7F]/g,u)},f=function(t){var n=[0,2,1][t.length%3],e=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[o.charAt(e>>>18),o.charAt(e>>>12&63),n>=2?"=":o.charAt(e>>>6&63),n>=1?"=":o.charAt(63&e)].join("")},p=self.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,f)},l=function(){function t(t,n,e,r){var o=this;this.clear=n,this.timer=t(function(){o.timer&&(o.timer=r(o.timer))},e)}return t.prototype.isRunning=function(){return null!==this.timer},t.prototype.ensureAborted=function(){this.timer&&(this.clear(this.timer),this.timer=null)},t}(),d=(a=function(t,n){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(t,n)},function(t,n){function e(){this.constructor=t}a(t,n),t.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)});function y(t){self.clearTimeout(t)}function b(t){self.clearInterval(t)}var v=function(t){function n(n,e){return t.call(this,setTimeout,y,n,function(t){return e(),null})||this}return d(n,t),n}(l),g=function(t){function n(n,e){return t.call(this,setInterval,b,n,function(t){return e(),t})||this}return d(n,t),n}(l),m={now:function(){return Date.now?Date.now():(new Date).valueOf()},defer:function(t){return new v(0,t)},method:function(t){for(var n=[],e=1;e0)for(r=0;r=1002&&t.code<=1004?"backoff":null:4e3===t.code?"tls_only":t.code<4100?"refused":t.code<4200?"backoff":t.code<4300?"retry":"refused"},getCloseError:function(t){return 1e3!==t.code&&1001!==t.code?{type:"PusherError",data:{code:t.code,message:t.reason||t.message}}:null}},$=Q,tt=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),nt=function(t){function n(n,e){var r=t.call(this)||this;return r.id=n,r.transport=e,r.activityTimeout=e.activityTimeout,r.bindListeners(),r}return tt(n,t),n.prototype.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()},n.prototype.send=function(t){return this.transport.send(t)},n.prototype.send_event=function(t,n,e){var r={event:t,data:n};return e&&(r.channel=e),H.debug("Event sent",r),this.send($.encodeMessage(r))},n.prototype.ping=function(){this.transport.supportsPing()?this.transport.ping():this.send_event("pusher:ping",{})},n.prototype.close=function(){this.transport.close()},n.prototype.bindListeners=function(){var t=this,n={message:function(n){var e;try{e=$.decodeMessage(n)}catch(e){t.emit("error",{type:"MessageParseError",error:e,data:n.data})}if(void 0!==e){switch(H.debug("Event recd",e),e.event){case"pusher:error":t.emit("error",{type:"PusherError",data:e.data});break;case"pusher:ping":t.emit("ping");break;case"pusher:pong":t.emit("pong")}t.emit("message",e)}},activity:function(){t.emit("activity")},error:function(n){t.emit("error",{type:"WebSocketError",error:n})},closed:function(n){e(),n&&n.code&&t.handleCloseEvent(n),t.transport=null,t.emit("closed")}},e=function(){k(n,function(n,e){t.transport.unbind(e,n)})};k(n,function(n,e){t.transport.bind(e,n)})},n.prototype.handleCloseEvent=function(t){var n=$.getCloseAction(t),e=$.getCloseError(t);e&&this.emit("error",e),n&&this.emit(n,{action:n,error:e})},n}(D),et=function(){function t(t,n){this.transport=t,this.callback=n,this.bindListeners()}return t.prototype.close=function(){this.unbindListeners(),this.transport.close()},t.prototype.bindListeners=function(){var t=this;this.onMessage=function(n){var e;t.unbindListeners();try{e=$.processHandshake(n)}catch(n){return t.finish("error",{error:n}),void t.transport.close()}"connected"===e.action?t.finish("connected",{connection:new nt(e.id,t.transport),activityTimeout:e.activityTimeout}):(t.finish(e.action,{error:e.error}),t.transport.close())},this.onClosed=function(n){t.unbindListeners();var e=$.getCloseAction(n)||"backoff",r=$.getCloseError(n);t.finish(e,{error:r})},this.transport.bind("message",this.onMessage),this.transport.bind("closed",this.onClosed)},t.prototype.unbindListeners=function(){this.transport.unbind("message",this.onMessage),this.transport.unbind("closed",this.onClosed)},t.prototype.finish=function(t,n){this.callback(_({transport:this.transport,action:t},n))},t}(),rt=function(){function t(t,n){this.channel=t;var e=n.authTransport;if(void 0===rn.getAuthorizers()[e])throw"'"+e+"' is not a recognized auth transport";this.type=e,this.options=n,this.authOptions=(n||{}).auth||{}}return t.prototype.composeQuery=function(t){var n="socket_id="+encodeURIComponent(t)+"&channel_name="+encodeURIComponent(this.channel.name);for(var e in this.authOptions.params)n+="&"+encodeURIComponent(e)+"="+encodeURIComponent(this.authOptions.params[e]);return n},t.prototype.authorize=function(n,e){return t.authorizers=t.authorizers||rn.getAuthorizers(),t.authorizers[this.type].call(this,rn,n,e)},t}(),ot=function(){function t(t,n){this.timeline=t,this.options=n||{}}return t.prototype.send=function(t,n){this.timeline.isEmpty()||this.timeline.send(rn.TimelineTransport.getAgent(this,t),n)},t}(),it=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),st=function(t){function n(n){var e=this.constructor,r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return it(n,t),n}(Error),ct=(function(t){function n(n){var e=this.constructor,r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}it(n,t)}(Error),function(t){function n(n){var e=this.constructor,r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return it(n,t),n}(Error)),at=function(t){function n(n){var e=this.constructor,r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return it(n,t),n}(Error),ut=function(t){function n(n){var e=this.constructor,r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return it(n,t),n}(Error),ht=function(t){function n(n){var e=this.constructor,r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return it(n,t),n}(Error),ft=function(t){function n(n){var e=this.constructor,r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return it(n,t),n}(Error),pt={baseUrl:"https://pusher.com",urls:{authenticationEndpoint:{path:"/docs/authenticating_users"},javascriptQuickStart:{path:"/docs/javascript_quick_start"},triggeringClientEvents:{path:"/docs/client_api_guide/client_events#trigger-events"}}},lt={buildLogSuffix:function(t){var n,e=pt.urls[t];return e?(e.fullUrl?n=e.fullUrl:e.path&&(n=pt.baseUrl+e.path),n?"See: "+n:""):""}},dt=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),yt=function(t){function n(n,e){var r=t.call(this,function(t,e){H.debug("No callbacks on "+n+" for "+t)})||this;return r.name=n,r.pusher=e,r.subscribed=!1,r.subscriptionPending=!1,r.subscriptionCancelled=!1,r}return dt(n,t),n.prototype.authorize=function(t,n){return n(!1,{})},n.prototype.trigger=function(t,n){if(0!==t.indexOf("client-"))throw new st("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var e=lt.buildLogSuffix("triggeringClientEvents");H.warn("Client event triggered before channel 'subscription_succeeded' event . "+e)}return this.pusher.send_event(t,n,this.name)},n.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},n.prototype.handleEvent=function(t){var n=t.event,e=t.data;if("pusher_internal:subscription_succeeded"===n)this.handleSubscriptionSucceededEvent(t);else if(0!==n.indexOf("pusher_internal:")){this.emit(n,e,{})}},n.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",t.data)},n.prototype.subscribe=function(){var t=this;this.subscribed||(this.subscriptionPending=!0,this.subscriptionCancelled=!1,this.authorize(this.pusher.connection.socket_id,function(n,e){n?t.emit("pusher:subscription_error",e):t.pusher.send_event("pusher:subscribe",{auth:e.auth,channel_data:e.channel_data,channel:t.name})}))},n.prototype.unsubscribe=function(){this.subscribed=!1,this.pusher.send_event("pusher:unsubscribe",{channel:this.name})},n.prototype.cancelSubscription=function(){this.subscriptionCancelled=!0},n.prototype.reinstateSubscription=function(){this.subscriptionCancelled=!1},n}(D),bt=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),vt=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return bt(n,t),n.prototype.authorize=function(t,n){return Pt.createAuthorizer(this,this.pusher.config).authorize(t,n)},n}(yt),gt=function(){function t(){this.reset()}return t.prototype.get=function(t){return Object.prototype.hasOwnProperty.call(this.members,t)?{id:t,info:this.members[t]}:null},t.prototype.each=function(t){var n=this;k(this.members,function(e,r){t(n.get(r))})},t.prototype.setMyID=function(t){this.myID=t},t.prototype.onSubscription=function(t){this.members=t.presence.hash,this.count=t.presence.count,this.me=this.get(this.myID)},t.prototype.addMember=function(t){return null===this.get(t.user_id)&&this.count++,this.members[t.user_id]=t.user_info,this.get(t.user_id)},t.prototype.removeMember=function(t){var n=this.get(t.user_id);return n&&(delete this.members[t.user_id],this.count--),n},t.prototype.reset=function(){this.members={},this.count=0,this.myID=null,this.me=null},t}(),mt=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),_t=function(t){function n(n,e){var r=t.call(this,n,e)||this;return r.members=new gt,r}return mt(n,t),n.prototype.authorize=function(n,e){var r=this;t.prototype.authorize.call(this,n,function(t,n){if(!t){if(void 0===n.channel_data){var o=lt.buildLogSuffix("authenticationEndpoint");return H.warn("Invalid auth response for channel '"+r.name+"',expected 'channel_data' field. "+o),void e("Invalid auth response")}var i=JSON.parse(n.channel_data);r.members.setMyID(i.user_id)}e(t,n)})},n.prototype.handleEvent=function(t){var n=t.event;if(0===n.indexOf("pusher_internal:"))this.handleInternalEvent(t);else{var e=t.data,r={};t.user_id&&(r.user_id=t.user_id),this.emit(n,e,r)}},n.prototype.handleInternalEvent=function(t){var n=t.event,e=t.data;switch(n){case"pusher_internal:subscription_succeeded":this.handleSubscriptionSucceededEvent(t);break;case"pusher_internal:member_added":var r=this.members.addMember(e);this.emit("pusher:member_added",r);break;case"pusher_internal:member_removed":var o=this.members.removeMember(e);o&&this.emit("pusher:member_removed",o)}},n.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(t.data),this.emit("pusher:subscription_succeeded",this.members))},n.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},n}(vt),wt=e(0),St=e(1),kt=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),Tt=function(t){function n(){var n=null!==t&&t.apply(this,arguments)||this;return n.key=null,n}return kt(n,t),n.prototype.authorize=function(n,e){var r=this;t.prototype.authorize.call(this,n,function(t,n){if(t)e(!0,n);else{var o=n.shared_secret;if(!o){var i="No shared_secret key in auth payload for encrypted channel: "+r.name;return e(!0,i),void H.warn("Error: "+i)}r.key=Object(St.decodeBase64)(o),delete n.shared_secret,e(!1,n)}})},n.prototype.trigger=function(t,n){throw new ut("Client events are not currently supported for encrypted channels")},n.prototype.handleEvent=function(n){var e=n.event,r=n.data;0!==e.indexOf("pusher_internal:")&&0!==e.indexOf("pusher:")?this.handleEncryptedEvent(e,r):t.prototype.handleEvent.call(this,n)},n.prototype.handleEncryptedEvent=function(t,n){var e=this;if(this.key)if(n.ciphertext&&n.nonce){var r=Object(St.decodeBase64)(n.ciphertext);if(r.length0&&this.emit("connecting_in",Math.round(t/1e3)),this.retryTimer=new v(t||0,function(){n.disconnectInternally(),n.connect()})},n.prototype.clearRetryTimer=function(){this.retryTimer&&(this.retryTimer.ensureAborted(),this.retryTimer=null)},n.prototype.setUnavailableTimer=function(){var t=this;this.unavailableTimer=new v(this.options.unavailableTimeout,function(){t.updateState("unavailable")})},n.prototype.clearUnavailableTimer=function(){this.unavailableTimer&&this.unavailableTimer.ensureAborted()},n.prototype.sendActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection.ping(),this.activityTimer=new v(this.options.pongTimeout,function(){t.timeline.error({pong_timed_out:t.options.pongTimeout}),t.retryIn(0)})},n.prototype.resetActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection&&!this.connection.handlesActivityChecks()&&(this.activityTimer=new v(this.activityTimeout,function(){t.sendActivityCheck()}))},n.prototype.stopActivityCheck=function(){this.activityTimer&&this.activityTimer.ensureAborted()},n.prototype.buildConnectionCallbacks=function(t){var n=this;return _({},t,{message:function(t){n.resetActivityCheck(),n.emit("message",t)},ping:function(){n.send_event("pusher:pong",{})},activity:function(){n.resetActivityCheck()},error:function(t){n.emit("error",{type:"WebSocketError",error:t})},closed:function(){n.abandonConnection(),n.shouldRetry()&&n.retryIn(1e3)}})},n.prototype.buildHandshakeCallbacks=function(t){var n=this;return _({},t,{connected:function(t){n.activityTimeout=Math.min(n.options.activityTimeout,t.activityTimeout,t.connection.activityTimeout||1/0),n.clearUnavailableTimer(),n.setConnection(t.connection),n.socket_id=n.connection.id,n.updateState("connected",{socket_id:n.socket_id})}})},n.prototype.buildErrorCallbacks=function(){var t=this,n=function(n){return function(e){e.error&&t.emit("error",{type:"WebSocketError",error:e.error}),n(e)}};return{tls_only:n(function(){t.usingTLS=!0,t.updateStrategy(),t.retryIn(0)}),refused:n(function(){t.disconnect()}),backoff:n(function(){t.retryIn(1e3)}),retry:n(function(){t.retryIn(0)})}},n.prototype.setConnection=function(t){for(var n in this.connection=t,this.connectionCallbacks)this.connection.bind(n,this.connectionCallbacks[n]);this.resetActivityCheck()},n.prototype.abandonConnection=function(){if(this.connection){for(var t in this.stopActivityCheck(),this.connectionCallbacks)this.connection.unbind(t,this.connectionCallbacks[t]);var n=this.connection;return this.connection=null,n}},n.prototype.updateState=function(t,n){var e=this.state;if(this.state=t,e!==t){var r=t;"connected"===r&&(r+=" with new socket ID "+n.socket_id),H.debug("State changed",e+" -> "+r),this.timeline.info({state:t,params:n}),this.emit("state_change",{previous:e,current:t}),this.emit(t,n)}},n.prototype.shouldRetry=function(){return"connecting"===this.state||"connected"===this.state},n}(D),At=function(){function t(){this.channels={}}return t.prototype.add=function(t,n){return this.channels[t]||(this.channels[t]=function(t,n){return 0===t.indexOf("private-encrypted-")?Pt.createEncryptedChannel(t,n):0===t.indexOf("private-")?Pt.createPrivateChannel(t,n):0===t.indexOf("presence-")?Pt.createPresenceChannel(t,n):Pt.createChannel(t,n)}(t,n)),this.channels[t]},t.prototype.all=function(){return function(t){var n=[];return k(t,function(t){n.push(t)}),n}(this.channels)},t.prototype.find=function(t){return this.channels[t]},t.prototype.remove=function(t){var n=this.channels[t];return delete this.channels[t],n},t.prototype.disconnect=function(){k(this.channels,function(t){t.disconnect()})},t}();var Pt={createChannels:function(){return new At},createConnectionManager:function(t,n){return new Ct(t,n)},createChannel:function(t,n){return new yt(t,n)},createPrivateChannel:function(t,n){return new vt(t,n)},createPresenceChannel:function(t,n){return new _t(t,n)},createEncryptedChannel:function(t,n){return new Tt(t,n)},createTimelineSender:function(t,n){return new ot(t,n)},createAuthorizer:function(t,n){return n.authorizer?n.authorizer(t,n):new rt(t,n)},createHandshake:function(t,n){return new et(t,n)},createAssistantToTheTransportManager:function(t,n,e){return new V(t,n,e)}},Et=function(){function t(t){this.options=t||{},this.livesLeft=this.options.lives||1/0}return t.prototype.getAssistant=function(t){return Pt.createAssistantToTheTransportManager(this,t,{minPingDelay:this.options.minPingDelay,maxPingDelay:this.options.maxPingDelay})},t.prototype.isAlive=function(){return this.livesLeft>0},t.prototype.reportDeath=function(){this.livesLeft-=1},t}(),xt=function(){function t(t,n){this.strategies=t,this.loop=Boolean(n.loop),this.failFast=Boolean(n.failFast),this.timeout=n.timeout,this.timeoutLimit=n.timeoutLimit}return t.prototype.isSupported=function(){return E(this.strategies,m.method("isSupported"))},t.prototype.connect=function(t,n){var e=this,r=this.strategies,o=0,i=this.timeout,s=null,c=function(a,u){u?n(null,u):(o+=1,e.loop&&(o%=r.length),o0&&(o=new v(e.timeout,function(){i.abort(),r(!0)})),i=t.connect(n,function(t,n){t&&o&&o.isRunning()&&!e.failFast||(o&&o.ensureAborted(),r(t,n))}),{abort:function(){o&&o.ensureAborted(),i.abort()},forceMinPriority:function(t){i.forceMinPriority(t)}}},t}(),Ut=function(){function t(t){this.strategies=t}return t.prototype.isSupported=function(){return E(this.strategies,m.method("isSupported"))},t.prototype.connect=function(t,n){return function(t,n,e){var r=C(t,function(t,r,o,i){return t.connect(n,e(r,i))});return{abort:function(){O(r,Lt)},forceMinPriority:function(t){O(r,function(n){n.forceMinPriority(t)})}}}(this.strategies,t,function(t,e){return function(r,o){e[t].error=r,r?function(t){return function(t,n){for(var e=0;e=m.now()){var i=this.transports[r.transport];i&&(this.timeline.info({cached:!0,transport:r.transport,latency:r.latency}),o.push(new xt([i],{timeout:2*r.latency+1e3,failFast:!0})))}var s=m.now(),c=o.pop().connect(t,function r(i,a){i?(jt(e),o.length>0?(s=m.now(),c=o.pop().connect(t,r)):n(i)):(!function(t,n,e){var r=rn.getLocalStorage();if(r)try{r[Rt(t)]=L({timestamp:m.now(),transport:n,latency:e})}catch(t){}}(e,a.transport.name,m.now()-s),n(null,a))});return{abort:function(){c.abort()},forceMinPriority:function(n){t=n,c&&c.forceMinPriority(n)}}},t}();function Rt(t){return"pusherTransport"+(t?"TLS":"NonTLS")}function jt(t){var n=rn.getLocalStorage();if(n)try{delete n[Rt(t)]}catch(t){}}var It=function(){function t(t,n){var e=n.delay;this.strategy=t,this.options={delay:e}}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,n){var e,r=this.strategy,o=new v(this.options.delay,function(){e=r.connect(t,n)});return{abort:function(){o.ensureAborted(),e&&e.abort()},forceMinPriority:function(n){t=n,e&&e.forceMinPriority(n)}}},t}(),Nt=function(){function t(t,n,e){this.test=t,this.trueBranch=n,this.falseBranch=e}return t.prototype.isSupported=function(){return(this.test()?this.trueBranch:this.falseBranch).isSupported()},t.prototype.connect=function(t,n){return(this.test()?this.trueBranch:this.falseBranch).connect(t,n)},t}(),Bt=function(){function t(t){this.strategy=t}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,n){var e=this.strategy.connect(t,function(t,r){r&&e.abort(),n(t,r)});return e},t}();function zt(t){return function(){return t.isSupported()}}var Dt,Ht=function(t,n){var e={};function r(r,o,i,s,c){var a=n(t,r,o,i,s,c);return e[r]=a,a}var o,i={hostNonTLS:t.wsHost+":"+t.wsPort,hostTLS:t.wsHost+":"+t.wssPort,httpPath:t.wsPath},s=_({},i,{useTLS:!0}),c={hostNonTLS:t.httpHost+":"+t.httpPort,hostTLS:t.httpHost+":"+t.httpsPort,httpPath:t.httpPath},a={loop:!0,timeout:15e3,timeoutLimit:6e4},u=new Et({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),h=new Et({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),f=r("ws","ws",3,i,u),p=r("wss","ws",3,s,u),l=r("xhr_streaming","xhr_streaming",1,c,h),d=r("xhr_polling","xhr_polling",1,c),y=new xt([f],a),b=new xt([p],a),v=new xt([l],a),g=new xt([d],a),m=new xt([new Nt(zt(v),new Ut([v,new It(g,{delay:4e3})]),g)],a);return o=t.useTLS?new Ut([y,new It(m,{delay:2e3})]):new Ut([y,new It(b,{delay:2e3}),new It(m,{delay:5e3})]),new Mt(new Bt(new Nt(zt(f),o,m)),e,{ttl:18e5,timeline:t.timeline,useTLS:t.useTLS})},Ft=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),qt=function(t){function n(n,e,r){var o=t.call(this)||this;return o.hooks=n,o.method=e,o.url=r,o}return Ft(n,t),n.prototype.start=function(t){var n=this;this.position=0,this.xhr=this.hooks.getRequest(this),this.unloader=function(){n.close()},rn.addUnloadListener(this.unloader),this.xhr.open(this.method,this.url,!0),this.xhr.setRequestHeader&&this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.send(t)},n.prototype.close=function(){this.unloader&&(rn.removeUnloadListener(this.unloader),this.unloader=null),this.xhr&&(this.hooks.abortRequest(this.xhr),this.xhr=null)},n.prototype.onChunk=function(t,n){for(;;){var e=this.advanceBuffer(n);if(!e)break;this.emit("chunk",{status:t,data:e})}this.isBufferTooLong(n)&&this.emit("buffer_too_long")},n.prototype.advanceBuffer=function(t){var n=t.slice(this.position),e=n.indexOf("\n");return-1!==e?(this.position+=e+1,n.slice(0,e)):null},n.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>262144},n}(D);!function(t){t[t.CONNECTING=0]="CONNECTING",t[t.OPEN=1]="OPEN",t[t.CLOSED=3]="CLOSED"}(Dt||(Dt={}));var Yt=Dt,Kt=1;function Jt(t){var n=-1===t.indexOf("?")?"?":"&";return t+n+"t="+ +new Date+"&n="+Kt++}function Xt(t){return Math.floor(Math.random()*t)}var Wt,Gt=function(){function t(t,n){this.hooks=t,this.session=Xt(1e3)+"/"+function(t){for(var n=[],e=0;e0&&t.onChunk(n.status,n.responseText);break;case 4:n.responseText&&n.responseText.length>0&&t.onChunk(n.status,n.responseText),t.emit("finished",n.status),t.close()}},n},abortRequest:function(t){t.onreadystatechange=null,t.abort()}},$t={getDefaultStrategy:Ht,Transports:Z,transportConnectionInitializer:function(){this.timeline.info(this.buildTimelineMessage({transport:this.name+(this.options.useTLS?"s":"")})),this.hooks.isInitialized()?this.changeState("initialized"):this.onClose()},HTTPFactory:{createStreamingSocket:function(t){return this.createSocket(Zt,t)},createPollingSocket:function(t){return this.createSocket(Vt,t)},createSocket:function(t,n){return new Gt(t,n)},createXHR:function(t,n){return this.createRequest(Qt,t,n)},createRequest:function(t,n,e){return new qt(t,n,e)}},setup:function(t){t.ready()},getLocalStorage:function(){},getClientFeatures:function(){return T(P({ws:Z.ws},function(t){return t.isSupported({})}))},getProtocol:function(){return"http:"},isXHRSupported:function(){return!0},createSocketRequest:function(t,n){if(this.isXHRSupported())return this.HTTPFactory.createXHR(t,n);throw"Cross-origin HTTP requests are not supported"},createXHR:function(){return new(this.getXHRAPI())},createWebSocket:function(t){return new(this.getWebSocketAPI())(t)},addUnloadListener:function(t){},removeUnloadListener:function(t){}},tn=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),nn=new(function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return tn(n,t),n.prototype.isOnline=function(){return!0},n}(D)),en=function(t,n,e){var r=new Headers;for(var o in r.set("Content-Type","application/x-www-form-urlencoded"),this.authOptions.headers)r.set(o,this.authOptions.headers[o]);var i=this.composeQuery(n),s=new Request(this.options.authEndpoint,{headers:r,body:i,credentials:"same-origin",method:"POST"});return fetch(s).then(function(t){var n=t.status;if(200===n)return t.text();throw H.warn("Couldn't get auth info from your webapp",n),n}).then(function(t){try{t=JSON.parse(t)}catch(e){var n="JSON returned from webapp was invalid, yet status code was 200. Data was: "+t;throw H.warn(n),n}e(!1,t)}).catch(function(t){e(!0,t)})},rn={getDefaultStrategy:$t.getDefaultStrategy,Transports:$t.Transports,setup:$t.setup,getProtocol:$t.getProtocol,isXHRSupported:$t.isXHRSupported,getLocalStorage:$t.getLocalStorage,createXHR:$t.createXHR,createWebSocket:$t.createWebSocket,addUnloadListener:$t.addUnloadListener,removeUnloadListener:$t.removeUnloadListener,transportConnectionInitializer:$t.transportConnectionInitializer,createSocketRequest:$t.createSocketRequest,HTTPFactory:$t.HTTPFactory,TimelineTransport:{name:"xhr",getAgent:function(t,n){return function(e,r){var o="http"+(n?"s":"")+"://"+(t.host||t.options.host)+t.options.path,i=U(e);fetch(o+="/2?"+i).then(function(t){if(200!==t.status)throw"received "+t.status+" from stats.pusher.com";return t.json()}).then(function(n){var e=n.host;e&&(t.host=e)}).catch(function(t){H.debug("TimelineSender Error: ",t)})}}},getAuthorizers:function(){return{ajax:en}},getWebSocketAPI:function(){return WebSocket},getXHRAPI:function(){return XMLHttpRequest},getNetwork:function(){return nn}};!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(Wt||(Wt={}));var on=Wt,sn=function(){function t(t,n,e){this.key=t,this.session=n,this.events=[],this.options=e||{},this.sent=0,this.uniqueID=0}return t.prototype.log=function(t,n){t<=this.options.level&&(this.events.push(_({},n,{timestamp:m.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(on.ERROR,t)},t.prototype.info=function(t){this.log(on.INFO,t)},t.prototype.debug=function(t){this.log(on.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,n){var e=this,r=_({session:this.session,bundle:this.sent+1,key:this.key,lib:"js",version:this.options.version,cluster:this.options.cluster,features:this.options.features,timeline:this.events},this.options.params);return this.events=[],t(r,function(t,r){t||e.sent++,n&&n(t,r)}),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}(),cn=function(){function t(t,n,e,r){this.name=t,this.priority=n,this.transport=e,this.options=r||{}}return t.prototype.isSupported=function(){return this.transport.isSupported({useTLS:this.options.useTLS})},t.prototype.connect=function(t,n){var e=this;if(!this.isSupported())return an(new ft,n);if(this.priority Date: Wed, 25 Sep 2019 17:15:01 +0100 Subject: [PATCH 4/4] bump version in README --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9a2c40403..c1fee12fc 100644 --- a/README.md +++ b/README.md @@ -536,17 +536,17 @@ First, clone this repository and run `npm install && git submodule init && git s In the `dist/web` folder, you should see the files you need: `pusher.js`, `pusher.min.js`, `json2.js`, `json.min.js`, `sockjs.js` and `sockjs.min.js`. `pusher.js` should be built referencing your URLs as the dependency hosts. -First, make sure you expose all files from the `dist` directory. They need to be in a directory with named after the version number. For example, if you're hosting version 5.0.0 under `http://example.com/pusher-js` (and https for SSL), files should be accessible under following URL's: +First, make sure you expose all files from the `dist` directory. They need to be in a directory with named after the version number. For example, if you're hosting version 5.0.2 under `http://example.com/pusher-js` (and https for SSL), files should be accessible under following URL's: - http://example.com/pusher-js/5.0.0/pusher.js - http://example.com/pusher-js/5.0.0/json2.js - http://example.com/pusher-js/5.0.0/sockjs.js + http://example.com/pusher-js/5.0.2/pusher.js + http://example.com/pusher-js/5.0.2/json2.js + http://example.com/pusher-js/5.0.2/sockjs.js Minified files should have `.min` in their names, as in the `dist/web` directory: - http://example.com/pusher-js/5.0.0/pusher.min.js - http://example.com/pusher-js/5.0.0/json2.min.js - http://example.com/pusher-js/5.0.0/sockjs.min.js + http://example.com/pusher-js/5.0.2/pusher.min.js + http://example.com/pusher-js/5.0.2/json2.min.js + http://example.com/pusher-js/5.0.2/sockjs.min.js ## SockJS compatibility