-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeerjs.js
10135 lines (8285 loc) · 308 KB
/
peerjs.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
// modules are defined as an array
// [ module function, map of requires ]
//
// map of requires is short require name -> numeric require
//
// anything defined in a previous bundle is accessed via the
// orig method which is the require for previous bundles
parcelRequire = (function (modules, cache, entry, globalName) {
// Save the require from previous bundle to this closure if any
var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
var nodeRequire = typeof require === 'function' && require;
function newRequire(name, jumped) {
if (!cache[name]) {
if (!modules[name]) {
// if we cannot find the module within our internal map or
// cache jump to the current global require ie. the last bundle
// that was added to the page.
var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
if (!jumped && currentRequire) {
return currentRequire(name, true);
}
// If there are other bundles on this page the require from the
// previous one is saved to 'previousRequire'. Repeat this as
// many times as there are bundles until the module is found or
// we exhaust the require chain.
if (previousRequire) {
return previousRequire(name, true);
}
// Try the node require function if it exists.
if (nodeRequire && typeof name === 'string') {
return nodeRequire(name);
}
var err = new Error('Cannot find module \'' + name + '\'');
err.code = 'MODULE_NOT_FOUND';
throw err;
}
localRequire.resolve = resolve;
localRequire.cache = {};
var module = cache[name] = new newRequire.Module(name);
modules[name][0].call(module.exports, localRequire, module, module.exports, this);
}
return cache[name].exports;
function localRequire(x){
return newRequire(localRequire.resolve(x));
}
function resolve(x){
return modules[name][1][x] || x;
}
}
function Module(moduleName) {
this.id = moduleName;
this.bundle = newRequire;
this.exports = {};
}
newRequire.isParcelRequire = true;
newRequire.Module = Module;
newRequire.modules = modules;
newRequire.cache = cache;
newRequire.parent = previousRequire;
newRequire.register = function (id, exports) {
modules[id] = [function (require, module) {
module.exports = exports;
}, {}];
};
var error;
for (var i = 0; i < entry.length; i++) {
try {
newRequire(entry[i]);
} catch (e) {
// Save first error but execute all entries
if (!error) {
error = e;
}
}
}
if (entry.length) {
// Expose entry point to Node, AMD or browser globals
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
var mainExports = newRequire(entry[entry.length - 1]);
// CommonJS
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = mainExports;
// RequireJS
} else if (typeof define === "function" && define.amd) {
define(function () {
return mainExports;
});
// <script>
} else if (globalName) {
this[globalName] = mainExports;
}
}
// Override the current require with this new one
parcelRequire = newRequire;
if (error) {
// throw error from earlier, _after updating parcelRequire_
throw error;
}
return newRequire;
})({"EgBh":[function(require,module,exports) {
var binaryFeatures = {};
binaryFeatures.useBlobBuilder = (function () {
try {
new Blob([]);
return false;
} catch (e) {
return true;
}
})();
binaryFeatures.useArrayBufferView = !binaryFeatures.useBlobBuilder && (function () {
try {
return (new Blob([new Uint8Array([])])).size === 0;
} catch (e) {
return true;
}
})();
module.exports.binaryFeatures = binaryFeatures;
var BlobBuilder = module.exports.BlobBuilder;
if (typeof window !== 'undefined') {
BlobBuilder = module.exports.BlobBuilder = window.WebKitBlobBuilder ||
window.MozBlobBuilder || window.MSBlobBuilder || window.BlobBuilder;
}
function BufferBuilder () {
this._pieces = [];
this._parts = [];
}
BufferBuilder.prototype.append = function (data) {
if (typeof data === 'number') {
this._pieces.push(data);
} else {
this.flush();
this._parts.push(data);
}
};
BufferBuilder.prototype.flush = function () {
if (this._pieces.length > 0) {
var buf = new Uint8Array(this._pieces);
if (!binaryFeatures.useArrayBufferView) {
buf = buf.buffer;
}
this._parts.push(buf);
this._pieces = [];
}
};
BufferBuilder.prototype.getBuffer = function () {
this.flush();
if (binaryFeatures.useBlobBuilder) {
var builder = new BlobBuilder();
for (var i = 0, ii = this._parts.length; i < ii; i++) {
builder.append(this._parts[i]);
}
return builder.getBlob();
} else {
return new Blob(this._parts);
}
};
module.exports.BufferBuilder = BufferBuilder;
},{}],"kdPp":[function(require,module,exports) {
var BufferBuilder = require('./bufferbuilder').BufferBuilder;
var binaryFeatures = require('./bufferbuilder').binaryFeatures;
var BinaryPack = {
unpack: function (data) {
var unpacker = new Unpacker(data);
return unpacker.unpack();
},
pack: function (data) {
var packer = new Packer();
packer.pack(data);
var buffer = packer.getBuffer();
return buffer;
}
};
module.exports = BinaryPack;
function Unpacker (data) {
// Data is ArrayBuffer
this.index = 0;
this.dataBuffer = data;
this.dataView = new Uint8Array(this.dataBuffer);
this.length = this.dataBuffer.byteLength;
}
Unpacker.prototype.unpack = function () {
var type = this.unpack_uint8();
if (type < 0x80) {
return type;
} else if ((type ^ 0xe0) < 0x20) {
return (type ^ 0xe0) - 0x20;
}
var size;
if ((size = type ^ 0xa0) <= 0x0f) {
return this.unpack_raw(size);
} else if ((size = type ^ 0xb0) <= 0x0f) {
return this.unpack_string(size);
} else if ((size = type ^ 0x90) <= 0x0f) {
return this.unpack_array(size);
} else if ((size = type ^ 0x80) <= 0x0f) {
return this.unpack_map(size);
}
switch (type) {
case 0xc0:
return null;
case 0xc1:
return undefined;
case 0xc2:
return false;
case 0xc3:
return true;
case 0xca:
return this.unpack_float();
case 0xcb:
return this.unpack_double();
case 0xcc:
return this.unpack_uint8();
case 0xcd:
return this.unpack_uint16();
case 0xce:
return this.unpack_uint32();
case 0xcf:
return this.unpack_uint64();
case 0xd0:
return this.unpack_int8();
case 0xd1:
return this.unpack_int16();
case 0xd2:
return this.unpack_int32();
case 0xd3:
return this.unpack_int64();
case 0xd4:
return undefined;
case 0xd5:
return undefined;
case 0xd6:
return undefined;
case 0xd7:
return undefined;
case 0xd8:
size = this.unpack_uint16();
return this.unpack_string(size);
case 0xd9:
size = this.unpack_uint32();
return this.unpack_string(size);
case 0xda:
size = this.unpack_uint16();
return this.unpack_raw(size);
case 0xdb:
size = this.unpack_uint32();
return this.unpack_raw(size);
case 0xdc:
size = this.unpack_uint16();
return this.unpack_array(size);
case 0xdd:
size = this.unpack_uint32();
return this.unpack_array(size);
case 0xde:
size = this.unpack_uint16();
return this.unpack_map(size);
case 0xdf:
size = this.unpack_uint32();
return this.unpack_map(size);
}
};
Unpacker.prototype.unpack_uint8 = function () {
var byte = this.dataView[this.index] & 0xff;
this.index++;
return byte;
};
Unpacker.prototype.unpack_uint16 = function () {
var bytes = this.read(2);
var uint16 =
((bytes[0] & 0xff) * 256) + (bytes[1] & 0xff);
this.index += 2;
return uint16;
};
Unpacker.prototype.unpack_uint32 = function () {
var bytes = this.read(4);
var uint32 =
((bytes[0] * 256 +
bytes[1]) * 256 +
bytes[2]) * 256 +
bytes[3];
this.index += 4;
return uint32;
};
Unpacker.prototype.unpack_uint64 = function () {
var bytes = this.read(8);
var uint64 =
((((((bytes[0] * 256 +
bytes[1]) * 256 +
bytes[2]) * 256 +
bytes[3]) * 256 +
bytes[4]) * 256 +
bytes[5]) * 256 +
bytes[6]) * 256 +
bytes[7];
this.index += 8;
return uint64;
};
Unpacker.prototype.unpack_int8 = function () {
var uint8 = this.unpack_uint8();
return (uint8 < 0x80) ? uint8 : uint8 - (1 << 8);
};
Unpacker.prototype.unpack_int16 = function () {
var uint16 = this.unpack_uint16();
return (uint16 < 0x8000) ? uint16 : uint16 - (1 << 16);
};
Unpacker.prototype.unpack_int32 = function () {
var uint32 = this.unpack_uint32();
return (uint32 < Math.pow(2, 31)) ? uint32
: uint32 - Math.pow(2, 32);
};
Unpacker.prototype.unpack_int64 = function () {
var uint64 = this.unpack_uint64();
return (uint64 < Math.pow(2, 63)) ? uint64
: uint64 - Math.pow(2, 64);
};
Unpacker.prototype.unpack_raw = function (size) {
if (this.length < this.index + size) {
throw new Error('BinaryPackFailure: index is out of range' +
' ' + this.index + ' ' + size + ' ' + this.length);
}
var buf = this.dataBuffer.slice(this.index, this.index + size);
this.index += size;
// buf = util.bufferToString(buf);
return buf;
};
Unpacker.prototype.unpack_string = function (size) {
var bytes = this.read(size);
var i = 0;
var str = '';
var c;
var code;
while (i < size) {
c = bytes[i];
if (c < 128) {
str += String.fromCharCode(c);
i++;
} else if ((c ^ 0xc0) < 32) {
code = ((c ^ 0xc0) << 6) | (bytes[i + 1] & 63);
str += String.fromCharCode(code);
i += 2;
} else {
code = ((c & 15) << 12) | ((bytes[i + 1] & 63) << 6) |
(bytes[i + 2] & 63);
str += String.fromCharCode(code);
i += 3;
}
}
this.index += size;
return str;
};
Unpacker.prototype.unpack_array = function (size) {
var objects = new Array(size);
for (var i = 0; i < size; i++) {
objects[i] = this.unpack();
}
return objects;
};
Unpacker.prototype.unpack_map = function (size) {
var map = {};
for (var i = 0; i < size; i++) {
var key = this.unpack();
var value = this.unpack();
map[key] = value;
}
return map;
};
Unpacker.prototype.unpack_float = function () {
var uint32 = this.unpack_uint32();
var sign = uint32 >> 31;
var exp = ((uint32 >> 23) & 0xff) - 127;
var fraction = (uint32 & 0x7fffff) | 0x800000;
return (sign === 0 ? 1 : -1) *
fraction * Math.pow(2, exp - 23);
};
Unpacker.prototype.unpack_double = function () {
var h32 = this.unpack_uint32();
var l32 = this.unpack_uint32();
var sign = h32 >> 31;
var exp = ((h32 >> 20) & 0x7ff) - 1023;
var hfrac = (h32 & 0xfffff) | 0x100000;
var frac = hfrac * Math.pow(2, exp - 20) +
l32 * Math.pow(2, exp - 52);
return (sign === 0 ? 1 : -1) * frac;
};
Unpacker.prototype.read = function (length) {
var j = this.index;
if (j + length <= this.length) {
return this.dataView.subarray(j, j + length);
} else {
throw new Error('BinaryPackFailure: read index out of range');
}
};
function Packer () {
this.bufferBuilder = new BufferBuilder();
}
Packer.prototype.getBuffer = function () {
return this.bufferBuilder.getBuffer();
};
Packer.prototype.pack = function (value) {
var type = typeof (value);
if (type === 'string') {
this.pack_string(value);
} else if (type === 'number') {
if (Math.floor(value) === value) {
this.pack_integer(value);
} else {
this.pack_double(value);
}
} else if (type === 'boolean') {
if (value === true) {
this.bufferBuilder.append(0xc3);
} else if (value === false) {
this.bufferBuilder.append(0xc2);
}
} else if (type === 'undefined') {
this.bufferBuilder.append(0xc0);
} else if (type === 'object') {
if (value === null) {
this.bufferBuilder.append(0xc0);
} else {
var constructor = value.constructor;
if (constructor == Array) {
this.pack_array(value);
} else if (constructor == Blob || constructor == File || value instanceof Blob || value instanceof File) {
this.pack_bin(value);
} else if (constructor == ArrayBuffer) {
if (binaryFeatures.useArrayBufferView) {
this.pack_bin(new Uint8Array(value));
} else {
this.pack_bin(value);
}
} else if ('BYTES_PER_ELEMENT' in value) {
if (binaryFeatures.useArrayBufferView) {
this.pack_bin(new Uint8Array(value.buffer));
} else {
this.pack_bin(value.buffer);
}
} else if ((constructor == Object) || (constructor.toString().startsWith('class'))) {
this.pack_object(value);
} else if (constructor == Date) {
this.pack_string(value.toString());
} else if (typeof value.toBinaryPack === 'function') {
this.bufferBuilder.append(value.toBinaryPack());
} else {
throw new Error('Type "' + constructor.toString() + '" not yet supported');
}
}
} else {
throw new Error('Type "' + type + '" not yet supported');
}
this.bufferBuilder.flush();
};
Packer.prototype.pack_bin = function (blob) {
var length = blob.length || blob.byteLength || blob.size;
if (length <= 0x0f) {
this.pack_uint8(0xa0 + length);
} else if (length <= 0xffff) {
this.bufferBuilder.append(0xda);
this.pack_uint16(length);
} else if (length <= 0xffffffff) {
this.bufferBuilder.append(0xdb);
this.pack_uint32(length);
} else {
throw new Error('Invalid length');
}
this.bufferBuilder.append(blob);
};
Packer.prototype.pack_string = function (str) {
var length = utf8Length(str);
if (length <= 0x0f) {
this.pack_uint8(0xb0 + length);
} else if (length <= 0xffff) {
this.bufferBuilder.append(0xd8);
this.pack_uint16(length);
} else if (length <= 0xffffffff) {
this.bufferBuilder.append(0xd9);
this.pack_uint32(length);
} else {
throw new Error('Invalid length');
}
this.bufferBuilder.append(str);
};
Packer.prototype.pack_array = function (ary) {
var length = ary.length;
if (length <= 0x0f) {
this.pack_uint8(0x90 + length);
} else if (length <= 0xffff) {
this.bufferBuilder.append(0xdc);
this.pack_uint16(length);
} else if (length <= 0xffffffff) {
this.bufferBuilder.append(0xdd);
this.pack_uint32(length);
} else {
throw new Error('Invalid length');
}
for (var i = 0; i < length; i++) {
this.pack(ary[i]);
}
};
Packer.prototype.pack_integer = function (num) {
if (num >= -0x20 && num <= 0x7f) {
this.bufferBuilder.append(num & 0xff);
} else if (num >= 0x00 && num <= 0xff) {
this.bufferBuilder.append(0xcc);
this.pack_uint8(num);
} else if (num >= -0x80 && num <= 0x7f) {
this.bufferBuilder.append(0xd0);
this.pack_int8(num);
} else if (num >= 0x0000 && num <= 0xffff) {
this.bufferBuilder.append(0xcd);
this.pack_uint16(num);
} else if (num >= -0x8000 && num <= 0x7fff) {
this.bufferBuilder.append(0xd1);
this.pack_int16(num);
} else if (num >= 0x00000000 && num <= 0xffffffff) {
this.bufferBuilder.append(0xce);
this.pack_uint32(num);
} else if (num >= -0x80000000 && num <= 0x7fffffff) {
this.bufferBuilder.append(0xd2);
this.pack_int32(num);
} else if (num >= -0x8000000000000000 && num <= 0x7FFFFFFFFFFFFFFF) {
this.bufferBuilder.append(0xd3);
this.pack_int64(num);
} else if (num >= 0x0000000000000000 && num <= 0xFFFFFFFFFFFFFFFF) {
this.bufferBuilder.append(0xcf);
this.pack_uint64(num);
} else {
throw new Error('Invalid integer');
}
};
Packer.prototype.pack_double = function (num) {
var sign = 0;
if (num < 0) {
sign = 1;
num = -num;
}
var exp = Math.floor(Math.log(num) / Math.LN2);
var frac0 = num / Math.pow(2, exp) - 1;
var frac1 = Math.floor(frac0 * Math.pow(2, 52));
var b32 = Math.pow(2, 32);
var h32 = (sign << 31) | ((exp + 1023) << 20) |
(frac1 / b32) & 0x0fffff;
var l32 = frac1 % b32;
this.bufferBuilder.append(0xcb);
this.pack_int32(h32);
this.pack_int32(l32);
};
Packer.prototype.pack_object = function (obj) {
var keys = Object.keys(obj);
var length = keys.length;
if (length <= 0x0f) {
this.pack_uint8(0x80 + length);
} else if (length <= 0xffff) {
this.bufferBuilder.append(0xde);
this.pack_uint16(length);
} else if (length <= 0xffffffff) {
this.bufferBuilder.append(0xdf);
this.pack_uint32(length);
} else {
throw new Error('Invalid length');
}
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
this.pack(prop);
this.pack(obj[prop]);
}
}
};
Packer.prototype.pack_uint8 = function (num) {
this.bufferBuilder.append(num);
};
Packer.prototype.pack_uint16 = function (num) {
this.bufferBuilder.append(num >> 8);
this.bufferBuilder.append(num & 0xff);
};
Packer.prototype.pack_uint32 = function (num) {
var n = num & 0xffffffff;
this.bufferBuilder.append((n & 0xff000000) >>> 24);
this.bufferBuilder.append((n & 0x00ff0000) >>> 16);
this.bufferBuilder.append((n & 0x0000ff00) >>> 8);
this.bufferBuilder.append((n & 0x000000ff));
};
Packer.prototype.pack_uint64 = function (num) {
var high = num / Math.pow(2, 32);
var low = num % Math.pow(2, 32);
this.bufferBuilder.append((high & 0xff000000) >>> 24);
this.bufferBuilder.append((high & 0x00ff0000) >>> 16);
this.bufferBuilder.append((high & 0x0000ff00) >>> 8);
this.bufferBuilder.append((high & 0x000000ff));
this.bufferBuilder.append((low & 0xff000000) >>> 24);
this.bufferBuilder.append((low & 0x00ff0000) >>> 16);
this.bufferBuilder.append((low & 0x0000ff00) >>> 8);
this.bufferBuilder.append((low & 0x000000ff));
};
Packer.prototype.pack_int8 = function (num) {
this.bufferBuilder.append(num & 0xff);
};
Packer.prototype.pack_int16 = function (num) {
this.bufferBuilder.append((num & 0xff00) >> 8);
this.bufferBuilder.append(num & 0xff);
};
Packer.prototype.pack_int32 = function (num) {
this.bufferBuilder.append((num >>> 24) & 0xff);
this.bufferBuilder.append((num & 0x00ff0000) >>> 16);
this.bufferBuilder.append((num & 0x0000ff00) >>> 8);
this.bufferBuilder.append((num & 0x000000ff));
};
Packer.prototype.pack_int64 = function (num) {
var high = Math.floor(num / Math.pow(2, 32));
var low = num % Math.pow(2, 32);
this.bufferBuilder.append((high & 0xff000000) >>> 24);
this.bufferBuilder.append((high & 0x00ff0000) >>> 16);
this.bufferBuilder.append((high & 0x0000ff00) >>> 8);
this.bufferBuilder.append((high & 0x000000ff));
this.bufferBuilder.append((low & 0xff000000) >>> 24);
this.bufferBuilder.append((low & 0x00ff0000) >>> 16);
this.bufferBuilder.append((low & 0x0000ff00) >>> 8);
this.bufferBuilder.append((low & 0x000000ff));
};
function _utf8Replace (m) {
var code = m.charCodeAt(0);
if (code <= 0x7ff) return '00';
if (code <= 0xffff) return '000';
if (code <= 0x1fffff) return '0000';
if (code <= 0x3ffffff) return '00000';
return '000000';
}
function utf8Length (str) {
if (str.length > 600) {
// Blob method faster for large strings
return (new Blob([str])).size;
} else {
return str.replace(/[^\u0000-\u007F]/g, _utf8Replace).length;
}
}
},{"./bufferbuilder":"EgBh"}],"iSxC":[function(require,module,exports) {
/*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree.
*/
/* eslint-env node */
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.extractVersion = extractVersion;
exports.wrapPeerConnectionEvent = wrapPeerConnectionEvent;
exports.disableLog = disableLog;
exports.disableWarnings = disableWarnings;
exports.log = log;
exports.deprecated = deprecated;
exports.detectBrowser = detectBrowser;
exports.compactObject = compactObject;
exports.walkStats = walkStats;
exports.filterStats = filterStats;
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function (obj) { return typeof obj; }; } else { _typeof = function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var logDisabled_ = true;
var deprecationWarnings_ = true;
/**
* Extract browser version out of the provided user agent string.
*
* @param {!string} uastring userAgent string.
* @param {!string} expr Regular expression used as match criteria.
* @param {!number} pos position in the version string to be returned.
* @return {!number} browser version.
*/
function extractVersion(uastring, expr, pos) {
var match = uastring.match(expr);
return match && match.length >= pos && parseInt(match[pos], 10);
} // Wraps the peerconnection event eventNameToWrap in a function
// which returns the modified event object (or false to prevent
// the event).
function wrapPeerConnectionEvent(window, eventNameToWrap, wrapper) {
if (!window.RTCPeerConnection) {
return;
}
var proto = window.RTCPeerConnection.prototype;
var nativeAddEventListener = proto.addEventListener;
proto.addEventListener = function (nativeEventName, cb) {
if (nativeEventName !== eventNameToWrap) {
return nativeAddEventListener.apply(this, arguments);
}
var wrappedCallback = function (e) {
var modifiedEvent = wrapper(e);
if (modifiedEvent) {
cb(modifiedEvent);
}
};
this._eventMap = this._eventMap || {};
this._eventMap[cb] = wrappedCallback;
return nativeAddEventListener.apply(this, [nativeEventName, wrappedCallback]);
};
var nativeRemoveEventListener = proto.removeEventListener;
proto.removeEventListener = function (nativeEventName, cb) {
if (nativeEventName !== eventNameToWrap || !this._eventMap || !this._eventMap[cb]) {
return nativeRemoveEventListener.apply(this, arguments);
}
var unwrappedCb = this._eventMap[cb];
delete this._eventMap[cb];
return nativeRemoveEventListener.apply(this, [nativeEventName, unwrappedCb]);
};
Object.defineProperty(proto, 'on' + eventNameToWrap, {
get: function () {
return this['_on' + eventNameToWrap];
},
set: function (cb) {
if (this['_on' + eventNameToWrap]) {
this.removeEventListener(eventNameToWrap, this['_on' + eventNameToWrap]);
delete this['_on' + eventNameToWrap];
}
if (cb) {
this.addEventListener(eventNameToWrap, this['_on' + eventNameToWrap] = cb);
}
},
enumerable: true,
configurable: true
});
}
function disableLog(bool) {
if (typeof bool !== 'boolean') {
return new Error('Argument type: ' + _typeof(bool) + '. Please use a boolean.');
}
logDisabled_ = bool;
return bool ? 'adapter.js logging disabled' : 'adapter.js logging enabled';
}
/**
* Disable or enable deprecation warnings
* @param {!boolean} bool set to true to disable warnings.
*/
function disableWarnings(bool) {
if (typeof bool !== 'boolean') {
return new Error('Argument type: ' + _typeof(bool) + '. Please use a boolean.');
}
deprecationWarnings_ = !bool;
return 'adapter.js deprecation warnings ' + (bool ? 'disabled' : 'enabled');
}
function log() {
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object') {
if (logDisabled_) {
return;
}
if (typeof console !== 'undefined' && typeof console.log === 'function') {
console.log.apply(console, arguments);
}
}
}
/**
* Shows a deprecation warning suggesting the modern and spec-compatible API.
*/
function deprecated(oldMethod, newMethod) {
if (!deprecationWarnings_) {
return;
}
console.warn(oldMethod + ' is deprecated, please use ' + newMethod + ' instead.');
}
/**
* Browser detector.
*
* @return {object} result containing browser and version
* properties.
*/
function detectBrowser(window) {
var {
navigator: navigator
} = window; // Returned result object.
var result = {
browser: null,
version: null
}; // Fail early if it's not a browser
if (typeof window === 'undefined' || !window.navigator) {
result.browser = 'Not a browser.';
return result;
}
if (navigator.mozGetUserMedia) {
// Firefox.
result.browser = 'firefox';
result.version = extractVersion(navigator.userAgent, /Firefox\/(\d+)\./, 1);
} else if (navigator.webkitGetUserMedia || window.isSecureContext === false && window.webkitRTCPeerConnection && !window.RTCIceGatherer) {
// Chrome, Chromium, Webview, Opera.
// Version matches Chrome/WebRTC version.
// Chrome 74 removed webkitGetUserMedia on http as well so we need the
// more complicated fallback to webkitRTCPeerConnection.
result.browser = 'chrome';
result.version = extractVersion(navigator.userAgent, /Chrom(e|ium)\/(\d+)\./, 2);
} else if (navigator.mediaDevices && navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)) {
// Edge.
result.browser = 'edge';
result.version = extractVersion(navigator.userAgent, /Edge\/(\d+).(\d+)$/, 2);
} else if (window.RTCPeerConnection && navigator.userAgent.match(/AppleWebKit\/(\d+)\./)) {
// Safari.
result.browser = 'safari';
result.version = extractVersion(navigator.userAgent, /AppleWebKit\/(\d+)\./, 1);
result.supportsUnifiedPlan = window.RTCRtpTransceiver && 'currentDirection' in window.RTCRtpTransceiver.prototype;
} else {
// Default fallthrough: not supported.
result.browser = 'Not a supported browser.';
return result;
}
return result;
}
/**
* Checks if something is an object.
*
* @param {*} val The something you want to check.
* @return true if val is an object, false otherwise.
*/
function isObject(val) {
return Object.prototype.toString.call(val) === '[object Object]';
}
/**
* Remove all empty objects and undefined values
* from a nested object -- an enhanced and vanilla version
* of Lodash's `compact`.
*/
function compactObject(data) {
if (!isObject(data)) {
return data;
}
return Object.keys(data).reduce(function (accumulator, key) {
var isObj = isObject(data[key]);
var value = isObj ? compactObject(data[key]) : data[key];
var isEmptyObject = isObj && !Object.keys(value).length;
if (value === undefined || isEmptyObject) {
return accumulator;
}
return Object.assign(accumulator, _defineProperty({}, key, value));
}, {});
}
/* iterates the stats graph recursively. */
function walkStats(stats, base, resultSet) {
if (!base || resultSet.has(base.id)) {
return;
}
resultSet.set(base.id, base);
Object.keys(base).forEach(function (name) {
if (name.endsWith('Id')) {
walkStats(stats, stats.get(base[name]), resultSet);
} else if (name.endsWith('Ids')) {
base[name].forEach(function (id) {
walkStats(stats, stats.get(id), resultSet);
});
}
});
}
/* filter getStats for a sender/receiver track. */
function filterStats(result, track, outbound) {
var streamStatsType = outbound ? 'outbound-rtp' : 'inbound-rtp';
var filteredResult = new Map();
if (track === null) {
return filteredResult;
}
var trackStats = [];
result.forEach(function (value) {
if (value.type === 'track' && value.trackIdentifier === track.id) {
trackStats.push(value);
}
});
trackStats.forEach(function (trackStat) {
result.forEach(function (stats) {
if (stats.type === streamStatsType && stats.trackId === trackStat.id) {
walkStats(result, stats, filteredResult);
}
});
});
return filteredResult;
}
},{}],"s6SN":[function(require,module,exports) {
/*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree.
*/