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