pusher-fake 4.1.0 → 4.2.0

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