@ylink-sdk/mobile-web 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4198 @@
1
+ (function (f) {
2
+ if (typeof exports === 'object' && typeof module !== 'undefined') {
3
+ module.exports = f();
4
+ } else if (typeof define === 'function' && define.amd) {
5
+ define([], f);
6
+ } else {
7
+ var g;
8
+ if (typeof window !== 'undefined') {
9
+ g = window;
10
+ } else if (typeof global !== 'undefined') {
11
+ g = global;
12
+ } else if (typeof self !== 'undefined') {
13
+ g = self;
14
+ } else {
15
+ g = this;
16
+ }
17
+ g.adapter = f();
18
+ }
19
+ })(function () {
20
+ var define, module, exports;
21
+ return (function () {
22
+ function r(e, n, t) {
23
+ function o(i, f) {
24
+ if (!n[i]) {
25
+ if (!e[i]) {
26
+ var c = 'function' == typeof require && require;
27
+ if (!f && c) return c(i, !0);
28
+ if (u) return u(i, !0);
29
+ var a = new Error("Cannot find module '" + i + "'");
30
+ throw ((a.code = 'MODULE_NOT_FOUND'), a);
31
+ }
32
+ var p = (n[i] = { exports: {} });
33
+ e[i][0].call(
34
+ p.exports,
35
+ function (r) {
36
+ var n = e[i][1][r];
37
+ return o(n || r);
38
+ },
39
+ p,
40
+ p.exports,
41
+ r,
42
+ e,
43
+ n,
44
+ t
45
+ );
46
+ }
47
+ return n[i].exports;
48
+ }
49
+ for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++) o(t[i]);
50
+ return o;
51
+ }
52
+ return r;
53
+ })()(
54
+ {
55
+ 1: [
56
+ function (require, module, exports) {
57
+ /*
58
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
59
+ *
60
+ * Use of this source code is governed by a BSD-style license
61
+ * that can be found in the LICENSE file in the root of the source
62
+ * tree.
63
+ */
64
+ /* eslint-env node */
65
+
66
+ 'use strict';
67
+
68
+ var _adapter_factory = require('./adapter_factory.js');
69
+
70
+ var adapter = (0, _adapter_factory.adapterFactory)({
71
+ window: typeof window === 'undefined' ? undefined : window
72
+ });
73
+ module.exports = adapter; // this is the difference from adapter_core.
74
+ },
75
+ { './adapter_factory.js': 2 }
76
+ ],
77
+ 2: [
78
+ function (require, module, exports) {
79
+ 'use strict';
80
+
81
+ Object.defineProperty(exports, '__esModule', {
82
+ value: true
83
+ });
84
+ exports.adapterFactory = adapterFactory;
85
+
86
+ var _utils = require('./utils');
87
+
88
+ var utils = _interopRequireWildcard(_utils);
89
+
90
+ var _chrome_shim = require('./chrome/chrome_shim');
91
+
92
+ var chromeShim = _interopRequireWildcard(_chrome_shim);
93
+
94
+ var _firefox_shim = require('./firefox/firefox_shim');
95
+
96
+ var firefoxShim = _interopRequireWildcard(_firefox_shim);
97
+
98
+ var _safari_shim = require('./safari/safari_shim');
99
+
100
+ var safariShim = _interopRequireWildcard(_safari_shim);
101
+
102
+ var _common_shim = require('./common_shim');
103
+
104
+ var commonShim = _interopRequireWildcard(_common_shim);
105
+
106
+ var _sdp = require('sdp');
107
+
108
+ var sdp = _interopRequireWildcard(_sdp);
109
+
110
+ function _interopRequireWildcard(obj) {
111
+ if (obj && obj.__esModule) {
112
+ return obj;
113
+ } else {
114
+ var newObj = {};
115
+ if (obj != null) {
116
+ for (var key in obj) {
117
+ if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
118
+ }
119
+ }
120
+ newObj.default = obj;
121
+ return newObj;
122
+ }
123
+ }
124
+
125
+ // Shimming starts here.
126
+ /*
127
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
128
+ *
129
+ * Use of this source code is governed by a BSD-style license
130
+ * that can be found in the LICENSE file in the root of the source
131
+ * tree.
132
+ */
133
+ function adapterFactory() {
134
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
135
+ window = _ref.window;
136
+
137
+ var options =
138
+ arguments.length > 1 && arguments[1] !== undefined
139
+ ? arguments[1]
140
+ : {
141
+ shimChrome: true,
142
+ shimFirefox: true,
143
+ shimSafari: true
144
+ };
145
+
146
+ // Utils.
147
+ var logging = utils.log;
148
+ var browserDetails = utils.detectBrowser(window);
149
+
150
+ var adapter = {
151
+ browserDetails: browserDetails,
152
+ commonShim: commonShim,
153
+ extractVersion: utils.extractVersion,
154
+ disableLog: utils.disableLog,
155
+ disableWarnings: utils.disableWarnings,
156
+ // Expose sdp as a convenience. For production apps include directly.
157
+ sdp: sdp
158
+ };
159
+
160
+ // Shim browser if found.
161
+ switch (browserDetails.browser) {
162
+ case 'chrome':
163
+ if (!chromeShim || !chromeShim.shimPeerConnection || !options.shimChrome) {
164
+ logging('Chrome shim is not included in this adapter release.');
165
+ return adapter;
166
+ }
167
+ if (browserDetails.version === null) {
168
+ logging('Chrome shim can not determine version, not shimming.');
169
+ return adapter;
170
+ }
171
+ logging('adapter.js shimming chrome.');
172
+ // Export to the adapter global object visible in the browser.
173
+ adapter.browserShim = chromeShim;
174
+
175
+ // Must be called before shimPeerConnection.
176
+ commonShim.shimAddIceCandidateNullOrEmpty(window, browserDetails);
177
+ commonShim.shimParameterlessSetLocalDescription(window, browserDetails);
178
+
179
+ chromeShim.shimGetUserMedia(window, browserDetails);
180
+ chromeShim.shimMediaStream(window, browserDetails);
181
+ chromeShim.shimPeerConnection(window, browserDetails);
182
+ chromeShim.shimOnTrack(window, browserDetails);
183
+ chromeShim.shimAddTrackRemoveTrack(window, browserDetails);
184
+ chromeShim.shimGetSendersWithDtmf(window, browserDetails);
185
+ chromeShim.shimGetStats(window, browserDetails);
186
+ chromeShim.shimSenderReceiverGetStats(window, browserDetails);
187
+ chromeShim.fixNegotiationNeeded(window, browserDetails);
188
+
189
+ commonShim.shimRTCIceCandidate(window, browserDetails);
190
+ commonShim.shimConnectionState(window, browserDetails);
191
+ commonShim.shimMaxMessageSize(window, browserDetails);
192
+ commonShim.shimSendThrowTypeError(window, browserDetails);
193
+ commonShim.removeExtmapAllowMixed(window, browserDetails);
194
+ break;
195
+ case 'firefox':
196
+ if (!firefoxShim || !firefoxShim.shimPeerConnection || !options.shimFirefox) {
197
+ logging('Firefox shim is not included in this adapter release.');
198
+ return adapter;
199
+ }
200
+ logging('adapter.js shimming firefox.');
201
+ // Export to the adapter global object visible in the browser.
202
+ adapter.browserShim = firefoxShim;
203
+
204
+ // Must be called before shimPeerConnection.
205
+ commonShim.shimAddIceCandidateNullOrEmpty(window, browserDetails);
206
+ commonShim.shimParameterlessSetLocalDescription(window, browserDetails);
207
+
208
+ firefoxShim.shimGetUserMedia(window, browserDetails);
209
+ firefoxShim.shimPeerConnection(window, browserDetails);
210
+ firefoxShim.shimOnTrack(window, browserDetails);
211
+ firefoxShim.shimRemoveStream(window, browserDetails);
212
+ firefoxShim.shimSenderGetStats(window, browserDetails);
213
+ firefoxShim.shimReceiverGetStats(window, browserDetails);
214
+ firefoxShim.shimRTCDataChannel(window, browserDetails);
215
+ firefoxShim.shimAddTransceiver(window, browserDetails);
216
+ firefoxShim.shimGetParameters(window, browserDetails);
217
+ firefoxShim.shimCreateOffer(window, browserDetails);
218
+ firefoxShim.shimCreateAnswer(window, browserDetails);
219
+
220
+ commonShim.shimRTCIceCandidate(window, browserDetails);
221
+ commonShim.shimConnectionState(window, browserDetails);
222
+ commonShim.shimMaxMessageSize(window, browserDetails);
223
+ commonShim.shimSendThrowTypeError(window, browserDetails);
224
+ break;
225
+ case 'safari':
226
+ if (!safariShim || !options.shimSafari) {
227
+ logging('Safari shim is not included in this adapter release.');
228
+ return adapter;
229
+ }
230
+ logging('adapter.js shimming safari.');
231
+ // Export to the adapter global object visible in the browser.
232
+ adapter.browserShim = safariShim;
233
+
234
+ // Must be called before shimCallbackAPI.
235
+ commonShim.shimAddIceCandidateNullOrEmpty(window, browserDetails);
236
+ commonShim.shimParameterlessSetLocalDescription(window, browserDetails);
237
+
238
+ safariShim.shimRTCIceServerUrls(window, browserDetails);
239
+ safariShim.shimCreateOfferLegacy(window, browserDetails);
240
+ safariShim.shimCallbacksAPI(window, browserDetails);
241
+ safariShim.shimLocalStreamsAPI(window, browserDetails);
242
+ safariShim.shimRemoteStreamsAPI(window, browserDetails);
243
+ safariShim.shimTrackEventTransceiver(window, browserDetails);
244
+ safariShim.shimGetUserMedia(window, browserDetails);
245
+ safariShim.shimAudioContext(window, browserDetails);
246
+
247
+ commonShim.shimRTCIceCandidate(window, browserDetails);
248
+ commonShim.shimMaxMessageSize(window, browserDetails);
249
+ commonShim.shimSendThrowTypeError(window, browserDetails);
250
+ commonShim.removeExtmapAllowMixed(window, browserDetails);
251
+ break;
252
+ default:
253
+ logging('Unsupported browser!');
254
+ break;
255
+ }
256
+
257
+ return adapter;
258
+ }
259
+
260
+ // Browser shims.
261
+ },
262
+ {
263
+ './chrome/chrome_shim': 3,
264
+ './common_shim': 6,
265
+ './firefox/firefox_shim': 7,
266
+ './safari/safari_shim': 10,
267
+ './utils': 11,
268
+ sdp: 12
269
+ }
270
+ ],
271
+ 3: [
272
+ function (require, module, exports) {
273
+ /*
274
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
275
+ *
276
+ * Use of this source code is governed by a BSD-style license
277
+ * that can be found in the LICENSE file in the root of the source
278
+ * tree.
279
+ */
280
+ /* eslint-env node */
281
+ 'use strict';
282
+
283
+ Object.defineProperty(exports, '__esModule', {
284
+ value: true
285
+ });
286
+ exports.shimGetDisplayMedia = exports.shimGetUserMedia = undefined;
287
+
288
+ var _typeof =
289
+ typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
290
+ ? function (obj) {
291
+ return typeof obj;
292
+ }
293
+ : function (obj) {
294
+ return obj &&
295
+ typeof Symbol === 'function' &&
296
+ obj.constructor === Symbol &&
297
+ obj !== Symbol.prototype
298
+ ? 'symbol'
299
+ : typeof obj;
300
+ };
301
+
302
+ var _getusermedia = require('./getusermedia');
303
+
304
+ Object.defineProperty(exports, 'shimGetUserMedia', {
305
+ enumerable: true,
306
+ get: function get() {
307
+ return _getusermedia.shimGetUserMedia;
308
+ }
309
+ });
310
+
311
+ var _getdisplaymedia = require('./getdisplaymedia');
312
+
313
+ Object.defineProperty(exports, 'shimGetDisplayMedia', {
314
+ enumerable: true,
315
+ get: function get() {
316
+ return _getdisplaymedia.shimGetDisplayMedia;
317
+ }
318
+ });
319
+ exports.shimMediaStream = shimMediaStream;
320
+ exports.shimOnTrack = shimOnTrack;
321
+ exports.shimGetSendersWithDtmf = shimGetSendersWithDtmf;
322
+ exports.shimGetStats = shimGetStats;
323
+ exports.shimSenderReceiverGetStats = shimSenderReceiverGetStats;
324
+ exports.shimAddTrackRemoveTrackWithNative = shimAddTrackRemoveTrackWithNative;
325
+ exports.shimAddTrackRemoveTrack = shimAddTrackRemoveTrack;
326
+ exports.shimPeerConnection = shimPeerConnection;
327
+ exports.fixNegotiationNeeded = fixNegotiationNeeded;
328
+
329
+ var _utils = require('../utils.js');
330
+
331
+ var utils = _interopRequireWildcard(_utils);
332
+
333
+ function _interopRequireWildcard(obj) {
334
+ if (obj && obj.__esModule) {
335
+ return obj;
336
+ } else {
337
+ var newObj = {};
338
+ if (obj != null) {
339
+ for (var key in obj) {
340
+ if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
341
+ }
342
+ }
343
+ newObj.default = obj;
344
+ return newObj;
345
+ }
346
+ }
347
+
348
+ function _defineProperty(obj, key, value) {
349
+ if (key in obj) {
350
+ Object.defineProperty(obj, key, {
351
+ value: value,
352
+ enumerable: true,
353
+ configurable: true,
354
+ writable: true
355
+ });
356
+ } else {
357
+ obj[key] = value;
358
+ }
359
+ return obj;
360
+ }
361
+
362
+ function shimMediaStream(window) {
363
+ window.MediaStream = window.MediaStream || window.webkitMediaStream;
364
+ }
365
+
366
+ function shimOnTrack(window) {
367
+ if (
368
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' &&
369
+ window.RTCPeerConnection &&
370
+ !('ontrack' in window.RTCPeerConnection.prototype)
371
+ ) {
372
+ Object.defineProperty(window.RTCPeerConnection.prototype, 'ontrack', {
373
+ get: function get() {
374
+ return this._ontrack;
375
+ },
376
+ set: function set(f) {
377
+ if (this._ontrack) {
378
+ this.removeEventListener('track', this._ontrack);
379
+ }
380
+ this.addEventListener('track', (this._ontrack = f));
381
+ },
382
+
383
+ enumerable: true,
384
+ configurable: true
385
+ });
386
+ var origSetRemoteDescription =
387
+ window.RTCPeerConnection.prototype.setRemoteDescription;
388
+ window.RTCPeerConnection.prototype.setRemoteDescription =
389
+ function setRemoteDescription() {
390
+ var _this = this;
391
+
392
+ if (!this._ontrackpoly) {
393
+ this._ontrackpoly = function (e) {
394
+ // onaddstream does not fire when a track is added to an existing
395
+ // stream. But stream.onaddtrack is implemented so we use that.
396
+ e.stream.addEventListener('addtrack', function (te) {
397
+ var receiver = void 0;
398
+ if (window.RTCPeerConnection.prototype.getReceivers) {
399
+ receiver = _this.getReceivers().find(function (r) {
400
+ return r.track && r.track.id === te.track.id;
401
+ });
402
+ } else {
403
+ receiver = { track: te.track };
404
+ }
405
+
406
+ var event = new Event('track');
407
+ event.track = te.track;
408
+ event.receiver = receiver;
409
+ event.transceiver = { receiver: receiver };
410
+ event.streams = [e.stream];
411
+ _this.dispatchEvent(event);
412
+ });
413
+ e.stream.getTracks().forEach(function (track) {
414
+ var receiver = void 0;
415
+ if (window.RTCPeerConnection.prototype.getReceivers) {
416
+ receiver = _this.getReceivers().find(function (r) {
417
+ return r.track && r.track.id === track.id;
418
+ });
419
+ } else {
420
+ receiver = { track: track };
421
+ }
422
+ var event = new Event('track');
423
+ event.track = track;
424
+ event.receiver = receiver;
425
+ event.transceiver = { receiver: receiver };
426
+ event.streams = [e.stream];
427
+ _this.dispatchEvent(event);
428
+ });
429
+ };
430
+ this.addEventListener('addstream', this._ontrackpoly);
431
+ }
432
+ return origSetRemoteDescription.apply(this, arguments);
433
+ };
434
+ } else {
435
+ // even if RTCRtpTransceiver is in window, it is only used and
436
+ // emitted in unified-plan. Unfortunately this means we need
437
+ // to unconditionally wrap the event.
438
+ utils.wrapPeerConnectionEvent(window, 'track', function (e) {
439
+ if (!e.transceiver) {
440
+ Object.defineProperty(e, 'transceiver', { value: { receiver: e.receiver } });
441
+ }
442
+ return e;
443
+ });
444
+ }
445
+ }
446
+
447
+ function shimGetSendersWithDtmf(window) {
448
+ // Overrides addTrack/removeTrack, depends on shimAddTrackRemoveTrack.
449
+ if (
450
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' &&
451
+ window.RTCPeerConnection &&
452
+ !('getSenders' in window.RTCPeerConnection.prototype) &&
453
+ 'createDTMFSender' in window.RTCPeerConnection.prototype
454
+ ) {
455
+ var shimSenderWithDtmf = function shimSenderWithDtmf(pc, track) {
456
+ return {
457
+ track: track,
458
+ get dtmf() {
459
+ if (this._dtmf === undefined) {
460
+ if (track.kind === 'audio') {
461
+ this._dtmf = pc.createDTMFSender(track);
462
+ } else {
463
+ this._dtmf = null;
464
+ }
465
+ }
466
+ return this._dtmf;
467
+ },
468
+ _pc: pc
469
+ };
470
+ };
471
+
472
+ // augment addTrack when getSenders is not available.
473
+ if (!window.RTCPeerConnection.prototype.getSenders) {
474
+ window.RTCPeerConnection.prototype.getSenders = function getSenders() {
475
+ this._senders = this._senders || [];
476
+ return this._senders.slice(); // return a copy of the internal state.
477
+ };
478
+ var origAddTrack = window.RTCPeerConnection.prototype.addTrack;
479
+ window.RTCPeerConnection.prototype.addTrack = function addTrack(track, stream) {
480
+ var sender = origAddTrack.apply(this, arguments);
481
+ if (!sender) {
482
+ sender = shimSenderWithDtmf(this, track);
483
+ this._senders.push(sender);
484
+ }
485
+ return sender;
486
+ };
487
+
488
+ var origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;
489
+ window.RTCPeerConnection.prototype.removeTrack = function removeTrack(sender) {
490
+ origRemoveTrack.apply(this, arguments);
491
+ var idx = this._senders.indexOf(sender);
492
+ if (idx !== -1) {
493
+ this._senders.splice(idx, 1);
494
+ }
495
+ };
496
+ }
497
+ var origAddStream = window.RTCPeerConnection.prototype.addStream;
498
+ window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
499
+ var _this2 = this;
500
+
501
+ this._senders = this._senders || [];
502
+ origAddStream.apply(this, [stream]);
503
+ stream.getTracks().forEach(function (track) {
504
+ _this2._senders.push(shimSenderWithDtmf(_this2, track));
505
+ });
506
+ };
507
+
508
+ var origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
509
+ window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
510
+ var _this3 = this;
511
+
512
+ this._senders = this._senders || [];
513
+ origRemoveStream.apply(this, [stream]);
514
+
515
+ stream.getTracks().forEach(function (track) {
516
+ var sender = _this3._senders.find(function (s) {
517
+ return s.track === track;
518
+ });
519
+ if (sender) {
520
+ // remove sender
521
+ _this3._senders.splice(_this3._senders.indexOf(sender), 1);
522
+ }
523
+ });
524
+ };
525
+ } else if (
526
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' &&
527
+ window.RTCPeerConnection &&
528
+ 'getSenders' in window.RTCPeerConnection.prototype &&
529
+ 'createDTMFSender' in window.RTCPeerConnection.prototype &&
530
+ window.RTCRtpSender &&
531
+ !('dtmf' in window.RTCRtpSender.prototype)
532
+ ) {
533
+ var origGetSenders = window.RTCPeerConnection.prototype.getSenders;
534
+ window.RTCPeerConnection.prototype.getSenders = function getSenders() {
535
+ var _this4 = this;
536
+
537
+ var senders = origGetSenders.apply(this, []);
538
+ senders.forEach(function (sender) {
539
+ return (sender._pc = _this4);
540
+ });
541
+ return senders;
542
+ };
543
+
544
+ Object.defineProperty(window.RTCRtpSender.prototype, 'dtmf', {
545
+ get: function get() {
546
+ if (this._dtmf === undefined) {
547
+ if (this.track.kind === 'audio') {
548
+ this._dtmf = this._pc.createDTMFSender(this.track);
549
+ } else {
550
+ this._dtmf = null;
551
+ }
552
+ }
553
+ return this._dtmf;
554
+ }
555
+ });
556
+ }
557
+ }
558
+
559
+ function shimGetStats(window) {
560
+ if (!window.RTCPeerConnection) {
561
+ return;
562
+ }
563
+
564
+ var origGetStats = window.RTCPeerConnection.prototype.getStats;
565
+ window.RTCPeerConnection.prototype.getStats = function getStats() {
566
+ var _this5 = this;
567
+
568
+ var _arguments = Array.prototype.slice.call(arguments),
569
+ selector = _arguments[0],
570
+ onSucc = _arguments[1],
571
+ onErr = _arguments[2];
572
+
573
+ // If selector is a function then we are in the old style stats so just
574
+ // pass back the original getStats format to avoid breaking old users.
575
+
576
+ if (arguments.length > 0 && typeof selector === 'function') {
577
+ return origGetStats.apply(this, arguments);
578
+ }
579
+
580
+ // When spec-style getStats is supported, return those when called with
581
+ // either no arguments or the selector argument is null.
582
+ if (
583
+ origGetStats.length === 0 &&
584
+ (arguments.length === 0 || typeof selector !== 'function')
585
+ ) {
586
+ return origGetStats.apply(this, []);
587
+ }
588
+
589
+ var fixChromeStats_ = function fixChromeStats_(response) {
590
+ var standardReport = {};
591
+ var reports = response.result();
592
+ reports.forEach(function (report) {
593
+ var standardStats = {
594
+ id: report.id,
595
+ timestamp: report.timestamp,
596
+ type:
597
+ {
598
+ localcandidate: 'local-candidate',
599
+ remotecandidate: 'remote-candidate'
600
+ }[report.type] || report.type
601
+ };
602
+ report.names().forEach(function (name) {
603
+ standardStats[name] = report.stat(name);
604
+ });
605
+ standardReport[standardStats.id] = standardStats;
606
+ });
607
+
608
+ return standardReport;
609
+ };
610
+
611
+ // shim getStats with maplike support
612
+ var makeMapStats = function makeMapStats(stats) {
613
+ return new Map(
614
+ Object.keys(stats).map(function (key) {
615
+ return [key, stats[key]];
616
+ })
617
+ );
618
+ };
619
+
620
+ if (arguments.length >= 2) {
621
+ var successCallbackWrapper_ = function successCallbackWrapper_(response) {
622
+ onSucc(makeMapStats(fixChromeStats_(response)));
623
+ };
624
+
625
+ return origGetStats.apply(this, [successCallbackWrapper_, selector]);
626
+ }
627
+
628
+ // promise-support
629
+ return new Promise(function (resolve, reject) {
630
+ origGetStats.apply(_this5, [
631
+ function (response) {
632
+ resolve(makeMapStats(fixChromeStats_(response)));
633
+ },
634
+ reject
635
+ ]);
636
+ }).then(onSucc, onErr);
637
+ };
638
+ }
639
+
640
+ function shimSenderReceiverGetStats(window) {
641
+ if (
642
+ !(
643
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' &&
644
+ window.RTCPeerConnection &&
645
+ window.RTCRtpSender &&
646
+ window.RTCRtpReceiver
647
+ )
648
+ ) {
649
+ return;
650
+ }
651
+
652
+ // shim sender stats.
653
+ if (!('getStats' in window.RTCRtpSender.prototype)) {
654
+ var origGetSenders = window.RTCPeerConnection.prototype.getSenders;
655
+ if (origGetSenders) {
656
+ window.RTCPeerConnection.prototype.getSenders = function getSenders() {
657
+ var _this6 = this;
658
+
659
+ var senders = origGetSenders.apply(this, []);
660
+ senders.forEach(function (sender) {
661
+ return (sender._pc = _this6);
662
+ });
663
+ return senders;
664
+ };
665
+ }
666
+
667
+ var origAddTrack = window.RTCPeerConnection.prototype.addTrack;
668
+ if (origAddTrack) {
669
+ window.RTCPeerConnection.prototype.addTrack = function addTrack() {
670
+ var sender = origAddTrack.apply(this, arguments);
671
+ sender._pc = this;
672
+ return sender;
673
+ };
674
+ }
675
+ window.RTCRtpSender.prototype.getStats = function getStats() {
676
+ var sender = this;
677
+ return this._pc.getStats().then(function (result) {
678
+ return (
679
+ /* Note: this will include stats of all senders that
680
+ * send a track with the same id as sender.track as
681
+ * it is not possible to identify the RTCRtpSender.
682
+ */
683
+ utils.filterStats(result, sender.track, true)
684
+ );
685
+ });
686
+ };
687
+ }
688
+
689
+ // shim receiver stats.
690
+ if (!('getStats' in window.RTCRtpReceiver.prototype)) {
691
+ var origGetReceivers = window.RTCPeerConnection.prototype.getReceivers;
692
+ if (origGetReceivers) {
693
+ window.RTCPeerConnection.prototype.getReceivers = function getReceivers() {
694
+ var _this7 = this;
695
+
696
+ var receivers = origGetReceivers.apply(this, []);
697
+ receivers.forEach(function (receiver) {
698
+ return (receiver._pc = _this7);
699
+ });
700
+ return receivers;
701
+ };
702
+ }
703
+ utils.wrapPeerConnectionEvent(window, 'track', function (e) {
704
+ e.receiver._pc = e.srcElement;
705
+ return e;
706
+ });
707
+ window.RTCRtpReceiver.prototype.getStats = function getStats() {
708
+ var receiver = this;
709
+ return this._pc.getStats().then(function (result) {
710
+ return utils.filterStats(result, receiver.track, false);
711
+ });
712
+ };
713
+ }
714
+
715
+ if (
716
+ !(
717
+ 'getStats' in window.RTCRtpSender.prototype &&
718
+ 'getStats' in window.RTCRtpReceiver.prototype
719
+ )
720
+ ) {
721
+ return;
722
+ }
723
+
724
+ // shim RTCPeerConnection.getStats(track).
725
+ var origGetStats = window.RTCPeerConnection.prototype.getStats;
726
+ window.RTCPeerConnection.prototype.getStats = function getStats() {
727
+ if (arguments.length > 0 && arguments[0] instanceof window.MediaStreamTrack) {
728
+ var track = arguments[0];
729
+ var sender = void 0;
730
+ var receiver = void 0;
731
+ var err = void 0;
732
+ this.getSenders().forEach(function (s) {
733
+ if (s.track === track) {
734
+ if (sender) {
735
+ err = true;
736
+ } else {
737
+ sender = s;
738
+ }
739
+ }
740
+ });
741
+ this.getReceivers().forEach(function (r) {
742
+ if (r.track === track) {
743
+ if (receiver) {
744
+ err = true;
745
+ } else {
746
+ receiver = r;
747
+ }
748
+ }
749
+ return r.track === track;
750
+ });
751
+ if (err || (sender && receiver)) {
752
+ return Promise.reject(
753
+ new DOMException(
754
+ 'There are more than one sender or receiver for the track.',
755
+ 'InvalidAccessError'
756
+ )
757
+ );
758
+ } else if (sender) {
759
+ return sender.getStats();
760
+ } else if (receiver) {
761
+ return receiver.getStats();
762
+ }
763
+ return Promise.reject(
764
+ new DOMException(
765
+ 'There is no sender or receiver for the track.',
766
+ 'InvalidAccessError'
767
+ )
768
+ );
769
+ }
770
+ return origGetStats.apply(this, arguments);
771
+ };
772
+ }
773
+
774
+ function shimAddTrackRemoveTrackWithNative(window) {
775
+ // shim addTrack/removeTrack with native variants in order to make
776
+ // the interactions with legacy getLocalStreams behave as in other browsers.
777
+ // Keeps a mapping stream.id => [stream, rtpsenders...]
778
+ window.RTCPeerConnection.prototype.getLocalStreams = function getLocalStreams() {
779
+ var _this8 = this;
780
+
781
+ this._shimmedLocalStreams = this._shimmedLocalStreams || {};
782
+ return Object.keys(this._shimmedLocalStreams).map(function (streamId) {
783
+ return _this8._shimmedLocalStreams[streamId][0];
784
+ });
785
+ };
786
+
787
+ var origAddTrack = window.RTCPeerConnection.prototype.addTrack;
788
+ window.RTCPeerConnection.prototype.addTrack = function addTrack(track, stream) {
789
+ if (!stream) {
790
+ return origAddTrack.apply(this, arguments);
791
+ }
792
+ this._shimmedLocalStreams = this._shimmedLocalStreams || {};
793
+
794
+ var sender = origAddTrack.apply(this, arguments);
795
+ if (!this._shimmedLocalStreams[stream.id]) {
796
+ this._shimmedLocalStreams[stream.id] = [stream, sender];
797
+ } else if (this._shimmedLocalStreams[stream.id].indexOf(sender) === -1) {
798
+ this._shimmedLocalStreams[stream.id].push(sender);
799
+ }
800
+ return sender;
801
+ };
802
+
803
+ var origAddStream = window.RTCPeerConnection.prototype.addStream;
804
+ window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
805
+ var _this9 = this;
806
+
807
+ this._shimmedLocalStreams = this._shimmedLocalStreams || {};
808
+
809
+ stream.getTracks().forEach(function (track) {
810
+ var alreadyExists = _this9.getSenders().find(function (s) {
811
+ return s.track === track;
812
+ });
813
+ if (alreadyExists) {
814
+ throw new DOMException('Track already exists.', 'InvalidAccessError');
815
+ }
816
+ });
817
+ var existingSenders = this.getSenders();
818
+ origAddStream.apply(this, arguments);
819
+ var newSenders = this.getSenders().filter(function (newSender) {
820
+ return existingSenders.indexOf(newSender) === -1;
821
+ });
822
+ this._shimmedLocalStreams[stream.id] = [stream].concat(newSenders);
823
+ };
824
+
825
+ var origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
826
+ window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
827
+ this._shimmedLocalStreams = this._shimmedLocalStreams || {};
828
+ delete this._shimmedLocalStreams[stream.id];
829
+ return origRemoveStream.apply(this, arguments);
830
+ };
831
+
832
+ var origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;
833
+ window.RTCPeerConnection.prototype.removeTrack = function removeTrack(sender) {
834
+ var _this10 = this;
835
+
836
+ this._shimmedLocalStreams = this._shimmedLocalStreams || {};
837
+ if (sender) {
838
+ Object.keys(this._shimmedLocalStreams).forEach(function (streamId) {
839
+ var idx = _this10._shimmedLocalStreams[streamId].indexOf(sender);
840
+ if (idx !== -1) {
841
+ _this10._shimmedLocalStreams[streamId].splice(idx, 1);
842
+ }
843
+ if (_this10._shimmedLocalStreams[streamId].length === 1) {
844
+ delete _this10._shimmedLocalStreams[streamId];
845
+ }
846
+ });
847
+ }
848
+ return origRemoveTrack.apply(this, arguments);
849
+ };
850
+ }
851
+
852
+ function shimAddTrackRemoveTrack(window, browserDetails) {
853
+ if (!window.RTCPeerConnection) {
854
+ return;
855
+ }
856
+ // shim addTrack and removeTrack.
857
+ if (window.RTCPeerConnection.prototype.addTrack && browserDetails.version >= 65) {
858
+ return shimAddTrackRemoveTrackWithNative(window);
859
+ }
860
+
861
+ // also shim pc.getLocalStreams when addTrack is shimmed
862
+ // to return the original streams.
863
+ var origGetLocalStreams = window.RTCPeerConnection.prototype.getLocalStreams;
864
+ window.RTCPeerConnection.prototype.getLocalStreams = function getLocalStreams() {
865
+ var _this11 = this;
866
+
867
+ var nativeStreams = origGetLocalStreams.apply(this);
868
+ this._reverseStreams = this._reverseStreams || {};
869
+ return nativeStreams.map(function (stream) {
870
+ return _this11._reverseStreams[stream.id];
871
+ });
872
+ };
873
+
874
+ var origAddStream = window.RTCPeerConnection.prototype.addStream;
875
+ window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
876
+ var _this12 = this;
877
+
878
+ this._streams = this._streams || {};
879
+ this._reverseStreams = this._reverseStreams || {};
880
+
881
+ stream.getTracks().forEach(function (track) {
882
+ var alreadyExists = _this12.getSenders().find(function (s) {
883
+ return s.track === track;
884
+ });
885
+ if (alreadyExists) {
886
+ throw new DOMException('Track already exists.', 'InvalidAccessError');
887
+ }
888
+ });
889
+ // Add identity mapping for consistency with addTrack.
890
+ // Unless this is being used with a stream from addTrack.
891
+ if (!this._reverseStreams[stream.id]) {
892
+ var newStream = new window.MediaStream(stream.getTracks());
893
+ this._streams[stream.id] = newStream;
894
+ this._reverseStreams[newStream.id] = stream;
895
+ stream = newStream;
896
+ }
897
+ origAddStream.apply(this, [stream]);
898
+ };
899
+
900
+ var origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
901
+ window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
902
+ this._streams = this._streams || {};
903
+ this._reverseStreams = this._reverseStreams || {};
904
+
905
+ origRemoveStream.apply(this, [this._streams[stream.id] || stream]);
906
+ delete this._reverseStreams[
907
+ this._streams[stream.id] ? this._streams[stream.id].id : stream.id
908
+ ];
909
+ delete this._streams[stream.id];
910
+ };
911
+
912
+ window.RTCPeerConnection.prototype.addTrack = function addTrack(track, stream) {
913
+ var _this13 = this;
914
+
915
+ if (this.signalingState === 'closed') {
916
+ throw new DOMException(
917
+ "The RTCPeerConnection's signalingState is 'closed'.",
918
+ 'InvalidStateError'
919
+ );
920
+ }
921
+ var streams = [].slice.call(arguments, 1);
922
+ if (
923
+ streams.length !== 1 ||
924
+ !streams[0].getTracks().find(function (t) {
925
+ return t === track;
926
+ })
927
+ ) {
928
+ // this is not fully correct but all we can manage without
929
+ // [[associated MediaStreams]] internal slot.
930
+ throw new DOMException(
931
+ 'The adapter.js addTrack polyfill only supports a single ' +
932
+ ' stream which is associated with the specified track.',
933
+ 'NotSupportedError'
934
+ );
935
+ }
936
+
937
+ var alreadyExists = this.getSenders().find(function (s) {
938
+ return s.track === track;
939
+ });
940
+ if (alreadyExists) {
941
+ throw new DOMException('Track already exists.', 'InvalidAccessError');
942
+ }
943
+
944
+ this._streams = this._streams || {};
945
+ this._reverseStreams = this._reverseStreams || {};
946
+ var oldStream = this._streams[stream.id];
947
+ if (oldStream) {
948
+ // this is using odd Chrome behaviour, use with caution:
949
+ // https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
950
+ // Note: we rely on the high-level addTrack/dtmf shim to
951
+ // create the sender with a dtmf sender.
952
+ oldStream.addTrack(track);
953
+
954
+ // Trigger ONN async.
955
+ Promise.resolve().then(function () {
956
+ _this13.dispatchEvent(new Event('negotiationneeded'));
957
+ });
958
+ } else {
959
+ var newStream = new window.MediaStream([track]);
960
+ this._streams[stream.id] = newStream;
961
+ this._reverseStreams[newStream.id] = stream;
962
+ this.addStream(newStream);
963
+ }
964
+ return this.getSenders().find(function (s) {
965
+ return s.track === track;
966
+ });
967
+ };
968
+
969
+ // replace the internal stream id with the external one and
970
+ // vice versa.
971
+ function replaceInternalStreamId(pc, description) {
972
+ var sdp = description.sdp;
973
+ Object.keys(pc._reverseStreams || []).forEach(function (internalId) {
974
+ var externalStream = pc._reverseStreams[internalId];
975
+ var internalStream = pc._streams[externalStream.id];
976
+ sdp = sdp.replace(new RegExp(internalStream.id, 'g'), externalStream.id);
977
+ });
978
+ return new RTCSessionDescription({
979
+ type: description.type,
980
+ sdp: sdp
981
+ });
982
+ }
983
+ function replaceExternalStreamId(pc, description) {
984
+ var sdp = description.sdp;
985
+ Object.keys(pc._reverseStreams || []).forEach(function (internalId) {
986
+ var externalStream = pc._reverseStreams[internalId];
987
+ var internalStream = pc._streams[externalStream.id];
988
+ sdp = sdp.replace(new RegExp(externalStream.id, 'g'), internalStream.id);
989
+ });
990
+ return new RTCSessionDescription({
991
+ type: description.type,
992
+ sdp: sdp
993
+ });
994
+ }
995
+ ['createOffer', 'createAnswer'].forEach(function (method) {
996
+ var nativeMethod = window.RTCPeerConnection.prototype[method];
997
+ var methodObj = _defineProperty({}, method, function () {
998
+ var _this14 = this;
999
+
1000
+ var args = arguments;
1001
+ var isLegacyCall = arguments.length && typeof arguments[0] === 'function';
1002
+ if (isLegacyCall) {
1003
+ return nativeMethod.apply(this, [
1004
+ function (description) {
1005
+ var desc = replaceInternalStreamId(_this14, description);
1006
+ args[0].apply(null, [desc]);
1007
+ },
1008
+ function (err) {
1009
+ if (args[1]) {
1010
+ args[1].apply(null, err);
1011
+ }
1012
+ },
1013
+ arguments[2]
1014
+ ]);
1015
+ }
1016
+ return nativeMethod.apply(this, arguments).then(function (description) {
1017
+ return replaceInternalStreamId(_this14, description);
1018
+ });
1019
+ });
1020
+ window.RTCPeerConnection.prototype[method] = methodObj[method];
1021
+ });
1022
+
1023
+ var origSetLocalDescription = window.RTCPeerConnection.prototype.setLocalDescription;
1024
+ window.RTCPeerConnection.prototype.setLocalDescription =
1025
+ function setLocalDescription() {
1026
+ if (!arguments.length || !arguments[0].type) {
1027
+ return origSetLocalDescription.apply(this, arguments);
1028
+ }
1029
+ arguments[0] = replaceExternalStreamId(this, arguments[0]);
1030
+ return origSetLocalDescription.apply(this, arguments);
1031
+ };
1032
+
1033
+ // TODO: mangle getStats: https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamstats-streamidentifier
1034
+
1035
+ var origLocalDescription = Object.getOwnPropertyDescriptor(
1036
+ window.RTCPeerConnection.prototype,
1037
+ 'localDescription'
1038
+ );
1039
+ Object.defineProperty(window.RTCPeerConnection.prototype, 'localDescription', {
1040
+ get: function get() {
1041
+ var description = origLocalDescription.get.apply(this);
1042
+ if (description.type === '') {
1043
+ return description;
1044
+ }
1045
+ return replaceInternalStreamId(this, description);
1046
+ }
1047
+ });
1048
+
1049
+ window.RTCPeerConnection.prototype.removeTrack = function removeTrack(sender) {
1050
+ var _this15 = this;
1051
+
1052
+ if (this.signalingState === 'closed') {
1053
+ throw new DOMException(
1054
+ "The RTCPeerConnection's signalingState is 'closed'.",
1055
+ 'InvalidStateError'
1056
+ );
1057
+ }
1058
+ // We can not yet check for sender instanceof RTCRtpSender
1059
+ // since we shim RTPSender. So we check if sender._pc is set.
1060
+ if (!sender._pc) {
1061
+ throw new DOMException(
1062
+ 'Argument 1 of RTCPeerConnection.removeTrack ' +
1063
+ 'does not implement interface RTCRtpSender.',
1064
+ 'TypeError'
1065
+ );
1066
+ }
1067
+ var isLocal = sender._pc === this;
1068
+ if (!isLocal) {
1069
+ throw new DOMException(
1070
+ 'Sender was not created by this connection.',
1071
+ 'InvalidAccessError'
1072
+ );
1073
+ }
1074
+
1075
+ // Search for the native stream the senders track belongs to.
1076
+ this._streams = this._streams || {};
1077
+ var stream = void 0;
1078
+ Object.keys(this._streams).forEach(function (streamid) {
1079
+ var hasTrack = _this15._streams[streamid].getTracks().find(function (track) {
1080
+ return sender.track === track;
1081
+ });
1082
+ if (hasTrack) {
1083
+ stream = _this15._streams[streamid];
1084
+ }
1085
+ });
1086
+
1087
+ if (stream) {
1088
+ if (stream.getTracks().length === 1) {
1089
+ // if this is the last track of the stream, remove the stream. This
1090
+ // takes care of any shimmed _senders.
1091
+ this.removeStream(this._reverseStreams[stream.id]);
1092
+ } else {
1093
+ // relying on the same odd chrome behaviour as above.
1094
+ stream.removeTrack(sender.track);
1095
+ }
1096
+ this.dispatchEvent(new Event('negotiationneeded'));
1097
+ }
1098
+ };
1099
+ }
1100
+
1101
+ function shimPeerConnection(window, browserDetails) {
1102
+ if (!window.RTCPeerConnection && window.webkitRTCPeerConnection) {
1103
+ // very basic support for old versions.
1104
+ window.RTCPeerConnection = window.webkitRTCPeerConnection;
1105
+ }
1106
+ if (!window.RTCPeerConnection) {
1107
+ return;
1108
+ }
1109
+
1110
+ // shim implicit creation of RTCSessionDescription/RTCIceCandidate
1111
+ if (browserDetails.version < 53) {
1112
+ ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate'].forEach(function (
1113
+ method
1114
+ ) {
1115
+ var nativeMethod = window.RTCPeerConnection.prototype[method];
1116
+ var methodObj = _defineProperty({}, method, function () {
1117
+ arguments[0] = new (
1118
+ method === 'addIceCandidate'
1119
+ ? window.RTCIceCandidate
1120
+ : window.RTCSessionDescription
1121
+ )(arguments[0]);
1122
+ return nativeMethod.apply(this, arguments);
1123
+ });
1124
+ window.RTCPeerConnection.prototype[method] = methodObj[method];
1125
+ });
1126
+ }
1127
+ }
1128
+
1129
+ // Attempt to fix ONN in plan-b mode.
1130
+ function fixNegotiationNeeded(window, browserDetails) {
1131
+ utils.wrapPeerConnectionEvent(window, 'negotiationneeded', function (e) {
1132
+ var pc = e.target;
1133
+ if (
1134
+ browserDetails.version < 72 ||
1135
+ (pc.getConfiguration && pc.getConfiguration().sdpSemantics === 'plan-b')
1136
+ ) {
1137
+ if (pc.signalingState !== 'stable') {
1138
+ return;
1139
+ }
1140
+ }
1141
+ return e;
1142
+ });
1143
+ }
1144
+ },
1145
+ { '../utils.js': 11, './getdisplaymedia': 4, './getusermedia': 5 }
1146
+ ],
1147
+ 4: [
1148
+ function (require, module, exports) {
1149
+ /*
1150
+ * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved.
1151
+ *
1152
+ * Use of this source code is governed by a BSD-style license
1153
+ * that can be found in the LICENSE file in the root of the source
1154
+ * tree.
1155
+ */
1156
+ /* eslint-env node */
1157
+ 'use strict';
1158
+
1159
+ Object.defineProperty(exports, '__esModule', {
1160
+ value: true
1161
+ });
1162
+ exports.shimGetDisplayMedia = shimGetDisplayMedia;
1163
+ function shimGetDisplayMedia(window, getSourceId) {
1164
+ if (
1165
+ window.navigator.mediaDevices &&
1166
+ 'getDisplayMedia' in window.navigator.mediaDevices
1167
+ ) {
1168
+ return;
1169
+ }
1170
+ if (!window.navigator.mediaDevices) {
1171
+ return;
1172
+ }
1173
+ // getSourceId is a function that returns a promise resolving with
1174
+ // the sourceId of the screen/window/tab to be shared.
1175
+ if (typeof getSourceId !== 'function') {
1176
+ console.error('shimGetDisplayMedia: getSourceId argument is not ' + 'a function');
1177
+ return;
1178
+ }
1179
+ window.navigator.mediaDevices.getDisplayMedia = function getDisplayMedia(constraints) {
1180
+ return getSourceId(constraints).then(function (sourceId) {
1181
+ var widthSpecified = constraints.video && constraints.video.width;
1182
+ var heightSpecified = constraints.video && constraints.video.height;
1183
+ var frameRateSpecified = constraints.video && constraints.video.frameRate;
1184
+ constraints.video = {
1185
+ mandatory: {
1186
+ chromeMediaSource: 'desktop',
1187
+ chromeMediaSourceId: sourceId,
1188
+ maxFrameRate: frameRateSpecified || 3
1189
+ }
1190
+ };
1191
+ if (widthSpecified) {
1192
+ constraints.video.mandatory.maxWidth = widthSpecified;
1193
+ }
1194
+ if (heightSpecified) {
1195
+ constraints.video.mandatory.maxHeight = heightSpecified;
1196
+ }
1197
+ return window.navigator.mediaDevices.getUserMedia(constraints);
1198
+ });
1199
+ };
1200
+ }
1201
+ },
1202
+ {}
1203
+ ],
1204
+ 5: [
1205
+ function (require, module, exports) {
1206
+ /*
1207
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
1208
+ *
1209
+ * Use of this source code is governed by a BSD-style license
1210
+ * that can be found in the LICENSE file in the root of the source
1211
+ * tree.
1212
+ */
1213
+ /* eslint-env node */
1214
+ 'use strict';
1215
+
1216
+ Object.defineProperty(exports, '__esModule', {
1217
+ value: true
1218
+ });
1219
+
1220
+ var _typeof =
1221
+ typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
1222
+ ? function (obj) {
1223
+ return typeof obj;
1224
+ }
1225
+ : function (obj) {
1226
+ return obj &&
1227
+ typeof Symbol === 'function' &&
1228
+ obj.constructor === Symbol &&
1229
+ obj !== Symbol.prototype
1230
+ ? 'symbol'
1231
+ : typeof obj;
1232
+ };
1233
+
1234
+ exports.shimGetUserMedia = shimGetUserMedia;
1235
+
1236
+ var _utils = require('../utils.js');
1237
+
1238
+ var utils = _interopRequireWildcard(_utils);
1239
+
1240
+ function _interopRequireWildcard(obj) {
1241
+ if (obj && obj.__esModule) {
1242
+ return obj;
1243
+ } else {
1244
+ var newObj = {};
1245
+ if (obj != null) {
1246
+ for (var key in obj) {
1247
+ if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
1248
+ }
1249
+ }
1250
+ newObj.default = obj;
1251
+ return newObj;
1252
+ }
1253
+ }
1254
+
1255
+ var logging = utils.log;
1256
+
1257
+ function shimGetUserMedia(window, browserDetails) {
1258
+ var navigator = window && window.navigator;
1259
+
1260
+ if (!navigator.mediaDevices) {
1261
+ return;
1262
+ }
1263
+
1264
+ var constraintsToChrome_ = function constraintsToChrome_(c) {
1265
+ if (
1266
+ (typeof c === 'undefined' ? 'undefined' : _typeof(c)) !== 'object' ||
1267
+ c.mandatory ||
1268
+ c.optional
1269
+ ) {
1270
+ return c;
1271
+ }
1272
+ var cc = {};
1273
+ Object.keys(c).forEach(function (key) {
1274
+ if (key === 'require' || key === 'advanced' || key === 'mediaSource') {
1275
+ return;
1276
+ }
1277
+ var r = _typeof(c[key]) === 'object' ? c[key] : { ideal: c[key] };
1278
+ if (r.exact !== undefined && typeof r.exact === 'number') {
1279
+ r.min = r.max = r.exact;
1280
+ }
1281
+ var oldname_ = function oldname_(prefix, name) {
1282
+ if (prefix) {
1283
+ return prefix + name.charAt(0).toUpperCase() + name.slice(1);
1284
+ }
1285
+ return name === 'deviceId' ? 'sourceId' : name;
1286
+ };
1287
+ if (r.ideal !== undefined) {
1288
+ cc.optional = cc.optional || [];
1289
+ var oc = {};
1290
+ if (typeof r.ideal === 'number') {
1291
+ oc[oldname_('min', key)] = r.ideal;
1292
+ cc.optional.push(oc);
1293
+ oc = {};
1294
+ oc[oldname_('max', key)] = r.ideal;
1295
+ cc.optional.push(oc);
1296
+ } else {
1297
+ oc[oldname_('', key)] = r.ideal;
1298
+ cc.optional.push(oc);
1299
+ }
1300
+ }
1301
+ if (r.exact !== undefined && typeof r.exact !== 'number') {
1302
+ cc.mandatory = cc.mandatory || {};
1303
+ cc.mandatory[oldname_('', key)] = r.exact;
1304
+ } else {
1305
+ ['min', 'max'].forEach(function (mix) {
1306
+ if (r[mix] !== undefined) {
1307
+ cc.mandatory = cc.mandatory || {};
1308
+ cc.mandatory[oldname_(mix, key)] = r[mix];
1309
+ }
1310
+ });
1311
+ }
1312
+ });
1313
+ if (c.advanced) {
1314
+ cc.optional = (cc.optional || []).concat(c.advanced);
1315
+ }
1316
+ return cc;
1317
+ };
1318
+
1319
+ var shimConstraints_ = function shimConstraints_(constraints, func) {
1320
+ if (browserDetails.version >= 61) {
1321
+ return func(constraints);
1322
+ }
1323
+ constraints = JSON.parse(JSON.stringify(constraints));
1324
+ if (constraints && _typeof(constraints.audio) === 'object') {
1325
+ var remap = function remap(obj, a, b) {
1326
+ if (a in obj && !(b in obj)) {
1327
+ obj[b] = obj[a];
1328
+ delete obj[a];
1329
+ }
1330
+ };
1331
+ constraints = JSON.parse(JSON.stringify(constraints));
1332
+ remap(constraints.audio, 'autoGainControl', 'googAutoGainControl');
1333
+ remap(constraints.audio, 'noiseSuppression', 'googNoiseSuppression');
1334
+ constraints.audio = constraintsToChrome_(constraints.audio);
1335
+ }
1336
+ if (constraints && _typeof(constraints.video) === 'object') {
1337
+ // Shim facingMode for mobile & surface pro.
1338
+ var face = constraints.video.facingMode;
1339
+ face =
1340
+ face &&
1341
+ ((typeof face === 'undefined' ? 'undefined' : _typeof(face)) === 'object'
1342
+ ? face
1343
+ : { ideal: face });
1344
+ var getSupportedFacingModeLies = browserDetails.version < 66;
1345
+
1346
+ if (
1347
+ face &&
1348
+ (face.exact === 'user' ||
1349
+ face.exact === 'environment' ||
1350
+ face.ideal === 'user' ||
1351
+ face.ideal === 'environment') &&
1352
+ !(
1353
+ navigator.mediaDevices.getSupportedConstraints &&
1354
+ navigator.mediaDevices.getSupportedConstraints().facingMode &&
1355
+ !getSupportedFacingModeLies
1356
+ )
1357
+ ) {
1358
+ delete constraints.video.facingMode;
1359
+ var matches = void 0;
1360
+ if (face.exact === 'environment' || face.ideal === 'environment') {
1361
+ matches = ['back', 'rear'];
1362
+ } else if (face.exact === 'user' || face.ideal === 'user') {
1363
+ matches = ['front'];
1364
+ }
1365
+ if (matches) {
1366
+ // Look for matches in label, or use last cam for back (typical).
1367
+ return navigator.mediaDevices.enumerateDevices().then(function (devices) {
1368
+ devices = devices.filter(function (d) {
1369
+ return d.kind === 'videoinput';
1370
+ });
1371
+ var dev = devices.find(function (d) {
1372
+ return matches.some(function (match) {
1373
+ return d.label.toLowerCase().includes(match);
1374
+ });
1375
+ });
1376
+ if (!dev && devices.length && matches.includes('back')) {
1377
+ dev = devices[devices.length - 1]; // more likely the back cam
1378
+ }
1379
+ if (dev) {
1380
+ constraints.video.deviceId = face.exact
1381
+ ? { exact: dev.deviceId }
1382
+ : { ideal: dev.deviceId };
1383
+ }
1384
+ constraints.video = constraintsToChrome_(constraints.video);
1385
+ logging('chrome: ' + JSON.stringify(constraints));
1386
+ return func(constraints);
1387
+ });
1388
+ }
1389
+ }
1390
+ constraints.video = constraintsToChrome_(constraints.video);
1391
+ }
1392
+ logging('chrome: ' + JSON.stringify(constraints));
1393
+ return func(constraints);
1394
+ };
1395
+
1396
+ var shimError_ = function shimError_(e) {
1397
+ if (browserDetails.version >= 64) {
1398
+ return e;
1399
+ }
1400
+ return {
1401
+ name:
1402
+ {
1403
+ PermissionDeniedError: 'NotAllowedError',
1404
+ PermissionDismissedError: 'NotAllowedError',
1405
+ InvalidStateError: 'NotAllowedError',
1406
+ DevicesNotFoundError: 'NotFoundError',
1407
+ ConstraintNotSatisfiedError: 'OverconstrainedError',
1408
+ TrackStartError: 'NotReadableError',
1409
+ MediaDeviceFailedDueToShutdown: 'NotAllowedError',
1410
+ MediaDeviceKillSwitchOn: 'NotAllowedError',
1411
+ TabCaptureError: 'AbortError',
1412
+ ScreenCaptureError: 'AbortError',
1413
+ DeviceCaptureError: 'AbortError'
1414
+ }[e.name] || e.name,
1415
+ message: e.message,
1416
+ constraint: e.constraint || e.constraintName,
1417
+ toString: function toString() {
1418
+ return this.name + (this.message && ': ') + this.message;
1419
+ }
1420
+ };
1421
+ };
1422
+
1423
+ var getUserMedia_ = function getUserMedia_(constraints, onSuccess, onError) {
1424
+ shimConstraints_(constraints, function (c) {
1425
+ navigator.webkitGetUserMedia(c, onSuccess, function (e) {
1426
+ if (onError) {
1427
+ onError(shimError_(e));
1428
+ }
1429
+ });
1430
+ });
1431
+ };
1432
+ navigator.getUserMedia = getUserMedia_.bind(navigator);
1433
+
1434
+ // Even though Chrome 45 has navigator.mediaDevices and a getUserMedia
1435
+ // function which returns a Promise, it does not accept spec-style
1436
+ // constraints.
1437
+ if (navigator.mediaDevices.getUserMedia) {
1438
+ var origGetUserMedia = navigator.mediaDevices.getUserMedia.bind(
1439
+ navigator.mediaDevices
1440
+ );
1441
+ navigator.mediaDevices.getUserMedia = function (cs) {
1442
+ return shimConstraints_(cs, function (c) {
1443
+ return origGetUserMedia(c).then(
1444
+ function (stream) {
1445
+ if (
1446
+ (c.audio && !stream.getAudioTracks().length) ||
1447
+ (c.video && !stream.getVideoTracks().length)
1448
+ ) {
1449
+ stream.getTracks().forEach(function (track) {
1450
+ track.stop();
1451
+ });
1452
+ throw new DOMException('', 'NotFoundError');
1453
+ }
1454
+ return stream;
1455
+ },
1456
+ function (e) {
1457
+ return Promise.reject(shimError_(e));
1458
+ }
1459
+ );
1460
+ });
1461
+ };
1462
+ }
1463
+ }
1464
+ },
1465
+ { '../utils.js': 11 }
1466
+ ],
1467
+ 6: [
1468
+ function (require, module, exports) {
1469
+ /*
1470
+ * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
1471
+ *
1472
+ * Use of this source code is governed by a BSD-style license
1473
+ * that can be found in the LICENSE file in the root of the source
1474
+ * tree.
1475
+ */
1476
+ /* eslint-env node */
1477
+ 'use strict';
1478
+
1479
+ Object.defineProperty(exports, '__esModule', {
1480
+ value: true
1481
+ });
1482
+
1483
+ var _typeof =
1484
+ typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
1485
+ ? function (obj) {
1486
+ return typeof obj;
1487
+ }
1488
+ : function (obj) {
1489
+ return obj &&
1490
+ typeof Symbol === 'function' &&
1491
+ obj.constructor === Symbol &&
1492
+ obj !== Symbol.prototype
1493
+ ? 'symbol'
1494
+ : typeof obj;
1495
+ };
1496
+
1497
+ exports.shimRTCIceCandidate = shimRTCIceCandidate;
1498
+ exports.shimMaxMessageSize = shimMaxMessageSize;
1499
+ exports.shimSendThrowTypeError = shimSendThrowTypeError;
1500
+ exports.shimConnectionState = shimConnectionState;
1501
+ exports.removeExtmapAllowMixed = removeExtmapAllowMixed;
1502
+ exports.shimAddIceCandidateNullOrEmpty = shimAddIceCandidateNullOrEmpty;
1503
+ exports.shimParameterlessSetLocalDescription = shimParameterlessSetLocalDescription;
1504
+
1505
+ var _sdp = require('sdp');
1506
+
1507
+ var _sdp2 = _interopRequireDefault(_sdp);
1508
+
1509
+ var _utils = require('./utils');
1510
+
1511
+ var utils = _interopRequireWildcard(_utils);
1512
+
1513
+ function _interopRequireWildcard(obj) {
1514
+ if (obj && obj.__esModule) {
1515
+ return obj;
1516
+ } else {
1517
+ var newObj = {};
1518
+ if (obj != null) {
1519
+ for (var key in obj) {
1520
+ if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
1521
+ }
1522
+ }
1523
+ newObj.default = obj;
1524
+ return newObj;
1525
+ }
1526
+ }
1527
+
1528
+ function _interopRequireDefault(obj) {
1529
+ return obj && obj.__esModule ? obj : { default: obj };
1530
+ }
1531
+
1532
+ function shimRTCIceCandidate(window) {
1533
+ // foundation is arbitrarily chosen as an indicator for full support for
1534
+ // https://w3c.github.io/webrtc-pc/#rtcicecandidate-interface
1535
+ if (
1536
+ !window.RTCIceCandidate ||
1537
+ (window.RTCIceCandidate && 'foundation' in window.RTCIceCandidate.prototype)
1538
+ ) {
1539
+ return;
1540
+ }
1541
+
1542
+ var NativeRTCIceCandidate = window.RTCIceCandidate;
1543
+ window.RTCIceCandidate = function RTCIceCandidate(args) {
1544
+ // Remove the a= which shouldn't be part of the candidate string.
1545
+ if (
1546
+ (typeof args === 'undefined' ? 'undefined' : _typeof(args)) === 'object' &&
1547
+ args.candidate &&
1548
+ args.candidate.indexOf('a=') === 0
1549
+ ) {
1550
+ args = JSON.parse(JSON.stringify(args));
1551
+ args.candidate = args.candidate.substr(2);
1552
+ }
1553
+
1554
+ if (args.candidate && args.candidate.length) {
1555
+ // Augment the native candidate with the parsed fields.
1556
+ var nativeCandidate = new NativeRTCIceCandidate(args);
1557
+ var parsedCandidate = _sdp2.default.parseCandidate(args.candidate);
1558
+ var augmentedCandidate = Object.assign(nativeCandidate, parsedCandidate);
1559
+
1560
+ // Add a serializer that does not serialize the extra attributes.
1561
+ augmentedCandidate.toJSON = function toJSON() {
1562
+ return {
1563
+ candidate: augmentedCandidate.candidate,
1564
+ sdpMid: augmentedCandidate.sdpMid,
1565
+ sdpMLineIndex: augmentedCandidate.sdpMLineIndex,
1566
+ usernameFragment: augmentedCandidate.usernameFragment
1567
+ };
1568
+ };
1569
+ return augmentedCandidate;
1570
+ }
1571
+ return new NativeRTCIceCandidate(args);
1572
+ };
1573
+ window.RTCIceCandidate.prototype = NativeRTCIceCandidate.prototype;
1574
+
1575
+ // Hook up the augmented candidate in onicecandidate and
1576
+ // addEventListener('icecandidate', ...)
1577
+ utils.wrapPeerConnectionEvent(window, 'icecandidate', function (e) {
1578
+ if (e.candidate) {
1579
+ Object.defineProperty(e, 'candidate', {
1580
+ value: new window.RTCIceCandidate(e.candidate),
1581
+ writable: 'false'
1582
+ });
1583
+ }
1584
+ return e;
1585
+ });
1586
+ }
1587
+
1588
+ function shimMaxMessageSize(window, browserDetails) {
1589
+ if (!window.RTCPeerConnection) {
1590
+ return;
1591
+ }
1592
+
1593
+ if (!('sctp' in window.RTCPeerConnection.prototype)) {
1594
+ Object.defineProperty(window.RTCPeerConnection.prototype, 'sctp', {
1595
+ get: function get() {
1596
+ return typeof this._sctp === 'undefined' ? null : this._sctp;
1597
+ }
1598
+ });
1599
+ }
1600
+
1601
+ var sctpInDescription = function sctpInDescription(description) {
1602
+ if (!description || !description.sdp) {
1603
+ return false;
1604
+ }
1605
+ var sections = _sdp2.default.splitSections(description.sdp);
1606
+ sections.shift();
1607
+ return sections.some(function (mediaSection) {
1608
+ var mLine = _sdp2.default.parseMLine(mediaSection);
1609
+ return (
1610
+ mLine && mLine.kind === 'application' && mLine.protocol.indexOf('SCTP') !== -1
1611
+ );
1612
+ });
1613
+ };
1614
+
1615
+ var getRemoteFirefoxVersion = function getRemoteFirefoxVersion(description) {
1616
+ // TODO: Is there a better solution for detecting Firefox?
1617
+ var match = description.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);
1618
+ if (match === null || match.length < 2) {
1619
+ return -1;
1620
+ }
1621
+ var version = parseInt(match[1], 10);
1622
+ // Test for NaN (yes, this is ugly)
1623
+ return version !== version ? -1 : version;
1624
+ };
1625
+
1626
+ var getCanSendMaxMessageSize = function getCanSendMaxMessageSize(remoteIsFirefox) {
1627
+ // Every implementation we know can send at least 64 KiB.
1628
+ // Note: Although Chrome is technically able to send up to 256 KiB, the
1629
+ // data does not reach the other peer reliably.
1630
+ // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=8419
1631
+ var canSendMaxMessageSize = 65536;
1632
+ if (browserDetails.browser === 'firefox') {
1633
+ if (browserDetails.version < 57) {
1634
+ if (remoteIsFirefox === -1) {
1635
+ // FF < 57 will send in 16 KiB chunks using the deprecated PPID
1636
+ // fragmentation.
1637
+ canSendMaxMessageSize = 16384;
1638
+ } else {
1639
+ // However, other FF (and RAWRTC) can reassemble PPID-fragmented
1640
+ // messages. Thus, supporting ~2 GiB when sending.
1641
+ canSendMaxMessageSize = 2147483637;
1642
+ }
1643
+ } else if (browserDetails.version < 60) {
1644
+ // Currently, all FF >= 57 will reset the remote maximum message size
1645
+ // to the default value when a data channel is created at a later
1646
+ // stage. :(
1647
+ // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1426831
1648
+ canSendMaxMessageSize = browserDetails.version === 57 ? 65535 : 65536;
1649
+ } else {
1650
+ // FF >= 60 supports sending ~2 GiB
1651
+ canSendMaxMessageSize = 2147483637;
1652
+ }
1653
+ }
1654
+ return canSendMaxMessageSize;
1655
+ };
1656
+
1657
+ var getMaxMessageSize = function getMaxMessageSize(description, remoteIsFirefox) {
1658
+ // Note: 65536 bytes is the default value from the SDP spec. Also,
1659
+ // every implementation we know supports receiving 65536 bytes.
1660
+ var maxMessageSize = 65536;
1661
+
1662
+ // FF 57 has a slightly incorrect default remote max message size, so
1663
+ // we need to adjust it here to avoid a failure when sending.
1664
+ // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1425697
1665
+ if (browserDetails.browser === 'firefox' && browserDetails.version === 57) {
1666
+ maxMessageSize = 65535;
1667
+ }
1668
+
1669
+ var match = _sdp2.default.matchPrefix(description.sdp, 'a=max-message-size:');
1670
+ if (match.length > 0) {
1671
+ maxMessageSize = parseInt(match[0].substr(19), 10);
1672
+ } else if (browserDetails.browser === 'firefox' && remoteIsFirefox !== -1) {
1673
+ // If the maximum message size is not present in the remote SDP and
1674
+ // both local and remote are Firefox, the remote peer can receive
1675
+ // ~2 GiB.
1676
+ maxMessageSize = 2147483637;
1677
+ }
1678
+ return maxMessageSize;
1679
+ };
1680
+
1681
+ var origSetRemoteDescription = window.RTCPeerConnection.prototype.setRemoteDescription;
1682
+ window.RTCPeerConnection.prototype.setRemoteDescription =
1683
+ function setRemoteDescription() {
1684
+ this._sctp = null;
1685
+ // Chrome decided to not expose .sctp in plan-b mode.
1686
+ // As usual, adapter.js has to do an 'ugly worakaround'
1687
+ // to cover up the mess.
1688
+ if (browserDetails.browser === 'chrome' && browserDetails.version >= 76) {
1689
+ var _getConfiguration = this.getConfiguration(),
1690
+ sdpSemantics = _getConfiguration.sdpSemantics;
1691
+
1692
+ if (sdpSemantics === 'plan-b') {
1693
+ Object.defineProperty(this, 'sctp', {
1694
+ get: function get() {
1695
+ return typeof this._sctp === 'undefined' ? null : this._sctp;
1696
+ },
1697
+
1698
+ enumerable: true,
1699
+ configurable: true
1700
+ });
1701
+ }
1702
+ }
1703
+
1704
+ if (sctpInDescription(arguments[0])) {
1705
+ // Check if the remote is FF.
1706
+ var isFirefox = getRemoteFirefoxVersion(arguments[0]);
1707
+
1708
+ // Get the maximum message size the local peer is capable of sending
1709
+ var canSendMMS = getCanSendMaxMessageSize(isFirefox);
1710
+
1711
+ // Get the maximum message size of the remote peer.
1712
+ var remoteMMS = getMaxMessageSize(arguments[0], isFirefox);
1713
+
1714
+ // Determine final maximum message size
1715
+ var maxMessageSize = void 0;
1716
+ if (canSendMMS === 0 && remoteMMS === 0) {
1717
+ maxMessageSize = Number.POSITIVE_INFINITY;
1718
+ } else if (canSendMMS === 0 || remoteMMS === 0) {
1719
+ maxMessageSize = Math.max(canSendMMS, remoteMMS);
1720
+ } else {
1721
+ maxMessageSize = Math.min(canSendMMS, remoteMMS);
1722
+ }
1723
+
1724
+ // Create a dummy RTCSctpTransport object and the 'maxMessageSize'
1725
+ // attribute.
1726
+ var sctp = {};
1727
+ Object.defineProperty(sctp, 'maxMessageSize', {
1728
+ get: function get() {
1729
+ return maxMessageSize;
1730
+ }
1731
+ });
1732
+ this._sctp = sctp;
1733
+ }
1734
+
1735
+ return origSetRemoteDescription.apply(this, arguments);
1736
+ };
1737
+ }
1738
+
1739
+ function shimSendThrowTypeError(window) {
1740
+ if (
1741
+ !(
1742
+ window.RTCPeerConnection &&
1743
+ 'createDataChannel' in window.RTCPeerConnection.prototype
1744
+ )
1745
+ ) {
1746
+ return;
1747
+ }
1748
+
1749
+ // Note: Although Firefox >= 57 has a native implementation, the maximum
1750
+ // message size can be reset for all data channels at a later stage.
1751
+ // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1426831
1752
+
1753
+ function wrapDcSend(dc, pc) {
1754
+ var origDataChannelSend = dc.send;
1755
+ dc.send = function send() {
1756
+ var data = arguments[0];
1757
+ var length = data.length || data.size || data.byteLength;
1758
+ if (dc.readyState === 'open' && pc.sctp && length > pc.sctp.maxMessageSize) {
1759
+ throw new TypeError(
1760
+ 'Message too large (can send a maximum of ' + pc.sctp.maxMessageSize + ' bytes)'
1761
+ );
1762
+ }
1763
+ return origDataChannelSend.apply(dc, arguments);
1764
+ };
1765
+ }
1766
+ var origCreateDataChannel = window.RTCPeerConnection.prototype.createDataChannel;
1767
+ window.RTCPeerConnection.prototype.createDataChannel = function createDataChannel() {
1768
+ var dataChannel = origCreateDataChannel.apply(this, arguments);
1769
+ wrapDcSend(dataChannel, this);
1770
+ return dataChannel;
1771
+ };
1772
+ utils.wrapPeerConnectionEvent(window, 'datachannel', function (e) {
1773
+ wrapDcSend(e.channel, e.target);
1774
+ return e;
1775
+ });
1776
+ }
1777
+
1778
+ /* shims RTCConnectionState by pretending it is the same as iceConnectionState.
1779
+ * See https://bugs.chromium.org/p/webrtc/issues/detail?id=6145#c12
1780
+ * for why this is a valid hack in Chrome. In Firefox it is slightly incorrect
1781
+ * since DTLS failures would be hidden. See
1782
+ * https://bugzilla.mozilla.org/show_bug.cgi?id=1265827
1783
+ * for the Firefox tracking bug.
1784
+ */
1785
+ function shimConnectionState(window) {
1786
+ if (
1787
+ !window.RTCPeerConnection ||
1788
+ 'connectionState' in window.RTCPeerConnection.prototype
1789
+ ) {
1790
+ return;
1791
+ }
1792
+ var proto = window.RTCPeerConnection.prototype;
1793
+ Object.defineProperty(proto, 'connectionState', {
1794
+ get: function get() {
1795
+ return (
1796
+ {
1797
+ completed: 'connected',
1798
+ checking: 'connecting'
1799
+ }[this.iceConnectionState] || this.iceConnectionState
1800
+ );
1801
+ },
1802
+
1803
+ enumerable: true,
1804
+ configurable: true
1805
+ });
1806
+ Object.defineProperty(proto, 'onconnectionstatechange', {
1807
+ get: function get() {
1808
+ return this._onconnectionstatechange || null;
1809
+ },
1810
+ set: function set(cb) {
1811
+ if (this._onconnectionstatechange) {
1812
+ this.removeEventListener('connectionstatechange', this._onconnectionstatechange);
1813
+ delete this._onconnectionstatechange;
1814
+ }
1815
+ if (cb) {
1816
+ this.addEventListener(
1817
+ 'connectionstatechange',
1818
+ (this._onconnectionstatechange = cb)
1819
+ );
1820
+ }
1821
+ },
1822
+
1823
+ enumerable: true,
1824
+ configurable: true
1825
+ });
1826
+
1827
+ ['setLocalDescription', 'setRemoteDescription'].forEach(function (method) {
1828
+ var origMethod = proto[method];
1829
+ proto[method] = function () {
1830
+ if (!this._connectionstatechangepoly) {
1831
+ this._connectionstatechangepoly = function (e) {
1832
+ var pc = e.target;
1833
+ if (pc._lastConnectionState !== pc.connectionState) {
1834
+ pc._lastConnectionState = pc.connectionState;
1835
+ var newEvent = new Event('connectionstatechange', e);
1836
+ pc.dispatchEvent(newEvent);
1837
+ }
1838
+ return e;
1839
+ };
1840
+ this.addEventListener(
1841
+ 'iceconnectionstatechange',
1842
+ this._connectionstatechangepoly
1843
+ );
1844
+ }
1845
+ return origMethod.apply(this, arguments);
1846
+ };
1847
+ });
1848
+ }
1849
+
1850
+ function removeExtmapAllowMixed(window, browserDetails) {
1851
+ /* remove a=extmap-allow-mixed for webrtc.org < M71 */
1852
+ if (!window.RTCPeerConnection) {
1853
+ return;
1854
+ }
1855
+ if (browserDetails.browser === 'chrome' && browserDetails.version >= 71) {
1856
+ return;
1857
+ }
1858
+ if (browserDetails.browser === 'safari' && browserDetails.version >= 605) {
1859
+ return;
1860
+ }
1861
+ var nativeSRD = window.RTCPeerConnection.prototype.setRemoteDescription;
1862
+ window.RTCPeerConnection.prototype.setRemoteDescription = function setRemoteDescription(
1863
+ desc
1864
+ ) {
1865
+ if (desc && desc.sdp && desc.sdp.indexOf('\na=extmap-allow-mixed') !== -1) {
1866
+ var sdp = desc.sdp
1867
+ .split('\n')
1868
+ .filter(function (line) {
1869
+ return line.trim() !== 'a=extmap-allow-mixed';
1870
+ })
1871
+ .join('\n');
1872
+ // Safari enforces read-only-ness of RTCSessionDescription fields.
1873
+ if (window.RTCSessionDescription && desc instanceof window.RTCSessionDescription) {
1874
+ arguments[0] = new window.RTCSessionDescription({
1875
+ type: desc.type,
1876
+ sdp: sdp
1877
+ });
1878
+ } else {
1879
+ desc.sdp = sdp;
1880
+ }
1881
+ }
1882
+ return nativeSRD.apply(this, arguments);
1883
+ };
1884
+ }
1885
+
1886
+ function shimAddIceCandidateNullOrEmpty(window, browserDetails) {
1887
+ // Support for addIceCandidate(null or undefined)
1888
+ // as well as addIceCandidate({candidate: "", ...})
1889
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=978582
1890
+ // Note: must be called before other polyfills which change the signature.
1891
+ if (!(window.RTCPeerConnection && window.RTCPeerConnection.prototype)) {
1892
+ return;
1893
+ }
1894
+ var nativeAddIceCandidate = window.RTCPeerConnection.prototype.addIceCandidate;
1895
+ if (!nativeAddIceCandidate || nativeAddIceCandidate.length === 0) {
1896
+ return;
1897
+ }
1898
+ window.RTCPeerConnection.prototype.addIceCandidate = function addIceCandidate() {
1899
+ if (!arguments[0]) {
1900
+ if (arguments[1]) {
1901
+ arguments[1].apply(null);
1902
+ }
1903
+ return Promise.resolve();
1904
+ }
1905
+ // Firefox 68+ emits and processes {candidate: "", ...}, ignore
1906
+ // in older versions.
1907
+ // Native support for ignoring exists for Chrome M77+.
1908
+ // Safari ignores as well, exact version unknown but works in the same
1909
+ // version that also ignores addIceCandidate(null).
1910
+ if (
1911
+ ((browserDetails.browser === 'chrome' && browserDetails.version < 78) ||
1912
+ (browserDetails.browser === 'firefox' && browserDetails.version < 68) ||
1913
+ browserDetails.browser === 'safari') &&
1914
+ arguments[0] &&
1915
+ arguments[0].candidate === ''
1916
+ ) {
1917
+ return Promise.resolve();
1918
+ }
1919
+ return nativeAddIceCandidate.apply(this, arguments);
1920
+ };
1921
+ }
1922
+
1923
+ // Note: Make sure to call this ahead of APIs that modify
1924
+ // setLocalDescription.length
1925
+ function shimParameterlessSetLocalDescription(window, browserDetails) {
1926
+ if (!(window.RTCPeerConnection && window.RTCPeerConnection.prototype)) {
1927
+ return;
1928
+ }
1929
+ var nativeSetLocalDescription = window.RTCPeerConnection.prototype.setLocalDescription;
1930
+ if (!nativeSetLocalDescription || nativeSetLocalDescription.length === 0) {
1931
+ return;
1932
+ }
1933
+ window.RTCPeerConnection.prototype.setLocalDescription =
1934
+ function setLocalDescription() {
1935
+ var _this = this;
1936
+
1937
+ var desc = arguments[0] || {};
1938
+ if (
1939
+ (typeof desc === 'undefined' ? 'undefined' : _typeof(desc)) !== 'object' ||
1940
+ (desc.type && desc.sdp)
1941
+ ) {
1942
+ return nativeSetLocalDescription.apply(this, arguments);
1943
+ }
1944
+ // The remaining steps should technically happen when SLD comes off the
1945
+ // RTCPeerConnection's operations chain (not ahead of going on it), but
1946
+ // this is too difficult to shim. Instead, this shim only covers the
1947
+ // common case where the operations chain is empty. This is imperfect, but
1948
+ // should cover many cases. Rationale: Even if we can't reduce the glare
1949
+ // window to zero on imperfect implementations, there's value in tapping
1950
+ // into the perfect negotiation pattern that several browsers support.
1951
+ desc = { type: desc.type, sdp: desc.sdp };
1952
+ if (!desc.type) {
1953
+ switch (this.signalingState) {
1954
+ case 'stable':
1955
+ case 'have-local-offer':
1956
+ case 'have-remote-pranswer':
1957
+ desc.type = 'offer';
1958
+ break;
1959
+ default:
1960
+ desc.type = 'answer';
1961
+ break;
1962
+ }
1963
+ }
1964
+ if (desc.sdp || (desc.type !== 'offer' && desc.type !== 'answer')) {
1965
+ return nativeSetLocalDescription.apply(this, [desc]);
1966
+ }
1967
+ var func = desc.type === 'offer' ? this.createOffer : this.createAnswer;
1968
+ return func.apply(this).then(function (d) {
1969
+ return nativeSetLocalDescription.apply(_this, [d]);
1970
+ });
1971
+ };
1972
+ }
1973
+ },
1974
+ { './utils': 11, sdp: 12 }
1975
+ ],
1976
+ 7: [
1977
+ function (require, module, exports) {
1978
+ /*
1979
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
1980
+ *
1981
+ * Use of this source code is governed by a BSD-style license
1982
+ * that can be found in the LICENSE file in the root of the source
1983
+ * tree.
1984
+ */
1985
+ /* eslint-env node */
1986
+ 'use strict';
1987
+
1988
+ Object.defineProperty(exports, '__esModule', {
1989
+ value: true
1990
+ });
1991
+ exports.shimGetDisplayMedia = exports.shimGetUserMedia = undefined;
1992
+
1993
+ var _typeof =
1994
+ typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
1995
+ ? function (obj) {
1996
+ return typeof obj;
1997
+ }
1998
+ : function (obj) {
1999
+ return obj &&
2000
+ typeof Symbol === 'function' &&
2001
+ obj.constructor === Symbol &&
2002
+ obj !== Symbol.prototype
2003
+ ? 'symbol'
2004
+ : typeof obj;
2005
+ };
2006
+
2007
+ var _getusermedia = require('./getusermedia');
2008
+
2009
+ Object.defineProperty(exports, 'shimGetUserMedia', {
2010
+ enumerable: true,
2011
+ get: function get() {
2012
+ return _getusermedia.shimGetUserMedia;
2013
+ }
2014
+ });
2015
+
2016
+ var _getdisplaymedia = require('./getdisplaymedia');
2017
+
2018
+ Object.defineProperty(exports, 'shimGetDisplayMedia', {
2019
+ enumerable: true,
2020
+ get: function get() {
2021
+ return _getdisplaymedia.shimGetDisplayMedia;
2022
+ }
2023
+ });
2024
+ exports.shimOnTrack = shimOnTrack;
2025
+ exports.shimPeerConnection = shimPeerConnection;
2026
+ exports.shimSenderGetStats = shimSenderGetStats;
2027
+ exports.shimReceiverGetStats = shimReceiverGetStats;
2028
+ exports.shimRemoveStream = shimRemoveStream;
2029
+ exports.shimRTCDataChannel = shimRTCDataChannel;
2030
+ exports.shimAddTransceiver = shimAddTransceiver;
2031
+ exports.shimGetParameters = shimGetParameters;
2032
+ exports.shimCreateOffer = shimCreateOffer;
2033
+ exports.shimCreateAnswer = shimCreateAnswer;
2034
+
2035
+ var _utils = require('../utils');
2036
+
2037
+ var utils = _interopRequireWildcard(_utils);
2038
+
2039
+ function _interopRequireWildcard(obj) {
2040
+ if (obj && obj.__esModule) {
2041
+ return obj;
2042
+ } else {
2043
+ var newObj = {};
2044
+ if (obj != null) {
2045
+ for (var key in obj) {
2046
+ if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
2047
+ }
2048
+ }
2049
+ newObj.default = obj;
2050
+ return newObj;
2051
+ }
2052
+ }
2053
+
2054
+ function _defineProperty(obj, key, value) {
2055
+ if (key in obj) {
2056
+ Object.defineProperty(obj, key, {
2057
+ value: value,
2058
+ enumerable: true,
2059
+ configurable: true,
2060
+ writable: true
2061
+ });
2062
+ } else {
2063
+ obj[key] = value;
2064
+ }
2065
+ return obj;
2066
+ }
2067
+
2068
+ function shimOnTrack(window) {
2069
+ if (
2070
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' &&
2071
+ window.RTCTrackEvent &&
2072
+ 'receiver' in window.RTCTrackEvent.prototype &&
2073
+ !('transceiver' in window.RTCTrackEvent.prototype)
2074
+ ) {
2075
+ Object.defineProperty(window.RTCTrackEvent.prototype, 'transceiver', {
2076
+ get: function get() {
2077
+ return { receiver: this.receiver };
2078
+ }
2079
+ });
2080
+ }
2081
+ }
2082
+
2083
+ function shimPeerConnection(window, browserDetails) {
2084
+ if (
2085
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) !== 'object' ||
2086
+ !(window.RTCPeerConnection || window.mozRTCPeerConnection)
2087
+ ) {
2088
+ return; // probably media.peerconnection.enabled=false in about:config
2089
+ }
2090
+ if (!window.RTCPeerConnection && window.mozRTCPeerConnection) {
2091
+ // very basic support for old versions.
2092
+ window.RTCPeerConnection = window.mozRTCPeerConnection;
2093
+ }
2094
+
2095
+ if (browserDetails.version < 53) {
2096
+ // shim away need for obsolete RTCIceCandidate/RTCSessionDescription.
2097
+ ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate'].forEach(function (
2098
+ method
2099
+ ) {
2100
+ var nativeMethod = window.RTCPeerConnection.prototype[method];
2101
+ var methodObj = _defineProperty({}, method, function () {
2102
+ arguments[0] = new (
2103
+ method === 'addIceCandidate'
2104
+ ? window.RTCIceCandidate
2105
+ : window.RTCSessionDescription
2106
+ )(arguments[0]);
2107
+ return nativeMethod.apply(this, arguments);
2108
+ });
2109
+ window.RTCPeerConnection.prototype[method] = methodObj[method];
2110
+ });
2111
+ }
2112
+
2113
+ var modernStatsTypes = {
2114
+ inboundrtp: 'inbound-rtp',
2115
+ outboundrtp: 'outbound-rtp',
2116
+ candidatepair: 'candidate-pair',
2117
+ localcandidate: 'local-candidate',
2118
+ remotecandidate: 'remote-candidate'
2119
+ };
2120
+
2121
+ var nativeGetStats = window.RTCPeerConnection.prototype.getStats;
2122
+ window.RTCPeerConnection.prototype.getStats = function getStats() {
2123
+ var _arguments = Array.prototype.slice.call(arguments),
2124
+ selector = _arguments[0],
2125
+ onSucc = _arguments[1],
2126
+ onErr = _arguments[2];
2127
+
2128
+ return nativeGetStats
2129
+ .apply(this, [selector || null])
2130
+ .then(function (stats) {
2131
+ if (browserDetails.version < 53 && !onSucc) {
2132
+ // Shim only promise getStats with spec-hyphens in type names
2133
+ // Leave callback version alone; misc old uses of forEach before Map
2134
+ try {
2135
+ stats.forEach(function (stat) {
2136
+ stat.type = modernStatsTypes[stat.type] || stat.type;
2137
+ });
2138
+ } catch (e) {
2139
+ if (e.name !== 'TypeError') {
2140
+ throw e;
2141
+ }
2142
+ // Avoid TypeError: "type" is read-only, in old versions. 34-43ish
2143
+ stats.forEach(function (stat, i) {
2144
+ stats.set(
2145
+ i,
2146
+ Object.assign({}, stat, {
2147
+ type: modernStatsTypes[stat.type] || stat.type
2148
+ })
2149
+ );
2150
+ });
2151
+ }
2152
+ }
2153
+ return stats;
2154
+ })
2155
+ .then(onSucc, onErr);
2156
+ };
2157
+ }
2158
+
2159
+ function shimSenderGetStats(window) {
2160
+ if (
2161
+ !(
2162
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' &&
2163
+ window.RTCPeerConnection &&
2164
+ window.RTCRtpSender
2165
+ )
2166
+ ) {
2167
+ return;
2168
+ }
2169
+ if (window.RTCRtpSender && 'getStats' in window.RTCRtpSender.prototype) {
2170
+ return;
2171
+ }
2172
+ var origGetSenders = window.RTCPeerConnection.prototype.getSenders;
2173
+ if (origGetSenders) {
2174
+ window.RTCPeerConnection.prototype.getSenders = function getSenders() {
2175
+ var _this = this;
2176
+
2177
+ var senders = origGetSenders.apply(this, []);
2178
+ senders.forEach(function (sender) {
2179
+ return (sender._pc = _this);
2180
+ });
2181
+ return senders;
2182
+ };
2183
+ }
2184
+
2185
+ var origAddTrack = window.RTCPeerConnection.prototype.addTrack;
2186
+ if (origAddTrack) {
2187
+ window.RTCPeerConnection.prototype.addTrack = function addTrack() {
2188
+ var sender = origAddTrack.apply(this, arguments);
2189
+ sender._pc = this;
2190
+ return sender;
2191
+ };
2192
+ }
2193
+ window.RTCRtpSender.prototype.getStats = function getStats() {
2194
+ return this.track ? this._pc.getStats(this.track) : Promise.resolve(new Map());
2195
+ };
2196
+ }
2197
+
2198
+ function shimReceiverGetStats(window) {
2199
+ if (
2200
+ !(
2201
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' &&
2202
+ window.RTCPeerConnection &&
2203
+ window.RTCRtpSender
2204
+ )
2205
+ ) {
2206
+ return;
2207
+ }
2208
+ if (window.RTCRtpSender && 'getStats' in window.RTCRtpReceiver.prototype) {
2209
+ return;
2210
+ }
2211
+ var origGetReceivers = window.RTCPeerConnection.prototype.getReceivers;
2212
+ if (origGetReceivers) {
2213
+ window.RTCPeerConnection.prototype.getReceivers = function getReceivers() {
2214
+ var _this2 = this;
2215
+
2216
+ var receivers = origGetReceivers.apply(this, []);
2217
+ receivers.forEach(function (receiver) {
2218
+ return (receiver._pc = _this2);
2219
+ });
2220
+ return receivers;
2221
+ };
2222
+ }
2223
+ utils.wrapPeerConnectionEvent(window, 'track', function (e) {
2224
+ e.receiver._pc = e.srcElement;
2225
+ return e;
2226
+ });
2227
+ window.RTCRtpReceiver.prototype.getStats = function getStats() {
2228
+ return this._pc.getStats(this.track);
2229
+ };
2230
+ }
2231
+
2232
+ function shimRemoveStream(window) {
2233
+ if (!window.RTCPeerConnection || 'removeStream' in window.RTCPeerConnection.prototype) {
2234
+ return;
2235
+ }
2236
+ window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
2237
+ var _this3 = this;
2238
+
2239
+ utils.deprecated('removeStream', 'removeTrack');
2240
+ this.getSenders().forEach(function (sender) {
2241
+ if (sender.track && stream.getTracks().includes(sender.track)) {
2242
+ _this3.removeTrack(sender);
2243
+ }
2244
+ });
2245
+ };
2246
+ }
2247
+
2248
+ function shimRTCDataChannel(window) {
2249
+ // rename DataChannel to RTCDataChannel (native fix in FF60):
2250
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1173851
2251
+ if (window.DataChannel && !window.RTCDataChannel) {
2252
+ window.RTCDataChannel = window.DataChannel;
2253
+ }
2254
+ }
2255
+
2256
+ function shimAddTransceiver(window) {
2257
+ // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647
2258
+ // Firefox ignores the init sendEncodings options passed to addTransceiver
2259
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918
2260
+ if (
2261
+ !(
2262
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' &&
2263
+ window.RTCPeerConnection
2264
+ )
2265
+ ) {
2266
+ return;
2267
+ }
2268
+ var origAddTransceiver = window.RTCPeerConnection.prototype.addTransceiver;
2269
+ if (origAddTransceiver) {
2270
+ window.RTCPeerConnection.prototype.addTransceiver = function addTransceiver() {
2271
+ this.setParametersPromises = [];
2272
+ var initParameters = arguments[1];
2273
+ var shouldPerformCheck = initParameters && 'sendEncodings' in initParameters;
2274
+ if (shouldPerformCheck) {
2275
+ // If sendEncodings params are provided, validate grammar
2276
+ initParameters.sendEncodings.forEach(function (encodingParam) {
2277
+ if ('rid' in encodingParam) {
2278
+ var ridRegex = /^[a-z0-9]{0,16}$/i;
2279
+ if (!ridRegex.test(encodingParam.rid)) {
2280
+ throw new TypeError('Invalid RID value provided.');
2281
+ }
2282
+ }
2283
+ if ('scaleResolutionDownBy' in encodingParam) {
2284
+ if (!(parseFloat(encodingParam.scaleResolutionDownBy) >= 1.0)) {
2285
+ throw new RangeError('scale_resolution_down_by must be >= 1.0');
2286
+ }
2287
+ }
2288
+ if ('maxFramerate' in encodingParam) {
2289
+ if (!(parseFloat(encodingParam.maxFramerate) >= 0)) {
2290
+ throw new RangeError('max_framerate must be >= 0.0');
2291
+ }
2292
+ }
2293
+ });
2294
+ }
2295
+ var transceiver = origAddTransceiver.apply(this, arguments);
2296
+ if (shouldPerformCheck) {
2297
+ // Check if the init options were applied. If not we do this in an
2298
+ // asynchronous way and save the promise reference in a global object.
2299
+ // This is an ugly hack, but at the same time is way more robust than
2300
+ // checking the sender parameters before and after the createOffer
2301
+ // Also note that after the createoffer we are not 100% sure that
2302
+ // the params were asynchronously applied so we might miss the
2303
+ // opportunity to recreate offer.
2304
+ var sender = transceiver.sender;
2305
+
2306
+ var params = sender.getParameters();
2307
+ if (
2308
+ !('encodings' in params) ||
2309
+ // Avoid being fooled by patched getParameters() below.
2310
+ (params.encodings.length === 1 && Object.keys(params.encodings[0]).length === 0)
2311
+ ) {
2312
+ params.encodings = initParameters.sendEncodings;
2313
+ sender.sendEncodings = initParameters.sendEncodings;
2314
+ this.setParametersPromises.push(
2315
+ sender
2316
+ .setParameters(params)
2317
+ .then(function () {
2318
+ delete sender.sendEncodings;
2319
+ })
2320
+ .catch(function () {
2321
+ delete sender.sendEncodings;
2322
+ })
2323
+ );
2324
+ }
2325
+ }
2326
+ return transceiver;
2327
+ };
2328
+ }
2329
+ }
2330
+
2331
+ function shimGetParameters(window) {
2332
+ if (
2333
+ !(
2334
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' &&
2335
+ window.RTCRtpSender
2336
+ )
2337
+ ) {
2338
+ return;
2339
+ }
2340
+ var origGetParameters = window.RTCRtpSender.prototype.getParameters;
2341
+ if (origGetParameters) {
2342
+ window.RTCRtpSender.prototype.getParameters = function getParameters() {
2343
+ var params = origGetParameters.apply(this, arguments);
2344
+ if (!('encodings' in params)) {
2345
+ params.encodings = [].concat(this.sendEncodings || [{}]);
2346
+ }
2347
+ return params;
2348
+ };
2349
+ }
2350
+ }
2351
+
2352
+ function shimCreateOffer(window) {
2353
+ // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647
2354
+ // Firefox ignores the init sendEncodings options passed to addTransceiver
2355
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918
2356
+ if (
2357
+ !(
2358
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' &&
2359
+ window.RTCPeerConnection
2360
+ )
2361
+ ) {
2362
+ return;
2363
+ }
2364
+ var origCreateOffer = window.RTCPeerConnection.prototype.createOffer;
2365
+ window.RTCPeerConnection.prototype.createOffer = function createOffer() {
2366
+ var _this4 = this,
2367
+ _arguments2 = arguments;
2368
+
2369
+ if (this.setParametersPromises && this.setParametersPromises.length) {
2370
+ return Promise.all(this.setParametersPromises)
2371
+ .then(function () {
2372
+ return origCreateOffer.apply(_this4, _arguments2);
2373
+ })
2374
+ .finally(function () {
2375
+ _this4.setParametersPromises = [];
2376
+ });
2377
+ }
2378
+ return origCreateOffer.apply(this, arguments);
2379
+ };
2380
+ }
2381
+
2382
+ function shimCreateAnswer(window) {
2383
+ // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647
2384
+ // Firefox ignores the init sendEncodings options passed to addTransceiver
2385
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918
2386
+ if (
2387
+ !(
2388
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' &&
2389
+ window.RTCPeerConnection
2390
+ )
2391
+ ) {
2392
+ return;
2393
+ }
2394
+ var origCreateAnswer = window.RTCPeerConnection.prototype.createAnswer;
2395
+ window.RTCPeerConnection.prototype.createAnswer = function createAnswer() {
2396
+ var _this5 = this,
2397
+ _arguments3 = arguments;
2398
+
2399
+ if (this.setParametersPromises && this.setParametersPromises.length) {
2400
+ return Promise.all(this.setParametersPromises)
2401
+ .then(function () {
2402
+ return origCreateAnswer.apply(_this5, _arguments3);
2403
+ })
2404
+ .finally(function () {
2405
+ _this5.setParametersPromises = [];
2406
+ });
2407
+ }
2408
+ return origCreateAnswer.apply(this, arguments);
2409
+ };
2410
+ }
2411
+ },
2412
+ { '../utils': 11, './getdisplaymedia': 8, './getusermedia': 9 }
2413
+ ],
2414
+ 8: [
2415
+ function (require, module, exports) {
2416
+ /*
2417
+ * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved.
2418
+ *
2419
+ * Use of this source code is governed by a BSD-style license
2420
+ * that can be found in the LICENSE file in the root of the source
2421
+ * tree.
2422
+ */
2423
+ /* eslint-env node */
2424
+ 'use strict';
2425
+
2426
+ Object.defineProperty(exports, '__esModule', {
2427
+ value: true
2428
+ });
2429
+ exports.shimGetDisplayMedia = shimGetDisplayMedia;
2430
+ function shimGetDisplayMedia(window, preferredMediaSource) {
2431
+ if (
2432
+ window.navigator.mediaDevices &&
2433
+ 'getDisplayMedia' in window.navigator.mediaDevices
2434
+ ) {
2435
+ return;
2436
+ }
2437
+ if (!window.navigator.mediaDevices) {
2438
+ return;
2439
+ }
2440
+ window.navigator.mediaDevices.getDisplayMedia = function getDisplayMedia(constraints) {
2441
+ if (!(constraints && constraints.video)) {
2442
+ var err = new DOMException(
2443
+ 'getDisplayMedia without video ' + 'constraints is undefined'
2444
+ );
2445
+ err.name = 'NotFoundError';
2446
+ // from https://heycam.github.io/webidl/#idl-DOMException-error-names
2447
+ err.code = 8;
2448
+ return Promise.reject(err);
2449
+ }
2450
+ if (constraints.video === true) {
2451
+ constraints.video = { mediaSource: preferredMediaSource };
2452
+ } else {
2453
+ constraints.video.mediaSource = preferredMediaSource;
2454
+ }
2455
+ return window.navigator.mediaDevices.getUserMedia(constraints);
2456
+ };
2457
+ }
2458
+ },
2459
+ {}
2460
+ ],
2461
+ 9: [
2462
+ function (require, module, exports) {
2463
+ /*
2464
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
2465
+ *
2466
+ * Use of this source code is governed by a BSD-style license
2467
+ * that can be found in the LICENSE file in the root of the source
2468
+ * tree.
2469
+ */
2470
+ /* eslint-env node */
2471
+ 'use strict';
2472
+
2473
+ Object.defineProperty(exports, '__esModule', {
2474
+ value: true
2475
+ });
2476
+
2477
+ var _typeof =
2478
+ typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
2479
+ ? function (obj) {
2480
+ return typeof obj;
2481
+ }
2482
+ : function (obj) {
2483
+ return obj &&
2484
+ typeof Symbol === 'function' &&
2485
+ obj.constructor === Symbol &&
2486
+ obj !== Symbol.prototype
2487
+ ? 'symbol'
2488
+ : typeof obj;
2489
+ };
2490
+
2491
+ exports.shimGetUserMedia = shimGetUserMedia;
2492
+
2493
+ var _utils = require('../utils');
2494
+
2495
+ var utils = _interopRequireWildcard(_utils);
2496
+
2497
+ function _interopRequireWildcard(obj) {
2498
+ if (obj && obj.__esModule) {
2499
+ return obj;
2500
+ } else {
2501
+ var newObj = {};
2502
+ if (obj != null) {
2503
+ for (var key in obj) {
2504
+ if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
2505
+ }
2506
+ }
2507
+ newObj.default = obj;
2508
+ return newObj;
2509
+ }
2510
+ }
2511
+
2512
+ function shimGetUserMedia(window, browserDetails) {
2513
+ var navigator = window && window.navigator;
2514
+ var MediaStreamTrack = window && window.MediaStreamTrack;
2515
+
2516
+ navigator.getUserMedia = function (constraints, onSuccess, onError) {
2517
+ // Replace Firefox 44+'s deprecation warning with unprefixed version.
2518
+ utils.deprecated('navigator.getUserMedia', 'navigator.mediaDevices.getUserMedia');
2519
+ navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError);
2520
+ };
2521
+
2522
+ if (
2523
+ !(
2524
+ browserDetails.version > 55 &&
2525
+ 'autoGainControl' in navigator.mediaDevices.getSupportedConstraints()
2526
+ )
2527
+ ) {
2528
+ var remap = function remap(obj, a, b) {
2529
+ if (a in obj && !(b in obj)) {
2530
+ obj[b] = obj[a];
2531
+ delete obj[a];
2532
+ }
2533
+ };
2534
+
2535
+ var nativeGetUserMedia = navigator.mediaDevices.getUserMedia.bind(
2536
+ navigator.mediaDevices
2537
+ );
2538
+ navigator.mediaDevices.getUserMedia = function (c) {
2539
+ if (
2540
+ (typeof c === 'undefined' ? 'undefined' : _typeof(c)) === 'object' &&
2541
+ _typeof(c.audio) === 'object'
2542
+ ) {
2543
+ c = JSON.parse(JSON.stringify(c));
2544
+ remap(c.audio, 'autoGainControl', 'mozAutoGainControl');
2545
+ remap(c.audio, 'noiseSuppression', 'mozNoiseSuppression');
2546
+ }
2547
+ return nativeGetUserMedia(c);
2548
+ };
2549
+
2550
+ if (MediaStreamTrack && MediaStreamTrack.prototype.getSettings) {
2551
+ var nativeGetSettings = MediaStreamTrack.prototype.getSettings;
2552
+ MediaStreamTrack.prototype.getSettings = function () {
2553
+ var obj = nativeGetSettings.apply(this, arguments);
2554
+ remap(obj, 'mozAutoGainControl', 'autoGainControl');
2555
+ remap(obj, 'mozNoiseSuppression', 'noiseSuppression');
2556
+ return obj;
2557
+ };
2558
+ }
2559
+
2560
+ if (MediaStreamTrack && MediaStreamTrack.prototype.applyConstraints) {
2561
+ var nativeApplyConstraints = MediaStreamTrack.prototype.applyConstraints;
2562
+ MediaStreamTrack.prototype.applyConstraints = function (c) {
2563
+ if (
2564
+ this.kind === 'audio' &&
2565
+ (typeof c === 'undefined' ? 'undefined' : _typeof(c)) === 'object'
2566
+ ) {
2567
+ c = JSON.parse(JSON.stringify(c));
2568
+ remap(c, 'autoGainControl', 'mozAutoGainControl');
2569
+ remap(c, 'noiseSuppression', 'mozNoiseSuppression');
2570
+ }
2571
+ return nativeApplyConstraints.apply(this, [c]);
2572
+ };
2573
+ }
2574
+ }
2575
+ }
2576
+ },
2577
+ { '../utils': 11 }
2578
+ ],
2579
+ 10: [
2580
+ function (require, module, exports) {
2581
+ /*
2582
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
2583
+ *
2584
+ * Use of this source code is governed by a BSD-style license
2585
+ * that can be found in the LICENSE file in the root of the source
2586
+ * tree.
2587
+ */
2588
+ 'use strict';
2589
+
2590
+ Object.defineProperty(exports, '__esModule', {
2591
+ value: true
2592
+ });
2593
+
2594
+ var _typeof =
2595
+ typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
2596
+ ? function (obj) {
2597
+ return typeof obj;
2598
+ }
2599
+ : function (obj) {
2600
+ return obj &&
2601
+ typeof Symbol === 'function' &&
2602
+ obj.constructor === Symbol &&
2603
+ obj !== Symbol.prototype
2604
+ ? 'symbol'
2605
+ : typeof obj;
2606
+ };
2607
+
2608
+ exports.shimLocalStreamsAPI = shimLocalStreamsAPI;
2609
+ exports.shimRemoteStreamsAPI = shimRemoteStreamsAPI;
2610
+ exports.shimCallbacksAPI = shimCallbacksAPI;
2611
+ exports.shimGetUserMedia = shimGetUserMedia;
2612
+ exports.shimConstraints = shimConstraints;
2613
+ exports.shimRTCIceServerUrls = shimRTCIceServerUrls;
2614
+ exports.shimTrackEventTransceiver = shimTrackEventTransceiver;
2615
+ exports.shimCreateOfferLegacy = shimCreateOfferLegacy;
2616
+ exports.shimAudioContext = shimAudioContext;
2617
+
2618
+ var _utils = require('../utils');
2619
+
2620
+ var utils = _interopRequireWildcard(_utils);
2621
+
2622
+ function _interopRequireWildcard(obj) {
2623
+ if (obj && obj.__esModule) {
2624
+ return obj;
2625
+ } else {
2626
+ var newObj = {};
2627
+ if (obj != null) {
2628
+ for (var key in obj) {
2629
+ if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
2630
+ }
2631
+ }
2632
+ newObj.default = obj;
2633
+ return newObj;
2634
+ }
2635
+ }
2636
+
2637
+ function shimLocalStreamsAPI(window) {
2638
+ if (
2639
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) !== 'object' ||
2640
+ !window.RTCPeerConnection
2641
+ ) {
2642
+ return;
2643
+ }
2644
+ if (!('getLocalStreams' in window.RTCPeerConnection.prototype)) {
2645
+ window.RTCPeerConnection.prototype.getLocalStreams = function getLocalStreams() {
2646
+ if (!this._localStreams) {
2647
+ this._localStreams = [];
2648
+ }
2649
+ return this._localStreams;
2650
+ };
2651
+ }
2652
+ if (!('addStream' in window.RTCPeerConnection.prototype)) {
2653
+ var _addTrack = window.RTCPeerConnection.prototype.addTrack;
2654
+ window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
2655
+ var _this = this;
2656
+
2657
+ if (!this._localStreams) {
2658
+ this._localStreams = [];
2659
+ }
2660
+ if (!this._localStreams.includes(stream)) {
2661
+ this._localStreams.push(stream);
2662
+ }
2663
+ // Try to emulate Chrome's behaviour of adding in audio-video order.
2664
+ // Safari orders by track id.
2665
+ stream.getAudioTracks().forEach(function (track) {
2666
+ return _addTrack.call(_this, track, stream);
2667
+ });
2668
+ stream.getVideoTracks().forEach(function (track) {
2669
+ return _addTrack.call(_this, track, stream);
2670
+ });
2671
+ };
2672
+
2673
+ window.RTCPeerConnection.prototype.addTrack = function addTrack(track) {
2674
+ var _this2 = this;
2675
+
2676
+ for (
2677
+ var _len = arguments.length, streams = Array(_len > 1 ? _len - 1 : 0), _key = 1;
2678
+ _key < _len;
2679
+ _key++
2680
+ ) {
2681
+ streams[_key - 1] = arguments[_key];
2682
+ }
2683
+
2684
+ if (streams) {
2685
+ streams.forEach(function (stream) {
2686
+ if (!_this2._localStreams) {
2687
+ _this2._localStreams = [stream];
2688
+ } else if (!_this2._localStreams.includes(stream)) {
2689
+ _this2._localStreams.push(stream);
2690
+ }
2691
+ });
2692
+ }
2693
+ return _addTrack.apply(this, arguments);
2694
+ };
2695
+ }
2696
+ if (!('removeStream' in window.RTCPeerConnection.prototype)) {
2697
+ window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
2698
+ var _this3 = this;
2699
+
2700
+ if (!this._localStreams) {
2701
+ this._localStreams = [];
2702
+ }
2703
+ var index = this._localStreams.indexOf(stream);
2704
+ if (index === -1) {
2705
+ return;
2706
+ }
2707
+ this._localStreams.splice(index, 1);
2708
+ var tracks = stream.getTracks();
2709
+ this.getSenders().forEach(function (sender) {
2710
+ if (tracks.includes(sender.track)) {
2711
+ _this3.removeTrack(sender);
2712
+ }
2713
+ });
2714
+ };
2715
+ }
2716
+ }
2717
+
2718
+ function shimRemoteStreamsAPI(window) {
2719
+ if (
2720
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) !== 'object' ||
2721
+ !window.RTCPeerConnection
2722
+ ) {
2723
+ return;
2724
+ }
2725
+ if (!('getRemoteStreams' in window.RTCPeerConnection.prototype)) {
2726
+ window.RTCPeerConnection.prototype.getRemoteStreams = function getRemoteStreams() {
2727
+ return this._remoteStreams ? this._remoteStreams : [];
2728
+ };
2729
+ }
2730
+ if (!('onaddstream' in window.RTCPeerConnection.prototype)) {
2731
+ Object.defineProperty(window.RTCPeerConnection.prototype, 'onaddstream', {
2732
+ get: function get() {
2733
+ return this._onaddstream;
2734
+ },
2735
+ set: function set(f) {
2736
+ var _this4 = this;
2737
+
2738
+ if (this._onaddstream) {
2739
+ this.removeEventListener('addstream', this._onaddstream);
2740
+ this.removeEventListener('track', this._onaddstreampoly);
2741
+ }
2742
+ this.addEventListener('addstream', (this._onaddstream = f));
2743
+ this.addEventListener(
2744
+ 'track',
2745
+ (this._onaddstreampoly = function (e) {
2746
+ e.streams.forEach(function (stream) {
2747
+ if (!_this4._remoteStreams) {
2748
+ _this4._remoteStreams = [];
2749
+ }
2750
+ if (_this4._remoteStreams.includes(stream)) {
2751
+ return;
2752
+ }
2753
+ _this4._remoteStreams.push(stream);
2754
+ var event = new Event('addstream');
2755
+ event.stream = stream;
2756
+ _this4.dispatchEvent(event);
2757
+ });
2758
+ })
2759
+ );
2760
+ }
2761
+ });
2762
+ var origSetRemoteDescription =
2763
+ window.RTCPeerConnection.prototype.setRemoteDescription;
2764
+ window.RTCPeerConnection.prototype.setRemoteDescription =
2765
+ function setRemoteDescription() {
2766
+ var pc = this;
2767
+ if (!this._onaddstreampoly) {
2768
+ this.addEventListener(
2769
+ 'track',
2770
+ (this._onaddstreampoly = function (e) {
2771
+ e.streams.forEach(function (stream) {
2772
+ if (!pc._remoteStreams) {
2773
+ pc._remoteStreams = [];
2774
+ }
2775
+ if (pc._remoteStreams.indexOf(stream) >= 0) {
2776
+ return;
2777
+ }
2778
+ pc._remoteStreams.push(stream);
2779
+ var event = new Event('addstream');
2780
+ event.stream = stream;
2781
+ pc.dispatchEvent(event);
2782
+ });
2783
+ })
2784
+ );
2785
+ }
2786
+ return origSetRemoteDescription.apply(pc, arguments);
2787
+ };
2788
+ }
2789
+ }
2790
+
2791
+ function shimCallbacksAPI(window) {
2792
+ if (
2793
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) !== 'object' ||
2794
+ !window.RTCPeerConnection
2795
+ ) {
2796
+ return;
2797
+ }
2798
+ var prototype = window.RTCPeerConnection.prototype;
2799
+ var origCreateOffer = prototype.createOffer;
2800
+ var origCreateAnswer = prototype.createAnswer;
2801
+ var setLocalDescription = prototype.setLocalDescription;
2802
+ var setRemoteDescription = prototype.setRemoteDescription;
2803
+ var addIceCandidate = prototype.addIceCandidate;
2804
+
2805
+ prototype.createOffer = function createOffer(successCallback, failureCallback) {
2806
+ var options = arguments.length >= 2 ? arguments[2] : arguments[0];
2807
+ var promise = origCreateOffer.apply(this, [options]);
2808
+ if (!failureCallback) {
2809
+ return promise;
2810
+ }
2811
+ promise.then(successCallback, failureCallback);
2812
+ return Promise.resolve();
2813
+ };
2814
+
2815
+ prototype.createAnswer = function createAnswer(successCallback, failureCallback) {
2816
+ var options = arguments.length >= 2 ? arguments[2] : arguments[0];
2817
+ var promise = origCreateAnswer.apply(this, [options]);
2818
+ if (!failureCallback) {
2819
+ return promise;
2820
+ }
2821
+ promise.then(successCallback, failureCallback);
2822
+ return Promise.resolve();
2823
+ };
2824
+
2825
+ var withCallback = function withCallback(
2826
+ description,
2827
+ successCallback,
2828
+ failureCallback
2829
+ ) {
2830
+ var promise = setLocalDescription.apply(this, [description]);
2831
+ if (!failureCallback) {
2832
+ return promise;
2833
+ }
2834
+ promise.then(successCallback, failureCallback);
2835
+ return Promise.resolve();
2836
+ };
2837
+ prototype.setLocalDescription = withCallback;
2838
+
2839
+ withCallback = function withCallback(description, successCallback, failureCallback) {
2840
+ var promise = setRemoteDescription.apply(this, [description]);
2841
+ if (!failureCallback) {
2842
+ return promise;
2843
+ }
2844
+ promise.then(successCallback, failureCallback);
2845
+ return Promise.resolve();
2846
+ };
2847
+ prototype.setRemoteDescription = withCallback;
2848
+
2849
+ withCallback = function withCallback(candidate, successCallback, failureCallback) {
2850
+ var promise = addIceCandidate.apply(this, [candidate]);
2851
+ if (!failureCallback) {
2852
+ return promise;
2853
+ }
2854
+ promise.then(successCallback, failureCallback);
2855
+ return Promise.resolve();
2856
+ };
2857
+ prototype.addIceCandidate = withCallback;
2858
+ }
2859
+
2860
+ function shimGetUserMedia(window) {
2861
+ var navigator = window && window.navigator;
2862
+
2863
+ if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
2864
+ // shim not needed in Safari 12.1
2865
+ var mediaDevices = navigator.mediaDevices;
2866
+ var _getUserMedia = mediaDevices.getUserMedia.bind(mediaDevices);
2867
+ navigator.mediaDevices.getUserMedia = function (constraints) {
2868
+ return _getUserMedia(shimConstraints(constraints));
2869
+ };
2870
+ }
2871
+
2872
+ if (
2873
+ !navigator.getUserMedia &&
2874
+ navigator.mediaDevices &&
2875
+ navigator.mediaDevices.getUserMedia
2876
+ ) {
2877
+ navigator.getUserMedia = function getUserMedia(constraints, cb, errcb) {
2878
+ navigator.mediaDevices.getUserMedia(constraints).then(cb, errcb);
2879
+ }.bind(navigator);
2880
+ }
2881
+ }
2882
+
2883
+ function shimConstraints(constraints) {
2884
+ if (constraints && constraints.video !== undefined) {
2885
+ return Object.assign({}, constraints, {
2886
+ video: utils.compactObject(constraints.video)
2887
+ });
2888
+ }
2889
+
2890
+ return constraints;
2891
+ }
2892
+
2893
+ function shimRTCIceServerUrls(window) {
2894
+ if (!window.RTCPeerConnection) {
2895
+ return;
2896
+ }
2897
+ // migrate from non-spec RTCIceServer.url to RTCIceServer.urls
2898
+ var OrigPeerConnection = window.RTCPeerConnection;
2899
+ window.RTCPeerConnection = function RTCPeerConnection(pcConfig, pcConstraints) {
2900
+ if (pcConfig && pcConfig.iceServers) {
2901
+ var newIceServers = [];
2902
+ for (var i = 0; i < pcConfig.iceServers.length; i++) {
2903
+ var server = pcConfig.iceServers[i];
2904
+ if (!server.hasOwnProperty('urls') && server.hasOwnProperty('url')) {
2905
+ utils.deprecated('RTCIceServer.url', 'RTCIceServer.urls');
2906
+ server = JSON.parse(JSON.stringify(server));
2907
+ server.urls = server.url;
2908
+ delete server.url;
2909
+ newIceServers.push(server);
2910
+ } else {
2911
+ newIceServers.push(pcConfig.iceServers[i]);
2912
+ }
2913
+ }
2914
+ pcConfig.iceServers = newIceServers;
2915
+ }
2916
+ return new OrigPeerConnection(pcConfig, pcConstraints);
2917
+ };
2918
+ window.RTCPeerConnection.prototype = OrigPeerConnection.prototype;
2919
+ // wrap static methods. Currently just generateCertificate.
2920
+ if ('generateCertificate' in OrigPeerConnection) {
2921
+ Object.defineProperty(window.RTCPeerConnection, 'generateCertificate', {
2922
+ get: function get() {
2923
+ return OrigPeerConnection.generateCertificate;
2924
+ }
2925
+ });
2926
+ }
2927
+ }
2928
+
2929
+ function shimTrackEventTransceiver(window) {
2930
+ // Add event.transceiver member over deprecated event.receiver
2931
+ if (
2932
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' &&
2933
+ window.RTCTrackEvent &&
2934
+ 'receiver' in window.RTCTrackEvent.prototype &&
2935
+ !('transceiver' in window.RTCTrackEvent.prototype)
2936
+ ) {
2937
+ Object.defineProperty(window.RTCTrackEvent.prototype, 'transceiver', {
2938
+ get: function get() {
2939
+ return { receiver: this.receiver };
2940
+ }
2941
+ });
2942
+ }
2943
+ }
2944
+
2945
+ function shimCreateOfferLegacy(window) {
2946
+ var origCreateOffer = window.RTCPeerConnection.prototype.createOffer;
2947
+ window.RTCPeerConnection.prototype.createOffer = function createOffer(offerOptions) {
2948
+ if (offerOptions) {
2949
+ if (typeof offerOptions.offerToReceiveAudio !== 'undefined') {
2950
+ // support bit values
2951
+ offerOptions.offerToReceiveAudio = !!offerOptions.offerToReceiveAudio;
2952
+ }
2953
+ var audioTransceiver = this.getTransceivers().find(function (transceiver) {
2954
+ return transceiver.receiver.track.kind === 'audio';
2955
+ });
2956
+ if (offerOptions.offerToReceiveAudio === false && audioTransceiver) {
2957
+ if (audioTransceiver.direction === 'sendrecv') {
2958
+ if (audioTransceiver.setDirection) {
2959
+ audioTransceiver.setDirection('sendonly');
2960
+ } else {
2961
+ audioTransceiver.direction = 'sendonly';
2962
+ }
2963
+ } else if (audioTransceiver.direction === 'recvonly') {
2964
+ if (audioTransceiver.setDirection) {
2965
+ audioTransceiver.setDirection('inactive');
2966
+ } else {
2967
+ audioTransceiver.direction = 'inactive';
2968
+ }
2969
+ }
2970
+ } else if (offerOptions.offerToReceiveAudio === true && !audioTransceiver) {
2971
+ this.addTransceiver('audio');
2972
+ }
2973
+
2974
+ if (typeof offerOptions.offerToReceiveVideo !== 'undefined') {
2975
+ // support bit values
2976
+ offerOptions.offerToReceiveVideo = !!offerOptions.offerToReceiveVideo;
2977
+ }
2978
+ var videoTransceiver = this.getTransceivers().find(function (transceiver) {
2979
+ return transceiver.receiver.track.kind === 'video';
2980
+ });
2981
+ if (offerOptions.offerToReceiveVideo === false && videoTransceiver) {
2982
+ if (videoTransceiver.direction === 'sendrecv') {
2983
+ if (videoTransceiver.setDirection) {
2984
+ videoTransceiver.setDirection('sendonly');
2985
+ } else {
2986
+ videoTransceiver.direction = 'sendonly';
2987
+ }
2988
+ } else if (videoTransceiver.direction === 'recvonly') {
2989
+ if (videoTransceiver.setDirection) {
2990
+ videoTransceiver.setDirection('inactive');
2991
+ } else {
2992
+ videoTransceiver.direction = 'inactive';
2993
+ }
2994
+ }
2995
+ } else if (offerOptions.offerToReceiveVideo === true && !videoTransceiver) {
2996
+ this.addTransceiver('video');
2997
+ }
2998
+ }
2999
+ return origCreateOffer.apply(this, arguments);
3000
+ };
3001
+ }
3002
+
3003
+ function shimAudioContext(window) {
3004
+ if (
3005
+ (typeof window === 'undefined' ? 'undefined' : _typeof(window)) !== 'object' ||
3006
+ window.AudioContext
3007
+ ) {
3008
+ return;
3009
+ }
3010
+ window.AudioContext = window.webkitAudioContext;
3011
+ }
3012
+ },
3013
+ { '../utils': 11 }
3014
+ ],
3015
+ 11: [
3016
+ function (require, module, exports) {
3017
+ /*
3018
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3019
+ *
3020
+ * Use of this source code is governed by a BSD-style license
3021
+ * that can be found in the LICENSE file in the root of the source
3022
+ * tree.
3023
+ */
3024
+ /* eslint-env node */
3025
+ 'use strict';
3026
+
3027
+ Object.defineProperty(exports, '__esModule', {
3028
+ value: true
3029
+ });
3030
+
3031
+ var _typeof =
3032
+ typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
3033
+ ? function (obj) {
3034
+ return typeof obj;
3035
+ }
3036
+ : function (obj) {
3037
+ return obj &&
3038
+ typeof Symbol === 'function' &&
3039
+ obj.constructor === Symbol &&
3040
+ obj !== Symbol.prototype
3041
+ ? 'symbol'
3042
+ : typeof obj;
3043
+ };
3044
+
3045
+ exports.extractVersion = extractVersion;
3046
+ exports.wrapPeerConnectionEvent = wrapPeerConnectionEvent;
3047
+ exports.disableLog = disableLog;
3048
+ exports.disableWarnings = disableWarnings;
3049
+ exports.log = log;
3050
+ exports.deprecated = deprecated;
3051
+ exports.detectBrowser = detectBrowser;
3052
+ exports.compactObject = compactObject;
3053
+ exports.walkStats = walkStats;
3054
+ exports.filterStats = filterStats;
3055
+
3056
+ function _defineProperty(obj, key, value) {
3057
+ if (key in obj) {
3058
+ Object.defineProperty(obj, key, {
3059
+ value: value,
3060
+ enumerable: true,
3061
+ configurable: true,
3062
+ writable: true
3063
+ });
3064
+ } else {
3065
+ obj[key] = value;
3066
+ }
3067
+ return obj;
3068
+ }
3069
+
3070
+ var logDisabled_ = true;
3071
+ var deprecationWarnings_ = true;
3072
+
3073
+ /**
3074
+ * Extract browser version out of the provided user agent string.
3075
+ *
3076
+ * @param {!string} uastring userAgent string.
3077
+ * @param {!string} expr Regular expression used as match criteria.
3078
+ * @param {!number} pos position in the version string to be returned.
3079
+ * @return {!number} browser version.
3080
+ */
3081
+ function extractVersion(uastring, expr, pos) {
3082
+ var match = uastring.match(expr);
3083
+ return match && match.length >= pos && parseInt(match[pos], 10);
3084
+ }
3085
+
3086
+ // Wraps the peerconnection event eventNameToWrap in a function
3087
+ // which returns the modified event object (or false to prevent
3088
+ // the event).
3089
+ function wrapPeerConnectionEvent(window, eventNameToWrap, wrapper) {
3090
+ if (!window.RTCPeerConnection) {
3091
+ return;
3092
+ }
3093
+ var proto = window.RTCPeerConnection.prototype;
3094
+ var nativeAddEventListener = proto.addEventListener;
3095
+ proto.addEventListener = function (nativeEventName, cb) {
3096
+ if (nativeEventName !== eventNameToWrap) {
3097
+ return nativeAddEventListener.apply(this, arguments);
3098
+ }
3099
+ var wrappedCallback = function wrappedCallback(e) {
3100
+ var modifiedEvent = wrapper(e);
3101
+ if (modifiedEvent) {
3102
+ if (cb.handleEvent) {
3103
+ cb.handleEvent(modifiedEvent);
3104
+ } else {
3105
+ cb(modifiedEvent);
3106
+ }
3107
+ }
3108
+ };
3109
+ this._eventMap = this._eventMap || {};
3110
+ if (!this._eventMap[eventNameToWrap]) {
3111
+ this._eventMap[eventNameToWrap] = new Map();
3112
+ }
3113
+ this._eventMap[eventNameToWrap].set(cb, wrappedCallback);
3114
+ return nativeAddEventListener.apply(this, [nativeEventName, wrappedCallback]);
3115
+ };
3116
+
3117
+ var nativeRemoveEventListener = proto.removeEventListener;
3118
+ proto.removeEventListener = function (nativeEventName, cb) {
3119
+ if (
3120
+ nativeEventName !== eventNameToWrap ||
3121
+ !this._eventMap ||
3122
+ !this._eventMap[eventNameToWrap]
3123
+ ) {
3124
+ return nativeRemoveEventListener.apply(this, arguments);
3125
+ }
3126
+ if (!this._eventMap[eventNameToWrap].has(cb)) {
3127
+ return nativeRemoveEventListener.apply(this, arguments);
3128
+ }
3129
+ var unwrappedCb = this._eventMap[eventNameToWrap].get(cb);
3130
+ this._eventMap[eventNameToWrap].delete(cb);
3131
+ if (this._eventMap[eventNameToWrap].size === 0) {
3132
+ delete this._eventMap[eventNameToWrap];
3133
+ }
3134
+ if (Object.keys(this._eventMap).length === 0) {
3135
+ delete this._eventMap;
3136
+ }
3137
+ return nativeRemoveEventListener.apply(this, [nativeEventName, unwrappedCb]);
3138
+ };
3139
+
3140
+ Object.defineProperty(proto, 'on' + eventNameToWrap, {
3141
+ get: function get() {
3142
+ return this['_on' + eventNameToWrap];
3143
+ },
3144
+ set: function set(cb) {
3145
+ if (this['_on' + eventNameToWrap]) {
3146
+ this.removeEventListener(eventNameToWrap, this['_on' + eventNameToWrap]);
3147
+ delete this['_on' + eventNameToWrap];
3148
+ }
3149
+ if (cb) {
3150
+ this.addEventListener(eventNameToWrap, (this['_on' + eventNameToWrap] = cb));
3151
+ }
3152
+ },
3153
+
3154
+ enumerable: true,
3155
+ configurable: true
3156
+ });
3157
+ }
3158
+
3159
+ function disableLog(bool) {
3160
+ if (typeof bool !== 'boolean') {
3161
+ return new Error(
3162
+ 'Argument type: ' +
3163
+ (typeof bool === 'undefined' ? 'undefined' : _typeof(bool)) +
3164
+ '. Please use a boolean.'
3165
+ );
3166
+ }
3167
+ logDisabled_ = bool;
3168
+ return bool ? 'adapter.js logging disabled' : 'adapter.js logging enabled';
3169
+ }
3170
+
3171
+ /**
3172
+ * Disable or enable deprecation warnings
3173
+ * @param {!boolean} bool set to true to disable warnings.
3174
+ */
3175
+ function disableWarnings(bool) {
3176
+ if (typeof bool !== 'boolean') {
3177
+ return new Error(
3178
+ 'Argument type: ' +
3179
+ (typeof bool === 'undefined' ? 'undefined' : _typeof(bool)) +
3180
+ '. Please use a boolean.'
3181
+ );
3182
+ }
3183
+ deprecationWarnings_ = !bool;
3184
+ return 'adapter.js deprecation warnings ' + (bool ? 'disabled' : 'enabled');
3185
+ }
3186
+
3187
+ function log() {
3188
+ if ((typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object') {
3189
+ if (logDisabled_) {
3190
+ return;
3191
+ }
3192
+ if (typeof console !== 'undefined' && typeof console.log === 'function') {
3193
+ console.log.apply(console, arguments);
3194
+ }
3195
+ }
3196
+ }
3197
+
3198
+ /**
3199
+ * Shows a deprecation warning suggesting the modern and spec-compatible API.
3200
+ */
3201
+ function deprecated(oldMethod, newMethod) {
3202
+ if (!deprecationWarnings_) {
3203
+ return;
3204
+ }
3205
+ console.warn(oldMethod + ' is deprecated, please use ' + newMethod + ' instead.');
3206
+ }
3207
+
3208
+ /**
3209
+ * Browser detector.
3210
+ *
3211
+ * @return {object} result containing browser and version
3212
+ * properties.
3213
+ */
3214
+ function detectBrowser(window) {
3215
+ // Returned result object.
3216
+ var result = { browser: null, version: null };
3217
+
3218
+ // Fail early if it's not a browser
3219
+ if (typeof window === 'undefined' || !window.navigator) {
3220
+ result.browser = 'Not a browser.';
3221
+ return result;
3222
+ }
3223
+
3224
+ var navigator = window.navigator;
3225
+
3226
+ if (navigator.mozGetUserMedia) {
3227
+ // Firefox.
3228
+ result.browser = 'firefox';
3229
+ result.version = extractVersion(navigator.userAgent, /Firefox\/(\d+)\./, 1);
3230
+ } else if (
3231
+ navigator.webkitGetUserMedia ||
3232
+ (window.isSecureContext === false &&
3233
+ window.webkitRTCPeerConnection &&
3234
+ !window.RTCIceGatherer)
3235
+ ) {
3236
+ // Chrome, Chromium, Webview, Opera.
3237
+ // Version matches Chrome/WebRTC version.
3238
+ // Chrome 74 removed webkitGetUserMedia on http as well so we need the
3239
+ // more complicated fallback to webkitRTCPeerConnection.
3240
+ result.browser = 'chrome';
3241
+ result.version = extractVersion(navigator.userAgent, /Chrom(e|ium)\/(\d+)\./, 2);
3242
+ } else if (
3243
+ window.RTCPeerConnection &&
3244
+ navigator.userAgent.match(/AppleWebKit\/(\d+)\./)
3245
+ ) {
3246
+ // Safari.
3247
+ result.browser = 'safari';
3248
+ result.version = extractVersion(navigator.userAgent, /AppleWebKit\/(\d+)\./, 1);
3249
+ result.supportsUnifiedPlan =
3250
+ window.RTCRtpTransceiver &&
3251
+ 'currentDirection' in window.RTCRtpTransceiver.prototype;
3252
+ } else {
3253
+ // Default fallthrough: not supported.
3254
+ result.browser = 'Not a supported browser.';
3255
+ return result;
3256
+ }
3257
+
3258
+ return result;
3259
+ }
3260
+
3261
+ /**
3262
+ * Checks if something is an object.
3263
+ *
3264
+ * @param {*} val The something you want to check.
3265
+ * @return true if val is an object, false otherwise.
3266
+ */
3267
+ function isObject(val) {
3268
+ return Object.prototype.toString.call(val) === '[object Object]';
3269
+ }
3270
+
3271
+ /**
3272
+ * Remove all empty objects and undefined values
3273
+ * from a nested object -- an enhanced and vanilla version
3274
+ * of Lodash's `compact`.
3275
+ */
3276
+ function compactObject(data) {
3277
+ if (!isObject(data)) {
3278
+ return data;
3279
+ }
3280
+
3281
+ return Object.keys(data).reduce(function (accumulator, key) {
3282
+ var isObj = isObject(data[key]);
3283
+ var value = isObj ? compactObject(data[key]) : data[key];
3284
+ var isEmptyObject = isObj && !Object.keys(value).length;
3285
+ if (value === undefined || isEmptyObject) {
3286
+ return accumulator;
3287
+ }
3288
+ return Object.assign(accumulator, _defineProperty({}, key, value));
3289
+ }, {});
3290
+ }
3291
+
3292
+ /* iterates the stats graph recursively. */
3293
+ function walkStats(stats, base, resultSet) {
3294
+ if (!base || resultSet.has(base.id)) {
3295
+ return;
3296
+ }
3297
+ resultSet.set(base.id, base);
3298
+ Object.keys(base).forEach(function (name) {
3299
+ if (name.endsWith('Id')) {
3300
+ walkStats(stats, stats.get(base[name]), resultSet);
3301
+ } else if (name.endsWith('Ids')) {
3302
+ base[name].forEach(function (id) {
3303
+ walkStats(stats, stats.get(id), resultSet);
3304
+ });
3305
+ }
3306
+ });
3307
+ }
3308
+
3309
+ /* filter getStats for a sender/receiver track. */
3310
+ function filterStats(result, track, outbound) {
3311
+ var streamStatsType = outbound ? 'outbound-rtp' : 'inbound-rtp';
3312
+ var filteredResult = new Map();
3313
+ if (track === null) {
3314
+ return filteredResult;
3315
+ }
3316
+ var trackStats = [];
3317
+ result.forEach(function (value) {
3318
+ if (value.type === 'track' && value.trackIdentifier === track.id) {
3319
+ trackStats.push(value);
3320
+ }
3321
+ });
3322
+ trackStats.forEach(function (trackStat) {
3323
+ result.forEach(function (stats) {
3324
+ if (stats.type === streamStatsType && stats.trackId === trackStat.id) {
3325
+ walkStats(result, stats, filteredResult);
3326
+ }
3327
+ });
3328
+ });
3329
+ return filteredResult;
3330
+ }
3331
+ },
3332
+ {}
3333
+ ],
3334
+ 12: [
3335
+ function (require, module, exports) {
3336
+ /* eslint-env node */
3337
+ 'use strict';
3338
+
3339
+ // SDP helpers.
3340
+
3341
+ var _typeof =
3342
+ typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
3343
+ ? function (obj) {
3344
+ return typeof obj;
3345
+ }
3346
+ : function (obj) {
3347
+ return obj &&
3348
+ typeof Symbol === 'function' &&
3349
+ obj.constructor === Symbol &&
3350
+ obj !== Symbol.prototype
3351
+ ? 'symbol'
3352
+ : typeof obj;
3353
+ };
3354
+
3355
+ var SDPUtils = {};
3356
+
3357
+ // Generate an alphanumeric identifier for cname or mids.
3358
+ // TODO: use UUIDs instead? https://gist.github.com/jed/982883
3359
+ SDPUtils.generateIdentifier = function () {
3360
+ return Math.random().toString(36).substr(2, 10);
3361
+ };
3362
+
3363
+ // The RTCP CNAME used by all peerconnections from the same JS.
3364
+ SDPUtils.localCName = SDPUtils.generateIdentifier();
3365
+
3366
+ // Splits SDP into lines, dealing with both CRLF and LF.
3367
+ SDPUtils.splitLines = function (blob) {
3368
+ return blob
3369
+ .trim()
3370
+ .split('\n')
3371
+ .map(function (line) {
3372
+ return line.trim();
3373
+ });
3374
+ };
3375
+ // Splits SDP into sessionpart and mediasections. Ensures CRLF.
3376
+ SDPUtils.splitSections = function (blob) {
3377
+ var parts = blob.split('\nm=');
3378
+ return parts.map(function (part, index) {
3379
+ return (index > 0 ? 'm=' + part : part).trim() + '\r\n';
3380
+ });
3381
+ };
3382
+
3383
+ // Returns the session description.
3384
+ SDPUtils.getDescription = function (blob) {
3385
+ var sections = SDPUtils.splitSections(blob);
3386
+ return sections && sections[0];
3387
+ };
3388
+
3389
+ // Returns the individual media sections.
3390
+ SDPUtils.getMediaSections = function (blob) {
3391
+ var sections = SDPUtils.splitSections(blob);
3392
+ sections.shift();
3393
+ return sections;
3394
+ };
3395
+
3396
+ // Returns lines that start with a certain prefix.
3397
+ SDPUtils.matchPrefix = function (blob, prefix) {
3398
+ return SDPUtils.splitLines(blob).filter(function (line) {
3399
+ return line.indexOf(prefix) === 0;
3400
+ });
3401
+ };
3402
+
3403
+ // Parses an ICE candidate line. Sample input:
3404
+ // candidate:702786350 2 udp 41819902 8.8.8.8 60769 typ relay raddr 8.8.8.8
3405
+ // rport 55996"
3406
+ // Input can be prefixed with a=.
3407
+ SDPUtils.parseCandidate = function (line) {
3408
+ var parts = void 0;
3409
+ // Parse both variants.
3410
+ if (line.indexOf('a=candidate:') === 0) {
3411
+ parts = line.substring(12).split(' ');
3412
+ } else {
3413
+ parts = line.substring(10).split(' ');
3414
+ }
3415
+
3416
+ var candidate = {
3417
+ foundation: parts[0],
3418
+ component: { 1: 'rtp', 2: 'rtcp' }[parts[1]] || parts[1],
3419
+ protocol: parts[2].toLowerCase(),
3420
+ priority: parseInt(parts[3], 10),
3421
+ ip: parts[4],
3422
+ address: parts[4], // address is an alias for ip.
3423
+ port: parseInt(parts[5], 10),
3424
+ // skip parts[6] == 'typ'
3425
+ type: parts[7]
3426
+ };
3427
+
3428
+ for (var i = 8; i < parts.length; i += 2) {
3429
+ switch (parts[i]) {
3430
+ case 'raddr':
3431
+ candidate.relatedAddress = parts[i + 1];
3432
+ break;
3433
+ case 'rport':
3434
+ candidate.relatedPort = parseInt(parts[i + 1], 10);
3435
+ break;
3436
+ case 'tcptype':
3437
+ candidate.tcpType = parts[i + 1];
3438
+ break;
3439
+ case 'ufrag':
3440
+ candidate.ufrag = parts[i + 1]; // for backward compatibility.
3441
+ candidate.usernameFragment = parts[i + 1];
3442
+ break;
3443
+ default:
3444
+ // extension handling, in particular ufrag. Don't overwrite.
3445
+ if (candidate[parts[i]] === undefined) {
3446
+ candidate[parts[i]] = parts[i + 1];
3447
+ }
3448
+ break;
3449
+ }
3450
+ }
3451
+ return candidate;
3452
+ };
3453
+
3454
+ // Translates a candidate object into SDP candidate attribute.
3455
+ // This does not include the a= prefix!
3456
+ SDPUtils.writeCandidate = function (candidate) {
3457
+ var sdp = [];
3458
+ sdp.push(candidate.foundation);
3459
+
3460
+ var component = candidate.component;
3461
+ if (component === 'rtp') {
3462
+ sdp.push(1);
3463
+ } else if (component === 'rtcp') {
3464
+ sdp.push(2);
3465
+ } else {
3466
+ sdp.push(component);
3467
+ }
3468
+ sdp.push(candidate.protocol.toUpperCase());
3469
+ sdp.push(candidate.priority);
3470
+ sdp.push(candidate.address || candidate.ip);
3471
+ sdp.push(candidate.port);
3472
+
3473
+ var type = candidate.type;
3474
+ sdp.push('typ');
3475
+ sdp.push(type);
3476
+ if (type !== 'host' && candidate.relatedAddress && candidate.relatedPort) {
3477
+ sdp.push('raddr');
3478
+ sdp.push(candidate.relatedAddress);
3479
+ sdp.push('rport');
3480
+ sdp.push(candidate.relatedPort);
3481
+ }
3482
+ if (candidate.tcpType && candidate.protocol.toLowerCase() === 'tcp') {
3483
+ sdp.push('tcptype');
3484
+ sdp.push(candidate.tcpType);
3485
+ }
3486
+ if (candidate.usernameFragment || candidate.ufrag) {
3487
+ sdp.push('ufrag');
3488
+ sdp.push(candidate.usernameFragment || candidate.ufrag);
3489
+ }
3490
+ return 'candidate:' + sdp.join(' ');
3491
+ };
3492
+
3493
+ // Parses an ice-options line, returns an array of option tags.
3494
+ // Sample input:
3495
+ // a=ice-options:foo bar
3496
+ SDPUtils.parseIceOptions = function (line) {
3497
+ return line.substr(14).split(' ');
3498
+ };
3499
+
3500
+ // Parses a rtpmap line, returns RTCRtpCoddecParameters. Sample input:
3501
+ // a=rtpmap:111 opus/48000/2
3502
+ SDPUtils.parseRtpMap = function (line) {
3503
+ var parts = line.substr(9).split(' ');
3504
+ var parsed = {
3505
+ payloadType: parseInt(parts.shift(), 10) // was: id
3506
+ };
3507
+
3508
+ parts = parts[0].split('/');
3509
+
3510
+ parsed.name = parts[0];
3511
+ parsed.clockRate = parseInt(parts[1], 10); // was: clockrate
3512
+ parsed.channels = parts.length === 3 ? parseInt(parts[2], 10) : 1;
3513
+ // legacy alias, got renamed back to channels in ORTC.
3514
+ parsed.numChannels = parsed.channels;
3515
+ return parsed;
3516
+ };
3517
+
3518
+ // Generates a rtpmap line from RTCRtpCodecCapability or
3519
+ // RTCRtpCodecParameters.
3520
+ SDPUtils.writeRtpMap = function (codec) {
3521
+ var pt = codec.payloadType;
3522
+ if (codec.preferredPayloadType !== undefined) {
3523
+ pt = codec.preferredPayloadType;
3524
+ }
3525
+ var channels = codec.channels || codec.numChannels || 1;
3526
+ return (
3527
+ 'a=rtpmap:' +
3528
+ pt +
3529
+ ' ' +
3530
+ codec.name +
3531
+ '/' +
3532
+ codec.clockRate +
3533
+ (channels !== 1 ? '/' + channels : '') +
3534
+ '\r\n'
3535
+ );
3536
+ };
3537
+
3538
+ // Parses a extmap line (headerextension from RFC 5285). Sample input:
3539
+ // a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
3540
+ // a=extmap:2/sendonly urn:ietf:params:rtp-hdrext:toffset
3541
+ SDPUtils.parseExtmap = function (line) {
3542
+ var parts = line.substr(9).split(' ');
3543
+ return {
3544
+ id: parseInt(parts[0], 10),
3545
+ direction: parts[0].indexOf('/') > 0 ? parts[0].split('/')[1] : 'sendrecv',
3546
+ uri: parts[1]
3547
+ };
3548
+ };
3549
+
3550
+ // Generates an extmap line from RTCRtpHeaderExtensionParameters or
3551
+ // RTCRtpHeaderExtension.
3552
+ SDPUtils.writeExtmap = function (headerExtension) {
3553
+ return (
3554
+ 'a=extmap:' +
3555
+ (headerExtension.id || headerExtension.preferredId) +
3556
+ (headerExtension.direction && headerExtension.direction !== 'sendrecv'
3557
+ ? '/' + headerExtension.direction
3558
+ : '') +
3559
+ ' ' +
3560
+ headerExtension.uri +
3561
+ '\r\n'
3562
+ );
3563
+ };
3564
+
3565
+ // Parses a fmtp line, returns dictionary. Sample input:
3566
+ // a=fmtp:96 vbr=on;cng=on
3567
+ // Also deals with vbr=on; cng=on
3568
+ SDPUtils.parseFmtp = function (line) {
3569
+ var parsed = {};
3570
+ var kv = void 0;
3571
+ var parts = line.substr(line.indexOf(' ') + 1).split(';');
3572
+ for (var j = 0; j < parts.length; j++) {
3573
+ kv = parts[j].trim().split('=');
3574
+ parsed[kv[0].trim()] = kv[1];
3575
+ }
3576
+ return parsed;
3577
+ };
3578
+
3579
+ // Generates a fmtp line from RTCRtpCodecCapability or RTCRtpCodecParameters.
3580
+ SDPUtils.writeFmtp = function (codec) {
3581
+ var line = '';
3582
+ var pt = codec.payloadType;
3583
+ if (codec.preferredPayloadType !== undefined) {
3584
+ pt = codec.preferredPayloadType;
3585
+ }
3586
+ if (codec.parameters && Object.keys(codec.parameters).length) {
3587
+ var params = [];
3588
+ Object.keys(codec.parameters).forEach(function (param) {
3589
+ if (codec.parameters[param] !== undefined) {
3590
+ params.push(param + '=' + codec.parameters[param]);
3591
+ } else {
3592
+ params.push(param);
3593
+ }
3594
+ });
3595
+ line += 'a=fmtp:' + pt + ' ' + params.join(';') + '\r\n';
3596
+ }
3597
+ return line;
3598
+ };
3599
+
3600
+ // Parses a rtcp-fb line, returns RTCPRtcpFeedback object. Sample input:
3601
+ // a=rtcp-fb:98 nack rpsi
3602
+ SDPUtils.parseRtcpFb = function (line) {
3603
+ var parts = line.substr(line.indexOf(' ') + 1).split(' ');
3604
+ return {
3605
+ type: parts.shift(),
3606
+ parameter: parts.join(' ')
3607
+ };
3608
+ };
3609
+
3610
+ // Generate a=rtcp-fb lines from RTCRtpCodecCapability or RTCRtpCodecParameters.
3611
+ SDPUtils.writeRtcpFb = function (codec) {
3612
+ var lines = '';
3613
+ var pt = codec.payloadType;
3614
+ if (codec.preferredPayloadType !== undefined) {
3615
+ pt = codec.preferredPayloadType;
3616
+ }
3617
+ if (codec.rtcpFeedback && codec.rtcpFeedback.length) {
3618
+ // FIXME: special handling for trr-int?
3619
+ codec.rtcpFeedback.forEach(function (fb) {
3620
+ lines +=
3621
+ 'a=rtcp-fb:' +
3622
+ pt +
3623
+ ' ' +
3624
+ fb.type +
3625
+ (fb.parameter && fb.parameter.length ? ' ' + fb.parameter : '') +
3626
+ '\r\n';
3627
+ });
3628
+ }
3629
+ return lines;
3630
+ };
3631
+
3632
+ // Parses a RFC 5576 ssrc media attribute. Sample input:
3633
+ // a=ssrc:3735928559 cname:something
3634
+ SDPUtils.parseSsrcMedia = function (line) {
3635
+ var sp = line.indexOf(' ');
3636
+ var parts = {
3637
+ ssrc: parseInt(line.substr(7, sp - 7), 10)
3638
+ };
3639
+ var colon = line.indexOf(':', sp);
3640
+ if (colon > -1) {
3641
+ parts.attribute = line.substr(sp + 1, colon - sp - 1);
3642
+ parts.value = line.substr(colon + 1);
3643
+ } else {
3644
+ parts.attribute = line.substr(sp + 1);
3645
+ }
3646
+ return parts;
3647
+ };
3648
+
3649
+ // Parse a ssrc-group line (see RFC 5576). Sample input:
3650
+ // a=ssrc-group:semantics 12 34
3651
+ SDPUtils.parseSsrcGroup = function (line) {
3652
+ var parts = line.substr(13).split(' ');
3653
+ return {
3654
+ semantics: parts.shift(),
3655
+ ssrcs: parts.map(function (ssrc) {
3656
+ return parseInt(ssrc, 10);
3657
+ })
3658
+ };
3659
+ };
3660
+
3661
+ // Extracts the MID (RFC 5888) from a media section.
3662
+ // Returns the MID or undefined if no mid line was found.
3663
+ SDPUtils.getMid = function (mediaSection) {
3664
+ var mid = SDPUtils.matchPrefix(mediaSection, 'a=mid:')[0];
3665
+ if (mid) {
3666
+ return mid.substr(6);
3667
+ }
3668
+ };
3669
+
3670
+ // Parses a fingerprint line for DTLS-SRTP.
3671
+ SDPUtils.parseFingerprint = function (line) {
3672
+ var parts = line.substr(14).split(' ');
3673
+ return {
3674
+ algorithm: parts[0].toLowerCase(), // algorithm is case-sensitive in Edge.
3675
+ value: parts[1].toUpperCase() // the definition is upper-case in RFC 4572.
3676
+ };
3677
+ };
3678
+
3679
+ // Extracts DTLS parameters from SDP media section or sessionpart.
3680
+ // FIXME: for consistency with other functions this should only
3681
+ // get the fingerprint line as input. See also getIceParameters.
3682
+ SDPUtils.getDtlsParameters = function (mediaSection, sessionpart) {
3683
+ var lines = SDPUtils.matchPrefix(mediaSection + sessionpart, 'a=fingerprint:');
3684
+ // Note: a=setup line is ignored since we use the 'auto' role in Edge.
3685
+ return {
3686
+ role: 'auto',
3687
+ fingerprints: lines.map(SDPUtils.parseFingerprint)
3688
+ };
3689
+ };
3690
+
3691
+ // Serializes DTLS parameters to SDP.
3692
+ SDPUtils.writeDtlsParameters = function (params, setupType) {
3693
+ var sdp = 'a=setup:' + setupType + '\r\n';
3694
+ params.fingerprints.forEach(function (fp) {
3695
+ sdp += 'a=fingerprint:' + fp.algorithm + ' ' + fp.value + '\r\n';
3696
+ });
3697
+ return sdp;
3698
+ };
3699
+
3700
+ // Parses a=crypto lines into
3701
+ // https://rawgit.com/aboba/edgertc/master/msortc-rs4.html#dictionary-rtcsrtpsdesparameters-members
3702
+ SDPUtils.parseCryptoLine = function (line) {
3703
+ var parts = line.substr(9).split(' ');
3704
+ return {
3705
+ tag: parseInt(parts[0], 10),
3706
+ cryptoSuite: parts[1],
3707
+ keyParams: parts[2],
3708
+ sessionParams: parts.slice(3)
3709
+ };
3710
+ };
3711
+
3712
+ SDPUtils.writeCryptoLine = function (parameters) {
3713
+ return (
3714
+ 'a=crypto:' +
3715
+ parameters.tag +
3716
+ ' ' +
3717
+ parameters.cryptoSuite +
3718
+ ' ' +
3719
+ (_typeof(parameters.keyParams) === 'object'
3720
+ ? SDPUtils.writeCryptoKeyParams(parameters.keyParams)
3721
+ : parameters.keyParams) +
3722
+ (parameters.sessionParams ? ' ' + parameters.sessionParams.join(' ') : '') +
3723
+ '\r\n'
3724
+ );
3725
+ };
3726
+
3727
+ // Parses the crypto key parameters into
3728
+ // https://rawgit.com/aboba/edgertc/master/msortc-rs4.html#rtcsrtpkeyparam*
3729
+ SDPUtils.parseCryptoKeyParams = function (keyParams) {
3730
+ if (keyParams.indexOf('inline:') !== 0) {
3731
+ return null;
3732
+ }
3733
+ var parts = keyParams.substr(7).split('|');
3734
+ return {
3735
+ keyMethod: 'inline',
3736
+ keySalt: parts[0],
3737
+ lifeTime: parts[1],
3738
+ mkiValue: parts[2] ? parts[2].split(':')[0] : undefined,
3739
+ mkiLength: parts[2] ? parts[2].split(':')[1] : undefined
3740
+ };
3741
+ };
3742
+
3743
+ SDPUtils.writeCryptoKeyParams = function (keyParams) {
3744
+ return (
3745
+ keyParams.keyMethod +
3746
+ ':' +
3747
+ keyParams.keySalt +
3748
+ (keyParams.lifeTime ? '|' + keyParams.lifeTime : '') +
3749
+ (keyParams.mkiValue && keyParams.mkiLength
3750
+ ? '|' + keyParams.mkiValue + ':' + keyParams.mkiLength
3751
+ : '')
3752
+ );
3753
+ };
3754
+
3755
+ // Extracts all SDES parameters.
3756
+ SDPUtils.getCryptoParameters = function (mediaSection, sessionpart) {
3757
+ var lines = SDPUtils.matchPrefix(mediaSection + sessionpart, 'a=crypto:');
3758
+ return lines.map(SDPUtils.parseCryptoLine);
3759
+ };
3760
+
3761
+ // Parses ICE information from SDP media section or sessionpart.
3762
+ // FIXME: for consistency with other functions this should only
3763
+ // get the ice-ufrag and ice-pwd lines as input.
3764
+ SDPUtils.getIceParameters = function (mediaSection, sessionpart) {
3765
+ var ufrag = SDPUtils.matchPrefix(mediaSection + sessionpart, 'a=ice-ufrag:')[0];
3766
+ var pwd = SDPUtils.matchPrefix(mediaSection + sessionpart, 'a=ice-pwd:')[0];
3767
+ if (!(ufrag && pwd)) {
3768
+ return null;
3769
+ }
3770
+ return {
3771
+ usernameFragment: ufrag.substr(12),
3772
+ password: pwd.substr(10)
3773
+ };
3774
+ };
3775
+
3776
+ // Serializes ICE parameters to SDP.
3777
+ SDPUtils.writeIceParameters = function (params) {
3778
+ var sdp =
3779
+ 'a=ice-ufrag:' +
3780
+ params.usernameFragment +
3781
+ '\r\n' +
3782
+ 'a=ice-pwd:' +
3783
+ params.password +
3784
+ '\r\n';
3785
+ if (params.iceLite) {
3786
+ sdp += 'a=ice-lite\r\n';
3787
+ }
3788
+ return sdp;
3789
+ };
3790
+
3791
+ // Parses the SDP media section and returns RTCRtpParameters.
3792
+ SDPUtils.parseRtpParameters = function (mediaSection) {
3793
+ var description = {
3794
+ codecs: [],
3795
+ headerExtensions: [],
3796
+ fecMechanisms: [],
3797
+ rtcp: []
3798
+ };
3799
+ var lines = SDPUtils.splitLines(mediaSection);
3800
+ var mline = lines[0].split(' ');
3801
+ for (var i = 3; i < mline.length; i++) {
3802
+ // find all codecs from mline[3..]
3803
+ var pt = mline[i];
3804
+ var rtpmapline = SDPUtils.matchPrefix(mediaSection, 'a=rtpmap:' + pt + ' ')[0];
3805
+ if (rtpmapline) {
3806
+ var codec = SDPUtils.parseRtpMap(rtpmapline);
3807
+ var fmtps = SDPUtils.matchPrefix(mediaSection, 'a=fmtp:' + pt + ' ');
3808
+ // Only the first a=fmtp:<pt> is considered.
3809
+ codec.parameters = fmtps.length ? SDPUtils.parseFmtp(fmtps[0]) : {};
3810
+ codec.rtcpFeedback = SDPUtils.matchPrefix(
3811
+ mediaSection,
3812
+ 'a=rtcp-fb:' + pt + ' '
3813
+ ).map(SDPUtils.parseRtcpFb);
3814
+ description.codecs.push(codec);
3815
+ // parse FEC mechanisms from rtpmap lines.
3816
+ switch (codec.name.toUpperCase()) {
3817
+ case 'RED':
3818
+ case 'ULPFEC':
3819
+ description.fecMechanisms.push(codec.name.toUpperCase());
3820
+ break;
3821
+ default:
3822
+ // only RED and ULPFEC are recognized as FEC mechanisms.
3823
+ break;
3824
+ }
3825
+ }
3826
+ }
3827
+ SDPUtils.matchPrefix(mediaSection, 'a=extmap:').forEach(function (line) {
3828
+ description.headerExtensions.push(SDPUtils.parseExtmap(line));
3829
+ });
3830
+ // FIXME: parse rtcp.
3831
+ return description;
3832
+ };
3833
+
3834
+ // Generates parts of the SDP media section describing the capabilities /
3835
+ // parameters.
3836
+ SDPUtils.writeRtpDescription = function (kind, caps) {
3837
+ var sdp = '';
3838
+
3839
+ // Build the mline.
3840
+ sdp += 'm=' + kind + ' ';
3841
+ sdp += caps.codecs.length > 0 ? '9' : '0'; // reject if no codecs.
3842
+ sdp += ' UDP/TLS/RTP/SAVPF ';
3843
+ sdp +=
3844
+ caps.codecs
3845
+ .map(function (codec) {
3846
+ if (codec.preferredPayloadType !== undefined) {
3847
+ return codec.preferredPayloadType;
3848
+ }
3849
+ return codec.payloadType;
3850
+ })
3851
+ .join(' ') + '\r\n';
3852
+
3853
+ sdp += 'c=IN IP4 0.0.0.0\r\n';
3854
+ sdp += 'a=rtcp:9 IN IP4 0.0.0.0\r\n';
3855
+
3856
+ // Add a=rtpmap lines for each codec. Also fmtp and rtcp-fb.
3857
+ caps.codecs.forEach(function (codec) {
3858
+ sdp += SDPUtils.writeRtpMap(codec);
3859
+ sdp += SDPUtils.writeFmtp(codec);
3860
+ sdp += SDPUtils.writeRtcpFb(codec);
3861
+ });
3862
+ var maxptime = 0;
3863
+ caps.codecs.forEach(function (codec) {
3864
+ if (codec.maxptime > maxptime) {
3865
+ maxptime = codec.maxptime;
3866
+ }
3867
+ });
3868
+ if (maxptime > 0) {
3869
+ sdp += 'a=maxptime:' + maxptime + '\r\n';
3870
+ }
3871
+
3872
+ if (caps.headerExtensions) {
3873
+ caps.headerExtensions.forEach(function (extension) {
3874
+ sdp += SDPUtils.writeExtmap(extension);
3875
+ });
3876
+ }
3877
+ // FIXME: write fecMechanisms.
3878
+ return sdp;
3879
+ };
3880
+
3881
+ // Parses the SDP media section and returns an array of
3882
+ // RTCRtpEncodingParameters.
3883
+ SDPUtils.parseRtpEncodingParameters = function (mediaSection) {
3884
+ var encodingParameters = [];
3885
+ var description = SDPUtils.parseRtpParameters(mediaSection);
3886
+ var hasRed = description.fecMechanisms.indexOf('RED') !== -1;
3887
+ var hasUlpfec = description.fecMechanisms.indexOf('ULPFEC') !== -1;
3888
+
3889
+ // filter a=ssrc:... cname:, ignore PlanB-msid
3890
+ var ssrcs = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:')
3891
+ .map(function (line) {
3892
+ return SDPUtils.parseSsrcMedia(line);
3893
+ })
3894
+ .filter(function (parts) {
3895
+ return parts.attribute === 'cname';
3896
+ });
3897
+ var primarySsrc = ssrcs.length > 0 && ssrcs[0].ssrc;
3898
+ var secondarySsrc = void 0;
3899
+
3900
+ var flows = SDPUtils.matchPrefix(mediaSection, 'a=ssrc-group:FID').map(function (line) {
3901
+ var parts = line.substr(17).split(' ');
3902
+ return parts.map(function (part) {
3903
+ return parseInt(part, 10);
3904
+ });
3905
+ });
3906
+ if (flows.length > 0 && flows[0].length > 1 && flows[0][0] === primarySsrc) {
3907
+ secondarySsrc = flows[0][1];
3908
+ }
3909
+
3910
+ description.codecs.forEach(function (codec) {
3911
+ if (codec.name.toUpperCase() === 'RTX' && codec.parameters.apt) {
3912
+ var encParam = {
3913
+ ssrc: primarySsrc,
3914
+ codecPayloadType: parseInt(codec.parameters.apt, 10)
3915
+ };
3916
+ if (primarySsrc && secondarySsrc) {
3917
+ encParam.rtx = { ssrc: secondarySsrc };
3918
+ }
3919
+ encodingParameters.push(encParam);
3920
+ if (hasRed) {
3921
+ encParam = JSON.parse(JSON.stringify(encParam));
3922
+ encParam.fec = {
3923
+ ssrc: primarySsrc,
3924
+ mechanism: hasUlpfec ? 'red+ulpfec' : 'red'
3925
+ };
3926
+ encodingParameters.push(encParam);
3927
+ }
3928
+ }
3929
+ });
3930
+ if (encodingParameters.length === 0 && primarySsrc) {
3931
+ encodingParameters.push({
3932
+ ssrc: primarySsrc
3933
+ });
3934
+ }
3935
+
3936
+ // we support both b=AS and b=TIAS but interpret AS as TIAS.
3937
+ var bandwidth = SDPUtils.matchPrefix(mediaSection, 'b=');
3938
+ if (bandwidth.length) {
3939
+ if (bandwidth[0].indexOf('b=TIAS:') === 0) {
3940
+ bandwidth = parseInt(bandwidth[0].substr(7), 10);
3941
+ } else if (bandwidth[0].indexOf('b=AS:') === 0) {
3942
+ // use formula from JSEP to convert b=AS to TIAS value.
3943
+ bandwidth = parseInt(bandwidth[0].substr(5), 10) * 1000 * 0.95 - 50 * 40 * 8;
3944
+ } else {
3945
+ bandwidth = undefined;
3946
+ }
3947
+ encodingParameters.forEach(function (params) {
3948
+ params.maxBitrate = bandwidth;
3949
+ });
3950
+ }
3951
+ return encodingParameters;
3952
+ };
3953
+
3954
+ // parses http://draft.ortc.org/#rtcrtcpparameters*
3955
+ SDPUtils.parseRtcpParameters = function (mediaSection) {
3956
+ var rtcpParameters = {};
3957
+
3958
+ // Gets the first SSRC. Note that with RTX there might be multiple
3959
+ // SSRCs.
3960
+ var remoteSsrc = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:')
3961
+ .map(function (line) {
3962
+ return SDPUtils.parseSsrcMedia(line);
3963
+ })
3964
+ .filter(function (obj) {
3965
+ return obj.attribute === 'cname';
3966
+ })[0];
3967
+ if (remoteSsrc) {
3968
+ rtcpParameters.cname = remoteSsrc.value;
3969
+ rtcpParameters.ssrc = remoteSsrc.ssrc;
3970
+ }
3971
+
3972
+ // Edge uses the compound attribute instead of reducedSize
3973
+ // compound is !reducedSize
3974
+ var rsize = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-rsize');
3975
+ rtcpParameters.reducedSize = rsize.length > 0;
3976
+ rtcpParameters.compound = rsize.length === 0;
3977
+
3978
+ // parses the rtcp-mux attrіbute.
3979
+ // Note that Edge does not support unmuxed RTCP.
3980
+ var mux = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-mux');
3981
+ rtcpParameters.mux = mux.length > 0;
3982
+
3983
+ return rtcpParameters;
3984
+ };
3985
+
3986
+ SDPUtils.writeRtcpParameters = function (rtcpParameters) {
3987
+ var sdp = '';
3988
+ if (rtcpParameters.reducedSize) {
3989
+ sdp += 'a=rtcp-rsize\r\n';
3990
+ }
3991
+ if (rtcpParameters.mux) {
3992
+ sdp += 'a=rtcp-mux\r\n';
3993
+ }
3994
+ if (rtcpParameters.ssrc !== undefined && rtcpParameters.cname) {
3995
+ sdp += 'a=ssrc:' + rtcpParameters.ssrc + ' cname:' + rtcpParameters.cname + '\r\n';
3996
+ }
3997
+ return sdp;
3998
+ };
3999
+
4000
+ // parses either a=msid: or a=ssrc:... msid lines and returns
4001
+ // the id of the MediaStream and MediaStreamTrack.
4002
+ SDPUtils.parseMsid = function (mediaSection) {
4003
+ var parts = void 0;
4004
+ var spec = SDPUtils.matchPrefix(mediaSection, 'a=msid:');
4005
+ if (spec.length === 1) {
4006
+ parts = spec[0].substr(7).split(' ');
4007
+ return { stream: parts[0], track: parts[1] };
4008
+ }
4009
+ var planB = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:')
4010
+ .map(function (line) {
4011
+ return SDPUtils.parseSsrcMedia(line);
4012
+ })
4013
+ .filter(function (msidParts) {
4014
+ return msidParts.attribute === 'msid';
4015
+ });
4016
+ if (planB.length > 0) {
4017
+ parts = planB[0].value.split(' ');
4018
+ return { stream: parts[0], track: parts[1] };
4019
+ }
4020
+ };
4021
+
4022
+ // SCTP
4023
+ // parses draft-ietf-mmusic-sctp-sdp-26 first and falls back
4024
+ // to draft-ietf-mmusic-sctp-sdp-05
4025
+ SDPUtils.parseSctpDescription = function (mediaSection) {
4026
+ var mline = SDPUtils.parseMLine(mediaSection);
4027
+ var maxSizeLine = SDPUtils.matchPrefix(mediaSection, 'a=max-message-size:');
4028
+ var maxMessageSize = void 0;
4029
+ if (maxSizeLine.length > 0) {
4030
+ maxMessageSize = parseInt(maxSizeLine[0].substr(19), 10);
4031
+ }
4032
+ if (isNaN(maxMessageSize)) {
4033
+ maxMessageSize = 65536;
4034
+ }
4035
+ var sctpPort = SDPUtils.matchPrefix(mediaSection, 'a=sctp-port:');
4036
+ if (sctpPort.length > 0) {
4037
+ return {
4038
+ port: parseInt(sctpPort[0].substr(12), 10),
4039
+ protocol: mline.fmt,
4040
+ maxMessageSize: maxMessageSize
4041
+ };
4042
+ }
4043
+ var sctpMapLines = SDPUtils.matchPrefix(mediaSection, 'a=sctpmap:');
4044
+ if (sctpMapLines.length > 0) {
4045
+ var parts = sctpMapLines[0].substr(10).split(' ');
4046
+ return {
4047
+ port: parseInt(parts[0], 10),
4048
+ protocol: parts[1],
4049
+ maxMessageSize: maxMessageSize
4050
+ };
4051
+ }
4052
+ };
4053
+
4054
+ // SCTP
4055
+ // outputs the draft-ietf-mmusic-sctp-sdp-26 version that all browsers
4056
+ // support by now receiving in this format, unless we originally parsed
4057
+ // as the draft-ietf-mmusic-sctp-sdp-05 format (indicated by the m-line
4058
+ // protocol of DTLS/SCTP -- without UDP/ or TCP/)
4059
+ SDPUtils.writeSctpDescription = function (media, sctp) {
4060
+ var output = [];
4061
+ if (media.protocol !== 'DTLS/SCTP') {
4062
+ output = [
4063
+ 'm=' + media.kind + ' 9 ' + media.protocol + ' ' + sctp.protocol + '\r\n',
4064
+ 'c=IN IP4 0.0.0.0\r\n',
4065
+ 'a=sctp-port:' + sctp.port + '\r\n'
4066
+ ];
4067
+ } else {
4068
+ output = [
4069
+ 'm=' + media.kind + ' 9 ' + media.protocol + ' ' + sctp.port + '\r\n',
4070
+ 'c=IN IP4 0.0.0.0\r\n',
4071
+ 'a=sctpmap:' + sctp.port + ' ' + sctp.protocol + ' 65535\r\n'
4072
+ ];
4073
+ }
4074
+ if (sctp.maxMessageSize !== undefined) {
4075
+ output.push('a=max-message-size:' + sctp.maxMessageSize + '\r\n');
4076
+ }
4077
+ return output.join('');
4078
+ };
4079
+
4080
+ // Generate a session ID for SDP.
4081
+ // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-20#section-5.2.1
4082
+ // recommends using a cryptographically random +ve 64-bit value
4083
+ // but right now this should be acceptable and within the right range
4084
+ SDPUtils.generateSessionId = function () {
4085
+ return Math.random().toString().substr(2, 21);
4086
+ };
4087
+
4088
+ // Write boiler plate for start of SDP
4089
+ // sessId argument is optional - if not supplied it will
4090
+ // be generated randomly
4091
+ // sessVersion is optional and defaults to 2
4092
+ // sessUser is optional and defaults to 'thisisadapterortc'
4093
+ SDPUtils.writeSessionBoilerplate = function (sessId, sessVer, sessUser) {
4094
+ var sessionId = void 0;
4095
+ var version = sessVer !== undefined ? sessVer : 2;
4096
+ if (sessId) {
4097
+ sessionId = sessId;
4098
+ } else {
4099
+ sessionId = SDPUtils.generateSessionId();
4100
+ }
4101
+ var user = sessUser || 'thisisadapterortc';
4102
+ // FIXME: sess-id should be an NTP timestamp.
4103
+ return (
4104
+ 'v=0\r\n' +
4105
+ 'o=' +
4106
+ user +
4107
+ ' ' +
4108
+ sessionId +
4109
+ ' ' +
4110
+ version +
4111
+ ' IN IP4 127.0.0.1\r\n' +
4112
+ 's=-\r\n' +
4113
+ 't=0 0\r\n'
4114
+ );
4115
+ };
4116
+
4117
+ // Gets the direction from the mediaSection or the sessionpart.
4118
+ SDPUtils.getDirection = function (mediaSection, sessionpart) {
4119
+ // Look for sendrecv, sendonly, recvonly, inactive, default to sendrecv.
4120
+ var lines = SDPUtils.splitLines(mediaSection);
4121
+ for (var i = 0; i < lines.length; i++) {
4122
+ switch (lines[i]) {
4123
+ case 'a=sendrecv':
4124
+ case 'a=sendonly':
4125
+ case 'a=recvonly':
4126
+ case 'a=inactive':
4127
+ return lines[i].substr(2);
4128
+ default:
4129
+ // FIXME: What should happen here?
4130
+ }
4131
+ }
4132
+ if (sessionpart) {
4133
+ return SDPUtils.getDirection(sessionpart);
4134
+ }
4135
+ return 'sendrecv';
4136
+ };
4137
+
4138
+ SDPUtils.getKind = function (mediaSection) {
4139
+ var lines = SDPUtils.splitLines(mediaSection);
4140
+ var mline = lines[0].split(' ');
4141
+ return mline[0].substr(2);
4142
+ };
4143
+
4144
+ SDPUtils.isRejected = function (mediaSection) {
4145
+ return mediaSection.split(' ', 2)[1] === '0';
4146
+ };
4147
+
4148
+ SDPUtils.parseMLine = function (mediaSection) {
4149
+ var lines = SDPUtils.splitLines(mediaSection);
4150
+ var parts = lines[0].substr(2).split(' ');
4151
+ return {
4152
+ kind: parts[0],
4153
+ port: parseInt(parts[1], 10),
4154
+ protocol: parts[2],
4155
+ fmt: parts.slice(3).join(' ')
4156
+ };
4157
+ };
4158
+
4159
+ SDPUtils.parseOLine = function (mediaSection) {
4160
+ var line = SDPUtils.matchPrefix(mediaSection, 'o=')[0];
4161
+ var parts = line.substr(2).split(' ');
4162
+ return {
4163
+ username: parts[0],
4164
+ sessionId: parts[1],
4165
+ sessionVersion: parseInt(parts[2], 10),
4166
+ netType: parts[3],
4167
+ addressType: parts[4],
4168
+ address: parts[5]
4169
+ };
4170
+ };
4171
+
4172
+ // a very naive interpretation of a valid SDP.
4173
+ SDPUtils.isValidSDP = function (blob) {
4174
+ if (typeof blob !== 'string' || blob.length === 0) {
4175
+ return false;
4176
+ }
4177
+ var lines = SDPUtils.splitLines(blob);
4178
+ for (var i = 0; i < lines.length; i++) {
4179
+ if (lines[i].length < 2 || lines[i].charAt(1) !== '=') {
4180
+ return false;
4181
+ }
4182
+ // TODO: check the modifier a bit more.
4183
+ }
4184
+ return true;
4185
+ };
4186
+
4187
+ // Expose public methods.
4188
+ if ((typeof module === 'undefined' ? 'undefined' : _typeof(module)) === 'object') {
4189
+ module.exports = SDPUtils;
4190
+ }
4191
+ },
4192
+ {}
4193
+ ]
4194
+ },
4195
+ {},
4196
+ [1]
4197
+ )(1);
4198
+ });