react-native-webrtc 106.0.0-beta.5 → 106.0.0-beta.7
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/README.md +2 -2
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +18 -24
- package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +59 -68
- package/ios/RCTWebRTC/RCTConvert+WebRTC.m +10 -0
- package/ios/RCTWebRTC/SerializeUtils.m +4 -2
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +73 -60
- package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +23 -22
- package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.m +1 -1
- package/ios/RCTWebRTC/WebRTCModule.h +0 -8
- package/ios/RCTWebRTC/WebRTCModule.m +1 -20
- package/lib/commonjs/MediaStreamTrack.js +24 -7
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/RTCIceCandidate.js +14 -4
- package/lib/commonjs/RTCIceCandidate.js.map +1 -1
- package/lib/commonjs/RTCPeerConnection.js +129 -132
- package/lib/commonjs/RTCPeerConnection.js.map +1 -1
- package/lib/commonjs/RTCRtpSender.js +6 -5
- package/lib/commonjs/RTCRtpSender.js.map +1 -1
- package/lib/commonjs/RTCRtpTransceiver.js +11 -49
- package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
- package/lib/commonjs/RTCView.js +0 -55
- package/lib/commonjs/RTCView.js.map +1 -1
- package/lib/commonjs/index.js +3 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +25 -8
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/RTCIceCandidate.js +14 -4
- package/lib/module/RTCIceCandidate.js.map +1 -1
- package/lib/module/RTCPeerConnection.js +129 -130
- package/lib/module/RTCPeerConnection.js.map +1 -1
- package/lib/module/RTCRtpSender.js +6 -5
- package/lib/module/RTCRtpSender.js.map +1 -1
- package/lib/module/RTCRtpTransceiver.js +11 -44
- package/lib/module/RTCRtpTransceiver.js.map +1 -1
- package/lib/module/RTCView.js +0 -49
- package/lib/module/RTCView.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/MediaStreamTrack.d.ts +11 -3
- package/lib/typescript/RTCIceCandidate.d.ts +5 -1
- package/lib/typescript/RTCPeerConnection.d.ts +5 -5
- package/lib/typescript/RTCRtpTransceiver.d.ts +2 -8
- package/lib/typescript/RTCView.d.ts +53 -46
- package/package.json +2 -2
- package/src/MediaStreamTrack.ts +23 -7
- package/src/RTCIceCandidate.ts +8 -5
- package/src/RTCPeerConnection.ts +133 -126
- package/src/RTCRtpSender.ts +6 -7
- package/src/RTCRtpTransceiver.ts +15 -45
- package/src/RTCView.ts +53 -49
- package/src/index.ts +2 -0
|
@@ -17,14 +17,10 @@ var _MediaStream = _interopRequireDefault(require("./MediaStream"));
|
|
|
17
17
|
|
|
18
18
|
var _MediaStreamTrack = _interopRequireDefault(require("./MediaStreamTrack"));
|
|
19
19
|
|
|
20
|
-
var _MediaStreamTrackEvent = _interopRequireDefault(require("./MediaStreamTrackEvent"));
|
|
21
|
-
|
|
22
20
|
var _RTCDataChannel = _interopRequireDefault(require("./RTCDataChannel"));
|
|
23
21
|
|
|
24
22
|
var _RTCDataChannelEvent = _interopRequireDefault(require("./RTCDataChannelEvent"));
|
|
25
23
|
|
|
26
|
-
var _RTCErrorEvent = _interopRequireDefault(require("./RTCErrorEvent"));
|
|
27
|
-
|
|
28
24
|
var _RTCEvent = _interopRequireDefault(require("./RTCEvent"));
|
|
29
25
|
|
|
30
26
|
var _RTCIceCandidate = _interopRequireDefault(require("./RTCIceCandidate"));
|
|
@@ -78,32 +74,32 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
78
74
|
|
|
79
75
|
_defineProperty(this, "iceConnectionState", 'new');
|
|
80
76
|
|
|
81
|
-
_defineProperty(this, "
|
|
77
|
+
_defineProperty(this, "_pcId", void 0);
|
|
82
78
|
|
|
83
79
|
_defineProperty(this, "_transceivers", []);
|
|
84
80
|
|
|
85
81
|
_defineProperty(this, "_remoteStreams", new Map());
|
|
86
82
|
|
|
87
|
-
this.
|
|
88
|
-
WebRTCModule.peerConnectionInit(configuration, this.
|
|
83
|
+
this._pcId = nextPeerConnectionId++;
|
|
84
|
+
WebRTCModule.peerConnectionInit(configuration, this._pcId);
|
|
89
85
|
|
|
90
86
|
this._registerEvents();
|
|
91
87
|
|
|
92
|
-
log.debug(`${this.
|
|
88
|
+
log.debug(`${this._pcId} ctor`);
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
createOffer(options) {
|
|
96
|
-
log.debug(`${this.
|
|
92
|
+
log.debug(`${this._pcId} createOffer`);
|
|
97
93
|
return new Promise((resolve, reject) => {
|
|
98
|
-
WebRTCModule.peerConnectionCreateOffer(this.
|
|
94
|
+
WebRTCModule.peerConnectionCreateOffer(this._pcId, RTCUtil.normalizeOfferOptions(options), (successful, data) => {
|
|
99
95
|
if (successful) {
|
|
100
|
-
log.debug(`${this.
|
|
96
|
+
log.debug(`${this._pcId} createOffer OK`);
|
|
101
97
|
|
|
102
98
|
this._updateTransceivers(data.transceiversInfo);
|
|
103
99
|
|
|
104
100
|
resolve(data.sdpInfo);
|
|
105
101
|
} else {
|
|
106
|
-
log.debug(`${this.
|
|
102
|
+
log.debug(`${this._pcId} createOffer ERROR`);
|
|
107
103
|
reject(data);
|
|
108
104
|
}
|
|
109
105
|
});
|
|
@@ -111,17 +107,17 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
111
107
|
}
|
|
112
108
|
|
|
113
109
|
createAnswer() {
|
|
114
|
-
log.debug(`${this.
|
|
110
|
+
log.debug(`${this._pcId} createAnswer`);
|
|
115
111
|
return new Promise((resolve, reject) => {
|
|
116
|
-
WebRTCModule.peerConnectionCreateAnswer(this.
|
|
112
|
+
WebRTCModule.peerConnectionCreateAnswer(this._pcId, {}, (successful, data) => {
|
|
117
113
|
if (successful) {
|
|
118
|
-
log.debug(`${this.
|
|
114
|
+
log.debug(`${this._pcId} createAnswer OK`);
|
|
119
115
|
|
|
120
116
|
this._updateTransceivers(data.transceiversInfo);
|
|
121
117
|
|
|
122
118
|
resolve(data.sdpInfo);
|
|
123
119
|
} else {
|
|
124
|
-
log.debug(`${this.
|
|
120
|
+
log.debug(`${this._pcId} createAnswer ERROR`);
|
|
125
121
|
reject(data);
|
|
126
122
|
}
|
|
127
123
|
});
|
|
@@ -129,11 +125,11 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
129
125
|
}
|
|
130
126
|
|
|
131
127
|
setConfiguration(configuration) {
|
|
132
|
-
WebRTCModule.peerConnectionSetConfiguration(configuration, this.
|
|
128
|
+
WebRTCModule.peerConnectionSetConfiguration(configuration, this._pcId);
|
|
133
129
|
}
|
|
134
130
|
|
|
135
131
|
async setLocalDescription(sessionDescription) {
|
|
136
|
-
log.debug(`${this.
|
|
132
|
+
log.debug(`${this._pcId} setLocalDescription`);
|
|
137
133
|
let desc;
|
|
138
134
|
|
|
139
135
|
if (sessionDescription) {
|
|
@@ -154,18 +150,23 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
154
150
|
const {
|
|
155
151
|
sdpInfo,
|
|
156
152
|
transceiversInfo
|
|
157
|
-
} = await WebRTCModule.peerConnectionSetLocalDescription(this.
|
|
158
|
-
|
|
153
|
+
} = await WebRTCModule.peerConnectionSetLocalDescription(this._pcId, desc);
|
|
154
|
+
|
|
155
|
+
if (sdpInfo.type && sdpInfo.sdp) {
|
|
156
|
+
this.localDescription = new _RTCSessionDescription.default(sdpInfo);
|
|
157
|
+
} else {
|
|
158
|
+
this.localDescription = null;
|
|
159
|
+
}
|
|
159
160
|
|
|
160
161
|
this._updateTransceivers(transceiversInfo);
|
|
161
162
|
|
|
162
|
-
log.debug(`${this.
|
|
163
|
+
log.debug(`${this._pcId} setLocalDescription OK`);
|
|
163
164
|
}
|
|
164
165
|
|
|
165
166
|
setRemoteDescription(sessionDescription) {
|
|
166
167
|
var _sessionDescription$s2, _desc$type;
|
|
167
168
|
|
|
168
|
-
log.debug(`${this.
|
|
169
|
+
log.debug(`${this._pcId} setRemoteDescription`);
|
|
169
170
|
|
|
170
171
|
if (!sessionDescription) {
|
|
171
172
|
return Promise.reject(new Error('No session description provided'));
|
|
@@ -181,19 +182,33 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
return new Promise((resolve, reject) => {
|
|
184
|
-
WebRTCModule.peerConnectionSetRemoteDescription(desc, this.
|
|
185
|
+
WebRTCModule.peerConnectionSetRemoteDescription(desc, this._pcId, (successful, data) => {
|
|
185
186
|
if (successful) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
187
|
+
log.debug(`${this._pcId} setRemoteDescription OK`);
|
|
188
|
+
const {
|
|
189
|
+
sdpInfo,
|
|
190
|
+
newTransceivers,
|
|
191
|
+
transceiversInfo
|
|
192
|
+
} = data;
|
|
193
|
+
|
|
194
|
+
if (sdpInfo.type && sdpInfo.sdp) {
|
|
195
|
+
this.remoteDescription = new _RTCSessionDescription.default(sdpInfo);
|
|
196
|
+
} else {
|
|
197
|
+
this.remoteDescription = null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
newTransceivers === null || newTransceivers === void 0 ? void 0 : newTransceivers.forEach(t => {
|
|
191
201
|
const {
|
|
192
202
|
transceiverOrder,
|
|
193
203
|
transceiver
|
|
194
204
|
} = t;
|
|
195
|
-
const newSender = new _RTCRtpSender.default(transceiver.sender
|
|
196
|
-
|
|
205
|
+
const newSender = new _RTCRtpSender.default({ ...transceiver.sender,
|
|
206
|
+
track: null
|
|
207
|
+
});
|
|
208
|
+
const remoteTrack = transceiver.receiver.track ? new _MediaStreamTrack.default(transceiver.receiver.track) : null;
|
|
209
|
+
const newReceiver = new _RTCRtpReceiver.default({ ...transceiver.receiver,
|
|
210
|
+
track: remoteTrack
|
|
211
|
+
});
|
|
197
212
|
const newTransceiver = new _RTCRtpTransceiver.default({ ...transceiver,
|
|
198
213
|
sender: newSender,
|
|
199
214
|
receiver: newReceiver
|
|
@@ -202,7 +217,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
202
217
|
this._insertTransceiverSorted(transceiverOrder, newTransceiver);
|
|
203
218
|
});
|
|
204
219
|
|
|
205
|
-
this._updateTransceivers(
|
|
220
|
+
this._updateTransceivers(transceiversInfo);
|
|
206
221
|
|
|
207
222
|
resolve();
|
|
208
223
|
} else {
|
|
@@ -213,29 +228,32 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
213
228
|
}
|
|
214
229
|
|
|
215
230
|
async addIceCandidate(candidate) {
|
|
216
|
-
log.debug(`${this.
|
|
231
|
+
log.debug(`${this._pcId} addIceCandidate`);
|
|
217
232
|
|
|
218
233
|
if (!candidate || !candidate.candidate) {
|
|
219
|
-
// XXX end-of
|
|
234
|
+
// XXX end-of candidates is not implemented: https://bugs.chromium.org/p/webrtc/issues/detail?id=9218
|
|
220
235
|
return;
|
|
221
236
|
}
|
|
222
237
|
|
|
223
|
-
|
|
238
|
+
if (candidate.sdpMLineIndex === null || candidate.sdpMLineIndex === undefined || candidate.sdpMid === null || candidate.sdpMid === undefined) {
|
|
239
|
+
throw new TypeError('`sdpMLineIndex` and `sdpMid` must not null or undefined');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const newSdp = await WebRTCModule.peerConnectionAddICECandidate(this._pcId, candidate.toJSON ? candidate.toJSON() : candidate);
|
|
224
243
|
this.remoteDescription = new _RTCSessionDescription.default(newSdp);
|
|
225
244
|
}
|
|
226
245
|
/**
|
|
227
246
|
* @brief Adds a new track to the {@link RTCPeerConnection},
|
|
228
|
-
* and indicates that it is contained in the specified {@link MediaStream}
|
|
229
|
-
* This method has to be synchronous as the W3C API expects a track to be
|
|
247
|
+
* and indicates that it is contained in the specified {@link MediaStream}s.
|
|
248
|
+
* This method has to be synchronous as the W3C API expects a track to be returned
|
|
230
249
|
* @param {MediaStreamTrack} track The track to be added
|
|
231
|
-
* @param {MediaStream
|
|
250
|
+
* @param {...MediaStream} streams One or more {@link MediaStream}s the track needs to be added to
|
|
232
251
|
* https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack
|
|
233
252
|
*/
|
|
234
253
|
|
|
235
254
|
|
|
236
255
|
addTrack(track) {
|
|
237
|
-
|
|
238
|
-
log.debug(`${this._peerConnectionId} addTrack`);
|
|
256
|
+
log.debug(`${this._pcId} addTrack`);
|
|
239
257
|
|
|
240
258
|
if (this.connectionState === 'closed') {
|
|
241
259
|
throw new Error('Peer Connection is closed');
|
|
@@ -245,8 +263,12 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
245
263
|
throw new Error('Track already exists in a sender');
|
|
246
264
|
}
|
|
247
265
|
|
|
266
|
+
for (var _len = arguments.length, streams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
267
|
+
streams[_key - 1] = arguments[_key];
|
|
268
|
+
}
|
|
269
|
+
|
|
248
270
|
const streamIds = streams.map(s => s.id);
|
|
249
|
-
const result = WebRTCModule.peerConnectionAddTrack(this.
|
|
271
|
+
const result = WebRTCModule.peerConnectionAddTrack(this._pcId, track.id, {
|
|
250
272
|
streamIds
|
|
251
273
|
});
|
|
252
274
|
|
|
@@ -292,7 +314,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
292
314
|
}
|
|
293
315
|
|
|
294
316
|
addTransceiver(source, init) {
|
|
295
|
-
log.debug(`${this.
|
|
317
|
+
log.debug(`${this._pcId} addTransceiver`);
|
|
296
318
|
let src = {};
|
|
297
319
|
|
|
298
320
|
if (source === 'audio') {
|
|
@@ -314,7 +336,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
314
336
|
init.streamIds = init.streams.map(stream => stream.id);
|
|
315
337
|
}
|
|
316
338
|
|
|
317
|
-
const result = WebRTCModule.peerConnectionAddTransceiver(this.
|
|
339
|
+
const result = WebRTCModule.peerConnectionAddTransceiver(this._pcId, { ...src,
|
|
318
340
|
init: { ...init
|
|
319
341
|
}
|
|
320
342
|
});
|
|
@@ -353,9 +375,9 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
353
375
|
}
|
|
354
376
|
|
|
355
377
|
removeTrack(sender) {
|
|
356
|
-
log.debug(`${this.
|
|
378
|
+
log.debug(`${this._pcId} removeTrack`);
|
|
357
379
|
|
|
358
|
-
if (this.
|
|
380
|
+
if (this._pcId !== sender._peerConnectionId) {
|
|
359
381
|
throw new Error('Sender does not belong to this peer connection');
|
|
360
382
|
}
|
|
361
383
|
|
|
@@ -371,14 +393,18 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
371
393
|
|
|
372
394
|
if (existingSender.track === null) {
|
|
373
395
|
return;
|
|
374
|
-
}
|
|
396
|
+
} // Blocking!
|
|
397
|
+
|
|
375
398
|
|
|
376
|
-
WebRTCModule.peerConnectionRemoveTrack(this.
|
|
399
|
+
WebRTCModule.peerConnectionRemoveTrack(this._pcId, sender.id);
|
|
400
|
+
existingSender._track = null;
|
|
401
|
+
const [existingTransceiver] = this.getTransceivers().filter(t => t.sender.id === existingSender.id);
|
|
402
|
+
existingTransceiver._direction = existingTransceiver.direction === 'sendrecv' ? 'recvonly' : 'inactive';
|
|
377
403
|
}
|
|
378
404
|
|
|
379
405
|
getStats() {
|
|
380
|
-
log.debug(`${this.
|
|
381
|
-
return WebRTCModule.peerConnectionGetStats(this.
|
|
406
|
+
log.debug(`${this._pcId} getStats`);
|
|
407
|
+
return WebRTCModule.peerConnectionGetStats(this._pcId).then(data =>
|
|
382
408
|
/* On both Android and iOS it is faster to construct a single
|
|
383
409
|
JSON string representing the Map of StatsReports and have it
|
|
384
410
|
pass through the React Native bridge rather than the Map of
|
|
@@ -405,26 +431,25 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
405
431
|
}
|
|
406
432
|
|
|
407
433
|
close() {
|
|
408
|
-
log.debug(`${this.
|
|
409
|
-
// transceivers
|
|
434
|
+
log.debug(`${this._pcId} close`);
|
|
435
|
+
WebRTCModule.peerConnectionClose(this._pcId); // Mark transceivers as stopped.
|
|
410
436
|
|
|
411
437
|
this._transceivers.forEach(_ref => {
|
|
412
438
|
let {
|
|
413
439
|
transceiver
|
|
414
440
|
} = _ref;
|
|
415
|
-
transceiver.stop();
|
|
416
|
-
});
|
|
417
441
|
|
|
418
|
-
|
|
442
|
+
transceiver._setStopped();
|
|
443
|
+
});
|
|
419
444
|
}
|
|
420
445
|
|
|
421
446
|
restartIce() {
|
|
422
|
-
WebRTCModule.peerConnectionRestartIce(this.
|
|
447
|
+
WebRTCModule.peerConnectionRestartIce(this._pcId);
|
|
423
448
|
}
|
|
424
449
|
|
|
425
450
|
_registerEvents() {
|
|
426
451
|
(0, _EventEmitter.addListener)(this, 'peerConnectionOnRenegotiationNeeded', ev => {
|
|
427
|
-
if (ev.
|
|
452
|
+
if (ev.pcId !== this._pcId) {
|
|
428
453
|
return;
|
|
429
454
|
} // @ts-ignore
|
|
430
455
|
|
|
@@ -432,7 +457,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
432
457
|
this.dispatchEvent(new _RTCEvent.default('negotiationneeded'));
|
|
433
458
|
});
|
|
434
459
|
(0, _EventEmitter.addListener)(this, 'peerConnectionIceConnectionChanged', ev => {
|
|
435
|
-
if (ev.
|
|
460
|
+
if (ev.pcId !== this._pcId) {
|
|
436
461
|
return;
|
|
437
462
|
}
|
|
438
463
|
|
|
@@ -447,7 +472,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
447
472
|
this.dispatchEvent(new _RTCEvent.default('iceconnectionstatechange'));
|
|
448
473
|
});
|
|
449
474
|
(0, _EventEmitter.addListener)(this, 'peerConnectionStateChanged', ev => {
|
|
450
|
-
if (ev.
|
|
475
|
+
if (ev.pcId !== this._pcId) {
|
|
451
476
|
return;
|
|
452
477
|
}
|
|
453
478
|
|
|
@@ -462,7 +487,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
462
487
|
this.dispatchEvent(new _RTCEvent.default('connectionstatechange'));
|
|
463
488
|
});
|
|
464
489
|
(0, _EventEmitter.addListener)(this, 'peerConnectionSignalingStateChanged', ev => {
|
|
465
|
-
if (ev.
|
|
490
|
+
if (ev.pcId !== this._pcId) {
|
|
466
491
|
return;
|
|
467
492
|
}
|
|
468
493
|
|
|
@@ -472,29 +497,29 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
472
497
|
}); // Consider moving away from this event: https://github.com/WebKit/WebKit/pull/3953
|
|
473
498
|
|
|
474
499
|
(0, _EventEmitter.addListener)(this, 'peerConnectionOnTrack', ev => {
|
|
475
|
-
if (ev.
|
|
500
|
+
if (ev.pcId !== this._pcId) {
|
|
476
501
|
return;
|
|
477
502
|
}
|
|
478
503
|
|
|
479
|
-
log.debug(`${this.
|
|
480
|
-
|
|
481
|
-
let transceiver;
|
|
482
|
-
//
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
transceiver: oldTransceiver
|
|
486
|
-
} = {
|
|
487
|
-
transceiver: null
|
|
488
|
-
}] = this._transceivers.filter(_ref2 => {
|
|
489
|
-
let {
|
|
490
|
-
transceiver
|
|
491
|
-
} = _ref2;
|
|
492
|
-
return transceiver.id === ev.transceiver.id;
|
|
493
|
-
});
|
|
504
|
+
log.debug(`${this._pcId} ontrack`);
|
|
505
|
+
let track;
|
|
506
|
+
let transceiver;
|
|
507
|
+
const [oldTransceiver] = this.getTransceivers().filter(t => t.receiver.id === ev.receiver.id); // We need to fire this event for an existing track sometimes, like
|
|
508
|
+
// when the transceiver direction (on the sending side) switches from
|
|
509
|
+
// sendrecv to recvonly and then back.
|
|
494
510
|
|
|
495
|
-
if (
|
|
496
|
-
|
|
497
|
-
|
|
511
|
+
if (oldTransceiver) {
|
|
512
|
+
transceiver = oldTransceiver;
|
|
513
|
+
track = transceiver.receiver.track;
|
|
514
|
+
transceiver._mid = ev.transceiver.mid;
|
|
515
|
+
transceiver._currentDirection = ev.transceiver.currentDirection;
|
|
516
|
+
transceiver._direction = ev.transceiver.direction;
|
|
517
|
+
} else {
|
|
518
|
+
// TODO: re-evaluate if we need this branch at all. Since we now add new transceivers
|
|
519
|
+
// in sRD, we should always find them when this handler runs.
|
|
520
|
+
track = new _MediaStreamTrack.default(ev.receiver.track);
|
|
521
|
+
const sender = new _RTCRtpSender.default({ ...ev.transceiver,
|
|
522
|
+
track: null
|
|
498
523
|
});
|
|
499
524
|
const receiver = new _RTCRtpReceiver.default({ ...ev.receiver,
|
|
500
525
|
track
|
|
@@ -505,12 +530,6 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
505
530
|
});
|
|
506
531
|
|
|
507
532
|
this._insertTransceiverSorted(ev.transceiverOrder, transceiver);
|
|
508
|
-
} else {
|
|
509
|
-
transceiver = oldTransceiver;
|
|
510
|
-
transceiver._receiver._track = track;
|
|
511
|
-
transceiver._mid = ev.transceiver.mid;
|
|
512
|
-
transceiver._currentDirection = ev.transceiver.currentDirection;
|
|
513
|
-
transceiver._direction = ev.transceiver.direction;
|
|
514
533
|
} // Get the stream object from the event. Create if necessary.
|
|
515
534
|
|
|
516
535
|
|
|
@@ -529,7 +548,10 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
529
548
|
|
|
530
549
|
const stream = this._remoteStreams.get(streamInfo.streamId);
|
|
531
550
|
|
|
532
|
-
stream
|
|
551
|
+
if (!(stream !== null && stream !== void 0 && stream._tracks.includes(track))) {
|
|
552
|
+
stream === null || stream === void 0 ? void 0 : stream._tracks.push(track);
|
|
553
|
+
}
|
|
554
|
+
|
|
533
555
|
return stream;
|
|
534
556
|
});
|
|
535
557
|
const eventData = {
|
|
@@ -539,43 +561,36 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
539
561
|
receiver: transceiver.receiver
|
|
540
562
|
}; // @ts-ignore
|
|
541
563
|
|
|
542
|
-
this.dispatchEvent(new _RTCTrackEvent.default('track', eventData));
|
|
564
|
+
this.dispatchEvent(new _RTCTrackEvent.default('track', eventData)); // Dispatch an unmute event for the track.
|
|
565
|
+
|
|
566
|
+
track._setMutedInternal(false);
|
|
543
567
|
});
|
|
544
568
|
(0, _EventEmitter.addListener)(this, 'peerConnectionOnRemoveTrack', ev => {
|
|
545
|
-
if (ev.
|
|
569
|
+
if (ev.pcId !== this._pcId) {
|
|
546
570
|
return;
|
|
547
571
|
}
|
|
548
572
|
|
|
549
|
-
log.debug(`${this.
|
|
550
|
-
//
|
|
551
|
-
//
|
|
573
|
+
log.debug(`${this._pcId} onremovetrack`); // As per the spec:
|
|
574
|
+
// - Remove the track from any media streams that were previously passed to the `track` event.
|
|
575
|
+
// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-removetrack,
|
|
576
|
+
// - Mark the track as muted:
|
|
577
|
+
// https://w3c.github.io/webrtc-pc/#process-remote-track-removal
|
|
552
578
|
|
|
553
579
|
for (const stream of this._remoteStreams.values()) {
|
|
554
|
-
const
|
|
580
|
+
const [track] = stream._tracks.filter(t => t.id === ev.trackId);
|
|
555
581
|
|
|
556
|
-
if (
|
|
557
|
-
stream._tracks.
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
});
|
|
561
|
-
(0, _EventEmitter.addListener)(this, 'peerConnectionOnRemoveTrackSuccessful', ev => {
|
|
562
|
-
if (ev.peerConnectionId !== this._peerConnectionId) {
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
582
|
+
if (track) {
|
|
583
|
+
const trackIdx = stream._tracks.indexOf(track);
|
|
565
584
|
|
|
566
|
-
|
|
567
|
-
const oldTrack = existingSender._track;
|
|
585
|
+
stream._tracks.splice(trackIdx, 1); // Dispatch a mute event for the track.
|
|
568
586
|
|
|
569
|
-
if (oldTrack) {
|
|
570
|
-
oldTrack._muted = true;
|
|
571
|
-
}
|
|
572
587
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
588
|
+
track._setMutedInternal(true);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
576
591
|
});
|
|
577
592
|
(0, _EventEmitter.addListener)(this, 'peerConnectionGotICECandidate', ev => {
|
|
578
|
-
if (ev.
|
|
593
|
+
if (ev.pcId !== this._pcId) {
|
|
579
594
|
return;
|
|
580
595
|
}
|
|
581
596
|
|
|
@@ -587,7 +602,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
587
602
|
}));
|
|
588
603
|
});
|
|
589
604
|
(0, _EventEmitter.addListener)(this, 'peerConnectionIceGatheringChanged', ev => {
|
|
590
|
-
if (ev.
|
|
605
|
+
if (ev.pcId !== this._pcId) {
|
|
591
606
|
return;
|
|
592
607
|
}
|
|
593
608
|
|
|
@@ -605,7 +620,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
605
620
|
this.dispatchEvent(new _RTCEvent.default('icegatheringstatechange'));
|
|
606
621
|
});
|
|
607
622
|
(0, _EventEmitter.addListener)(this, 'peerConnectionDidOpenDataChannel', ev => {
|
|
608
|
-
if (ev.
|
|
623
|
+
if (ev.pcId !== this._pcId) {
|
|
609
624
|
return;
|
|
610
625
|
}
|
|
611
626
|
|
|
@@ -614,34 +629,16 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
614
629
|
this.dispatchEvent(new _RTCDataChannelEvent.default('datachannel', {
|
|
615
630
|
channel
|
|
616
631
|
}));
|
|
617
|
-
}); // Since the current underlying architecture performs certain actions
|
|
618
|
-
// Asynchronously when the outer web API expects synchronous behaviour
|
|
619
|
-
// This is the only way to report error on operations for those who wish
|
|
620
|
-
// to handle them.
|
|
621
|
-
|
|
622
|
-
(0, _EventEmitter.addListener)(this, 'peerConnectionOnError', ev => {
|
|
623
|
-
if (ev.info.peerConnectionId !== this._peerConnectionId) {
|
|
624
|
-
return;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
log.error(`onerror: ${JSON.stringify(ev)}`); // @ts-ignore
|
|
628
|
-
|
|
629
|
-
this.dispatchEvent(new _RTCErrorEvent.default('error', ev.func, ev.message));
|
|
630
632
|
});
|
|
631
633
|
(0, _EventEmitter.addListener)(this, 'mediaStreamTrackMuteChanged', ev => {
|
|
632
|
-
if (ev.
|
|
634
|
+
if (ev.pcId !== this._pcId) {
|
|
633
635
|
return;
|
|
634
636
|
}
|
|
635
637
|
|
|
636
638
|
const [track] = this.getReceivers().map(r => r.track).filter(t => (t === null || t === void 0 ? void 0 : t.id) === ev.trackId);
|
|
637
639
|
|
|
638
640
|
if (track) {
|
|
639
|
-
track.
|
|
640
|
-
const eventName = ev.muted ? 'mute' : 'unmute'; // @ts-ignore
|
|
641
|
-
|
|
642
|
-
track.dispatchEvent(new _MediaStreamTrackEvent.default(eventName, {
|
|
643
|
-
track
|
|
644
|
-
}));
|
|
641
|
+
track._setMutedInternal(ev.muted);
|
|
645
642
|
}
|
|
646
643
|
});
|
|
647
644
|
}
|
|
@@ -667,7 +664,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
667
664
|
}
|
|
668
665
|
}
|
|
669
666
|
|
|
670
|
-
const channelInfo = WebRTCModule.createDataChannel(this.
|
|
667
|
+
const channelInfo = WebRTCModule.createDataChannel(this._pcId, label, dataChannelDict);
|
|
671
668
|
|
|
672
669
|
if (channelInfo === null) {
|
|
673
670
|
throw new TypeError('Failed to create new DataChannel');
|
|
@@ -696,7 +693,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
696
693
|
|
|
697
694
|
_updateTransceivers(transceiverUpdates) {
|
|
698
695
|
for (const update of transceiverUpdates) {
|
|
699
|
-
const [transceiver] = this.getTransceivers().filter(t => t.id === update.transceiverId);
|
|
696
|
+
const [transceiver] = this.getTransceivers().filter(t => t.sender.id === update.transceiverId);
|
|
700
697
|
|
|
701
698
|
if (!transceiver) {
|
|
702
699
|
continue;
|