pusher-fake 3.0.1 → 4.2.0

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