-
Notifications
You must be signed in to change notification settings - Fork 371
/
pusher.js
4993 lines (4722 loc) · 170 KB
/
pusher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* Pusher JavaScript Library v7.6.0
* https://pusher.com/
*
* Copyright 2020, Pusher
* Released under the MIT licence.
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["Pusher"] = factory();
else
root["Pusher"] = factory();
})(window, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
// Copyright (C) 2016 Dmitry Chestnykh
// MIT License. See LICENSE file for details.
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Package base64 implements Base64 encoding and decoding.
*/
// Invalid character used in decoding to indicate
// that the character to decode is out of range of
// alphabet and cannot be decoded.
var INVALID_BYTE = 256;
/**
* Implements standard Base64 encoding.
*
* Operates in constant time.
*/
var Coder = /** @class */ (function () {
// TODO(dchest): methods to encode chunk-by-chunk.
function Coder(_paddingCharacter) {
if (_paddingCharacter === void 0) { _paddingCharacter = "="; }
this._paddingCharacter = _paddingCharacter;
}
Coder.prototype.encodedLength = function (length) {
if (!this._paddingCharacter) {
return (length * 8 + 5) / 6 | 0;
}
return (length + 2) / 3 * 4 | 0;
};
Coder.prototype.encode = function (data) {
var out = "";
var i = 0;
for (; i < data.length - 2; i += 3) {
var c = (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]);
out += this._encodeByte((c >>> 3 * 6) & 63);
out += this._encodeByte((c >>> 2 * 6) & 63);
out += this._encodeByte((c >>> 1 * 6) & 63);
out += this._encodeByte((c >>> 0 * 6) & 63);
}
var left = data.length - i;
if (left > 0) {
var c = (data[i] << 16) | (left === 2 ? data[i + 1] << 8 : 0);
out += this._encodeByte((c >>> 3 * 6) & 63);
out += this._encodeByte((c >>> 2 * 6) & 63);
if (left === 2) {
out += this._encodeByte((c >>> 1 * 6) & 63);
}
else {
out += this._paddingCharacter || "";
}
out += this._paddingCharacter || "";
}
return out;
};
Coder.prototype.maxDecodedLength = function (length) {
if (!this._paddingCharacter) {
return (length * 6 + 7) / 8 | 0;
}
return length / 4 * 3 | 0;
};
Coder.prototype.decodedLength = function (s) {
return this.maxDecodedLength(s.length - this._getPaddingLength(s));
};
Coder.prototype.decode = function (s) {
if (s.length === 0) {
return new Uint8Array(0);
}
var paddingLength = this._getPaddingLength(s);
var length = s.length - paddingLength;
var out = new Uint8Array(this.maxDecodedLength(length));
var op = 0;
var i = 0;
var haveBad = 0;
var v0 = 0, v1 = 0, v2 = 0, v3 = 0;
for (; i < length - 4; i += 4) {
v0 = this._decodeChar(s.charCodeAt(i + 0));
v1 = this._decodeChar(s.charCodeAt(i + 1));
v2 = this._decodeChar(s.charCodeAt(i + 2));
v3 = this._decodeChar(s.charCodeAt(i + 3));
out[op++] = (v0 << 2) | (v1 >>> 4);
out[op++] = (v1 << 4) | (v2 >>> 2);
out[op++] = (v2 << 6) | v3;
haveBad |= v0 & INVALID_BYTE;
haveBad |= v1 & INVALID_BYTE;
haveBad |= v2 & INVALID_BYTE;
haveBad |= v3 & INVALID_BYTE;
}
if (i < length - 1) {
v0 = this._decodeChar(s.charCodeAt(i));
v1 = this._decodeChar(s.charCodeAt(i + 1));
out[op++] = (v0 << 2) | (v1 >>> 4);
haveBad |= v0 & INVALID_BYTE;
haveBad |= v1 & INVALID_BYTE;
}
if (i < length - 2) {
v2 = this._decodeChar(s.charCodeAt(i + 2));
out[op++] = (v1 << 4) | (v2 >>> 2);
haveBad |= v2 & INVALID_BYTE;
}
if (i < length - 3) {
v3 = this._decodeChar(s.charCodeAt(i + 3));
out[op++] = (v2 << 6) | v3;
haveBad |= v3 & INVALID_BYTE;
}
if (haveBad !== 0) {
throw new Error("Base64Coder: incorrect characters for decoding");
}
return out;
};
// Standard encoding have the following encoded/decoded ranges,
// which we need to convert between.
//
// ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 + /
// Index: 0 - 25 26 - 51 52 - 61 62 63
// ASCII: 65 - 90 97 - 122 48 - 57 43 47
//
// Encode 6 bits in b into a new character.
Coder.prototype._encodeByte = function (b) {
// Encoding uses constant time operations as follows:
//
// 1. Define comparison of A with B using (A - B) >>> 8:
// if A > B, then result is positive integer
// if A <= B, then result is 0
//
// 2. Define selection of C or 0 using bitwise AND: X & C:
// if X == 0, then result is 0
// if X != 0, then result is C
//
// 3. Start with the smallest comparison (b >= 0), which is always
// true, so set the result to the starting ASCII value (65).
//
// 4. Continue comparing b to higher ASCII values, and selecting
// zero if comparison isn't true, otherwise selecting a value
// to add to result, which:
//
// a) undoes the previous addition
// b) provides new value to add
//
var result = b;
// b >= 0
result += 65;
// b > 25
result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97);
// b > 51
result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48);
// b > 61
result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 43);
// b > 62
result += ((62 - b) >>> 8) & ((62 - 43) - 63 + 47);
return String.fromCharCode(result);
};
// Decode a character code into a byte.
// Must return 256 if character is out of alphabet range.
Coder.prototype._decodeChar = function (c) {
// Decoding works similar to encoding: using the same comparison
// function, but now it works on ranges: result is always incremented
// by value, but this value becomes zero if the range is not
// satisfied.
//
// Decoding starts with invalid value, 256, which is then
// subtracted when the range is satisfied. If none of the ranges
// apply, the function returns 256, which is then checked by
// the caller to throw error.
var result = INVALID_BYTE; // start with invalid character
// c == 43 (c > 42 and c < 44)
result += (((42 - c) & (c - 44)) >>> 8) & (-INVALID_BYTE + c - 43 + 62);
// c == 47 (c > 46 and c < 48)
result += (((46 - c) & (c - 48)) >>> 8) & (-INVALID_BYTE + c - 47 + 63);
// c > 47 and c < 58
result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52);
// c > 64 and c < 91
result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0);
// c > 96 and c < 123
result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26);
return result;
};
Coder.prototype._getPaddingLength = function (s) {
var paddingLength = 0;
if (this._paddingCharacter) {
for (var i = s.length - 1; i >= 0; i--) {
if (s[i] !== this._paddingCharacter) {
break;
}
paddingLength++;
}
if (s.length < 4 || paddingLength > 2) {
throw new Error("Base64Coder: incorrect padding");
}
}
return paddingLength;
};
return Coder;
}());
exports.Coder = Coder;
var stdCoder = new Coder();
function encode(data) {
return stdCoder.encode(data);
}
exports.encode = encode;
function decode(s) {
return stdCoder.decode(s);
}
exports.decode = decode;
/**
* Implements URL-safe Base64 encoding.
* (Same as Base64, but '+' is replaced with '-', and '/' with '_').
*
* Operates in constant time.
*/
var URLSafeCoder = /** @class */ (function (_super) {
__extends(URLSafeCoder, _super);
function URLSafeCoder() {
return _super !== null && _super.apply(this, arguments) || this;
}
// URL-safe encoding have the following encoded/decoded ranges:
//
// ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 - _
// Index: 0 - 25 26 - 51 52 - 61 62 63
// ASCII: 65 - 90 97 - 122 48 - 57 45 95
//
URLSafeCoder.prototype._encodeByte = function (b) {
var result = b;
// b >= 0
result += 65;
// b > 25
result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97);
// b > 51
result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48);
// b > 61
result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 45);
// b > 62
result += ((62 - b) >>> 8) & ((62 - 45) - 63 + 95);
return String.fromCharCode(result);
};
URLSafeCoder.prototype._decodeChar = function (c) {
var result = INVALID_BYTE;
// c == 45 (c > 44 and c < 46)
result += (((44 - c) & (c - 46)) >>> 8) & (-INVALID_BYTE + c - 45 + 62);
// c == 95 (c > 94 and c < 96)
result += (((94 - c) & (c - 96)) >>> 8) & (-INVALID_BYTE + c - 95 + 63);
// c > 47 and c < 58
result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52);
// c > 64 and c < 91
result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0);
// c > 96 and c < 123
result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26);
return result;
};
return URLSafeCoder;
}(Coder));
exports.URLSafeCoder = URLSafeCoder;
var urlSafeCoder = new URLSafeCoder();
function encodeURLSafe(data) {
return urlSafeCoder.encode(data);
}
exports.encodeURLSafe = encodeURLSafe;
function decodeURLSafe(s) {
return urlSafeCoder.decode(s);
}
exports.decodeURLSafe = decodeURLSafe;
exports.encodedLength = function (length) {
return stdCoder.encodedLength(length);
};
exports.maxDecodedLength = function (length) {
return stdCoder.maxDecodedLength(length);
};
exports.decodedLength = function (s) {
return stdCoder.decodedLength(s);
};
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
// Copyright (C) 2016 Dmitry Chestnykh
// MIT License. See LICENSE file for details.
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Package utf8 implements UTF-8 encoding and decoding.
*/
var INVALID_UTF16 = "utf8: invalid string";
var INVALID_UTF8 = "utf8: invalid source encoding";
/**
* Encodes the given string into UTF-8 byte array.
* Throws if the source string has invalid UTF-16 encoding.
*/
function encode(s) {
// Calculate result length and allocate output array.
// encodedLength() also validates string and throws errors,
// so we don't need repeat validation here.
var arr = new Uint8Array(encodedLength(s));
var pos = 0;
for (var i = 0; i < s.length; i++) {
var c = s.charCodeAt(i);
if (c < 0x80) {
arr[pos++] = c;
}
else if (c < 0x800) {
arr[pos++] = 0xc0 | c >> 6;
arr[pos++] = 0x80 | c & 0x3f;
}
else if (c < 0xd800) {
arr[pos++] = 0xe0 | c >> 12;
arr[pos++] = 0x80 | (c >> 6) & 0x3f;
arr[pos++] = 0x80 | c & 0x3f;
}
else {
i++; // get one more character
c = (c & 0x3ff) << 10;
c |= s.charCodeAt(i) & 0x3ff;
c += 0x10000;
arr[pos++] = 0xf0 | c >> 18;
arr[pos++] = 0x80 | (c >> 12) & 0x3f;
arr[pos++] = 0x80 | (c >> 6) & 0x3f;
arr[pos++] = 0x80 | c & 0x3f;
}
}
return arr;
}
exports.encode = encode;
/**
* Returns the number of bytes required to encode the given string into UTF-8.
* Throws if the source string has invalid UTF-16 encoding.
*/
function encodedLength(s) {
var result = 0;
for (var i = 0; i < s.length; i++) {
var c = s.charCodeAt(i);
if (c < 0x80) {
result += 1;
}
else if (c < 0x800) {
result += 2;
}
else if (c < 0xd800) {
result += 3;
}
else if (c <= 0xdfff) {
if (i >= s.length - 1) {
throw new Error(INVALID_UTF16);
}
i++; // "eat" next character
result += 4;
}
else {
throw new Error(INVALID_UTF16);
}
}
return result;
}
exports.encodedLength = encodedLength;
/**
* Decodes the given byte array from UTF-8 into a string.
* Throws if encoding is invalid.
*/
function decode(arr) {
var chars = [];
for (var i = 0; i < arr.length; i++) {
var b = arr[i];
if (b & 0x80) {
var min = void 0;
if (b < 0xe0) {
// Need 1 more byte.
if (i >= arr.length) {
throw new Error(INVALID_UTF8);
}
var n1 = arr[++i];
if ((n1 & 0xc0) !== 0x80) {
throw new Error(INVALID_UTF8);
}
b = (b & 0x1f) << 6 | (n1 & 0x3f);
min = 0x80;
}
else if (b < 0xf0) {
// Need 2 more bytes.
if (i >= arr.length - 1) {
throw new Error(INVALID_UTF8);
}
var n1 = arr[++i];
var n2 = arr[++i];
if ((n1 & 0xc0) !== 0x80 || (n2 & 0xc0) !== 0x80) {
throw new Error(INVALID_UTF8);
}
b = (b & 0x0f) << 12 | (n1 & 0x3f) << 6 | (n2 & 0x3f);
min = 0x800;
}
else if (b < 0xf8) {
// Need 3 more bytes.
if (i >= arr.length - 2) {
throw new Error(INVALID_UTF8);
}
var n1 = arr[++i];
var n2 = arr[++i];
var n3 = arr[++i];
if ((n1 & 0xc0) !== 0x80 || (n2 & 0xc0) !== 0x80 || (n3 & 0xc0) !== 0x80) {
throw new Error(INVALID_UTF8);
}
b = (b & 0x0f) << 18 | (n1 & 0x3f) << 12 | (n2 & 0x3f) << 6 | (n3 & 0x3f);
min = 0x10000;
}
else {
throw new Error(INVALID_UTF8);
}
if (b < min || (b >= 0xd800 && b <= 0xdfff)) {
throw new Error(INVALID_UTF8);
}
if (b >= 0x10000) {
// Surrogate pair.
if (b > 0x10ffff) {
throw new Error(INVALID_UTF8);
}
b -= 0x10000;
chars.push(String.fromCharCode(0xd800 | (b >> 10)));
b = 0xdc00 | (b & 0x3ff);
}
}
chars.push(String.fromCharCode(b));
}
return chars.join("");
}
exports.decode = decode;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
// required so we don't have to do require('pusher').default etc.
module.exports = __webpack_require__(3).default;
/***/ }),
/* 3 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// CONCATENATED MODULE: ./src/runtimes/web/dom/script_receiver_factory.ts
var ScriptReceiverFactory = (function () {
function ScriptReceiverFactory(prefix, name) {
this.lastId = 0;
this.prefix = prefix;
this.name = name;
}
ScriptReceiverFactory.prototype.create = function (callback) {
this.lastId++;
var number = this.lastId;
var id = this.prefix + number;
var name = this.name + '[' + number + ']';
var called = false;
var callbackWrapper = function () {
if (!called) {
callback.apply(null, arguments);
called = true;
}
};
this[number] = callbackWrapper;
return { number: number, id: id, name: name, callback: callbackWrapper };
};
ScriptReceiverFactory.prototype.remove = function (receiver) {
delete this[receiver.number];
};
return ScriptReceiverFactory;
}());
var ScriptReceivers = new ScriptReceiverFactory('_pusher_script_', 'Pusher.ScriptReceivers');
// CONCATENATED MODULE: ./src/core/defaults.ts
var Defaults = {
VERSION: "7.6.0",
PROTOCOL: 7,
wsPort: 80,
wssPort: 443,
wsPath: '',
httpHost: 'sockjs.pusher.com',
httpPort: 80,
httpsPort: 443,
httpPath: '/pusher',
stats_host: 'stats.pusher.com',
authEndpoint: '/pusher/auth',
authTransport: 'ajax',
activityTimeout: 120000,
pongTimeout: 30000,
unavailableTimeout: 10000,
cluster: 'mt1',
userAuthentication: {
endpoint: '/pusher/user-auth',
transport: 'ajax'
},
channelAuthorization: {
endpoint: '/pusher/auth',
transport: 'ajax'
},
cdn_http: "http://js.pusher.com",
cdn_https: "https://js.pusher.com",
dependency_suffix: ""
};
/* harmony default export */ var defaults = (Defaults);
// CONCATENATED MODULE: ./src/runtimes/web/dom/dependency_loader.ts
var dependency_loader_DependencyLoader = (function () {
function DependencyLoader(options) {
this.options = options;
this.receivers = options.receivers || ScriptReceivers;
this.loading = {};
}
DependencyLoader.prototype.load = function (name, options, callback) {
var self = this;
if (self.loading[name] && self.loading[name].length > 0) {
self.loading[name].push(callback);
}
else {
self.loading[name] = [callback];
var request = runtime.createScriptRequest(self.getPath(name, options));
var receiver = self.receivers.create(function (error) {
self.receivers.remove(receiver);
if (self.loading[name]) {
var callbacks = self.loading[name];
delete self.loading[name];
var successCallback = function (wasSuccessful) {
if (!wasSuccessful) {
request.cleanup();
}
};
for (var i = 0; i < callbacks.length; i++) {
callbacks[i](error, successCallback);
}
}
});
request.send(receiver);
}
};
DependencyLoader.prototype.getRoot = function (options) {
var cdn;
var protocol = runtime.getDocument().location.protocol;
if ((options && options.useTLS) || protocol === 'https:') {
cdn = this.options.cdn_https;
}
else {
cdn = this.options.cdn_http;
}
return cdn.replace(/\/*$/, '') + '/' + this.options.version;
};
DependencyLoader.prototype.getPath = function (name, options) {
return this.getRoot(options) + '/' + name + this.options.suffix + '.js';
};
return DependencyLoader;
}());
/* harmony default export */ var dependency_loader = (dependency_loader_DependencyLoader);
// CONCATENATED MODULE: ./src/runtimes/web/dom/dependencies.ts
var DependenciesReceivers = new ScriptReceiverFactory('_pusher_dependencies', 'Pusher.DependenciesReceivers');
var Dependencies = new dependency_loader({
cdn_http: defaults.cdn_http,
cdn_https: defaults.cdn_https,
version: defaults.VERSION,
suffix: defaults.dependency_suffix,
receivers: DependenciesReceivers
});
// CONCATENATED MODULE: ./src/core/utils/url_store.ts
var urlStore = {
baseUrl: 'https://pusher.com',
urls: {
authenticationEndpoint: {
path: '/docs/channels/server_api/authenticating_users'
},
authorizationEndpoint: {
path: '/docs/channels/server_api/authorizing-users/'
},
javascriptQuickStart: {
path: '/docs/javascript_quick_start'
},
triggeringClientEvents: {
path: '/docs/client_api_guide/client_events#trigger-events'
},
encryptedChannelSupport: {
fullUrl: 'https://github.com/pusher/pusher-js/tree/cc491015371a4bde5743d1c87a0fbac0feb53195#encrypted-channel-support'
}
}
};
var buildLogSuffix = function (key) {
var urlPrefix = 'See:';
var urlObj = urlStore.urls[key];
if (!urlObj)
return '';
var url;
if (urlObj.fullUrl) {
url = urlObj.fullUrl;
}
else if (urlObj.path) {
url = urlStore.baseUrl + urlObj.path;
}
if (!url)
return '';
return urlPrefix + " " + url;
};
/* harmony default export */ var url_store = ({ buildLogSuffix: buildLogSuffix });
// CONCATENATED MODULE: ./src/core/auth/options.ts
var AuthRequestType;
(function (AuthRequestType) {
AuthRequestType["UserAuthentication"] = "user-authentication";
AuthRequestType["ChannelAuthorization"] = "channel-authorization";
})(AuthRequestType || (AuthRequestType = {}));
// CONCATENATED MODULE: ./src/core/errors.ts
var __extends = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var BadEventName = (function (_super) {
__extends(BadEventName, _super);
function BadEventName(msg) {
var _newTarget = this.constructor;
var _this = _super.call(this, msg) || this;
Object.setPrototypeOf(_this, _newTarget.prototype);
return _this;
}
return BadEventName;
}(Error));
var BadChannelName = (function (_super) {
__extends(BadChannelName, _super);
function BadChannelName(msg) {
var _newTarget = this.constructor;
var _this = _super.call(this, msg) || this;
Object.setPrototypeOf(_this, _newTarget.prototype);
return _this;
}
return BadChannelName;
}(Error));
var RequestTimedOut = (function (_super) {
__extends(RequestTimedOut, _super);
function RequestTimedOut(msg) {
var _newTarget = this.constructor;
var _this = _super.call(this, msg) || this;
Object.setPrototypeOf(_this, _newTarget.prototype);
return _this;
}
return RequestTimedOut;
}(Error));
var TransportPriorityTooLow = (function (_super) {
__extends(TransportPriorityTooLow, _super);
function TransportPriorityTooLow(msg) {
var _newTarget = this.constructor;
var _this = _super.call(this, msg) || this;
Object.setPrototypeOf(_this, _newTarget.prototype);
return _this;
}
return TransportPriorityTooLow;
}(Error));
var TransportClosed = (function (_super) {
__extends(TransportClosed, _super);
function TransportClosed(msg) {
var _newTarget = this.constructor;
var _this = _super.call(this, msg) || this;
Object.setPrototypeOf(_this, _newTarget.prototype);
return _this;
}
return TransportClosed;
}(Error));
var UnsupportedFeature = (function (_super) {
__extends(UnsupportedFeature, _super);
function UnsupportedFeature(msg) {
var _newTarget = this.constructor;
var _this = _super.call(this, msg) || this;
Object.setPrototypeOf(_this, _newTarget.prototype);
return _this;
}
return UnsupportedFeature;
}(Error));
var UnsupportedTransport = (function (_super) {
__extends(UnsupportedTransport, _super);
function UnsupportedTransport(msg) {
var _newTarget = this.constructor;
var _this = _super.call(this, msg) || this;
Object.setPrototypeOf(_this, _newTarget.prototype);
return _this;
}
return UnsupportedTransport;
}(Error));
var UnsupportedStrategy = (function (_super) {
__extends(UnsupportedStrategy, _super);
function UnsupportedStrategy(msg) {
var _newTarget = this.constructor;
var _this = _super.call(this, msg) || this;
Object.setPrototypeOf(_this, _newTarget.prototype);
return _this;
}
return UnsupportedStrategy;
}(Error));
var HTTPAuthError = (function (_super) {
__extends(HTTPAuthError, _super);
function HTTPAuthError(status, msg) {
var _newTarget = this.constructor;
var _this = _super.call(this, msg) || this;
_this.status = status;
Object.setPrototypeOf(_this, _newTarget.prototype);
return _this;
}
return HTTPAuthError;
}(Error));
// CONCATENATED MODULE: ./src/runtimes/isomorphic/auth/xhr_auth.ts
var ajax = function (context, query, authOptions, authRequestType, callback) {
var xhr = runtime.createXHR();
xhr.open('POST', authOptions.endpoint, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
for (var headerName in authOptions.headers) {
xhr.setRequestHeader(headerName, authOptions.headers[headerName]);
}
if (authOptions.headersProvider != null) {
var dynamicHeaders = authOptions.headersProvider();
for (var headerName in dynamicHeaders) {
xhr.setRequestHeader(headerName, dynamicHeaders[headerName]);
}
}
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var data = void 0;
var parsed = false;
try {
data = JSON.parse(xhr.responseText);
parsed = true;
}
catch (e) {
callback(new HTTPAuthError(200, "JSON returned from " + authRequestType.toString() + " endpoint was invalid, yet status code was 200. Data was: " + xhr.responseText), null);
}
if (parsed) {
callback(null, data);
}
}
else {
var suffix = '';
switch (authRequestType) {
case AuthRequestType.UserAuthentication:
suffix = url_store.buildLogSuffix('authenticationEndpoint');
break;
case AuthRequestType.ChannelAuthorization:
suffix = "Clients must be authorized to join private or presence channels. " + url_store.buildLogSuffix('authorizationEndpoint');
break;
}
callback(new HTTPAuthError(xhr.status, "Unable to retrieve auth string from " + authRequestType.toString() + " endpoint - " +
("received status: " + xhr.status + " from " + authOptions.endpoint + ". " + suffix)), null);
}
}
};
xhr.send(query);
return xhr;
};
/* harmony default export */ var xhr_auth = (ajax);
// CONCATENATED MODULE: ./src/core/base64.ts
function encode(s) {
return btoa(utob(s));
}
var fromCharCode = String.fromCharCode;
var b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var b64tab = {};
for (var base64_i = 0, l = b64chars.length; base64_i < l; base64_i++) {
b64tab[b64chars.charAt(base64_i)] = base64_i;
}
var cb_utob = function (c) {
var cc = c.charCodeAt(0);
return cc < 0x80
? c
: cc < 0x800
? fromCharCode(0xc0 | (cc >>> 6)) + fromCharCode(0x80 | (cc & 0x3f))
: fromCharCode(0xe0 | ((cc >>> 12) & 0x0f)) +
fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) +
fromCharCode(0x80 | (cc & 0x3f));
};
var utob = function (u) {
return u.replace(/[^\x00-\x7F]/g, cb_utob);
};
var cb_encode = function (ccc) {
var padlen = [0, 2, 1][ccc.length % 3];
var ord = (ccc.charCodeAt(0) << 16) |
((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8) |
(ccc.length > 2 ? ccc.charCodeAt(2) : 0);
var chars = [
b64chars.charAt(ord >>> 18),
b64chars.charAt((ord >>> 12) & 63),
padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63),
padlen >= 1 ? '=' : b64chars.charAt(ord & 63)
];
return chars.join('');
};
var btoa = window.btoa ||
function (b) {
return b.replace(/[\s\S]{1,3}/g, cb_encode);
};
// CONCATENATED MODULE: ./src/core/utils/timers/abstract_timer.ts
var Timer = (function () {
function Timer(set, clear, delay, callback) {
var _this = this;
this.clear = clear;
this.timer = set(function () {
if (_this.timer) {
_this.timer = callback(_this.timer);
}
}, delay);
}
Timer.prototype.isRunning = function () {
return this.timer !== null;
};
Timer.prototype.ensureAborted = function () {
if (this.timer) {
this.clear(this.timer);
this.timer = null;
}
};
return Timer;
}());
/* harmony default export */ var abstract_timer = (Timer);
// CONCATENATED MODULE: ./src/core/utils/timers/index.ts
var timers_extends = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
function timers_clearTimeout(timer) {
window.clearTimeout(timer);
}
function timers_clearInterval(timer) {
window.clearInterval(timer);
}
var OneOffTimer = (function (_super) {
timers_extends(OneOffTimer, _super);
function OneOffTimer(delay, callback) {
return _super.call(this, setTimeout, timers_clearTimeout, delay, function (timer) {
callback();
return null;
}) || this;
}