twilio-video 2.24.3 → 2.26.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/CHANGELOG.md +172 -0
- package/README.md +1 -2
- package/dist/twilio-video.js +1651 -1174
- package/dist/twilio-video.min.js +21 -21
- package/es5/createlocaltrack.js +10 -2
- package/es5/createlocaltrack.js.map +1 -1
- package/es5/createlocaltracks.js +20 -8
- package/es5/createlocaltracks.js.map +1 -1
- package/es5/media/track/localaudiotrack.js +140 -7
- package/es5/media/track/localaudiotrack.js.map +1 -1
- package/es5/media/track/localmediatrack.js +32 -6
- package/es5/media/track/localmediatrack.js.map +1 -1
- package/es5/media/track/localvideotrack.js +33 -12
- package/es5/media/track/localvideotrack.js.map +1 -1
- package/es5/media/track/mediatrack.js +3 -3
- package/es5/media/track/mediatrack.js.map +1 -1
- package/es5/media/track/remotemediatrack.js +2 -2
- package/es5/media/track/remotemediatrack.js.map +1 -1
- package/es5/media/track/sender.js +39 -1
- package/es5/media/track/sender.js.map +1 -1
- package/es5/room.js +50 -1
- package/es5/room.js.map +1 -1
- package/es5/transceiver.js +3 -3
- package/es5/transceiver.js.map +1 -1
- package/es5/util/browserdetection.js +16 -15
- package/es5/util/browserdetection.js.map +1 -1
- package/es5/webrtc/getstats.js +75 -58
- package/es5/webrtc/getstats.js.map +1 -1
- package/es5/webrtc/getusermedia.js +1 -1
- package/es5/webrtc/getusermedia.js.map +1 -1
- package/es5/webrtc/index.js.map +1 -1
- package/es5/webrtc/rtcpeerconnection/chrome.js +339 -286
- package/es5/webrtc/rtcpeerconnection/chrome.js.map +1 -1
- package/es5/webrtc/rtcpeerconnection/firefox.js +225 -179
- package/es5/webrtc/rtcpeerconnection/firefox.js.map +1 -1
- package/es5/webrtc/rtcpeerconnection/index.js.map +1 -1
- package/es5/webrtc/rtcpeerconnection/safari.js +276 -236
- package/es5/webrtc/rtcpeerconnection/safari.js.map +1 -1
- package/es5/webrtc/rtcrtpsender.js +12 -9
- package/es5/webrtc/rtcrtpsender.js.map +1 -1
- package/es5/webrtc/rtcsessiondescription/chrome.js +29 -22
- package/es5/webrtc/rtcsessiondescription/chrome.js.map +1 -1
- package/es5/webrtc/rtcsessiondescription/index.js.map +1 -1
- package/es5/webrtc/util/index.js +32 -15
- package/es5/webrtc/util/index.js.map +1 -1
- package/es5/webrtc/util/latch.js +83 -82
- package/es5/webrtc/util/latch.js.map +1 -1
- package/es5/webrtc/util/sdp.js +12 -19
- package/es5/webrtc/util/sdp.js.map +1 -1
- package/lib/createlocaltrack.js +10 -2
- package/lib/createlocaltracks.ts +32 -11
- package/lib/media/track/localaudiotrack.js +142 -8
- package/lib/media/track/localmediatrack.js +31 -5
- package/lib/media/track/localvideotrack.js +35 -13
- package/lib/media/track/mediatrack.js +2 -2
- package/lib/media/track/remotemediatrack.js +2 -2
- package/lib/media/track/sender.js +42 -1
- package/lib/room.js +41 -1
- package/lib/transceiver.js +3 -3
- package/lib/util/browserdetection.js +16 -15
- package/lib/webrtc/getstats.js +155 -171
- package/lib/webrtc/getusermedia.js +1 -2
- package/lib/webrtc/index.js +1 -1
- package/lib/webrtc/rtcpeerconnection/chrome.js +284 -316
- package/lib/webrtc/rtcpeerconnection/firefox.js +173 -197
- package/lib/webrtc/rtcpeerconnection/index.js +1 -1
- package/lib/webrtc/rtcpeerconnection/safari.js +228 -256
- package/lib/webrtc/rtcrtpsender.js +10 -8
- package/lib/webrtc/rtcsessiondescription/chrome.js +24 -24
- package/lib/webrtc/rtcsessiondescription/index.js +1 -1
- package/lib/webrtc/util/index.js +26 -33
- package/lib/webrtc/util/latch.js +78 -83
- package/lib/webrtc/util/sdp.js +32 -41
- package/package.json +3 -3
- package/tsdef/LocalAudioTrack.d.ts +3 -0
- package/tsdef/LocalVideoTrack.d.ts +3 -0
- package/tsdef/Room.d.ts +1 -0
- package/tsdef/index.d.ts +1 -0
- package/tsdef/types.d.ts +2 -0
- package/es5/webrtc/util/eventtarget.js +0 -34
- package/es5/webrtc/util/eventtarget.js.map +0 -1
- package/lib/webrtc/util/eventtarget.js +0 -39
|
@@ -1,15 +1,49 @@
|
|
|
1
1
|
/* globals RTCDataChannel, RTCPeerConnection, RTCSessionDescription */
|
|
2
2
|
'use strict';
|
|
3
|
+
var __extends = (this && this.__extends) || (function () {
|
|
4
|
+
var extendStatics = function (d, b) {
|
|
5
|
+
extendStatics = Object.setPrototypeOf ||
|
|
6
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
7
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
8
|
+
return extendStatics(d, b);
|
|
9
|
+
};
|
|
10
|
+
return function (d, b) {
|
|
11
|
+
if (typeof b !== "function" && b !== null)
|
|
12
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
13
|
+
extendStatics(d, b);
|
|
14
|
+
function __() { this.constructor = d; }
|
|
15
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
16
|
+
};
|
|
17
|
+
})();
|
|
18
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
19
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
20
|
+
if (!m) return o;
|
|
21
|
+
var i = m.call(o), r, ar = [], e;
|
|
22
|
+
try {
|
|
23
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
24
|
+
}
|
|
25
|
+
catch (error) { e = { error: error }; }
|
|
26
|
+
finally {
|
|
27
|
+
try {
|
|
28
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
29
|
+
}
|
|
30
|
+
finally { if (e) throw e.error; }
|
|
31
|
+
}
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
35
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
36
|
+
to[j] = from[i];
|
|
37
|
+
return to;
|
|
38
|
+
};
|
|
3
39
|
var ChromeRTCSessionDescription = require('../rtcsessiondescription/chrome');
|
|
4
|
-
var EventTarget = require('
|
|
5
|
-
var inherits = require('../../vendor/inherits');
|
|
40
|
+
var EventTarget = require('../../eventtarget');
|
|
6
41
|
var Latch = require('../util/latch');
|
|
7
42
|
var MediaStream = require('../mediastream');
|
|
8
43
|
var RTCRtpSenderShim = require('../rtcrtpsender');
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var isUnifiedPlan = sdpUtils.getSdpFormat() === 'unified';
|
|
44
|
+
var _a = require('../util/sdp'), getSdpFormat = _a.getSdpFormat, updatePlanBTrackIdsToSSRCs = _a.updatePlanBTrackIdsToSSRCs, updateUnifiedPlanTrackIdsToSSRCs = _a.updateUnifiedPlanTrackIdsToSSRCs;
|
|
45
|
+
var _b = require('../util'), delegateMethods = _b.delegateMethods, interceptEvent = _b.interceptEvent, isIOSChrome = _b.isIOSChrome, legacyPromise = _b.legacyPromise, proxyProperties = _b.proxyProperties;
|
|
46
|
+
var isUnifiedPlan = getSdpFormat() === 'unified';
|
|
13
47
|
// NOTE(mroberts): This class wraps Chrome's RTCPeerConnection implementation.
|
|
14
48
|
// It provides some functionality not currently present in Chrome, namely the
|
|
15
49
|
// abilities to
|
|
@@ -21,119 +55,127 @@ var isUnifiedPlan = sdpUtils.getSdpFormat() === 'unified';
|
|
|
21
55
|
//
|
|
22
56
|
// 3. Set iceTransportPolicy.
|
|
23
57
|
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
writable: true
|
|
72
|
-
},
|
|
73
|
-
localDescription: {
|
|
74
|
-
enumerable: true,
|
|
75
|
-
get: function () {
|
|
76
|
-
return this._pendingLocalOffer ? this._pendingLocalOffer : peerConnection.localDescription;
|
|
58
|
+
var ChromeRTCPeerConnection = /** @class */ (function (_super) {
|
|
59
|
+
__extends(ChromeRTCPeerConnection, _super);
|
|
60
|
+
function ChromeRTCPeerConnection(configuration, constraints) {
|
|
61
|
+
if (configuration === void 0) { configuration = {}; }
|
|
62
|
+
var _this = _super.call(this) || this;
|
|
63
|
+
var newConfiguration = Object.assign(configuration.iceTransportPolicy
|
|
64
|
+
? { iceTransports: configuration.iceTransportPolicy }
|
|
65
|
+
: {}, configuration);
|
|
66
|
+
interceptEvent(_this, 'datachannel');
|
|
67
|
+
interceptEvent(_this, 'signalingstatechange');
|
|
68
|
+
var sdpFormat = getSdpFormat(newConfiguration.sdpSemantics);
|
|
69
|
+
var peerConnection = new RTCPeerConnection(newConfiguration, constraints);
|
|
70
|
+
Object.defineProperties(_this, {
|
|
71
|
+
_appliedTracksToSSRCs: {
|
|
72
|
+
value: new Map(),
|
|
73
|
+
writable: true
|
|
74
|
+
},
|
|
75
|
+
_localStream: {
|
|
76
|
+
value: new MediaStream()
|
|
77
|
+
},
|
|
78
|
+
_peerConnection: {
|
|
79
|
+
value: peerConnection
|
|
80
|
+
},
|
|
81
|
+
_pendingLocalOffer: {
|
|
82
|
+
value: null,
|
|
83
|
+
writable: true
|
|
84
|
+
},
|
|
85
|
+
_pendingRemoteOffer: {
|
|
86
|
+
value: null,
|
|
87
|
+
writable: true
|
|
88
|
+
},
|
|
89
|
+
_rolledBackTracksToSSRCs: {
|
|
90
|
+
value: new Map(),
|
|
91
|
+
writable: true
|
|
92
|
+
},
|
|
93
|
+
_sdpFormat: {
|
|
94
|
+
value: sdpFormat
|
|
95
|
+
},
|
|
96
|
+
_senders: {
|
|
97
|
+
value: new Map()
|
|
98
|
+
},
|
|
99
|
+
_signalingStateLatch: {
|
|
100
|
+
value: new Latch()
|
|
101
|
+
},
|
|
102
|
+
_tracksToSSRCs: {
|
|
103
|
+
value: new Map(),
|
|
104
|
+
writable: true
|
|
77
105
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
106
|
+
});
|
|
107
|
+
peerConnection.addEventListener('datachannel', function (event) {
|
|
108
|
+
shimDataChannel(event.channel);
|
|
109
|
+
_this.dispatchEvent(event);
|
|
110
|
+
});
|
|
111
|
+
peerConnection.addEventListener('signalingstatechange', function () {
|
|
112
|
+
var args = [];
|
|
113
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
114
|
+
args[_i] = arguments[_i];
|
|
83
115
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
enumerable: true,
|
|
87
|
-
get: function () {
|
|
88
|
-
if (this._pendingLocalOffer) {
|
|
89
|
-
return 'have-local-offer';
|
|
90
|
-
}
|
|
91
|
-
else if (this._pendingRemoteOffer) {
|
|
92
|
-
return 'have-remote-offer';
|
|
93
|
-
}
|
|
94
|
-
return peerConnection.signalingState;
|
|
116
|
+
if (peerConnection.signalingState === 'stable') {
|
|
117
|
+
_this._appliedTracksToSSRCs = new Map(_this._tracksToSSRCs);
|
|
95
118
|
}
|
|
119
|
+
if (!_this._pendingLocalOffer && !_this._pendingRemoteOffer) {
|
|
120
|
+
_this.dispatchEvent.apply(_this, __spreadArray([], __read(args)));
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
peerConnection.ontrack = function () {
|
|
124
|
+
// NOTE(mroberts): adapter.js's "track" event shim only kicks off if we set
|
|
125
|
+
// the ontrack property of the RTCPeerConnection.
|
|
126
|
+
};
|
|
127
|
+
if (typeof peerConnection.addTrack !== 'function') {
|
|
128
|
+
peerConnection.addStream(_this._localStream);
|
|
96
129
|
}
|
|
130
|
+
proxyProperties(RTCPeerConnection.prototype, _this, peerConnection);
|
|
131
|
+
return _this;
|
|
132
|
+
}
|
|
133
|
+
Object.defineProperty(ChromeRTCPeerConnection.prototype, "localDescription", {
|
|
134
|
+
get: function () {
|
|
135
|
+
return this._pendingLocalOffer ? this._pendingLocalOffer : this._peerConnection.localDescription;
|
|
136
|
+
},
|
|
137
|
+
enumerable: false,
|
|
138
|
+
configurable: true
|
|
97
139
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
140
|
+
Object.defineProperty(ChromeRTCPeerConnection.prototype, "remoteDescription", {
|
|
141
|
+
get: function () {
|
|
142
|
+
return this._pendingRemoteOffer ? this._pendingRemoteOffer : this._peerConnection.remoteDescription;
|
|
143
|
+
},
|
|
144
|
+
enumerable: false,
|
|
145
|
+
configurable: true
|
|
102
146
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
147
|
+
Object.defineProperty(ChromeRTCPeerConnection.prototype, "signalingState", {
|
|
148
|
+
get: function () {
|
|
149
|
+
if (this._pendingLocalOffer) {
|
|
150
|
+
return 'have-local-offer';
|
|
151
|
+
}
|
|
152
|
+
else if (this._pendingRemoteOffer) {
|
|
153
|
+
return 'have-remote-offer';
|
|
154
|
+
}
|
|
155
|
+
return this._peerConnection.signalingState;
|
|
156
|
+
},
|
|
157
|
+
enumerable: false,
|
|
158
|
+
configurable: true
|
|
110
159
|
});
|
|
111
|
-
peerConnection.ontrack = function ontrack() {
|
|
112
|
-
// NOTE(mroberts): adapter.js's "track" event shim only kicks off if we set
|
|
113
|
-
// the ontrack property of the RTCPeerConnection.
|
|
114
|
-
};
|
|
115
|
-
if (typeof RTCPeerConnection.prototype.addTrack !== 'function') {
|
|
116
|
-
peerConnection.addStream(this._localStream);
|
|
117
|
-
}
|
|
118
|
-
util.proxyProperties(RTCPeerConnection.prototype, this, peerConnection);
|
|
119
|
-
}
|
|
120
|
-
inherits(ChromeRTCPeerConnection, EventTarget);
|
|
121
|
-
if (typeof RTCPeerConnection.prototype.addTrack !== 'function') {
|
|
122
160
|
// NOTE(mmalavalli): This shim supports our limited case of adding
|
|
123
161
|
// all MediaStreamTracks to one MediaStream. It has been implemented this
|
|
124
162
|
// keeping in mind that this is to be maintained only until "addTrack" is
|
|
125
163
|
// supported natively in Chrome.
|
|
126
|
-
ChromeRTCPeerConnection.prototype.addTrack = function
|
|
127
|
-
var
|
|
128
|
-
var
|
|
164
|
+
ChromeRTCPeerConnection.prototype.addTrack = function (track) {
|
|
165
|
+
var _a;
|
|
166
|
+
var rest = [];
|
|
167
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
168
|
+
rest[_i - 1] = arguments[_i];
|
|
169
|
+
}
|
|
170
|
+
if (typeof this._peerConnection.addTrack === 'function') {
|
|
171
|
+
return (_a = this._peerConnection).addTrack.apply(_a, __spreadArray([track], __read(rest)));
|
|
172
|
+
}
|
|
129
173
|
if (this._peerConnection.signalingState === 'closed') {
|
|
130
|
-
throw new Error(
|
|
131
|
-
+ track.kind + ']: RTCPeerConnection is closed');
|
|
174
|
+
throw new Error("Cannot add MediaStreamTrack [" + track.id + ", \n " + track.kind + "]: RTCPeerConnection is closed");
|
|
132
175
|
}
|
|
133
176
|
var sender = this._senders.get(track);
|
|
134
177
|
if (sender && sender.track) {
|
|
135
|
-
throw new Error(
|
|
136
|
-
+ track.kind + ']: RTCPeerConnection already has it');
|
|
178
|
+
throw new Error("Cannot add MediaStreamTrack ['" + track.id + ", \n " + track.kind + "]: RTCPeerConnection already has it");
|
|
137
179
|
}
|
|
138
180
|
this._peerConnection.removeStream(this._localStream);
|
|
139
181
|
this._localStream.addTrack(track);
|
|
@@ -146,192 +188,207 @@ if (typeof RTCPeerConnection.prototype.addTrack !== 'function') {
|
|
|
146
188
|
// MediaStreamTracks from one MediaStream. It has been implemented this
|
|
147
189
|
// keeping in mind that this is to be maintained only until "removeTrack" is
|
|
148
190
|
// supported natively in Chrome.
|
|
149
|
-
ChromeRTCPeerConnection.prototype.removeTrack = function
|
|
191
|
+
ChromeRTCPeerConnection.prototype.removeTrack = function (sender) {
|
|
150
192
|
if (this._peerConnection.signalingState === 'closed') {
|
|
151
193
|
throw new Error('Cannot remove MediaStreamTrack: RTCPeerConnection is closed');
|
|
152
194
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
195
|
+
if (typeof this._peerConnection.addTrack === 'function') {
|
|
196
|
+
try {
|
|
197
|
+
return this._peerConnection.removeTrack(sender);
|
|
198
|
+
}
|
|
199
|
+
catch (e) {
|
|
200
|
+
// NOTE(mhuynh): Do nothing. In Chrome, will throw if a 'sender was not
|
|
201
|
+
// created by this peer connection'. This behavior does not seem to be
|
|
202
|
+
// spec compliant, so a temporary shim is introduced. A bug has been filed,
|
|
203
|
+
// and is tracked here:
|
|
204
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=860853
|
|
205
|
+
}
|
|
156
206
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
this.
|
|
207
|
+
else {
|
|
208
|
+
var track = sender.track;
|
|
209
|
+
if (!track) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
sender = this._senders.get(track);
|
|
213
|
+
if (sender && sender.track) {
|
|
214
|
+
sender.track = null;
|
|
215
|
+
this._peerConnection.removeStream(this._localStream);
|
|
216
|
+
this._localStream.removeTrack(track);
|
|
217
|
+
this._peerConnection.addStream(this._localStream);
|
|
218
|
+
}
|
|
163
219
|
}
|
|
164
220
|
};
|
|
165
|
-
ChromeRTCPeerConnection.prototype.getSenders = function
|
|
221
|
+
ChromeRTCPeerConnection.prototype.getSenders = function () {
|
|
222
|
+
if (typeof this._peerConnection.addTrack === 'function') {
|
|
223
|
+
return this._peerConnection.getSenders();
|
|
224
|
+
}
|
|
166
225
|
return Array.from(this._senders.values());
|
|
167
226
|
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
227
|
+
ChromeRTCPeerConnection.prototype.addIceCandidate = function (candidate) {
|
|
228
|
+
var _this = this;
|
|
229
|
+
var rest = [];
|
|
230
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
231
|
+
rest[_i - 1] = arguments[_i];
|
|
173
232
|
}
|
|
174
|
-
|
|
175
|
-
|
|
233
|
+
var promise;
|
|
234
|
+
if (this.signalingState === 'have-remote-offer') {
|
|
235
|
+
// NOTE(mroberts): Because the ChromeRTCPeerConnection simulates the
|
|
236
|
+
// "have-remote-offer" signalingStates, we only want to invoke the true
|
|
237
|
+
// addIceCandidates method when the remote description has been applied.
|
|
238
|
+
promise = this._signalingStateLatch.when('low').then(function () {
|
|
239
|
+
return _this._peerConnection.addIceCandidate(candidate);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
promise = this._peerConnection.addIceCandidate(candidate);
|
|
176
244
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
245
|
+
return rest.length > 0
|
|
246
|
+
? legacyPromise.apply(void 0, __spreadArray([promise], __read(rest))) : promise;
|
|
247
|
+
};
|
|
248
|
+
// NOTE(mroberts): The WebRTC spec does not specify that close should throw an
|
|
249
|
+
// Error; however, in Chrome it does. We workaround this by checking the
|
|
250
|
+
// signalingState manually.
|
|
251
|
+
ChromeRTCPeerConnection.prototype.close = function () {
|
|
252
|
+
if (this.signalingState !== 'closed') {
|
|
253
|
+
this._pendingLocalOffer = null;
|
|
254
|
+
this._pendingRemoteOffer = null;
|
|
255
|
+
this._peerConnection.close();
|
|
183
256
|
}
|
|
184
257
|
};
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
// apply the remote description. This means, once you call createAnswer, you
|
|
218
|
-
// can no longer rollback. This is acceptable for our use case because we will
|
|
219
|
-
// apply the newly-created answer almost immediately; however, this may be
|
|
220
|
-
// unacceptable for other use cases.
|
|
221
|
-
ChromeRTCPeerConnection.prototype.createAnswer = function createAnswer() {
|
|
222
|
-
var args = [].slice.call(arguments);
|
|
223
|
-
var promise;
|
|
224
|
-
var self = this;
|
|
225
|
-
if (this._pendingRemoteOffer) {
|
|
226
|
-
promise = this._peerConnection.setRemoteDescription(this._pendingRemoteOffer).then(function setRemoteDescriptionSucceeded() {
|
|
227
|
-
// NOTE(mroberts): The signalingStates between the ChromeRTCPeerConnection
|
|
228
|
-
// and the underlying RTCPeerConnection implementation have converged. We
|
|
229
|
-
// can unblock any pending calls to addIceCandidate now.
|
|
230
|
-
self._signalingStateLatch.lower();
|
|
231
|
-
return self._peerConnection.createAnswer();
|
|
232
|
-
}).then(function createAnswerSucceeded(answer) {
|
|
233
|
-
self._pendingRemoteOffer = null;
|
|
234
|
-
// NOTE(mmalavalli): If createAnswer() is called immediately after rolling back, then we no
|
|
235
|
-
// longer need to retain the rolled back tracks to SSRCs Map.
|
|
236
|
-
self._rolledBackTracksToSSRCs.clear();
|
|
237
|
-
return new ChromeRTCSessionDescription({
|
|
238
|
-
type: 'answer',
|
|
239
|
-
sdp: updateTrackIdsToSSRCs(self._sdpFormat, self._tracksToSSRCs, answer.sdp)
|
|
258
|
+
// NOTE(mroberts): Because we workaround Chrome's lack of rollback support by
|
|
259
|
+
// "faking" setRemoteDescription, we cannot create an answer until we actually
|
|
260
|
+
// apply the remote description. This means, once you call createAnswer, you
|
|
261
|
+
// can no longer rollback. This is acceptable for our use case because we will
|
|
262
|
+
// apply the newly-created answer almost immediately; however, this may be
|
|
263
|
+
// unacceptable for other use cases.
|
|
264
|
+
ChromeRTCPeerConnection.prototype.createAnswer = function () {
|
|
265
|
+
var _this = this;
|
|
266
|
+
var args = [];
|
|
267
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
268
|
+
args[_i] = arguments[_i];
|
|
269
|
+
}
|
|
270
|
+
var promise;
|
|
271
|
+
if (this._pendingRemoteOffer) {
|
|
272
|
+
promise = this._peerConnection.setRemoteDescription(this._pendingRemoteOffer).then(function () {
|
|
273
|
+
// NOTE(mroberts): The signalingStates between the ChromeRTCPeerConnection
|
|
274
|
+
// and the underlying RTCPeerConnection implementation have converged. We
|
|
275
|
+
// can unblock any pending calls to addIceCandidate now.
|
|
276
|
+
_this._signalingStateLatch.lower();
|
|
277
|
+
return _this._peerConnection.createAnswer();
|
|
278
|
+
}).then(function (answer) {
|
|
279
|
+
_this._pendingRemoteOffer = null;
|
|
280
|
+
// NOTE(mmalavalli): If createAnswer() is called immediately after rolling back, then we no
|
|
281
|
+
// longer need to retain the rolled back tracks to SSRCs Map.
|
|
282
|
+
_this._rolledBackTracksToSSRCs.clear();
|
|
283
|
+
return new ChromeRTCSessionDescription({
|
|
284
|
+
type: 'answer',
|
|
285
|
+
sdp: updateTrackIdsToSSRCs(_this._sdpFormat, _this._tracksToSSRCs, answer.sdp)
|
|
286
|
+
});
|
|
287
|
+
}, function (error) {
|
|
288
|
+
_this._pendingRemoteOffer = null;
|
|
289
|
+
throw error;
|
|
240
290
|
});
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return new ChromeRTCSessionDescription({
|
|
252
|
-
type: 'answer',
|
|
253
|
-
sdp: updateTrackIdsToSSRCs(self._sdpFormat, self._tracksToSSRCs, answer.sdp)
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
promise = this._peerConnection.createAnswer().then(function (answer) {
|
|
294
|
+
// NOTE(mmalavalli): If createAnswer() is called immediately after rolling back, then we no
|
|
295
|
+
// longer need to retain the rolled back tracks to SSRCs Map.
|
|
296
|
+
_this._rolledBackTracksToSSRCs.clear();
|
|
297
|
+
return new ChromeRTCSessionDescription({
|
|
298
|
+
type: 'answer',
|
|
299
|
+
sdp: updateTrackIdsToSSRCs(_this._sdpFormat, _this._tracksToSSRCs, answer.sdp)
|
|
300
|
+
});
|
|
254
301
|
});
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
return args.length > 1
|
|
258
|
-
? util.legacyPromise(promise, args[0], args[1])
|
|
259
|
-
: promise;
|
|
260
|
-
};
|
|
261
|
-
ChromeRTCPeerConnection.prototype.createOffer = function createOffer() {
|
|
262
|
-
var args = [].slice.call(arguments);
|
|
263
|
-
var options = (args.length > 1 ? args[2] : args[0]) || {};
|
|
264
|
-
var self = this;
|
|
265
|
-
if (isIOSChrome()) {
|
|
266
|
-
// NOTE (joma): From SafariRTCPeerConnection in order to support iOS Chrome.
|
|
267
|
-
if (options.offerToReceiveVideo && !this._audioTransceiver && !(isUnifiedPlan && hasReceiversForTracksOfKind(this, 'audio'))) {
|
|
268
|
-
delete options.offerToReceiveAudio;
|
|
269
|
-
try {
|
|
270
|
-
this._audioTransceiver = isUnifiedPlan
|
|
271
|
-
? this.addTransceiver('audio', { direction: 'recvonly' })
|
|
272
|
-
: this.addTransceiver('audio');
|
|
273
|
-
}
|
|
274
|
-
catch (e) {
|
|
275
|
-
return Promise.reject(e);
|
|
276
|
-
}
|
|
277
302
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
303
|
+
return args.length > 1
|
|
304
|
+
? legacyPromise.apply(void 0, __spreadArray([promise], __read(args))) : promise;
|
|
305
|
+
};
|
|
306
|
+
ChromeRTCPeerConnection.prototype.createOffer = function () {
|
|
307
|
+
var _this = this;
|
|
308
|
+
var args = [];
|
|
309
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
310
|
+
args[_i] = arguments[_i];
|
|
311
|
+
}
|
|
312
|
+
var _a = __read(args, 3), arg1 = _a[0], arg2 = _a[1], arg3 = _a[2];
|
|
313
|
+
var options = arg3 || arg1 || {};
|
|
314
|
+
if (isIOSChrome()) {
|
|
315
|
+
// NOTE (joma): From SafariRTCPeerConnection in order to support iOS Chrome.
|
|
316
|
+
if (options.offerToReceiveVideo && !this._audioTransceiver && !(isUnifiedPlan && hasReceiversForTracksOfKind(this, 'audio'))) {
|
|
317
|
+
delete options.offerToReceiveAudio;
|
|
318
|
+
try {
|
|
319
|
+
this._audioTransceiver = isUnifiedPlan
|
|
320
|
+
? this.addTransceiver('audio', { direction: 'recvonly' })
|
|
321
|
+
: this.addTransceiver('audio');
|
|
322
|
+
}
|
|
323
|
+
catch (e) {
|
|
324
|
+
return Promise.reject(e);
|
|
325
|
+
}
|
|
284
326
|
}
|
|
285
|
-
|
|
286
|
-
|
|
327
|
+
if (options.offerToReceiveVideo && !this._videoTransceiver && !(isUnifiedPlan && hasReceiversForTracksOfKind(this, 'video'))) {
|
|
328
|
+
delete options.offerToReceiveVideo;
|
|
329
|
+
try {
|
|
330
|
+
this._videoTransceiver = isUnifiedPlan
|
|
331
|
+
? this.addTransceiver('video', { direction: 'recvonly' })
|
|
332
|
+
: this.addTransceiver('video');
|
|
333
|
+
}
|
|
334
|
+
catch (e) {
|
|
335
|
+
return Promise.reject(e);
|
|
336
|
+
}
|
|
287
337
|
}
|
|
288
338
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
339
|
+
var promise = this._peerConnection.createOffer(options).then(function (offer) {
|
|
340
|
+
// NOTE(mmalavalli): If createOffer() is called immediately after rolling back, then we no
|
|
341
|
+
// longer need to retain the rolled back tracks to SSRCs Map.
|
|
342
|
+
_this._rolledBackTracksToSSRCs.clear();
|
|
343
|
+
return new ChromeRTCSessionDescription({
|
|
344
|
+
type: offer.type,
|
|
345
|
+
sdp: updateTrackIdsToSSRCs(_this._sdpFormat, _this._tracksToSSRCs, offer.sdp)
|
|
346
|
+
});
|
|
297
347
|
});
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
348
|
+
return args.length > 1
|
|
349
|
+
? legacyPromise(promise, arg1, arg2)
|
|
350
|
+
: promise;
|
|
351
|
+
};
|
|
352
|
+
ChromeRTCPeerConnection.prototype.createDataChannel = function (label, dataChannelDict) {
|
|
353
|
+
dataChannelDict = shimDataChannelInit(dataChannelDict);
|
|
354
|
+
var dataChannel = this._peerConnection.createDataChannel(label, dataChannelDict);
|
|
355
|
+
shimDataChannel(dataChannel);
|
|
356
|
+
return dataChannel;
|
|
357
|
+
};
|
|
358
|
+
ChromeRTCPeerConnection.prototype.setLocalDescription = function () {
|
|
359
|
+
var args = [];
|
|
360
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
361
|
+
args[_i] = arguments[_i];
|
|
362
|
+
}
|
|
363
|
+
var _a = __read(args, 3), description = _a[0], arg1 = _a[1], arg2 = _a[2];
|
|
364
|
+
// NOTE(mmalavalli): If setLocalDescription() is called immediately after rolling back,
|
|
365
|
+
// then we need to restore the rolled back tracks to SSRCs Map.
|
|
366
|
+
if (this._rolledBackTracksToSSRCs.size > 0) {
|
|
367
|
+
this._tracksToSSRCs = new Map(this._rolledBackTracksToSSRCs);
|
|
368
|
+
this._rolledBackTracksToSSRCs.clear();
|
|
369
|
+
}
|
|
370
|
+
var promise = setDescription(this, true, description);
|
|
371
|
+
return args.length > 1
|
|
372
|
+
? legacyPromise(promise, arg1, arg2)
|
|
373
|
+
: promise;
|
|
374
|
+
};
|
|
375
|
+
ChromeRTCPeerConnection.prototype.setRemoteDescription = function () {
|
|
376
|
+
var args = [];
|
|
377
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
378
|
+
args[_i] = arguments[_i];
|
|
379
|
+
}
|
|
380
|
+
var _a = __read(args, 3), description = _a[0], arg1 = _a[1], arg2 = _a[2];
|
|
381
|
+
// NOTE(mmalavalli): If setRemoteDescription() is called immediately after rolling back,
|
|
382
|
+
// then we no longer need to retain the rolled back tracks to SSRCs Map.
|
|
316
383
|
this._rolledBackTracksToSSRCs.clear();
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
var description = args[0];
|
|
326
|
-
// NOTE(mmalavalli): If setRemoteDescription() is called immediately after rolling back,
|
|
327
|
-
// then we no longer need to retain the rolled back tracks to SSRCs Map.
|
|
328
|
-
this._rolledBackTracksToSSRCs.clear();
|
|
329
|
-
var promise = setDescription(this, false, description);
|
|
330
|
-
return args.length > 1
|
|
331
|
-
? util.legacyPromise(promise, args[1], args[2])
|
|
332
|
-
: promise;
|
|
333
|
-
};
|
|
334
|
-
util.delegateMethods(RTCPeerConnection.prototype, ChromeRTCPeerConnection.prototype, '_peerConnection');
|
|
384
|
+
var promise = setDescription(this, false, description);
|
|
385
|
+
return args.length > 1
|
|
386
|
+
? legacyPromise(promise, arg1, arg2)
|
|
387
|
+
: promise;
|
|
388
|
+
};
|
|
389
|
+
return ChromeRTCPeerConnection;
|
|
390
|
+
}(EventTarget));
|
|
391
|
+
delegateMethods(RTCPeerConnection.prototype, ChromeRTCPeerConnection.prototype, '_peerConnection');
|
|
335
392
|
// NOTE(mroberts): We workaround Chrome's lack of rollback support, per the
|
|
336
393
|
// workaround suggested here: https://bugs.chromium.org/p/webrtc/issues/detail?id=5738#c3
|
|
337
394
|
// Namely, we "fake" setting the local or remote description and instead buffer
|
|
@@ -366,8 +423,7 @@ function setDescription(peerConnection, local, description) {
|
|
|
366
423
|
else if (description.type === 'offer') {
|
|
367
424
|
if (peerConnection.signalingState !== intermediateState && peerConnection.signalingState !== 'stable') {
|
|
368
425
|
// NOTE(mroberts): Error message copied from Firefox.
|
|
369
|
-
return Promise.reject(new Error(
|
|
370
|
-
' offer in state ' + peerConnection.signalingState));
|
|
426
|
+
return Promise.reject(new Error("Cannot set " + (local ? 'local' : 'remote') + " offer in state " + peerConnection.signalingState));
|
|
371
427
|
}
|
|
372
428
|
// We need to save this local offer in case of a rollback. We also need to
|
|
373
429
|
// check to see if the signalingState between the ChromeRTCPeerConnection
|
|
@@ -381,16 +437,13 @@ function setDescription(peerConnection, local, description) {
|
|
|
381
437
|
promise = Promise.resolve();
|
|
382
438
|
// Only dispatch a signalingstatechange event if we transitioned.
|
|
383
439
|
if (peerConnection.signalingState !== previousSignalingState) {
|
|
384
|
-
promise.then(function
|
|
385
|
-
peerConnection.dispatchEvent(new Event('signalingstatechange'));
|
|
386
|
-
});
|
|
440
|
+
promise.then(function () { return peerConnection.dispatchEvent(new Event('signalingstatechange')); });
|
|
387
441
|
}
|
|
388
442
|
}
|
|
389
443
|
else if (description.type === 'rollback') {
|
|
390
444
|
if (peerConnection.signalingState !== intermediateState) {
|
|
391
445
|
// NOTE(mroberts): Error message copied from Firefox.
|
|
392
|
-
promise = Promise.reject(new Error(
|
|
393
|
-
(local ? 'local' : 'remote') + ' description in ' + peerConnection.signalingState));
|
|
446
|
+
promise = Promise.reject(new Error("Cannot rollback " + (local ? 'local' : 'remote') + " description in " + peerConnection.signalingState));
|
|
394
447
|
}
|
|
395
448
|
else {
|
|
396
449
|
// Reset the pending offer.
|
|
@@ -402,9 +455,7 @@ function setDescription(peerConnection, local, description) {
|
|
|
402
455
|
peerConnection._rolledBackTracksToSSRCs = new Map(peerConnection._tracksToSSRCs);
|
|
403
456
|
peerConnection._tracksToSSRCs = new Map(peerConnection._appliedTracksToSSRCs);
|
|
404
457
|
promise = Promise.resolve();
|
|
405
|
-
promise.then(function
|
|
406
|
-
peerConnection.dispatchEvent(new Event('signalingstatechange'));
|
|
407
|
-
});
|
|
458
|
+
promise.then(function () { return peerConnection.dispatchEvent(new Event('signalingstatechange')); });
|
|
408
459
|
}
|
|
409
460
|
}
|
|
410
461
|
return promise || peerConnection._peerConnection[setLocalDescription](unwrap(description));
|
|
@@ -412,10 +463,10 @@ function setDescription(peerConnection, local, description) {
|
|
|
412
463
|
function setRemoteAnswer(peerConnection, answer) {
|
|
413
464
|
// Apply the pending local offer.
|
|
414
465
|
var pendingLocalOffer = peerConnection._pendingLocalOffer;
|
|
415
|
-
return peerConnection._peerConnection.setLocalDescription(pendingLocalOffer).then(function
|
|
466
|
+
return peerConnection._peerConnection.setLocalDescription(pendingLocalOffer).then(function () {
|
|
416
467
|
peerConnection._pendingLocalOffer = null;
|
|
417
468
|
return peerConnection.setRemoteDescription(answer);
|
|
418
|
-
}).then(function
|
|
469
|
+
}).then(function () {
|
|
419
470
|
// NOTE(mroberts): The signalingStates between the ChromeRTCPeerConnection
|
|
420
471
|
// and the underlying RTCPeerConnection implementation have converged. We
|
|
421
472
|
// can unblock any pending calls to addIceCandidate now.
|
|
@@ -430,8 +481,10 @@ function setRemoteAnswer(peerConnection, answer) {
|
|
|
430
481
|
* @returns {boolean}
|
|
431
482
|
*/
|
|
432
483
|
function hasReceiversForTracksOfKind(peerConnection, kind) {
|
|
433
|
-
return !!peerConnection.getTransceivers().find(function (
|
|
434
|
-
|
|
484
|
+
return !!peerConnection.getTransceivers().find(function (_a) {
|
|
485
|
+
var _b = _a.receiver, receiver = _b === void 0 ? {} : _b;
|
|
486
|
+
var _c = receiver.track, track = _c === void 0 ? {} : _c;
|
|
487
|
+
return track.kind === kind;
|
|
435
488
|
});
|
|
436
489
|
}
|
|
437
490
|
function unwrap(description) {
|
|
@@ -503,8 +556,8 @@ function shimDataChannel(dataChannel) {
|
|
|
503
556
|
*/
|
|
504
557
|
function updateTrackIdsToSSRCs(sdpFormat, tracksToSSRCs, sdp) {
|
|
505
558
|
return sdpFormat === 'unified'
|
|
506
|
-
?
|
|
507
|
-
:
|
|
559
|
+
? updateUnifiedPlanTrackIdsToSSRCs(tracksToSSRCs, sdp)
|
|
560
|
+
: updatePlanBTrackIdsToSSRCs(tracksToSSRCs, sdp);
|
|
508
561
|
}
|
|
509
562
|
module.exports = ChromeRTCPeerConnection;
|
|
510
563
|
//# sourceMappingURL=chrome.js.map
|