react-native-webrtc 106.0.0-beta.4 → 106.0.0-beta.6
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/PeerConnectionObserver.java +18 -24
- package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +39 -62
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +54 -48
- 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 +16 -0
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/RTCPeerConnection.js +92 -109
- 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 -42
- package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
- package/lib/commonjs/index.js +3 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +17 -1
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/RTCPeerConnection.js +92 -107
- 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 -37
- package/lib/module/RTCRtpTransceiver.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 +9 -2
- package/lib/typescript/RTCPeerConnection.d.ts +5 -5
- package/lib/typescript/RTCRtpTransceiver.d.ts +2 -5
- package/package.json +2 -2
- package/src/MediaStreamTrack.ts +16 -1
- package/src/RTCPeerConnection.ts +94 -114
- package/src/RTCRtpSender.ts +6 -7
- package/src/RTCRtpTransceiver.ts +15 -38
- package/src/index.ts +2 -0
|
@@ -6,10 +6,8 @@ import { addListener, removeListener } from './EventEmitter';
|
|
|
6
6
|
import Logger from './Logger';
|
|
7
7
|
import MediaStream from './MediaStream';
|
|
8
8
|
import MediaStreamTrack from './MediaStreamTrack';
|
|
9
|
-
import MediaStreamTrackEvent from './MediaStreamTrackEvent';
|
|
10
9
|
import RTCDataChannel from './RTCDataChannel';
|
|
11
10
|
import RTCDataChannelEvent from './RTCDataChannelEvent';
|
|
12
|
-
import RTCErrorEvent from './RTCErrorEvent';
|
|
13
11
|
import RTCEvent from './RTCEvent';
|
|
14
12
|
import RTCIceCandidate from './RTCIceCandidate';
|
|
15
13
|
import RTCIceCandidateEvent from './RTCIceCandidateEvent';
|
|
@@ -43,32 +41,32 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
43
41
|
|
|
44
42
|
_defineProperty(this, "iceConnectionState", 'new');
|
|
45
43
|
|
|
46
|
-
_defineProperty(this, "
|
|
44
|
+
_defineProperty(this, "_pcId", void 0);
|
|
47
45
|
|
|
48
46
|
_defineProperty(this, "_transceivers", []);
|
|
49
47
|
|
|
50
48
|
_defineProperty(this, "_remoteStreams", new Map());
|
|
51
49
|
|
|
52
|
-
this.
|
|
53
|
-
WebRTCModule.peerConnectionInit(configuration, this.
|
|
50
|
+
this._pcId = nextPeerConnectionId++;
|
|
51
|
+
WebRTCModule.peerConnectionInit(configuration, this._pcId);
|
|
54
52
|
|
|
55
53
|
this._registerEvents();
|
|
56
54
|
|
|
57
|
-
log.debug(`${this.
|
|
55
|
+
log.debug(`${this._pcId} ctor`);
|
|
58
56
|
}
|
|
59
57
|
|
|
60
58
|
createOffer(options) {
|
|
61
|
-
log.debug(`${this.
|
|
59
|
+
log.debug(`${this._pcId} createOffer`);
|
|
62
60
|
return new Promise((resolve, reject) => {
|
|
63
|
-
WebRTCModule.peerConnectionCreateOffer(this.
|
|
61
|
+
WebRTCModule.peerConnectionCreateOffer(this._pcId, RTCUtil.normalizeOfferOptions(options), (successful, data) => {
|
|
64
62
|
if (successful) {
|
|
65
|
-
log.debug(`${this.
|
|
63
|
+
log.debug(`${this._pcId} createOffer OK`);
|
|
66
64
|
|
|
67
65
|
this._updateTransceivers(data.transceiversInfo);
|
|
68
66
|
|
|
69
67
|
resolve(data.sdpInfo);
|
|
70
68
|
} else {
|
|
71
|
-
log.debug(`${this.
|
|
69
|
+
log.debug(`${this._pcId} createOffer ERROR`);
|
|
72
70
|
reject(data);
|
|
73
71
|
}
|
|
74
72
|
});
|
|
@@ -76,17 +74,17 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
createAnswer() {
|
|
79
|
-
log.debug(`${this.
|
|
77
|
+
log.debug(`${this._pcId} createAnswer`);
|
|
80
78
|
return new Promise((resolve, reject) => {
|
|
81
|
-
WebRTCModule.peerConnectionCreateAnswer(this.
|
|
79
|
+
WebRTCModule.peerConnectionCreateAnswer(this._pcId, {}, (successful, data) => {
|
|
82
80
|
if (successful) {
|
|
83
|
-
log.debug(`${this.
|
|
81
|
+
log.debug(`${this._pcId} createAnswer OK`);
|
|
84
82
|
|
|
85
83
|
this._updateTransceivers(data.transceiversInfo);
|
|
86
84
|
|
|
87
85
|
resolve(data.sdpInfo);
|
|
88
86
|
} else {
|
|
89
|
-
log.debug(`${this.
|
|
87
|
+
log.debug(`${this._pcId} createAnswer ERROR`);
|
|
90
88
|
reject(data);
|
|
91
89
|
}
|
|
92
90
|
});
|
|
@@ -94,11 +92,11 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
setConfiguration(configuration) {
|
|
97
|
-
WebRTCModule.peerConnectionSetConfiguration(configuration, this.
|
|
95
|
+
WebRTCModule.peerConnectionSetConfiguration(configuration, this._pcId);
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
async setLocalDescription(sessionDescription) {
|
|
101
|
-
log.debug(`${this.
|
|
99
|
+
log.debug(`${this._pcId} setLocalDescription`);
|
|
102
100
|
let desc;
|
|
103
101
|
|
|
104
102
|
if (sessionDescription) {
|
|
@@ -119,18 +117,18 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
119
117
|
const {
|
|
120
118
|
sdpInfo,
|
|
121
119
|
transceiversInfo
|
|
122
|
-
} = await WebRTCModule.peerConnectionSetLocalDescription(this.
|
|
120
|
+
} = await WebRTCModule.peerConnectionSetLocalDescription(this._pcId, desc);
|
|
123
121
|
this.localDescription = new RTCSessionDescription(sdpInfo);
|
|
124
122
|
|
|
125
123
|
this._updateTransceivers(transceiversInfo);
|
|
126
124
|
|
|
127
|
-
log.debug(`${this.
|
|
125
|
+
log.debug(`${this._pcId} setLocalDescription OK`);
|
|
128
126
|
}
|
|
129
127
|
|
|
130
128
|
setRemoteDescription(sessionDescription) {
|
|
131
129
|
var _sessionDescription$s2, _desc$type;
|
|
132
130
|
|
|
133
|
-
log.debug(`${this.
|
|
131
|
+
log.debug(`${this._pcId} setRemoteDescription`);
|
|
134
132
|
|
|
135
133
|
if (!sessionDescription) {
|
|
136
134
|
return Promise.reject(new Error('No session description provided'));
|
|
@@ -146,11 +144,11 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
146
144
|
}
|
|
147
145
|
|
|
148
146
|
return new Promise((resolve, reject) => {
|
|
149
|
-
WebRTCModule.peerConnectionSetRemoteDescription(desc, this.
|
|
147
|
+
WebRTCModule.peerConnectionSetRemoteDescription(desc, this._pcId, (successful, data) => {
|
|
150
148
|
if (successful) {
|
|
151
149
|
var _data$newTransceivers;
|
|
152
150
|
|
|
153
|
-
log.debug(`${this.
|
|
151
|
+
log.debug(`${this._pcId} setRemoteDescription OK`);
|
|
154
152
|
this.remoteDescription = new RTCSessionDescription(data.sdpInfo);
|
|
155
153
|
(_data$newTransceivers = data.newTransceivers) === null || _data$newTransceivers === void 0 ? void 0 : _data$newTransceivers.forEach(t => {
|
|
156
154
|
const {
|
|
@@ -178,29 +176,28 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
178
176
|
}
|
|
179
177
|
|
|
180
178
|
async addIceCandidate(candidate) {
|
|
181
|
-
log.debug(`${this.
|
|
179
|
+
log.debug(`${this._pcId} addIceCandidate`);
|
|
182
180
|
|
|
183
181
|
if (!candidate || !candidate.candidate) {
|
|
184
182
|
// XXX end-of cantidates is not implemented: https://bugs.chromium.org/p/webrtc/issues/detail?id=9218
|
|
185
183
|
return;
|
|
186
184
|
}
|
|
187
185
|
|
|
188
|
-
const newSdp = await WebRTCModule.peerConnectionAddICECandidate(this.
|
|
186
|
+
const newSdp = await WebRTCModule.peerConnectionAddICECandidate(this._pcId, candidate.toJSON ? candidate.toJSON() : candidate);
|
|
189
187
|
this.remoteDescription = new RTCSessionDescription(newSdp);
|
|
190
188
|
}
|
|
191
189
|
/**
|
|
192
190
|
* @brief Adds a new track to the {@link RTCPeerConnection},
|
|
193
|
-
* and indicates that it is contained in the specified {@link MediaStream}
|
|
194
|
-
* This method has to be synchronous as the W3C API expects a track to be
|
|
191
|
+
* and indicates that it is contained in the specified {@link MediaStream}s.
|
|
192
|
+
* This method has to be synchronous as the W3C API expects a track to be returned
|
|
195
193
|
* @param {MediaStreamTrack} track The track to be added
|
|
196
|
-
* @param {MediaStream
|
|
194
|
+
* @param {...MediaStream} streams One or more {@link MediaStream}s the track needs to be added to
|
|
197
195
|
* https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack
|
|
198
196
|
*/
|
|
199
197
|
|
|
200
198
|
|
|
201
199
|
addTrack(track) {
|
|
202
|
-
|
|
203
|
-
log.debug(`${this._peerConnectionId} addTrack`);
|
|
200
|
+
log.debug(`${this._pcId} addTrack`);
|
|
204
201
|
|
|
205
202
|
if (this.connectionState === 'closed') {
|
|
206
203
|
throw new Error('Peer Connection is closed');
|
|
@@ -210,8 +207,12 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
210
207
|
throw new Error('Track already exists in a sender');
|
|
211
208
|
}
|
|
212
209
|
|
|
210
|
+
for (var _len = arguments.length, streams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
211
|
+
streams[_key - 1] = arguments[_key];
|
|
212
|
+
}
|
|
213
|
+
|
|
213
214
|
const streamIds = streams.map(s => s.id);
|
|
214
|
-
const result = WebRTCModule.peerConnectionAddTrack(this.
|
|
215
|
+
const result = WebRTCModule.peerConnectionAddTrack(this._pcId, track.id, {
|
|
215
216
|
streamIds
|
|
216
217
|
});
|
|
217
218
|
|
|
@@ -257,7 +258,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
257
258
|
}
|
|
258
259
|
|
|
259
260
|
addTransceiver(source, init) {
|
|
260
|
-
log.debug(`${this.
|
|
261
|
+
log.debug(`${this._pcId} addTransceiver`);
|
|
261
262
|
let src = {};
|
|
262
263
|
|
|
263
264
|
if (source === 'audio') {
|
|
@@ -279,7 +280,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
279
280
|
init.streamIds = init.streams.map(stream => stream.id);
|
|
280
281
|
}
|
|
281
282
|
|
|
282
|
-
const result = WebRTCModule.peerConnectionAddTransceiver(this.
|
|
283
|
+
const result = WebRTCModule.peerConnectionAddTransceiver(this._pcId, { ...src,
|
|
283
284
|
init: { ...init
|
|
284
285
|
}
|
|
285
286
|
});
|
|
@@ -318,9 +319,9 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
318
319
|
}
|
|
319
320
|
|
|
320
321
|
removeTrack(sender) {
|
|
321
|
-
log.debug(`${this.
|
|
322
|
+
log.debug(`${this._pcId} removeTrack`);
|
|
322
323
|
|
|
323
|
-
if (this.
|
|
324
|
+
if (this._pcId !== sender._peerConnectionId) {
|
|
324
325
|
throw new Error('Sender does not belong to this peer connection');
|
|
325
326
|
}
|
|
326
327
|
|
|
@@ -336,14 +337,18 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
336
337
|
|
|
337
338
|
if (existingSender.track === null) {
|
|
338
339
|
return;
|
|
339
|
-
}
|
|
340
|
+
} // Blocking!
|
|
340
341
|
|
|
341
|
-
|
|
342
|
+
|
|
343
|
+
WebRTCModule.peerConnectionRemoveTrack(this._pcId, sender.id);
|
|
344
|
+
existingSender._track = null;
|
|
345
|
+
const [existingTransceiver] = this.getTransceivers().filter(t => t.sender.id === existingSender.id);
|
|
346
|
+
existingTransceiver._direction = existingTransceiver.direction === 'sendrecv' ? 'recvonly' : 'inactive';
|
|
342
347
|
}
|
|
343
348
|
|
|
344
349
|
getStats() {
|
|
345
|
-
log.debug(`${this.
|
|
346
|
-
return WebRTCModule.peerConnectionGetStats(this.
|
|
350
|
+
log.debug(`${this._pcId} getStats`);
|
|
351
|
+
return WebRTCModule.peerConnectionGetStats(this._pcId).then(data =>
|
|
347
352
|
/* On both Android and iOS it is faster to construct a single
|
|
348
353
|
JSON string representing the Map of StatsReports and have it
|
|
349
354
|
pass through the React Native bridge rather than the Map of
|
|
@@ -370,26 +375,25 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
370
375
|
}
|
|
371
376
|
|
|
372
377
|
close() {
|
|
373
|
-
log.debug(`${this.
|
|
374
|
-
// transceivers
|
|
378
|
+
log.debug(`${this._pcId} close`);
|
|
379
|
+
WebRTCModule.peerConnectionClose(this._pcId); // Mark transceivers as stopped.
|
|
375
380
|
|
|
376
381
|
this._transceivers.forEach(_ref => {
|
|
377
382
|
let {
|
|
378
383
|
transceiver
|
|
379
384
|
} = _ref;
|
|
380
|
-
transceiver.stop();
|
|
381
|
-
});
|
|
382
385
|
|
|
383
|
-
|
|
386
|
+
transceiver._setStopped();
|
|
387
|
+
});
|
|
384
388
|
}
|
|
385
389
|
|
|
386
390
|
restartIce() {
|
|
387
|
-
WebRTCModule.peerConnectionRestartIce(this.
|
|
391
|
+
WebRTCModule.peerConnectionRestartIce(this._pcId);
|
|
388
392
|
}
|
|
389
393
|
|
|
390
394
|
_registerEvents() {
|
|
391
395
|
addListener(this, 'peerConnectionOnRenegotiationNeeded', ev => {
|
|
392
|
-
if (ev.
|
|
396
|
+
if (ev.pcId !== this._pcId) {
|
|
393
397
|
return;
|
|
394
398
|
} // @ts-ignore
|
|
395
399
|
|
|
@@ -397,7 +401,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
397
401
|
this.dispatchEvent(new RTCEvent('negotiationneeded'));
|
|
398
402
|
});
|
|
399
403
|
addListener(this, 'peerConnectionIceConnectionChanged', ev => {
|
|
400
|
-
if (ev.
|
|
404
|
+
if (ev.pcId !== this._pcId) {
|
|
401
405
|
return;
|
|
402
406
|
}
|
|
403
407
|
|
|
@@ -412,7 +416,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
412
416
|
this.dispatchEvent(new RTCEvent('iceconnectionstatechange'));
|
|
413
417
|
});
|
|
414
418
|
addListener(this, 'peerConnectionStateChanged', ev => {
|
|
415
|
-
if (ev.
|
|
419
|
+
if (ev.pcId !== this._pcId) {
|
|
416
420
|
return;
|
|
417
421
|
}
|
|
418
422
|
|
|
@@ -427,7 +431,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
427
431
|
this.dispatchEvent(new RTCEvent('connectionstatechange'));
|
|
428
432
|
});
|
|
429
433
|
addListener(this, 'peerConnectionSignalingStateChanged', ev => {
|
|
430
|
-
if (ev.
|
|
434
|
+
if (ev.pcId !== this._pcId) {
|
|
431
435
|
return;
|
|
432
436
|
}
|
|
433
437
|
|
|
@@ -437,12 +441,12 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
437
441
|
}); // Consider moving away from this event: https://github.com/WebKit/WebKit/pull/3953
|
|
438
442
|
|
|
439
443
|
addListener(this, 'peerConnectionOnTrack', ev => {
|
|
440
|
-
if (ev.
|
|
444
|
+
if (ev.pcId !== this._pcId) {
|
|
441
445
|
return;
|
|
442
446
|
}
|
|
443
447
|
|
|
444
|
-
log.debug(`${this.
|
|
445
|
-
|
|
448
|
+
log.debug(`${this._pcId} ontrack`);
|
|
449
|
+
let track;
|
|
446
450
|
let transceiver; // Make sure transceivers are stored in timestamp order. Also, we have to make
|
|
447
451
|
// sure we do not add a transceiver if it exists.
|
|
448
452
|
|
|
@@ -455,10 +459,19 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
455
459
|
transceiver
|
|
456
460
|
} = _ref2;
|
|
457
461
|
return transceiver.id === ev.transceiver.id;
|
|
458
|
-
});
|
|
462
|
+
}); // We need to fire this event for an existing track sometimes, like
|
|
463
|
+
// when the transceiver direction (on the sending side) switches from
|
|
464
|
+
// sendrecv to recvonly and then back.
|
|
465
|
+
|
|
459
466
|
|
|
460
|
-
if (
|
|
461
|
-
|
|
467
|
+
if (oldTransceiver) {
|
|
468
|
+
transceiver = oldTransceiver;
|
|
469
|
+
track = transceiver._receiver._track;
|
|
470
|
+
transceiver._mid = ev.transceiver.mid;
|
|
471
|
+
transceiver._currentDirection = ev.transceiver.currentDirection;
|
|
472
|
+
transceiver._direction = ev.transceiver.direction;
|
|
473
|
+
} else {
|
|
474
|
+
track = new MediaStreamTrack(ev.receiver.track);
|
|
462
475
|
const sender = new RTCRtpSender({ ...ev.transceiver.sender
|
|
463
476
|
});
|
|
464
477
|
const receiver = new RTCRtpReceiver({ ...ev.receiver,
|
|
@@ -470,12 +483,6 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
470
483
|
});
|
|
471
484
|
|
|
472
485
|
this._insertTransceiverSorted(ev.transceiverOrder, transceiver);
|
|
473
|
-
} else {
|
|
474
|
-
transceiver = oldTransceiver;
|
|
475
|
-
transceiver._receiver._track = track;
|
|
476
|
-
transceiver._mid = ev.transceiver.mid;
|
|
477
|
-
transceiver._currentDirection = ev.transceiver.currentDirection;
|
|
478
|
-
transceiver._direction = ev.transceiver.direction;
|
|
479
486
|
} // Get the stream object from the event. Create if necessary.
|
|
480
487
|
|
|
481
488
|
|
|
@@ -494,7 +501,10 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
494
501
|
|
|
495
502
|
const stream = this._remoteStreams.get(streamInfo.streamId);
|
|
496
503
|
|
|
497
|
-
stream
|
|
504
|
+
if (!(stream !== null && stream !== void 0 && stream._tracks.includes(track))) {
|
|
505
|
+
stream === null || stream === void 0 ? void 0 : stream._tracks.push(track);
|
|
506
|
+
}
|
|
507
|
+
|
|
498
508
|
return stream;
|
|
499
509
|
});
|
|
500
510
|
const eventData = {
|
|
@@ -504,43 +514,36 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
504
514
|
receiver: transceiver.receiver
|
|
505
515
|
}; // @ts-ignore
|
|
506
516
|
|
|
507
|
-
this.dispatchEvent(new RTCTrackEvent('track', eventData));
|
|
517
|
+
this.dispatchEvent(new RTCTrackEvent('track', eventData)); // Dispatch an unmute event for the track.
|
|
518
|
+
|
|
519
|
+
track._setMutedInternal(false);
|
|
508
520
|
});
|
|
509
521
|
addListener(this, 'peerConnectionOnRemoveTrack', ev => {
|
|
510
|
-
if (ev.
|
|
522
|
+
if (ev.pcId !== this._pcId) {
|
|
511
523
|
return;
|
|
512
524
|
}
|
|
513
525
|
|
|
514
|
-
log.debug(`${this.
|
|
515
|
-
//
|
|
516
|
-
//
|
|
526
|
+
log.debug(`${this._pcId} onremovetrack`); // As per the spec:
|
|
527
|
+
// - Remove the track from any media streams that were previously passed to the `track` event.
|
|
528
|
+
// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-removetrack,
|
|
529
|
+
// - Mark the track as muted:
|
|
530
|
+
// https://w3c.github.io/webrtc-pc/#process-remote-track-removal
|
|
517
531
|
|
|
518
532
|
for (const stream of this._remoteStreams.values()) {
|
|
519
|
-
const
|
|
533
|
+
const [track] = stream._tracks.filter(t => t.id === ev.trackId);
|
|
520
534
|
|
|
521
|
-
if (
|
|
522
|
-
stream._tracks.
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
addListener(this, 'peerConnectionOnRemoveTrackSuccessful', ev => {
|
|
527
|
-
if (ev.peerConnectionId !== this._peerConnectionId) {
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
535
|
+
if (track) {
|
|
536
|
+
const trackIdx = stream._tracks.indexOf(track);
|
|
530
537
|
|
|
531
|
-
|
|
532
|
-
const oldTrack = existingSender._track;
|
|
538
|
+
stream._tracks.splice(trackIdx, 1); // Dispatch a mute event for the track.
|
|
533
539
|
|
|
534
|
-
if (oldTrack) {
|
|
535
|
-
oldTrack._muted = true;
|
|
536
|
-
}
|
|
537
540
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
+
track._setMutedInternal(true);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
541
544
|
});
|
|
542
545
|
addListener(this, 'peerConnectionGotICECandidate', ev => {
|
|
543
|
-
if (ev.
|
|
546
|
+
if (ev.pcId !== this._pcId) {
|
|
544
547
|
return;
|
|
545
548
|
}
|
|
546
549
|
|
|
@@ -552,7 +555,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
552
555
|
}));
|
|
553
556
|
});
|
|
554
557
|
addListener(this, 'peerConnectionIceGatheringChanged', ev => {
|
|
555
|
-
if (ev.
|
|
558
|
+
if (ev.pcId !== this._pcId) {
|
|
556
559
|
return;
|
|
557
560
|
}
|
|
558
561
|
|
|
@@ -570,7 +573,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
570
573
|
this.dispatchEvent(new RTCEvent('icegatheringstatechange'));
|
|
571
574
|
});
|
|
572
575
|
addListener(this, 'peerConnectionDidOpenDataChannel', ev => {
|
|
573
|
-
if (ev.
|
|
576
|
+
if (ev.pcId !== this._pcId) {
|
|
574
577
|
return;
|
|
575
578
|
}
|
|
576
579
|
|
|
@@ -579,34 +582,16 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
579
582
|
this.dispatchEvent(new RTCDataChannelEvent('datachannel', {
|
|
580
583
|
channel
|
|
581
584
|
}));
|
|
582
|
-
}); // Since the current underlying architecture performs certain actions
|
|
583
|
-
// Asynchronously when the outer web API expects synchronous behaviour
|
|
584
|
-
// This is the only way to report error on operations for those who wish
|
|
585
|
-
// to handle them.
|
|
586
|
-
|
|
587
|
-
addListener(this, 'peerConnectionOnError', ev => {
|
|
588
|
-
if (ev.info.peerConnectionId !== this._peerConnectionId) {
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
log.error(`onerror: ${JSON.stringify(ev)}`); // @ts-ignore
|
|
593
|
-
|
|
594
|
-
this.dispatchEvent(new RTCErrorEvent('error', ev.func, ev.message));
|
|
595
585
|
});
|
|
596
586
|
addListener(this, 'mediaStreamTrackMuteChanged', ev => {
|
|
597
|
-
if (ev.
|
|
587
|
+
if (ev.pcId !== this._pcId) {
|
|
598
588
|
return;
|
|
599
589
|
}
|
|
600
590
|
|
|
601
591
|
const [track] = this.getReceivers().map(r => r.track).filter(t => (t === null || t === void 0 ? void 0 : t.id) === ev.trackId);
|
|
602
592
|
|
|
603
593
|
if (track) {
|
|
604
|
-
track.
|
|
605
|
-
const eventName = ev.muted ? 'mute' : 'unmute'; // @ts-ignore
|
|
606
|
-
|
|
607
|
-
track.dispatchEvent(new MediaStreamTrackEvent(eventName, {
|
|
608
|
-
track
|
|
609
|
-
}));
|
|
594
|
+
track._setMutedInternal(ev.muted);
|
|
610
595
|
}
|
|
611
596
|
});
|
|
612
597
|
}
|
|
@@ -632,7 +617,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
632
617
|
}
|
|
633
618
|
}
|
|
634
619
|
|
|
635
|
-
const channelInfo = WebRTCModule.createDataChannel(this.
|
|
620
|
+
const channelInfo = WebRTCModule.createDataChannel(this._pcId, label, dataChannelDict);
|
|
636
621
|
|
|
637
622
|
if (channelInfo === null) {
|
|
638
623
|
throw new TypeError('Failed to create new DataChannel');
|