pusher-fake 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62beea93e9ce28262adbb1c518dc08339653a1ab
4
- data.tar.gz: eb3e058b54e30f0c5c0bf16ec34997e20a1d279d
3
+ metadata.gz: b8c976f869c3748f43a742935c8acad5cde44975
4
+ data.tar.gz: db6247945298f77491265ae3286ea5f74919b0df
5
5
  SHA512:
6
- metadata.gz: f4f120392332c62301f21506c155e339bedf2ef35ee9dc9a301f9ee020332d72e51d8281b4a036a8e026d77e9d4a6c5b15b414085ba10a96fe9bce00d5af3856
7
- data.tar.gz: cc290d61c303374212512c59570f1e2b4d469b92343fb0bfc804b4e754bf35ccccba9cb819f7276cd474b26ab581e3fa925a3e7f75ed2d03f2442d6b92056995
6
+ metadata.gz: 6bf7fa18cb12730f9605d35e305ee17d9a47f2504ac539f69413e382a84f9057774960536b2dbf2dd813ec84082e3265efd6f4967eb5029167bdfef1c35c088f
7
+ data.tar.gz: a69826309bcd9da0fe4882cc5f153303aa46a7397ba977ca1497f68cae6cc8c3ba342cc901f27b08dd0be3dfb14dfaaff0136123d98887676823365fa159545d
@@ -6,7 +6,7 @@ require "thin"
6
6
 
7
7
  module PusherFake
8
8
  # The current version string.
9
- VERSION = "1.5.0"
9
+ VERSION = "1.6.0"
10
10
 
11
11
  autoload :Channel, "pusher-fake/channel"
12
12
  autoload :Configuration, "pusher-fake/configuration"
@@ -0,0 +1,4052 @@
1
+ /*!
2
+ * Pusher JavaScript Library v3.1.0
3
+ * http://pusher.com/
4
+ *
5
+ * Copyright 2016, Pusher
6
+ * Released under the MIT licence.
7
+ */
8
+
9
+ (function webpackUniversalModuleDefinition(root, factory) {
10
+ if(typeof exports === 'object' && typeof module === 'object')
11
+ module.exports = factory();
12
+ else if(typeof define === 'function' && define.amd)
13
+ define([], factory);
14
+ else if(typeof exports === 'object')
15
+ exports["Pusher"] = factory();
16
+ else
17
+ root["Pusher"] = factory();
18
+ })(this, function() {
19
+ return /******/ (function(modules) { // webpackBootstrap
20
+ /******/ // The module cache
21
+ /******/ var installedModules = {};
22
+
23
+ /******/ // The require function
24
+ /******/ function __webpack_require__(moduleId) {
25
+
26
+ /******/ // Check if module is in cache
27
+ /******/ if(installedModules[moduleId])
28
+ /******/ return installedModules[moduleId].exports;
29
+
30
+ /******/ // Create a new module (and put it into the cache)
31
+ /******/ var module = installedModules[moduleId] = {
32
+ /******/ exports: {},
33
+ /******/ id: moduleId,
34
+ /******/ loaded: false
35
+ /******/ };
36
+
37
+ /******/ // Execute the module function
38
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
39
+
40
+ /******/ // Flag the module as loaded
41
+ /******/ module.loaded = true;
42
+
43
+ /******/ // Return the exports of the module
44
+ /******/ return module.exports;
45
+ /******/ }
46
+
47
+
48
+ /******/ // expose the modules object (__webpack_modules__)
49
+ /******/ __webpack_require__.m = modules;
50
+
51
+ /******/ // expose the module cache
52
+ /******/ __webpack_require__.c = installedModules;
53
+
54
+ /******/ // __webpack_public_path__
55
+ /******/ __webpack_require__.p = "";
56
+
57
+ /******/ // Load entry module and return exports
58
+ /******/ return __webpack_require__(0);
59
+ /******/ })
60
+ /************************************************************************/
61
+ /******/ ([
62
+ /* 0 */
63
+ /***/ function(module, exports, __webpack_require__) {
64
+
65
+ "use strict";
66
+ var pusher_1 = __webpack_require__(1);
67
+ module.exports = pusher_1["default"];
68
+
69
+
70
+ /***/ },
71
+ /* 1 */
72
+ /***/ function(module, exports, __webpack_require__) {
73
+
74
+ "use strict";
75
+ var runtime_1 = __webpack_require__(2);
76
+ var Collections = __webpack_require__(9);
77
+ var dispatcher_1 = __webpack_require__(23);
78
+ var timeline_1 = __webpack_require__(38);
79
+ var level_1 = __webpack_require__(39);
80
+ var StrategyBuilder = __webpack_require__(40);
81
+ var timers_1 = __webpack_require__(12);
82
+ var defaults_1 = __webpack_require__(5);
83
+ var DefaultConfig = __webpack_require__(62);
84
+ var logger_1 = __webpack_require__(8);
85
+ var factory_1 = __webpack_require__(42);
86
+ var Pusher = (function () {
87
+ function Pusher(app_key, options) {
88
+ var _this = this;
89
+ checkAppKey(app_key);
90
+ options = options || {};
91
+ this.key = app_key;
92
+ this.config = Collections.extend(DefaultConfig.getGlobalConfig(), options.cluster ? DefaultConfig.getClusterConfig(options.cluster) : {}, options);
93
+ this.channels = factory_1["default"].createChannels();
94
+ this.global_emitter = new dispatcher_1["default"]();
95
+ this.sessionID = Math.floor(Math.random() * 1000000000);
96
+ this.timeline = new timeline_1["default"](this.key, this.sessionID, {
97
+ cluster: this.config.cluster,
98
+ features: Pusher.getClientFeatures(),
99
+ params: this.config.timelineParams || {},
100
+ limit: 50,
101
+ level: level_1["default"].INFO,
102
+ version: defaults_1["default"].VERSION
103
+ });
104
+ if (!this.config.disableStats) {
105
+ this.timelineSender = factory_1["default"].createTimelineSender(this.timeline, {
106
+ host: this.config.statsHost,
107
+ path: "/timeline/v2/" + runtime_1["default"].TimelineTransport.name
108
+ });
109
+ }
110
+ var getStrategy = function (options) {
111
+ var config = Collections.extend({}, _this.config, options);
112
+ return StrategyBuilder.build(runtime_1["default"].getDefaultStrategy(config), config);
113
+ };
114
+ this.connection = factory_1["default"].createConnectionManager(this.key, Collections.extend({ getStrategy: getStrategy,
115
+ timeline: this.timeline,
116
+ activityTimeout: this.config.activity_timeout,
117
+ pongTimeout: this.config.pong_timeout,
118
+ unavailableTimeout: this.config.unavailable_timeout
119
+ }, this.config, { encrypted: this.isEncrypted() }));
120
+ this.connection.bind('connected', function () {
121
+ _this.subscribeAll();
122
+ if (_this.timelineSender) {
123
+ _this.timelineSender.send(_this.connection.isEncrypted());
124
+ }
125
+ });
126
+ this.connection.bind('message', function (params) {
127
+ var internal = (params.event.indexOf('pusher_internal:') === 0);
128
+ if (params.channel) {
129
+ var channel = _this.channel(params.channel);
130
+ if (channel) {
131
+ channel.handleEvent(params.event, params.data);
132
+ }
133
+ }
134
+ if (!internal) {
135
+ _this.global_emitter.emit(params.event, params.data);
136
+ }
137
+ });
138
+ this.connection.bind('disconnected', function () {
139
+ _this.channels.disconnect();
140
+ });
141
+ this.connection.bind('error', function (err) {
142
+ logger_1["default"].warn('Error', err);
143
+ });
144
+ Pusher.instances.push(this);
145
+ this.timeline.info({ instances: Pusher.instances.length });
146
+ if (Pusher.isReady) {
147
+ this.connect();
148
+ }
149
+ }
150
+ Pusher.ready = function () {
151
+ Pusher.isReady = true;
152
+ for (var i = 0, l = Pusher.instances.length; i < l; i++) {
153
+ Pusher.instances[i].connect();
154
+ }
155
+ };
156
+ Pusher.log = function (message) {
157
+ var global = Function("return this")();
158
+ if (Pusher.logToConsole && global.console && global.console.log) {
159
+ global.console.log(message);
160
+ }
161
+ };
162
+ Pusher.getClientFeatures = function () {
163
+ return Collections.keys(Collections.filterObject({ "ws": runtime_1["default"].Transports.ws }, function (t) { return t.isSupported({}); }));
164
+ };
165
+ Pusher.prototype.channel = function (name) {
166
+ return this.channels.find(name);
167
+ };
168
+ Pusher.prototype.allChannels = function () {
169
+ return this.channels.all();
170
+ };
171
+ Pusher.prototype.connect = function () {
172
+ this.connection.connect();
173
+ if (this.timelineSender) {
174
+ if (!this.timelineSenderTimer) {
175
+ var encrypted = this.connection.isEncrypted();
176
+ var timelineSender = this.timelineSender;
177
+ this.timelineSenderTimer = new timers_1.PeriodicTimer(60000, function () {
178
+ timelineSender.send(encrypted);
179
+ });
180
+ }
181
+ }
182
+ };
183
+ Pusher.prototype.disconnect = function () {
184
+ this.connection.disconnect();
185
+ if (this.timelineSenderTimer) {
186
+ this.timelineSenderTimer.ensureAborted();
187
+ this.timelineSenderTimer = null;
188
+ }
189
+ };
190
+ Pusher.prototype.bind = function (event_name, callback) {
191
+ this.global_emitter.bind(event_name, callback);
192
+ return this;
193
+ };
194
+ Pusher.prototype.bind_all = function (callback) {
195
+ this.global_emitter.bind_all(callback);
196
+ return this;
197
+ };
198
+ Pusher.prototype.subscribeAll = function () {
199
+ var channelName;
200
+ for (channelName in this.channels.channels) {
201
+ if (this.channels.channels.hasOwnProperty(channelName)) {
202
+ this.subscribe(channelName);
203
+ }
204
+ }
205
+ };
206
+ Pusher.prototype.subscribe = function (channel_name) {
207
+ var channel = this.channels.add(channel_name, this);
208
+ if (this.connection.state === "connected") {
209
+ channel.subscribe();
210
+ }
211
+ return channel;
212
+ };
213
+ Pusher.prototype.unsubscribe = function (channel_name) {
214
+ var channel = this.channels.remove(channel_name);
215
+ if (channel && this.connection.state === "connected") {
216
+ channel.unsubscribe();
217
+ }
218
+ };
219
+ Pusher.prototype.send_event = function (event_name, data, channel) {
220
+ return this.connection.send_event(event_name, data, channel);
221
+ };
222
+ Pusher.prototype.isEncrypted = function () {
223
+ if (runtime_1["default"].getProtocol() === "https:") {
224
+ return true;
225
+ }
226
+ else {
227
+ return Boolean(this.config.encrypted);
228
+ }
229
+ };
230
+ Pusher.instances = [];
231
+ Pusher.isReady = false;
232
+ Pusher.logToConsole = false;
233
+ Pusher.Runtime = runtime_1["default"];
234
+ Pusher.ScriptReceivers = runtime_1["default"].ScriptReceivers;
235
+ Pusher.DependenciesReceivers = runtime_1["default"].DependenciesReceivers;
236
+ Pusher.auth_callbacks = runtime_1["default"].auth_callbacks;
237
+ return Pusher;
238
+ }());
239
+ exports.__esModule = true;
240
+ exports["default"] = Pusher;
241
+ function checkAppKey(key) {
242
+ if (key === null || key === undefined) {
243
+ throw "You must pass your app key when you instantiate Pusher.";
244
+ }
245
+ }
246
+ runtime_1["default"].setup(Pusher);
247
+
248
+
249
+ /***/ },
250
+ /* 2 */
251
+ /***/ function(module, exports, __webpack_require__) {
252
+
253
+ "use strict";
254
+ var dependencies_1 = __webpack_require__(3);
255
+ var xhr_auth_1 = __webpack_require__(7);
256
+ var jsonp_auth_1 = __webpack_require__(14);
257
+ var script_request_1 = __webpack_require__(15);
258
+ var jsonp_request_1 = __webpack_require__(16);
259
+ var script_receiver_factory_1 = __webpack_require__(4);
260
+ var jsonp_timeline_1 = __webpack_require__(17);
261
+ var transports_1 = __webpack_require__(18);
262
+ var net_info_1 = __webpack_require__(25);
263
+ var default_strategy_1 = __webpack_require__(26);
264
+ var transport_connection_initializer_1 = __webpack_require__(27);
265
+ var http_1 = __webpack_require__(28);
266
+ var Runtime = {
267
+ nextAuthCallbackID: 1,
268
+ auth_callbacks: {},
269
+ ScriptReceivers: script_receiver_factory_1.ScriptReceivers,
270
+ DependenciesReceivers: dependencies_1.DependenciesReceivers,
271
+ getDefaultStrategy: default_strategy_1["default"],
272
+ Transports: transports_1["default"],
273
+ transportConnectionInitializer: transport_connection_initializer_1["default"],
274
+ HTTPFactory: http_1["default"],
275
+ TimelineTransport: jsonp_timeline_1["default"],
276
+ getXHRAPI: function () {
277
+ return window.XMLHttpRequest;
278
+ },
279
+ getWebSocketAPI: function () {
280
+ return window.WebSocket || window.MozWebSocket;
281
+ },
282
+ setup: function (PusherClass) {
283
+ var _this = this;
284
+ window.Pusher = PusherClass;
285
+ var initializeOnDocumentBody = function () {
286
+ _this.onDocumentBody(PusherClass.ready);
287
+ };
288
+ if (!window.JSON) {
289
+ dependencies_1.Dependencies.load("json2", {}, initializeOnDocumentBody);
290
+ }
291
+ else {
292
+ initializeOnDocumentBody();
293
+ }
294
+ },
295
+ getDocument: function () {
296
+ return document;
297
+ },
298
+ getProtocol: function () {
299
+ return this.getDocument().location.protocol;
300
+ },
301
+ getGlobal: function () {
302
+ return window;
303
+ },
304
+ getAuthorizers: function () {
305
+ return { ajax: xhr_auth_1["default"], jsonp: jsonp_auth_1["default"] };
306
+ },
307
+ onDocumentBody: function (callback) {
308
+ var _this = this;
309
+ if (document.body) {
310
+ callback();
311
+ }
312
+ else {
313
+ setTimeout(function () {
314
+ _this.onDocumentBody(callback);
315
+ }, 0);
316
+ }
317
+ },
318
+ createJSONPRequest: function (url, data) {
319
+ return new jsonp_request_1["default"](url, data);
320
+ },
321
+ createScriptRequest: function (src) {
322
+ return new script_request_1["default"](src);
323
+ },
324
+ getLocalStorage: function () {
325
+ try {
326
+ return window.localStorage;
327
+ }
328
+ catch (e) {
329
+ return undefined;
330
+ }
331
+ },
332
+ createXHR: function () {
333
+ if (this.getXHRAPI()) {
334
+ return this.createXMLHttpRequest();
335
+ }
336
+ else {
337
+ return this.createMicrosoftXHR();
338
+ }
339
+ },
340
+ createXMLHttpRequest: function () {
341
+ var Constructor = this.getXHRAPI();
342
+ return new Constructor();
343
+ },
344
+ createMicrosoftXHR: function () {
345
+ return new ActiveXObject("Microsoft.XMLHTTP");
346
+ },
347
+ getNetwork: function () {
348
+ return net_info_1.Network;
349
+ },
350
+ createWebSocket: function (url) {
351
+ var Constructor = this.getWebSocketAPI();
352
+ return new Constructor(url);
353
+ },
354
+ createSocketRequest: function (method, url) {
355
+ if (this.isXHRSupported()) {
356
+ return this.HTTPFactory.createXHR(method, url);
357
+ }
358
+ else if (this.isXDRSupported(url.indexOf("https:") === 0)) {
359
+ return this.HTTPFactory.createXDR(method, url);
360
+ }
361
+ else {
362
+ throw "Cross-origin HTTP requests are not supported";
363
+ }
364
+ },
365
+ isXHRSupported: function () {
366
+ var Constructor = this.getXHRAPI();
367
+ return Boolean(Constructor) && (new Constructor()).withCredentials !== undefined;
368
+ },
369
+ isXDRSupported: function (encrypted) {
370
+ var protocol = encrypted ? "https:" : "http:";
371
+ var documentProtocol = this.getProtocol();
372
+ return Boolean((window['XDomainRequest'])) && documentProtocol === protocol;
373
+ },
374
+ addUnloadListener: function (listener) {
375
+ if (window.addEventListener !== undefined) {
376
+ window.addEventListener("unload", listener, false);
377
+ }
378
+ else if (window.attachEvent !== undefined) {
379
+ window.attachEvent("onunload", listener);
380
+ }
381
+ },
382
+ removeUnloadListener: function (listener) {
383
+ if (window.addEventListener !== undefined) {
384
+ window.removeEventListener("unload", listener, false);
385
+ }
386
+ else if (window.detachEvent !== undefined) {
387
+ window.detachEvent("onunload", listener);
388
+ }
389
+ }
390
+ };
391
+ exports.__esModule = true;
392
+ exports["default"] = Runtime;
393
+
394
+
395
+ /***/ },
396
+ /* 3 */
397
+ /***/ function(module, exports, __webpack_require__) {
398
+
399
+ "use strict";
400
+ var script_receiver_factory_1 = __webpack_require__(4);
401
+ var defaults_1 = __webpack_require__(5);
402
+ var dependency_loader_1 = __webpack_require__(6);
403
+ exports.DependenciesReceivers = new script_receiver_factory_1.ScriptReceiverFactory("_pusher_dependencies", "Pusher.DependenciesReceivers");
404
+ exports.Dependencies = new dependency_loader_1["default"]({
405
+ cdn_http: defaults_1["default"].cdn_http,
406
+ cdn_https: defaults_1["default"].cdn_https,
407
+ version: defaults_1["default"].VERSION,
408
+ suffix: defaults_1["default"].dependency_suffix,
409
+ receivers: exports.DependenciesReceivers
410
+ });
411
+
412
+
413
+ /***/ },
414
+ /* 4 */
415
+ /***/ function(module, exports) {
416
+
417
+ "use strict";
418
+ var ScriptReceiverFactory = (function () {
419
+ function ScriptReceiverFactory(prefix, name) {
420
+ this.lastId = 0;
421
+ this.prefix = prefix;
422
+ this.name = name;
423
+ }
424
+ ScriptReceiverFactory.prototype.create = function (callback) {
425
+ this.lastId++;
426
+ var number = this.lastId;
427
+ var id = this.prefix + number;
428
+ var name = this.name + "[" + number + "]";
429
+ var called = false;
430
+ var callbackWrapper = function () {
431
+ if (!called) {
432
+ callback.apply(null, arguments);
433
+ called = true;
434
+ }
435
+ };
436
+ this[number] = callbackWrapper;
437
+ return { number: number, id: id, name: name, callback: callbackWrapper };
438
+ };
439
+ ScriptReceiverFactory.prototype.remove = function (receiver) {
440
+ delete this[receiver.number];
441
+ };
442
+ return ScriptReceiverFactory;
443
+ }());
444
+ exports.ScriptReceiverFactory = ScriptReceiverFactory;
445
+ exports.ScriptReceivers = new ScriptReceiverFactory("_pusher_script_", "Pusher.ScriptReceivers");
446
+
447
+
448
+ /***/ },
449
+ /* 5 */
450
+ /***/ function(module, exports) {
451
+
452
+ "use strict";
453
+ var Defaults = {
454
+ VERSION: "3.1.0",
455
+ PROTOCOL: 7,
456
+ host: 'ws.pusherapp.com',
457
+ ws_port: 80,
458
+ wss_port: 443,
459
+ sockjs_host: 'sockjs.pusher.com',
460
+ sockjs_http_port: 80,
461
+ sockjs_https_port: 443,
462
+ sockjs_path: "/pusher",
463
+ stats_host: 'stats.pusher.com',
464
+ channel_auth_endpoint: '/pusher/auth',
465
+ channel_auth_transport: 'ajax',
466
+ activity_timeout: 120000,
467
+ pong_timeout: 30000,
468
+ unavailable_timeout: 10000,
469
+ cdn_http: 'http://js.pusher.com',
470
+ cdn_https: 'https://js.pusher.com',
471
+ dependency_suffix: ''
472
+ };
473
+ exports.__esModule = true;
474
+ exports["default"] = Defaults;
475
+
476
+
477
+ /***/ },
478
+ /* 6 */
479
+ /***/ function(module, exports, __webpack_require__) {
480
+
481
+ "use strict";
482
+ var script_receiver_factory_1 = __webpack_require__(4);
483
+ var runtime_1 = __webpack_require__(2);
484
+ var DependencyLoader = (function () {
485
+ function DependencyLoader(options) {
486
+ this.options = options;
487
+ this.receivers = options.receivers || script_receiver_factory_1.ScriptReceivers;
488
+ this.loading = {};
489
+ }
490
+ DependencyLoader.prototype.load = function (name, options, callback) {
491
+ var self = this;
492
+ if (self.loading[name] && self.loading[name].length > 0) {
493
+ self.loading[name].push(callback);
494
+ }
495
+ else {
496
+ self.loading[name] = [callback];
497
+ var request = runtime_1["default"].createScriptRequest(self.getPath(name, options));
498
+ var receiver = self.receivers.create(function (error) {
499
+ self.receivers.remove(receiver);
500
+ if (self.loading[name]) {
501
+ var callbacks = self.loading[name];
502
+ delete self.loading[name];
503
+ var successCallback = function (wasSuccessful) {
504
+ if (!wasSuccessful) {
505
+ request.cleanup();
506
+ }
507
+ };
508
+ for (var i = 0; i < callbacks.length; i++) {
509
+ callbacks[i](error, successCallback);
510
+ }
511
+ }
512
+ });
513
+ request.send(receiver);
514
+ }
515
+ };
516
+ DependencyLoader.prototype.getRoot = function (options) {
517
+ var cdn;
518
+ var protocol = runtime_1["default"].getDocument().location.protocol;
519
+ if ((options && options.encrypted) || protocol === "https:") {
520
+ cdn = this.options.cdn_https;
521
+ }
522
+ else {
523
+ cdn = this.options.cdn_http;
524
+ }
525
+ return cdn.replace(/\/*$/, "") + "/" + this.options.version;
526
+ };
527
+ DependencyLoader.prototype.getPath = function (name, options) {
528
+ return this.getRoot(options) + '/' + name + this.options.suffix + '.js';
529
+ };
530
+ ;
531
+ return DependencyLoader;
532
+ }());
533
+ exports.__esModule = true;
534
+ exports["default"] = DependencyLoader;
535
+
536
+
537
+ /***/ },
538
+ /* 7 */
539
+ /***/ function(module, exports, __webpack_require__) {
540
+
541
+ "use strict";
542
+ var logger_1 = __webpack_require__(8);
543
+ var runtime_1 = __webpack_require__(2);
544
+ var ajax = function (context, socketId, callback) {
545
+ var self = this, xhr;
546
+ xhr = runtime_1["default"].createXHR();
547
+ xhr.open("POST", self.options.authEndpoint, true);
548
+ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
549
+ for (var headerName in this.authOptions.headers) {
550
+ xhr.setRequestHeader(headerName, this.authOptions.headers[headerName]);
551
+ }
552
+ xhr.onreadystatechange = function () {
553
+ if (xhr.readyState === 4) {
554
+ if (xhr.status === 200) {
555
+ var data, parsed = false;
556
+ try {
557
+ data = JSON.parse(xhr.responseText);
558
+ parsed = true;
559
+ }
560
+ catch (e) {
561
+ callback(true, 'JSON returned from webapp was invalid, yet status code was 200. Data was: ' + xhr.responseText);
562
+ }
563
+ if (parsed) {
564
+ callback(false, data);
565
+ }
566
+ }
567
+ else {
568
+ logger_1["default"].warn("Couldn't get auth info from your webapp", xhr.status);
569
+ callback(true, xhr.status);
570
+ }
571
+ }
572
+ };
573
+ xhr.send(this.composeQuery(socketId));
574
+ return xhr;
575
+ };
576
+ exports.__esModule = true;
577
+ exports["default"] = ajax;
578
+
579
+
580
+ /***/ },
581
+ /* 8 */
582
+ /***/ function(module, exports, __webpack_require__) {
583
+
584
+ "use strict";
585
+ var collections_1 = __webpack_require__(9);
586
+ var pusher_1 = __webpack_require__(1);
587
+ var Logger = {
588
+ debug: function () {
589
+ var args = [];
590
+ for (var _i = 0; _i < arguments.length; _i++) {
591
+ args[_i - 0] = arguments[_i];
592
+ }
593
+ if (!pusher_1["default"].log) {
594
+ return;
595
+ }
596
+ pusher_1["default"].log(collections_1.stringify.apply(this, arguments));
597
+ },
598
+ warn: function () {
599
+ var args = [];
600
+ for (var _i = 0; _i < arguments.length; _i++) {
601
+ args[_i - 0] = arguments[_i];
602
+ }
603
+ var message = collections_1.stringify.apply(this, arguments);
604
+ var global = Function("return this")();
605
+ if (global.console) {
606
+ if (global.console.warn) {
607
+ global.console.warn(message);
608
+ }
609
+ else if (global.console.log) {
610
+ global.console.log(message);
611
+ }
612
+ }
613
+ if (pusher_1["default"].log) {
614
+ pusher_1["default"].log(message);
615
+ }
616
+ }
617
+ };
618
+ exports.__esModule = true;
619
+ exports["default"] = Logger;
620
+
621
+
622
+ /***/ },
623
+ /* 9 */
624
+ /***/ function(module, exports, __webpack_require__) {
625
+
626
+ "use strict";
627
+ var base64_1 = __webpack_require__(10);
628
+ var util_1 = __webpack_require__(11);
629
+ var global = Function("return this")();
630
+ function extend(target) {
631
+ var sources = [];
632
+ for (var _i = 1; _i < arguments.length; _i++) {
633
+ sources[_i - 1] = arguments[_i];
634
+ }
635
+ for (var i = 0; i < sources.length; i++) {
636
+ var extensions = sources[i];
637
+ for (var property in extensions) {
638
+ if (extensions[property] && extensions[property].constructor &&
639
+ extensions[property].constructor === Object) {
640
+ target[property] = extend(target[property] || {}, extensions[property]);
641
+ }
642
+ else {
643
+ target[property] = extensions[property];
644
+ }
645
+ }
646
+ }
647
+ return target;
648
+ }
649
+ exports.extend = extend;
650
+ function stringify() {
651
+ var m = ["Pusher"];
652
+ for (var i = 0; i < arguments.length; i++) {
653
+ if (typeof arguments[i] === "string") {
654
+ m.push(arguments[i]);
655
+ }
656
+ else {
657
+ m.push(JSON.stringify(arguments[i]));
658
+ }
659
+ }
660
+ return m.join(" : ");
661
+ }
662
+ exports.stringify = stringify;
663
+ function arrayIndexOf(array, item) {
664
+ var nativeIndexOf = Array.prototype.indexOf;
665
+ if (array === null) {
666
+ return -1;
667
+ }
668
+ if (nativeIndexOf && array.indexOf === nativeIndexOf) {
669
+ return array.indexOf(item);
670
+ }
671
+ for (var i = 0, l = array.length; i < l; i++) {
672
+ if (array[i] === item) {
673
+ return i;
674
+ }
675
+ }
676
+ return -1;
677
+ }
678
+ exports.arrayIndexOf = arrayIndexOf;
679
+ function objectApply(object, f) {
680
+ for (var key in object) {
681
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
682
+ f(object[key], key, object);
683
+ }
684
+ }
685
+ }
686
+ exports.objectApply = objectApply;
687
+ function keys(object) {
688
+ var keys = [];
689
+ objectApply(object, function (_, key) {
690
+ keys.push(key);
691
+ });
692
+ return keys;
693
+ }
694
+ exports.keys = keys;
695
+ function values(object) {
696
+ var values = [];
697
+ objectApply(object, function (value) {
698
+ values.push(value);
699
+ });
700
+ return values;
701
+ }
702
+ exports.values = values;
703
+ function apply(array, f, context) {
704
+ for (var i = 0; i < array.length; i++) {
705
+ f.call(context || global, array[i], i, array);
706
+ }
707
+ }
708
+ exports.apply = apply;
709
+ function map(array, f) {
710
+ var result = [];
711
+ for (var i = 0; i < array.length; i++) {
712
+ result.push(f(array[i], i, array, result));
713
+ }
714
+ return result;
715
+ }
716
+ exports.map = map;
717
+ function mapObject(object, f) {
718
+ var result = {};
719
+ objectApply(object, function (value, key) {
720
+ result[key] = f(value);
721
+ });
722
+ return result;
723
+ }
724
+ exports.mapObject = mapObject;
725
+ function filter(array, test) {
726
+ test = test || function (value) { return !!value; };
727
+ var result = [];
728
+ for (var i = 0; i < array.length; i++) {
729
+ if (test(array[i], i, array, result)) {
730
+ result.push(array[i]);
731
+ }
732
+ }
733
+ return result;
734
+ }
735
+ exports.filter = filter;
736
+ function filterObject(object, test) {
737
+ var result = {};
738
+ objectApply(object, function (value, key) {
739
+ if ((test && test(value, key, object, result)) || Boolean(value)) {
740
+ result[key] = value;
741
+ }
742
+ });
743
+ return result;
744
+ }
745
+ exports.filterObject = filterObject;
746
+ function flatten(object) {
747
+ var result = [];
748
+ objectApply(object, function (value, key) {
749
+ result.push([key, value]);
750
+ });
751
+ return result;
752
+ }
753
+ exports.flatten = flatten;
754
+ function any(array, test) {
755
+ for (var i = 0; i < array.length; i++) {
756
+ if (test(array[i], i, array)) {
757
+ return true;
758
+ }
759
+ }
760
+ return false;
761
+ }
762
+ exports.any = any;
763
+ function all(array, test) {
764
+ for (var i = 0; i < array.length; i++) {
765
+ if (!test(array[i], i, array)) {
766
+ return false;
767
+ }
768
+ }
769
+ return true;
770
+ }
771
+ exports.all = all;
772
+ function encodeParamsObject(data) {
773
+ return mapObject(data, function (value) {
774
+ if (typeof value === "object") {
775
+ value = JSON.stringify(value);
776
+ }
777
+ return encodeURIComponent(base64_1["default"](value.toString()));
778
+ });
779
+ }
780
+ exports.encodeParamsObject = encodeParamsObject;
781
+ function buildQueryString(data) {
782
+ var params = filterObject(data, function (value) {
783
+ return value !== undefined;
784
+ });
785
+ var query = map(flatten(encodeParamsObject(params)), util_1["default"].method("join", "=")).join("&");
786
+ return query;
787
+ }
788
+ exports.buildQueryString = buildQueryString;
789
+ function safeJSONStringify(source) {
790
+ var cache = [];
791
+ var serialized = JSON.stringify(source, function (key, value) {
792
+ if (typeof value === 'object' && value !== null) {
793
+ if (cache.indexOf(value) !== -1) {
794
+ return;
795
+ }
796
+ cache.push(value);
797
+ }
798
+ return value;
799
+ });
800
+ cache = null;
801
+ return serialized;
802
+ }
803
+ exports.safeJSONStringify = safeJSONStringify;
804
+
805
+
806
+ /***/ },
807
+ /* 10 */
808
+ /***/ function(module, exports) {
809
+
810
+ "use strict";
811
+ var global = Function("return this")();
812
+ function encode(s) {
813
+ return btoa(utob(s));
814
+ }
815
+ exports.__esModule = true;
816
+ exports["default"] = encode;
817
+ var fromCharCode = String.fromCharCode;
818
+ var b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
819
+ var b64tab = {};
820
+ for (var i = 0, l = b64chars.length; i < l; i++) {
821
+ b64tab[b64chars.charAt(i)] = i;
822
+ }
823
+ var cb_utob = function (c) {
824
+ var cc = c.charCodeAt(0);
825
+ return cc < 0x80 ? c
826
+ : cc < 0x800 ? fromCharCode(0xc0 | (cc >>> 6)) +
827
+ fromCharCode(0x80 | (cc & 0x3f))
828
+ : fromCharCode(0xe0 | ((cc >>> 12) & 0x0f)) +
829
+ fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) +
830
+ fromCharCode(0x80 | (cc & 0x3f));
831
+ };
832
+ var utob = function (u) {
833
+ return u.replace(/[^\x00-\x7F]/g, cb_utob);
834
+ };
835
+ var cb_encode = function (ccc) {
836
+ var padlen = [0, 2, 1][ccc.length % 3];
837
+ var ord = ccc.charCodeAt(0) << 16
838
+ | ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8)
839
+ | ((ccc.length > 2 ? ccc.charCodeAt(2) : 0));
840
+ var chars = [
841
+ b64chars.charAt(ord >>> 18),
842
+ b64chars.charAt((ord >>> 12) & 63),
843
+ padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63),
844
+ padlen >= 1 ? '=' : b64chars.charAt(ord & 63)
845
+ ];
846
+ return chars.join('');
847
+ };
848
+ var btoa = global.btoa || function (b) {
849
+ return b.replace(/[\s\S]{1,3}/g, cb_encode);
850
+ };
851
+
852
+
853
+ /***/ },
854
+ /* 11 */
855
+ /***/ function(module, exports, __webpack_require__) {
856
+
857
+ "use strict";
858
+ var timers_1 = __webpack_require__(12);
859
+ var Util = {
860
+ getGlobal: function () {
861
+ return Function("return this")();
862
+ },
863
+ now: function () {
864
+ if (Date.now) {
865
+ return Date.now();
866
+ }
867
+ else {
868
+ return new Date().valueOf();
869
+ }
870
+ },
871
+ defer: function (callback) {
872
+ return new timers_1.OneOffTimer(0, callback);
873
+ },
874
+ method: function (name) {
875
+ var args = [];
876
+ for (var _i = 1; _i < arguments.length; _i++) {
877
+ args[_i - 1] = arguments[_i];
878
+ }
879
+ var boundArguments = Array.prototype.slice.call(arguments, 1);
880
+ return function (object) {
881
+ return object[name].apply(object, boundArguments.concat(arguments));
882
+ };
883
+ }
884
+ };
885
+ exports.__esModule = true;
886
+ exports["default"] = Util;
887
+
888
+
889
+ /***/ },
890
+ /* 12 */
891
+ /***/ function(module, exports, __webpack_require__) {
892
+
893
+ "use strict";
894
+ var __extends = (this && this.__extends) || function (d, b) {
895
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
896
+ function __() { this.constructor = d; }
897
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
898
+ };
899
+ var abstract_timer_1 = __webpack_require__(13);
900
+ var global = Function("return this")();
901
+ function clearTimeout(timer) {
902
+ global.clearTimeout(timer);
903
+ }
904
+ function clearInterval(timer) {
905
+ global.clearInterval(timer);
906
+ }
907
+ var OneOffTimer = (function (_super) {
908
+ __extends(OneOffTimer, _super);
909
+ function OneOffTimer(delay, callback) {
910
+ _super.call(this, setTimeout, clearTimeout, delay, function (timer) {
911
+ callback();
912
+ return null;
913
+ });
914
+ }
915
+ return OneOffTimer;
916
+ }(abstract_timer_1["default"]));
917
+ exports.OneOffTimer = OneOffTimer;
918
+ var PeriodicTimer = (function (_super) {
919
+ __extends(PeriodicTimer, _super);
920
+ function PeriodicTimer(delay, callback) {
921
+ _super.call(this, setInterval, clearInterval, delay, function (timer) {
922
+ callback();
923
+ return timer;
924
+ });
925
+ }
926
+ return PeriodicTimer;
927
+ }(abstract_timer_1["default"]));
928
+ exports.PeriodicTimer = PeriodicTimer;
929
+
930
+
931
+ /***/ },
932
+ /* 13 */
933
+ /***/ function(module, exports) {
934
+
935
+ "use strict";
936
+ var Timer = (function () {
937
+ function Timer(set, clear, delay, callback) {
938
+ var _this = this;
939
+ this.clear = clear;
940
+ this.timer = set(function () {
941
+ if (_this.timer) {
942
+ _this.timer = callback(_this.timer);
943
+ }
944
+ }, delay);
945
+ }
946
+ Timer.prototype.isRunning = function () {
947
+ return this.timer !== null;
948
+ };
949
+ Timer.prototype.ensureAborted = function () {
950
+ if (this.timer) {
951
+ this.clear(this.timer);
952
+ this.timer = null;
953
+ }
954
+ };
955
+ return Timer;
956
+ }());
957
+ exports.__esModule = true;
958
+ exports["default"] = Timer;
959
+
960
+
961
+ /***/ },
962
+ /* 14 */
963
+ /***/ function(module, exports, __webpack_require__) {
964
+
965
+ "use strict";
966
+ var logger_1 = __webpack_require__(8);
967
+ var jsonp = function (context, socketId, callback) {
968
+ if (this.authOptions.headers !== undefined) {
969
+ logger_1["default"].warn("Warn", "To send headers with the auth request, you must use AJAX, rather than JSONP.");
970
+ }
971
+ var callbackName = context.nextAuthCallbackID.toString();
972
+ context.nextAuthCallbackID++;
973
+ var document = context.getDocument();
974
+ var script = document.createElement("script");
975
+ context.auth_callbacks[callbackName] = function (data) {
976
+ callback(false, data);
977
+ };
978
+ var callback_name = "Pusher.auth_callbacks['" + callbackName + "']";
979
+ script.src = this.options.authEndpoint +
980
+ '?callback=' +
981
+ encodeURIComponent(callback_name) +
982
+ '&' +
983
+ this.composeQuery(socketId);
984
+ var head = document.getElementsByTagName("head")[0] || document.documentElement;
985
+ head.insertBefore(script, head.firstChild);
986
+ };
987
+ exports.__esModule = true;
988
+ exports["default"] = jsonp;
989
+
990
+
991
+ /***/ },
992
+ /* 15 */
993
+ /***/ function(module, exports) {
994
+
995
+ "use strict";
996
+ var ScriptRequest = (function () {
997
+ function ScriptRequest(src) {
998
+ this.src = src;
999
+ }
1000
+ ScriptRequest.prototype.send = function (receiver) {
1001
+ var self = this;
1002
+ var errorString = "Error loading " + self.src;
1003
+ self.script = document.createElement("script");
1004
+ self.script.id = receiver.id;
1005
+ self.script.src = self.src;
1006
+ self.script.type = "text/javascript";
1007
+ self.script.charset = "UTF-8";
1008
+ if (self.script.addEventListener) {
1009
+ self.script.onerror = function () {
1010
+ receiver.callback(errorString);
1011
+ };
1012
+ self.script.onload = function () {
1013
+ receiver.callback(null);
1014
+ };
1015
+ }
1016
+ else {
1017
+ self.script.onreadystatechange = function () {
1018
+ if (self.script.readyState === 'loaded' ||
1019
+ self.script.readyState === 'complete') {
1020
+ receiver.callback(null);
1021
+ }
1022
+ };
1023
+ }
1024
+ if (self.script.async === undefined && document.attachEvent &&
1025
+ /opera/i.test(navigator.userAgent)) {
1026
+ self.errorScript = document.createElement("script");
1027
+ self.errorScript.id = receiver.id + "_error";
1028
+ self.errorScript.text = receiver.name + "('" + errorString + "');";
1029
+ self.script.async = self.errorScript.async = false;
1030
+ }
1031
+ else {
1032
+ self.script.async = true;
1033
+ }
1034
+ var head = document.getElementsByTagName('head')[0];
1035
+ head.insertBefore(self.script, head.firstChild);
1036
+ if (self.errorScript) {
1037
+ head.insertBefore(self.errorScript, self.script.nextSibling);
1038
+ }
1039
+ };
1040
+ ScriptRequest.prototype.cleanup = function () {
1041
+ if (this.script) {
1042
+ this.script.onload = this.script.onerror = null;
1043
+ this.script.onreadystatechange = null;
1044
+ }
1045
+ if (this.script && this.script.parentNode) {
1046
+ this.script.parentNode.removeChild(this.script);
1047
+ }
1048
+ if (this.errorScript && this.errorScript.parentNode) {
1049
+ this.errorScript.parentNode.removeChild(this.errorScript);
1050
+ }
1051
+ this.script = null;
1052
+ this.errorScript = null;
1053
+ };
1054
+ return ScriptRequest;
1055
+ }());
1056
+ exports.__esModule = true;
1057
+ exports["default"] = ScriptRequest;
1058
+
1059
+
1060
+ /***/ },
1061
+ /* 16 */
1062
+ /***/ function(module, exports, __webpack_require__) {
1063
+
1064
+ "use strict";
1065
+ var Collections = __webpack_require__(9);
1066
+ var runtime_1 = __webpack_require__(2);
1067
+ var JSONPRequest = (function () {
1068
+ function JSONPRequest(url, data) {
1069
+ this.url = url;
1070
+ this.data = data;
1071
+ }
1072
+ JSONPRequest.prototype.send = function (receiver) {
1073
+ if (this.request) {
1074
+ return;
1075
+ }
1076
+ var query = Collections.buildQueryString(this.data);
1077
+ var url = this.url + "/" + receiver.number + "?" + query;
1078
+ this.request = runtime_1["default"].createScriptRequest(url);
1079
+ this.request.send(receiver);
1080
+ };
1081
+ JSONPRequest.prototype.cleanup = function () {
1082
+ if (this.request) {
1083
+ this.request.cleanup();
1084
+ }
1085
+ };
1086
+ return JSONPRequest;
1087
+ }());
1088
+ exports.__esModule = true;
1089
+ exports["default"] = JSONPRequest;
1090
+
1091
+
1092
+ /***/ },
1093
+ /* 17 */
1094
+ /***/ function(module, exports, __webpack_require__) {
1095
+
1096
+ "use strict";
1097
+ var runtime_1 = __webpack_require__(2);
1098
+ var script_receiver_factory_1 = __webpack_require__(4);
1099
+ var getAgent = function (sender, encrypted) {
1100
+ return function (data, callback) {
1101
+ var scheme = "http" + (encrypted ? "s" : "") + "://";
1102
+ var url = scheme + (sender.host || sender.options.host) + sender.options.path;
1103
+ var request = runtime_1["default"].createJSONPRequest(url, data);
1104
+ var receiver = runtime_1["default"].ScriptReceivers.create(function (error, result) {
1105
+ script_receiver_factory_1.ScriptReceivers.remove(receiver);
1106
+ request.cleanup();
1107
+ if (result && result.host) {
1108
+ sender.host = result.host;
1109
+ }
1110
+ if (callback) {
1111
+ callback(error, result);
1112
+ }
1113
+ });
1114
+ request.send(receiver);
1115
+ };
1116
+ };
1117
+ var jsonp = {
1118
+ name: 'jsonp',
1119
+ getAgent: getAgent
1120
+ };
1121
+ exports.__esModule = true;
1122
+ exports["default"] = jsonp;
1123
+
1124
+
1125
+ /***/ },
1126
+ /* 18 */
1127
+ /***/ function(module, exports, __webpack_require__) {
1128
+
1129
+ "use strict";
1130
+ var transports_1 = __webpack_require__(19);
1131
+ var transport_1 = __webpack_require__(21);
1132
+ var URLSchemes = __webpack_require__(20);
1133
+ var runtime_1 = __webpack_require__(2);
1134
+ var dependencies_1 = __webpack_require__(3);
1135
+ var Collections = __webpack_require__(9);
1136
+ var SockJSTransport = new transport_1["default"]({
1137
+ file: "sockjs",
1138
+ urls: URLSchemes.sockjs,
1139
+ handlesActivityChecks: true,
1140
+ supportsPing: false,
1141
+ isSupported: function () {
1142
+ return true;
1143
+ },
1144
+ isInitialized: function () {
1145
+ return window.SockJS !== undefined;
1146
+ },
1147
+ getSocket: function (url, options) {
1148
+ return new window.SockJS(url, null, {
1149
+ js_path: dependencies_1.Dependencies.getPath("sockjs", {
1150
+ encrypted: options.encrypted
1151
+ }),
1152
+ ignore_null_origin: options.ignoreNullOrigin
1153
+ });
1154
+ },
1155
+ beforeOpen: function (socket, path) {
1156
+ socket.send(JSON.stringify({
1157
+ path: path
1158
+ }));
1159
+ }
1160
+ });
1161
+ var xdrConfiguration = {
1162
+ isSupported: function (environment) {
1163
+ var yes = runtime_1["default"].isXDRSupported(environment.encrypted);
1164
+ return yes;
1165
+ }
1166
+ };
1167
+ var XDRStreamingTransport = new transport_1["default"](Collections.extend({}, transports_1.streamingConfiguration, xdrConfiguration));
1168
+ var XDRPollingTransport = new transport_1["default"](Collections.extend({}, transports_1.pollingConfiguration, xdrConfiguration));
1169
+ transports_1["default"].xdr_streaming = XDRStreamingTransport;
1170
+ transports_1["default"].xdr_polling = XDRPollingTransport;
1171
+ transports_1["default"].sockjs = SockJSTransport;
1172
+ exports.__esModule = true;
1173
+ exports["default"] = transports_1["default"];
1174
+
1175
+
1176
+ /***/ },
1177
+ /* 19 */
1178
+ /***/ function(module, exports, __webpack_require__) {
1179
+
1180
+ "use strict";
1181
+ var URLSchemes = __webpack_require__(20);
1182
+ var transport_1 = __webpack_require__(21);
1183
+ var Collections = __webpack_require__(9);
1184
+ var runtime_1 = __webpack_require__(2);
1185
+ var WSTransport = new transport_1["default"]({
1186
+ urls: URLSchemes.ws,
1187
+ handlesActivityChecks: false,
1188
+ supportsPing: false,
1189
+ isInitialized: function () {
1190
+ return Boolean(runtime_1["default"].getWebSocketAPI());
1191
+ },
1192
+ isSupported: function () {
1193
+ return Boolean(runtime_1["default"].getWebSocketAPI());
1194
+ },
1195
+ getSocket: function (url) {
1196
+ return runtime_1["default"].createWebSocket(url);
1197
+ }
1198
+ });
1199
+ var httpConfiguration = {
1200
+ urls: URLSchemes.http,
1201
+ handlesActivityChecks: false,
1202
+ supportsPing: true,
1203
+ isInitialized: function () {
1204
+ return true;
1205
+ }
1206
+ };
1207
+ exports.streamingConfiguration = Collections.extend({ getSocket: function (url) {
1208
+ return runtime_1["default"].HTTPFactory.createStreamingSocket(url);
1209
+ }
1210
+ }, httpConfiguration);
1211
+ exports.pollingConfiguration = Collections.extend({ getSocket: function (url) {
1212
+ return runtime_1["default"].HTTPFactory.createPollingSocket(url);
1213
+ }
1214
+ }, httpConfiguration);
1215
+ var xhrConfiguration = {
1216
+ isSupported: function () {
1217
+ return runtime_1["default"].isXHRSupported();
1218
+ }
1219
+ };
1220
+ var XHRStreamingTransport = new transport_1["default"](Collections.extend({}, exports.streamingConfiguration, xhrConfiguration));
1221
+ var XHRPollingTransport = new transport_1["default"](Collections.extend({}, exports.pollingConfiguration, xhrConfiguration));
1222
+ var Transports = {
1223
+ ws: WSTransport,
1224
+ xhr_streaming: XHRStreamingTransport,
1225
+ xhr_polling: XHRPollingTransport
1226
+ };
1227
+ exports.__esModule = true;
1228
+ exports["default"] = Transports;
1229
+
1230
+
1231
+ /***/ },
1232
+ /* 20 */
1233
+ /***/ function(module, exports, __webpack_require__) {
1234
+
1235
+ "use strict";
1236
+ var defaults_1 = __webpack_require__(5);
1237
+ function getGenericURL(baseScheme, params, path) {
1238
+ var scheme = baseScheme + (params.encrypted ? "s" : "");
1239
+ var host = params.encrypted ? params.hostEncrypted : params.hostUnencrypted;
1240
+ return scheme + "://" + host + path;
1241
+ }
1242
+ function getGenericPath(key, queryString) {
1243
+ var path = "/app/" + key;
1244
+ var query = "?protocol=" + defaults_1["default"].PROTOCOL +
1245
+ "&client=js" +
1246
+ "&version=" + defaults_1["default"].VERSION +
1247
+ (queryString ? ("&" + queryString) : "");
1248
+ return path + query;
1249
+ }
1250
+ exports.ws = {
1251
+ getInitial: function (key, params) {
1252
+ return getGenericURL("ws", params, getGenericPath(key, "flash=false"));
1253
+ }
1254
+ };
1255
+ exports.http = {
1256
+ getInitial: function (key, params) {
1257
+ var path = (params.httpPath || "/pusher") + getGenericPath(key);
1258
+ return getGenericURL("http", params, path);
1259
+ }
1260
+ };
1261
+ exports.sockjs = {
1262
+ getInitial: function (key, params) {
1263
+ return getGenericURL("http", params, params.httpPath || "/pusher");
1264
+ },
1265
+ getPath: function (key, params) {
1266
+ return getGenericPath(key);
1267
+ }
1268
+ };
1269
+
1270
+
1271
+ /***/ },
1272
+ /* 21 */
1273
+ /***/ function(module, exports, __webpack_require__) {
1274
+
1275
+ "use strict";
1276
+ var transport_connection_1 = __webpack_require__(22);
1277
+ var Transport = (function () {
1278
+ function Transport(hooks) {
1279
+ this.hooks = hooks;
1280
+ }
1281
+ Transport.prototype.isSupported = function (environment) {
1282
+ return this.hooks.isSupported(environment);
1283
+ };
1284
+ Transport.prototype.createConnection = function (name, priority, key, options) {
1285
+ return new transport_connection_1["default"](this.hooks, name, priority, key, options);
1286
+ };
1287
+ return Transport;
1288
+ }());
1289
+ exports.__esModule = true;
1290
+ exports["default"] = Transport;
1291
+
1292
+
1293
+ /***/ },
1294
+ /* 22 */
1295
+ /***/ function(module, exports, __webpack_require__) {
1296
+
1297
+ "use strict";
1298
+ var __extends = (this && this.__extends) || function (d, b) {
1299
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
1300
+ function __() { this.constructor = d; }
1301
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1302
+ };
1303
+ var util_1 = __webpack_require__(11);
1304
+ var Collections = __webpack_require__(9);
1305
+ var dispatcher_1 = __webpack_require__(23);
1306
+ var logger_1 = __webpack_require__(8);
1307
+ var runtime_1 = __webpack_require__(2);
1308
+ var TransportConnection = (function (_super) {
1309
+ __extends(TransportConnection, _super);
1310
+ function TransportConnection(hooks, name, priority, key, options) {
1311
+ _super.call(this);
1312
+ this.initialize = runtime_1["default"].transportConnectionInitializer;
1313
+ this.hooks = hooks;
1314
+ this.name = name;
1315
+ this.priority = priority;
1316
+ this.key = key;
1317
+ this.options = options;
1318
+ this.state = "new";
1319
+ this.timeline = options.timeline;
1320
+ this.activityTimeout = options.activityTimeout;
1321
+ this.id = this.timeline.generateUniqueID();
1322
+ }
1323
+ TransportConnection.prototype.handlesActivityChecks = function () {
1324
+ return Boolean(this.hooks.handlesActivityChecks);
1325
+ };
1326
+ TransportConnection.prototype.supportsPing = function () {
1327
+ return Boolean(this.hooks.supportsPing);
1328
+ };
1329
+ TransportConnection.prototype.connect = function () {
1330
+ var _this = this;
1331
+ if (this.socket || this.state !== "initialized") {
1332
+ return false;
1333
+ }
1334
+ var url = this.hooks.urls.getInitial(this.key, this.options);
1335
+ try {
1336
+ this.socket = this.hooks.getSocket(url, this.options);
1337
+ }
1338
+ catch (e) {
1339
+ util_1["default"].defer(function () {
1340
+ _this.onError(e);
1341
+ _this.changeState("closed");
1342
+ });
1343
+ return false;
1344
+ }
1345
+ this.bindListeners();
1346
+ logger_1["default"].debug("Connecting", { transport: this.name, url: url });
1347
+ this.changeState("connecting");
1348
+ return true;
1349
+ };
1350
+ TransportConnection.prototype.close = function () {
1351
+ if (this.socket) {
1352
+ this.socket.close();
1353
+ return true;
1354
+ }
1355
+ else {
1356
+ return false;
1357
+ }
1358
+ };
1359
+ TransportConnection.prototype.send = function (data) {
1360
+ var _this = this;
1361
+ if (this.state === "open") {
1362
+ util_1["default"].defer(function () {
1363
+ if (_this.socket) {
1364
+ _this.socket.send(data);
1365
+ }
1366
+ });
1367
+ return true;
1368
+ }
1369
+ else {
1370
+ return false;
1371
+ }
1372
+ };
1373
+ TransportConnection.prototype.ping = function () {
1374
+ if (this.state === "open" && this.supportsPing()) {
1375
+ this.socket.ping();
1376
+ }
1377
+ };
1378
+ TransportConnection.prototype.onOpen = function () {
1379
+ if (this.hooks.beforeOpen) {
1380
+ this.hooks.beforeOpen(this.socket, this.hooks.urls.getPath(this.key, this.options));
1381
+ }
1382
+ this.changeState("open");
1383
+ this.socket.onopen = undefined;
1384
+ };
1385
+ TransportConnection.prototype.onError = function (error) {
1386
+ this.emit("error", { type: 'WebSocketError', error: error });
1387
+ this.timeline.error(this.buildTimelineMessage({ error: error.toString() }));
1388
+ };
1389
+ TransportConnection.prototype.onClose = function (closeEvent) {
1390
+ if (closeEvent) {
1391
+ this.changeState("closed", {
1392
+ code: closeEvent.code,
1393
+ reason: closeEvent.reason,
1394
+ wasClean: closeEvent.wasClean
1395
+ });
1396
+ }
1397
+ else {
1398
+ this.changeState("closed");
1399
+ }
1400
+ this.unbindListeners();
1401
+ this.socket = undefined;
1402
+ };
1403
+ TransportConnection.prototype.onMessage = function (message) {
1404
+ this.emit("message", message);
1405
+ };
1406
+ TransportConnection.prototype.onActivity = function () {
1407
+ this.emit("activity");
1408
+ };
1409
+ TransportConnection.prototype.bindListeners = function () {
1410
+ var _this = this;
1411
+ this.socket.onopen = function () {
1412
+ _this.onOpen();
1413
+ };
1414
+ this.socket.onerror = function (error) {
1415
+ _this.onError(error);
1416
+ };
1417
+ this.socket.onclose = function (closeEvent) {
1418
+ _this.onClose(closeEvent);
1419
+ };
1420
+ this.socket.onmessage = function (message) {
1421
+ _this.onMessage(message);
1422
+ };
1423
+ if (this.supportsPing()) {
1424
+ this.socket.onactivity = function () { _this.onActivity(); };
1425
+ }
1426
+ };
1427
+ TransportConnection.prototype.unbindListeners = function () {
1428
+ if (this.socket) {
1429
+ this.socket.onopen = undefined;
1430
+ this.socket.onerror = undefined;
1431
+ this.socket.onclose = undefined;
1432
+ this.socket.onmessage = undefined;
1433
+ if (this.supportsPing()) {
1434
+ this.socket.onactivity = undefined;
1435
+ }
1436
+ }
1437
+ };
1438
+ TransportConnection.prototype.changeState = function (state, params) {
1439
+ this.state = state;
1440
+ this.timeline.info(this.buildTimelineMessage({
1441
+ state: state,
1442
+ params: params
1443
+ }));
1444
+ this.emit(state, params);
1445
+ };
1446
+ TransportConnection.prototype.buildTimelineMessage = function (message) {
1447
+ return Collections.extend({ cid: this.id }, message);
1448
+ };
1449
+ return TransportConnection;
1450
+ }(dispatcher_1["default"]));
1451
+ exports.__esModule = true;
1452
+ exports["default"] = TransportConnection;
1453
+
1454
+
1455
+ /***/ },
1456
+ /* 23 */
1457
+ /***/ function(module, exports, __webpack_require__) {
1458
+
1459
+ "use strict";
1460
+ var callback_registry_1 = __webpack_require__(24);
1461
+ var global = Function("return this")();
1462
+ var Dispatcher = (function () {
1463
+ function Dispatcher(failThrough) {
1464
+ this.callbacks = new callback_registry_1["default"]();
1465
+ this.global_callbacks = [];
1466
+ this.failThrough = failThrough;
1467
+ }
1468
+ Dispatcher.prototype.bind = function (eventName, callback, context) {
1469
+ this.callbacks.add(eventName, callback, context);
1470
+ return this;
1471
+ };
1472
+ Dispatcher.prototype.bind_all = function (callback) {
1473
+ this.global_callbacks.push(callback);
1474
+ return this;
1475
+ };
1476
+ Dispatcher.prototype.unbind = function (eventName, callback, context) {
1477
+ this.callbacks.remove(eventName, callback, context);
1478
+ return this;
1479
+ };
1480
+ Dispatcher.prototype.unbind_all = function (eventName, callback) {
1481
+ this.callbacks.remove(eventName, callback);
1482
+ return this;
1483
+ };
1484
+ Dispatcher.prototype.emit = function (eventName, data) {
1485
+ var i;
1486
+ for (i = 0; i < this.global_callbacks.length; i++) {
1487
+ this.global_callbacks[i](eventName, data);
1488
+ }
1489
+ var callbacks = this.callbacks.get(eventName);
1490
+ if (callbacks && callbacks.length > 0) {
1491
+ for (i = 0; i < callbacks.length; i++) {
1492
+ callbacks[i].fn.call(callbacks[i].context || global, data);
1493
+ }
1494
+ }
1495
+ else if (this.failThrough) {
1496
+ this.failThrough(eventName, data);
1497
+ }
1498
+ return this;
1499
+ };
1500
+ return Dispatcher;
1501
+ }());
1502
+ exports.__esModule = true;
1503
+ exports["default"] = Dispatcher;
1504
+
1505
+
1506
+ /***/ },
1507
+ /* 24 */
1508
+ /***/ function(module, exports, __webpack_require__) {
1509
+
1510
+ "use strict";
1511
+ var Collections = __webpack_require__(9);
1512
+ var CallbackRegistry = (function () {
1513
+ function CallbackRegistry() {
1514
+ this._callbacks = {};
1515
+ }
1516
+ CallbackRegistry.prototype.get = function (name) {
1517
+ return this._callbacks[prefix(name)];
1518
+ };
1519
+ CallbackRegistry.prototype.add = function (name, callback, context) {
1520
+ var prefixedEventName = prefix(name);
1521
+ this._callbacks[prefixedEventName] = this._callbacks[prefixedEventName] || [];
1522
+ this._callbacks[prefixedEventName].push({
1523
+ fn: callback,
1524
+ context: context
1525
+ });
1526
+ };
1527
+ CallbackRegistry.prototype.remove = function (name, callback, context) {
1528
+ if (!name && !callback && !context) {
1529
+ this._callbacks = {};
1530
+ return;
1531
+ }
1532
+ var names = name ? [prefix(name)] : Collections.keys(this._callbacks);
1533
+ if (callback || context) {
1534
+ this.removeCallback(names, callback, context);
1535
+ }
1536
+ else {
1537
+ this.removeAllCallbacks(names);
1538
+ }
1539
+ };
1540
+ CallbackRegistry.prototype.removeCallback = function (names, callback, context) {
1541
+ Collections.apply(names, function (name) {
1542
+ this._callbacks[name] = Collections.filter(this._callbacks[name] || [], function (binding) {
1543
+ return (callback && callback !== binding.fn) ||
1544
+ (context && context !== binding.context);
1545
+ });
1546
+ if (this._callbacks[name].length === 0) {
1547
+ delete this._callbacks[name];
1548
+ }
1549
+ }, this);
1550
+ };
1551
+ CallbackRegistry.prototype.removeAllCallbacks = function (names) {
1552
+ Collections.apply(names, function (name) {
1553
+ delete this._callbacks[name];
1554
+ }, this);
1555
+ };
1556
+ return CallbackRegistry;
1557
+ }());
1558
+ exports.__esModule = true;
1559
+ exports["default"] = CallbackRegistry;
1560
+ function prefix(name) {
1561
+ return "_" + name;
1562
+ }
1563
+
1564
+
1565
+ /***/ },
1566
+ /* 25 */
1567
+ /***/ function(module, exports, __webpack_require__) {
1568
+
1569
+ "use strict";
1570
+ var __extends = (this && this.__extends) || function (d, b) {
1571
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
1572
+ function __() { this.constructor = d; }
1573
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1574
+ };
1575
+ var dispatcher_1 = __webpack_require__(23);
1576
+ var NetInfo = (function (_super) {
1577
+ __extends(NetInfo, _super);
1578
+ function NetInfo() {
1579
+ _super.call(this);
1580
+ var self = this;
1581
+ if (window.addEventListener !== undefined) {
1582
+ window.addEventListener("online", function () {
1583
+ self.emit('online');
1584
+ }, false);
1585
+ window.addEventListener("offline", function () {
1586
+ self.emit('offline');
1587
+ }, false);
1588
+ }
1589
+ }
1590
+ NetInfo.prototype.isOnline = function () {
1591
+ if (window.navigator.onLine === undefined) {
1592
+ return true;
1593
+ }
1594
+ else {
1595
+ return window.navigator.onLine;
1596
+ }
1597
+ };
1598
+ return NetInfo;
1599
+ }(dispatcher_1["default"]));
1600
+ exports.NetInfo = NetInfo;
1601
+ exports.Network = new NetInfo();
1602
+
1603
+
1604
+ /***/ },
1605
+ /* 26 */
1606
+ /***/ function(module, exports) {
1607
+
1608
+ "use strict";
1609
+ var getDefaultStrategy = function (config) {
1610
+ var wsStrategy;
1611
+ if (config.encrypted) {
1612
+ wsStrategy = [
1613
+ ":best_connected_ever",
1614
+ ":ws_loop",
1615
+ [":delayed", 2000, [":http_fallback_loop"]]
1616
+ ];
1617
+ }
1618
+ else {
1619
+ wsStrategy = [
1620
+ ":best_connected_ever",
1621
+ ":ws_loop",
1622
+ [":delayed", 2000, [":wss_loop"]],
1623
+ [":delayed", 5000, [":http_fallback_loop"]]
1624
+ ];
1625
+ }
1626
+ return [
1627
+ [":def", "ws_options", {
1628
+ hostUnencrypted: config.wsHost + ":" + config.wsPort,
1629
+ hostEncrypted: config.wsHost + ":" + config.wssPort
1630
+ }],
1631
+ [":def", "wss_options", [":extend", ":ws_options", {
1632
+ encrypted: true
1633
+ }]],
1634
+ [":def", "sockjs_options", {
1635
+ hostUnencrypted: config.httpHost + ":" + config.httpPort,
1636
+ hostEncrypted: config.httpHost + ":" + config.httpsPort,
1637
+ httpPath: config.httpPath
1638
+ }],
1639
+ [":def", "timeouts", {
1640
+ loop: true,
1641
+ timeout: 15000,
1642
+ timeoutLimit: 60000
1643
+ }],
1644
+ [":def", "ws_manager", [":transport_manager", {
1645
+ lives: 2,
1646
+ minPingDelay: 10000,
1647
+ maxPingDelay: config.activity_timeout
1648
+ }]],
1649
+ [":def", "streaming_manager", [":transport_manager", {
1650
+ lives: 2,
1651
+ minPingDelay: 10000,
1652
+ maxPingDelay: config.activity_timeout
1653
+ }]],
1654
+ [":def_transport", "ws", "ws", 3, ":ws_options", ":ws_manager"],
1655
+ [":def_transport", "wss", "ws", 3, ":wss_options", ":ws_manager"],
1656
+ [":def_transport", "sockjs", "sockjs", 1, ":sockjs_options"],
1657
+ [":def_transport", "xhr_streaming", "xhr_streaming", 1, ":sockjs_options", ":streaming_manager"],
1658
+ [":def_transport", "xdr_streaming", "xdr_streaming", 1, ":sockjs_options", ":streaming_manager"],
1659
+ [":def_transport", "xhr_polling", "xhr_polling", 1, ":sockjs_options"],
1660
+ [":def_transport", "xdr_polling", "xdr_polling", 1, ":sockjs_options"],
1661
+ [":def", "ws_loop", [":sequential", ":timeouts", ":ws"]],
1662
+ [":def", "wss_loop", [":sequential", ":timeouts", ":wss"]],
1663
+ [":def", "sockjs_loop", [":sequential", ":timeouts", ":sockjs"]],
1664
+ [":def", "streaming_loop", [":sequential", ":timeouts",
1665
+ [":if", [":is_supported", ":xhr_streaming"],
1666
+ ":xhr_streaming",
1667
+ ":xdr_streaming"
1668
+ ]
1669
+ ]],
1670
+ [":def", "polling_loop", [":sequential", ":timeouts",
1671
+ [":if", [":is_supported", ":xhr_polling"],
1672
+ ":xhr_polling",
1673
+ ":xdr_polling"
1674
+ ]
1675
+ ]],
1676
+ [":def", "http_loop", [":if", [":is_supported", ":streaming_loop"], [
1677
+ ":best_connected_ever",
1678
+ ":streaming_loop",
1679
+ [":delayed", 4000, [":polling_loop"]]
1680
+ ], [
1681
+ ":polling_loop"
1682
+ ]]],
1683
+ [":def", "http_fallback_loop",
1684
+ [":if", [":is_supported", ":http_loop"], [
1685
+ ":http_loop"
1686
+ ], [
1687
+ ":sockjs_loop"
1688
+ ]]
1689
+ ],
1690
+ [":def", "strategy",
1691
+ [":cached", 1800000,
1692
+ [":first_connected",
1693
+ [":if", [":is_supported", ":ws"],
1694
+ wsStrategy,
1695
+ ":http_fallback_loop"
1696
+ ]
1697
+ ]
1698
+ ]
1699
+ ]
1700
+ ];
1701
+ };
1702
+ exports.__esModule = true;
1703
+ exports["default"] = getDefaultStrategy;
1704
+
1705
+
1706
+ /***/ },
1707
+ /* 27 */
1708
+ /***/ function(module, exports, __webpack_require__) {
1709
+
1710
+ "use strict";
1711
+ var dependencies_1 = __webpack_require__(3);
1712
+ function default_1() {
1713
+ var self = this;
1714
+ self.timeline.info(self.buildTimelineMessage({
1715
+ transport: self.name + (self.options.encrypted ? "s" : "")
1716
+ }));
1717
+ if (self.hooks.isInitialized()) {
1718
+ self.changeState("initialized");
1719
+ }
1720
+ else if (self.hooks.file) {
1721
+ self.changeState("initializing");
1722
+ dependencies_1.Dependencies.load(self.hooks.file, { encrypted: self.options.encrypted }, function (error, callback) {
1723
+ if (self.hooks.isInitialized()) {
1724
+ self.changeState("initialized");
1725
+ callback(true);
1726
+ }
1727
+ else {
1728
+ if (error) {
1729
+ self.onError(error);
1730
+ }
1731
+ self.onClose();
1732
+ callback(false);
1733
+ }
1734
+ });
1735
+ }
1736
+ else {
1737
+ self.onClose();
1738
+ }
1739
+ }
1740
+ exports.__esModule = true;
1741
+ exports["default"] = default_1;
1742
+
1743
+
1744
+ /***/ },
1745
+ /* 28 */
1746
+ /***/ function(module, exports, __webpack_require__) {
1747
+
1748
+ "use strict";
1749
+ var http_xdomain_request_1 = __webpack_require__(29);
1750
+ var http_1 = __webpack_require__(31);
1751
+ http_1["default"].createXDR = function (method, url) {
1752
+ return this.createRequest(http_xdomain_request_1["default"], method, url);
1753
+ };
1754
+ exports.__esModule = true;
1755
+ exports["default"] = http_1["default"];
1756
+
1757
+
1758
+ /***/ },
1759
+ /* 29 */
1760
+ /***/ function(module, exports, __webpack_require__) {
1761
+
1762
+ "use strict";
1763
+ var Errors = __webpack_require__(30);
1764
+ var hooks = {
1765
+ getRequest: function (socket) {
1766
+ var xdr = new window.XDomainRequest();
1767
+ xdr.ontimeout = function () {
1768
+ socket.emit("error", new Errors.RequestTimedOut());
1769
+ socket.close();
1770
+ };
1771
+ xdr.onerror = function (e) {
1772
+ socket.emit("error", e);
1773
+ socket.close();
1774
+ };
1775
+ xdr.onprogress = function () {
1776
+ if (xdr.responseText && xdr.responseText.length > 0) {
1777
+ socket.onChunk(200, xdr.responseText);
1778
+ }
1779
+ };
1780
+ xdr.onload = function () {
1781
+ if (xdr.responseText && xdr.responseText.length > 0) {
1782
+ socket.onChunk(200, xdr.responseText);
1783
+ }
1784
+ socket.emit("finished", 200);
1785
+ socket.close();
1786
+ };
1787
+ return xdr;
1788
+ },
1789
+ abortRequest: function (xdr) {
1790
+ xdr.ontimeout = xdr.onerror = xdr.onprogress = xdr.onload = null;
1791
+ xdr.abort();
1792
+ }
1793
+ };
1794
+ exports.__esModule = true;
1795
+ exports["default"] = hooks;
1796
+
1797
+
1798
+ /***/ },
1799
+ /* 30 */
1800
+ /***/ function(module, exports) {
1801
+
1802
+ "use strict";
1803
+ var __extends = (this && this.__extends) || function (d, b) {
1804
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
1805
+ function __() { this.constructor = d; }
1806
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1807
+ };
1808
+ var BadEventName = (function (_super) {
1809
+ __extends(BadEventName, _super);
1810
+ function BadEventName() {
1811
+ _super.apply(this, arguments);
1812
+ }
1813
+ return BadEventName;
1814
+ }(Error));
1815
+ exports.BadEventName = BadEventName;
1816
+ var RequestTimedOut = (function (_super) {
1817
+ __extends(RequestTimedOut, _super);
1818
+ function RequestTimedOut() {
1819
+ _super.apply(this, arguments);
1820
+ }
1821
+ return RequestTimedOut;
1822
+ }(Error));
1823
+ exports.RequestTimedOut = RequestTimedOut;
1824
+ var TransportPriorityTooLow = (function (_super) {
1825
+ __extends(TransportPriorityTooLow, _super);
1826
+ function TransportPriorityTooLow() {
1827
+ _super.apply(this, arguments);
1828
+ }
1829
+ return TransportPriorityTooLow;
1830
+ }(Error));
1831
+ exports.TransportPriorityTooLow = TransportPriorityTooLow;
1832
+ var TransportClosed = (function (_super) {
1833
+ __extends(TransportClosed, _super);
1834
+ function TransportClosed() {
1835
+ _super.apply(this, arguments);
1836
+ }
1837
+ return TransportClosed;
1838
+ }(Error));
1839
+ exports.TransportClosed = TransportClosed;
1840
+ var UnsupportedTransport = (function (_super) {
1841
+ __extends(UnsupportedTransport, _super);
1842
+ function UnsupportedTransport() {
1843
+ _super.apply(this, arguments);
1844
+ }
1845
+ return UnsupportedTransport;
1846
+ }(Error));
1847
+ exports.UnsupportedTransport = UnsupportedTransport;
1848
+ var UnsupportedStrategy = (function (_super) {
1849
+ __extends(UnsupportedStrategy, _super);
1850
+ function UnsupportedStrategy() {
1851
+ _super.apply(this, arguments);
1852
+ }
1853
+ return UnsupportedStrategy;
1854
+ }(Error));
1855
+ exports.UnsupportedStrategy = UnsupportedStrategy;
1856
+
1857
+
1858
+ /***/ },
1859
+ /* 31 */
1860
+ /***/ function(module, exports, __webpack_require__) {
1861
+
1862
+ "use strict";
1863
+ var http_request_1 = __webpack_require__(32);
1864
+ var http_socket_1 = __webpack_require__(33);
1865
+ var http_streaming_socket_1 = __webpack_require__(35);
1866
+ var http_polling_socket_1 = __webpack_require__(36);
1867
+ var http_xhr_request_1 = __webpack_require__(37);
1868
+ var HTTP = {
1869
+ createStreamingSocket: function (url) {
1870
+ return this.createSocket(http_streaming_socket_1["default"], url);
1871
+ },
1872
+ createPollingSocket: function (url) {
1873
+ return this.createSocket(http_polling_socket_1["default"], url);
1874
+ },
1875
+ createSocket: function (hooks, url) {
1876
+ return new http_socket_1["default"](hooks, url);
1877
+ },
1878
+ createXHR: function (method, url) {
1879
+ return this.createRequest(http_xhr_request_1["default"], method, url);
1880
+ },
1881
+ createRequest: function (hooks, method, url) {
1882
+ return new http_request_1["default"](hooks, method, url);
1883
+ }
1884
+ };
1885
+ exports.__esModule = true;
1886
+ exports["default"] = HTTP;
1887
+
1888
+
1889
+ /***/ },
1890
+ /* 32 */
1891
+ /***/ function(module, exports, __webpack_require__) {
1892
+
1893
+ "use strict";
1894
+ var __extends = (this && this.__extends) || function (d, b) {
1895
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
1896
+ function __() { this.constructor = d; }
1897
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1898
+ };
1899
+ var runtime_1 = __webpack_require__(2);
1900
+ var dispatcher_1 = __webpack_require__(23);
1901
+ var MAX_BUFFER_LENGTH = 256 * 1024;
1902
+ var HTTPRequest = (function (_super) {
1903
+ __extends(HTTPRequest, _super);
1904
+ function HTTPRequest(hooks, method, url) {
1905
+ _super.call(this);
1906
+ this.hooks = hooks;
1907
+ this.method = method;
1908
+ this.url = url;
1909
+ }
1910
+ HTTPRequest.prototype.start = function (payload) {
1911
+ var _this = this;
1912
+ this.position = 0;
1913
+ this.xhr = this.hooks.getRequest(this);
1914
+ this.unloader = function () {
1915
+ _this.close();
1916
+ };
1917
+ runtime_1["default"].addUnloadListener(this.unloader);
1918
+ this.xhr.open(this.method, this.url, true);
1919
+ if (this.xhr.setRequestHeader) {
1920
+ this.xhr.setRequestHeader("Content-Type", "application/json");
1921
+ }
1922
+ this.xhr.send(payload);
1923
+ };
1924
+ HTTPRequest.prototype.close = function () {
1925
+ if (this.unloader) {
1926
+ runtime_1["default"].removeUnloadListener(this.unloader);
1927
+ this.unloader = null;
1928
+ }
1929
+ if (this.xhr) {
1930
+ this.hooks.abortRequest(this.xhr);
1931
+ this.xhr = null;
1932
+ }
1933
+ };
1934
+ HTTPRequest.prototype.onChunk = function (status, data) {
1935
+ while (true) {
1936
+ var chunk = this.advanceBuffer(data);
1937
+ if (chunk) {
1938
+ this.emit("chunk", { status: status, data: chunk });
1939
+ }
1940
+ else {
1941
+ break;
1942
+ }
1943
+ }
1944
+ if (this.isBufferTooLong(data)) {
1945
+ this.emit("buffer_too_long");
1946
+ }
1947
+ };
1948
+ HTTPRequest.prototype.advanceBuffer = function (buffer) {
1949
+ var unreadData = buffer.slice(this.position);
1950
+ var endOfLinePosition = unreadData.indexOf("\n");
1951
+ if (endOfLinePosition !== -1) {
1952
+ this.position += endOfLinePosition + 1;
1953
+ return unreadData.slice(0, endOfLinePosition);
1954
+ }
1955
+ else {
1956
+ return null;
1957
+ }
1958
+ };
1959
+ HTTPRequest.prototype.isBufferTooLong = function (buffer) {
1960
+ return this.position === buffer.length && buffer.length > MAX_BUFFER_LENGTH;
1961
+ };
1962
+ return HTTPRequest;
1963
+ }(dispatcher_1["default"]));
1964
+ exports.__esModule = true;
1965
+ exports["default"] = HTTPRequest;
1966
+
1967
+
1968
+ /***/ },
1969
+ /* 33 */
1970
+ /***/ function(module, exports, __webpack_require__) {
1971
+
1972
+ "use strict";
1973
+ var state_1 = __webpack_require__(34);
1974
+ var util_1 = __webpack_require__(11);
1975
+ var runtime_1 = __webpack_require__(2);
1976
+ var autoIncrement = 1;
1977
+ var HTTPSocket = (function () {
1978
+ function HTTPSocket(hooks, url) {
1979
+ this.hooks = hooks;
1980
+ this.session = randomNumber(1000) + "/" + randomString(8);
1981
+ this.location = getLocation(url);
1982
+ this.readyState = state_1["default"].CONNECTING;
1983
+ this.openStream();
1984
+ }
1985
+ HTTPSocket.prototype.send = function (payload) {
1986
+ return this.sendRaw(JSON.stringify([payload]));
1987
+ };
1988
+ HTTPSocket.prototype.ping = function () {
1989
+ this.hooks.sendHeartbeat(this);
1990
+ };
1991
+ HTTPSocket.prototype.close = function (code, reason) {
1992
+ this.onClose(code, reason, true);
1993
+ };
1994
+ HTTPSocket.prototype.sendRaw = function (payload) {
1995
+ if (this.readyState === state_1["default"].OPEN) {
1996
+ try {
1997
+ runtime_1["default"].createSocketRequest("POST", getUniqueURL(getSendURL(this.location, this.session))).start(payload);
1998
+ return true;
1999
+ }
2000
+ catch (e) {
2001
+ return false;
2002
+ }
2003
+ }
2004
+ else {
2005
+ return false;
2006
+ }
2007
+ };
2008
+ HTTPSocket.prototype.reconnect = function () {
2009
+ this.closeStream();
2010
+ this.openStream();
2011
+ };
2012
+ ;
2013
+ HTTPSocket.prototype.onClose = function (code, reason, wasClean) {
2014
+ this.closeStream();
2015
+ this.readyState = state_1["default"].CLOSED;
2016
+ if (this.onclose) {
2017
+ this.onclose({
2018
+ code: code,
2019
+ reason: reason,
2020
+ wasClean: wasClean
2021
+ });
2022
+ }
2023
+ };
2024
+ HTTPSocket.prototype.onChunk = function (chunk) {
2025
+ if (chunk.status !== 200) {
2026
+ return;
2027
+ }
2028
+ if (this.readyState === state_1["default"].OPEN) {
2029
+ this.onActivity();
2030
+ }
2031
+ var payload;
2032
+ var type = chunk.data.slice(0, 1);
2033
+ switch (type) {
2034
+ case 'o':
2035
+ payload = JSON.parse(chunk.data.slice(1) || '{}');
2036
+ this.onOpen(payload);
2037
+ break;
2038
+ case 'a':
2039
+ payload = JSON.parse(chunk.data.slice(1) || '[]');
2040
+ for (var i = 0; i < payload.length; i++) {
2041
+ this.onEvent(payload[i]);
2042
+ }
2043
+ break;
2044
+ case 'm':
2045
+ payload = JSON.parse(chunk.data.slice(1) || 'null');
2046
+ this.onEvent(payload);
2047
+ break;
2048
+ case 'h':
2049
+ this.hooks.onHeartbeat(this);
2050
+ break;
2051
+ case 'c':
2052
+ payload = JSON.parse(chunk.data.slice(1) || '[]');
2053
+ this.onClose(payload[0], payload[1], true);
2054
+ break;
2055
+ }
2056
+ };
2057
+ HTTPSocket.prototype.onOpen = function (options) {
2058
+ if (this.readyState === state_1["default"].CONNECTING) {
2059
+ if (options && options.hostname) {
2060
+ this.location.base = replaceHost(this.location.base, options.hostname);
2061
+ }
2062
+ this.readyState = state_1["default"].OPEN;
2063
+ if (this.onopen) {
2064
+ this.onopen();
2065
+ }
2066
+ }
2067
+ else {
2068
+ this.onClose(1006, "Server lost session", true);
2069
+ }
2070
+ };
2071
+ HTTPSocket.prototype.onEvent = function (event) {
2072
+ if (this.readyState === state_1["default"].OPEN && this.onmessage) {
2073
+ this.onmessage({ data: event });
2074
+ }
2075
+ };
2076
+ HTTPSocket.prototype.onActivity = function () {
2077
+ if (this.onactivity) {
2078
+ this.onactivity();
2079
+ }
2080
+ };
2081
+ HTTPSocket.prototype.onError = function (error) {
2082
+ if (this.onerror) {
2083
+ this.onerror(error);
2084
+ }
2085
+ };
2086
+ HTTPSocket.prototype.openStream = function () {
2087
+ var _this = this;
2088
+ this.stream = runtime_1["default"].createSocketRequest("POST", getUniqueURL(this.hooks.getReceiveURL(this.location, this.session)));
2089
+ this.stream.bind("chunk", function (chunk) {
2090
+ _this.onChunk(chunk);
2091
+ });
2092
+ this.stream.bind("finished", function (status) {
2093
+ _this.hooks.onFinished(_this, status);
2094
+ });
2095
+ this.stream.bind("buffer_too_long", function () {
2096
+ _this.reconnect();
2097
+ });
2098
+ try {
2099
+ this.stream.start();
2100
+ }
2101
+ catch (error) {
2102
+ util_1["default"].defer(function () {
2103
+ _this.onError(error);
2104
+ _this.onClose(1006, "Could not start streaming", false);
2105
+ });
2106
+ }
2107
+ };
2108
+ HTTPSocket.prototype.closeStream = function () {
2109
+ if (this.stream) {
2110
+ this.stream.unbind_all();
2111
+ this.stream.close();
2112
+ this.stream = null;
2113
+ }
2114
+ };
2115
+ return HTTPSocket;
2116
+ }());
2117
+ function getLocation(url) {
2118
+ var parts = /([^\?]*)\/*(\??.*)/.exec(url);
2119
+ return {
2120
+ base: parts[1],
2121
+ queryString: parts[2]
2122
+ };
2123
+ }
2124
+ function getSendURL(url, session) {
2125
+ return url.base + "/" + session + "/xhr_send";
2126
+ }
2127
+ function getUniqueURL(url) {
2128
+ var separator = (url.indexOf('?') === -1) ? "?" : "&";
2129
+ return url + separator + "t=" + (+new Date()) + "&n=" + autoIncrement++;
2130
+ }
2131
+ function replaceHost(url, hostname) {
2132
+ var urlParts = /(https?:\/\/)([^\/:]+)((\/|:)?.*)/.exec(url);
2133
+ return urlParts[1] + hostname + urlParts[3];
2134
+ }
2135
+ function randomNumber(max) {
2136
+ return Math.floor(Math.random() * max);
2137
+ }
2138
+ function randomString(length) {
2139
+ var result = [];
2140
+ for (var i = 0; i < length; i++) {
2141
+ result.push(randomNumber(32).toString(32));
2142
+ }
2143
+ return result.join('');
2144
+ }
2145
+ exports.__esModule = true;
2146
+ exports["default"] = HTTPSocket;
2147
+
2148
+
2149
+ /***/ },
2150
+ /* 34 */
2151
+ /***/ function(module, exports) {
2152
+
2153
+ "use strict";
2154
+ var State;
2155
+ (function (State) {
2156
+ State[State["CONNECTING"] = 0] = "CONNECTING";
2157
+ State[State["OPEN"] = 1] = "OPEN";
2158
+ State[State["CLOSED"] = 3] = "CLOSED";
2159
+ })(State || (State = {}));
2160
+ exports.__esModule = true;
2161
+ exports["default"] = State;
2162
+
2163
+
2164
+ /***/ },
2165
+ /* 35 */
2166
+ /***/ function(module, exports) {
2167
+
2168
+ "use strict";
2169
+ var hooks = {
2170
+ getReceiveURL: function (url, session) {
2171
+ return url.base + "/" + session + "/xhr_streaming" + url.queryString;
2172
+ },
2173
+ onHeartbeat: function (socket) {
2174
+ socket.sendRaw("[]");
2175
+ },
2176
+ sendHeartbeat: function (socket) {
2177
+ socket.sendRaw("[]");
2178
+ },
2179
+ onFinished: function (socket, status) {
2180
+ socket.onClose(1006, "Connection interrupted (" + status + ")", false);
2181
+ }
2182
+ };
2183
+ exports.__esModule = true;
2184
+ exports["default"] = hooks;
2185
+
2186
+
2187
+ /***/ },
2188
+ /* 36 */
2189
+ /***/ function(module, exports) {
2190
+
2191
+ "use strict";
2192
+ var hooks = {
2193
+ getReceiveURL: function (url, session) {
2194
+ return url.base + "/" + session + "/xhr" + url.queryString;
2195
+ },
2196
+ onHeartbeat: function () {
2197
+ },
2198
+ sendHeartbeat: function (socket) {
2199
+ socket.sendRaw("[]");
2200
+ },
2201
+ onFinished: function (socket, status) {
2202
+ if (status === 200) {
2203
+ socket.reconnect();
2204
+ }
2205
+ else {
2206
+ socket.onClose(1006, "Connection interrupted (" + status + ")", false);
2207
+ }
2208
+ }
2209
+ };
2210
+ exports.__esModule = true;
2211
+ exports["default"] = hooks;
2212
+
2213
+
2214
+ /***/ },
2215
+ /* 37 */
2216
+ /***/ function(module, exports, __webpack_require__) {
2217
+
2218
+ "use strict";
2219
+ var runtime_1 = __webpack_require__(2);
2220
+ var hooks = {
2221
+ getRequest: function (socket) {
2222
+ var Constructor = runtime_1["default"].getXHRAPI();
2223
+ var xhr = new Constructor();
2224
+ xhr.onreadystatechange = xhr.onprogress = function () {
2225
+ switch (xhr.readyState) {
2226
+ case 3:
2227
+ if (xhr.responseText && xhr.responseText.length > 0) {
2228
+ socket.onChunk(xhr.status, xhr.responseText);
2229
+ }
2230
+ break;
2231
+ case 4:
2232
+ if (xhr.responseText && xhr.responseText.length > 0) {
2233
+ socket.onChunk(xhr.status, xhr.responseText);
2234
+ }
2235
+ socket.emit("finished", xhr.status);
2236
+ socket.close();
2237
+ break;
2238
+ }
2239
+ };
2240
+ return xhr;
2241
+ },
2242
+ abortRequest: function (xhr) {
2243
+ xhr.onreadystatechange = null;
2244
+ xhr.abort();
2245
+ }
2246
+ };
2247
+ exports.__esModule = true;
2248
+ exports["default"] = hooks;
2249
+
2250
+
2251
+ /***/ },
2252
+ /* 38 */
2253
+ /***/ function(module, exports, __webpack_require__) {
2254
+
2255
+ "use strict";
2256
+ var Collections = __webpack_require__(9);
2257
+ var util_1 = __webpack_require__(11);
2258
+ var level_1 = __webpack_require__(39);
2259
+ var Timeline = (function () {
2260
+ function Timeline(key, session, options) {
2261
+ this.key = key;
2262
+ this.session = session;
2263
+ this.events = [];
2264
+ this.options = options || {};
2265
+ this.sent = 0;
2266
+ this.uniqueID = 0;
2267
+ }
2268
+ Timeline.prototype.log = function (level, event) {
2269
+ if (level <= this.options.level) {
2270
+ this.events.push(Collections.extend({}, event, { timestamp: util_1["default"].now() }));
2271
+ if (this.options.limit && this.events.length > this.options.limit) {
2272
+ this.events.shift();
2273
+ }
2274
+ }
2275
+ };
2276
+ Timeline.prototype.error = function (event) {
2277
+ this.log(level_1["default"].ERROR, event);
2278
+ };
2279
+ Timeline.prototype.info = function (event) {
2280
+ this.log(level_1["default"].INFO, event);
2281
+ };
2282
+ Timeline.prototype.debug = function (event) {
2283
+ this.log(level_1["default"].DEBUG, event);
2284
+ };
2285
+ Timeline.prototype.isEmpty = function () {
2286
+ return this.events.length === 0;
2287
+ };
2288
+ Timeline.prototype.send = function (sendfn, callback) {
2289
+ var _this = this;
2290
+ var data = Collections.extend({
2291
+ session: this.session,
2292
+ bundle: this.sent + 1,
2293
+ key: this.key,
2294
+ lib: "js",
2295
+ version: this.options.version,
2296
+ cluster: this.options.cluster,
2297
+ features: this.options.features,
2298
+ timeline: this.events
2299
+ }, this.options.params);
2300
+ this.events = [];
2301
+ sendfn(data, function (error, result) {
2302
+ if (!error) {
2303
+ _this.sent++;
2304
+ }
2305
+ if (callback) {
2306
+ callback(error, result);
2307
+ }
2308
+ });
2309
+ return true;
2310
+ };
2311
+ Timeline.prototype.generateUniqueID = function () {
2312
+ this.uniqueID++;
2313
+ return this.uniqueID;
2314
+ };
2315
+ return Timeline;
2316
+ }());
2317
+ exports.__esModule = true;
2318
+ exports["default"] = Timeline;
2319
+
2320
+
2321
+ /***/ },
2322
+ /* 39 */
2323
+ /***/ function(module, exports) {
2324
+
2325
+ "use strict";
2326
+ var TimelineLevel;
2327
+ (function (TimelineLevel) {
2328
+ TimelineLevel[TimelineLevel["ERROR"] = 3] = "ERROR";
2329
+ TimelineLevel[TimelineLevel["INFO"] = 6] = "INFO";
2330
+ TimelineLevel[TimelineLevel["DEBUG"] = 7] = "DEBUG";
2331
+ })(TimelineLevel || (TimelineLevel = {}));
2332
+ exports.__esModule = true;
2333
+ exports["default"] = TimelineLevel;
2334
+
2335
+
2336
+ /***/ },
2337
+ /* 40 */
2338
+ /***/ function(module, exports, __webpack_require__) {
2339
+
2340
+ "use strict";
2341
+ var Collections = __webpack_require__(9);
2342
+ var util_1 = __webpack_require__(11);
2343
+ var transport_manager_1 = __webpack_require__(41);
2344
+ var Errors = __webpack_require__(30);
2345
+ var transport_strategy_1 = __webpack_require__(55);
2346
+ var sequential_strategy_1 = __webpack_require__(56);
2347
+ var best_connected_ever_strategy_1 = __webpack_require__(57);
2348
+ var cached_strategy_1 = __webpack_require__(58);
2349
+ var delayed_strategy_1 = __webpack_require__(59);
2350
+ var if_strategy_1 = __webpack_require__(60);
2351
+ var first_connected_strategy_1 = __webpack_require__(61);
2352
+ var runtime_1 = __webpack_require__(2);
2353
+ var Transports = runtime_1["default"].Transports;
2354
+ exports.build = function (scheme, options) {
2355
+ var context = Collections.extend({}, globalContext, options);
2356
+ return evaluate(scheme, context)[1].strategy;
2357
+ };
2358
+ var UnsupportedStrategy = {
2359
+ isSupported: function () {
2360
+ return false;
2361
+ },
2362
+ connect: function (_, callback) {
2363
+ var deferred = util_1["default"].defer(function () {
2364
+ callback(new Errors.UnsupportedStrategy());
2365
+ });
2366
+ return {
2367
+ abort: function () {
2368
+ deferred.ensureAborted();
2369
+ },
2370
+ forceMinPriority: function () { }
2371
+ };
2372
+ }
2373
+ };
2374
+ function returnWithOriginalContext(f) {
2375
+ return function (context) {
2376
+ return [f.apply(this, arguments), context];
2377
+ };
2378
+ }
2379
+ var globalContext = {
2380
+ extend: function (context, first, second) {
2381
+ return [Collections.extend({}, first, second), context];
2382
+ },
2383
+ def: function (context, name, value) {
2384
+ if (context[name] !== undefined) {
2385
+ throw "Redefining symbol " + name;
2386
+ }
2387
+ context[name] = value;
2388
+ return [undefined, context];
2389
+ },
2390
+ def_transport: function (context, name, type, priority, options, manager) {
2391
+ var transportClass = Transports[type];
2392
+ if (!transportClass) {
2393
+ throw new Errors.UnsupportedTransport(type);
2394
+ }
2395
+ var enabled = (!context.enabledTransports ||
2396
+ Collections.arrayIndexOf(context.enabledTransports, name) !== -1) &&
2397
+ (!context.disabledTransports ||
2398
+ Collections.arrayIndexOf(context.disabledTransports, name) === -1);
2399
+ var transport;
2400
+ if (enabled) {
2401
+ transport = new transport_strategy_1["default"](name, priority, manager ? manager.getAssistant(transportClass) : transportClass, Collections.extend({
2402
+ key: context.key,
2403
+ encrypted: context.encrypted,
2404
+ timeline: context.timeline,
2405
+ ignoreNullOrigin: context.ignoreNullOrigin
2406
+ }, options));
2407
+ }
2408
+ else {
2409
+ transport = UnsupportedStrategy;
2410
+ }
2411
+ var newContext = context.def(context, name, transport)[1];
2412
+ newContext.Transports = context.Transports || {};
2413
+ newContext.Transports[name] = transport;
2414
+ return [undefined, newContext];
2415
+ },
2416
+ transport_manager: returnWithOriginalContext(function (_, options) {
2417
+ return new transport_manager_1["default"](options);
2418
+ }),
2419
+ sequential: returnWithOriginalContext(function (_, options) {
2420
+ var strategies = Array.prototype.slice.call(arguments, 2);
2421
+ return new sequential_strategy_1["default"](strategies, options);
2422
+ }),
2423
+ cached: returnWithOriginalContext(function (context, ttl, strategy) {
2424
+ return new cached_strategy_1["default"](strategy, context.Transports, {
2425
+ ttl: ttl,
2426
+ timeline: context.timeline,
2427
+ encrypted: context.encrypted
2428
+ });
2429
+ }),
2430
+ first_connected: returnWithOriginalContext(function (_, strategy) {
2431
+ return new first_connected_strategy_1["default"](strategy);
2432
+ }),
2433
+ best_connected_ever: returnWithOriginalContext(function () {
2434
+ var strategies = Array.prototype.slice.call(arguments, 1);
2435
+ return new best_connected_ever_strategy_1["default"](strategies);
2436
+ }),
2437
+ delayed: returnWithOriginalContext(function (_, delay, strategy) {
2438
+ return new delayed_strategy_1["default"](strategy, { delay: delay });
2439
+ }),
2440
+ "if": returnWithOriginalContext(function (_, test, trueBranch, falseBranch) {
2441
+ return new if_strategy_1["default"](test, trueBranch, falseBranch);
2442
+ }),
2443
+ is_supported: returnWithOriginalContext(function (_, strategy) {
2444
+ return function () {
2445
+ return strategy.isSupported();
2446
+ };
2447
+ })
2448
+ };
2449
+ function isSymbol(expression) {
2450
+ return (typeof expression === "string") && expression.charAt(0) === ":";
2451
+ }
2452
+ function getSymbolValue(expression, context) {
2453
+ return context[expression.slice(1)];
2454
+ }
2455
+ function evaluateListOfExpressions(expressions, context) {
2456
+ if (expressions.length === 0) {
2457
+ return [[], context];
2458
+ }
2459
+ var head = evaluate(expressions[0], context);
2460
+ var tail = evaluateListOfExpressions(expressions.slice(1), head[1]);
2461
+ return [[head[0]].concat(tail[0]), tail[1]];
2462
+ }
2463
+ function evaluateString(expression, context) {
2464
+ if (!isSymbol(expression)) {
2465
+ return [expression, context];
2466
+ }
2467
+ var value = getSymbolValue(expression, context);
2468
+ if (value === undefined) {
2469
+ throw "Undefined symbol " + expression;
2470
+ }
2471
+ return [value, context];
2472
+ }
2473
+ function evaluateArray(expression, context) {
2474
+ if (isSymbol(expression[0])) {
2475
+ var f = getSymbolValue(expression[0], context);
2476
+ if (expression.length > 1) {
2477
+ if (typeof f !== "function") {
2478
+ throw "Calling non-function " + expression[0];
2479
+ }
2480
+ var args = [Collections.extend({}, context)].concat(Collections.map(expression.slice(1), function (arg) {
2481
+ return evaluate(arg, Collections.extend({}, context))[0];
2482
+ }));
2483
+ return f.apply(this, args);
2484
+ }
2485
+ else {
2486
+ return [f, context];
2487
+ }
2488
+ }
2489
+ else {
2490
+ return evaluateListOfExpressions(expression, context);
2491
+ }
2492
+ }
2493
+ function evaluate(expression, context) {
2494
+ if (typeof expression === "string") {
2495
+ return evaluateString(expression, context);
2496
+ }
2497
+ else if (typeof expression === "object") {
2498
+ if (expression instanceof Array && expression.length > 0) {
2499
+ return evaluateArray(expression, context);
2500
+ }
2501
+ }
2502
+ return [expression, context];
2503
+ }
2504
+
2505
+
2506
+ /***/ },
2507
+ /* 41 */
2508
+ /***/ function(module, exports, __webpack_require__) {
2509
+
2510
+ "use strict";
2511
+ var factory_1 = __webpack_require__(42);
2512
+ var TransportManager = (function () {
2513
+ function TransportManager(options) {
2514
+ this.options = options || {};
2515
+ this.livesLeft = this.options.lives || Infinity;
2516
+ }
2517
+ TransportManager.prototype.getAssistant = function (transport) {
2518
+ return factory_1["default"].createAssistantToTheTransportManager(this, transport, {
2519
+ minPingDelay: this.options.minPingDelay,
2520
+ maxPingDelay: this.options.maxPingDelay
2521
+ });
2522
+ };
2523
+ TransportManager.prototype.isAlive = function () {
2524
+ return this.livesLeft > 0;
2525
+ };
2526
+ TransportManager.prototype.reportDeath = function () {
2527
+ this.livesLeft -= 1;
2528
+ };
2529
+ return TransportManager;
2530
+ }());
2531
+ exports.__esModule = true;
2532
+ exports["default"] = TransportManager;
2533
+
2534
+
2535
+ /***/ },
2536
+ /* 42 */
2537
+ /***/ function(module, exports, __webpack_require__) {
2538
+
2539
+ "use strict";
2540
+ var assistant_to_the_transport_manager_1 = __webpack_require__(43);
2541
+ var handshake_1 = __webpack_require__(44);
2542
+ var pusher_authorizer_1 = __webpack_require__(47);
2543
+ var timeline_sender_1 = __webpack_require__(48);
2544
+ var presence_channel_1 = __webpack_require__(49);
2545
+ var private_channel_1 = __webpack_require__(50);
2546
+ var channel_1 = __webpack_require__(51);
2547
+ var connection_manager_1 = __webpack_require__(53);
2548
+ var channels_1 = __webpack_require__(54);
2549
+ var Factory = {
2550
+ createChannels: function () {
2551
+ return new channels_1["default"]();
2552
+ },
2553
+ createConnectionManager: function (key, options) {
2554
+ return new connection_manager_1["default"](key, options);
2555
+ },
2556
+ createChannel: function (name, pusher) {
2557
+ return new channel_1["default"](name, pusher);
2558
+ },
2559
+ createPrivateChannel: function (name, pusher) {
2560
+ return new private_channel_1["default"](name, pusher);
2561
+ },
2562
+ createPresenceChannel: function (name, pusher) {
2563
+ return new presence_channel_1["default"](name, pusher);
2564
+ },
2565
+ createTimelineSender: function (timeline, options) {
2566
+ return new timeline_sender_1["default"](timeline, options);
2567
+ },
2568
+ createAuthorizer: function (channel, options) {
2569
+ return new pusher_authorizer_1["default"](channel, options);
2570
+ },
2571
+ createHandshake: function (transport, callback) {
2572
+ return new handshake_1["default"](transport, callback);
2573
+ },
2574
+ createAssistantToTheTransportManager: function (manager, transport, options) {
2575
+ return new assistant_to_the_transport_manager_1["default"](manager, transport, options);
2576
+ }
2577
+ };
2578
+ exports.__esModule = true;
2579
+ exports["default"] = Factory;
2580
+
2581
+
2582
+ /***/ },
2583
+ /* 43 */
2584
+ /***/ function(module, exports, __webpack_require__) {
2585
+
2586
+ "use strict";
2587
+ var util_1 = __webpack_require__(11);
2588
+ var Collections = __webpack_require__(9);
2589
+ var AssistantToTheTransportManager = (function () {
2590
+ function AssistantToTheTransportManager(manager, transport, options) {
2591
+ this.manager = manager;
2592
+ this.transport = transport;
2593
+ this.minPingDelay = options.minPingDelay;
2594
+ this.maxPingDelay = options.maxPingDelay;
2595
+ this.pingDelay = undefined;
2596
+ }
2597
+ AssistantToTheTransportManager.prototype.createConnection = function (name, priority, key, options) {
2598
+ var _this = this;
2599
+ options = Collections.extend({}, options, {
2600
+ activityTimeout: this.pingDelay
2601
+ });
2602
+ var connection = this.transport.createConnection(name, priority, key, options);
2603
+ var openTimestamp = null;
2604
+ var onOpen = function () {
2605
+ connection.unbind("open", onOpen);
2606
+ connection.bind("closed", onClosed);
2607
+ openTimestamp = util_1["default"].now();
2608
+ };
2609
+ var onClosed = function (closeEvent) {
2610
+ connection.unbind("closed", onClosed);
2611
+ if (closeEvent.code === 1002 || closeEvent.code === 1003) {
2612
+ _this.manager.reportDeath();
2613
+ }
2614
+ else if (!closeEvent.wasClean && openTimestamp) {
2615
+ var lifespan = util_1["default"].now() - openTimestamp;
2616
+ if (lifespan < 2 * _this.maxPingDelay) {
2617
+ _this.manager.reportDeath();
2618
+ _this.pingDelay = Math.max(lifespan / 2, _this.minPingDelay);
2619
+ }
2620
+ }
2621
+ };
2622
+ connection.bind("open", onOpen);
2623
+ return connection;
2624
+ };
2625
+ AssistantToTheTransportManager.prototype.isSupported = function (environment) {
2626
+ return this.manager.isAlive() && this.transport.isSupported(environment);
2627
+ };
2628
+ return AssistantToTheTransportManager;
2629
+ }());
2630
+ exports.__esModule = true;
2631
+ exports["default"] = AssistantToTheTransportManager;
2632
+
2633
+
2634
+ /***/ },
2635
+ /* 44 */
2636
+ /***/ function(module, exports, __webpack_require__) {
2637
+
2638
+ "use strict";
2639
+ var Collections = __webpack_require__(9);
2640
+ var Protocol = __webpack_require__(45);
2641
+ var connection_1 = __webpack_require__(46);
2642
+ var Handshake = (function () {
2643
+ function Handshake(transport, callback) {
2644
+ this.transport = transport;
2645
+ this.callback = callback;
2646
+ this.bindListeners();
2647
+ }
2648
+ Handshake.prototype.close = function () {
2649
+ this.unbindListeners();
2650
+ this.transport.close();
2651
+ };
2652
+ Handshake.prototype.bindListeners = function () {
2653
+ var _this = this;
2654
+ this.onMessage = function (m) {
2655
+ _this.unbindListeners();
2656
+ var result;
2657
+ try {
2658
+ result = Protocol.processHandshake(m);
2659
+ }
2660
+ catch (e) {
2661
+ _this.finish("error", { error: e });
2662
+ _this.transport.close();
2663
+ return;
2664
+ }
2665
+ if (result.action === "connected") {
2666
+ _this.finish("connected", {
2667
+ connection: new connection_1["default"](result.id, _this.transport),
2668
+ activityTimeout: result.activityTimeout
2669
+ });
2670
+ }
2671
+ else {
2672
+ _this.finish(result.action, { error: result.error });
2673
+ _this.transport.close();
2674
+ }
2675
+ };
2676
+ this.onClosed = function (closeEvent) {
2677
+ _this.unbindListeners();
2678
+ var action = Protocol.getCloseAction(closeEvent) || "backoff";
2679
+ var error = Protocol.getCloseError(closeEvent);
2680
+ _this.finish(action, { error: error });
2681
+ };
2682
+ this.transport.bind("message", this.onMessage);
2683
+ this.transport.bind("closed", this.onClosed);
2684
+ };
2685
+ Handshake.prototype.unbindListeners = function () {
2686
+ this.transport.unbind("message", this.onMessage);
2687
+ this.transport.unbind("closed", this.onClosed);
2688
+ };
2689
+ Handshake.prototype.finish = function (action, params) {
2690
+ this.callback(Collections.extend({ transport: this.transport, action: action }, params));
2691
+ };
2692
+ return Handshake;
2693
+ }());
2694
+ exports.__esModule = true;
2695
+ exports["default"] = Handshake;
2696
+
2697
+
2698
+ /***/ },
2699
+ /* 45 */
2700
+ /***/ function(module, exports) {
2701
+
2702
+ "use strict";
2703
+ exports.decodeMessage = function (message) {
2704
+ try {
2705
+ var params = JSON.parse(message.data);
2706
+ if (typeof params.data === 'string') {
2707
+ try {
2708
+ params.data = JSON.parse(params.data);
2709
+ }
2710
+ catch (e) {
2711
+ if (!(e instanceof SyntaxError)) {
2712
+ throw e;
2713
+ }
2714
+ }
2715
+ }
2716
+ return params;
2717
+ }
2718
+ catch (e) {
2719
+ throw { type: 'MessageParseError', error: e, data: message.data };
2720
+ }
2721
+ };
2722
+ exports.encodeMessage = function (message) {
2723
+ return JSON.stringify(message);
2724
+ };
2725
+ exports.processHandshake = function (message) {
2726
+ message = exports.decodeMessage(message);
2727
+ if (message.event === "pusher:connection_established") {
2728
+ if (!message.data.activity_timeout) {
2729
+ throw "No activity timeout specified in handshake";
2730
+ }
2731
+ return {
2732
+ action: "connected",
2733
+ id: message.data.socket_id,
2734
+ activityTimeout: message.data.activity_timeout * 1000
2735
+ };
2736
+ }
2737
+ else if (message.event === "pusher:error") {
2738
+ return {
2739
+ action: this.getCloseAction(message.data),
2740
+ error: this.getCloseError(message.data)
2741
+ };
2742
+ }
2743
+ else {
2744
+ throw "Invalid handshake";
2745
+ }
2746
+ };
2747
+ exports.getCloseAction = function (closeEvent) {
2748
+ if (closeEvent.code < 4000) {
2749
+ if (closeEvent.code >= 1002 && closeEvent.code <= 1004) {
2750
+ return "backoff";
2751
+ }
2752
+ else {
2753
+ return null;
2754
+ }
2755
+ }
2756
+ else if (closeEvent.code === 4000) {
2757
+ return "ssl_only";
2758
+ }
2759
+ else if (closeEvent.code < 4100) {
2760
+ return "refused";
2761
+ }
2762
+ else if (closeEvent.code < 4200) {
2763
+ return "backoff";
2764
+ }
2765
+ else if (closeEvent.code < 4300) {
2766
+ return "retry";
2767
+ }
2768
+ else {
2769
+ return "refused";
2770
+ }
2771
+ };
2772
+ exports.getCloseError = function (closeEvent) {
2773
+ if (closeEvent.code !== 1000 && closeEvent.code !== 1001) {
2774
+ return {
2775
+ type: 'PusherError',
2776
+ data: {
2777
+ code: closeEvent.code,
2778
+ message: closeEvent.reason || closeEvent.message
2779
+ }
2780
+ };
2781
+ }
2782
+ else {
2783
+ return null;
2784
+ }
2785
+ };
2786
+
2787
+
2788
+ /***/ },
2789
+ /* 46 */
2790
+ /***/ function(module, exports, __webpack_require__) {
2791
+
2792
+ "use strict";
2793
+ var __extends = (this && this.__extends) || function (d, b) {
2794
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
2795
+ function __() { this.constructor = d; }
2796
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
2797
+ };
2798
+ var Collections = __webpack_require__(9);
2799
+ var dispatcher_1 = __webpack_require__(23);
2800
+ var Protocol = __webpack_require__(45);
2801
+ var logger_1 = __webpack_require__(8);
2802
+ var Connection = (function (_super) {
2803
+ __extends(Connection, _super);
2804
+ function Connection(id, transport) {
2805
+ _super.call(this);
2806
+ this.id = id;
2807
+ this.transport = transport;
2808
+ this.activityTimeout = transport.activityTimeout;
2809
+ this.bindListeners();
2810
+ }
2811
+ Connection.prototype.handlesActivityChecks = function () {
2812
+ return this.transport.handlesActivityChecks();
2813
+ };
2814
+ Connection.prototype.send = function (data) {
2815
+ return this.transport.send(data);
2816
+ };
2817
+ Connection.prototype.send_event = function (name, data, channel) {
2818
+ var message = { event: name, data: data };
2819
+ if (channel) {
2820
+ message.channel = channel;
2821
+ }
2822
+ logger_1["default"].debug('Event sent', message);
2823
+ return this.send(Protocol.encodeMessage(message));
2824
+ };
2825
+ Connection.prototype.ping = function () {
2826
+ if (this.transport.supportsPing()) {
2827
+ this.transport.ping();
2828
+ }
2829
+ else {
2830
+ this.send_event('pusher:ping', {});
2831
+ }
2832
+ };
2833
+ Connection.prototype.close = function () {
2834
+ this.transport.close();
2835
+ };
2836
+ Connection.prototype.bindListeners = function () {
2837
+ var _this = this;
2838
+ var listeners = {
2839
+ message: function (m) {
2840
+ var message;
2841
+ try {
2842
+ message = Protocol.decodeMessage(m);
2843
+ }
2844
+ catch (e) {
2845
+ _this.emit('error', {
2846
+ type: 'MessageParseError',
2847
+ error: e,
2848
+ data: m.data
2849
+ });
2850
+ }
2851
+ if (message !== undefined) {
2852
+ logger_1["default"].debug('Event recd', message);
2853
+ switch (message.event) {
2854
+ case 'pusher:error':
2855
+ _this.emit('error', { type: 'PusherError', data: message.data });
2856
+ break;
2857
+ case 'pusher:ping':
2858
+ _this.emit("ping");
2859
+ break;
2860
+ case 'pusher:pong':
2861
+ _this.emit("pong");
2862
+ break;
2863
+ }
2864
+ _this.emit('message', message);
2865
+ }
2866
+ },
2867
+ activity: function () {
2868
+ _this.emit("activity");
2869
+ },
2870
+ error: function (error) {
2871
+ _this.emit("error", { type: "WebSocketError", error: error });
2872
+ },
2873
+ closed: function (closeEvent) {
2874
+ unbindListeners();
2875
+ if (closeEvent && closeEvent.code) {
2876
+ _this.handleCloseEvent(closeEvent);
2877
+ }
2878
+ _this.transport = null;
2879
+ _this.emit("closed");
2880
+ }
2881
+ };
2882
+ var unbindListeners = function () {
2883
+ Collections.objectApply(listeners, function (listener, event) {
2884
+ _this.transport.unbind(event, listener);
2885
+ });
2886
+ };
2887
+ Collections.objectApply(listeners, function (listener, event) {
2888
+ _this.transport.bind(event, listener);
2889
+ });
2890
+ };
2891
+ Connection.prototype.handleCloseEvent = function (closeEvent) {
2892
+ var action = Protocol.getCloseAction(closeEvent);
2893
+ var error = Protocol.getCloseError(closeEvent);
2894
+ if (error) {
2895
+ this.emit('error', error);
2896
+ }
2897
+ if (action) {
2898
+ this.emit(action);
2899
+ }
2900
+ };
2901
+ return Connection;
2902
+ }(dispatcher_1["default"]));
2903
+ exports.__esModule = true;
2904
+ exports["default"] = Connection;
2905
+
2906
+
2907
+ /***/ },
2908
+ /* 47 */
2909
+ /***/ function(module, exports, __webpack_require__) {
2910
+
2911
+ "use strict";
2912
+ var runtime_1 = __webpack_require__(2);
2913
+ var Authorizer = (function () {
2914
+ function Authorizer(channel, options) {
2915
+ this.channel = channel;
2916
+ var authTransport = options.authTransport;
2917
+ if (typeof runtime_1["default"].getAuthorizers()[authTransport] === "undefined") {
2918
+ throw "'" + authTransport + "' is not a recognized auth transport";
2919
+ }
2920
+ this.type = authTransport;
2921
+ this.options = options;
2922
+ this.authOptions = (options || {}).auth || {};
2923
+ }
2924
+ Authorizer.prototype.composeQuery = function (socketId) {
2925
+ var query = 'socket_id=' + encodeURIComponent(socketId) +
2926
+ '&channel_name=' + encodeURIComponent(this.channel.name);
2927
+ for (var i in this.authOptions.params) {
2928
+ query += "&" + encodeURIComponent(i) + "=" + encodeURIComponent(this.authOptions.params[i]);
2929
+ }
2930
+ return query;
2931
+ };
2932
+ Authorizer.prototype.authorize = function (socketId, callback) {
2933
+ Authorizer.authorizers = Authorizer.authorizers || runtime_1["default"].getAuthorizers();
2934
+ return Authorizer.authorizers[this.type].call(this, runtime_1["default"], socketId, callback);
2935
+ };
2936
+ return Authorizer;
2937
+ }());
2938
+ exports.__esModule = true;
2939
+ exports["default"] = Authorizer;
2940
+
2941
+
2942
+ /***/ },
2943
+ /* 48 */
2944
+ /***/ function(module, exports, __webpack_require__) {
2945
+
2946
+ "use strict";
2947
+ var runtime_1 = __webpack_require__(2);
2948
+ var TimelineSender = (function () {
2949
+ function TimelineSender(timeline, options) {
2950
+ this.timeline = timeline;
2951
+ this.options = options || {};
2952
+ }
2953
+ TimelineSender.prototype.send = function (encrypted, callback) {
2954
+ if (this.timeline.isEmpty()) {
2955
+ return;
2956
+ }
2957
+ this.timeline.send(runtime_1["default"].TimelineTransport.getAgent(this, encrypted), callback);
2958
+ };
2959
+ return TimelineSender;
2960
+ }());
2961
+ exports.__esModule = true;
2962
+ exports["default"] = TimelineSender;
2963
+
2964
+
2965
+ /***/ },
2966
+ /* 49 */
2967
+ /***/ function(module, exports, __webpack_require__) {
2968
+
2969
+ "use strict";
2970
+ var __extends = (this && this.__extends) || function (d, b) {
2971
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
2972
+ function __() { this.constructor = d; }
2973
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
2974
+ };
2975
+ var private_channel_1 = __webpack_require__(50);
2976
+ var logger_1 = __webpack_require__(8);
2977
+ var members_1 = __webpack_require__(52);
2978
+ var PresenceChannel = (function (_super) {
2979
+ __extends(PresenceChannel, _super);
2980
+ function PresenceChannel(name, pusher) {
2981
+ _super.call(this, name, pusher);
2982
+ this.members = new members_1["default"]();
2983
+ }
2984
+ PresenceChannel.prototype.authorize = function (socketId, callback) {
2985
+ var _this = this;
2986
+ _super.prototype.authorize.call(this, socketId, function (error, authData) {
2987
+ if (!error) {
2988
+ if (authData.channel_data === undefined) {
2989
+ logger_1["default"].warn("Invalid auth response for channel '" +
2990
+ _this.name +
2991
+ "', expected 'channel_data' field");
2992
+ callback("Invalid auth response");
2993
+ return;
2994
+ }
2995
+ var channelData = JSON.parse(authData.channel_data);
2996
+ _this.members.setMyID(channelData.user_id);
2997
+ }
2998
+ callback(error, authData);
2999
+ });
3000
+ };
3001
+ PresenceChannel.prototype.handleEvent = function (event, data) {
3002
+ switch (event) {
3003
+ case "pusher_internal:subscription_succeeded":
3004
+ this.members.onSubscription(data);
3005
+ this.subscribed = true;
3006
+ this.emit("pusher:subscription_succeeded", this.members);
3007
+ break;
3008
+ case "pusher_internal:member_added":
3009
+ var addedMember = this.members.addMember(data);
3010
+ this.emit('pusher:member_added', addedMember);
3011
+ break;
3012
+ case "pusher_internal:member_removed":
3013
+ var removedMember = this.members.removeMember(data);
3014
+ if (removedMember) {
3015
+ this.emit('pusher:member_removed', removedMember);
3016
+ }
3017
+ break;
3018
+ default:
3019
+ private_channel_1["default"].prototype.handleEvent.call(this, event, data);
3020
+ }
3021
+ };
3022
+ PresenceChannel.prototype.disconnect = function () {
3023
+ this.members.reset();
3024
+ _super.prototype.disconnect.call(this);
3025
+ };
3026
+ return PresenceChannel;
3027
+ }(private_channel_1["default"]));
3028
+ exports.__esModule = true;
3029
+ exports["default"] = PresenceChannel;
3030
+
3031
+
3032
+ /***/ },
3033
+ /* 50 */
3034
+ /***/ function(module, exports, __webpack_require__) {
3035
+
3036
+ "use strict";
3037
+ var __extends = (this && this.__extends) || function (d, b) {
3038
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3039
+ function __() { this.constructor = d; }
3040
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3041
+ };
3042
+ var factory_1 = __webpack_require__(42);
3043
+ var channel_1 = __webpack_require__(51);
3044
+ var PrivateChannel = (function (_super) {
3045
+ __extends(PrivateChannel, _super);
3046
+ function PrivateChannel() {
3047
+ _super.apply(this, arguments);
3048
+ }
3049
+ PrivateChannel.prototype.authorize = function (socketId, callback) {
3050
+ var authorizer = factory_1["default"].createAuthorizer(this, this.pusher.config);
3051
+ return authorizer.authorize(socketId, callback);
3052
+ };
3053
+ return PrivateChannel;
3054
+ }(channel_1["default"]));
3055
+ exports.__esModule = true;
3056
+ exports["default"] = PrivateChannel;
3057
+
3058
+
3059
+ /***/ },
3060
+ /* 51 */
3061
+ /***/ function(module, exports, __webpack_require__) {
3062
+
3063
+ "use strict";
3064
+ var __extends = (this && this.__extends) || function (d, b) {
3065
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3066
+ function __() { this.constructor = d; }
3067
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3068
+ };
3069
+ var dispatcher_1 = __webpack_require__(23);
3070
+ var Errors = __webpack_require__(30);
3071
+ var logger_1 = __webpack_require__(8);
3072
+ var Channel = (function (_super) {
3073
+ __extends(Channel, _super);
3074
+ function Channel(name, pusher) {
3075
+ _super.call(this, function (event, data) {
3076
+ logger_1["default"].debug('No callbacks on ' + name + ' for ' + event);
3077
+ });
3078
+ this.name = name;
3079
+ this.pusher = pusher;
3080
+ this.subscribed = false;
3081
+ }
3082
+ Channel.prototype.authorize = function (socketId, callback) {
3083
+ return callback(false, {});
3084
+ };
3085
+ Channel.prototype.trigger = function (event, data) {
3086
+ if (event.indexOf("client-") !== 0) {
3087
+ throw new Errors.BadEventName("Event '" + event + "' does not start with 'client-'");
3088
+ }
3089
+ return this.pusher.send_event(event, data, this.name);
3090
+ };
3091
+ Channel.prototype.disconnect = function () {
3092
+ this.subscribed = false;
3093
+ };
3094
+ Channel.prototype.handleEvent = function (event, data) {
3095
+ if (event.indexOf("pusher_internal:") === 0) {
3096
+ if (event === "pusher_internal:subscription_succeeded") {
3097
+ this.subscribed = true;
3098
+ this.emit("pusher:subscription_succeeded", data);
3099
+ }
3100
+ }
3101
+ else {
3102
+ this.emit(event, data);
3103
+ }
3104
+ };
3105
+ Channel.prototype.subscribe = function () {
3106
+ var _this = this;
3107
+ this.authorize(this.pusher.connection.socket_id, function (error, data) {
3108
+ if (error) {
3109
+ _this.handleEvent('pusher:subscription_error', data);
3110
+ }
3111
+ else {
3112
+ _this.pusher.send_event('pusher:subscribe', {
3113
+ auth: data.auth,
3114
+ channel_data: data.channel_data,
3115
+ channel: _this.name
3116
+ });
3117
+ }
3118
+ });
3119
+ };
3120
+ Channel.prototype.unsubscribe = function () {
3121
+ this.pusher.send_event('pusher:unsubscribe', {
3122
+ channel: this.name
3123
+ });
3124
+ };
3125
+ return Channel;
3126
+ }(dispatcher_1["default"]));
3127
+ exports.__esModule = true;
3128
+ exports["default"] = Channel;
3129
+
3130
+
3131
+ /***/ },
3132
+ /* 52 */
3133
+ /***/ function(module, exports, __webpack_require__) {
3134
+
3135
+ "use strict";
3136
+ var Collections = __webpack_require__(9);
3137
+ var Members = (function () {
3138
+ function Members() {
3139
+ this.reset();
3140
+ }
3141
+ Members.prototype.get = function (id) {
3142
+ if (Object.prototype.hasOwnProperty.call(this.members, id)) {
3143
+ return {
3144
+ id: id,
3145
+ info: this.members[id]
3146
+ };
3147
+ }
3148
+ else {
3149
+ return null;
3150
+ }
3151
+ };
3152
+ Members.prototype.each = function (callback) {
3153
+ var _this = this;
3154
+ Collections.objectApply(this.members, function (member, id) {
3155
+ callback(_this.get(id));
3156
+ });
3157
+ };
3158
+ Members.prototype.setMyID = function (id) {
3159
+ this.myID = id;
3160
+ };
3161
+ Members.prototype.onSubscription = function (subscriptionData) {
3162
+ this.members = subscriptionData.presence.hash;
3163
+ this.count = subscriptionData.presence.count;
3164
+ this.me = this.get(this.myID);
3165
+ };
3166
+ Members.prototype.addMember = function (memberData) {
3167
+ if (this.get(memberData.user_id) === null) {
3168
+ this.count++;
3169
+ }
3170
+ this.members[memberData.user_id] = memberData.user_info;
3171
+ return this.get(memberData.user_id);
3172
+ };
3173
+ Members.prototype.removeMember = function (memberData) {
3174
+ var member = this.get(memberData.user_id);
3175
+ if (member) {
3176
+ delete this.members[memberData.user_id];
3177
+ this.count--;
3178
+ }
3179
+ return member;
3180
+ };
3181
+ Members.prototype.reset = function () {
3182
+ this.members = {};
3183
+ this.count = 0;
3184
+ this.myID = null;
3185
+ this.me = null;
3186
+ };
3187
+ return Members;
3188
+ }());
3189
+ exports.__esModule = true;
3190
+ exports["default"] = Members;
3191
+
3192
+
3193
+ /***/ },
3194
+ /* 53 */
3195
+ /***/ function(module, exports, __webpack_require__) {
3196
+
3197
+ "use strict";
3198
+ var __extends = (this && this.__extends) || function (d, b) {
3199
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3200
+ function __() { this.constructor = d; }
3201
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3202
+ };
3203
+ var dispatcher_1 = __webpack_require__(23);
3204
+ var timers_1 = __webpack_require__(12);
3205
+ var logger_1 = __webpack_require__(8);
3206
+ var Collections = __webpack_require__(9);
3207
+ var runtime_1 = __webpack_require__(2);
3208
+ var ConnectionManager = (function (_super) {
3209
+ __extends(ConnectionManager, _super);
3210
+ function ConnectionManager(key, options) {
3211
+ var _this = this;
3212
+ _super.call(this);
3213
+ this.key = key;
3214
+ this.options = options || {};
3215
+ this.state = "initialized";
3216
+ this.connection = null;
3217
+ this.encrypted = !!options.encrypted;
3218
+ this.timeline = this.options.timeline;
3219
+ this.connectionCallbacks = this.buildConnectionCallbacks();
3220
+ this.errorCallbacks = this.buildErrorCallbacks();
3221
+ this.handshakeCallbacks = this.buildHandshakeCallbacks(this.errorCallbacks);
3222
+ var Network = runtime_1["default"].getNetwork();
3223
+ Network.bind("online", function () {
3224
+ _this.timeline.info({ netinfo: "online" });
3225
+ if (_this.state === "connecting" || _this.state === "unavailable") {
3226
+ _this.retryIn(0);
3227
+ }
3228
+ });
3229
+ Network.bind("offline", function () {
3230
+ _this.timeline.info({ netinfo: "offline" });
3231
+ if (_this.connection) {
3232
+ _this.sendActivityCheck();
3233
+ }
3234
+ });
3235
+ this.updateStrategy();
3236
+ }
3237
+ ConnectionManager.prototype.connect = function () {
3238
+ if (this.connection || this.runner) {
3239
+ return;
3240
+ }
3241
+ if (!this.strategy.isSupported()) {
3242
+ this.updateState("failed");
3243
+ return;
3244
+ }
3245
+ this.updateState("connecting");
3246
+ this.startConnecting();
3247
+ this.setUnavailableTimer();
3248
+ };
3249
+ ;
3250
+ ConnectionManager.prototype.send = function (data) {
3251
+ if (this.connection) {
3252
+ return this.connection.send(data);
3253
+ }
3254
+ else {
3255
+ return false;
3256
+ }
3257
+ };
3258
+ ;
3259
+ ConnectionManager.prototype.send_event = function (name, data, channel) {
3260
+ if (this.connection) {
3261
+ return this.connection.send_event(name, data, channel);
3262
+ }
3263
+ else {
3264
+ return false;
3265
+ }
3266
+ };
3267
+ ;
3268
+ ConnectionManager.prototype.disconnect = function () {
3269
+ this.disconnectInternally();
3270
+ this.updateState("disconnected");
3271
+ };
3272
+ ;
3273
+ ConnectionManager.prototype.isEncrypted = function () {
3274
+ return this.encrypted;
3275
+ };
3276
+ ;
3277
+ ConnectionManager.prototype.startConnecting = function () {
3278
+ var _this = this;
3279
+ var callback = function (error, handshake) {
3280
+ if (error) {
3281
+ _this.runner = _this.strategy.connect(0, callback);
3282
+ }
3283
+ else {
3284
+ if (handshake.action === "error") {
3285
+ _this.emit("error", { type: "HandshakeError", error: handshake.error });
3286
+ _this.timeline.error({ handshakeError: handshake.error });
3287
+ }
3288
+ else {
3289
+ _this.abortConnecting();
3290
+ _this.handshakeCallbacks[handshake.action](handshake);
3291
+ }
3292
+ }
3293
+ };
3294
+ this.runner = this.strategy.connect(0, callback);
3295
+ };
3296
+ ;
3297
+ ConnectionManager.prototype.abortConnecting = function () {
3298
+ if (this.runner) {
3299
+ this.runner.abort();
3300
+ this.runner = null;
3301
+ }
3302
+ };
3303
+ ;
3304
+ ConnectionManager.prototype.disconnectInternally = function () {
3305
+ this.abortConnecting();
3306
+ this.clearRetryTimer();
3307
+ this.clearUnavailableTimer();
3308
+ if (this.connection) {
3309
+ var connection = this.abandonConnection();
3310
+ connection.close();
3311
+ }
3312
+ };
3313
+ ;
3314
+ ConnectionManager.prototype.updateStrategy = function () {
3315
+ this.strategy = this.options.getStrategy({
3316
+ key: this.key,
3317
+ timeline: this.timeline,
3318
+ encrypted: this.encrypted
3319
+ });
3320
+ };
3321
+ ;
3322
+ ConnectionManager.prototype.retryIn = function (delay) {
3323
+ var _this = this;
3324
+ this.timeline.info({ action: "retry", delay: delay });
3325
+ if (delay > 0) {
3326
+ this.emit("connecting_in", Math.round(delay / 1000));
3327
+ }
3328
+ this.retryTimer = new timers_1.OneOffTimer(delay || 0, function () {
3329
+ _this.disconnectInternally();
3330
+ _this.connect();
3331
+ });
3332
+ };
3333
+ ;
3334
+ ConnectionManager.prototype.clearRetryTimer = function () {
3335
+ if (this.retryTimer) {
3336
+ this.retryTimer.ensureAborted();
3337
+ this.retryTimer = null;
3338
+ }
3339
+ };
3340
+ ;
3341
+ ConnectionManager.prototype.setUnavailableTimer = function () {
3342
+ var _this = this;
3343
+ this.unavailableTimer = new timers_1.OneOffTimer(this.options.unavailableTimeout, function () {
3344
+ _this.updateState("unavailable");
3345
+ });
3346
+ };
3347
+ ;
3348
+ ConnectionManager.prototype.clearUnavailableTimer = function () {
3349
+ if (this.unavailableTimer) {
3350
+ this.unavailableTimer.ensureAborted();
3351
+ }
3352
+ };
3353
+ ;
3354
+ ConnectionManager.prototype.sendActivityCheck = function () {
3355
+ var _this = this;
3356
+ this.stopActivityCheck();
3357
+ this.connection.ping();
3358
+ this.activityTimer = new timers_1.OneOffTimer(this.options.pongTimeout, function () {
3359
+ _this.timeline.error({ pong_timed_out: _this.options.pongTimeout });
3360
+ _this.retryIn(0);
3361
+ });
3362
+ };
3363
+ ;
3364
+ ConnectionManager.prototype.resetActivityCheck = function () {
3365
+ var _this = this;
3366
+ this.stopActivityCheck();
3367
+ if (!this.connection.handlesActivityChecks()) {
3368
+ this.activityTimer = new timers_1.OneOffTimer(this.activityTimeout, function () {
3369
+ _this.sendActivityCheck();
3370
+ });
3371
+ }
3372
+ };
3373
+ ;
3374
+ ConnectionManager.prototype.stopActivityCheck = function () {
3375
+ if (this.activityTimer) {
3376
+ this.activityTimer.ensureAborted();
3377
+ }
3378
+ };
3379
+ ;
3380
+ ConnectionManager.prototype.buildConnectionCallbacks = function () {
3381
+ var _this = this;
3382
+ return {
3383
+ message: function (message) {
3384
+ _this.resetActivityCheck();
3385
+ _this.emit('message', message);
3386
+ },
3387
+ ping: function () {
3388
+ _this.send_event('pusher:pong', {});
3389
+ },
3390
+ activity: function () {
3391
+ _this.resetActivityCheck();
3392
+ },
3393
+ error: function (error) {
3394
+ _this.emit("error", { type: "WebSocketError", error: error });
3395
+ },
3396
+ closed: function () {
3397
+ _this.abandonConnection();
3398
+ if (_this.shouldRetry()) {
3399
+ _this.retryIn(1000);
3400
+ }
3401
+ }
3402
+ };
3403
+ };
3404
+ ;
3405
+ ConnectionManager.prototype.buildHandshakeCallbacks = function (errorCallbacks) {
3406
+ var _this = this;
3407
+ return Collections.extend({}, errorCallbacks, {
3408
+ connected: function (handshake) {
3409
+ _this.activityTimeout = Math.min(_this.options.activityTimeout, handshake.activityTimeout, handshake.connection.activityTimeout || Infinity);
3410
+ _this.clearUnavailableTimer();
3411
+ _this.setConnection(handshake.connection);
3412
+ _this.socket_id = _this.connection.id;
3413
+ _this.updateState("connected", { socket_id: _this.socket_id });
3414
+ }
3415
+ });
3416
+ };
3417
+ ;
3418
+ ConnectionManager.prototype.buildErrorCallbacks = function () {
3419
+ var _this = this;
3420
+ var withErrorEmitted = function (callback) {
3421
+ return function (result) {
3422
+ if (result.error) {
3423
+ _this.emit("error", { type: "WebSocketError", error: result.error });
3424
+ }
3425
+ callback(result);
3426
+ };
3427
+ };
3428
+ return {
3429
+ ssl_only: withErrorEmitted(function () {
3430
+ _this.encrypted = true;
3431
+ _this.updateStrategy();
3432
+ _this.retryIn(0);
3433
+ }),
3434
+ refused: withErrorEmitted(function () {
3435
+ _this.disconnect();
3436
+ }),
3437
+ backoff: withErrorEmitted(function () {
3438
+ _this.retryIn(1000);
3439
+ }),
3440
+ retry: withErrorEmitted(function () {
3441
+ _this.retryIn(0);
3442
+ })
3443
+ };
3444
+ };
3445
+ ;
3446
+ ConnectionManager.prototype.setConnection = function (connection) {
3447
+ this.connection = connection;
3448
+ for (var event in this.connectionCallbacks) {
3449
+ this.connection.bind(event, this.connectionCallbacks[event]);
3450
+ }
3451
+ this.resetActivityCheck();
3452
+ };
3453
+ ;
3454
+ ConnectionManager.prototype.abandonConnection = function () {
3455
+ if (!this.connection) {
3456
+ return;
3457
+ }
3458
+ this.stopActivityCheck();
3459
+ for (var event in this.connectionCallbacks) {
3460
+ this.connection.unbind(event, this.connectionCallbacks[event]);
3461
+ }
3462
+ var connection = this.connection;
3463
+ this.connection = null;
3464
+ return connection;
3465
+ };
3466
+ ConnectionManager.prototype.updateState = function (newState, data) {
3467
+ var previousState = this.state;
3468
+ this.state = newState;
3469
+ if (previousState !== newState) {
3470
+ var newStateDescription = newState;
3471
+ if (newStateDescription === "connected") {
3472
+ newStateDescription += " with new socket ID " + data.socket_id;
3473
+ }
3474
+ logger_1["default"].debug('State changed', previousState + ' -> ' + newStateDescription);
3475
+ this.timeline.info({ state: newState, params: data });
3476
+ this.emit('state_change', { previous: previousState, current: newState });
3477
+ this.emit(newState, data);
3478
+ }
3479
+ };
3480
+ ConnectionManager.prototype.shouldRetry = function () {
3481
+ return this.state === "connecting" || this.state === "connected";
3482
+ };
3483
+ return ConnectionManager;
3484
+ }(dispatcher_1["default"]));
3485
+ exports.__esModule = true;
3486
+ exports["default"] = ConnectionManager;
3487
+
3488
+
3489
+ /***/ },
3490
+ /* 54 */
3491
+ /***/ function(module, exports, __webpack_require__) {
3492
+
3493
+ "use strict";
3494
+ var Collections = __webpack_require__(9);
3495
+ var factory_1 = __webpack_require__(42);
3496
+ var Channels = (function () {
3497
+ function Channels() {
3498
+ this.channels = {};
3499
+ }
3500
+ Channels.prototype.add = function (name, pusher) {
3501
+ if (!this.channels[name]) {
3502
+ this.channels[name] = createChannel(name, pusher);
3503
+ }
3504
+ return this.channels[name];
3505
+ };
3506
+ Channels.prototype.all = function () {
3507
+ return Collections.values(this.channels);
3508
+ };
3509
+ Channels.prototype.find = function (name) {
3510
+ return this.channels[name];
3511
+ };
3512
+ Channels.prototype.remove = function (name) {
3513
+ var channel = this.channels[name];
3514
+ delete this.channels[name];
3515
+ return channel;
3516
+ };
3517
+ Channels.prototype.disconnect = function () {
3518
+ Collections.objectApply(this.channels, function (channel) {
3519
+ channel.disconnect();
3520
+ });
3521
+ };
3522
+ return Channels;
3523
+ }());
3524
+ exports.__esModule = true;
3525
+ exports["default"] = Channels;
3526
+ function createChannel(name, pusher) {
3527
+ if (name.indexOf('private-') === 0) {
3528
+ return factory_1["default"].createPrivateChannel(name, pusher);
3529
+ }
3530
+ else if (name.indexOf('presence-') === 0) {
3531
+ return factory_1["default"].createPresenceChannel(name, pusher);
3532
+ }
3533
+ else {
3534
+ return factory_1["default"].createChannel(name, pusher);
3535
+ }
3536
+ }
3537
+
3538
+
3539
+ /***/ },
3540
+ /* 55 */
3541
+ /***/ function(module, exports, __webpack_require__) {
3542
+
3543
+ "use strict";
3544
+ var factory_1 = __webpack_require__(42);
3545
+ var util_1 = __webpack_require__(11);
3546
+ var Errors = __webpack_require__(30);
3547
+ var Collections = __webpack_require__(9);
3548
+ var TransportStrategy = (function () {
3549
+ function TransportStrategy(name, priority, transport, options) {
3550
+ this.name = name;
3551
+ this.priority = priority;
3552
+ this.transport = transport;
3553
+ this.options = options || {};
3554
+ }
3555
+ TransportStrategy.prototype.isSupported = function () {
3556
+ return this.transport.isSupported({
3557
+ encrypted: this.options.encrypted
3558
+ });
3559
+ };
3560
+ TransportStrategy.prototype.connect = function (minPriority, callback) {
3561
+ var _this = this;
3562
+ if (!this.isSupported()) {
3563
+ return failAttempt(new Errors.UnsupportedStrategy(), callback);
3564
+ }
3565
+ else if (this.priority < minPriority) {
3566
+ return failAttempt(new Errors.TransportPriorityTooLow(), callback);
3567
+ }
3568
+ var connected = false;
3569
+ var transport = this.transport.createConnection(this.name, this.priority, this.options.key, this.options);
3570
+ var handshake = null;
3571
+ var onInitialized = function () {
3572
+ transport.unbind("initialized", onInitialized);
3573
+ transport.connect();
3574
+ };
3575
+ var onOpen = function () {
3576
+ handshake = factory_1["default"].createHandshake(transport, function (result) {
3577
+ connected = true;
3578
+ unbindListeners();
3579
+ callback(null, result);
3580
+ });
3581
+ };
3582
+ var onError = function (error) {
3583
+ unbindListeners();
3584
+ callback(error);
3585
+ };
3586
+ var onClosed = function () {
3587
+ unbindListeners();
3588
+ var serializedTransport;
3589
+ try {
3590
+ serializedTransport = JSON.stringify(transport);
3591
+ }
3592
+ catch (e) {
3593
+ serializedTransport = Collections.safeJSONStringify(transport);
3594
+ }
3595
+ callback(new Errors.TransportClosed(serializedTransport));
3596
+ };
3597
+ var unbindListeners = function () {
3598
+ transport.unbind("initialized", onInitialized);
3599
+ transport.unbind("open", onOpen);
3600
+ transport.unbind("error", onError);
3601
+ transport.unbind("closed", onClosed);
3602
+ };
3603
+ transport.bind("initialized", onInitialized);
3604
+ transport.bind("open", onOpen);
3605
+ transport.bind("error", onError);
3606
+ transport.bind("closed", onClosed);
3607
+ transport.initialize();
3608
+ return {
3609
+ abort: function () {
3610
+ if (connected) {
3611
+ return;
3612
+ }
3613
+ unbindListeners();
3614
+ if (handshake) {
3615
+ handshake.close();
3616
+ }
3617
+ else {
3618
+ transport.close();
3619
+ }
3620
+ },
3621
+ forceMinPriority: function (p) {
3622
+ if (connected) {
3623
+ return;
3624
+ }
3625
+ if (_this.priority < p) {
3626
+ if (handshake) {
3627
+ handshake.close();
3628
+ }
3629
+ else {
3630
+ transport.close();
3631
+ }
3632
+ }
3633
+ }
3634
+ };
3635
+ };
3636
+ return TransportStrategy;
3637
+ }());
3638
+ exports.__esModule = true;
3639
+ exports["default"] = TransportStrategy;
3640
+ function failAttempt(error, callback) {
3641
+ util_1["default"].defer(function () {
3642
+ callback(error);
3643
+ });
3644
+ return {
3645
+ abort: function () { },
3646
+ forceMinPriority: function () { }
3647
+ };
3648
+ }
3649
+
3650
+
3651
+ /***/ },
3652
+ /* 56 */
3653
+ /***/ function(module, exports, __webpack_require__) {
3654
+
3655
+ "use strict";
3656
+ var Collections = __webpack_require__(9);
3657
+ var util_1 = __webpack_require__(11);
3658
+ var timers_1 = __webpack_require__(12);
3659
+ var SequentialStrategy = (function () {
3660
+ function SequentialStrategy(strategies, options) {
3661
+ this.strategies = strategies;
3662
+ this.loop = Boolean(options.loop);
3663
+ this.failFast = Boolean(options.failFast);
3664
+ this.timeout = options.timeout;
3665
+ this.timeoutLimit = options.timeoutLimit;
3666
+ }
3667
+ SequentialStrategy.prototype.isSupported = function () {
3668
+ return Collections.any(this.strategies, util_1["default"].method("isSupported"));
3669
+ };
3670
+ SequentialStrategy.prototype.connect = function (minPriority, callback) {
3671
+ var _this = this;
3672
+ var strategies = this.strategies;
3673
+ var current = 0;
3674
+ var timeout = this.timeout;
3675
+ var runner = null;
3676
+ var tryNextStrategy = function (error, handshake) {
3677
+ if (handshake) {
3678
+ callback(null, handshake);
3679
+ }
3680
+ else {
3681
+ current = current + 1;
3682
+ if (_this.loop) {
3683
+ current = current % strategies.length;
3684
+ }
3685
+ if (current < strategies.length) {
3686
+ if (timeout) {
3687
+ timeout = timeout * 2;
3688
+ if (_this.timeoutLimit) {
3689
+ timeout = Math.min(timeout, _this.timeoutLimit);
3690
+ }
3691
+ }
3692
+ runner = _this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: _this.failFast }, tryNextStrategy);
3693
+ }
3694
+ else {
3695
+ callback(true);
3696
+ }
3697
+ }
3698
+ };
3699
+ runner = this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: this.failFast }, tryNextStrategy);
3700
+ return {
3701
+ abort: function () {
3702
+ runner.abort();
3703
+ },
3704
+ forceMinPriority: function (p) {
3705
+ minPriority = p;
3706
+ if (runner) {
3707
+ runner.forceMinPriority(p);
3708
+ }
3709
+ }
3710
+ };
3711
+ };
3712
+ SequentialStrategy.prototype.tryStrategy = function (strategy, minPriority, options, callback) {
3713
+ var timer = null;
3714
+ var runner = null;
3715
+ if (options.timeout > 0) {
3716
+ timer = new timers_1.OneOffTimer(options.timeout, function () {
3717
+ runner.abort();
3718
+ callback(true);
3719
+ });
3720
+ }
3721
+ runner = strategy.connect(minPriority, function (error, handshake) {
3722
+ if (error && timer && timer.isRunning() && !options.failFast) {
3723
+ return;
3724
+ }
3725
+ if (timer) {
3726
+ timer.ensureAborted();
3727
+ }
3728
+ callback(error, handshake);
3729
+ });
3730
+ return {
3731
+ abort: function () {
3732
+ if (timer) {
3733
+ timer.ensureAborted();
3734
+ }
3735
+ runner.abort();
3736
+ },
3737
+ forceMinPriority: function (p) {
3738
+ runner.forceMinPriority(p);
3739
+ }
3740
+ };
3741
+ };
3742
+ return SequentialStrategy;
3743
+ }());
3744
+ exports.__esModule = true;
3745
+ exports["default"] = SequentialStrategy;
3746
+
3747
+
3748
+ /***/ },
3749
+ /* 57 */
3750
+ /***/ function(module, exports, __webpack_require__) {
3751
+
3752
+ "use strict";
3753
+ var Collections = __webpack_require__(9);
3754
+ var util_1 = __webpack_require__(11);
3755
+ var BestConnectedEverStrategy = (function () {
3756
+ function BestConnectedEverStrategy(strategies) {
3757
+ this.strategies = strategies;
3758
+ }
3759
+ BestConnectedEverStrategy.prototype.isSupported = function () {
3760
+ return Collections.any(this.strategies, util_1["default"].method("isSupported"));
3761
+ };
3762
+ BestConnectedEverStrategy.prototype.connect = function (minPriority, callback) {
3763
+ return connect(this.strategies, minPriority, function (i, runners) {
3764
+ return function (error, handshake) {
3765
+ runners[i].error = error;
3766
+ if (error) {
3767
+ if (allRunnersFailed(runners)) {
3768
+ callback(true);
3769
+ }
3770
+ return;
3771
+ }
3772
+ Collections.apply(runners, function (runner) {
3773
+ runner.forceMinPriority(handshake.transport.priority);
3774
+ });
3775
+ callback(null, handshake);
3776
+ };
3777
+ });
3778
+ };
3779
+ return BestConnectedEverStrategy;
3780
+ }());
3781
+ exports.__esModule = true;
3782
+ exports["default"] = BestConnectedEverStrategy;
3783
+ function connect(strategies, minPriority, callbackBuilder) {
3784
+ var runners = Collections.map(strategies, function (strategy, i, _, rs) {
3785
+ return strategy.connect(minPriority, callbackBuilder(i, rs));
3786
+ });
3787
+ return {
3788
+ abort: function () {
3789
+ Collections.apply(runners, abortRunner);
3790
+ },
3791
+ forceMinPriority: function (p) {
3792
+ Collections.apply(runners, function (runner) {
3793
+ runner.forceMinPriority(p);
3794
+ });
3795
+ }
3796
+ };
3797
+ }
3798
+ function allRunnersFailed(runners) {
3799
+ return Collections.all(runners, function (runner) {
3800
+ return Boolean(runner.error);
3801
+ });
3802
+ }
3803
+ function abortRunner(runner) {
3804
+ if (!runner.error && !runner.aborted) {
3805
+ runner.abort();
3806
+ runner.aborted = true;
3807
+ }
3808
+ }
3809
+
3810
+
3811
+ /***/ },
3812
+ /* 58 */
3813
+ /***/ function(module, exports, __webpack_require__) {
3814
+
3815
+ "use strict";
3816
+ var util_1 = __webpack_require__(11);
3817
+ var runtime_1 = __webpack_require__(2);
3818
+ var sequential_strategy_1 = __webpack_require__(56);
3819
+ var CachedStrategy = (function () {
3820
+ function CachedStrategy(strategy, transports, options) {
3821
+ this.strategy = strategy;
3822
+ this.transports = transports;
3823
+ this.ttl = options.ttl || 1800 * 1000;
3824
+ this.encrypted = options.encrypted;
3825
+ this.timeline = options.timeline;
3826
+ }
3827
+ CachedStrategy.prototype.isSupported = function () {
3828
+ return this.strategy.isSupported();
3829
+ };
3830
+ CachedStrategy.prototype.connect = function (minPriority, callback) {
3831
+ var encrypted = this.encrypted;
3832
+ var info = fetchTransportCache(encrypted);
3833
+ var strategies = [this.strategy];
3834
+ if (info && info.timestamp + this.ttl >= util_1["default"].now()) {
3835
+ var transport = this.transports[info.transport];
3836
+ if (transport) {
3837
+ this.timeline.info({
3838
+ cached: true,
3839
+ transport: info.transport,
3840
+ latency: info.latency
3841
+ });
3842
+ strategies.push(new sequential_strategy_1["default"]([transport], {
3843
+ timeout: info.latency * 2 + 1000,
3844
+ failFast: true
3845
+ }));
3846
+ }
3847
+ }
3848
+ var startTimestamp = util_1["default"].now();
3849
+ var runner = strategies.pop().connect(minPriority, function cb(error, handshake) {
3850
+ if (error) {
3851
+ flushTransportCache(encrypted);
3852
+ if (strategies.length > 0) {
3853
+ startTimestamp = util_1["default"].now();
3854
+ runner = strategies.pop().connect(minPriority, cb);
3855
+ }
3856
+ else {
3857
+ callback(error);
3858
+ }
3859
+ }
3860
+ else {
3861
+ storeTransportCache(encrypted, handshake.transport.name, util_1["default"].now() - startTimestamp);
3862
+ callback(null, handshake);
3863
+ }
3864
+ });
3865
+ return {
3866
+ abort: function () {
3867
+ runner.abort();
3868
+ },
3869
+ forceMinPriority: function (p) {
3870
+ minPriority = p;
3871
+ if (runner) {
3872
+ runner.forceMinPriority(p);
3873
+ }
3874
+ }
3875
+ };
3876
+ };
3877
+ return CachedStrategy;
3878
+ }());
3879
+ exports.__esModule = true;
3880
+ exports["default"] = CachedStrategy;
3881
+ function getTransportCacheKey(encrypted) {
3882
+ return "pusherTransport" + (encrypted ? "Encrypted" : "Unencrypted");
3883
+ }
3884
+ function fetchTransportCache(encrypted) {
3885
+ var storage = runtime_1["default"].getLocalStorage();
3886
+ if (storage) {
3887
+ try {
3888
+ var serializedCache = storage[getTransportCacheKey(encrypted)];
3889
+ if (serializedCache) {
3890
+ return JSON.parse(serializedCache);
3891
+ }
3892
+ }
3893
+ catch (e) {
3894
+ flushTransportCache(encrypted);
3895
+ }
3896
+ }
3897
+ return null;
3898
+ }
3899
+ function storeTransportCache(encrypted, transport, latency) {
3900
+ var storage = runtime_1["default"].getLocalStorage();
3901
+ if (storage) {
3902
+ try {
3903
+ storage[getTransportCacheKey(encrypted)] = JSON.stringify({
3904
+ timestamp: util_1["default"].now(),
3905
+ transport: transport,
3906
+ latency: latency
3907
+ });
3908
+ }
3909
+ catch (e) {
3910
+ }
3911
+ }
3912
+ }
3913
+ function flushTransportCache(encrypted) {
3914
+ var storage = runtime_1["default"].getLocalStorage();
3915
+ if (storage) {
3916
+ try {
3917
+ delete storage[getTransportCacheKey(encrypted)];
3918
+ }
3919
+ catch (e) {
3920
+ }
3921
+ }
3922
+ }
3923
+
3924
+
3925
+ /***/ },
3926
+ /* 59 */
3927
+ /***/ function(module, exports, __webpack_require__) {
3928
+
3929
+ "use strict";
3930
+ var timers_1 = __webpack_require__(12);
3931
+ var DelayedStrategy = (function () {
3932
+ function DelayedStrategy(strategy, _a) {
3933
+ var number = _a.delay;
3934
+ this.strategy = strategy;
3935
+ this.options = { delay: number };
3936
+ }
3937
+ DelayedStrategy.prototype.isSupported = function () {
3938
+ return this.strategy.isSupported();
3939
+ };
3940
+ DelayedStrategy.prototype.connect = function (minPriority, callback) {
3941
+ var strategy = this.strategy;
3942
+ var runner;
3943
+ var timer = new timers_1.OneOffTimer(this.options.delay, function () {
3944
+ runner = strategy.connect(minPriority, callback);
3945
+ });
3946
+ return {
3947
+ abort: function () {
3948
+ timer.ensureAborted();
3949
+ if (runner) {
3950
+ runner.abort();
3951
+ }
3952
+ },
3953
+ forceMinPriority: function (p) {
3954
+ minPriority = p;
3955
+ if (runner) {
3956
+ runner.forceMinPriority(p);
3957
+ }
3958
+ }
3959
+ };
3960
+ };
3961
+ return DelayedStrategy;
3962
+ }());
3963
+ exports.__esModule = true;
3964
+ exports["default"] = DelayedStrategy;
3965
+
3966
+
3967
+ /***/ },
3968
+ /* 60 */
3969
+ /***/ function(module, exports) {
3970
+
3971
+ "use strict";
3972
+ var IfStrategy = (function () {
3973
+ function IfStrategy(test, trueBranch, falseBranch) {
3974
+ this.test = test;
3975
+ this.trueBranch = trueBranch;
3976
+ this.falseBranch = falseBranch;
3977
+ }
3978
+ IfStrategy.prototype.isSupported = function () {
3979
+ var branch = this.test() ? this.trueBranch : this.falseBranch;
3980
+ return branch.isSupported();
3981
+ };
3982
+ IfStrategy.prototype.connect = function (minPriority, callback) {
3983
+ var branch = this.test() ? this.trueBranch : this.falseBranch;
3984
+ return branch.connect(minPriority, callback);
3985
+ };
3986
+ return IfStrategy;
3987
+ }());
3988
+ exports.__esModule = true;
3989
+ exports["default"] = IfStrategy;
3990
+
3991
+
3992
+ /***/ },
3993
+ /* 61 */
3994
+ /***/ function(module, exports) {
3995
+
3996
+ "use strict";
3997
+ var FirstConnectedStrategy = (function () {
3998
+ function FirstConnectedStrategy(strategy) {
3999
+ this.strategy = strategy;
4000
+ }
4001
+ FirstConnectedStrategy.prototype.isSupported = function () {
4002
+ return this.strategy.isSupported();
4003
+ };
4004
+ FirstConnectedStrategy.prototype.connect = function (minPriority, callback) {
4005
+ var runner = this.strategy.connect(minPriority, function (error, handshake) {
4006
+ if (handshake) {
4007
+ runner.abort();
4008
+ }
4009
+ callback(error, handshake);
4010
+ });
4011
+ return runner;
4012
+ };
4013
+ return FirstConnectedStrategy;
4014
+ }());
4015
+ exports.__esModule = true;
4016
+ exports["default"] = FirstConnectedStrategy;
4017
+
4018
+
4019
+ /***/ },
4020
+ /* 62 */
4021
+ /***/ function(module, exports, __webpack_require__) {
4022
+
4023
+ "use strict";
4024
+ var defaults_1 = __webpack_require__(5);
4025
+ exports.getGlobalConfig = function () {
4026
+ return {
4027
+ wsHost: defaults_1["default"].host,
4028
+ wsPort: defaults_1["default"].ws_port,
4029
+ wssPort: defaults_1["default"].wss_port,
4030
+ httpHost: defaults_1["default"].sockjs_host,
4031
+ httpPort: defaults_1["default"].sockjs_http_port,
4032
+ httpsPort: defaults_1["default"].sockjs_https_port,
4033
+ httpPath: defaults_1["default"].sockjs_path,
4034
+ statsHost: defaults_1["default"].stats_host,
4035
+ authEndpoint: defaults_1["default"].channel_auth_endpoint,
4036
+ authTransport: defaults_1["default"].channel_auth_transport,
4037
+ activity_timeout: defaults_1["default"].activity_timeout,
4038
+ pong_timeout: defaults_1["default"].pong_timeout,
4039
+ unavailable_timeout: defaults_1["default"].unavailable_timeout
4040
+ };
4041
+ };
4042
+ exports.getClusterConfig = function (clusterName) {
4043
+ return {
4044
+ wsHost: "ws-" + clusterName + ".pusher.com",
4045
+ httpHost: "sockjs-" + clusterName + ".pusher.com"
4046
+ };
4047
+ };
4048
+
4049
+
4050
+ /***/ }
4051
+ /******/ ])
4052
+ });