diff --git a/CHANGELOG.md b/CHANGELOG.md index 54409aa98..87392485c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 4.4.0 (2019-02-14) + +[NEW] Callbacks bound to client events on presence channels will be called with an extra argument containing the `user_id` of the message sender + +[NEW] Warn when trying to trigger client-events to a channel that isn't subscribed + ## 4.3.1 (2018-09-03) [FIXED] Honour protocol error codes received after connection succeeds diff --git a/README.md b/README.md index 5acfbd7b8..cf556ff28 100644 --- a/README.md +++ b/README.md @@ -417,6 +417,14 @@ channel.bind('my-event', function () { }, { name: 'Pusher' }); ``` +For client-events on presence channels, bound callbacks will be called with an additional argument. This argument is an object containing the `user_id` of the user who triggered the event + +``` +presenceChannel.bind('client-message', function (data, metadata) { + console.log('received data from', metadata.user_id, ':', data); +}); +``` + Unsubscribe behaviour varies depending on which parameters you provide it with. For example: ```js diff --git a/dist/node/pusher.js b/dist/node/pusher.js index 6060c6d6f..aa105d321 100644 --- a/dist/node/pusher.js +++ b/dist/node/pusher.js @@ -1,5 +1,5 @@ /*! - * Pusher JavaScript Library v4.3.1 + * Pusher JavaScript Library v4.4.0 * https://pusher.com/ * * Copyright 2017, Pusher @@ -119,16 +119,17 @@ module.exports = _this.timelineSender.send(_this.connection.isUsingTLS()); } }); - this.connection.bind('message', function (params) { - var internal = (params.event.indexOf('pusher_internal:') === 0); - if (params.channel) { - var channel = _this.channel(params.channel); + 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(params.event, params.data); + channel.handleEvent(event); } } if (!internal) { - _this.global_emitter.emit(params.event, params.data); + _this.global_emitter.emit(event.event, event.data); } }); this.connection.bind('connecting', function () { @@ -833,7 +834,7 @@ module.exports = "use strict"; var Defaults = { - VERSION: "4.3.1", + VERSION: "4.4.0", PROTOCOL: 7, host: 'ws.pusherapp.com', ws_port: 80, @@ -1079,15 +1080,21 @@ module.exports = this.unbind_global(); return this; }; - Dispatcher.prototype.emit = function (eventName, data) { - var i; - for (i = 0; i < this.global_callbacks.length; i++) { + 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 (i = 0; i < callbacks.length; i++) { - callbacks[i].fn.call(callbacks[i].context || global, data); + for (var i = 0; i < callbacks.length; i++) { + callbacks[i].fn.apply(callbacks[i].context || global, args); } } else if (this.failThrough) { @@ -1793,6 +1800,9 @@ module.exports = }, javascriptQuickStart: { path: "/docs/javascript_quick_start" + }, + triggeringClientEvents: { + path: "/docs/client_api_guide/client_events#trigger-events" } } }; @@ -2320,30 +2330,35 @@ module.exports = /***/ (function(module, exports) { "use strict"; - exports.decodeMessage = function (message) { + exports.decodeMessage = function (messageEvent) { try { - var params = JSON.parse(message.data); - if (typeof params.data === 'string') { + var messageData = JSON.parse(messageEvent.data); + var pusherEventData = messageData.data; + if (typeof pusherEventData === 'string') { try { - params.data = JSON.parse(params.data); - } - catch (e) { - if (!(e instanceof SyntaxError)) { - throw e; - } + 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 params; + return pusherEvent; } catch (e) { - throw { type: 'MessageParseError', error: e, data: message.data }; + throw { type: 'MessageParseError', error: e, data: messageEvent.data }; } }; - exports.encodeMessage = function (message) { - return JSON.stringify(message); + exports.encodeMessage = function (event) { + return JSON.stringify(event); }; - exports.processHandshake = function (message) { - message = exports.decodeMessage(message); + 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"; @@ -2435,12 +2450,12 @@ module.exports = return this.transport.send(data); }; Connection.prototype.send_event = function (name, data, channel) { - var message = { event: name, data: data }; + var event = { event: name, data: data }; if (channel) { - message.channel = channel; + event.channel = channel; } - logger_1["default"].debug('Event sent', message); - return this.send(Protocol.encodeMessage(message)); + logger_1["default"].debug('Event sent', event); + return this.send(Protocol.encodeMessage(event)); }; Connection.prototype.ping = function () { if (this.transport.supportsPing()) { @@ -2456,23 +2471,23 @@ module.exports = Connection.prototype.bindListeners = function () { var _this = this; var listeners = { - message: function (m) { - var message; + message: function (messageEvent) { + var pusherEvent; try { - message = Protocol.decodeMessage(m); + pusherEvent = Protocol.decodeMessage(messageEvent); } catch (e) { _this.emit('error', { type: 'MessageParseError', error: e, - data: m.data + data: messageEvent.data }); } - if (message !== undefined) { - logger_1["default"].debug('Event recd', message); - switch (message.event) { + if (pusherEvent !== undefined) { + logger_1["default"].debug('Event recd', pusherEvent); + switch (pusherEvent.event) { case 'pusher:error': - _this.emit('error', { type: 'PusherError', data: message.data }); + _this.emit('error', { type: 'PusherError', data: pusherEvent.data }); break; case 'pusher:ping': _this.emit("ping"); @@ -2481,7 +2496,7 @@ module.exports = _this.emit("pong"); break; } - _this.emit('message', message); + _this.emit('message', pusherEvent); } }, activity: function () { @@ -2619,18 +2634,26 @@ module.exports = callback(error, authData); }); }; - PresenceChannel.prototype.handleEvent = function (event, data) { - switch (event) { + 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.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } - else { - this.members.onSubscription(data); - this.emit("pusher:subscription_succeeded", this.members); - } + this.handleSubscriptionSucceededEvent(event); break; case "pusher_internal:member_added": var addedMember = this.members.addMember(data); @@ -2642,8 +2665,17 @@ module.exports = this.emit('pusher:member_removed', removedMember); } break; - default: - private_channel_1["default"].prototype.handleEvent.call(this, event, data); + } + }; + 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 () { @@ -2696,6 +2728,7 @@ module.exports = var dispatcher_1 = __webpack_require__(14); var Errors = __webpack_require__(46); var logger_1 = __webpack_require__(16); + var url_store_1 = __webpack_require__(30); var Channel = (function (_super) { __extends(Channel, _super); function Channel(name, pusher) { @@ -2715,27 +2748,35 @@ module.exports = 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, data) { - if (event.indexOf("pusher_internal:") === 0) { - if (event === "pusher_internal:subscription_succeeded") { - this.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } - else { - this.emit("pusher:subscription_succeeded", data); - } - } + 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(event, data); + this.emit("pusher:subscription_succeeded", event.data); } }; Channel.prototype.subscribe = function () { @@ -2747,7 +2788,7 @@ module.exports = this.subscriptionCancelled = false; this.authorize(this.pusher.connection.socket_id, function (error, data) { if (error) { - _this.handleEvent('pusher:subscription_error', data); + _this.emit('pusher:subscription_error', data); } else { _this.pusher.send_event('pusher:subscribe', { @@ -2949,12 +2990,14 @@ module.exports = EncryptedChannel.prototype.trigger = function (event, data) { throw new Errors.UnsupportedFeature('Client events are not currently supported for encrypted channels'); }; - EncryptedChannel.prototype.handleEvent = function (event, data) { - if (event.indexOf("pusher_internal:") === 0 || event.indexOf("pusher:") === 0) { - _super.prototype.handleEvent.call(this, event, data); + 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(event, data); + this.handleEncryptedEvent(eventName, data); }; EncryptedChannel.prototype.handleEncryptedEvent = function (event, data) { var _this = this; diff --git a/dist/react-native/pusher.js b/dist/react-native/pusher.js index e3ee99190..daf6dfb39 100644 --- a/dist/react-native/pusher.js +++ b/dist/react-native/pusher.js @@ -1,5 +1,5 @@ /*! - * Pusher JavaScript Library v4.3.1 + * Pusher JavaScript Library v4.4.0 * https://pusher.com/ * * Copyright 2017, Pusher @@ -119,16 +119,17 @@ module.exports = _this.timelineSender.send(_this.connection.isUsingTLS()); } }); - this.connection.bind('message', function (params) { - var internal = (params.event.indexOf('pusher_internal:') === 0); - if (params.channel) { - var channel = _this.channel(params.channel); + 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(params.event, params.data); + channel.handleEvent(event); } } if (!internal) { - _this.global_emitter.emit(params.event, params.data); + _this.global_emitter.emit(event.event, event.data); } }); this.connection.bind('connecting', function () { @@ -831,7 +832,7 @@ module.exports = "use strict"; var Defaults = { - VERSION: "4.3.1", + VERSION: "4.4.0", PROTOCOL: 7, host: 'ws.pusherapp.com', ws_port: 80, @@ -1077,15 +1078,21 @@ module.exports = this.unbind_global(); return this; }; - Dispatcher.prototype.emit = function (eventName, data) { - var i; - for (i = 0; i < this.global_callbacks.length; i++) { + 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 (i = 0; i < callbacks.length; i++) { - callbacks[i].fn.call(callbacks[i].context || global, data); + for (var i = 0; i < callbacks.length; i++) { + callbacks[i].fn.apply(callbacks[i].context || global, args); } } else if (this.failThrough) { @@ -1806,6 +1813,9 @@ module.exports = }, javascriptQuickStart: { path: "/docs/javascript_quick_start" + }, + triggeringClientEvents: { + path: "/docs/client_api_guide/client_events#trigger-events" } } }; @@ -2333,30 +2343,35 @@ module.exports = /***/ (function(module, exports) { "use strict"; - exports.decodeMessage = function (message) { + exports.decodeMessage = function (messageEvent) { try { - var params = JSON.parse(message.data); - if (typeof params.data === 'string') { + var messageData = JSON.parse(messageEvent.data); + var pusherEventData = messageData.data; + if (typeof pusherEventData === 'string') { try { - params.data = JSON.parse(params.data); - } - catch (e) { - if (!(e instanceof SyntaxError)) { - throw e; - } + 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 params; + return pusherEvent; } catch (e) { - throw { type: 'MessageParseError', error: e, data: message.data }; + throw { type: 'MessageParseError', error: e, data: messageEvent.data }; } }; - exports.encodeMessage = function (message) { - return JSON.stringify(message); + exports.encodeMessage = function (event) { + return JSON.stringify(event); }; - exports.processHandshake = function (message) { - message = exports.decodeMessage(message); + 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"; @@ -2448,12 +2463,12 @@ module.exports = return this.transport.send(data); }; Connection.prototype.send_event = function (name, data, channel) { - var message = { event: name, data: data }; + var event = { event: name, data: data }; if (channel) { - message.channel = channel; + event.channel = channel; } - logger_1["default"].debug('Event sent', message); - return this.send(Protocol.encodeMessage(message)); + logger_1["default"].debug('Event sent', event); + return this.send(Protocol.encodeMessage(event)); }; Connection.prototype.ping = function () { if (this.transport.supportsPing()) { @@ -2469,23 +2484,23 @@ module.exports = Connection.prototype.bindListeners = function () { var _this = this; var listeners = { - message: function (m) { - var message; + message: function (messageEvent) { + var pusherEvent; try { - message = Protocol.decodeMessage(m); + pusherEvent = Protocol.decodeMessage(messageEvent); } catch (e) { _this.emit('error', { type: 'MessageParseError', error: e, - data: m.data + data: messageEvent.data }); } - if (message !== undefined) { - logger_1["default"].debug('Event recd', message); - switch (message.event) { + if (pusherEvent !== undefined) { + logger_1["default"].debug('Event recd', pusherEvent); + switch (pusherEvent.event) { case 'pusher:error': - _this.emit('error', { type: 'PusherError', data: message.data }); + _this.emit('error', { type: 'PusherError', data: pusherEvent.data }); break; case 'pusher:ping': _this.emit("ping"); @@ -2494,7 +2509,7 @@ module.exports = _this.emit("pong"); break; } - _this.emit('message', message); + _this.emit('message', pusherEvent); } }, activity: function () { @@ -2632,18 +2647,26 @@ module.exports = callback(error, authData); }); }; - PresenceChannel.prototype.handleEvent = function (event, data) { - switch (event) { + 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.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } - else { - this.members.onSubscription(data); - this.emit("pusher:subscription_succeeded", this.members); - } + this.handleSubscriptionSucceededEvent(event); break; case "pusher_internal:member_added": var addedMember = this.members.addMember(data); @@ -2655,8 +2678,17 @@ module.exports = this.emit('pusher:member_removed', removedMember); } break; - default: - private_channel_1["default"].prototype.handleEvent.call(this, event, data); + } + }; + 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 () { @@ -2709,6 +2741,7 @@ module.exports = var dispatcher_1 = __webpack_require__(14); var Errors = __webpack_require__(45); var logger_1 = __webpack_require__(16); + var url_store_1 = __webpack_require__(29); var Channel = (function (_super) { __extends(Channel, _super); function Channel(name, pusher) { @@ -2728,27 +2761,35 @@ module.exports = 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, data) { - if (event.indexOf("pusher_internal:") === 0) { - if (event === "pusher_internal:subscription_succeeded") { - this.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } - else { - this.emit("pusher:subscription_succeeded", data); - } - } + 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(event, data); + this.emit("pusher:subscription_succeeded", event.data); } }; Channel.prototype.subscribe = function () { @@ -2760,7 +2801,7 @@ module.exports = this.subscriptionCancelled = false; this.authorize(this.pusher.connection.socket_id, function (error, data) { if (error) { - _this.handleEvent('pusher:subscription_error', data); + _this.emit('pusher:subscription_error', data); } else { _this.pusher.send_event('pusher:subscribe', { @@ -2962,12 +3003,14 @@ module.exports = EncryptedChannel.prototype.trigger = function (event, data) { throw new Errors.UnsupportedFeature('Client events are not currently supported for encrypted channels'); }; - EncryptedChannel.prototype.handleEvent = function (event, data) { - if (event.indexOf("pusher_internal:") === 0 || event.indexOf("pusher:") === 0) { - _super.prototype.handleEvent.call(this, event, data); + 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(event, data); + this.handleEncryptedEvent(eventName, data); }; EncryptedChannel.prototype.handleEncryptedEvent = function (event, data) { var _this = this; diff --git a/dist/web/pusher.js b/dist/web/pusher.js index fd2d23208..5d47faf51 100644 --- a/dist/web/pusher.js +++ b/dist/web/pusher.js @@ -1,5 +1,5 @@ /*! - * Pusher JavaScript Library v4.3.1 + * Pusher JavaScript Library v4.4.0 * https://pusher.com/ * * Copyright 2017, Pusher @@ -128,16 +128,17 @@ return /******/ (function(modules) { // webpackBootstrap _this.timelineSender.send(_this.connection.isUsingTLS()); } }); - this.connection.bind('message', function (params) { - var internal = (params.event.indexOf('pusher_internal:') === 0); - if (params.channel) { - var channel = _this.channel(params.channel); + 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(params.event, params.data); + channel.handleEvent(event); } } if (!internal) { - _this.global_emitter.emit(params.event, params.data); + _this.global_emitter.emit(event.event, event.data); } }); this.connection.bind('connecting', function () { @@ -479,7 +480,7 @@ return /******/ (function(modules) { // webpackBootstrap "use strict"; var Defaults = { - VERSION: "4.3.1", + VERSION: "4.4.0", PROTOCOL: 7, host: 'ws.pusherapp.com', ws_port: 80, @@ -1029,6 +1030,9 @@ return /******/ (function(modules) { // webpackBootstrap }, javascriptQuickStart: { path: "/docs/javascript_quick_start" + }, + triggeringClientEvents: { + path: "/docs/client_api_guide/client_events#trigger-events" } } }; @@ -1585,15 +1589,21 @@ return /******/ (function(modules) { // webpackBootstrap this.unbind_global(); return this; }; - Dispatcher.prototype.emit = function (eventName, data) { - var i; - for (i = 0; i < this.global_callbacks.length; i++) { + 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 (i = 0; i < callbacks.length; i++) { - callbacks[i].fn.call(callbacks[i].context || (window), data); + for (var i = 0; i < callbacks.length; i++) { + callbacks[i].fn.apply(callbacks[i].context || (window), args); } } else if (this.failThrough) { @@ -2820,30 +2830,35 @@ return /******/ (function(modules) { // webpackBootstrap /***/ (function(module, exports) { "use strict"; - exports.decodeMessage = function (message) { + exports.decodeMessage = function (messageEvent) { try { - var params = JSON.parse(message.data); - if (typeof params.data === 'string') { + var messageData = JSON.parse(messageEvent.data); + var pusherEventData = messageData.data; + if (typeof pusherEventData === 'string') { try { - params.data = JSON.parse(params.data); - } - catch (e) { - if (!(e instanceof SyntaxError)) { - throw e; - } + 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 params; + return pusherEvent; } catch (e) { - throw { type: 'MessageParseError', error: e, data: message.data }; + throw { type: 'MessageParseError', error: e, data: messageEvent.data }; } }; - exports.encodeMessage = function (message) { - return JSON.stringify(message); + exports.encodeMessage = function (event) { + return JSON.stringify(event); }; - exports.processHandshake = function (message) { - message = exports.decodeMessage(message); + 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"; @@ -2935,12 +2950,12 @@ return /******/ (function(modules) { // webpackBootstrap return this.transport.send(data); }; Connection.prototype.send_event = function (name, data, channel) { - var message = { event: name, data: data }; + var event = { event: name, data: data }; if (channel) { - message.channel = channel; + event.channel = channel; } - logger_1["default"].debug('Event sent', message); - return this.send(Protocol.encodeMessage(message)); + logger_1["default"].debug('Event sent', event); + return this.send(Protocol.encodeMessage(event)); }; Connection.prototype.ping = function () { if (this.transport.supportsPing()) { @@ -2956,23 +2971,23 @@ return /******/ (function(modules) { // webpackBootstrap Connection.prototype.bindListeners = function () { var _this = this; var listeners = { - message: function (m) { - var message; + message: function (messageEvent) { + var pusherEvent; try { - message = Protocol.decodeMessage(m); + pusherEvent = Protocol.decodeMessage(messageEvent); } catch (e) { _this.emit('error', { type: 'MessageParseError', error: e, - data: m.data + data: messageEvent.data }); } - if (message !== undefined) { - logger_1["default"].debug('Event recd', message); - switch (message.event) { + if (pusherEvent !== undefined) { + logger_1["default"].debug('Event recd', pusherEvent); + switch (pusherEvent.event) { case 'pusher:error': - _this.emit('error', { type: 'PusherError', data: message.data }); + _this.emit('error', { type: 'PusherError', data: pusherEvent.data }); break; case 'pusher:ping': _this.emit("ping"); @@ -2981,7 +2996,7 @@ return /******/ (function(modules) { // webpackBootstrap _this.emit("pong"); break; } - _this.emit('message', message); + _this.emit('message', pusherEvent); } }, activity: function () { @@ -3119,18 +3134,26 @@ return /******/ (function(modules) { // webpackBootstrap callback(error, authData); }); }; - PresenceChannel.prototype.handleEvent = function (event, data) { - switch (event) { + 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.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } - else { - this.members.onSubscription(data); - this.emit("pusher:subscription_succeeded", this.members); - } + this.handleSubscriptionSucceededEvent(event); break; case "pusher_internal:member_added": var addedMember = this.members.addMember(data); @@ -3142,8 +3165,17 @@ return /******/ (function(modules) { // webpackBootstrap this.emit('pusher:member_removed', removedMember); } break; - default: - private_channel_1["default"].prototype.handleEvent.call(this, event, data); + } + }; + 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 () { @@ -3196,6 +3228,7 @@ return /******/ (function(modules) { // webpackBootstrap var dispatcher_1 = __webpack_require__(24); var Errors = __webpack_require__(31); var logger_1 = __webpack_require__(8); + var url_store_1 = __webpack_require__(14); var Channel = (function (_super) { __extends(Channel, _super); function Channel(name, pusher) { @@ -3215,27 +3248,35 @@ return /******/ (function(modules) { // webpackBootstrap 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, data) { - if (event.indexOf("pusher_internal:") === 0) { - if (event === "pusher_internal:subscription_succeeded") { - this.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } - else { - this.emit("pusher:subscription_succeeded", data); - } - } + 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(event, data); + this.emit("pusher:subscription_succeeded", event.data); } }; Channel.prototype.subscribe = function () { @@ -3247,7 +3288,7 @@ return /******/ (function(modules) { // webpackBootstrap this.subscriptionCancelled = false; this.authorize(this.pusher.connection.socket_id, function (error, data) { if (error) { - _this.handleEvent('pusher:subscription_error', data); + _this.emit('pusher:subscription_error', data); } else { _this.pusher.send_event('pusher:subscribe', { @@ -3381,12 +3422,14 @@ return /******/ (function(modules) { // webpackBootstrap EncryptedChannel.prototype.trigger = function (event, data) { throw new Errors.UnsupportedFeature('Client events are not currently supported for encrypted channels'); }; - EncryptedChannel.prototype.handleEvent = function (event, data) { - if (event.indexOf("pusher_internal:") === 0 || event.indexOf("pusher:") === 0) { - _super.prototype.handleEvent.call(this, event, data); + 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(event, data); + this.handleEncryptedEvent(eventName, data); }; EncryptedChannel.prototype.handleEncryptedEvent = function (event, data) { var _this = this; diff --git a/dist/web/pusher.min.js b/dist/web/pusher.min.js index 2319e93a5..fa48c87e5 100644 --- a/dist/web/pusher.min.js +++ b/dist/web/pusher.min.js @@ -1,13 +1,13 @@ /*! - * Pusher JavaScript Library v4.3.1 + * Pusher JavaScript Library v4.4.0 * 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()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";var r=n(1);t.exports=r.default},function(t,e,n){"use strict";function r(t){if(null===t||void 0===t)throw"You must pass your app key when you instantiate Pusher."}var i=n(2),o=n(9),s=n(24),a=n(39),u=n(40),c=n(41),h=n(12),f=n(5),l=n(71),p=n(8),d=n(43),y=n(14),g=function(){function t(e,n){var h=this;if(r(e),n=n||{},!n.cluster&&!n.wsHost&&!n.httpHost){var g=y.default.buildLogSuffix("javascriptQuickStart");p.default.warn("You should always specify a cluster when connecting. "+g)}this.key=e,this.config=o.extend(l.getGlobalConfig(),n.cluster?l.getClusterConfig(n.cluster):{},n),this.channels=d.default.createChannels(),this.global_emitter=new s.default,this.sessionID=Math.floor(1e9*Math.random()),this.timeline=new a.default(this.key,this.sessionID,{cluster:this.config.cluster,features:t.getClientFeatures(),params:this.config.timelineParams||{},limit:50,level:u.default.INFO,version:f.default.VERSION}),this.config.disableStats||(this.timelineSender=d.default.createTimelineSender(this.timeline,{host:this.config.statsHost,path:"/timeline/v2/"+i.default.TimelineTransport.name}));var v=function(t){var e=o.extend({},h.config,t);return c.build(i.default.getDefaultStrategy(e),e)};this.connection=d.default.createConnectionManager(this.key,o.extend({getStrategy:v,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(){h.subscribeAll(),h.timelineSender&&h.timelineSender.send(h.connection.isUsingTLS())}),this.connection.bind("message",function(t){var e=0===t.event.indexOf("pusher_internal:");if(t.channel){var n=h.channel(t.channel);n&&n.handleEvent(t.event,t.data)}e||h.global_emitter.emit(t.event,t.data)}),this.connection.bind("connecting",function(){h.channels.disconnect()}),this.connection.bind("disconnected",function(){h.channels.disconnect()}),this.connection.bind("error",function(t){p.default.warn("Error",t)}),t.instances.push(this),this.timeline.info({instances:t.instances.length}),t.isReady&&this.connect()}return t.ready=function(){t.isReady=!0;for(var e=0,n=t.instances.length;e0)r.loading[t].push(n);else{r.loading[t]=[n];var o=i.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 i=function(t){t||o.cleanup()},a=0;a>>6)+i(128|63&e):i(224|e>>>12&15)+i(128|e>>>6&63)+i(128|63&e)},h=function(t){return t.replace(/[^\x00-\x7F]/g,c)},f=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),r=[o.charAt(n>>>18),o.charAt(n>>>12&63),e>=2?"=":o.charAt(n>>>6&63),e>=1?"=":o.charAt(63&n)];return r.join("")},l=window.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,f)}},function(t,e,n){"use strict";var r=n(12),i={now:function(){return Date.now?Date.now():(new Date).valueOf()},defer:function(t){return new r.OneOffTimer(0,t)},method:function(t){for(var e=[],n=1;n0)for(n=0;n0&&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.__esModule=!0,e.default=i},function(t,e){"use strict";var n=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},r=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.BadEventName=r;var i=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.RequestTimedOut=i;var o=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.TransportPriorityTooLow=o;var s=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.TransportClosed=s;var a=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.UnsupportedFeature=a;var u=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.UnsupportedTransport=u;var c=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.UnsupportedStrategy=c},function(t,e,n){"use strict";var r=n(33),i=n(34),o=n(36),s=n(37),a=n(38),u={createStreamingSocket:function(t){return this.createSocket(o.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 r.default(t,e,n)}};e.__esModule=!0,e.default=u},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(2),o=n(24),s=262144,a=function(t){function e(e,n,r){t.call(this),this.hooks=e,this.method=n,this.url=r}return r(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 n!==-1?(this.position+=n+1,e.slice(0,n)):null},e.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>s},e}(o.default);e.__esModule=!0,e.default=a},function(t,e,n){"use strict";function r(t){var e=/([^\?]*)\/*(\??.*)/.exec(t);return{ -base:e[1],queryString:e[2]}}function i(t,e){return t.base+"/"+e+"/xhr_send"}function o(t){var e=t.indexOf("?")===-1?"?":"&";return t+e+"t="+ +new Date+"&n="+l++}function s(t,e){var n=/(https?:\/\/)([^\/:]+)((\/|:)?.*)/.exec(t);return n[1]+e+n[3]}function a(t){return Math.floor(Math.random()*t)}function u(t){for(var e=[],n=0;n0&&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()}};e.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=n(9),i=n(11),o=n(40),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:i.default.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(o.default.ERROR,t)},t.prototype.info=function(t){this.log(o.default.INFO,t)},t.prototype.debug=function(t){this.log(o.default.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,i=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(i,function(t,r){t||n.sent++,e&&e(t,r)}),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}();e.__esModule=!0,e.default=s},function(t,e){"use strict";var n;!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(n||(n={})),e.__esModule=!0,e.default=n},function(t,e,n){"use strict";function r(t){return function(e){return[t.apply(this,arguments),e]}}function i(t){return"string"==typeof t&&":"===t.charAt(0)}function o(t,e){return e[t.slice(1)]}function s(t,e){if(0===t.length)return[[],e];var n=c(t[0],e),r=s(t.slice(1),n[1]);return[[n[0]].concat(r[0]),r[1]]}function a(t,e){if(!i(t))return[t,e];var n=o(t,e);if(void 0===n)throw"Undefined symbol "+t;return[n,e]}function u(t,e){if(i(t[0])){var n=o(t[0],e);if(t.length>1){if("function"!=typeof n)throw"Calling non-function "+t[0];var r=[h.extend({},e)].concat(h.map(t.slice(1),function(t){return c(t,h.extend({},e))[0]}));return n.apply(this,r)}return[n,e]}return s(t,e)}function c(t,e){return"string"==typeof t?a(t,e):"object"==typeof t&&t instanceof Array&&t.length>0?u(t,e):[t,e]}var h=n(9),f=n(11),l=n(42),p=n(31),d=n(64),y=n(65),g=n(66),v=n(67),b=n(68),m=n(69),w=n(70),_=n(2),S=_.default.Transports;e.build=function(t,e){var n=h.extend({},T,e);return c(t,n)[1].strategy};var k={isSupported:function(){return!1},connect:function(t,e){var n=f.default.defer(function(){e(new p.UnsupportedStrategy)});return{abort:function(){n.ensureAborted()},forceMinPriority:function(){}}}},T={extend:function(t,e,n){return[h.extend({},e,n),t]},def:function(t,e,n){if(void 0!==t[e])throw"Redefining symbol "+e;return t[e]=n,[void 0,t]},def_transport:function(t,e,n,r,i,o){var s=S[n];if(!s)throw new p.UnsupportedTransport(n);var a,u=!(t.enabledTransports&&h.arrayIndexOf(t.enabledTransports,e)===-1||t.disabledTransports&&h.arrayIndexOf(t.disabledTransports,e)!==-1);a=u?new d.default(e,r,o?o.getAssistant(s):s,h.extend({key:t.key,useTLS:t.useTLS,timeline:t.timeline,ignoreNullOrigin:t.ignoreNullOrigin},i)):k;var c=t.def(t,e,a)[1];return c.Transports=t.Transports||{},c.Transports[e]=a,[void 0,c]},transport_manager:r(function(t,e){return new l.default(e)}),sequential:r(function(t,e){var n=Array.prototype.slice.call(arguments,2);return new y.default(n,e)}),cached:r(function(t,e,n){return new v.default(n,t.Transports,{ttl:e,timeline:t.timeline,useTLS:t.useTLS})}),first_connected:r(function(t,e){return new w.default(e)}),best_connected_ever:r(function(){var t=Array.prototype.slice.call(arguments,1);return new g.default(t)}),delayed:r(function(t,e,n){return new b.default(n,{delay:e})}),if:r(function(t,e,n,r){return new m.default(e,n,r)}),is_supported:r(function(t,e){return function(){return e.isSupported()}})}},function(t,e,n){"use strict";var r=n(43),i=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.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=n(44),i=n(45),o=n(48),s=n(49),a=n(50),u=n(51),c=n(54),h=n(52),f=n(62),l=n(63),p={createChannels:function(){return new l.default},createConnectionManager:function(t,e){return new f.default(t,e)},createChannel:function(t,e){return new h.default(t,e)},createPrivateChannel:function(t,e){return new u.default(t,e)},createPresenceChannel:function(t,e){return new a.default(t,e)},createEncryptedChannel:function(t,e){return new c.default(t,e)},createTimelineSender:function(t,e){return new s.default(t,e)},createAuthorizer:function(t,e){return e.authorizer?e.authorizer(t,e):new o.default(t,e)},createHandshake:function(t,e){return new i.default(t,e)},createAssistantToTheTransportManager:function(t,e,n){return new r.default(t,e,n)}};e.__esModule=!0,e.default=p},function(t,e,n){"use strict";var r=n(11),i=n(9),o=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,o){var s=this;o=i.extend({},o,{activityTimeout:this.pingDelay});var a=this.transport.createConnection(t,e,n,o),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.__esModule=!0,e.default=o},function(t,e,n){"use strict";var r=n(9),i=n(46),o=n(47),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){t.unbindListeners();var n;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 o.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",r=i.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.__esModule=!0,e.default=s},function(t,e){"use strict";e.decodeMessage=function(t){try{var e=JSON.parse(t.data);if("string"==typeof e.data)try{e.data=JSON.parse(e.data)}catch(t){if(!(t instanceof SyntaxError))throw t}return e}catch(e){throw{type:"MessageParseError",error:e,data:t.data}}},e.encodeMessage=function(t){return JSON.stringify(t)},e.processHandshake=function(t){if(t=e.decodeMessage(t),"pusher:connection_established"===t.event){if(!t.data.activity_timeout)throw"No activity timeout specified in handshake";return{action:"connected",id:t.data.socket_id,activityTimeout:1e3*t.data.activity_timeout}}if("pusher:error"===t.event)return{action:this.getCloseAction(t.data),error:this.getCloseError(t.data)};throw"Invalid handshake"},e.getCloseAction=function(t){return t.code<4e3?t.code>=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=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(9),o=n(24),s=n(46),a=n(8),u=function(t){function e(e,n){t.call(this),this.id=e,this.transport=n,this.activityTimeout=n.activityTimeout,this.bindListeners()}return r(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),a.default.debug("Event sent",r),this.send(s.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=s.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(a.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=s.getCloseAction(t),n=s.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(o.default);e.__esModule=!0,e.default=u},function(t,e,n){"use strict";var r=n(2),i=function(){function t(t,e){this.channel=t;var n=e.authTransport;if("undefined"==typeof 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.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=n(2),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(r.default.TimelineTransport.getAgent(this,t),e)},t}();e.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(51),o=n(8),s=n(53),a=n(14),u=function(t){function e(e,n){t.call(this,e,n),this.members=new s.default}return r(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 i=a.default.buildLogSuffix("authenticationEndpoint");return o.default.warn("Invalid auth response for channel '"+r.name+"',expected 'channel_data' field. "+i),void n("Invalid auth response")}var s=JSON.parse(e.channel_data);r.members.setMyID(s.user_id)}n(t,e)})},e.prototype.handleEvent=function(t,e){switch(t){case"pusher_internal:subscription_succeeded":this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(e),this.emit("pusher:subscription_succeeded",this.members));break;case"pusher_internal:member_added":var n=this.members.addMember(e);this.emit("pusher:member_added",n);break;case"pusher_internal:member_removed":var r=this.members.removeMember(e);r&&this.emit("pusher:member_removed",r);break;default:i.default.prototype.handleEvent.call(this,t,e)}},e.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},e}(i.default);e.__esModule=!0,e.default=u},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(43),o=n(52),s=function(t){function e(){t.apply(this,arguments)}return r(e,t),e.prototype.authorize=function(t,e){var n=i.default.createAuthorizer(this,this.pusher.config);return n.authorize(t,e)},e}(o.default);e.__esModule=!0,e.default=s},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(24),o=n(31),s=n(8),a=function(t){function e(e,n){t.call(this,function(t,n){s.default.debug("No callbacks on "+e+" for "+t)}),this.name=e,this.pusher=n,this.subscribed=!1,this.subscriptionPending=!1,this.subscriptionCancelled=!1}return r(e,t),e.prototype.authorize=function(t,e){return e(!1,{})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new o.BadEventName("Event '"+t+"' does not start with 'client-'");return this.pusher.send_event(t,e,this.name)},e.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},e.prototype.handleEvent=function(t,e){0===t.indexOf("pusher_internal:")?"pusher_internal:subscription_succeeded"===t&&(this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",e)):this.emit(t,e)},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.handleEvent("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.__esModule=!0,e.default=a},function(t,e,n){"use strict";var r=n(9),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;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.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(51),o=n(31),s=n(8),a=n(55),u=n(57),c=function(t){function e(){t.apply(this,arguments),this.key=null}return r(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,function(t,e){if(t)return void n(!0,e);var i=e.shared_secret;if(!i){var o="No shared_secret key in auth payload for encrypted channel: "+r.name;return n(!0,o),void s.default.warn("Error: "+o)}r.key=u.decodeBase64(i),delete e.shared_secret,n(!1,e)})},e.prototype.trigger=function(t,e){throw new o.UnsupportedFeature("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e,n){return 0===e.indexOf("pusher_internal:")||0===e.indexOf("pusher:")?void t.prototype.handleEvent.call(this,e,n):void this.handleEncryptedEvent(e,n)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(!this.key)return void s.default.debug("Received encrypted event before key has been retrieved from the authEndpoint");if(!e.ciphertext||!e.nonce)return void s.default.warn("Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: "+e);var r=u.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 r(t,e,n,r,i){var o,s=0;for(o=0;o>>8)-1}function i(t,e,n,i){return r(t,e,n,i,16)}function o(t,e,n,i){return r(t,e,n,i,32)}function s(t,e,n,r){for(var i,o=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,g=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,v=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,_=o,S=s,k=a,T=u,A=c,E=h,x=f,C=l,P=p,R=d,O=y,M=g,U=v,L=b,B=m,I=w,N=0;N<20;N+=2)i=_+U|0,A^=i<<7|i>>>25,i=A+_|0,P^=i<<9|i>>>23,i=P+A|0,U^=i<<13|i>>>19,i=U+P|0,_^=i<<18|i>>>14,i=E+S|0,R^=i<<7|i>>>25,i=R+E|0,L^=i<<9|i>>>23,i=L+R|0,S^=i<<13|i>>>19,i=S+L|0,E^=i<<18|i>>>14,i=O+x|0,B^=i<<7|i>>>25,i=B+O|0,k^=i<<9|i>>>23,i=k+B|0,x^=i<<13|i>>>19,i=x+k|0,O^=i<<18|i>>>14,i=I+M|0,T^=i<<7|i>>>25,i=T+I|0,C^=i<<9|i>>>23,i=C+T|0,M^=i<<13|i>>>19,i=M+C|0,I^=i<<18|i>>>14,i=_+T|0,S^=i<<7|i>>>25,i=S+_|0,k^=i<<9|i>>>23,i=k+S|0,T^=i<<13|i>>>19,i=T+k|0,_^=i<<18|i>>>14,i=E+A|0,x^=i<<7|i>>>25,i=x+E|0,C^=i<<9|i>>>23,i=C+x|0,A^=i<<13|i>>>19,i=A+C|0,E^=i<<18|i>>>14,i=O+R|0,M^=i<<7|i>>>25,i=M+O|0,P^=i<<9|i>>>23,i=P+M|0,R^=i<<13|i>>>19,i=R+P|0,O^=i<<18|i>>>14,i=I+B|0,U^=i<<7|i>>>25,i=U+I|0,L^=i<<9|i>>>23,i=L+U|0,B^=i<<13|i>>>19,i=B+L|0,I^=i<<18|i>>>14;_=_+o|0,S=S+s|0,k=k+a|0,T=T+u|0,A=A+c|0,E=E+h|0,x=x+f|0,C=C+l|0,P=P+p|0,R=R+d|0,O=O+y|0,M=M+g|0,U=U+v|0,L=L+b|0,B=B+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]=A>>>0&255,t[17]=A>>>8&255,t[18]=A>>>16&255,t[19]=A>>>24&255,t[20]=E>>>0&255,t[21]=E>>>8&255,t[22]=E>>>16&255,t[23]=E>>>24&255,t[24]=x>>>0&255,t[25]=x>>>8&255,t[26]=x>>>16&255,t[27]=x>>>24&255,t[28]=C>>>0&255,t[29]=C>>>8&255,t[30]=C>>>16&255,t[31]=C>>>24&255,t[32]=P>>>0&255,t[33]=P>>>8&255,t[34]=P>>>16&255,t[35]=P>>>24&255,t[36]=R>>>0&255,t[37]=R>>>8&255,t[38]=R>>>16&255,t[39]=R>>>24&255,t[40]=O>>>0&255,t[41]=O>>>8&255,t[42]=O>>>16&255,t[43]=O>>>24&255,t[44]=M>>>0&255,t[45]=M>>>8&255,t[46]=M>>>16&255,t[47]=M>>>24&255,t[48]=U>>>0&255,t[49]=U>>>8&255,t[50]=U>>>16&255,t[51]=U>>>24&255,t[52]=L>>>0&255,t[53]=L>>>8&255,t[54]=L>>>16&255,t[55]=L>>>24&255,t[56]=B>>>0&255,t[57]=B>>>8&255,t[58]=B>>>16&255,t[59]=B>>>24&255,t[60]=I>>>0&255,t[61]=I>>>8&255,t[62]=I>>>16&255,t[63]=I>>>24&255}function a(t,e,n,r){for(var i,o=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,g=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,v=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,_=o,S=s,k=a,T=u,A=c,E=h,x=f,C=l,P=p,R=d,O=y,M=g,U=v,L=b,B=m,I=w,N=0;N<20;N+=2)i=_+U|0,A^=i<<7|i>>>25,i=A+_|0,P^=i<<9|i>>>23,i=P+A|0,U^=i<<13|i>>>19,i=U+P|0,_^=i<<18|i>>>14,i=E+S|0,R^=i<<7|i>>>25,i=R+E|0,L^=i<<9|i>>>23,i=L+R|0,S^=i<<13|i>>>19,i=S+L|0,E^=i<<18|i>>>14,i=O+x|0,B^=i<<7|i>>>25,i=B+O|0,k^=i<<9|i>>>23,i=k+B|0,x^=i<<13|i>>>19,i=x+k|0,O^=i<<18|i>>>14,i=I+M|0,T^=i<<7|i>>>25,i=T+I|0,C^=i<<9|i>>>23,i=C+T|0,M^=i<<13|i>>>19,i=M+C|0,I^=i<<18|i>>>14,i=_+T|0,S^=i<<7|i>>>25,i=S+_|0,k^=i<<9|i>>>23,i=k+S|0,T^=i<<13|i>>>19,i=T+k|0,_^=i<<18|i>>>14,i=E+A|0,x^=i<<7|i>>>25,i=x+E|0,C^=i<<9|i>>>23,i=C+x|0,A^=i<<13|i>>>19,i=A+C|0,E^=i<<18|i>>>14,i=O+R|0,M^=i<<7|i>>>25,i=M+O|0,P^=i<<9|i>>>23,i=P+M|0,R^=i<<13|i>>>19,i=R+P|0,O^=i<<18|i>>>14,i=I+B|0,U^=i<<7|i>>>25,i=U+I|0,L^=i<<9|i>>>23,i=L+U|0,B^=i<<13|i>>>19,i=B+L|0,I^=i<<18|i>>>14;t[0]=_>>>0&255,t[1]=_>>>8&255,t[2]=_>>>16&255,t[3]=_>>>24&255,t[4]=E>>>0&255,t[5]=E>>>8&255,t[6]=E>>>16&255,t[7]=E>>>24&255,t[8]=O>>>0&255,t[9]=O>>>8&255,t[10]=O>>>16&255,t[11]=O>>>24&255,t[12]=I>>>0&255,t[13]=I>>>8&255,t[14]=I>>>16&255,t[15]=I>>>24&255,t[16]=x>>>0&255,t[17]=x>>>8&255,t[18]=x>>>16&255,t[19]=x>>>24&255,t[20]=C>>>0&255,t[21]=C>>>8&255,t[22]=C>>>16&255,t[23]=C>>>24&255,t[24]=P>>>0&255,t[25]=P>>>8&255,t[26]=P>>>16&255,t[27]=P>>>24&255,t[28]=R>>>0&255,t[29]=R>>>8&255,t[30]=R>>>16&255,t[31]=R>>>24&255}function u(t,e,n,r){s(t,e,n,r)}function c(t,e,n,r){a(t,e,n,r)}function h(t,e,n,r,i,o,s){var a,c,h=new Uint8Array(16),f=new Uint8Array(64);for(c=0;c<16;c++)h[c]=0;for(c=0;c<8;c++)h[c]=o[c];for(;i>=64;){for(u(f,h,s,lt),c=0;c<64;c++)t[e+c]=n[r+c]^f[c];for(a=1,c=8;c<16;c++)a=a+(255&h[c])|0,h[c]=255&a,a>>>=8;i-=64,e+=64,r+=64}if(i>0)for(u(f,h,s,lt),c=0;c=64;){for(u(c,a,i,lt),s=0;s<64;s++)t[e+s]=c[s];for(o=1,s=8;s<16;s++)o=o+(255&a[s])|0,a[s]=255&o,o>>>=8;n-=64,e+=64}if(n>0)for(u(c,a,i,lt),s=0;s>16&1),o[n-1]&=65535;o[15]=s[15]-32767-(o[14]>>16&1),i=o[15]>>16&1,o[14]&=65535,w(s,o,1-i)}for(n=0;n<16;n++)t[2*n]=255&s[n],t[2*n+1]=s[n]>>8}function S(t,e){var n=new Uint8Array(32),r=new Uint8Array(32);return _(n,t),_(r,e),o(n,0,r,0)}function k(t){var e=new Uint8Array(32);return _(e,t),1&e[0]}function T(t,e){var n;for(n=0;n<16;n++)t[n]=e[2*n]+(e[2*n+1]<<8);t[15]&=32767}function A(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]+n[r]}function E(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]-n[r]}function x(t,e,n){var r,i,o=0,s=0,a=0,u=0,c=0,h=0,f=0,l=0,p=0,d=0,y=0,g=0,v=0,b=0,m=0,w=0,_=0,S=0,k=0,T=0,A=0,E=0,x=0,C=0,P=0,R=0,O=0,M=0,U=0,L=0,B=0,I=n[0],N=n[1],D=n[2],j=n[3],Y=n[4],z=n[5],H=n[6],q=n[7],F=n[8],J=n[9],X=n[10],K=n[11],G=n[12],W=n[13],V=n[14],Z=n[15];r=e[0],o+=r*I,s+=r*N,a+=r*D,u+=r*j,c+=r*Y,h+=r*z,f+=r*H,l+=r*q,p+=r*F,d+=r*J,y+=r*X,g+=r*K,v+=r*G,b+=r*W,m+=r*V,w+=r*Z,r=e[1],s+=r*I,a+=r*N,u+=r*D,c+=r*j,h+=r*Y,f+=r*z,l+=r*H,p+=r*q,d+=r*F,y+=r*J,g+=r*X,v+=r*K,b+=r*G,m+=r*W,w+=r*V,_+=r*Z,r=e[2],a+=r*I,u+=r*N,c+=r*D,h+=r*j,f+=r*Y,l+=r*z,p+=r*H,d+=r*q,y+=r*F,g+=r*J,v+=r*X,b+=r*K,m+=r*G,w+=r*W,_+=r*V,S+=r*Z,r=e[3],u+=r*I,c+=r*N,h+=r*D,f+=r*j,l+=r*Y,p+=r*z,d+=r*H,y+=r*q,g+=r*F,v+=r*J,b+=r*X,m+=r*K,w+=r*G,_+=r*W,S+=r*V,k+=r*Z,r=e[4],c+=r*I,h+=r*N,f+=r*D,l+=r*j,p+=r*Y,d+=r*z,y+=r*H,g+=r*q,v+=r*F,b+=r*J,m+=r*X,w+=r*K,_+=r*G,S+=r*W,k+=r*V,T+=r*Z,r=e[5],h+=r*I,f+=r*N,l+=r*D,p+=r*j,d+=r*Y,y+=r*z,g+=r*H,v+=r*q,b+=r*F,m+=r*J,w+=r*X,_+=r*K,S+=r*G,k+=r*W,T+=r*V,A+=r*Z,r=e[6],f+=r*I,l+=r*N,p+=r*D,d+=r*j,y+=r*Y,g+=r*z,v+=r*H,b+=r*q,m+=r*F,w+=r*J,_+=r*X,S+=r*K,k+=r*G,T+=r*W,A+=r*V,E+=r*Z,r=e[7],l+=r*I,p+=r*N,d+=r*D,y+=r*j,g+=r*Y,v+=r*z,b+=r*H,m+=r*q,w+=r*F,_+=r*J,S+=r*X,k+=r*K,T+=r*G,A+=r*W,E+=r*V,x+=r*Z,r=e[8],p+=r*I,d+=r*N,y+=r*D,g+=r*j,v+=r*Y,b+=r*z,m+=r*H,w+=r*q,_+=r*F,S+=r*J,k+=r*X,T+=r*K,A+=r*G,E+=r*W,x+=r*V,C+=r*Z,r=e[9],d+=r*I,y+=r*N,g+=r*D,v+=r*j,b+=r*Y,m+=r*z,w+=r*H,_+=r*q,S+=r*F,k+=r*J,T+=r*X,A+=r*K,E+=r*G,x+=r*W,C+=r*V,P+=r*Z,r=e[10],y+=r*I,g+=r*N,v+=r*D,b+=r*j,m+=r*Y,w+=r*z,_+=r*H,S+=r*q,k+=r*F,T+=r*J,A+=r*X,E+=r*K,x+=r*G,C+=r*W,P+=r*V,R+=r*Z,r=e[11],g+=r*I,v+=r*N,b+=r*D,m+=r*j,w+=r*Y,_+=r*z,S+=r*H,k+=r*q,T+=r*F,A+=r*J,E+=r*X,x+=r*K;C+=r*G;P+=r*W,R+=r*V,O+=r*Z,r=e[12],v+=r*I,b+=r*N,m+=r*D,w+=r*j,_+=r*Y,S+=r*z,k+=r*H,T+=r*q,A+=r*F,E+=r*J,x+=r*X,C+=r*K,P+=r*G,R+=r*W,O+=r*V,M+=r*Z,r=e[13],b+=r*I,m+=r*N,w+=r*D,_+=r*j,S+=r*Y,k+=r*z,T+=r*H,A+=r*q,E+=r*F,x+=r*J,C+=r*X,P+=r*K,R+=r*G,O+=r*W,M+=r*V,U+=r*Z,r=e[14],m+=r*I,w+=r*N,_+=r*D,S+=r*j,k+=r*Y,T+=r*z,A+=r*H,E+=r*q,x+=r*F,C+=r*J,P+=r*X,R+=r*K,O+=r*G,M+=r*W,U+=r*V,L+=r*Z,r=e[15],w+=r*I,_+=r*N,S+=r*D,k+=r*j,T+=r*Y,A+=r*z,E+=r*H,x+=r*q,C+=r*F,P+=r*J,R+=r*X,O+=r*K,M+=r*G,U+=r*W,L+=r*V,B+=r*Z,o+=38*_,s+=38*S,a+=38*k,u+=38*T,c+=38*A,h+=38*E,f+=38*x,l+=38*C,p+=38*P,d+=38*R,y+=38*O,g+=38*M,v+=38*U,b+=38*L,m+=38*B,i=1,r=o+i+65535,i=Math.floor(r/65536),o=r-65536*i,r=s+i+65535,i=Math.floor(r/65536),s=r-65536*i,r=a+i+65535,i=Math.floor(r/65536),a=r-65536*i,r=u+i+65535,i=Math.floor(r/65536),u=r-65536*i,r=c+i+65535,i=Math.floor(r/65536),c=r-65536*i,r=h+i+65535,i=Math.floor(r/65536),h=r-65536*i,r=f+i+65535,i=Math.floor(r/65536),f=r-65536*i, -r=l+i+65535,i=Math.floor(r/65536),l=r-65536*i,r=p+i+65535,i=Math.floor(r/65536),p=r-65536*i,r=d+i+65535,i=Math.floor(r/65536),d=r-65536*i,r=y+i+65535,i=Math.floor(r/65536),y=r-65536*i,r=g+i+65535,i=Math.floor(r/65536),g=r-65536*i,r=v+i+65535,i=Math.floor(r/65536),v=r-65536*i,r=b+i+65535,i=Math.floor(r/65536),b=r-65536*i,r=m+i+65535,i=Math.floor(r/65536),m=r-65536*i,r=w+i+65535,i=Math.floor(r/65536),w=r-65536*i,o+=i-1+37*(i-1),i=1,r=o+i+65535,i=Math.floor(r/65536),o=r-65536*i,r=s+i+65535,i=Math.floor(r/65536),s=r-65536*i,r=a+i+65535,i=Math.floor(r/65536),a=r-65536*i,r=u+i+65535,i=Math.floor(r/65536),u=r-65536*i,r=c+i+65535,i=Math.floor(r/65536),c=r-65536*i,r=h+i+65535,i=Math.floor(r/65536),h=r-65536*i,r=f+i+65535,i=Math.floor(r/65536),f=r-65536*i,r=l+i+65535,i=Math.floor(r/65536),l=r-65536*i,r=p+i+65535,i=Math.floor(r/65536),p=r-65536*i,r=d+i+65535,i=Math.floor(r/65536),d=r-65536*i,r=y+i+65535,i=Math.floor(r/65536),y=r-65536*i,r=g+i+65535,i=Math.floor(r/65536),g=r-65536*i,r=v+i+65535,i=Math.floor(r/65536),v=r-65536*i,r=b+i+65535,i=Math.floor(r/65536),b=r-65536*i,r=m+i+65535,i=Math.floor(r/65536),m=r-65536*i,r=w+i+65535,i=Math.floor(r/65536),w=r-65536*i,o+=i-1+37*(i-1),t[0]=o,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]=g,t[12]=v,t[13]=b;t[14]=m;t[15]=w}function C(t,e){x(t,e,e)}function P(t,e){var n,r=tt();for(n=0;n<16;n++)r[n]=e[n];for(n=253;n>=0;n--)C(r,r),2!==n&&4!==n&&x(r,r,e);for(n=0;n<16;n++)t[n]=r[n]}function R(t,e){var n,r=tt();for(n=0;n<16;n++)r[n]=e[n];for(n=250;n>=0;n--)C(r,r),1!==n&&x(r,r,e);for(n=0;n<16;n++)t[n]=r[n]}function O(t,e,n){var r,i,o=new Uint8Array(32),s=new Float64Array(80),a=tt(),u=tt(),c=tt(),h=tt(),f=tt(),l=tt();for(i=0;i<31;i++)o[i]=e[i];for(o[31]=127&e[31]|64,o[0]&=248,T(s,n),i=0;i<16;i++)u[i]=s[i],h[i]=a[i]=c[i]=0;for(a[0]=h[0]=1,i=254;i>=0;--i)r=o[i>>>3]>>>(7&i)&1,w(a,u,r),w(c,h,r),A(f,a,c),E(a,a,c),A(c,u,h),E(u,u,h),C(h,f),C(l,a),x(a,c,a),x(c,u,f),A(f,a,c),E(a,a,c),C(u,a),E(c,h,l),x(a,c,st),A(a,a,h),x(c,c,a),x(a,h,l),x(h,u,s),C(u,f),w(a,u,r),w(c,h,r);for(i=0;i<16;i++)s[i+16]=a[i],s[i+32]=c[i],s[i+48]=u[i],s[i+64]=h[i];var p=s.subarray(32),d=s.subarray(16);return P(p,p),x(d,d,p),_(t,d),0}function M(t,e){return O(t,e,rt)}function U(t,e){return et(e,32),M(t,e)}function L(t,e,n){var r=new Uint8Array(32);return O(r,n,e),c(t,nt,r,lt)}function B(t,e,n,r,i,o){var s=new Uint8Array(32);return L(s,i,o),dt(t,e,n,r,s)}function I(t,e,n,r,i,o){var s=new Uint8Array(32);return L(s,i,o),yt(t,e,n,r,s)}function N(t,e,n,r){for(var i,o,s,a,u,c,h,f,l,p,d,y,g,v,b,m,w,_,S,k,T,A,E,x,C,P,R=new Int32Array(16),O=new Int32Array(16),M=t[0],U=t[1],L=t[2],B=t[3],I=t[4],N=t[5],D=t[6],j=t[7],Y=e[0],z=e[1],H=e[2],q=e[3],F=e[4],J=e[5],X=e[6],K=e[7],G=0;r>=128;){for(S=0;S<16;S++)k=8*S+G,R[S]=n[k+0]<<24|n[k+1]<<16|n[k+2]<<8|n[k+3],O[S]=n[k+4]<<24|n[k+5]<<16|n[k+6]<<8|n[k+7];for(S=0;S<80;S++)if(i=M,o=U,s=L,a=B,u=I,c=N,h=D,f=j,l=Y,p=z,d=H,y=q,g=F,v=J,b=X,m=K,T=j,A=K,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=(I>>>14|F<<18)^(I>>>18|F<<14)^(F>>>9|I<<23),A=(F>>>14|I<<18)^(F>>>18|I<<14)^(I>>>9|F<<23),E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,T=I&N^~I&D,A=F&J^~F&X,E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,T=gt[2*S],A=gt[2*S+1],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,T=R[S%16],A=O[S%16],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,w=65535&C|P<<16,_=65535&E|x<<16,T=w,A=_,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=(M>>>28|Y<<4)^(Y>>>2|M<<30)^(Y>>>7|M<<25),A=(Y>>>28|M<<4)^(M>>>2|Y<<30)^(M>>>7|Y<<25),E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,T=M&U^M&L^U&L,A=Y&z^Y&H^z&H,E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,f=65535&C|P<<16,m=65535&E|x<<16,T=a,A=y,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=w,A=_,E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,a=65535&C|P<<16,y=65535&E|x<<16,U=i,L=o,B=s,I=a,N=u,D=c,j=h,M=f,z=l,H=p,q=d,F=y,J=g,X=v,K=b,Y=m,S%16===15)for(k=0;k<16;k++)T=R[k],A=O[k],E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=R[(k+9)%16],A=O[(k+9)%16],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,w=R[(k+1)%16],_=O[(k+1)%16],T=(w>>>1|_<<31)^(w>>>8|_<<24)^w>>>7,A=(_>>>1|w<<31)^(_>>>8|w<<24)^(_>>>7|w<<25),E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,w=R[(k+14)%16],_=O[(k+14)%16],T=(w>>>19|_<<13)^(_>>>29|w<<3)^w>>>6,A=(_>>>19|w<<13)^(w>>>29|_<<3)^(_>>>6|w<<26),E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,R[k]=65535&C|P<<16,O[k]=65535&E|x<<16;T=M,A=Y,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[0],A=e[0],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[0]=M=65535&C|P<<16,e[0]=Y=65535&E|x<<16,T=U,A=z,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[1],A=e[1],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[1]=U=65535&C|P<<16,e[1]=z=65535&E|x<<16,T=L,A=H,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[2],A=e[2],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[2]=L=65535&C|P<<16,e[2]=H=65535&E|x<<16,T=B,A=q,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[3],A=e[3],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[3]=B=65535&C|P<<16,e[3]=q=65535&E|x<<16,T=I,A=F,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[4],A=e[4],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[4]=I=65535&C|P<<16,e[4]=F=65535&E|x<<16,T=N,A=J,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[5],A=e[5],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[5]=N=65535&C|P<<16,e[5]=J=65535&E|x<<16,T=D,A=X,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[6],A=e[6],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[6]=D=65535&C|P<<16,e[6]=X=65535&E|x<<16,T=j,A=K,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[7],A=e[7],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[7]=j=65535&C|P<<16,e[7]=K=65535&E|x<<16,G+=128,r-=128}return r}function D(t,n,r){var i,o=new Int32Array(8),s=new Int32Array(8),a=new Uint8Array(256),u=r;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,s[0]=4089235720,s[1]=2227873595,s[2]=4271175723,s[3]=1595750129,s[4]=2917565137,s[5]=725511199,s[6]=4215389547,s[7]=327033209,N(o,s,n,r),r%=128,i=0;i=0;--i)r=n[i/8|0]>>(7&i)&1,Y(t,e,r),j(e,t),j(t,t),Y(t,e,r)}function q(t,e){var n=[tt(),tt(),tt(),tt()];b(n[0],ct),b(n[1],ht),b(n[2],ot),x(n[3],ct,ht),H(t,n,e)}function F(t,e,n){var r,i=new Uint8Array(64),o=[tt(),tt(),tt(),tt()];for(n||et(e,32),D(i,e,32),i[0]&=248,i[31]&=127,i[31]|=64,q(o,i),z(t,o),r=0;r<32;r++)e[r+32]=t[r];return 0}function J(t,e){var n,r,i,o;for(r=63;r>=32;--r){for(n=0,i=r-32,o=r-12;i>8,e[i]-=256*n;e[i]+=n,e[r]=0}for(n=0,i=0;i<32;i++)e[i]+=n-(e[31]>>4)*vt[i],n=e[i]>>8,e[i]&=255;for(i=0;i<32;i++)e[i]-=n*vt[i];for(r=0;r<32;r++)e[r+1]+=e[r]>>8,t[r]=255&e[r]}function X(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;J(t,n)}function K(t,e,n,r){var i,o,s=new Uint8Array(64),a=new Uint8Array(64),u=new Uint8Array(64),c=new Float64Array(64),h=[tt(),tt(),tt(),tt()];D(s,r,32),s[0]&=248,s[31]&=127,s[31]|=64;var f=n+64;for(i=0;i>7&&E(t[0],it,t[0]),x(t[3],t[0],t[1]),0)}function W(t,e,n,r){var i,s,a=new Uint8Array(32),u=new Uint8Array(64),c=[tt(),tt(),tt(),tt()],h=[tt(),tt(),tt(),tt()];if(s=-1,n<64)return-1;if(G(h,r))return-1;for(i=0;i>>13|n<<3),r=255&t[4]|(255&t[5])<<8,this.r[2]=7939&(n>>>10|r<<6),i=255&t[6]|(255&t[7])<<8,this.r[3]=8191&(r>>>7|i<<9),o=255&t[8]|(255&t[9])<<8,this.r[4]=255&(i>>>4|o<<12),this.r[5]=o>>>1&8190,s=255&t[10]|(255&t[11])<<8,this.r[6]=8191&(o>>>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};pt.prototype.blocks=function(t,e,n){for(var r,i,o,s,a,u,c,h,f,l,p,d,y,g,v,b,m,w,_,S=this.fin?0:2048,k=this.h[0],T=this.h[1],A=this.h[2],E=this.h[3],x=this.h[4],C=this.h[5],P=this.h[6],R=this.h[7],O=this.h[8],M=this.h[9],U=this.r[0],L=this.r[1],B=this.r[2],I=this.r[3],N=this.r[4],D=this.r[5],j=this.r[6],Y=this.r[7],z=this.r[8],H=this.r[9];n>=16;)r=255&t[e+0]|(255&t[e+1])<<8,k+=8191&r,i=255&t[e+2]|(255&t[e+3])<<8,T+=8191&(r>>>13|i<<3),o=255&t[e+4]|(255&t[e+5])<<8,A+=8191&(i>>>10|o<<6),s=255&t[e+6]|(255&t[e+7])<<8,E+=8191&(o>>>7|s<<9),a=255&t[e+8]|(255&t[e+9])<<8,x+=8191&(s>>>4|a<<12),C+=a>>>1&8191,u=255&t[e+10]|(255&t[e+11])<<8,P+=8191&(a>>>14|u<<2),c=255&t[e+12]|(255&t[e+13])<<8,R+=8191&(u>>>11|c<<5),h=255&t[e+14]|(255&t[e+15])<<8,O+=8191&(c>>>8|h<<8),M+=h>>>5|S,f=0,l=f,l+=k*U,l+=T*(5*H),l+=A*(5*z),l+=E*(5*Y),l+=x*(5*j),f=l>>>13,l&=8191,l+=C*(5*D),l+=P*(5*N),l+=R*(5*I),l+=O*(5*B),l+=M*(5*L),f+=l>>>13,l&=8191,p=f,p+=k*L,p+=T*U,p+=A*(5*H),p+=E*(5*z),p+=x*(5*Y),f=p>>>13,p&=8191,p+=C*(5*j),p+=P*(5*D),p+=R*(5*N),p+=O*(5*I),p+=M*(5*B),f+=p>>>13,p&=8191,d=f,d+=k*B,d+=T*L,d+=A*U,d+=E*(5*H),d+=x*(5*z),f=d>>>13,d&=8191,d+=C*(5*Y),d+=P*(5*j),d+=R*(5*D),d+=O*(5*N),d+=M*(5*I),f+=d>>>13,d&=8191,y=f,y+=k*I,y+=T*B,y+=A*L,y+=E*U,y+=x*(5*H),f=y>>>13,y&=8191,y+=C*(5*z),y+=P*(5*Y),y+=R*(5*j),y+=O*(5*D),y+=M*(5*N),f+=y>>>13,y&=8191,g=f,g+=k*N,g+=T*I,g+=A*B,g+=E*L,g+=x*U,f=g>>>13,g&=8191,g+=C*(5*H),g+=P*(5*z),g+=R*(5*Y),g+=O*(5*j),g+=M*(5*D),f+=g>>>13,g&=8191,v=f,v+=k*D,v+=T*N,v+=A*I,v+=E*B,v+=x*L,f=v>>>13,v&=8191,v+=C*U,v+=P*(5*H),v+=R*(5*z),v+=O*(5*Y),v+=M*(5*j),f+=v>>>13,v&=8191,b=f,b+=k*j,b+=T*D,b+=A*N,b+=E*I,b+=x*B,f=b>>>13,b&=8191,b+=C*L,b+=P*U,b+=R*(5*H),b+=O*(5*z),b+=M*(5*Y),f+=b>>>13,b&=8191,m=f,m+=k*Y,m+=T*j,m+=A*D,m+=E*N,m+=x*I,f=m>>>13,m&=8191,m+=C*B,m+=P*L,m+=R*U,m+=O*(5*H),m+=M*(5*z),f+=m>>>13,m&=8191,w=f,w+=k*z,w+=T*Y,w+=A*j,w+=E*D,w+=x*N,f=w>>>13,w&=8191,w+=C*I,w+=P*B,w+=R*L,w+=O*U,w+=M*(5*H),f+=w>>>13,w&=8191,_=f,_+=k*H,_+=T*z,_+=A*Y,_+=E*j,_+=x*D,f=_>>>13,_&=8191,_+=C*N,_+=P*I,_+=R*B,_+=O*L,_+=M*U,f+=_>>>13,_&=8191,f=(f<<2)+f|0,f=f+l|0,l=8191&f,f>>>=13,p+=f,k=l,T=p,A=d,E=y,x=g,C=v,P=b,R=m,O=w,M=_,e+=16,n-=16;this.h[0]=k,this.h[1]=T,this.h[2]=A,this.h[3]=E,this.h[4]=x,this.h[5]=C,this.h[6]=P,this.h[7]=R,this.h[8]=O,this.h[9]=M},pt.prototype.finish=function(t,e){var n,r,i,o,s=new Uint16Array(10);if(this.leftover){for(o=this.leftover,this.buffer[o++]=1;o<16;o++)this.buffer[o]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,o=2;o<10;o++)this.h[o]+=n,n=this.h[o]>>>13,this.h[o]&=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,o=1;o<10;o++)s[o]=this.h[o]+n,n=s[o]>>>13,s[o]&=8191;for(s[9]-=8192,r=(1^n)-1,o=0;o<10;o++)s[o]&=r;for(r=~r,o=0;o<10;o++)this.h[o]=this.h[o]&r|s[o];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),i=this.h[0]+this.pad[0],this.h[0]=65535&i,o=1;o<8;o++)i=(this.h[o]+this.pad[o]|0)+(i>>>16)|0,this.h[o]=65535&i;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},pt.prototype.update=function(t,e,n){var r,i;if(this.leftover){for(i=16-this.leftover,i>n&&(i=n),r=0;r=16&&(i=n-n%16,this.blocks(t,e,i),e+=i,n-=i),n){for(r=0;r=0},t.sign.keyPair=function(){var t=new Uint8Array(Ot),e=new Uint8Array(Mt);return F(t,e),{publicKey:t,secretKey:e}},t.sign.keyPair.fromSecretKey=function(t){if(Q(t),t.length!==Mt)throw new Error("bad secret key size");for(var e=new Uint8Array(Ot),n=0;n0)r.loading[t].push(n);else{r.loading[t]=[n];var o=i.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 i=function(t){t||o.cleanup()},a=0;a>>6)+i(128|63&e):i(224|e>>>12&15)+i(128|e>>>6&63)+i(128|63&e)},h=function(t){return t.replace(/[^\x00-\x7F]/g,c)},f=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),r=[o.charAt(n>>>18),o.charAt(n>>>12&63),e>=2?"=":o.charAt(n>>>6&63),e>=1?"=":o.charAt(63&n)];return r.join("")},l=window.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,f)}},function(t,e,n){"use strict";var r=n(12),i={now:function(){return Date.now?Date.now():(new Date).valueOf()},defer:function(t){return new r.OneOffTimer(0,t)},method:function(t){for(var e=[],n=1;n0)for(var r=0;r0&&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.__esModule=!0,e.default=i},function(t,e){"use strict";var n=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},r=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.BadEventName=r;var i=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.RequestTimedOut=i;var o=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.TransportPriorityTooLow=o;var s=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.TransportClosed=s;var a=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.UnsupportedFeature=a;var u=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.UnsupportedTransport=u;var c=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.UnsupportedStrategy=c},function(t,e,n){"use strict";var r=n(33),i=n(34),o=n(36),s=n(37),a=n(38),u={createStreamingSocket:function(t){return this.createSocket(o.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 r.default(t,e,n)}};e.__esModule=!0,e.default=u},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(2),o=n(24),s=262144,a=function(t){function e(e,n,r){t.call(this),this.hooks=e,this.method=n,this.url=r}return r(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 n!==-1?(this.position+=n+1,e.slice(0,n)):null},e.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>s},e}(o.default); +e.__esModule=!0,e.default=a},function(t,e,n){"use strict";function r(t){var e=/([^\?]*)\/*(\??.*)/.exec(t);return{base:e[1],queryString:e[2]}}function i(t,e){return t.base+"/"+e+"/xhr_send"}function o(t){var e=t.indexOf("?")===-1?"?":"&";return t+e+"t="+ +new Date+"&n="+l++}function s(t,e){var n=/(https?:\/\/)([^\/:]+)((\/|:)?.*)/.exec(t);return n[1]+e+n[3]}function a(t){return Math.floor(Math.random()*t)}function u(t){for(var e=[],n=0;n0&&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()}};e.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=n(9),i=n(11),o=n(40),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:i.default.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(o.default.ERROR,t)},t.prototype.info=function(t){this.log(o.default.INFO,t)},t.prototype.debug=function(t){this.log(o.default.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,i=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(i,function(t,r){t||n.sent++,e&&e(t,r)}),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}();e.__esModule=!0,e.default=s},function(t,e){"use strict";var n;!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(n||(n={})),e.__esModule=!0,e.default=n},function(t,e,n){"use strict";function r(t){return function(e){return[t.apply(this,arguments),e]}}function i(t){return"string"==typeof t&&":"===t.charAt(0)}function o(t,e){return e[t.slice(1)]}function s(t,e){if(0===t.length)return[[],e];var n=c(t[0],e),r=s(t.slice(1),n[1]);return[[n[0]].concat(r[0]),r[1]]}function a(t,e){if(!i(t))return[t,e];var n=o(t,e);if(void 0===n)throw"Undefined symbol "+t;return[n,e]}function u(t,e){if(i(t[0])){var n=o(t[0],e);if(t.length>1){if("function"!=typeof n)throw"Calling non-function "+t[0];var r=[h.extend({},e)].concat(h.map(t.slice(1),function(t){return c(t,h.extend({},e))[0]}));return n.apply(this,r)}return[n,e]}return s(t,e)}function c(t,e){return"string"==typeof t?a(t,e):"object"==typeof t&&t instanceof Array&&t.length>0?u(t,e):[t,e]}var h=n(9),f=n(11),l=n(42),p=n(31),d=n(64),y=n(65),g=n(66),v=n(67),b=n(68),m=n(69),w=n(70),_=n(2),S=_.default.Transports;e.build=function(t,e){var n=h.extend({},T,e);return c(t,n)[1].strategy};var k={isSupported:function(){return!1},connect:function(t,e){var n=f.default.defer(function(){e(new p.UnsupportedStrategy)});return{abort:function(){n.ensureAborted()},forceMinPriority:function(){}}}},T={extend:function(t,e,n){return[h.extend({},e,n),t]},def:function(t,e,n){if(void 0!==t[e])throw"Redefining symbol "+e;return t[e]=n,[void 0,t]},def_transport:function(t,e,n,r,i,o){var s=S[n];if(!s)throw new p.UnsupportedTransport(n);var a,u=!(t.enabledTransports&&h.arrayIndexOf(t.enabledTransports,e)===-1||t.disabledTransports&&h.arrayIndexOf(t.disabledTransports,e)!==-1);a=u?new d.default(e,r,o?o.getAssistant(s):s,h.extend({key:t.key,useTLS:t.useTLS,timeline:t.timeline,ignoreNullOrigin:t.ignoreNullOrigin},i)):k;var c=t.def(t,e,a)[1];return c.Transports=t.Transports||{},c.Transports[e]=a,[void 0,c]},transport_manager:r(function(t,e){return new l.default(e)}),sequential:r(function(t,e){var n=Array.prototype.slice.call(arguments,2);return new y.default(n,e)}),cached:r(function(t,e,n){return new v.default(n,t.Transports,{ttl:e,timeline:t.timeline,useTLS:t.useTLS})}),first_connected:r(function(t,e){return new w.default(e)}),best_connected_ever:r(function(){var t=Array.prototype.slice.call(arguments,1);return new g.default(t)}),delayed:r(function(t,e,n){return new b.default(n,{delay:e})}),if:r(function(t,e,n,r){return new m.default(e,n,r)}),is_supported:r(function(t,e){return function(){return e.isSupported()}})}},function(t,e,n){"use strict";var r=n(43),i=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.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=n(44),i=n(45),o=n(48),s=n(49),a=n(50),u=n(51),c=n(54),h=n(52),f=n(62),l=n(63),p={createChannels:function(){return new l.default},createConnectionManager:function(t,e){return new f.default(t,e)},createChannel:function(t,e){return new h.default(t,e)},createPrivateChannel:function(t,e){return new u.default(t,e)},createPresenceChannel:function(t,e){return new a.default(t,e)},createEncryptedChannel:function(t,e){return new c.default(t,e)},createTimelineSender:function(t,e){return new s.default(t,e)},createAuthorizer:function(t,e){return e.authorizer?e.authorizer(t,e):new o.default(t,e)},createHandshake:function(t,e){return new i.default(t,e)},createAssistantToTheTransportManager:function(t,e,n){return new r.default(t,e,n)}};e.__esModule=!0,e.default=p},function(t,e,n){"use strict";var r=n(11),i=n(9),o=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,o){var s=this;o=i.extend({},o,{activityTimeout:this.pingDelay});var a=this.transport.createConnection(t,e,n,o),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.__esModule=!0,e.default=o},function(t,e,n){"use strict";var r=n(9),i=n(46),o=n(47),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){t.unbindListeners();var n;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 o.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",r=i.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.__esModule=!0,e.default=s},function(t,e){"use strict";e.decodeMessage=function(t){try{var e=JSON.parse(t.data),n=e.data;if("string"==typeof n)try{n=JSON.parse(e.data)}catch(t){}var r={event:e.event,channel:e.channel,data:n};return e.user_id&&(r.user_id=e.user_id),r}catch(e){throw{type:"MessageParseError",error:e,data:t.data}}},e.encodeMessage=function(t){return JSON.stringify(t)},e.processHandshake=function(t){var n=e.decodeMessage(t);if("pusher:connection_established"===n.event){if(!n.data.activity_timeout)throw"No activity timeout specified in handshake";return{action:"connected",id:n.data.socket_id,activityTimeout:1e3*n.data.activity_timeout}}if("pusher:error"===n.event)return{action:this.getCloseAction(n.data),error:this.getCloseError(n.data)};throw"Invalid handshake"},e.getCloseAction=function(t){return t.code<4e3?t.code>=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=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(9),o=n(24),s=n(46),a=n(8),u=function(t){function e(e,n){t.call(this),this.id=e,this.transport=n,this.activityTimeout=n.activityTimeout,this.bindListeners()}return r(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),a.default.debug("Event sent",r),this.send(s.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=s.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(a.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=s.getCloseAction(t),n=s.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(o.default);e.__esModule=!0,e.default=u},function(t,e,n){"use strict";var r=n(2),i=function(){function t(t,e){this.channel=t;var n=e.authTransport;if("undefined"==typeof 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.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=n(2),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(r.default.TimelineTransport.getAgent(this,t),e)},t}();e.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(51),o=n(8),s=n(53),a=n(14),u=function(t){function e(e,n){t.call(this,e,n),this.members=new s.default}return r(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 i=a.default.buildLogSuffix("authenticationEndpoint");return o.default.warn("Invalid auth response for channel '"+r.name+"',expected 'channel_data' field. "+i),void n("Invalid auth response")}var s=JSON.parse(e.channel_data);r.members.setMyID(s.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 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}(i.default);e.__esModule=!0,e.default=u},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(43),o=n(52),s=function(t){function e(){t.apply(this,arguments)}return r(e,t),e.prototype.authorize=function(t,e){var n=i.default.createAuthorizer(this,this.pusher.config);return n.authorize(t,e)},e}(o.default);e.__esModule=!0,e.default=s},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(24),o=n(31),s=n(8),a=n(14),u=function(t){function e(e,n){t.call(this,function(t,n){s.default.debug("No callbacks on "+e+" for "+t)}),this.name=e,this.pusher=n,this.subscribed=!1,this.subscriptionPending=!1,this.subscriptionCancelled=!1}return r(e,t),e.prototype.authorize=function(t,e){return e(!1,{})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new o.BadEventName("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var n=a.default.buildLogSuffix("triggeringClientEvents");s.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:")){var r={};this.emit(e,n,r)}},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.__esModule=!0,e.default=u},function(t,e,n){"use strict";var r=n(9),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;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.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(51),o=n(31),s=n(8),a=n(55),u=n(57),c=function(t){function e(){t.apply(this,arguments),this.key=null}return r(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,function(t,e){if(t)return void n(!0,e);var i=e.shared_secret;if(!i){var o="No shared_secret key in auth payload for encrypted channel: "+r.name;return n(!0,o),void s.default.warn("Error: "+o)}r.key=u.decodeBase64(i),delete e.shared_secret,n(!1,e)})},e.prototype.trigger=function(t,e){throw new o.UnsupportedFeature("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e){var n=e.event,r=e.data;return 0===n.indexOf("pusher_internal:")||0===n.indexOf("pusher:")?void t.prototype.handleEvent.call(this,e):void this.handleEncryptedEvent(n,r)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(!this.key)return void s.default.debug("Received encrypted event before key has been retrieved from the authEndpoint");if(!e.ciphertext||!e.nonce)return void s.default.warn("Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: "+e);var r=u.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 r(t,e,n,r,i){var o,s=0;for(o=0;o>>8)-1}function i(t,e,n,i){return r(t,e,n,i,16)}function o(t,e,n,i){return r(t,e,n,i,32)}function s(t,e,n,r){for(var i,o=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,g=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,v=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,_=o,S=s,k=a,T=u,A=c,E=h,x=f,C=l,P=p,R=d,O=y,M=g,U=v,L=b,B=m,I=w,N=0;N<20;N+=2)i=_+U|0,A^=i<<7|i>>>25,i=A+_|0,P^=i<<9|i>>>23,i=P+A|0,U^=i<<13|i>>>19,i=U+P|0,_^=i<<18|i>>>14,i=E+S|0,R^=i<<7|i>>>25,i=R+E|0,L^=i<<9|i>>>23,i=L+R|0,S^=i<<13|i>>>19,i=S+L|0,E^=i<<18|i>>>14,i=O+x|0,B^=i<<7|i>>>25,i=B+O|0,k^=i<<9|i>>>23,i=k+B|0,x^=i<<13|i>>>19,i=x+k|0,O^=i<<18|i>>>14,i=I+M|0,T^=i<<7|i>>>25,i=T+I|0,C^=i<<9|i>>>23,i=C+T|0,M^=i<<13|i>>>19,i=M+C|0,I^=i<<18|i>>>14,i=_+T|0,S^=i<<7|i>>>25,i=S+_|0,k^=i<<9|i>>>23,i=k+S|0,T^=i<<13|i>>>19,i=T+k|0,_^=i<<18|i>>>14,i=E+A|0,x^=i<<7|i>>>25,i=x+E|0,C^=i<<9|i>>>23,i=C+x|0,A^=i<<13|i>>>19,i=A+C|0,E^=i<<18|i>>>14,i=O+R|0,M^=i<<7|i>>>25,i=M+O|0,P^=i<<9|i>>>23,i=P+M|0,R^=i<<13|i>>>19,i=R+P|0,O^=i<<18|i>>>14,i=I+B|0,U^=i<<7|i>>>25,i=U+I|0,L^=i<<9|i>>>23,i=L+U|0,B^=i<<13|i>>>19,i=B+L|0,I^=i<<18|i>>>14;_=_+o|0,S=S+s|0,k=k+a|0,T=T+u|0,A=A+c|0,E=E+h|0,x=x+f|0,C=C+l|0,P=P+p|0,R=R+d|0,O=O+y|0,M=M+g|0,U=U+v|0,L=L+b|0,B=B+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]=A>>>0&255,t[17]=A>>>8&255,t[18]=A>>>16&255,t[19]=A>>>24&255,t[20]=E>>>0&255,t[21]=E>>>8&255,t[22]=E>>>16&255,t[23]=E>>>24&255,t[24]=x>>>0&255,t[25]=x>>>8&255,t[26]=x>>>16&255,t[27]=x>>>24&255,t[28]=C>>>0&255,t[29]=C>>>8&255,t[30]=C>>>16&255,t[31]=C>>>24&255,t[32]=P>>>0&255,t[33]=P>>>8&255,t[34]=P>>>16&255,t[35]=P>>>24&255,t[36]=R>>>0&255,t[37]=R>>>8&255,t[38]=R>>>16&255,t[39]=R>>>24&255,t[40]=O>>>0&255,t[41]=O>>>8&255,t[42]=O>>>16&255,t[43]=O>>>24&255,t[44]=M>>>0&255,t[45]=M>>>8&255,t[46]=M>>>16&255,t[47]=M>>>24&255,t[48]=U>>>0&255,t[49]=U>>>8&255,t[50]=U>>>16&255,t[51]=U>>>24&255,t[52]=L>>>0&255,t[53]=L>>>8&255,t[54]=L>>>16&255,t[55]=L>>>24&255,t[56]=B>>>0&255,t[57]=B>>>8&255,t[58]=B>>>16&255,t[59]=B>>>24&255,t[60]=I>>>0&255,t[61]=I>>>8&255,t[62]=I>>>16&255,t[63]=I>>>24&255}function a(t,e,n,r){for(var i,o=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,g=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,v=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,_=o,S=s,k=a,T=u,A=c,E=h,x=f,C=l,P=p,R=d,O=y,M=g,U=v,L=b,B=m,I=w,N=0;N<20;N+=2)i=_+U|0,A^=i<<7|i>>>25,i=A+_|0,P^=i<<9|i>>>23,i=P+A|0,U^=i<<13|i>>>19,i=U+P|0,_^=i<<18|i>>>14,i=E+S|0,R^=i<<7|i>>>25,i=R+E|0,L^=i<<9|i>>>23,i=L+R|0,S^=i<<13|i>>>19,i=S+L|0,E^=i<<18|i>>>14,i=O+x|0,B^=i<<7|i>>>25,i=B+O|0,k^=i<<9|i>>>23,i=k+B|0,x^=i<<13|i>>>19,i=x+k|0,O^=i<<18|i>>>14,i=I+M|0,T^=i<<7|i>>>25,i=T+I|0,C^=i<<9|i>>>23,i=C+T|0,M^=i<<13|i>>>19,i=M+C|0,I^=i<<18|i>>>14,i=_+T|0,S^=i<<7|i>>>25,i=S+_|0,k^=i<<9|i>>>23,i=k+S|0,T^=i<<13|i>>>19,i=T+k|0,_^=i<<18|i>>>14,i=E+A|0,x^=i<<7|i>>>25,i=x+E|0,C^=i<<9|i>>>23,i=C+x|0,A^=i<<13|i>>>19,i=A+C|0,E^=i<<18|i>>>14,i=O+R|0,M^=i<<7|i>>>25,i=M+O|0,P^=i<<9|i>>>23,i=P+M|0,R^=i<<13|i>>>19,i=R+P|0,O^=i<<18|i>>>14,i=I+B|0,U^=i<<7|i>>>25,i=U+I|0,L^=i<<9|i>>>23,i=L+U|0,B^=i<<13|i>>>19,i=B+L|0,I^=i<<18|i>>>14;t[0]=_>>>0&255,t[1]=_>>>8&255,t[2]=_>>>16&255,t[3]=_>>>24&255,t[4]=E>>>0&255,t[5]=E>>>8&255,t[6]=E>>>16&255,t[7]=E>>>24&255,t[8]=O>>>0&255,t[9]=O>>>8&255,t[10]=O>>>16&255,t[11]=O>>>24&255,t[12]=I>>>0&255,t[13]=I>>>8&255,t[14]=I>>>16&255,t[15]=I>>>24&255,t[16]=x>>>0&255,t[17]=x>>>8&255,t[18]=x>>>16&255,t[19]=x>>>24&255,t[20]=C>>>0&255,t[21]=C>>>8&255,t[22]=C>>>16&255,t[23]=C>>>24&255,t[24]=P>>>0&255,t[25]=P>>>8&255,t[26]=P>>>16&255,t[27]=P>>>24&255,t[28]=R>>>0&255,t[29]=R>>>8&255,t[30]=R>>>16&255,t[31]=R>>>24&255}function u(t,e,n,r){s(t,e,n,r)}function c(t,e,n,r){a(t,e,n,r)}function h(t,e,n,r,i,o,s){var a,c,h=new Uint8Array(16),f=new Uint8Array(64);for(c=0;c<16;c++)h[c]=0;for(c=0;c<8;c++)h[c]=o[c];for(;i>=64;){for(u(f,h,s,lt),c=0;c<64;c++)t[e+c]=n[r+c]^f[c];for(a=1,c=8;c<16;c++)a=a+(255&h[c])|0,h[c]=255&a,a>>>=8;i-=64,e+=64,r+=64}if(i>0)for(u(f,h,s,lt),c=0;c=64;){for(u(c,a,i,lt),s=0;s<64;s++)t[e+s]=c[s];for(o=1,s=8;s<16;s++)o=o+(255&a[s])|0,a[s]=255&o,o>>>=8;n-=64,e+=64}if(n>0)for(u(c,a,i,lt),s=0;s>16&1),o[n-1]&=65535;o[15]=s[15]-32767-(o[14]>>16&1),i=o[15]>>16&1,o[14]&=65535,w(s,o,1-i)}for(n=0;n<16;n++)t[2*n]=255&s[n],t[2*n+1]=s[n]>>8}function S(t,e){var n=new Uint8Array(32),r=new Uint8Array(32);return _(n,t),_(r,e),o(n,0,r,0)}function k(t){var e=new Uint8Array(32);return _(e,t),1&e[0]}function T(t,e){var n;for(n=0;n<16;n++)t[n]=e[2*n]+(e[2*n+1]<<8);t[15]&=32767}function A(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]+n[r]}function E(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]-n[r]}function x(t,e,n){var r,i,o=0,s=0,a=0,u=0,c=0,h=0,f=0,l=0,p=0,d=0,y=0,g=0,v=0,b=0,m=0,w=0,_=0,S=0,k=0,T=0,A=0,E=0,x=0,C=0,P=0,R=0,O=0,M=0,U=0,L=0,B=0,I=n[0],N=n[1],D=n[2],j=n[3],Y=n[4],z=n[5],H=n[6],q=n[7],F=n[8],J=n[9],X=n[10],K=n[11],G=n[12],W=n[13],V=n[14],Z=n[15];r=e[0],o+=r*I,s+=r*N,a+=r*D,u+=r*j,c+=r*Y,h+=r*z,f+=r*H,l+=r*q,p+=r*F,d+=r*J,y+=r*X,g+=r*K,v+=r*G,b+=r*W,m+=r*V,w+=r*Z,r=e[1],s+=r*I,a+=r*N,u+=r*D,c+=r*j,h+=r*Y,f+=r*z,l+=r*H,p+=r*q,d+=r*F,y+=r*J,g+=r*X,v+=r*K,b+=r*G,m+=r*W,w+=r*V,_+=r*Z,r=e[2],a+=r*I,u+=r*N,c+=r*D,h+=r*j,f+=r*Y,l+=r*z,p+=r*H,d+=r*q,y+=r*F,g+=r*J,v+=r*X,b+=r*K,m+=r*G,w+=r*W,_+=r*V,S+=r*Z,r=e[3],u+=r*I,c+=r*N,h+=r*D,f+=r*j,l+=r*Y,p+=r*z,d+=r*H,y+=r*q,g+=r*F,v+=r*J,b+=r*X,m+=r*K,w+=r*G,_+=r*W,S+=r*V,k+=r*Z,r=e[4],c+=r*I,h+=r*N,f+=r*D,l+=r*j,p+=r*Y,d+=r*z,y+=r*H,g+=r*q,v+=r*F,b+=r*J,m+=r*X,w+=r*K,_+=r*G,S+=r*W,k+=r*V,T+=r*Z,r=e[5],h+=r*I,f+=r*N,l+=r*D,p+=r*j,d+=r*Y,y+=r*z,g+=r*H,v+=r*q,b+=r*F,m+=r*J,w+=r*X,_+=r*K,S+=r*G,k+=r*W,T+=r*V,A+=r*Z,r=e[6],f+=r*I,l+=r*N,p+=r*D,d+=r*j,y+=r*Y,g+=r*z,v+=r*H,b+=r*q,m+=r*F,w+=r*J,_+=r*X,S+=r*K,k+=r*G,T+=r*W,A+=r*V,E+=r*Z,r=e[7],l+=r*I,p+=r*N,d+=r*D,y+=r*j,g+=r*Y,v+=r*z,b+=r*H,m+=r*q,w+=r*F,_+=r*J,S+=r*X,k+=r*K,T+=r*G,A+=r*W,E+=r*V,x+=r*Z,r=e[8],p+=r*I,d+=r*N,y+=r*D,g+=r*j,v+=r*Y,b+=r*z,m+=r*H,w+=r*q,_+=r*F,S+=r*J,k+=r*X,T+=r*K,A+=r*G,E+=r*W,x+=r*V,C+=r*Z,r=e[9],d+=r*I,y+=r*N,g+=r*D,v+=r*j,b+=r*Y,m+=r*z,w+=r*H,_+=r*q,S+=r*F,k+=r*J,T+=r*X,A+=r*K,E+=r*G,x+=r*W,C+=r*V,P+=r*Z,r=e[10],y+=r*I,g+=r*N,v+=r*D,b+=r*j,m+=r*Y,w+=r*z,_+=r*H,S+=r*q,k+=r*F,T+=r*J,A+=r*X,E+=r*K,x+=r*G,C+=r*W,P+=r*V,R+=r*Z,r=e[11],g+=r*I,v+=r*N,b+=r*D,m+=r*j,w+=r*Y,_+=r*z,S+=r*H,k+=r*q,T+=r*F,A+=r*J,E+=r*X,x+=r*K;C+=r*G;P+=r*W,R+=r*V,O+=r*Z,r=e[12],v+=r*I,b+=r*N,m+=r*D,w+=r*j,_+=r*Y,S+=r*z,k+=r*H,T+=r*q,A+=r*F,E+=r*J,x+=r*X,C+=r*K,P+=r*G,R+=r*W,O+=r*V,M+=r*Z,r=e[13],b+=r*I,m+=r*N,w+=r*D,_+=r*j,S+=r*Y,k+=r*z, +T+=r*H,A+=r*q,E+=r*F,x+=r*J,C+=r*X,P+=r*K,R+=r*G,O+=r*W,M+=r*V,U+=r*Z,r=e[14],m+=r*I,w+=r*N,_+=r*D,S+=r*j,k+=r*Y,T+=r*z,A+=r*H,E+=r*q,x+=r*F,C+=r*J,P+=r*X,R+=r*K,O+=r*G,M+=r*W,U+=r*V,L+=r*Z,r=e[15],w+=r*I,_+=r*N,S+=r*D,k+=r*j,T+=r*Y,A+=r*z,E+=r*H,x+=r*q,C+=r*F,P+=r*J,R+=r*X,O+=r*K,M+=r*G,U+=r*W,L+=r*V,B+=r*Z,o+=38*_,s+=38*S,a+=38*k,u+=38*T,c+=38*A,h+=38*E,f+=38*x,l+=38*C,p+=38*P,d+=38*R,y+=38*O,g+=38*M,v+=38*U,b+=38*L,m+=38*B,i=1,r=o+i+65535,i=Math.floor(r/65536),o=r-65536*i,r=s+i+65535,i=Math.floor(r/65536),s=r-65536*i,r=a+i+65535,i=Math.floor(r/65536),a=r-65536*i,r=u+i+65535,i=Math.floor(r/65536),u=r-65536*i,r=c+i+65535,i=Math.floor(r/65536),c=r-65536*i,r=h+i+65535,i=Math.floor(r/65536),h=r-65536*i,r=f+i+65535,i=Math.floor(r/65536),f=r-65536*i,r=l+i+65535,i=Math.floor(r/65536),l=r-65536*i,r=p+i+65535,i=Math.floor(r/65536),p=r-65536*i,r=d+i+65535,i=Math.floor(r/65536),d=r-65536*i,r=y+i+65535,i=Math.floor(r/65536),y=r-65536*i,r=g+i+65535,i=Math.floor(r/65536),g=r-65536*i,r=v+i+65535,i=Math.floor(r/65536),v=r-65536*i,r=b+i+65535,i=Math.floor(r/65536),b=r-65536*i,r=m+i+65535,i=Math.floor(r/65536),m=r-65536*i,r=w+i+65535,i=Math.floor(r/65536),w=r-65536*i,o+=i-1+37*(i-1),i=1,r=o+i+65535,i=Math.floor(r/65536),o=r-65536*i,r=s+i+65535,i=Math.floor(r/65536),s=r-65536*i,r=a+i+65535,i=Math.floor(r/65536),a=r-65536*i,r=u+i+65535,i=Math.floor(r/65536),u=r-65536*i,r=c+i+65535,i=Math.floor(r/65536),c=r-65536*i,r=h+i+65535,i=Math.floor(r/65536),h=r-65536*i,r=f+i+65535,i=Math.floor(r/65536),f=r-65536*i,r=l+i+65535,i=Math.floor(r/65536),l=r-65536*i,r=p+i+65535,i=Math.floor(r/65536),p=r-65536*i,r=d+i+65535,i=Math.floor(r/65536),d=r-65536*i,r=y+i+65535,i=Math.floor(r/65536),y=r-65536*i,r=g+i+65535,i=Math.floor(r/65536),g=r-65536*i,r=v+i+65535,i=Math.floor(r/65536),v=r-65536*i,r=b+i+65535,i=Math.floor(r/65536),b=r-65536*i,r=m+i+65535,i=Math.floor(r/65536),m=r-65536*i,r=w+i+65535,i=Math.floor(r/65536),w=r-65536*i,o+=i-1+37*(i-1),t[0]=o,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]=g,t[12]=v,t[13]=b;t[14]=m;t[15]=w}function C(t,e){x(t,e,e)}function P(t,e){var n,r=tt();for(n=0;n<16;n++)r[n]=e[n];for(n=253;n>=0;n--)C(r,r),2!==n&&4!==n&&x(r,r,e);for(n=0;n<16;n++)t[n]=r[n]}function R(t,e){var n,r=tt();for(n=0;n<16;n++)r[n]=e[n];for(n=250;n>=0;n--)C(r,r),1!==n&&x(r,r,e);for(n=0;n<16;n++)t[n]=r[n]}function O(t,e,n){var r,i,o=new Uint8Array(32),s=new Float64Array(80),a=tt(),u=tt(),c=tt(),h=tt(),f=tt(),l=tt();for(i=0;i<31;i++)o[i]=e[i];for(o[31]=127&e[31]|64,o[0]&=248,T(s,n),i=0;i<16;i++)u[i]=s[i],h[i]=a[i]=c[i]=0;for(a[0]=h[0]=1,i=254;i>=0;--i)r=o[i>>>3]>>>(7&i)&1,w(a,u,r),w(c,h,r),A(f,a,c),E(a,a,c),A(c,u,h),E(u,u,h),C(h,f),C(l,a),x(a,c,a),x(c,u,f),A(f,a,c),E(a,a,c),C(u,a),E(c,h,l),x(a,c,st),A(a,a,h),x(c,c,a),x(a,h,l),x(h,u,s),C(u,f),w(a,u,r),w(c,h,r);for(i=0;i<16;i++)s[i+16]=a[i],s[i+32]=c[i],s[i+48]=u[i],s[i+64]=h[i];var p=s.subarray(32),d=s.subarray(16);return P(p,p),x(d,d,p),_(t,d),0}function M(t,e){return O(t,e,rt)}function U(t,e){return et(e,32),M(t,e)}function L(t,e,n){var r=new Uint8Array(32);return O(r,n,e),c(t,nt,r,lt)}function B(t,e,n,r,i,o){var s=new Uint8Array(32);return L(s,i,o),dt(t,e,n,r,s)}function I(t,e,n,r,i,o){var s=new Uint8Array(32);return L(s,i,o),yt(t,e,n,r,s)}function N(t,e,n,r){for(var i,o,s,a,u,c,h,f,l,p,d,y,g,v,b,m,w,_,S,k,T,A,E,x,C,P,R=new Int32Array(16),O=new Int32Array(16),M=t[0],U=t[1],L=t[2],B=t[3],I=t[4],N=t[5],D=t[6],j=t[7],Y=e[0],z=e[1],H=e[2],q=e[3],F=e[4],J=e[5],X=e[6],K=e[7],G=0;r>=128;){for(S=0;S<16;S++)k=8*S+G,R[S]=n[k+0]<<24|n[k+1]<<16|n[k+2]<<8|n[k+3],O[S]=n[k+4]<<24|n[k+5]<<16|n[k+6]<<8|n[k+7];for(S=0;S<80;S++)if(i=M,o=U,s=L,a=B,u=I,c=N,h=D,f=j,l=Y,p=z,d=H,y=q,g=F,v=J,b=X,m=K,T=j,A=K,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=(I>>>14|F<<18)^(I>>>18|F<<14)^(F>>>9|I<<23),A=(F>>>14|I<<18)^(F>>>18|I<<14)^(I>>>9|F<<23),E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,T=I&N^~I&D,A=F&J^~F&X,E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,T=gt[2*S],A=gt[2*S+1],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,T=R[S%16],A=O[S%16],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,w=65535&C|P<<16,_=65535&E|x<<16,T=w,A=_,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=(M>>>28|Y<<4)^(Y>>>2|M<<30)^(Y>>>7|M<<25),A=(Y>>>28|M<<4)^(M>>>2|Y<<30)^(M>>>7|Y<<25),E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,T=M&U^M&L^U&L,A=Y&z^Y&H^z&H,E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,f=65535&C|P<<16,m=65535&E|x<<16,T=a,A=y,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=w,A=_,E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,a=65535&C|P<<16,y=65535&E|x<<16,U=i,L=o,B=s,I=a,N=u,D=c,j=h,M=f,z=l,H=p,q=d,F=y,J=g,X=v,K=b,Y=m,S%16===15)for(k=0;k<16;k++)T=R[k],A=O[k],E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=R[(k+9)%16],A=O[(k+9)%16],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,w=R[(k+1)%16],_=O[(k+1)%16],T=(w>>>1|_<<31)^(w>>>8|_<<24)^w>>>7,A=(_>>>1|w<<31)^(_>>>8|w<<24)^(_>>>7|w<<25),E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,w=R[(k+14)%16],_=O[(k+14)%16],T=(w>>>19|_<<13)^(_>>>29|w<<3)^w>>>6,A=(_>>>19|w<<13)^(w>>>29|_<<3)^(_>>>6|w<<26),E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,R[k]=65535&C|P<<16,O[k]=65535&E|x<<16;T=M,A=Y,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[0],A=e[0],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[0]=M=65535&C|P<<16,e[0]=Y=65535&E|x<<16,T=U,A=z,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[1],A=e[1],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[1]=U=65535&C|P<<16,e[1]=z=65535&E|x<<16,T=L,A=H,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[2],A=e[2],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[2]=L=65535&C|P<<16,e[2]=H=65535&E|x<<16,T=B,A=q,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[3],A=e[3],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[3]=B=65535&C|P<<16,e[3]=q=65535&E|x<<16,T=I,A=F,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[4],A=e[4],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[4]=I=65535&C|P<<16,e[4]=F=65535&E|x<<16,T=N,A=J,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[5],A=e[5],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[5]=N=65535&C|P<<16,e[5]=J=65535&E|x<<16,T=D,A=X,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[6],A=e[6],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[6]=D=65535&C|P<<16,e[6]=X=65535&E|x<<16,T=j,A=K,E=65535&A,x=A>>>16,C=65535&T,P=T>>>16,T=t[7],A=e[7],E+=65535&A,x+=A>>>16,C+=65535&T,P+=T>>>16,x+=E>>>16,C+=x>>>16,P+=C>>>16,t[7]=j=65535&C|P<<16,e[7]=K=65535&E|x<<16,G+=128,r-=128}return r}function D(t,n,r){var i,o=new Int32Array(8),s=new Int32Array(8),a=new Uint8Array(256),u=r;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,s[0]=4089235720,s[1]=2227873595,s[2]=4271175723,s[3]=1595750129,s[4]=2917565137,s[5]=725511199,s[6]=4215389547,s[7]=327033209,N(o,s,n,r),r%=128,i=0;i=0;--i)r=n[i/8|0]>>(7&i)&1,Y(t,e,r),j(e,t),j(t,t),Y(t,e,r)}function q(t,e){var n=[tt(),tt(),tt(),tt()];b(n[0],ct),b(n[1],ht),b(n[2],ot),x(n[3],ct,ht),H(t,n,e)}function F(t,e,n){var r,i=new Uint8Array(64),o=[tt(),tt(),tt(),tt()];for(n||et(e,32),D(i,e,32),i[0]&=248,i[31]&=127,i[31]|=64,q(o,i),z(t,o),r=0;r<32;r++)e[r+32]=t[r];return 0}function J(t,e){var n,r,i,o;for(r=63;r>=32;--r){for(n=0,i=r-32,o=r-12;i>8,e[i]-=256*n;e[i]+=n,e[r]=0}for(n=0,i=0;i<32;i++)e[i]+=n-(e[31]>>4)*vt[i],n=e[i]>>8,e[i]&=255;for(i=0;i<32;i++)e[i]-=n*vt[i];for(r=0;r<32;r++)e[r+1]+=e[r]>>8,t[r]=255&e[r]}function X(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;J(t,n)}function K(t,e,n,r){var i,o,s=new Uint8Array(64),a=new Uint8Array(64),u=new Uint8Array(64),c=new Float64Array(64),h=[tt(),tt(),tt(),tt()];D(s,r,32),s[0]&=248,s[31]&=127,s[31]|=64;var f=n+64;for(i=0;i>7&&E(t[0],it,t[0]),x(t[3],t[0],t[1]),0)}function W(t,e,n,r){var i,s,a=new Uint8Array(32),u=new Uint8Array(64),c=[tt(),tt(),tt(),tt()],h=[tt(),tt(),tt(),tt()];if(s=-1,n<64)return-1;if(G(h,r))return-1;for(i=0;i>>13|n<<3),r=255&t[4]|(255&t[5])<<8,this.r[2]=7939&(n>>>10|r<<6),i=255&t[6]|(255&t[7])<<8,this.r[3]=8191&(r>>>7|i<<9),o=255&t[8]|(255&t[9])<<8,this.r[4]=255&(i>>>4|o<<12),this.r[5]=o>>>1&8190,s=255&t[10]|(255&t[11])<<8,this.r[6]=8191&(o>>>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};pt.prototype.blocks=function(t,e,n){for(var r,i,o,s,a,u,c,h,f,l,p,d,y,g,v,b,m,w,_,S=this.fin?0:2048,k=this.h[0],T=this.h[1],A=this.h[2],E=this.h[3],x=this.h[4],C=this.h[5],P=this.h[6],R=this.h[7],O=this.h[8],M=this.h[9],U=this.r[0],L=this.r[1],B=this.r[2],I=this.r[3],N=this.r[4],D=this.r[5],j=this.r[6],Y=this.r[7],z=this.r[8],H=this.r[9];n>=16;)r=255&t[e+0]|(255&t[e+1])<<8,k+=8191&r,i=255&t[e+2]|(255&t[e+3])<<8,T+=8191&(r>>>13|i<<3),o=255&t[e+4]|(255&t[e+5])<<8,A+=8191&(i>>>10|o<<6),s=255&t[e+6]|(255&t[e+7])<<8,E+=8191&(o>>>7|s<<9),a=255&t[e+8]|(255&t[e+9])<<8,x+=8191&(s>>>4|a<<12),C+=a>>>1&8191,u=255&t[e+10]|(255&t[e+11])<<8,P+=8191&(a>>>14|u<<2),c=255&t[e+12]|(255&t[e+13])<<8,R+=8191&(u>>>11|c<<5),h=255&t[e+14]|(255&t[e+15])<<8,O+=8191&(c>>>8|h<<8),M+=h>>>5|S,f=0,l=f,l+=k*U,l+=T*(5*H),l+=A*(5*z),l+=E*(5*Y),l+=x*(5*j),f=l>>>13,l&=8191,l+=C*(5*D),l+=P*(5*N),l+=R*(5*I),l+=O*(5*B),l+=M*(5*L),f+=l>>>13,l&=8191,p=f,p+=k*L,p+=T*U,p+=A*(5*H),p+=E*(5*z),p+=x*(5*Y),f=p>>>13,p&=8191,p+=C*(5*j),p+=P*(5*D),p+=R*(5*N),p+=O*(5*I),p+=M*(5*B),f+=p>>>13,p&=8191,d=f,d+=k*B,d+=T*L,d+=A*U,d+=E*(5*H),d+=x*(5*z),f=d>>>13,d&=8191,d+=C*(5*Y),d+=P*(5*j),d+=R*(5*D),d+=O*(5*N),d+=M*(5*I),f+=d>>>13,d&=8191,y=f,y+=k*I,y+=T*B,y+=A*L,y+=E*U,y+=x*(5*H),f=y>>>13,y&=8191,y+=C*(5*z),y+=P*(5*Y),y+=R*(5*j),y+=O*(5*D),y+=M*(5*N),f+=y>>>13,y&=8191,g=f,g+=k*N,g+=T*I,g+=A*B,g+=E*L,g+=x*U,f=g>>>13,g&=8191,g+=C*(5*H),g+=P*(5*z),g+=R*(5*Y),g+=O*(5*j),g+=M*(5*D),f+=g>>>13,g&=8191,v=f,v+=k*D,v+=T*N,v+=A*I,v+=E*B,v+=x*L,f=v>>>13,v&=8191,v+=C*U,v+=P*(5*H),v+=R*(5*z),v+=O*(5*Y),v+=M*(5*j),f+=v>>>13,v&=8191,b=f,b+=k*j,b+=T*D,b+=A*N,b+=E*I,b+=x*B,f=b>>>13,b&=8191,b+=C*L,b+=P*U,b+=R*(5*H),b+=O*(5*z),b+=M*(5*Y),f+=b>>>13,b&=8191,m=f,m+=k*Y,m+=T*j,m+=A*D,m+=E*N,m+=x*I,f=m>>>13,m&=8191,m+=C*B,m+=P*L,m+=R*U,m+=O*(5*H),m+=M*(5*z),f+=m>>>13,m&=8191,w=f,w+=k*z,w+=T*Y,w+=A*j,w+=E*D,w+=x*N,f=w>>>13,w&=8191,w+=C*I,w+=P*B,w+=R*L,w+=O*U,w+=M*(5*H),f+=w>>>13,w&=8191,_=f,_+=k*H,_+=T*z,_+=A*Y,_+=E*j,_+=x*D,f=_>>>13,_&=8191,_+=C*N,_+=P*I,_+=R*B,_+=O*L,_+=M*U,f+=_>>>13,_&=8191,f=(f<<2)+f|0,f=f+l|0,l=8191&f,f>>>=13,p+=f,k=l,T=p,A=d,E=y,x=g,C=v,P=b,R=m,O=w,M=_,e+=16,n-=16;this.h[0]=k,this.h[1]=T,this.h[2]=A,this.h[3]=E,this.h[4]=x,this.h[5]=C,this.h[6]=P,this.h[7]=R,this.h[8]=O,this.h[9]=M},pt.prototype.finish=function(t,e){var n,r,i,o,s=new Uint16Array(10);if(this.leftover){for(o=this.leftover,this.buffer[o++]=1;o<16;o++)this.buffer[o]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,o=2;o<10;o++)this.h[o]+=n,n=this.h[o]>>>13,this.h[o]&=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,o=1;o<10;o++)s[o]=this.h[o]+n,n=s[o]>>>13,s[o]&=8191;for(s[9]-=8192,r=(1^n)-1,o=0;o<10;o++)s[o]&=r;for(r=~r,o=0;o<10;o++)this.h[o]=this.h[o]&r|s[o];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),i=this.h[0]+this.pad[0],this.h[0]=65535&i,o=1;o<8;o++)i=(this.h[o]+this.pad[o]|0)+(i>>>16)|0,this.h[o]=65535&i;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},pt.prototype.update=function(t,e,n){var r,i;if(this.leftover){for(i=16-this.leftover,i>n&&(i=n),r=0;r=16&&(i=n-n%16,this.blocks(t,e,i),e+=i,n-=i),n){for(r=0;r=0},t.sign.keyPair=function(){var t=new Uint8Array(Ot),e=new Uint8Array(Mt);return F(t,e),{publicKey:t,secretKey:e}},t.sign.keyPair.fromSecretKey=function(t){if(Q(t),t.length!==Mt)throw new Error("bad secret key size");for(var e=new Uint8Array(Ot),n=0;n diff --git a/dist/worker/pusher.worker.js b/dist/worker/pusher.worker.js index 651211f79..7a0e5d6a1 100644 --- a/dist/worker/pusher.worker.js +++ b/dist/worker/pusher.worker.js @@ -1,5 +1,5 @@ /*! - * Pusher JavaScript Library v4.3.1 + * Pusher JavaScript Library v4.4.0 * https://pusher.com/ * * Copyright 2017, Pusher @@ -74,7 +74,7 @@ var Pusher = var DefaultConfig = __webpack_require__(63); var logger_1 = __webpack_require__(16); var factory_1 = __webpack_require__(33); - var url_store_1 = __webpack_require__(45); + var url_store_1 = __webpack_require__(44); var Pusher = (function () { function Pusher(app_key, options) { var _this = this; @@ -119,16 +119,17 @@ var Pusher = _this.timelineSender.send(_this.connection.isUsingTLS()); } }); - this.connection.bind('message', function (params) { - var internal = (params.event.indexOf('pusher_internal:') === 0); - if (params.channel) { - var channel = _this.channel(params.channel); + 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(params.event, params.data); + channel.handleEvent(event); } } if (!internal) { - _this.global_emitter.emit(params.event, params.data); + _this.global_emitter.emit(event.event, event.data); } }); this.connection.bind('connecting', function () { @@ -831,7 +832,7 @@ var Pusher = "use strict"; var Defaults = { - VERSION: "4.3.1", + VERSION: "4.4.0", PROTOCOL: 7, host: 'ws.pusherapp.com', ws_port: 80, @@ -1077,15 +1078,21 @@ var Pusher = this.unbind_global(); return this; }; - Dispatcher.prototype.emit = function (eventName, data) { - var i; - for (i = 0; i < this.global_callbacks.length; i++) { + 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 (i = 0; i < callbacks.length; i++) { - callbacks[i].fn.call(callbacks[i].context || (self), data); + for (var i = 0; i < callbacks.length; i++) { + callbacks[i].fn.apply(callbacks[i].context || (self), args); } } else if (this.failThrough) { @@ -2262,30 +2269,35 @@ var Pusher = /***/ (function(module, exports) { "use strict"; - exports.decodeMessage = function (message) { + exports.decodeMessage = function (messageEvent) { try { - var params = JSON.parse(message.data); - if (typeof params.data === 'string') { + var messageData = JSON.parse(messageEvent.data); + var pusherEventData = messageData.data; + if (typeof pusherEventData === 'string') { try { - params.data = JSON.parse(params.data); - } - catch (e) { - if (!(e instanceof SyntaxError)) { - throw e; - } + pusherEventData = JSON.parse(messageData.data); } + catch (e) { } } - return params; + 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: message.data }; + throw { type: 'MessageParseError', error: e, data: messageEvent.data }; } }; - exports.encodeMessage = function (message) { - return JSON.stringify(message); + exports.encodeMessage = function (event) { + return JSON.stringify(event); }; - exports.processHandshake = function (message) { - message = exports.decodeMessage(message); + 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"; @@ -2377,12 +2389,12 @@ var Pusher = return this.transport.send(data); }; Connection.prototype.send_event = function (name, data, channel) { - var message = { event: name, data: data }; + var event = { event: name, data: data }; if (channel) { - message.channel = channel; + event.channel = channel; } - logger_1["default"].debug('Event sent', message); - return this.send(Protocol.encodeMessage(message)); + logger_1["default"].debug('Event sent', event); + return this.send(Protocol.encodeMessage(event)); }; Connection.prototype.ping = function () { if (this.transport.supportsPing()) { @@ -2398,23 +2410,23 @@ var Pusher = Connection.prototype.bindListeners = function () { var _this = this; var listeners = { - message: function (m) { - var message; + message: function (messageEvent) { + var pusherEvent; try { - message = Protocol.decodeMessage(m); + pusherEvent = Protocol.decodeMessage(messageEvent); } catch (e) { _this.emit('error', { type: 'MessageParseError', error: e, - data: m.data + data: messageEvent.data }); } - if (message !== undefined) { - logger_1["default"].debug('Event recd', message); - switch (message.event) { + if (pusherEvent !== undefined) { + logger_1["default"].debug('Event recd', pusherEvent); + switch (pusherEvent.event) { case 'pusher:error': - _this.emit('error', { type: 'PusherError', data: message.data }); + _this.emit('error', { type: 'PusherError', data: pusherEvent.data }); break; case 'pusher:ping': _this.emit("ping"); @@ -2423,7 +2435,7 @@ var Pusher = _this.emit("pong"); break; } - _this.emit('message', message); + _this.emit('message', pusherEvent); } }, activity: function () { @@ -2536,8 +2548,8 @@ var Pusher = }; var private_channel_1 = __webpack_require__(41); var logger_1 = __webpack_require__(16); - var members_1 = __webpack_require__(44); - var url_store_1 = __webpack_require__(45); + var members_1 = __webpack_require__(45); + var url_store_1 = __webpack_require__(44); var PresenceChannel = (function (_super) { __extends(PresenceChannel, _super); function PresenceChannel(name, pusher) { @@ -2561,18 +2573,26 @@ var Pusher = callback(error, authData); }); }; - PresenceChannel.prototype.handleEvent = function (event, data) { - switch (event) { + 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.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } - else { - this.members.onSubscription(data); - this.emit("pusher:subscription_succeeded", this.members); - } + this.handleSubscriptionSucceededEvent(event); break; case "pusher_internal:member_added": var addedMember = this.members.addMember(data); @@ -2584,8 +2604,17 @@ var Pusher = this.emit('pusher:member_removed', removedMember); } break; - default: - private_channel_1["default"].prototype.handleEvent.call(this, event, data); + } + }; + 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 () { @@ -2638,6 +2667,7 @@ var Pusher = var dispatcher_1 = __webpack_require__(14); var Errors = __webpack_require__(43); var logger_1 = __webpack_require__(16); + var url_store_1 = __webpack_require__(44); var Channel = (function (_super) { __extends(Channel, _super); function Channel(name, pusher) { @@ -2657,27 +2687,35 @@ var Pusher = 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, data) { - if (event.indexOf("pusher_internal:") === 0) { - if (event === "pusher_internal:subscription_succeeded") { - this.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } - else { - this.emit("pusher:subscription_succeeded", data); - } - } + 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(event, data); + this.emit("pusher:subscription_succeeded", event.data); } }; Channel.prototype.subscribe = function () { @@ -2689,7 +2727,7 @@ var Pusher = this.subscriptionCancelled = false; this.authorize(this.pusher.connection.socket_id, function (error, data) { if (error) { - _this.handleEvent('pusher:subscription_error', data); + _this.emit('pusher:subscription_error', data); } else { _this.pusher.send_event('pusher:subscribe', { @@ -2788,6 +2826,45 @@ var Pusher = /***/ }), /* 44 */ +/***/ (function(module, exports) { + + "use strict"; + 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.__esModule = true; + exports["default"] = { buildLogSuffix: buildLogSuffix }; + + +/***/ }), +/* 45 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -2848,42 +2925,6 @@ var Pusher = exports["default"] = Members; -/***/ }), -/* 45 */ -/***/ (function(module, exports) { - - "use strict"; - var urlStore = { - baseUrl: "https://pusher.com", - urls: { - authenticationEndpoint: { - path: "/docs/authenticating_users" - }, - javascriptQuickStart: { - path: "/docs/javascript_quick_start" - } - } - }; - 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.__esModule = true; - exports["default"] = { buildLogSuffix: buildLogSuffix }; - - /***/ }), /* 46 */ /***/ (function(module, exports, __webpack_require__) { @@ -2927,12 +2968,14 @@ var Pusher = EncryptedChannel.prototype.trigger = function (event, data) { throw new Errors.UnsupportedFeature('Client events are not currently supported for encrypted channels'); }; - EncryptedChannel.prototype.handleEvent = function (event, data) { - if (event.indexOf("pusher_internal:") === 0 || event.indexOf("pusher:") === 0) { - _super.prototype.handleEvent.call(this, event, data); + 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(event, data); + this.handleEncryptedEvent(eventName, data); }; EncryptedChannel.prototype.handleEncryptedEvent = function (event, data) { var _this = this; diff --git a/dist/worker/pusher.worker.min.js b/dist/worker/pusher.worker.min.js index b4a6f1a17..66d1e3e50 100644 --- a/dist/worker/pusher.worker.min.js +++ b/dist/worker/pusher.worker.min.js @@ -1,13 +1,13 @@ /*! - * Pusher JavaScript Library v4.3.1 + * Pusher JavaScript Library v4.4.0 * https://pusher.com/ * * Copyright 2017, Pusher * Released under the MIT licence. */ -var Pusher=function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";var r=n(1);t.exports=r.default},function(t,e,n){"use strict";function r(t){if(null===t||void 0===t)throw"You must pass your app key when you instantiate Pusher."}var i=n(2),o=n(4),s=n(14),a=n(29),u=n(30),c=n(31),h=n(7),f=n(11),l=n(63),p=n(16),d=n(33),y=n(45),g=function(){function t(e,n){var h=this;if(r(e),n=n||{},!n.cluster&&!n.wsHost&&!n.httpHost){var g=y.default.buildLogSuffix("javascriptQuickStart");p.default.warn("You should always specify a cluster when connecting. "+g)}this.key=e,this.config=o.extend(l.getGlobalConfig(),n.cluster?l.getClusterConfig(n.cluster):{},n),this.channels=d.default.createChannels(),this.global_emitter=new s.default,this.sessionID=Math.floor(1e9*Math.random()),this.timeline=new a.default(this.key,this.sessionID,{cluster:this.config.cluster,features:t.getClientFeatures(),params:this.config.timelineParams||{},limit:50,level:u.default.INFO,version:f.default.VERSION}),this.config.disableStats||(this.timelineSender=d.default.createTimelineSender(this.timeline,{host:this.config.statsHost,path:"/timeline/v2/"+i.default.TimelineTransport.name}));var v=function(t){var e=o.extend({},h.config,t);return c.build(i.default.getDefaultStrategy(e),e)};this.connection=d.default.createConnectionManager(this.key,o.extend({getStrategy:v,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(){h.subscribeAll(),h.timelineSender&&h.timelineSender.send(h.connection.isUsingTLS())}),this.connection.bind("message",function(t){var e=0===t.event.indexOf("pusher_internal:");if(t.channel){var n=h.channel(t.channel);n&&n.handleEvent(t.event,t.data)}e||h.global_emitter.emit(t.event,t.data)}),this.connection.bind("connecting",function(){h.channels.disconnect()}),this.connection.bind("disconnected",function(){h.channels.disconnect()}),this.connection.bind("error",function(t){p.default.warn("Error",t)}),t.instances.push(this),this.timeline.info({instances:t.instances.length}),t.isReady&&this.connect()}return t.ready=function(){t.isReady=!0;for(var e=0,n=t.instances.length;e>>6)+i(128|63&e):i(224|e>>>12&15)+i(128|e>>>6&63)+i(128|63&e)},h=function(t){return t.replace(/[^\x00-\x7F]/g,c)},f=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),r=[o.charAt(n>>>18),o.charAt(n>>>12&63),e>=2?"=":o.charAt(n>>>6&63),e>=1?"=":o.charAt(63&n)];return r.join("")},l=self.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,f)}},function(t,e,n){"use strict";var r=n(7),i={now:function(){return Date.now?Date.now():(new Date).valueOf()},defer:function(t){return new r.OneOffTimer(0,t)},method:function(t){for(var e=[],n=1;n0)for(n=0;ns},e}(o.default);e.__esModule=!0,e.default=a},function(t,e,n){"use strict";function r(t){var e=/([^\?]*)\/*(\??.*)/.exec(t);return{base:e[1],queryString:e[2]}}function i(t,e){return t.base+"/"+e+"/xhr_send"}function o(t){var e=t.indexOf("?")===-1?"?":"&";return t+e+"t="+ +new Date+"&n="+l++}function s(t,e){var n=/(https?:\/\/)([^\/:]+)((\/|:)?.*)/.exec(t);return n[1]+e+n[3]}function a(t){return Math.floor(Math.random()*t)}function u(t){for(var e=[],n=0;n0&&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()}};e.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(14),o=function(t){function e(){t.apply(this,arguments)}return r(e,t),e.prototype.isOnline=function(){return!0},e}(i.default);e.NetInfo=o,e.Network=new o},function(t,e,n){"use strict";var r=n(16),i=function(t,e,n){var i=new Headers;i.set("Content-Type","application/x-www-form-urlencoded");for(var o in this.authOptions.headers)i.set(o,this.authOptions.headers[o]);var s=this.composeQuery(e),a=new Request(this.options.authEndpoint,{headers:i,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)})};e.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=n(16),i=n(4),o=function(t,e){return function(n,o){var s="http"+(e?"s":"")+"://",a=s+(t.host||t.options.host)+t.options.path,u=i.buildQueryString(n);a+="/2?"+u,fetch(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)})}},s={name:"xhr",getAgent:o};e.__esModule=!0,e.default=s},function(t,e,n){"use strict";var r=n(4),i=n(6),o=n(30),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:i.default.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(o.default.ERROR,t)},t.prototype.info=function(t){this.log(o.default.INFO,t)},t.prototype.debug=function(t){this.log(o.default.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,i=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(i,function(t,r){t||n.sent++,e&&e(t,r)}),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}();e.__esModule=!0,e.default=s},function(t,e){"use strict";var n;!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(n||(n={})),e.__esModule=!0,e.default=n},function(t,e,n){"use strict";function r(t){return function(e){return[t.apply(this,arguments),e]}}function i(t){return"string"==typeof t&&":"===t.charAt(0)}function o(t,e){return e[t.slice(1)]}function s(t,e){if(0===t.length)return[[],e];var n=c(t[0],e),r=s(t.slice(1),n[1]);return[[n[0]].concat(r[0]),r[1]]}function a(t,e){if(!i(t))return[t,e];var n=o(t,e);if(void 0===n)throw"Undefined symbol "+t;return[n,e]}function u(t,e){if(i(t[0])){var n=o(t[0],e);if(t.length>1){if("function"!=typeof n)throw"Calling non-function "+t[0];var r=[h.extend({},e)].concat(h.map(t.slice(1),function(t){return c(t,h.extend({},e))[0]}));return n.apply(this,r)}return[n,e]}return s(t,e)}function c(t,e){return"string"==typeof t?a(t,e):"object"==typeof t&&t instanceof Array&&t.length>0?u(t,e):[t,e]}var h=n(4),f=n(6),l=n(32),p=n(43),d=n(56),y=n(57),g=n(58),v=n(59),b=n(60),m=n(61),_=n(62),w=n(2),S=w.default.Transports;e.build=function(t,e){var n=h.extend({},k,e);return c(t,n)[1].strategy};var A={isSupported:function(){return!1},connect:function(t,e){var n=f.default.defer(function(){e(new p.UnsupportedStrategy)});return{abort:function(){n.ensureAborted()},forceMinPriority:function(){}}}},k={extend:function(t,e,n){return[h.extend({},e,n),t]},def:function(t,e,n){if(void 0!==t[e])throw"Redefining symbol "+e;return t[e]=n,[void 0,t]},def_transport:function(t,e,n,r,i,o){var s=S[n];if(!s)throw new p.UnsupportedTransport(n);var a,u=!(t.enabledTransports&&h.arrayIndexOf(t.enabledTransports,e)===-1||t.disabledTransports&&h.arrayIndexOf(t.disabledTransports,e)!==-1);a=u?new d.default(e,r,o?o.getAssistant(s):s,h.extend({key:t.key,useTLS:t.useTLS,timeline:t.timeline,ignoreNullOrigin:t.ignoreNullOrigin},i)):A;var c=t.def(t,e,a)[1];return c.Transports=t.Transports||{},c.Transports[e]=a,[void 0,c]},transport_manager:r(function(t,e){return new l.default(e)}),sequential:r(function(t,e){var n=Array.prototype.slice.call(arguments,2);return new y.default(n,e)}),cached:r(function(t,e,n){return new v.default(n,t.Transports,{ttl:e,timeline:t.timeline,useTLS:t.useTLS})}),first_connected:r(function(t,e){return new _.default(e)}),best_connected_ever:r(function(){var t=Array.prototype.slice.call(arguments,1);return new g.default(t)}),delayed:r(function(t,e,n){return new b.default(n,{delay:e})}),if:r(function(t,e,n,r){return new m.default(e,n,r)}),is_supported:r(function(t,e){return function(){return e.isSupported()}})}},function(t,e,n){"use strict";var r=n(33),i=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.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=n(34),i=n(35),o=n(38),s=n(39),a=n(40),u=n(41),c=n(46),h=n(42),f=n(54),l=n(55),p={createChannels:function(){return new l.default},createConnectionManager:function(t,e){return new f.default(t,e)},createChannel:function(t,e){return new h.default(t,e)},createPrivateChannel:function(t,e){return new u.default(t,e)},createPresenceChannel:function(t,e){return new a.default(t,e)},createEncryptedChannel:function(t,e){return new c.default(t,e)},createTimelineSender:function(t,e){return new s.default(t,e)},createAuthorizer:function(t,e){return e.authorizer?e.authorizer(t,e):new o.default(t,e); -},createHandshake:function(t,e){return new i.default(t,e)},createAssistantToTheTransportManager:function(t,e,n){return new r.default(t,e,n)}};e.__esModule=!0,e.default=p},function(t,e,n){"use strict";var r=n(6),i=n(4),o=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,o){var s=this;o=i.extend({},o,{activityTimeout:this.pingDelay});var a=this.transport.createConnection(t,e,n,o),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.__esModule=!0,e.default=o},function(t,e,n){"use strict";var r=n(4),i=n(36),o=n(37),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){t.unbindListeners();var n;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 o.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",r=i.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.__esModule=!0,e.default=s},function(t,e){"use strict";e.decodeMessage=function(t){try{var e=JSON.parse(t.data);if("string"==typeof e.data)try{e.data=JSON.parse(e.data)}catch(t){if(!(t instanceof SyntaxError))throw t}return e}catch(e){throw{type:"MessageParseError",error:e,data:t.data}}},e.encodeMessage=function(t){return JSON.stringify(t)},e.processHandshake=function(t){if(t=e.decodeMessage(t),"pusher:connection_established"===t.event){if(!t.data.activity_timeout)throw"No activity timeout specified in handshake";return{action:"connected",id:t.data.socket_id,activityTimeout:1e3*t.data.activity_timeout}}if("pusher:error"===t.event)return{action:this.getCloseAction(t.data),error:this.getCloseError(t.data)};throw"Invalid handshake"},e.getCloseAction=function(t){return t.code<4e3?t.code>=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=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(4),o=n(14),s=n(36),a=n(16),u=function(t){function e(e,n){t.call(this),this.id=e,this.transport=n,this.activityTimeout=n.activityTimeout,this.bindListeners()}return r(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),a.default.debug("Event sent",r),this.send(s.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=s.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(a.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=s.getCloseAction(t),n=s.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(o.default);e.__esModule=!0,e.default=u},function(t,e,n){"use strict";var r=n(2),i=function(){function t(t,e){this.channel=t;var n=e.authTransport;if("undefined"==typeof 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.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=n(2),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(r.default.TimelineTransport.getAgent(this,t),e)},t}();e.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(41),o=n(16),s=n(44),a=n(45),u=function(t){function e(e,n){t.call(this,e,n),this.members=new s.default}return r(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 i=a.default.buildLogSuffix("authenticationEndpoint");return o.default.warn("Invalid auth response for channel '"+r.name+"',expected 'channel_data' field. "+i),void n("Invalid auth response")}var s=JSON.parse(e.channel_data);r.members.setMyID(s.user_id)}n(t,e)})},e.prototype.handleEvent=function(t,e){switch(t){case"pusher_internal:subscription_succeeded":this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(e),this.emit("pusher:subscription_succeeded",this.members));break;case"pusher_internal:member_added":var n=this.members.addMember(e);this.emit("pusher:member_added",n);break;case"pusher_internal:member_removed":var r=this.members.removeMember(e);r&&this.emit("pusher:member_removed",r);break;default:i.default.prototype.handleEvent.call(this,t,e)}},e.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},e}(i.default);e.__esModule=!0,e.default=u},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(33),o=n(42),s=function(t){function e(){t.apply(this,arguments)}return r(e,t),e.prototype.authorize=function(t,e){var n=i.default.createAuthorizer(this,this.pusher.config);return n.authorize(t,e)},e}(o.default);e.__esModule=!0,e.default=s},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(14),o=n(43),s=n(16),a=function(t){function e(e,n){t.call(this,function(t,n){s.default.debug("No callbacks on "+e+" for "+t)}),this.name=e,this.pusher=n,this.subscribed=!1,this.subscriptionPending=!1,this.subscriptionCancelled=!1}return r(e,t),e.prototype.authorize=function(t,e){return e(!1,{})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new o.BadEventName("Event '"+t+"' does not start with 'client-'");return this.pusher.send_event(t,e,this.name)},e.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},e.prototype.handleEvent=function(t,e){0===t.indexOf("pusher_internal:")?"pusher_internal:subscription_succeeded"===t&&(this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",e)):this.emit(t,e)},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.handleEvent("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.__esModule=!0,e.default=a},function(t,e){"use strict";var n=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},r=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.BadEventName=r;var i=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.RequestTimedOut=i;var o=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.TransportPriorityTooLow=o;var s=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.TransportClosed=s;var a=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.UnsupportedFeature=a;var u=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.UnsupportedTransport=u;var c=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.UnsupportedStrategy=c},function(t,e,n){"use strict";var r=n(4),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;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.__esModule=!0,e.default=i},function(t,e){"use strict";var n={baseUrl:"https://pusher.com",urls:{authenticationEndpoint:{path:"/docs/authenticating_users"},javascriptQuickStart:{path:"/docs/javascript_quick_start"}}},r=function(t){var e="See:",r=n.urls[t];if(!r)return"";var i;return r.fullUrl?i=r.fullUrl:r.path&&(i=n.baseUrl+r.path),i?e+" "+i:""};e.__esModule=!0,e.default={buildLogSuffix:r}},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(41),o=n(43),s=n(16),a=n(47),u=n(49),c=function(t){function e(){t.apply(this,arguments),this.key=null}return r(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,function(t,e){if(t)return void n(!0,e);var i=e.shared_secret;if(!i){var o="No shared_secret key in auth payload for encrypted channel: "+r.name;return n(!0,o),void s.default.warn("Error: "+o)}r.key=u.decodeBase64(i),delete e.shared_secret,n(!1,e)})},e.prototype.trigger=function(t,e){throw new o.UnsupportedFeature("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e,n){return 0===e.indexOf("pusher_internal:")||0===e.indexOf("pusher:")?void t.prototype.handleEvent.call(this,e,n):void this.handleEncryptedEvent(e,n)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(!this.key)return void s.default.debug("Received encrypted event before key has been retrieved from the authEndpoint");if(!e.ciphertext||!e.nonce)return void s.default.warn("Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: "+e);var r=u.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 r(t,e,n,r,i){var o,s=0;for(o=0;o>>8)-1}function i(t,e,n,i){return r(t,e,n,i,16)}function o(t,e,n,i){return r(t,e,n,i,32)}function s(t,e,n,r){for(var i,o=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,g=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,v=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,_=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=o,S=s,A=a,k=u,T=c,E=h,C=f,P=l,x=p,O=d,R=y,U=g,M=v,L=b,B=m,I=_,N=0;N<20;N+=2)i=w+M|0,T^=i<<7|i>>>25,i=T+w|0,x^=i<<9|i>>>23,i=x+T|0,M^=i<<13|i>>>19,i=M+x|0,w^=i<<18|i>>>14,i=E+S|0,O^=i<<7|i>>>25,i=O+E|0,L^=i<<9|i>>>23,i=L+O|0,S^=i<<13|i>>>19,i=S+L|0,E^=i<<18|i>>>14,i=R+C|0,B^=i<<7|i>>>25,i=B+R|0,A^=i<<9|i>>>23,i=A+B|0,C^=i<<13|i>>>19,i=C+A|0,R^=i<<18|i>>>14,i=I+U|0,k^=i<<7|i>>>25,i=k+I|0,P^=i<<9|i>>>23,i=P+k|0,U^=i<<13|i>>>19,i=U+P|0,I^=i<<18|i>>>14,i=w+k|0,S^=i<<7|i>>>25,i=S+w|0,A^=i<<9|i>>>23,i=A+S|0,k^=i<<13|i>>>19,i=k+A|0,w^=i<<18|i>>>14,i=E+T|0,C^=i<<7|i>>>25,i=C+E|0,P^=i<<9|i>>>23,i=P+C|0,T^=i<<13|i>>>19,i=T+P|0,E^=i<<18|i>>>14,i=R+O|0,U^=i<<7|i>>>25,i=U+R|0,x^=i<<9|i>>>23,i=x+U|0,O^=i<<13|i>>>19,i=O+x|0,R^=i<<18|i>>>14,i=I+B|0,M^=i<<7|i>>>25,i=M+I|0,L^=i<<9|i>>>23,i=L+M|0,B^=i<<13|i>>>19,i=B+L|0,I^=i<<18|i>>>14;w=w+o|0,S=S+s|0,A=A+a|0,k=k+u|0,T=T+c|0,E=E+h|0,C=C+f|0,P=P+l|0,x=x+p|0,O=O+d|0,R=R+y|0,U=U+g|0,M=M+v|0,L=L+b|0,B=B+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]=A>>>0&255,t[9]=A>>>8&255,t[10]=A>>>16&255,t[11]=A>>>24&255,t[12]=k>>>0&255,t[13]=k>>>8&255,t[14]=k>>>16&255,t[15]=k>>>24&255,t[16]=T>>>0&255,t[17]=T>>>8&255,t[18]=T>>>16&255,t[19]=T>>>24&255,t[20]=E>>>0&255,t[21]=E>>>8&255,t[22]=E>>>16&255,t[23]=E>>>24&255,t[24]=C>>>0&255,t[25]=C>>>8&255,t[26]=C>>>16&255,t[27]=C>>>24&255,t[28]=P>>>0&255,t[29]=P>>>8&255,t[30]=P>>>16&255,t[31]=P>>>24&255,t[32]=x>>>0&255,t[33]=x>>>8&255,t[34]=x>>>16&255,t[35]=x>>>24&255,t[36]=O>>>0&255,t[37]=O>>>8&255,t[38]=O>>>16&255,t[39]=O>>>24&255,t[40]=R>>>0&255,t[41]=R>>>8&255,t[42]=R>>>16&255,t[43]=R>>>24&255,t[44]=U>>>0&255,t[45]=U>>>8&255,t[46]=U>>>16&255,t[47]=U>>>24&255,t[48]=M>>>0&255,t[49]=M>>>8&255,t[50]=M>>>16&255,t[51]=M>>>24&255,t[52]=L>>>0&255,t[53]=L>>>8&255,t[54]=L>>>16&255,t[55]=L>>>24&255,t[56]=B>>>0&255,t[57]=B>>>8&255,t[58]=B>>>16&255,t[59]=B>>>24&255,t[60]=I>>>0&255,t[61]=I>>>8&255,t[62]=I>>>16&255,t[63]=I>>>24&255}function a(t,e,n,r){for(var i,o=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,g=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,v=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,_=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=o,S=s,A=a,k=u,T=c,E=h,C=f,P=l,x=p,O=d,R=y,U=g,M=v,L=b,B=m,I=_,N=0;N<20;N+=2)i=w+M|0,T^=i<<7|i>>>25,i=T+w|0,x^=i<<9|i>>>23,i=x+T|0,M^=i<<13|i>>>19,i=M+x|0,w^=i<<18|i>>>14,i=E+S|0,O^=i<<7|i>>>25,i=O+E|0,L^=i<<9|i>>>23,i=L+O|0,S^=i<<13|i>>>19,i=S+L|0,E^=i<<18|i>>>14,i=R+C|0,B^=i<<7|i>>>25,i=B+R|0,A^=i<<9|i>>>23,i=A+B|0,C^=i<<13|i>>>19,i=C+A|0,R^=i<<18|i>>>14,i=I+U|0,k^=i<<7|i>>>25,i=k+I|0,P^=i<<9|i>>>23,i=P+k|0,U^=i<<13|i>>>19,i=U+P|0,I^=i<<18|i>>>14,i=w+k|0,S^=i<<7|i>>>25,i=S+w|0,A^=i<<9|i>>>23,i=A+S|0,k^=i<<13|i>>>19,i=k+A|0,w^=i<<18|i>>>14,i=E+T|0,C^=i<<7|i>>>25,i=C+E|0,P^=i<<9|i>>>23,i=P+C|0,T^=i<<13|i>>>19,i=T+P|0,E^=i<<18|i>>>14,i=R+O|0,U^=i<<7|i>>>25,i=U+R|0,x^=i<<9|i>>>23,i=x+U|0,O^=i<<13|i>>>19,i=O+x|0,R^=i<<18|i>>>14,i=I+B|0,M^=i<<7|i>>>25,i=M+I|0,L^=i<<9|i>>>23,i=L+M|0,B^=i<<13|i>>>19,i=B+L|0,I^=i<<18|i>>>14;t[0]=w>>>0&255,t[1]=w>>>8&255,t[2]=w>>>16&255,t[3]=w>>>24&255,t[4]=E>>>0&255,t[5]=E>>>8&255,t[6]=E>>>16&255,t[7]=E>>>24&255,t[8]=R>>>0&255,t[9]=R>>>8&255,t[10]=R>>>16&255,t[11]=R>>>24&255,t[12]=I>>>0&255,t[13]=I>>>8&255,t[14]=I>>>16&255,t[15]=I>>>24&255,t[16]=C>>>0&255,t[17]=C>>>8&255,t[18]=C>>>16&255,t[19]=C>>>24&255,t[20]=P>>>0&255,t[21]=P>>>8&255,t[22]=P>>>16&255,t[23]=P>>>24&255,t[24]=x>>>0&255,t[25]=x>>>8&255,t[26]=x>>>16&255,t[27]=x>>>24&255,t[28]=O>>>0&255,t[29]=O>>>8&255,t[30]=O>>>16&255,t[31]=O>>>24&255}function u(t,e,n,r){s(t,e,n,r)}function c(t,e,n,r){a(t,e,n,r)}function h(t,e,n,r,i,o,s){var a,c,h=new Uint8Array(16),f=new Uint8Array(64);for(c=0;c<16;c++)h[c]=0;for(c=0;c<8;c++)h[c]=o[c];for(;i>=64;){for(u(f,h,s,lt),c=0;c<64;c++)t[e+c]=n[r+c]^f[c];for(a=1,c=8;c<16;c++)a=a+(255&h[c])|0,h[c]=255&a,a>>>=8;i-=64,e+=64,r+=64}if(i>0)for(u(f,h,s,lt),c=0;c=64;){for(u(c,a,i,lt),s=0;s<64;s++)t[e+s]=c[s];for(o=1,s=8;s<16;s++)o=o+(255&a[s])|0,a[s]=255&o,o>>>=8;n-=64,e+=64}if(n>0)for(u(c,a,i,lt),s=0;s>16&1),o[n-1]&=65535;o[15]=s[15]-32767-(o[14]>>16&1),i=o[15]>>16&1,o[14]&=65535,_(s,o,1-i)}for(n=0;n<16;n++)t[2*n]=255&s[n],t[2*n+1]=s[n]>>8}function S(t,e){var n=new Uint8Array(32),r=new Uint8Array(32);return w(n,t),w(r,e),o(n,0,r,0)}function A(t){var e=new Uint8Array(32);return w(e,t),1&e[0]}function k(t,e){var n;for(n=0;n<16;n++)t[n]=e[2*n]+(e[2*n+1]<<8);t[15]&=32767}function T(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]+n[r]}function E(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]-n[r]}function C(t,e,n){var r,i,o=0,s=0,a=0,u=0,c=0,h=0,f=0,l=0,p=0,d=0,y=0,g=0,v=0,b=0,m=0,_=0,w=0,S=0,A=0,k=0,T=0,E=0,C=0,P=0,x=0,O=0,R=0,U=0,M=0,L=0,B=0,I=n[0],N=n[1],D=n[2],Y=n[3],j=n[4],z=n[5],F=n[6],H=n[7],q=n[8],J=n[9],K=n[10],X=n[11],G=n[12],W=n[13],Z=n[14],V=n[15];r=e[0],o+=r*I,s+=r*N,a+=r*D,u+=r*Y,c+=r*j,h+=r*z,f+=r*F,l+=r*H,p+=r*q,d+=r*J,y+=r*K,g+=r*X,v+=r*G,b+=r*W,m+=r*Z,_+=r*V,r=e[1],s+=r*I,a+=r*N,u+=r*D,c+=r*Y,h+=r*j,f+=r*z,l+=r*F,p+=r*H,d+=r*q,y+=r*J,g+=r*K,v+=r*X,b+=r*G,m+=r*W,_+=r*Z,w+=r*V,r=e[2],a+=r*I,u+=r*N,c+=r*D,h+=r*Y,f+=r*j,l+=r*z,p+=r*F,d+=r*H,y+=r*q,g+=r*J,v+=r*K,b+=r*X,m+=r*G,_+=r*W,w+=r*Z,S+=r*V,r=e[3],u+=r*I,c+=r*N,h+=r*D,f+=r*Y,l+=r*j,p+=r*z,d+=r*F,y+=r*H,g+=r*q,v+=r*J,b+=r*K,m+=r*X,_+=r*G,w+=r*W,S+=r*Z,A+=r*V,r=e[4],c+=r*I,h+=r*N,f+=r*D,l+=r*Y,p+=r*j,d+=r*z,y+=r*F,g+=r*H,v+=r*q,b+=r*J,m+=r*K,_+=r*X,w+=r*G,S+=r*W,A+=r*Z,k+=r*V,r=e[5],h+=r*I,f+=r*N,l+=r*D,p+=r*Y,d+=r*j,y+=r*z,g+=r*F,v+=r*H,b+=r*q,m+=r*J,_+=r*K,w+=r*X,S+=r*G,A+=r*W,k+=r*Z,T+=r*V,r=e[6],f+=r*I,l+=r*N,p+=r*D,d+=r*Y,y+=r*j,g+=r*z,v+=r*F,b+=r*H,m+=r*q,_+=r*J,w+=r*K,S+=r*X,A+=r*G,k+=r*W,T+=r*Z,E+=r*V,r=e[7],l+=r*I,p+=r*N,d+=r*D,y+=r*Y,g+=r*j,v+=r*z,b+=r*F,m+=r*H,_+=r*q,w+=r*J,S+=r*K,A+=r*X,k+=r*G,T+=r*W,E+=r*Z,C+=r*V,r=e[8],p+=r*I,d+=r*N,y+=r*D,g+=r*Y,v+=r*j,b+=r*z,m+=r*F,_+=r*H,w+=r*q,S+=r*J,A+=r*K,k+=r*X,T+=r*G,E+=r*W,C+=r*Z,P+=r*V,r=e[9],d+=r*I,y+=r*N,g+=r*D,v+=r*Y,b+=r*j,m+=r*z,_+=r*F,w+=r*H,S+=r*q,A+=r*J,k+=r*K,T+=r*X,E+=r*G,C+=r*W,P+=r*Z,x+=r*V,r=e[10],y+=r*I,g+=r*N,v+=r*D,b+=r*Y,m+=r*j,_+=r*z,w+=r*F,S+=r*H,A+=r*q,k+=r*J,T+=r*K,E+=r*X,C+=r*G,P+=r*W,x+=r*Z,O+=r*V,r=e[11],g+=r*I,v+=r*N,b+=r*D,m+=r*Y,_+=r*j,w+=r*z,S+=r*F,A+=r*H,k+=r*q,T+=r*J,E+=r*K,C+=r*X;P+=r*G;x+=r*W,O+=r*Z,R+=r*V,r=e[12],v+=r*I,b+=r*N,m+=r*D,_+=r*Y,w+=r*j,S+=r*z,A+=r*F,k+=r*H,T+=r*q,E+=r*J,C+=r*K,P+=r*X,x+=r*G,O+=r*W,R+=r*Z,U+=r*V,r=e[13],b+=r*I,m+=r*N,_+=r*D,w+=r*Y,S+=r*j,A+=r*z,k+=r*F,T+=r*H,E+=r*q,C+=r*J,P+=r*K,x+=r*X,O+=r*G,R+=r*W,U+=r*Z,M+=r*V,r=e[14],m+=r*I,_+=r*N,w+=r*D,S+=r*Y,A+=r*j,k+=r*z,T+=r*F,E+=r*H,C+=r*q,P+=r*J,x+=r*K,O+=r*X,R+=r*G,U+=r*W,M+=r*Z,L+=r*V,r=e[15],_+=r*I,w+=r*N,S+=r*D,A+=r*Y,k+=r*j,T+=r*z,E+=r*F,C+=r*H,P+=r*q,x+=r*J,O+=r*K,R+=r*X,U+=r*G,M+=r*W,L+=r*Z,B+=r*V,o+=38*w,s+=38*S,a+=38*A,u+=38*k,c+=38*T,h+=38*E,f+=38*C,l+=38*P,p+=38*x,d+=38*O,y+=38*R,g+=38*U,v+=38*M,b+=38*L,m+=38*B,i=1,r=o+i+65535,i=Math.floor(r/65536),o=r-65536*i,r=s+i+65535,i=Math.floor(r/65536),s=r-65536*i,r=a+i+65535,i=Math.floor(r/65536),a=r-65536*i,r=u+i+65535,i=Math.floor(r/65536),u=r-65536*i,r=c+i+65535,i=Math.floor(r/65536),c=r-65536*i,r=h+i+65535,i=Math.floor(r/65536),h=r-65536*i,r=f+i+65535,i=Math.floor(r/65536),f=r-65536*i,r=l+i+65535,i=Math.floor(r/65536),l=r-65536*i,r=p+i+65535,i=Math.floor(r/65536),p=r-65536*i,r=d+i+65535,i=Math.floor(r/65536),d=r-65536*i,r=y+i+65535,i=Math.floor(r/65536),y=r-65536*i,r=g+i+65535,i=Math.floor(r/65536),g=r-65536*i,r=v+i+65535,i=Math.floor(r/65536),v=r-65536*i,r=b+i+65535,i=Math.floor(r/65536),b=r-65536*i,r=m+i+65535,i=Math.floor(r/65536),m=r-65536*i,r=_+i+65535,i=Math.floor(r/65536),_=r-65536*i,o+=i-1+37*(i-1),i=1,r=o+i+65535,i=Math.floor(r/65536),o=r-65536*i,r=s+i+65535,i=Math.floor(r/65536),s=r-65536*i,r=a+i+65535,i=Math.floor(r/65536),a=r-65536*i,r=u+i+65535,i=Math.floor(r/65536),u=r-65536*i,r=c+i+65535,i=Math.floor(r/65536),c=r-65536*i,r=h+i+65535,i=Math.floor(r/65536),h=r-65536*i,r=f+i+65535,i=Math.floor(r/65536),f=r-65536*i,r=l+i+65535,i=Math.floor(r/65536),l=r-65536*i,r=p+i+65535,i=Math.floor(r/65536),p=r-65536*i,r=d+i+65535,i=Math.floor(r/65536),d=r-65536*i,r=y+i+65535,i=Math.floor(r/65536),y=r-65536*i,r=g+i+65535,i=Math.floor(r/65536),g=r-65536*i,r=v+i+65535,i=Math.floor(r/65536),v=r-65536*i,r=b+i+65535,i=Math.floor(r/65536),b=r-65536*i,r=m+i+65535,i=Math.floor(r/65536),m=r-65536*i,r=_+i+65535,i=Math.floor(r/65536),_=r-65536*i,o+=i-1+37*(i-1),t[0]=o,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]=g,t[12]=v,t[13]=b;t[14]=m;t[15]=_}function P(t,e){C(t,e,e)}function x(t,e){var n,r=tt();for(n=0;n<16;n++)r[n]=e[n];for(n=253;n>=0;n--)P(r,r),2!==n&&4!==n&&C(r,r,e);for(n=0;n<16;n++)t[n]=r[n]}function O(t,e){var n,r=tt();for(n=0;n<16;n++)r[n]=e[n];for(n=250;n>=0;n--)P(r,r),1!==n&&C(r,r,e);for(n=0;n<16;n++)t[n]=r[n]}function R(t,e,n){var r,i,o=new Uint8Array(32),s=new Float64Array(80),a=tt(),u=tt(),c=tt(),h=tt(),f=tt(),l=tt();for(i=0;i<31;i++)o[i]=e[i];for(o[31]=127&e[31]|64,o[0]&=248,k(s,n),i=0;i<16;i++)u[i]=s[i],h[i]=a[i]=c[i]=0;for(a[0]=h[0]=1,i=254;i>=0;--i)r=o[i>>>3]>>>(7&i)&1,_(a,u,r),_(c,h,r),T(f,a,c),E(a,a,c),T(c,u,h),E(u,u,h),P(h,f),P(l,a),C(a,c,a),C(c,u,f),T(f,a,c),E(a,a,c),P(u,a),E(c,h,l),C(a,c,st),T(a,a,h),C(c,c,a),C(a,h,l),C(h,u,s),P(u,f),_(a,u,r),_(c,h,r);for(i=0;i<16;i++)s[i+16]=a[i],s[i+32]=c[i],s[i+48]=u[i],s[i+64]=h[i];var p=s.subarray(32),d=s.subarray(16);return x(p,p),C(d,d,p),w(t,d),0}function U(t,e){return R(t,e,rt)}function M(t,e){return et(e,32),U(t,e)}function L(t,e,n){var r=new Uint8Array(32);return R(r,n,e),c(t,nt,r,lt)}function B(t,e,n,r,i,o){var s=new Uint8Array(32);return L(s,i,o),dt(t,e,n,r,s)}function I(t,e,n,r,i,o){var s=new Uint8Array(32);return L(s,i,o),yt(t,e,n,r,s)}function N(t,e,n,r){for(var i,o,s,a,u,c,h,f,l,p,d,y,g,v,b,m,_,w,S,A,k,T,E,C,P,x,O=new Int32Array(16),R=new Int32Array(16),U=t[0],M=t[1],L=t[2],B=t[3],I=t[4],N=t[5],D=t[6],Y=t[7],j=e[0],z=e[1],F=e[2],H=e[3],q=e[4],J=e[5],K=e[6],X=e[7],G=0;r>=128;){for(S=0;S<16;S++)A=8*S+G,O[S]=n[A+0]<<24|n[A+1]<<16|n[A+2]<<8|n[A+3],R[S]=n[A+4]<<24|n[A+5]<<16|n[A+6]<<8|n[A+7];for(S=0;S<80;S++)if(i=U,o=M,s=L,a=B,u=I,c=N,h=D,f=Y,l=j,p=z,d=F,y=H,g=q,v=J,b=K,m=X,k=Y,T=X,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=(I>>>14|q<<18)^(I>>>18|q<<14)^(q>>>9|I<<23),T=(q>>>14|I<<18)^(q>>>18|I<<14)^(I>>>9|q<<23),E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,k=I&N^~I&D,T=q&J^~q&K,E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,k=gt[2*S],T=gt[2*S+1],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,k=O[S%16],T=R[S%16],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,_=65535&P|x<<16,w=65535&E|C<<16,k=_,T=w,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=(U>>>28|j<<4)^(j>>>2|U<<30)^(j>>>7|U<<25),T=(j>>>28|U<<4)^(U>>>2|j<<30)^(U>>>7|j<<25),E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,k=U&M^U&L^M&L,T=j&z^j&F^z&F,E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,f=65535&P|x<<16,m=65535&E|C<<16,k=a,T=y,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=_,T=w,E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,a=65535&P|x<<16,y=65535&E|C<<16,M=i,L=o,B=s,I=a,N=u,D=c,Y=h,U=f,z=l,F=p,H=d,q=y,J=g,K=v,X=b,j=m,S%16===15)for(A=0;A<16;A++)k=O[A],T=R[A],E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=O[(A+9)%16],T=R[(A+9)%16],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,_=O[(A+1)%16],w=R[(A+1)%16],k=(_>>>1|w<<31)^(_>>>8|w<<24)^_>>>7,T=(w>>>1|_<<31)^(w>>>8|_<<24)^(w>>>7|_<<25),E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,_=O[(A+14)%16],w=R[(A+14)%16],k=(_>>>19|w<<13)^(w>>>29|_<<3)^_>>>6,T=(w>>>19|_<<13)^(_>>>29|w<<3)^(w>>>6|_<<26),E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,O[A]=65535&P|x<<16,R[A]=65535&E|C<<16;k=U,T=j,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[0],T=e[0],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[0]=U=65535&P|x<<16,e[0]=j=65535&E|C<<16,k=M,T=z,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[1],T=e[1],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[1]=M=65535&P|x<<16,e[1]=z=65535&E|C<<16,k=L,T=F,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[2],T=e[2],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[2]=L=65535&P|x<<16,e[2]=F=65535&E|C<<16,k=B,T=H,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[3],T=e[3],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[3]=B=65535&P|x<<16,e[3]=H=65535&E|C<<16,k=I,T=q,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[4],T=e[4],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[4]=I=65535&P|x<<16,e[4]=q=65535&E|C<<16,k=N,T=J,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[5],T=e[5],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[5]=N=65535&P|x<<16,e[5]=J=65535&E|C<<16,k=D,T=K,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[6],T=e[6],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[6]=D=65535&P|x<<16,e[6]=K=65535&E|C<<16,k=Y,T=X,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[7],T=e[7],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[7]=Y=65535&P|x<<16,e[7]=X=65535&E|C<<16,G+=128,r-=128}return r}function D(t,n,r){var i,o=new Int32Array(8),s=new Int32Array(8),a=new Uint8Array(256),u=r;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,s[0]=4089235720,s[1]=2227873595,s[2]=4271175723,s[3]=1595750129,s[4]=2917565137,s[5]=725511199,s[6]=4215389547,s[7]=327033209,N(o,s,n,r),r%=128,i=0;i=0;--i)r=n[i/8|0]>>(7&i)&1,j(t,e,r),Y(e,t),Y(t,t),j(t,e,r)}function H(t,e){var n=[tt(),tt(),tt(),tt()];b(n[0],ct),b(n[1],ht),b(n[2],ot),C(n[3],ct,ht),F(t,n,e)}function q(t,e,n){var r,i=new Uint8Array(64),o=[tt(),tt(),tt(),tt()];for(n||et(e,32),D(i,e,32),i[0]&=248,i[31]&=127,i[31]|=64,H(o,i),z(t,o),r=0;r<32;r++)e[r+32]=t[r];return 0}function J(t,e){var n,r,i,o;for(r=63;r>=32;--r){for(n=0,i=r-32,o=r-12;i>8,e[i]-=256*n;e[i]+=n,e[r]=0; -}for(n=0,i=0;i<32;i++)e[i]+=n-(e[31]>>4)*vt[i],n=e[i]>>8,e[i]&=255;for(i=0;i<32;i++)e[i]-=n*vt[i];for(r=0;r<32;r++)e[r+1]+=e[r]>>8,t[r]=255&e[r]}function K(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;J(t,n)}function X(t,e,n,r){var i,o,s=new Uint8Array(64),a=new Uint8Array(64),u=new Uint8Array(64),c=new Float64Array(64),h=[tt(),tt(),tt(),tt()];D(s,r,32),s[0]&=248,s[31]&=127,s[31]|=64;var f=n+64;for(i=0;i>7&&E(t[0],it,t[0]),C(t[3],t[0],t[1]),0)}function W(t,e,n,r){var i,s,a=new Uint8Array(32),u=new Uint8Array(64),c=[tt(),tt(),tt(),tt()],h=[tt(),tt(),tt(),tt()];if(s=-1,n<64)return-1;if(G(h,r))return-1;for(i=0;i>>13|n<<3),r=255&t[4]|(255&t[5])<<8,this.r[2]=7939&(n>>>10|r<<6),i=255&t[6]|(255&t[7])<<8,this.r[3]=8191&(r>>>7|i<<9),o=255&t[8]|(255&t[9])<<8,this.r[4]=255&(i>>>4|o<<12),this.r[5]=o>>>1&8190,s=255&t[10]|(255&t[11])<<8,this.r[6]=8191&(o>>>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};pt.prototype.blocks=function(t,e,n){for(var r,i,o,s,a,u,c,h,f,l,p,d,y,g,v,b,m,_,w,S=this.fin?0:2048,A=this.h[0],k=this.h[1],T=this.h[2],E=this.h[3],C=this.h[4],P=this.h[5],x=this.h[6],O=this.h[7],R=this.h[8],U=this.h[9],M=this.r[0],L=this.r[1],B=this.r[2],I=this.r[3],N=this.r[4],D=this.r[5],Y=this.r[6],j=this.r[7],z=this.r[8],F=this.r[9];n>=16;)r=255&t[e+0]|(255&t[e+1])<<8,A+=8191&r,i=255&t[e+2]|(255&t[e+3])<<8,k+=8191&(r>>>13|i<<3),o=255&t[e+4]|(255&t[e+5])<<8,T+=8191&(i>>>10|o<<6),s=255&t[e+6]|(255&t[e+7])<<8,E+=8191&(o>>>7|s<<9),a=255&t[e+8]|(255&t[e+9])<<8,C+=8191&(s>>>4|a<<12),P+=a>>>1&8191,u=255&t[e+10]|(255&t[e+11])<<8,x+=8191&(a>>>14|u<<2),c=255&t[e+12]|(255&t[e+13])<<8,O+=8191&(u>>>11|c<<5),h=255&t[e+14]|(255&t[e+15])<<8,R+=8191&(c>>>8|h<<8),U+=h>>>5|S,f=0,l=f,l+=A*M,l+=k*(5*F),l+=T*(5*z),l+=E*(5*j),l+=C*(5*Y),f=l>>>13,l&=8191,l+=P*(5*D),l+=x*(5*N),l+=O*(5*I),l+=R*(5*B),l+=U*(5*L),f+=l>>>13,l&=8191,p=f,p+=A*L,p+=k*M,p+=T*(5*F),p+=E*(5*z),p+=C*(5*j),f=p>>>13,p&=8191,p+=P*(5*Y),p+=x*(5*D),p+=O*(5*N),p+=R*(5*I),p+=U*(5*B),f+=p>>>13,p&=8191,d=f,d+=A*B,d+=k*L,d+=T*M,d+=E*(5*F),d+=C*(5*z),f=d>>>13,d&=8191,d+=P*(5*j),d+=x*(5*Y),d+=O*(5*D),d+=R*(5*N),d+=U*(5*I),f+=d>>>13,d&=8191,y=f,y+=A*I,y+=k*B,y+=T*L,y+=E*M,y+=C*(5*F),f=y>>>13,y&=8191,y+=P*(5*z),y+=x*(5*j),y+=O*(5*Y),y+=R*(5*D),y+=U*(5*N),f+=y>>>13,y&=8191,g=f,g+=A*N,g+=k*I,g+=T*B,g+=E*L,g+=C*M,f=g>>>13,g&=8191,g+=P*(5*F),g+=x*(5*z),g+=O*(5*j),g+=R*(5*Y),g+=U*(5*D),f+=g>>>13,g&=8191,v=f,v+=A*D,v+=k*N,v+=T*I,v+=E*B,v+=C*L,f=v>>>13,v&=8191,v+=P*M,v+=x*(5*F),v+=O*(5*z),v+=R*(5*j),v+=U*(5*Y),f+=v>>>13,v&=8191,b=f,b+=A*Y,b+=k*D,b+=T*N,b+=E*I,b+=C*B,f=b>>>13,b&=8191,b+=P*L,b+=x*M,b+=O*(5*F),b+=R*(5*z),b+=U*(5*j),f+=b>>>13,b&=8191,m=f,m+=A*j,m+=k*Y,m+=T*D,m+=E*N,m+=C*I,f=m>>>13,m&=8191,m+=P*B,m+=x*L,m+=O*M,m+=R*(5*F),m+=U*(5*z),f+=m>>>13,m&=8191,_=f,_+=A*z,_+=k*j,_+=T*Y,_+=E*D,_+=C*N,f=_>>>13,_&=8191,_+=P*I,_+=x*B,_+=O*L,_+=R*M,_+=U*(5*F),f+=_>>>13,_&=8191,w=f,w+=A*F,w+=k*z,w+=T*j,w+=E*Y,w+=C*D,f=w>>>13,w&=8191,w+=P*N,w+=x*I,w+=O*B,w+=R*L,w+=U*M,f+=w>>>13,w&=8191,f=(f<<2)+f|0,f=f+l|0,l=8191&f,f>>>=13,p+=f,A=l,k=p,T=d,E=y,C=g,P=v,x=b,O=m,R=_,U=w,e+=16,n-=16;this.h[0]=A,this.h[1]=k,this.h[2]=T,this.h[3]=E,this.h[4]=C,this.h[5]=P,this.h[6]=x,this.h[7]=O,this.h[8]=R,this.h[9]=U},pt.prototype.finish=function(t,e){var n,r,i,o,s=new Uint16Array(10);if(this.leftover){for(o=this.leftover,this.buffer[o++]=1;o<16;o++)this.buffer[o]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,o=2;o<10;o++)this.h[o]+=n,n=this.h[o]>>>13,this.h[o]&=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,o=1;o<10;o++)s[o]=this.h[o]+n,n=s[o]>>>13,s[o]&=8191;for(s[9]-=8192,r=(1^n)-1,o=0;o<10;o++)s[o]&=r;for(r=~r,o=0;o<10;o++)this.h[o]=this.h[o]&r|s[o];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),i=this.h[0]+this.pad[0],this.h[0]=65535&i,o=1;o<8;o++)i=(this.h[o]+this.pad[o]|0)+(i>>>16)|0,this.h[o]=65535&i;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},pt.prototype.update=function(t,e,n){var r,i;if(this.leftover){for(i=16-this.leftover,i>n&&(i=n),r=0;r=16&&(i=n-n%16,this.blocks(t,e,i),e+=i,n-=i),n){for(r=0;r=0},t.sign.keyPair=function(){var t=new Uint8Array(Rt),e=new Uint8Array(Ut);return q(t,e),{publicKey:t,secretKey:e}},t.sign.keyPair.fromSecretKey=function(t){if(Q(t),t.length!==Ut)throw new Error("bad secret key size");for(var e=new Uint8Array(Rt),n=0;n>>6)+i(128|63&e):i(224|e>>>12&15)+i(128|e>>>6&63)+i(128|63&e)},h=function(t){return t.replace(/[^\x00-\x7F]/g,c)},f=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),r=[o.charAt(n>>>18),o.charAt(n>>>12&63),e>=2?"=":o.charAt(n>>>6&63),e>=1?"=":o.charAt(63&n)];return r.join("")},l=self.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,f)}},function(t,e,n){"use strict";var r=n(7),i={now:function(){return Date.now?Date.now():(new Date).valueOf()},defer:function(t){return new r.OneOffTimer(0,t)},method:function(t){for(var e=[],n=1;n0)for(var r=0;rs},e}(o.default);e.__esModule=!0,e.default=a},function(t,e,n){"use strict";function r(t){var e=/([^\?]*)\/*(\??.*)/.exec(t);return{base:e[1],queryString:e[2]}}function i(t,e){return t.base+"/"+e+"/xhr_send"}function o(t){var e=t.indexOf("?")===-1?"?":"&";return t+e+"t="+ +new Date+"&n="+l++}function s(t,e){var n=/(https?:\/\/)([^\/:]+)((\/|:)?.*)/.exec(t);return n[1]+e+n[3]}function a(t){return Math.floor(Math.random()*t)}function u(t){for(var e=[],n=0;n0&&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()}};e.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(14),o=function(t){function e(){t.apply(this,arguments)}return r(e,t),e.prototype.isOnline=function(){return!0},e}(i.default);e.NetInfo=o,e.Network=new o},function(t,e,n){"use strict";var r=n(16),i=function(t,e,n){var i=new Headers;i.set("Content-Type","application/x-www-form-urlencoded");for(var o in this.authOptions.headers)i.set(o,this.authOptions.headers[o]);var s=this.composeQuery(e),a=new Request(this.options.authEndpoint,{headers:i,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)})};e.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=n(16),i=n(4),o=function(t,e){return function(n,o){var s="http"+(e?"s":"")+"://",a=s+(t.host||t.options.host)+t.options.path,u=i.buildQueryString(n);a+="/2?"+u,fetch(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)})}},s={name:"xhr",getAgent:o};e.__esModule=!0,e.default=s},function(t,e,n){"use strict";var r=n(4),i=n(6),o=n(30),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:i.default.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(o.default.ERROR,t)},t.prototype.info=function(t){this.log(o.default.INFO,t)},t.prototype.debug=function(t){this.log(o.default.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,i=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(i,function(t,r){t||n.sent++,e&&e(t,r)}),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}();e.__esModule=!0,e.default=s},function(t,e){"use strict";var n;!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(n||(n={})),e.__esModule=!0,e.default=n},function(t,e,n){"use strict";function r(t){return function(e){return[t.apply(this,arguments),e]}}function i(t){return"string"==typeof t&&":"===t.charAt(0)}function o(t,e){return e[t.slice(1)]}function s(t,e){if(0===t.length)return[[],e];var n=c(t[0],e),r=s(t.slice(1),n[1]);return[[n[0]].concat(r[0]),r[1]]}function a(t,e){if(!i(t))return[t,e];var n=o(t,e);if(void 0===n)throw"Undefined symbol "+t;return[n,e]}function u(t,e){if(i(t[0])){var n=o(t[0],e);if(t.length>1){if("function"!=typeof n)throw"Calling non-function "+t[0];var r=[h.extend({},e)].concat(h.map(t.slice(1),function(t){return c(t,h.extend({},e))[0]}));return n.apply(this,r)}return[n,e]}return s(t,e)}function c(t,e){return"string"==typeof t?a(t,e):"object"==typeof t&&t instanceof Array&&t.length>0?u(t,e):[t,e]}var h=n(4),f=n(6),l=n(32),p=n(43),d=n(56),y=n(57),g=n(58),v=n(59),b=n(60),m=n(61),_=n(62),w=n(2),S=w.default.Transports;e.build=function(t,e){var n=h.extend({},k,e);return c(t,n)[1].strategy};var A={isSupported:function(){return!1},connect:function(t,e){var n=f.default.defer(function(){e(new p.UnsupportedStrategy)});return{abort:function(){n.ensureAborted()},forceMinPriority:function(){}}}},k={extend:function(t,e,n){return[h.extend({},e,n),t]},def:function(t,e,n){if(void 0!==t[e])throw"Redefining symbol "+e;return t[e]=n,[void 0,t]},def_transport:function(t,e,n,r,i,o){var s=S[n];if(!s)throw new p.UnsupportedTransport(n);var a,u=!(t.enabledTransports&&h.arrayIndexOf(t.enabledTransports,e)===-1||t.disabledTransports&&h.arrayIndexOf(t.disabledTransports,e)!==-1);a=u?new d.default(e,r,o?o.getAssistant(s):s,h.extend({key:t.key,useTLS:t.useTLS,timeline:t.timeline,ignoreNullOrigin:t.ignoreNullOrigin},i)):A;var c=t.def(t,e,a)[1];return c.Transports=t.Transports||{},c.Transports[e]=a,[void 0,c]},transport_manager:r(function(t,e){return new l.default(e)}),sequential:r(function(t,e){var n=Array.prototype.slice.call(arguments,2);return new y.default(n,e)}),cached:r(function(t,e,n){return new v.default(n,t.Transports,{ttl:e,timeline:t.timeline,useTLS:t.useTLS})}),first_connected:r(function(t,e){return new _.default(e)}),best_connected_ever:r(function(){var t=Array.prototype.slice.call(arguments,1);return new g.default(t)}),delayed:r(function(t,e,n){return new b.default(n,{delay:e})}),if:r(function(t,e,n,r){return new m.default(e,n,r)}),is_supported:r(function(t,e){return function(){return e.isSupported()}})}},function(t,e,n){"use strict";var r=n(33),i=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.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=n(34),i=n(35),o=n(38),s=n(39),a=n(40),u=n(41),c=n(46),h=n(42),f=n(54),l=n(55),p={createChannels:function(){return new l.default},createConnectionManager:function(t,e){return new f.default(t,e)},createChannel:function(t,e){return new h.default(t,e)},createPrivateChannel:function(t,e){return new u.default(t,e)},createPresenceChannel:function(t,e){return new a.default(t,e)},createEncryptedChannel:function(t,e){return new c.default(t,e)},createTimelineSender:function(t,e){return new s.default(t,e)},createAuthorizer:function(t,e){return e.authorizer?e.authorizer(t,e):new o.default(t,e); +},createHandshake:function(t,e){return new i.default(t,e)},createAssistantToTheTransportManager:function(t,e,n){return new r.default(t,e,n)}};e.__esModule=!0,e.default=p},function(t,e,n){"use strict";var r=n(6),i=n(4),o=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,o){var s=this;o=i.extend({},o,{activityTimeout:this.pingDelay});var a=this.transport.createConnection(t,e,n,o),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.__esModule=!0,e.default=o},function(t,e,n){"use strict";var r=n(4),i=n(36),o=n(37),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){t.unbindListeners();var n;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 o.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",r=i.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.__esModule=!0,e.default=s},function(t,e){"use strict";e.decodeMessage=function(t){try{var e=JSON.parse(t.data),n=e.data;if("string"==typeof n)try{n=JSON.parse(e.data)}catch(t){}var r={event:e.event,channel:e.channel,data:n};return e.user_id&&(r.user_id=e.user_id),r}catch(e){throw{type:"MessageParseError",error:e,data:t.data}}},e.encodeMessage=function(t){return JSON.stringify(t)},e.processHandshake=function(t){var n=e.decodeMessage(t);if("pusher:connection_established"===n.event){if(!n.data.activity_timeout)throw"No activity timeout specified in handshake";return{action:"connected",id:n.data.socket_id,activityTimeout:1e3*n.data.activity_timeout}}if("pusher:error"===n.event)return{action:this.getCloseAction(n.data),error:this.getCloseError(n.data)};throw"Invalid handshake"},e.getCloseAction=function(t){return t.code<4e3?t.code>=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=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(4),o=n(14),s=n(36),a=n(16),u=function(t){function e(e,n){t.call(this),this.id=e,this.transport=n,this.activityTimeout=n.activityTimeout,this.bindListeners()}return r(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),a.default.debug("Event sent",r),this.send(s.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=s.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(a.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=s.getCloseAction(t),n=s.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(o.default);e.__esModule=!0,e.default=u},function(t,e,n){"use strict";var r=n(2),i=function(){function t(t,e){this.channel=t;var n=e.authTransport;if("undefined"==typeof 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.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=n(2),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(r.default.TimelineTransport.getAgent(this,t),e)},t}();e.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(41),o=n(16),s=n(45),a=n(44),u=function(t){function e(e,n){t.call(this,e,n),this.members=new s.default}return r(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 i=a.default.buildLogSuffix("authenticationEndpoint");return o.default.warn("Invalid auth response for channel '"+r.name+"',expected 'channel_data' field. "+i),void n("Invalid auth response")}var s=JSON.parse(e.channel_data);r.members.setMyID(s.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 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}(i.default);e.__esModule=!0,e.default=u},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(33),o=n(42),s=function(t){function e(){t.apply(this,arguments)}return r(e,t),e.prototype.authorize=function(t,e){var n=i.default.createAuthorizer(this,this.pusher.config);return n.authorize(t,e)},e}(o.default);e.__esModule=!0,e.default=s},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(14),o=n(43),s=n(16),a=n(44),u=function(t){function e(e,n){t.call(this,function(t,n){s.default.debug("No callbacks on "+e+" for "+t)}),this.name=e,this.pusher=n,this.subscribed=!1,this.subscriptionPending=!1,this.subscriptionCancelled=!1}return r(e,t),e.prototype.authorize=function(t,e){return e(!1,{})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new o.BadEventName("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var n=a.default.buildLogSuffix("triggeringClientEvents");s.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:")){var r={};this.emit(e,n,r)}},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.__esModule=!0,e.default=u},function(t,e){"use strict";var n=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},r=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.BadEventName=r;var i=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.RequestTimedOut=i;var o=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.TransportPriorityTooLow=o;var s=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.TransportClosed=s;var a=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.UnsupportedFeature=a;var u=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.UnsupportedTransport=u;var c=function(t){function e(){t.apply(this,arguments)}return n(e,t),e}(Error);e.UnsupportedStrategy=c},function(t,e){"use strict";var n={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"}}},r=function(t){var e="See:",r=n.urls[t];if(!r)return"";var i;return r.fullUrl?i=r.fullUrl:r.path&&(i=n.baseUrl+r.path),i?e+" "+i:""};e.__esModule=!0,e.default={buildLogSuffix:r}},function(t,e,n){"use strict";var r=n(4),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;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.__esModule=!0,e.default=i},function(t,e,n){"use strict";var r=this&&this.__extends||function(t,e){function n(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)},i=n(41),o=n(43),s=n(16),a=n(47),u=n(49),c=function(t){function e(){t.apply(this,arguments),this.key=null}return r(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,function(t,e){if(t)return void n(!0,e);var i=e.shared_secret;if(!i){var o="No shared_secret key in auth payload for encrypted channel: "+r.name;return n(!0,o),void s.default.warn("Error: "+o)}r.key=u.decodeBase64(i),delete e.shared_secret,n(!1,e)})},e.prototype.trigger=function(t,e){throw new o.UnsupportedFeature("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e){var n=e.event,r=e.data;return 0===n.indexOf("pusher_internal:")||0===n.indexOf("pusher:")?void t.prototype.handleEvent.call(this,e):void this.handleEncryptedEvent(n,r)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(!this.key)return void s.default.debug("Received encrypted event before key has been retrieved from the authEndpoint");if(!e.ciphertext||!e.nonce)return void s.default.warn("Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: "+e);var r=u.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 r(t,e,n,r,i){var o,s=0;for(o=0;o>>8)-1}function i(t,e,n,i){return r(t,e,n,i,16)}function o(t,e,n,i){return r(t,e,n,i,32)}function s(t,e,n,r){for(var i,o=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,g=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,v=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,_=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=o,S=s,A=a,k=u,T=c,E=h,C=f,P=l,x=p,O=d,R=y,U=g,M=v,L=b,B=m,I=_,N=0;N<20;N+=2)i=w+M|0,T^=i<<7|i>>>25,i=T+w|0,x^=i<<9|i>>>23,i=x+T|0,M^=i<<13|i>>>19,i=M+x|0,w^=i<<18|i>>>14,i=E+S|0,O^=i<<7|i>>>25,i=O+E|0,L^=i<<9|i>>>23,i=L+O|0,S^=i<<13|i>>>19,i=S+L|0,E^=i<<18|i>>>14,i=R+C|0,B^=i<<7|i>>>25,i=B+R|0,A^=i<<9|i>>>23,i=A+B|0,C^=i<<13|i>>>19,i=C+A|0,R^=i<<18|i>>>14,i=I+U|0,k^=i<<7|i>>>25,i=k+I|0,P^=i<<9|i>>>23,i=P+k|0,U^=i<<13|i>>>19,i=U+P|0,I^=i<<18|i>>>14,i=w+k|0,S^=i<<7|i>>>25,i=S+w|0,A^=i<<9|i>>>23,i=A+S|0,k^=i<<13|i>>>19,i=k+A|0,w^=i<<18|i>>>14,i=E+T|0,C^=i<<7|i>>>25,i=C+E|0,P^=i<<9|i>>>23,i=P+C|0,T^=i<<13|i>>>19,i=T+P|0,E^=i<<18|i>>>14,i=R+O|0,U^=i<<7|i>>>25,i=U+R|0,x^=i<<9|i>>>23,i=x+U|0,O^=i<<13|i>>>19,i=O+x|0,R^=i<<18|i>>>14,i=I+B|0,M^=i<<7|i>>>25,i=M+I|0,L^=i<<9|i>>>23,i=L+M|0,B^=i<<13|i>>>19,i=B+L|0,I^=i<<18|i>>>14;w=w+o|0,S=S+s|0,A=A+a|0,k=k+u|0,T=T+c|0,E=E+h|0,C=C+f|0,P=P+l|0,x=x+p|0,O=O+d|0,R=R+y|0,U=U+g|0,M=M+v|0,L=L+b|0,B=B+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]=A>>>0&255,t[9]=A>>>8&255,t[10]=A>>>16&255,t[11]=A>>>24&255,t[12]=k>>>0&255,t[13]=k>>>8&255,t[14]=k>>>16&255,t[15]=k>>>24&255,t[16]=T>>>0&255,t[17]=T>>>8&255,t[18]=T>>>16&255,t[19]=T>>>24&255,t[20]=E>>>0&255,t[21]=E>>>8&255,t[22]=E>>>16&255,t[23]=E>>>24&255,t[24]=C>>>0&255,t[25]=C>>>8&255,t[26]=C>>>16&255,t[27]=C>>>24&255,t[28]=P>>>0&255,t[29]=P>>>8&255,t[30]=P>>>16&255,t[31]=P>>>24&255,t[32]=x>>>0&255,t[33]=x>>>8&255,t[34]=x>>>16&255,t[35]=x>>>24&255,t[36]=O>>>0&255,t[37]=O>>>8&255,t[38]=O>>>16&255,t[39]=O>>>24&255,t[40]=R>>>0&255,t[41]=R>>>8&255,t[42]=R>>>16&255,t[43]=R>>>24&255,t[44]=U>>>0&255,t[45]=U>>>8&255,t[46]=U>>>16&255,t[47]=U>>>24&255,t[48]=M>>>0&255,t[49]=M>>>8&255,t[50]=M>>>16&255,t[51]=M>>>24&255,t[52]=L>>>0&255,t[53]=L>>>8&255,t[54]=L>>>16&255,t[55]=L>>>24&255,t[56]=B>>>0&255,t[57]=B>>>8&255,t[58]=B>>>16&255,t[59]=B>>>24&255,t[60]=I>>>0&255,t[61]=I>>>8&255,t[62]=I>>>16&255,t[63]=I>>>24&255}function a(t,e,n,r){for(var i,o=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,g=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,v=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,_=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=o,S=s,A=a,k=u,T=c,E=h,C=f,P=l,x=p,O=d,R=y,U=g,M=v,L=b,B=m,I=_,N=0;N<20;N+=2)i=w+M|0,T^=i<<7|i>>>25,i=T+w|0,x^=i<<9|i>>>23,i=x+T|0,M^=i<<13|i>>>19,i=M+x|0,w^=i<<18|i>>>14,i=E+S|0,O^=i<<7|i>>>25,i=O+E|0,L^=i<<9|i>>>23,i=L+O|0,S^=i<<13|i>>>19,i=S+L|0,E^=i<<18|i>>>14,i=R+C|0,B^=i<<7|i>>>25,i=B+R|0,A^=i<<9|i>>>23,i=A+B|0,C^=i<<13|i>>>19,i=C+A|0,R^=i<<18|i>>>14,i=I+U|0,k^=i<<7|i>>>25,i=k+I|0,P^=i<<9|i>>>23,i=P+k|0,U^=i<<13|i>>>19,i=U+P|0,I^=i<<18|i>>>14,i=w+k|0,S^=i<<7|i>>>25,i=S+w|0,A^=i<<9|i>>>23,i=A+S|0,k^=i<<13|i>>>19,i=k+A|0,w^=i<<18|i>>>14,i=E+T|0,C^=i<<7|i>>>25,i=C+E|0,P^=i<<9|i>>>23,i=P+C|0,T^=i<<13|i>>>19,i=T+P|0,E^=i<<18|i>>>14,i=R+O|0,U^=i<<7|i>>>25,i=U+R|0,x^=i<<9|i>>>23,i=x+U|0,O^=i<<13|i>>>19,i=O+x|0,R^=i<<18|i>>>14,i=I+B|0,M^=i<<7|i>>>25,i=M+I|0,L^=i<<9|i>>>23,i=L+M|0,B^=i<<13|i>>>19,i=B+L|0,I^=i<<18|i>>>14;t[0]=w>>>0&255,t[1]=w>>>8&255,t[2]=w>>>16&255,t[3]=w>>>24&255,t[4]=E>>>0&255,t[5]=E>>>8&255,t[6]=E>>>16&255,t[7]=E>>>24&255,t[8]=R>>>0&255,t[9]=R>>>8&255,t[10]=R>>>16&255,t[11]=R>>>24&255,t[12]=I>>>0&255,t[13]=I>>>8&255,t[14]=I>>>16&255,t[15]=I>>>24&255,t[16]=C>>>0&255,t[17]=C>>>8&255,t[18]=C>>>16&255,t[19]=C>>>24&255,t[20]=P>>>0&255,t[21]=P>>>8&255,t[22]=P>>>16&255,t[23]=P>>>24&255,t[24]=x>>>0&255,t[25]=x>>>8&255,t[26]=x>>>16&255,t[27]=x>>>24&255,t[28]=O>>>0&255,t[29]=O>>>8&255,t[30]=O>>>16&255,t[31]=O>>>24&255}function u(t,e,n,r){s(t,e,n,r)}function c(t,e,n,r){a(t,e,n,r)}function h(t,e,n,r,i,o,s){var a,c,h=new Uint8Array(16),f=new Uint8Array(64);for(c=0;c<16;c++)h[c]=0;for(c=0;c<8;c++)h[c]=o[c];for(;i>=64;){for(u(f,h,s,lt),c=0;c<64;c++)t[e+c]=n[r+c]^f[c];for(a=1,c=8;c<16;c++)a=a+(255&h[c])|0,h[c]=255&a,a>>>=8;i-=64,e+=64,r+=64}if(i>0)for(u(f,h,s,lt),c=0;c=64;){for(u(c,a,i,lt),s=0;s<64;s++)t[e+s]=c[s];for(o=1,s=8;s<16;s++)o=o+(255&a[s])|0,a[s]=255&o,o>>>=8;n-=64,e+=64}if(n>0)for(u(c,a,i,lt),s=0;s>16&1),o[n-1]&=65535;o[15]=s[15]-32767-(o[14]>>16&1),i=o[15]>>16&1,o[14]&=65535,_(s,o,1-i)}for(n=0;n<16;n++)t[2*n]=255&s[n],t[2*n+1]=s[n]>>8}function S(t,e){var n=new Uint8Array(32),r=new Uint8Array(32);return w(n,t),w(r,e),o(n,0,r,0)}function A(t){var e=new Uint8Array(32);return w(e,t),1&e[0]}function k(t,e){var n;for(n=0;n<16;n++)t[n]=e[2*n]+(e[2*n+1]<<8);t[15]&=32767}function T(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]+n[r]}function E(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]-n[r]}function C(t,e,n){var r,i,o=0,s=0,a=0,u=0,c=0,h=0,f=0,l=0,p=0,d=0,y=0,g=0,v=0,b=0,m=0,_=0,w=0,S=0,A=0,k=0,T=0,E=0,C=0,P=0,x=0,O=0,R=0,U=0,M=0,L=0,B=0,I=n[0],N=n[1],D=n[2],Y=n[3],j=n[4],z=n[5],F=n[6],H=n[7],q=n[8],J=n[9],K=n[10],X=n[11],G=n[12],W=n[13],Z=n[14],V=n[15];r=e[0],o+=r*I,s+=r*N,a+=r*D,u+=r*Y,c+=r*j,h+=r*z,f+=r*F,l+=r*H,p+=r*q,d+=r*J,y+=r*K,g+=r*X,v+=r*G,b+=r*W,m+=r*Z,_+=r*V,r=e[1],s+=r*I,a+=r*N,u+=r*D,c+=r*Y,h+=r*j,f+=r*z,l+=r*F,p+=r*H,d+=r*q,y+=r*J,g+=r*K,v+=r*X,b+=r*G,m+=r*W,_+=r*Z,w+=r*V,r=e[2],a+=r*I,u+=r*N,c+=r*D,h+=r*Y,f+=r*j,l+=r*z,p+=r*F,d+=r*H,y+=r*q,g+=r*J,v+=r*K,b+=r*X,m+=r*G,_+=r*W,w+=r*Z,S+=r*V,r=e[3],u+=r*I,c+=r*N,h+=r*D,f+=r*Y,l+=r*j,p+=r*z,d+=r*F,y+=r*H,g+=r*q,v+=r*J,b+=r*K,m+=r*X,_+=r*G,w+=r*W,S+=r*Z,A+=r*V,r=e[4],c+=r*I,h+=r*N,f+=r*D,l+=r*Y,p+=r*j,d+=r*z,y+=r*F,g+=r*H,v+=r*q,b+=r*J,m+=r*K,_+=r*X,w+=r*G,S+=r*W,A+=r*Z,k+=r*V,r=e[5],h+=r*I,f+=r*N,l+=r*D,p+=r*Y,d+=r*j,y+=r*z,g+=r*F,v+=r*H,b+=r*q,m+=r*J,_+=r*K,w+=r*X,S+=r*G,A+=r*W,k+=r*Z,T+=r*V,r=e[6],f+=r*I,l+=r*N,p+=r*D,d+=r*Y,y+=r*j,g+=r*z,v+=r*F,b+=r*H,m+=r*q,_+=r*J,w+=r*K,S+=r*X,A+=r*G,k+=r*W,T+=r*Z,E+=r*V,r=e[7],l+=r*I,p+=r*N,d+=r*D,y+=r*Y,g+=r*j,v+=r*z,b+=r*F,m+=r*H,_+=r*q,w+=r*J,S+=r*K,A+=r*X,k+=r*G,T+=r*W,E+=r*Z,C+=r*V,r=e[8],p+=r*I,d+=r*N,y+=r*D,g+=r*Y,v+=r*j,b+=r*z,m+=r*F,_+=r*H,w+=r*q,S+=r*J,A+=r*K,k+=r*X,T+=r*G,E+=r*W,C+=r*Z,P+=r*V,r=e[9],d+=r*I,y+=r*N,g+=r*D,v+=r*Y,b+=r*j,m+=r*z,_+=r*F,w+=r*H,S+=r*q,A+=r*J,k+=r*K,T+=r*X,E+=r*G,C+=r*W,P+=r*Z,x+=r*V,r=e[10],y+=r*I,g+=r*N,v+=r*D,b+=r*Y,m+=r*j,_+=r*z,w+=r*F,S+=r*H,A+=r*q,k+=r*J,T+=r*K,E+=r*X,C+=r*G,P+=r*W,x+=r*Z,O+=r*V,r=e[11],g+=r*I,v+=r*N,b+=r*D,m+=r*Y,_+=r*j,w+=r*z,S+=r*F,A+=r*H,k+=r*q,T+=r*J,E+=r*K,C+=r*X;P+=r*G;x+=r*W,O+=r*Z,R+=r*V,r=e[12],v+=r*I,b+=r*N,m+=r*D,_+=r*Y,w+=r*j,S+=r*z,A+=r*F,k+=r*H,T+=r*q,E+=r*J,C+=r*K,P+=r*X,x+=r*G,O+=r*W,R+=r*Z,U+=r*V,r=e[13],b+=r*I,m+=r*N,_+=r*D,w+=r*Y,S+=r*j,A+=r*z,k+=r*F,T+=r*H,E+=r*q,C+=r*J,P+=r*K,x+=r*X,O+=r*G,R+=r*W,U+=r*Z,M+=r*V,r=e[14],m+=r*I,_+=r*N,w+=r*D,S+=r*Y,A+=r*j,k+=r*z,T+=r*F,E+=r*H,C+=r*q,P+=r*J,x+=r*K,O+=r*X,R+=r*G,U+=r*W,M+=r*Z,L+=r*V,r=e[15],_+=r*I,w+=r*N,S+=r*D,A+=r*Y,k+=r*j,T+=r*z,E+=r*F,C+=r*H,P+=r*q,x+=r*J,O+=r*K,R+=r*X,U+=r*G,M+=r*W,L+=r*Z,B+=r*V,o+=38*w,s+=38*S,a+=38*A,u+=38*k,c+=38*T,h+=38*E,f+=38*C,l+=38*P,p+=38*x,d+=38*O,y+=38*R,g+=38*U,v+=38*M,b+=38*L,m+=38*B,i=1,r=o+i+65535,i=Math.floor(r/65536),o=r-65536*i,r=s+i+65535,i=Math.floor(r/65536),s=r-65536*i,r=a+i+65535,i=Math.floor(r/65536),a=r-65536*i,r=u+i+65535,i=Math.floor(r/65536),u=r-65536*i,r=c+i+65535,i=Math.floor(r/65536),c=r-65536*i,r=h+i+65535,i=Math.floor(r/65536),h=r-65536*i,r=f+i+65535,i=Math.floor(r/65536),f=r-65536*i,r=l+i+65535,i=Math.floor(r/65536),l=r-65536*i,r=p+i+65535,i=Math.floor(r/65536),p=r-65536*i,r=d+i+65535,i=Math.floor(r/65536),d=r-65536*i,r=y+i+65535,i=Math.floor(r/65536),y=r-65536*i,r=g+i+65535,i=Math.floor(r/65536),g=r-65536*i,r=v+i+65535,i=Math.floor(r/65536),v=r-65536*i,r=b+i+65535,i=Math.floor(r/65536),b=r-65536*i,r=m+i+65535,i=Math.floor(r/65536),m=r-65536*i,r=_+i+65535,i=Math.floor(r/65536),_=r-65536*i,o+=i-1+37*(i-1),i=1,r=o+i+65535,i=Math.floor(r/65536),o=r-65536*i,r=s+i+65535,i=Math.floor(r/65536),s=r-65536*i,r=a+i+65535,i=Math.floor(r/65536),a=r-65536*i,r=u+i+65535,i=Math.floor(r/65536),u=r-65536*i,r=c+i+65535,i=Math.floor(r/65536),c=r-65536*i,r=h+i+65535,i=Math.floor(r/65536),h=r-65536*i,r=f+i+65535,i=Math.floor(r/65536),f=r-65536*i,r=l+i+65535,i=Math.floor(r/65536),l=r-65536*i,r=p+i+65535,i=Math.floor(r/65536),p=r-65536*i,r=d+i+65535,i=Math.floor(r/65536),d=r-65536*i,r=y+i+65535,i=Math.floor(r/65536),y=r-65536*i,r=g+i+65535,i=Math.floor(r/65536),g=r-65536*i,r=v+i+65535,i=Math.floor(r/65536),v=r-65536*i,r=b+i+65535,i=Math.floor(r/65536),b=r-65536*i,r=m+i+65535,i=Math.floor(r/65536),m=r-65536*i,r=_+i+65535,i=Math.floor(r/65536),_=r-65536*i,o+=i-1+37*(i-1),t[0]=o,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]=g,t[12]=v,t[13]=b;t[14]=m;t[15]=_}function P(t,e){C(t,e,e)}function x(t,e){var n,r=tt();for(n=0;n<16;n++)r[n]=e[n];for(n=253;n>=0;n--)P(r,r),2!==n&&4!==n&&C(r,r,e);for(n=0;n<16;n++)t[n]=r[n]}function O(t,e){var n,r=tt();for(n=0;n<16;n++)r[n]=e[n];for(n=250;n>=0;n--)P(r,r),1!==n&&C(r,r,e);for(n=0;n<16;n++)t[n]=r[n]}function R(t,e,n){var r,i,o=new Uint8Array(32),s=new Float64Array(80),a=tt(),u=tt(),c=tt(),h=tt(),f=tt(),l=tt();for(i=0;i<31;i++)o[i]=e[i];for(o[31]=127&e[31]|64,o[0]&=248,k(s,n),i=0;i<16;i++)u[i]=s[i],h[i]=a[i]=c[i]=0;for(a[0]=h[0]=1,i=254;i>=0;--i)r=o[i>>>3]>>>(7&i)&1,_(a,u,r),_(c,h,r),T(f,a,c),E(a,a,c),T(c,u,h),E(u,u,h),P(h,f),P(l,a),C(a,c,a),C(c,u,f),T(f,a,c),E(a,a,c),P(u,a),E(c,h,l),C(a,c,st),T(a,a,h),C(c,c,a),C(a,h,l),C(h,u,s),P(u,f),_(a,u,r),_(c,h,r);for(i=0;i<16;i++)s[i+16]=a[i],s[i+32]=c[i],s[i+48]=u[i],s[i+64]=h[i];var p=s.subarray(32),d=s.subarray(16);return x(p,p),C(d,d,p),w(t,d),0}function U(t,e){return R(t,e,rt)}function M(t,e){return et(e,32),U(t,e)}function L(t,e,n){var r=new Uint8Array(32);return R(r,n,e),c(t,nt,r,lt)}function B(t,e,n,r,i,o){var s=new Uint8Array(32);return L(s,i,o),dt(t,e,n,r,s)}function I(t,e,n,r,i,o){var s=new Uint8Array(32);return L(s,i,o),yt(t,e,n,r,s)}function N(t,e,n,r){for(var i,o,s,a,u,c,h,f,l,p,d,y,g,v,b,m,_,w,S,A,k,T,E,C,P,x,O=new Int32Array(16),R=new Int32Array(16),U=t[0],M=t[1],L=t[2],B=t[3],I=t[4],N=t[5],D=t[6],Y=t[7],j=e[0],z=e[1],F=e[2],H=e[3],q=e[4],J=e[5],K=e[6],X=e[7],G=0;r>=128;){for(S=0;S<16;S++)A=8*S+G,O[S]=n[A+0]<<24|n[A+1]<<16|n[A+2]<<8|n[A+3],R[S]=n[A+4]<<24|n[A+5]<<16|n[A+6]<<8|n[A+7];for(S=0;S<80;S++)if(i=U,o=M,s=L,a=B,u=I,c=N,h=D,f=Y,l=j,p=z,d=F,y=H,g=q,v=J,b=K,m=X,k=Y,T=X,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=(I>>>14|q<<18)^(I>>>18|q<<14)^(q>>>9|I<<23),T=(q>>>14|I<<18)^(q>>>18|I<<14)^(I>>>9|q<<23),E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,k=I&N^~I&D,T=q&J^~q&K,E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,k=gt[2*S],T=gt[2*S+1],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,k=O[S%16],T=R[S%16],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,_=65535&P|x<<16,w=65535&E|C<<16,k=_,T=w,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=(U>>>28|j<<4)^(j>>>2|U<<30)^(j>>>7|U<<25),T=(j>>>28|U<<4)^(U>>>2|j<<30)^(U>>>7|j<<25),E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,k=U&M^U&L^M&L,T=j&z^j&F^z&F,E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,f=65535&P|x<<16,m=65535&E|C<<16,k=a,T=y,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=_,T=w,E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,a=65535&P|x<<16,y=65535&E|C<<16,M=i,L=o,B=s,I=a,N=u,D=c,Y=h,U=f,z=l,F=p,H=d,q=y,J=g,K=v,X=b,j=m,S%16===15)for(A=0;A<16;A++)k=O[A],T=R[A],E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=O[(A+9)%16],T=R[(A+9)%16],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,_=O[(A+1)%16],w=R[(A+1)%16],k=(_>>>1|w<<31)^(_>>>8|w<<24)^_>>>7,T=(w>>>1|_<<31)^(w>>>8|_<<24)^(w>>>7|_<<25),E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,_=O[(A+14)%16],w=R[(A+14)%16],k=(_>>>19|w<<13)^(w>>>29|_<<3)^_>>>6,T=(w>>>19|_<<13)^(_>>>29|w<<3)^(w>>>6|_<<26),E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,O[A]=65535&P|x<<16,R[A]=65535&E|C<<16;k=U,T=j,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[0],T=e[0],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[0]=U=65535&P|x<<16,e[0]=j=65535&E|C<<16,k=M,T=z,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[1],T=e[1],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[1]=M=65535&P|x<<16,e[1]=z=65535&E|C<<16,k=L,T=F,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[2],T=e[2],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[2]=L=65535&P|x<<16,e[2]=F=65535&E|C<<16,k=B,T=H,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[3],T=e[3],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[3]=B=65535&P|x<<16,e[3]=H=65535&E|C<<16,k=I,T=q,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[4],T=e[4],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[4]=I=65535&P|x<<16,e[4]=q=65535&E|C<<16,k=N,T=J,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[5],T=e[5],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[5]=N=65535&P|x<<16,e[5]=J=65535&E|C<<16,k=D,T=K,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[6],T=e[6],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[6]=D=65535&P|x<<16,e[6]=K=65535&E|C<<16,k=Y,T=X,E=65535&T,C=T>>>16,P=65535&k,x=k>>>16,k=t[7],T=e[7],E+=65535&T,C+=T>>>16,P+=65535&k,x+=k>>>16,C+=E>>>16,P+=C>>>16,x+=P>>>16,t[7]=Y=65535&P|x<<16,e[7]=X=65535&E|C<<16,G+=128,r-=128}return r}function D(t,n,r){var i,o=new Int32Array(8),s=new Int32Array(8),a=new Uint8Array(256),u=r;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,s[0]=4089235720,s[1]=2227873595,s[2]=4271175723,s[3]=1595750129,s[4]=2917565137,s[5]=725511199,s[6]=4215389547,s[7]=327033209,N(o,s,n,r),r%=128,i=0;i=0;--i)r=n[i/8|0]>>(7&i)&1,j(t,e,r),Y(e,t),Y(t,t),j(t,e,r)}function H(t,e){var n=[tt(),tt(),tt(),tt()];b(n[0],ct),b(n[1],ht),b(n[2],ot),C(n[3],ct,ht),F(t,n,e)}function q(t,e,n){var r,i=new Uint8Array(64),o=[tt(),tt(),tt(),tt()];for(n||et(e,32),D(i,e,32),i[0]&=248,i[31]&=127,i[31]|=64,H(o,i),z(t,o),r=0;r<32;r++)e[r+32]=t[r];return 0}function J(t,e){var n,r,i,o;for(r=63;r>=32;--r){for(n=0,i=r-32,o=r-12;i>8,e[i]-=256*n;e[i]+=n,e[r]=0}for(n=0,i=0;i<32;i++)e[i]+=n-(e[31]>>4)*vt[i],n=e[i]>>8,e[i]&=255;for(i=0;i<32;i++)e[i]-=n*vt[i];for(r=0;r<32;r++)e[r+1]+=e[r]>>8,t[r]=255&e[r]}function K(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;J(t,n)}function X(t,e,n,r){var i,o,s=new Uint8Array(64),a=new Uint8Array(64),u=new Uint8Array(64),c=new Float64Array(64),h=[tt(),tt(),tt(),tt()];D(s,r,32),s[0]&=248,s[31]&=127,s[31]|=64;var f=n+64;for(i=0;i>7&&E(t[0],it,t[0]),C(t[3],t[0],t[1]),0)}function W(t,e,n,r){var i,s,a=new Uint8Array(32),u=new Uint8Array(64),c=[tt(),tt(),tt(),tt()],h=[tt(),tt(),tt(),tt()];if(s=-1,n<64)return-1;if(G(h,r))return-1;for(i=0;i>>13|n<<3),r=255&t[4]|(255&t[5])<<8,this.r[2]=7939&(n>>>10|r<<6),i=255&t[6]|(255&t[7])<<8,this.r[3]=8191&(r>>>7|i<<9),o=255&t[8]|(255&t[9])<<8,this.r[4]=255&(i>>>4|o<<12),this.r[5]=o>>>1&8190,s=255&t[10]|(255&t[11])<<8,this.r[6]=8191&(o>>>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};pt.prototype.blocks=function(t,e,n){for(var r,i,o,s,a,u,c,h,f,l,p,d,y,g,v,b,m,_,w,S=this.fin?0:2048,A=this.h[0],k=this.h[1],T=this.h[2],E=this.h[3],C=this.h[4],P=this.h[5],x=this.h[6],O=this.h[7],R=this.h[8],U=this.h[9],M=this.r[0],L=this.r[1],B=this.r[2],I=this.r[3],N=this.r[4],D=this.r[5],Y=this.r[6],j=this.r[7],z=this.r[8],F=this.r[9];n>=16;)r=255&t[e+0]|(255&t[e+1])<<8,A+=8191&r,i=255&t[e+2]|(255&t[e+3])<<8,k+=8191&(r>>>13|i<<3),o=255&t[e+4]|(255&t[e+5])<<8,T+=8191&(i>>>10|o<<6),s=255&t[e+6]|(255&t[e+7])<<8,E+=8191&(o>>>7|s<<9),a=255&t[e+8]|(255&t[e+9])<<8,C+=8191&(s>>>4|a<<12),P+=a>>>1&8191,u=255&t[e+10]|(255&t[e+11])<<8,x+=8191&(a>>>14|u<<2),c=255&t[e+12]|(255&t[e+13])<<8,O+=8191&(u>>>11|c<<5),h=255&t[e+14]|(255&t[e+15])<<8,R+=8191&(c>>>8|h<<8),U+=h>>>5|S,f=0,l=f,l+=A*M,l+=k*(5*F),l+=T*(5*z),l+=E*(5*j),l+=C*(5*Y),f=l>>>13,l&=8191,l+=P*(5*D),l+=x*(5*N),l+=O*(5*I),l+=R*(5*B),l+=U*(5*L),f+=l>>>13,l&=8191,p=f,p+=A*L,p+=k*M,p+=T*(5*F),p+=E*(5*z),p+=C*(5*j),f=p>>>13,p&=8191,p+=P*(5*Y),p+=x*(5*D),p+=O*(5*N),p+=R*(5*I),p+=U*(5*B),f+=p>>>13,p&=8191,d=f,d+=A*B,d+=k*L,d+=T*M,d+=E*(5*F),d+=C*(5*z),f=d>>>13,d&=8191,d+=P*(5*j),d+=x*(5*Y),d+=O*(5*D),d+=R*(5*N),d+=U*(5*I),f+=d>>>13,d&=8191,y=f,y+=A*I,y+=k*B,y+=T*L,y+=E*M,y+=C*(5*F),f=y>>>13,y&=8191,y+=P*(5*z),y+=x*(5*j),y+=O*(5*Y),y+=R*(5*D),y+=U*(5*N),f+=y>>>13,y&=8191,g=f,g+=A*N,g+=k*I,g+=T*B,g+=E*L,g+=C*M,f=g>>>13,g&=8191,g+=P*(5*F),g+=x*(5*z),g+=O*(5*j),g+=R*(5*Y),g+=U*(5*D),f+=g>>>13,g&=8191,v=f,v+=A*D,v+=k*N,v+=T*I,v+=E*B,v+=C*L,f=v>>>13,v&=8191,v+=P*M,v+=x*(5*F),v+=O*(5*z),v+=R*(5*j),v+=U*(5*Y),f+=v>>>13,v&=8191,b=f,b+=A*Y,b+=k*D,b+=T*N,b+=E*I,b+=C*B,f=b>>>13,b&=8191,b+=P*L,b+=x*M,b+=O*(5*F),b+=R*(5*z),b+=U*(5*j),f+=b>>>13,b&=8191,m=f,m+=A*j,m+=k*Y,m+=T*D,m+=E*N,m+=C*I,f=m>>>13,m&=8191,m+=P*B,m+=x*L,m+=O*M,m+=R*(5*F),m+=U*(5*z),f+=m>>>13,m&=8191,_=f,_+=A*z,_+=k*j,_+=T*Y,_+=E*D,_+=C*N,f=_>>>13,_&=8191,_+=P*I,_+=x*B,_+=O*L,_+=R*M,_+=U*(5*F),f+=_>>>13,_&=8191,w=f,w+=A*F,w+=k*z,w+=T*j,w+=E*Y,w+=C*D,f=w>>>13,w&=8191,w+=P*N,w+=x*I,w+=O*B,w+=R*L,w+=U*M,f+=w>>>13,w&=8191,f=(f<<2)+f|0,f=f+l|0,l=8191&f,f>>>=13,p+=f,A=l,k=p,T=d,E=y,C=g,P=v,x=b,O=m,R=_,U=w,e+=16,n-=16;this.h[0]=A,this.h[1]=k,this.h[2]=T,this.h[3]=E,this.h[4]=C,this.h[5]=P,this.h[6]=x,this.h[7]=O,this.h[8]=R,this.h[9]=U},pt.prototype.finish=function(t,e){var n,r,i,o,s=new Uint16Array(10);if(this.leftover){for(o=this.leftover,this.buffer[o++]=1;o<16;o++)this.buffer[o]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,o=2;o<10;o++)this.h[o]+=n,n=this.h[o]>>>13,this.h[o]&=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,o=1;o<10;o++)s[o]=this.h[o]+n,n=s[o]>>>13,s[o]&=8191;for(s[9]-=8192,r=(1^n)-1,o=0;o<10;o++)s[o]&=r;for(r=~r,o=0;o<10;o++)this.h[o]=this.h[o]&r|s[o];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),i=this.h[0]+this.pad[0],this.h[0]=65535&i,o=1;o<8;o++)i=(this.h[o]+this.pad[o]|0)+(i>>>16)|0,this.h[o]=65535&i;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},pt.prototype.update=function(t,e,n){var r,i;if(this.leftover){for(i=16-this.leftover,i>n&&(i=n),r=0;r=16&&(i=n-n%16,this.blocks(t,e,i),e+=i,n-=i),n){for(r=0;r=0},t.sign.keyPair=function(){var t=new Uint8Array(Rt),e=new Uint8Array(Ut);return q(t,e),{publicKey:t,secretKey:e}},t.sign.keyPair.fromSecretKey=function(t){if(Q(t),t.length!==Ut)throw new Error("bad secret key size");for(var e=new Uint8Array(Rt),n=0;n diff --git a/package.json b/package.json index f8007879d..ae63b6ac2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pusher-js", - "version": "4.3.1", + "version": "4.4.0", "description": "Pusher JavaScript library for browsers, React Native, NodeJS and web workers", "main": "dist/node/pusher.js", "browser": "dist/web/pusher.js", diff --git a/spec/javascripts/unit/core/channels/channel_spec.js b/spec/javascripts/unit/core/channels/channel_spec.js index 037474a3b..7bf8b1443 100644 --- a/spec/javascripts/unit/core/channels/channel_spec.js +++ b/spec/javascripts/unit/core/channels/channel_spec.js @@ -35,6 +35,9 @@ describe("Channel", function() { }); describe("#trigger", function() { + beforeEach(function() { + channel.subscribed = true; + }); it("should raise an exception if the event name does not start with client-", function() { expect(function() { channel.trigger("whatever", {}); @@ -60,7 +63,9 @@ describe("Channel", function() { describe("#disconnect", function() { it("should set subscribed to false", function() { - channel.handleEvent("pusher_internal:subscription_succeeded"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded" + }); channel.disconnect(); expect(channel.subscribed).toEqual(false); }); @@ -80,7 +85,9 @@ describe("Channel", function() { channel.bind("pusher_internal:test", callback); channel.bind_global(callback); - channel.handleEvent("pusher_internal:test"); + channel.handleEvent({ + event: "pusher_internal:test" + }); expect(callback).not.toHaveBeenCalled(); }); @@ -90,19 +97,28 @@ describe("Channel", function() { var callback = jasmine.createSpy("callback"); channel.bind("pusher:subscription_succeeded", callback); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(callback).toHaveBeenCalledWith("123"); }); it("should set #subscribed to true", function() { - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(channel.subscribed).toEqual(true); }); it("should set #subscriptionPending to false", function() { - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(channel.subscriptionPending).toEqual(false); }); @@ -114,21 +130,30 @@ describe("Channel", function() { channel.bind("pusher:subscription_succeeded", callback); channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(callback).not.toHaveBeenCalled(); }); it("should set #subscribed to true", function() { channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(channel.subscribed).toEqual(true); }); it("should set #subscriptionPending to false", function() { channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(channel.subscriptionPending).toEqual(false); }); @@ -137,7 +162,10 @@ describe("Channel", function() { expect(pusher.unsubscribe).not.toHaveBeenCalled(); channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(pusher.unsubscribe).toHaveBeenCalledWith(channel.name); }); @@ -148,18 +176,24 @@ describe("Channel", function() { var callback = jasmine.createSpy("callback"); channel.bind("something", callback); - channel.handleEvent("something", 9); + channel.handleEvent({ + event: "something", + data: 9 + }); - expect(callback).toHaveBeenCalledWith(9); + expect(callback).toHaveBeenCalledWith(9, {}); }); it("should emit the event even if it's named like JS built-in", function() { var callback = jasmine.createSpy("callback"); channel.bind("toString", callback); - channel.handleEvent("toString", "works"); + channel.handleEvent({ + event: "toString", + data: "works" + }); - expect(callback).toHaveBeenCalledWith("works"); + expect(callback).toHaveBeenCalledWith("works", {}); }); }); }); @@ -194,7 +228,7 @@ describe("Channel", function() { expect(pusher.send_event).toHaveBeenCalledWith( "pusher:subscribe", - { auth: "one", channel_data: "two", channel: "test" } + { auth: "one", channel_data: "two", channel: "test" }, ); }); diff --git a/spec/javascripts/unit/core/channels/encrypted_channel_spec.js b/spec/javascripts/unit/core/channels/encrypted_channel_spec.js index dde0fe80e..3e24a6e3b 100644 --- a/spec/javascripts/unit/core/channels/encrypted_channel_spec.js +++ b/spec/javascripts/unit/core/channels/encrypted_channel_spec.js @@ -113,7 +113,9 @@ describe("EncryptedChannel", function() { describe("#disconnect", function() { it("should set subscribed to false", function() { - channel.handleEvent("pusher_internal:subscription_succeeded"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded" + }); channel.disconnect(); expect(channel.subscribed).toEqual(false); }); @@ -125,7 +127,9 @@ describe("EncryptedChannel", function() { channel.bind("pusher_internal:test", callback); channel.bind_global(callback); - channel.handleEvent("pusher_internal:test"); + channel.handleEvent({ + event: "pusher_internal:test" + }); expect(callback).not.toHaveBeenCalled(); }); @@ -134,17 +138,26 @@ describe("EncryptedChannel", function() { it("should emit pusher:subscription_succeeded", function() { let callback = jasmine.createSpy("callback"); channel.bind("pusher:subscription_succeeded", callback); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(callback).toHaveBeenCalledWith("123"); }); it("should set #subscribed to true", function() { - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(channel.subscribed).toEqual(true); }); it("should set #subscriptionPending to false", function() { - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(channel.subscriptionPending).toEqual(false); }); }); @@ -154,26 +167,38 @@ describe("EncryptedChannel", function() { let callback = jasmine.createSpy("callback"); channel.bind("pusher:subscription_succeeded", callback); channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(callback).not.toHaveBeenCalled(); }); it("should set #subscribed to true", function() { channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(channel.subscribed).toEqual(true); }); it("should set #subscriptionPending to false", function() { channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(channel.subscriptionPending).toEqual(false); }); it("should call #pusher.unsubscribe", function() { expect(pusher.unsubscribe).not.toHaveBeenCalled(); channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(pusher.unsubscribe).toHaveBeenCalledWith(channel.name); }); }); @@ -197,15 +222,21 @@ describe("EncryptedChannel", function() { }; let boundCallback = jasmine.createSpy("boundCallback"); channel.bind("something", boundCallback); - channel.handleEvent("something", encryptedPayload); + channel.handleEvent({ + event: "something", + data: encryptedPayload + }); expect(boundCallback).toHaveBeenCalledWith(payload); }); it("should emit pusher: prefixed events unmodified", function() { let payload = { test: "payload" }; let boundCallback = jasmine.createSpy("boundCallback"); channel.bind("pusher:subscription_error", boundCallback); - channel.handleEvent("pusher:subscription_error", payload); - expect(boundCallback).toHaveBeenCalledWith(payload); + channel.handleEvent({ + event: "pusher:subscription_error", + data: payload + }); + expect(boundCallback).toHaveBeenCalledWith(payload, {}); }); describe("with rotated shared key", function() { @@ -233,7 +264,10 @@ describe("EncryptedChannel", function() { }; let boundCallback = jasmine.createSpy("boundCallback"); channel.bind("something", boundCallback); - channel.handleEvent("something", encryptedPayload); + channel.handleEvent({ + event: "something", + data: encryptedPayload + }); authorizer._callback(false, { shared_secret: newSecretBase64, foo: "bar" @@ -246,7 +280,10 @@ describe("EncryptedChannel", function() { ciphertext: tweetNaclUtil.encodeBase64('garbage-ciphertext') }; spyOn(Logger, "warn"); - channel.handleEvent("something", encryptedPayload); + channel.handleEvent({ + event: "something", + data: encryptedPayload + }); authorizer._callback(false, { shared_secret: newSecretBase64, foo: "bar" @@ -262,7 +299,10 @@ describe("EncryptedChannel", function() { ciphertext: newTestEncrypt(payload) }; spyOn(Logger, "warn"); - channel.handleEvent("something", encryptedPayload); + channel.handleEvent({ + event: "something", + data: encryptedPayload + }); authorizer._callback(true, "ERROR"); expect(Logger.warn).toHaveBeenCalledWith( "Failed to make a request to the authEndpoint: ERROR. Unable to fetch new key, so dropping encrypted event" diff --git a/spec/javascripts/unit/core/channels/presence_channel_spec.js b/spec/javascripts/unit/core/channels/presence_channel_spec.js index 435770067..3361a6539 100644 --- a/spec/javascripts/unit/core/channels/presence_channel_spec.js +++ b/spec/javascripts/unit/core/channels/presence_channel_spec.js @@ -89,6 +89,9 @@ describe("PresenceChannel", function() { }); describe("#trigger", function() { + beforeEach(function() { + channel.subscribed = true; + }); it("should raise an exception if the event name does not start with client-", function() { expect(function() { channel.trigger("whatever", {}); @@ -131,7 +134,7 @@ describe("PresenceChannel", function() { channel.bind("pusher_internal:test", callback); channel.bind_global(callback); - channel.handleEvent("pusher_internal:test"); + channel.handleEvent({event: "pusher_internal:test"}); expect(callback).not.toHaveBeenCalled(); }); @@ -141,10 +144,13 @@ describe("PresenceChannel", function() { var callback = jasmine.createSpy("callback"); channel.bind("pusher:subscription_succeeded", callback); - channel.handleEvent("pusher_internal:subscription_succeeded", { - presence: { - hash: { "U": "me" }, - count: 1 + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: { + presence: { + hash: { "U": "me" }, + count: 1 + } } }); @@ -152,10 +158,13 @@ describe("PresenceChannel", function() { }); it("should set #subscribed to true", function() { - channel.handleEvent("pusher_internal:subscription_succeeded", { - presence: { - hash: { "U": "me" }, - count: 1 + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: { + presence: { + hash: { "U": "me" }, + count: 1 + } } }); @@ -163,10 +172,13 @@ describe("PresenceChannel", function() { }); it("should set #subscriptionPending to false", function() { - channel.handleEvent("pusher_internal:subscription_succeeded", { - presence: { - hash: { "U": "me" }, - count: 1 + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: { + presence: { + hash: { "U": "me" }, + count: 1 + } } }); @@ -180,21 +192,30 @@ describe("PresenceChannel", function() { channel.bind("pusher:subscription_succeeded", callback); channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(callback).not.toHaveBeenCalled(); }); it("should set #subscribed to true", function() { channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(channel.subscribed).toEqual(true); }); it("should set #subscriptionPending to false", function() { channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(channel.subscriptionPending).toEqual(false); }); @@ -203,7 +224,10 @@ describe("PresenceChannel", function() { expect(pusher.unsubscribe).not.toHaveBeenCalled(); channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(pusher.unsubscribe).toHaveBeenCalledWith(channel.name); }); @@ -214,9 +238,23 @@ describe("PresenceChannel", function() { var callback = jasmine.createSpy("callback"); channel.bind("something", callback); - channel.handleEvent("something", 9); + channel.handleEvent({ + event: "something", + data: 9 + }); - expect(callback).toHaveBeenCalledWith(9); + expect(callback).toHaveBeenCalledWith(9, {}); + }); + it("should emit metadata with user_id", function() { + var callback = jasmine.createSpy("callback"); + channel.bind("client-something", callback); + + channel.handleEvent({ + event: "client-something", + data: 9, + user_id: "abc-def" + }); + expect(callback).toHaveBeenCalledWith(9, {user_id: "abc-def"}); }); }); }); @@ -227,14 +265,17 @@ describe("PresenceChannel", function() { beforeEach(function() { var callback = jasmine.createSpy("callback"); channel.bind("pusher:subscription_succeeded", callback); - channel.handleEvent("pusher_internal:subscription_succeeded", { - presence: { - hash: { - "A": "user A", - "B": "user B", - "U": "me" - }, - count: 3 + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: { + presence: { + hash: { + "A": "user A", + "B": "user B", + "U": "me" + }, + count: 3 + } } }); members = callback.calls[0].args[0]; @@ -264,18 +305,24 @@ describe("PresenceChannel", function() { describe("on pusher_internal:member_added", function() { it("should add a new member", function() { - channel.handleEvent("pusher_internal:member_added", { - user_id: "C", - user_info: "user C" + channel.handleEvent({ + event: "pusher_internal:member_added", + data: { + user_id: "C", + user_info: "user C" + } }); expect(members.get("C")).toEqual({ id: "C", info: "user C"}); }); it("should increment member count after adding a new member", function() { - channel.handleEvent("pusher_internal:member_added", { - user_id: "C", - user_info: "user C" + channel.handleEvent({ + event: "pusher_internal:member_added", + data: { + user_id: "C", + user_info: "user C" + } }); expect(members.count).toEqual(4); @@ -285,27 +332,36 @@ describe("PresenceChannel", function() { var callback = jasmine.createSpy("callback"); channel.bind("pusher:member_added", callback); - channel.handleEvent("pusher_internal:member_added", { - user_id: "C", - user_info: "user C" + channel.handleEvent({ + event: "pusher_internal:member_added", + data: { + user_id: "C", + user_info: "user C" + } }); expect(callback).toHaveBeenCalledWith({ id: "C", info: "user C" }); }); it("should update an existing member", function() { - channel.handleEvent("pusher_internal:member_added", { - user_id: "B", - user_info: "updated B" + channel.handleEvent({ + event: "pusher_internal:member_added", + data: { + user_id: "B", + user_info: "updated B" + } }); expect(members.get("B")).toEqual({ id: "B", info: "updated B"}); }); it("should not increment member count after updating a member", function() { - channel.handleEvent("pusher_internal:member_added", { - user_id: "B", - user_info: "updated B" + channel.handleEvent({ + event: "pusher_internal:member_added", + data: { + user_id: "B", + user_info: "updated B" + } }); expect(members.count).toEqual(3); @@ -315,9 +371,12 @@ describe("PresenceChannel", function() { var callback = jasmine.createSpy("callback"); channel.bind("pusher:member_added", callback); - channel.handleEvent("pusher_internal:member_added", { - user_id: "B", - user_info: "updated B" + channel.handleEvent({ + event: "pusher_internal:member_added", + data: { + user_id: "B", + user_info: "updated B" + } }); expect(callback).toHaveBeenCalledWith({ id: "B", info: "updated B" }); @@ -326,8 +385,11 @@ describe("PresenceChannel", function() { describe("on pusher_internal:member_removed", function() { it("should remove an existing member", function() { - channel.handleEvent("pusher_internal:member_removed", { - user_id: "B" + channel.handleEvent({ + event: "pusher_internal:member_removed", + data: { + user_id: "B" + } }); expect(members.get("B")).toEqual(null); @@ -337,16 +399,22 @@ describe("PresenceChannel", function() { var callback = jasmine.createSpy("callback"); channel.bind("pusher:member_removed", callback); - channel.handleEvent("pusher_internal:member_removed", { - user_id: "B" + channel.handleEvent({ + event: "pusher_internal:member_removed", + data: { + user_id: "B" + } }); expect(callback).toHaveBeenCalledWith({ id: "B", info: "user B" }); }); it("should decrement member count after removing a member", function() { - channel.handleEvent("pusher_internal:member_removed", { - user_id: "B" + channel.handleEvent({ + event: "pusher_internal:member_removed", + data: { + user_id: "B" + } }); expect(members.count).toEqual(2); @@ -356,16 +424,22 @@ describe("PresenceChannel", function() { var callback = jasmine.createSpy("callback"); channel.bind("pusher:member_removed", callback); - channel.handleEvent("pusher_internal:member_removed", { - user_id: "C" + channel.handleEvent({ + event: "pusher_internal:member_removed", + data: { + user_id: "C" + }, }); expect(callback).not.toHaveBeenCalled(); }); it("should not decrement member count if member was not removed", function() { - channel.handleEvent("pusher_internal:member_removed", { - user_id: "C" + channel.handleEvent({ + event: "pusher_internal:member_removed", + data: { + user_id: "C" + } }); expect(members.count).toEqual(3); diff --git a/spec/javascripts/unit/core/channels/private_channel_spec.js b/spec/javascripts/unit/core/channels/private_channel_spec.js index 993141b16..c3675a5f1 100644 --- a/spec/javascripts/unit/core/channels/private_channel_spec.js +++ b/spec/javascripts/unit/core/channels/private_channel_spec.js @@ -76,6 +76,9 @@ describe("PrivateChannel", function() { }); describe("#trigger", function() { + beforeEach(function() { + channel.subscribed = true; + }) it("should raise an exception if the event name does not start with client-", function() { expect(function() { channel.trigger("whatever", {}); @@ -101,7 +104,9 @@ describe("PrivateChannel", function() { describe("#disconnect", function() { it("should set subscribed to false", function() { - channel.handleEvent("pusher_internal:subscription_succeeded"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded" + }); channel.disconnect(); expect(channel.subscribed).toEqual(false); }); @@ -113,7 +118,9 @@ describe("PrivateChannel", function() { channel.bind("pusher_internal:test", callback); channel.bind_global(callback); - channel.handleEvent("pusher_internal:test"); + channel.handleEvent({ + event: "pusher_internal:test" + }); expect(callback).not.toHaveBeenCalled(); }); @@ -123,19 +130,28 @@ describe("PrivateChannel", function() { var callback = jasmine.createSpy("callback"); channel.bind("pusher:subscription_succeeded", callback); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(callback).toHaveBeenCalledWith("123"); }); it("should set #subscribed to true", function() { - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(channel.subscribed).toEqual(true); }); it("should set #subscriptionPending to false", function() { - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(channel.subscriptionPending).toEqual(false); }); @@ -147,21 +163,30 @@ describe("PrivateChannel", function() { channel.bind("pusher:subscription_succeeded", callback); channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(callback).not.toHaveBeenCalled(); }); it("should set #subscribed to true", function() { channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(channel.subscribed).toEqual(true); }); it("should set #subscriptionPending to false", function() { channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(channel.subscriptionPending).toEqual(false); }); @@ -170,7 +195,10 @@ describe("PrivateChannel", function() { expect(pusher.unsubscribe).not.toHaveBeenCalled(); channel.cancelSubscription(); - channel.handleEvent("pusher_internal:subscription_succeeded", "123"); + channel.handleEvent({ + event: "pusher_internal:subscription_succeeded", + data: "123" + }); expect(pusher.unsubscribe).toHaveBeenCalledWith(channel.name); }); @@ -181,9 +209,12 @@ describe("PrivateChannel", function() { var callback = jasmine.createSpy("callback"); channel.bind("something", callback); - channel.handleEvent("something", 9); + channel.handleEvent({ + event: "something", + data: 9 + }); - expect(callback).toHaveBeenCalledWith(9); + expect(callback).toHaveBeenCalledWith(9, {}); }); }); }); diff --git a/spec/javascripts/unit/core/connection/connection_spec.js b/spec/javascripts/unit/core/connection/connection_spec.js index 14705ed31..2e35e5ac6 100644 --- a/spec/javascripts/unit/core/connection/connection_spec.js +++ b/spec/javascripts/unit/core/connection/connection_spec.js @@ -114,7 +114,7 @@ describe("Connection", function() { }); expect(onMessage).toHaveBeenCalledWith({ event: "random", - data: { foo: "bar" } + data: { foo: "bar" }, }); }); diff --git a/spec/javascripts/unit/core/connection/protocol_spec.js b/spec/javascripts/unit/core/connection/protocol_spec.js index 4845bf2ad..792af440e 100644 --- a/spec/javascripts/unit/core/connection/protocol_spec.js +++ b/spec/javascripts/unit/core/connection/protocol_spec.js @@ -14,7 +14,7 @@ describe("Protocol", function() { event: "random", data: { foo: "bar" - } + }, }); }); @@ -28,7 +28,7 @@ describe("Protocol", function() { expect(Protocol.decodeMessage(message)).toEqual({ event: "raw", - data: "just a string" + data: "just a string", }); }); @@ -45,7 +45,22 @@ describe("Protocol", function() { data: { x: "y", z: 1 - } + }, + }); + }); + it("should parse user_id message with user_id", function() { + var message = { + data: JSON.stringify({ + event: "raw", + data: "just a string", + user_id: "abc-def", + }) + }; + + expect(Protocol.decodeMessage(message)).toEqual({ + event: "raw", + data: "just a string", + user_id: "abc-def" }); }); diff --git a/spec/javascripts/unit/core/events_dispatcher_spec.js b/spec/javascripts/unit/core/events_dispatcher_spec.js index 248def496..f19a01bd4 100644 --- a/spec/javascripts/unit/core/events_dispatcher_spec.js +++ b/spec/javascripts/unit/core/events_dispatcher_spec.js @@ -306,6 +306,14 @@ describe("EventsDispatcher", function() { expect(boundContext).toEqual(context); expect(unboundContext).toEqual(global); }); + it("should call listener with provided metadata", function() { + var callback = jasmine.createSpy("callback"); + dispatcher.bind("some-event", callback); + + dispatcher.emit("some-event", {data: 1}, {user_id: "123-abc"}) + + expect(callback).toHaveBeenCalledWith({data: 1}, {user_id: "123-abc"}) + }) }); describe("#unbind_global", function() { diff --git a/spec/javascripts/unit/core/pusher_spec.js b/spec/javascripts/unit/core/pusher_spec.js index c423170c6..8a44b2e60 100644 --- a/spec/javascripts/unit/core/pusher_spec.js +++ b/spec/javascripts/unit/core/pusher_spec.js @@ -376,9 +376,11 @@ describe("Pusher", function() { event: "event", data: { key: "value" } }); - expect(channel.handleEvent).toHaveBeenCalledWith( - "event", { key: "value" } - ); + expect(channel.handleEvent).toHaveBeenCalledWith({ + channel: "chan", + event: "event", + data: { key: "value" }, + }); }); it("should not publish events to other channels", function() { diff --git a/spec/javascripts/unit/core/transports/transport_connection_spec.js b/spec/javascripts/unit/core/transports/transport_connection_spec.js index 1a55e32a5..9fb0475fb 100644 --- a/spec/javascripts/unit/core/transports/transport_connection_spec.js +++ b/spec/javascripts/unit/core/transports/transport_connection_spec.js @@ -539,7 +539,7 @@ describe("TransportConnection", function() { socket.onclose(); - expect(onClosed).toHaveBeenCalledWith(undefined); + expect(onClosed).toHaveBeenCalled(); expect(onClosed.calls.length).toEqual(1); }); diff --git a/src/core/channels/channel.ts b/src/core/channels/channel.ts index c3b8cabd6..6b9183ad6 100644 --- a/src/core/channels/channel.ts +++ b/src/core/channels/channel.ts @@ -2,6 +2,9 @@ import {default as EventsDispatcher} from '../events/dispatcher'; import * as Errors from '../errors'; import Logger from '../logger'; import Pusher from '../pusher'; +import {PusherEvent} from '../connection/protocol/message-types'; +import Metadata from './metadata' +import UrlStore from '../utils/url_store'; /** Provides base public channel interface with an event emitter. * @@ -46,6 +49,12 @@ export default class Channel extends EventsDispatcher { "Event '" + event + "' does not start with 'client-'" ); } + if (!this.subscribed) { + var suffix = UrlStore.buildLogSuffix("triggeringClientEvents"); + Logger.warn( + `Client event triggered before channel 'subscription_succeeded' event . ${suffix}` + ); + } return this.pusher.send_event(event, data, this.name); } @@ -55,24 +64,28 @@ export default class Channel extends EventsDispatcher { this.subscriptionPending = false; } - /** Handles an event. For internal use only. + /** Handles a PusherEvent. For internal use only. * - * @param {String} event - * @param {*} data + * @param {PusherEvent} event */ - handleEvent(event : string, data : any) { - if (event.indexOf("pusher_internal:") === 0) { - if (event === "pusher_internal:subscription_succeeded") { - this.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } else { - this.emit("pusher:subscription_succeeded", data); - } - } + handleEvent(event: PusherEvent) { + 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: Metadata = {} + this.emit(eventName, data, metadata); + } + } + + handleSubscriptionSucceededEvent(event: PusherEvent) { + this.subscriptionPending = false; + this.subscribed = true; + if (this.subscriptionCancelled) { + this.pusher.unsubscribe(this.name); } else { - this.emit(event, data); + this.emit("pusher:subscription_succeeded", event.data); } } @@ -83,7 +96,7 @@ export default class Channel extends EventsDispatcher { this.subscriptionCancelled = false; this.authorize(this.pusher.connection.socket_id, (error, data)=> { if (error) { - this.handleEvent('pusher:subscription_error', data); + this.emit('pusher:subscription_error', data) } else { this.pusher.send_event('pusher:subscribe', { auth: data.auth, diff --git a/src/core/channels/encrypted_channel.ts b/src/core/channels/encrypted_channel.ts index af4af192d..9c44ce5f3 100644 --- a/src/core/channels/encrypted_channel.ts +++ b/src/core/channels/encrypted_channel.ts @@ -7,6 +7,7 @@ import { decodeBase64 } from "tweetnacl-util"; import Dispatcher from "../events/dispatcher"; +import {PusherEvent} from '../connection/protocol/message-types'; /** Extends private channels to provide encrypted channel interface. * @@ -48,15 +49,16 @@ export default class EncryptedChannel extends PrivateChannel { /** Handles an event. For internal use only. * - * @param {String} event - * @param {*} data + * @param {PusherEvent} event */ - handleEvent(event: string, data: any) { - if (event.indexOf("pusher_internal:") === 0 || event.indexOf("pusher:") === 0) { - super.handleEvent(event, data); + handleEvent(event: PusherEvent) { + var eventName = event.event; + var data = event.data; + if (eventName.indexOf("pusher_internal:") === 0 || eventName.indexOf("pusher:") === 0) { + super.handleEvent(event); return } - this.handleEncryptedEvent(event, data) + this.handleEncryptedEvent(eventName, data) } private handleEncryptedEvent(event: string, data: any): void { diff --git a/src/core/channels/metadata.ts b/src/core/channels/metadata.ts new file mode 100644 index 000000000..b359ab805 --- /dev/null +++ b/src/core/channels/metadata.ts @@ -0,0 +1,5 @@ +interface Metadata { + user_id?: string +} + +export default Metadata diff --git a/src/core/channels/presence_channel.ts b/src/core/channels/presence_channel.ts index d50c0d9fc..1d28018a8 100644 --- a/src/core/channels/presence_channel.ts +++ b/src/core/channels/presence_channel.ts @@ -3,6 +3,8 @@ import Logger from '../logger'; import Members from './members'; import Pusher from '../pusher'; import UrlStore from 'core/utils/url_store'; +import {PusherEvent} from '../connection/protocol/message-types'; +import Metadata from './metadata' export default class PresenceChannel extends PrivateChannel { members: Members; @@ -43,21 +45,28 @@ export default class PresenceChannel extends PrivateChannel { /** Handles presence and subscription events. For internal use only. * - * @param {String} event - * @param {*} data + * @param {PusherEvent} event */ - handleEvent(event : string, data : any) { - switch (event) { + handleEvent(event: PusherEvent) { + var eventName = event.event; + if (eventName.indexOf("pusher_internal:") === 0) { + this.handleInternalEvent(event) + } else { + var data = event.data; + var metadata: Metadata = {}; + if (event.user_id) { + metadata.user_id = event.user_id + } + this.emit(eventName, data, metadata); + } + } + handleInternalEvent(event: PusherEvent) { + var eventName = event.event; + var data = event.data; + switch (eventName) { case "pusher_internal:subscription_succeeded": - this.subscriptionPending = false; - this.subscribed = true; - if (this.subscriptionCancelled) { - this.pusher.unsubscribe(this.name); - } else { - this.members.onSubscription(data); - this.emit("pusher:subscription_succeeded", this.members); - } - break; + this.handleSubscriptionSucceededEvent(event) + break case "pusher_internal:member_added": var addedMember = this.members.addMember(data); this.emit('pusher:member_added', addedMember); @@ -68,8 +77,17 @@ export default class PresenceChannel extends PrivateChannel { this.emit('pusher:member_removed', removedMember); } break; - default: - PrivateChannel.prototype.handleEvent.call(this, event, data); + } + } + + handleSubscriptionSucceededEvent(event: PusherEvent) { + 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); } } diff --git a/src/core/connection/connection.ts b/src/core/connection/connection.ts index 7e288bb26..5c824ba4c 100644 --- a/src/core/connection/connection.ts +++ b/src/core/connection/connection.ts @@ -1,7 +1,7 @@ import * as Collections from '../utils/collections'; import {default as EventsDispatcher} from '../events/dispatcher'; import * as Protocol from './protocol/protocol'; -import Message from './protocol/message'; +import {PusherEvent} from './protocol/message-types'; import Logger from '../logger'; import TransportConnection from "../transports/transport_connection"; import Socket from "../socket"; @@ -58,12 +58,12 @@ export default class Connection extends EventsDispatcher implements Socket { * @returns {Boolean} whether message was sent or not */ send_event(name : string, data : any, channel?: string) : boolean { - var message : Message = { event: name, data: data }; + var event : PusherEvent = { event: name, data: data }; if (channel) { - message.channel = channel; + event.channel = channel; } - Logger.debug('Event sent', message); - return this.send(Protocol.encodeMessage(message)); + Logger.debug('Event sent', event); + return this.send(Protocol.encodeMessage(event)); } /** Sends a ping message to the server. @@ -86,24 +86,24 @@ export default class Connection extends EventsDispatcher implements Socket { private bindListeners() { var listeners = { - message: (m)=> { - var message; + message: (messageEvent: MessageEvent)=> { + var pusherEvent; try { - message = Protocol.decodeMessage(m); + pusherEvent = Protocol.decodeMessage(messageEvent); } catch(e) { this.emit('error', { type: 'MessageParseError', error: e, - data: m.data + data: messageEvent.data }); } - if (message !== undefined) { - Logger.debug('Event recd', message); + if (pusherEvent !== undefined) { + Logger.debug('Event recd', pusherEvent); - switch (message.event) { + switch (pusherEvent.event) { case 'pusher:error': - this.emit('error', { type: 'PusherError', data: message.data }); + this.emit('error', { type: 'PusherError', data: pusherEvent.data }); break; case 'pusher:ping': this.emit("ping"); @@ -112,7 +112,7 @@ export default class Connection extends EventsDispatcher implements Socket { this.emit("pong"); break; } - this.emit('message', message); + this.emit('message', pusherEvent); } }, activity: ()=> { diff --git a/src/core/connection/protocol/message-types.ts b/src/core/connection/protocol/message-types.ts new file mode 100644 index 000000000..c45dedf73 --- /dev/null +++ b/src/core/connection/protocol/message-types.ts @@ -0,0 +1,8 @@ +interface PusherEvent { + event: string; + channel?: string; + data?: any; + user_id?: string; +} + +export {PusherEvent} diff --git a/src/core/connection/protocol/message.ts b/src/core/connection/protocol/message.ts deleted file mode 100644 index 403293efe..000000000 --- a/src/core/connection/protocol/message.ts +++ /dev/null @@ -1,7 +0,0 @@ -interface Message { - event: string; - channel?: string; - data?: any; -} - -export default Message; diff --git a/src/core/connection/protocol/protocol.ts b/src/core/connection/protocol/protocol.ts index e033613a6..7d07e2003 100644 --- a/src/core/connection/protocol/protocol.ts +++ b/src/core/connection/protocol/protocol.ts @@ -1,5 +1,5 @@ import Action from './action'; -import Message from './message'; +import {PusherEvent} from './message-types'; /** * Provides functions for handling Pusher protocol-specific messages. */ @@ -7,39 +7,49 @@ import Message from './message'; /** * Decodes a message in a Pusher format. * + * The MessageEvent we receive from the transport should contain a pusher event + * (https://pusher.com/docs/pusher_protocol#events) serialized as JSON in the + * data field + * + * The pusher event may contain a data field too, and it may also be + * serialised as JSON + * * Throws errors when messages are not parse'able. * - * @param {Object} message - * @return {Object} + * @param {MessageEvent} messageEvent + * @return {PusherEvent} */ -export var decodeMessage = function(message : Message) : Message { +export var decodeMessage = function(messageEvent : MessageEvent) : PusherEvent { try { - var params = JSON.parse(message.data); - if (typeof params.data === 'string') { + var messageData = JSON.parse(messageEvent.data); + var pusherEventData = messageData.data; + if (typeof pusherEventData === 'string') { try { - params.data = JSON.parse(params.data); - } catch (e) { - if (!(e instanceof SyntaxError)) { - // TODO looks like unreachable code - // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/parse - throw e; - } - } + pusherEventData = JSON.parse(messageData.data) + } catch (e) {} + } + var pusherEvent: PusherEvent = { + event: messageData.event, + channel: messageData.channel, + data: pusherEventData, + } + if (messageData.user_id) { + pusherEvent.user_id = messageData.user_id } - return params; + return pusherEvent; } catch (e) { - throw { type: 'MessageParseError', error: e, data: message.data}; + throw { type: 'MessageParseError', error: e, data: messageEvent.data}; } }; /** * Encodes a message to be sent. * - * @param {Object} message + * @param {PusherEvent} event * @return {String} */ -export var encodeMessage = function(message : Message) : string { - return JSON.stringify(message); +export var encodeMessage = function(event : PusherEvent) : string { + return JSON.stringify(event); }; /** Processes a handshake message and returns appropriate actions. @@ -55,8 +65,8 @@ export var encodeMessage = function(message : Message) : string { * @param {String} message * @result Object */ -export var processHandshake = function(message : Message) : Action { - message = decodeMessage(message); +export var processHandshake = function(messageEvent : MessageEvent) : Action { + var message = decodeMessage(messageEvent); if (message.event === "pusher:connection_established") { if (!message.data.activity_timeout) { diff --git a/src/core/events/dispatcher.ts b/src/core/events/dispatcher.ts index ff62f1451..7c7f200fa 100644 --- a/src/core/events/dispatcher.ts +++ b/src/core/events/dispatcher.ts @@ -1,5 +1,6 @@ import * as Collections from '../utils/collections'; import Callback from './callback'; +import Metadata from '../channels/metadata'; import CallbackRegistry from './callback_registry'; /** Manages callback bindings and event emitting. @@ -52,17 +53,29 @@ export default class Dispatcher { return this; } - emit(eventName : string, data?: any) : Dispatcher { - var i; - - for (i = 0; i < this.global_callbacks.length; i++) { + emit(eventName : string, data?: any, metadata?: Metadata) : Dispatcher { + 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) { + + // if there's a metadata argument, we need to call the callback with both + // data and metadata regardless of whether data is undefined + args.push(data, metadata) + } else if (data) { + + // metadata is undefined, so we only need to call the callback with data + // if data exists + args.push(data) + } + if (callbacks && callbacks.length > 0) { - for (i = 0; i < callbacks.length; i++) { - callbacks[i].fn.call(callbacks[i].context || global, data); + 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); diff --git a/src/core/pusher.ts b/src/core/pusher.ts index a5d600930..4fdbf326a 100644 --- a/src/core/pusher.ts +++ b/src/core/pusher.ts @@ -128,17 +128,18 @@ export default class Pusher { this.timelineSender.send(this.connection.isUsingTLS()); } }); - this.connection.bind('message', (params)=> { - var internal = (params.event.indexOf('pusher_internal:') === 0); - if (params.channel) { - var channel = this.channel(params.channel); + this.connection.bind('message', (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(params.event, params.data); + channel.handleEvent(event); } } // Emit globally [deprecated] if (!internal) { - this.global_emitter.emit(params.event, params.data); + this.global_emitter.emit(event.event, event.data); } }); this.connection.bind('connecting', ()=> { diff --git a/src/core/utils/url_store.ts b/src/core/utils/url_store.ts index d8878dfdc..b124ada7c 100644 --- a/src/core/utils/url_store.ts +++ b/src/core/utils/url_store.ts @@ -11,6 +11,9 @@ const urlStore = { javascriptQuickStart: { path: "/docs/javascript_quick_start" }, + triggeringClientEvents: { + path: "/docs/client_api_guide/client_events#trigger-events" + } } }