react-native-webrtc 106.0.0-beta.1 → 106.0.0-beta.3
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/.eslintignore +6 -0
- package/.github/stale.yml +15 -0
- package/.github/workflows/ci.yml +17 -0
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +36 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +27 -1
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/ProcessorProvider.java +37 -0
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoEffectProcessor.java +57 -0
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessor.java +19 -0
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessorFactoryInterface.java +13 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +19 -3
- package/ios/RCTWebRTC.xcodeproj/project.pbxproj +46 -9
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/RCTWebRTC.xcodeproj/xcuserdata/saghul.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/ios/RCTWebRTC.xcworkspace/contents.xcworkspacedata +10 -0
- package/lib/commonjs/EventEmitter.js.map +1 -1
- package/lib/commonjs/Logger.js.map +1 -1
- package/lib/commonjs/MediaDevices.js +2 -2
- package/lib/commonjs/MediaDevices.js.map +1 -1
- package/lib/commonjs/MediaStream.js +3 -3
- package/lib/commonjs/MediaStream.js.map +1 -1
- package/lib/commonjs/MediaStreamTrack.js +15 -3
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/Permissions.js +3 -3
- package/lib/commonjs/Permissions.js.map +1 -1
- package/lib/commonjs/RTCDataChannel.js +6 -5
- package/lib/commonjs/RTCDataChannel.js.map +1 -1
- package/lib/commonjs/RTCErrorEvent.js +1 -1
- package/lib/commonjs/RTCErrorEvent.js.map +1 -1
- package/lib/commonjs/RTCPeerConnection.js +166 -61
- package/lib/commonjs/RTCPeerConnection.js.map +1 -1
- package/lib/commonjs/RTCRtcpParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpCapabilities.js +10 -2
- package/lib/commonjs/RTCRtpCapabilities.js.map +1 -1
- package/lib/commonjs/RTCRtpCodecParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpEncodingParameters.js +9 -9
- package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpReceiveParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpReceiver.js +5 -8
- package/lib/commonjs/RTCRtpReceiver.js.map +1 -1
- package/lib/commonjs/RTCRtpSendParameters.js +1 -1
- package/lib/commonjs/RTCRtpSendParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpSender.js +2 -2
- package/lib/commonjs/RTCRtpSender.js.map +1 -1
- package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
- package/lib/commonjs/RTCSessionDescription.js.map +1 -1
- package/lib/commonjs/RTCUtil.js +13 -0
- package/lib/commonjs/RTCUtil.js.map +1 -1
- package/lib/commonjs/getDisplayMedia.js.map +1 -1
- package/lib/commonjs/getUserMedia.js +3 -3
- package/lib/commonjs/getUserMedia.js.map +1 -1
- package/lib/commonjs/index.js +22 -22
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/Logger.js.map +1 -1
- package/lib/module/MediaDevices.js +1 -1
- package/lib/module/MediaDevices.js.map +1 -1
- package/lib/module/MediaStream.js +2 -2
- package/lib/module/MediaStream.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +14 -2
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/Permissions.js +3 -3
- package/lib/module/Permissions.js.map +1 -1
- package/lib/module/RTCDataChannel.js +4 -3
- package/lib/module/RTCDataChannel.js.map +1 -1
- package/lib/module/RTCErrorEvent.js +2 -2
- package/lib/module/RTCErrorEvent.js.map +1 -1
- package/lib/module/RTCPeerConnection.js +163 -59
- package/lib/module/RTCPeerConnection.js.map +1 -1
- package/lib/module/RTCRtcpParameters.js.map +1 -1
- package/lib/module/RTCRtpCapabilities.js +10 -2
- package/lib/module/RTCRtpCapabilities.js.map +1 -1
- package/lib/module/RTCRtpCodecParameters.js.map +1 -1
- package/lib/module/RTCRtpEncodingParameters.js +9 -9
- package/lib/module/RTCRtpEncodingParameters.js.map +1 -1
- package/lib/module/RTCRtpParameters.js.map +1 -1
- package/lib/module/RTCRtpReceiveParameters.js +1 -1
- package/lib/module/RTCRtpReceiveParameters.js.map +1 -1
- package/lib/module/RTCRtpReceiver.js +5 -6
- package/lib/module/RTCRtpReceiver.js.map +1 -1
- package/lib/module/RTCRtpSendParameters.js +2 -2
- package/lib/module/RTCRtpSendParameters.js.map +1 -1
- package/lib/module/RTCRtpSender.js +2 -2
- package/lib/module/RTCRtpSender.js.map +1 -1
- package/lib/module/RTCRtpTransceiver.js.map +1 -1
- package/lib/module/RTCSessionDescription.js.map +1 -1
- package/lib/module/RTCUtil.js +11 -0
- package/lib/module/RTCUtil.js.map +1 -1
- package/lib/module/getDisplayMedia.js.map +1 -1
- package/lib/module/getUserMedia.js +1 -1
- package/lib/module/getUserMedia.js.map +1 -1
- package/lib/module/index.js +14 -14
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/EventEmitter.d.ts +4 -3
- package/lib/typescript/MediaStreamTrack.d.ts +1 -0
- package/lib/typescript/Permissions.d.ts +1 -1
- package/lib/typescript/RTCDataChannel.d.ts +2 -1
- package/lib/typescript/RTCErrorEvent.d.ts +1 -1
- package/lib/typescript/RTCPeerConnection.d.ts +6 -7
- package/lib/typescript/RTCRtpCodecParameters.d.ts +2 -2
- package/lib/typescript/RTCRtpEncodingParameters.d.ts +2 -2
- package/lib/typescript/RTCRtpParameters.d.ts +3 -3
- package/lib/typescript/RTCRtpReceiveParameters.d.ts +1 -1
- package/lib/typescript/RTCRtpReceiver.d.ts +1 -1
- package/lib/typescript/RTCRtpSendParameters.d.ts +2 -2
- package/lib/typescript/RTCRtpSender.d.ts +1 -1
- package/lib/typescript/RTCRtpTransceiver.d.ts +1 -1
- package/lib/typescript/RTCSessionDescription.d.ts +6 -8
- package/lib/typescript/RTCUtil.d.ts +7 -0
- package/lib/typescript/index.d.ts +12 -12
- package/package.json +7 -4
- package/react-native-webrtc.podspec +1 -2
- package/src/.eslintrc.cjs +67 -0
- package/src/EventEmitter.ts +5 -4
- package/src/Logger.ts +1 -1
- package/src/MediaDevices.ts +2 -2
- package/src/MediaStream.ts +13 -4
- package/src/MediaStreamTrack.ts +21 -5
- package/src/Permissions.ts +12 -5
- package/src/RTCDataChannel.ts +17 -5
- package/src/RTCErrorEvent.ts +9 -9
- package/src/RTCPeerConnection.ts +213 -92
- package/src/RTCRtcpParameters.ts +7 -7
- package/src/RTCRtpCapabilities.ts +15 -4
- package/src/RTCRtpCodecParameters.ts +2 -2
- package/src/RTCRtpEncodingParameters.ts +19 -17
- package/src/RTCRtpParameters.ts +3 -3
- package/src/RTCRtpReceiveParameters.ts +1 -2
- package/src/RTCRtpReceiver.ts +7 -7
- package/src/RTCRtpSendParameters.ts +10 -8
- package/src/RTCRtpSender.ts +11 -9
- package/src/RTCRtpTransceiver.ts +11 -7
- package/src/RTCSessionDescription.ts +7 -2
- package/src/RTCUtil.ts +24 -4
- package/src/getDisplayMedia.ts +1 -1
- package/src/getUserMedia.ts +9 -2
- package/src/index.ts +16 -14
- package/tools/downloadWebRTC.js +7 -5
- package/.prettierignore +0 -9
- package/.prettierrc.json +0 -10
- package/lib/commonjs/typings.d.js +0 -2
- package/lib/commonjs/typings.d.js.map +0 -1
- package/lib/module/typings.d.js +0 -2
- package/lib/module/typings.d.js.map +0 -1
- package/src/typings.d.ts +0 -1
package/src/RTCPeerConnection.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
|
|
2
|
-
import { defineCustomEventTarget
|
|
2
|
+
import { defineCustomEventTarget } from 'event-target-shim';
|
|
3
3
|
import { NativeModules } from 'react-native';
|
|
4
4
|
|
|
5
|
+
import { addListener, removeListener } from './EventEmitter';
|
|
5
6
|
import Logger from './Logger';
|
|
6
7
|
import MediaStream from './MediaStream';
|
|
7
8
|
import MediaStreamTrack from './MediaStreamTrack';
|
|
8
|
-
import
|
|
9
|
+
import MediaStreamTrackEvent from './MediaStreamTrackEvent';
|
|
9
10
|
import RTCDataChannel from './RTCDataChannel';
|
|
10
11
|
import RTCDataChannelEvent from './RTCDataChannelEvent';
|
|
11
|
-
import RTCTrackEvent from './RTCTrackEvent';
|
|
12
|
-
import RTCSessionDescription from './RTCSessionDescription';
|
|
13
|
-
import RTCIceCandidate from './RTCIceCandidate';
|
|
14
|
-
import RTCIceCandidateEvent from './RTCIceCandidateEvent';
|
|
15
12
|
import RTCErrorEvent from './RTCErrorEvent';
|
|
16
13
|
import RTCEvent from './RTCEvent';
|
|
17
|
-
import
|
|
18
|
-
import
|
|
14
|
+
import RTCIceCandidate from './RTCIceCandidate';
|
|
15
|
+
import RTCIceCandidateEvent from './RTCIceCandidateEvent';
|
|
19
16
|
import RTCRtpReceiver from './RTCRtpReceiver';
|
|
20
|
-
import RTCRtpSender from './RTCRtpSender';
|
|
21
17
|
import RTCRtpSendParameters from './RTCRtpSendParameters';
|
|
18
|
+
import RTCRtpSender from './RTCRtpSender';
|
|
19
|
+
import RTCRtpTransceiver from './RTCRtpTransceiver';
|
|
20
|
+
import RTCSessionDescription, { RTCSessionDescriptionInit } from './RTCSessionDescription';
|
|
21
|
+
import RTCTrackEvent from './RTCTrackEvent';
|
|
22
|
+
import * as RTCUtil from './RTCUtil';
|
|
22
23
|
|
|
23
24
|
const log = new Logger('pc');
|
|
24
25
|
const { WebRTCModule } = NativeModules;
|
|
@@ -71,7 +72,6 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
71
72
|
iceConnectionState: RTCIceConnectionState = 'new';
|
|
72
73
|
|
|
73
74
|
_peerConnectionId: number;
|
|
74
|
-
_subscriptions: any[] = [];
|
|
75
75
|
_transceivers: { order: number, transceiver: RTCRtpTransceiver }[] = [];
|
|
76
76
|
_remoteStreams: Map<string, MediaStream> = new Map<string, MediaStream>();
|
|
77
77
|
|
|
@@ -134,15 +134,28 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
134
134
|
WebRTCModule.peerConnectionSetConfiguration(configuration, this._peerConnectionId);
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
async setLocalDescription(sessionDescription?: RTCSessionDescription): Promise<void> {
|
|
137
|
+
async setLocalDescription(sessionDescription?: RTCSessionDescription | RTCSessionDescriptionInit): Promise<void> {
|
|
138
138
|
log.debug(`${this._peerConnectionId} setLocalDescription`);
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
let desc;
|
|
141
|
+
|
|
142
|
+
if (sessionDescription) {
|
|
143
|
+
desc = {
|
|
144
|
+
type: sessionDescription.type,
|
|
145
|
+
sdp: sessionDescription.sdp ?? ''
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
if (!RTCUtil.isSdpTypeValid(desc.type)) {
|
|
149
|
+
throw new Error(`Invalid session description: invalid type: ${desc.type}`);
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
desc = null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const {
|
|
156
|
+
sdpInfo,
|
|
157
|
+
transceiversInfo
|
|
158
|
+
} = await WebRTCModule.peerConnectionSetLocalDescription(this._peerConnectionId, desc);
|
|
146
159
|
|
|
147
160
|
this.localDescription = new RTCSessionDescription(sdpInfo);
|
|
148
161
|
this._updateTransceivers(transceiversInfo);
|
|
@@ -150,19 +163,47 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
150
163
|
log.debug(`${this._peerConnectionId} setLocalDescription OK`);
|
|
151
164
|
}
|
|
152
165
|
|
|
153
|
-
setRemoteDescription(sessionDescription: RTCSessionDescription): Promise<void> {
|
|
166
|
+
setRemoteDescription(sessionDescription: RTCSessionDescription | RTCSessionDescriptionInit): Promise<void> {
|
|
154
167
|
log.debug(`${this._peerConnectionId} setRemoteDescription`);
|
|
155
168
|
|
|
169
|
+
if (!sessionDescription) {
|
|
170
|
+
return Promise.reject(new Error('No session description provided'));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const desc = {
|
|
174
|
+
type: sessionDescription.type,
|
|
175
|
+
sdp: sessionDescription.sdp ?? ''
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
if (!RTCUtil.isSdpTypeValid(desc.type ?? '')) {
|
|
179
|
+
throw new Error(`Invalid session description: invalid type: ${desc.type}`);
|
|
180
|
+
}
|
|
181
|
+
|
|
156
182
|
return new Promise((resolve, reject) => {
|
|
157
183
|
WebRTCModule.peerConnectionSetRemoteDescription(
|
|
158
|
-
|
|
184
|
+
desc,
|
|
159
185
|
this._peerConnectionId,
|
|
160
186
|
(successful, data) => {
|
|
161
187
|
if (successful) {
|
|
162
188
|
log.debug(`${this._peerConnectionId} setRemoteDescription OK`);
|
|
163
189
|
|
|
164
190
|
this.remoteDescription = new RTCSessionDescription(data.sdpInfo);
|
|
191
|
+
|
|
192
|
+
data.newTransceivers?.forEach( t => {
|
|
193
|
+
const { transceiverOrder, transceiver } = t;
|
|
194
|
+
const newSender = new RTCRtpSender(transceiver.sender);
|
|
195
|
+
const newReceiver = new RTCRtpReceiver(transceiver.receiver);
|
|
196
|
+
const newTransceiver = new RTCRtpTransceiver({
|
|
197
|
+
...transceiver,
|
|
198
|
+
sender: newSender,
|
|
199
|
+
receiver: newReceiver,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
this._insertTransceiverSorted(transceiverOrder, newTransceiver);
|
|
203
|
+
});
|
|
204
|
+
|
|
165
205
|
this._updateTransceivers(data.transceiversInfo);
|
|
206
|
+
|
|
166
207
|
resolve();
|
|
167
208
|
} else {
|
|
168
209
|
reject(data);
|
|
@@ -189,7 +230,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
189
230
|
}
|
|
190
231
|
|
|
191
232
|
/**
|
|
192
|
-
* @brief Adds a new track to the {@link RTCPeerConnection},
|
|
233
|
+
* @brief Adds a new track to the {@link RTCPeerConnection},
|
|
193
234
|
* and indicates that it is contained in the specified {@link MediaStream} array.
|
|
194
235
|
* This method has to be synchronous as the W3C API expects a track to be return
|
|
195
236
|
* @param {MediaStreamTrack} track The track to be added
|
|
@@ -199,39 +240,52 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
199
240
|
addTrack(track: MediaStreamTrack, streams: MediaStream[] = []): RTCRtpSender {
|
|
200
241
|
log.debug(`${this._peerConnectionId} addTrack`);
|
|
201
242
|
|
|
202
|
-
if (this.connectionState === 'closed')
|
|
203
|
-
|
|
243
|
+
if (this.connectionState === 'closed') {
|
|
244
|
+
throw new Error('Peer Connection is closed');
|
|
245
|
+
}
|
|
204
246
|
|
|
205
|
-
|
|
247
|
+
if (this._trackExists(track)) {
|
|
248
|
+
throw new Error('Track already exists in a sender');
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const streamIds = streams.map(s => s.id);
|
|
206
252
|
const result = WebRTCModule.peerConnectionAddTrack(this._peerConnectionId, track.id, { streamIds });
|
|
207
|
-
|
|
253
|
+
|
|
254
|
+
if (result === null) {
|
|
255
|
+
throw new Error('Could not add sender');
|
|
256
|
+
}
|
|
257
|
+
|
|
208
258
|
const { transceiverOrder, transceiver, sender } = result;
|
|
209
259
|
|
|
210
|
-
// According to the W3C docs, the sender could have been reused, and
|
|
260
|
+
// According to the W3C docs, the sender could have been reused, and
|
|
211
261
|
// so we check if that is the case, and update accordingly.
|
|
212
|
-
const [existingSender] = this
|
|
262
|
+
const [ existingSender ] = this
|
|
213
263
|
.getSenders()
|
|
214
|
-
.filter(
|
|
215
|
-
|
|
264
|
+
.filter(s => s.id === sender.id);
|
|
265
|
+
|
|
216
266
|
if (existingSender) {
|
|
217
267
|
// Update sender
|
|
218
268
|
existingSender._track = track;
|
|
219
269
|
|
|
220
270
|
// Update the corresponding transceiver as well
|
|
221
|
-
const [existingTransceiver] = this
|
|
271
|
+
const [ existingTransceiver ] = this
|
|
222
272
|
.getTransceivers()
|
|
223
|
-
.filter(
|
|
273
|
+
.filter(t => t.sender.id === existingSender.id);
|
|
274
|
+
|
|
224
275
|
existingTransceiver._direction = transceiver.direction;
|
|
225
276
|
existingTransceiver._currentDirection = transceiver.currentDirection;
|
|
277
|
+
|
|
226
278
|
return existingSender;
|
|
227
279
|
}
|
|
228
280
|
|
|
229
281
|
// This is a new transceiver, should create a transceiver for it and add it
|
|
230
282
|
const newSender = new RTCRtpSender({ ...transceiver.sender, track });
|
|
283
|
+
const remoteTrack = transceiver.receiver.track ? new MediaStreamTrack(transceiver.receiver.track) : null;
|
|
284
|
+
const newReceiver = new RTCRtpReceiver({ ...transceiver.receiver, track: remoteTrack });
|
|
231
285
|
const newTransceiver = new RTCRtpTransceiver({
|
|
232
286
|
...transceiver,
|
|
233
287
|
sender: newSender,
|
|
234
|
-
receiver:
|
|
288
|
+
receiver: newReceiver,
|
|
235
289
|
});
|
|
236
290
|
|
|
237
291
|
this._insertTransceiverSorted(transceiverOrder, newTransceiver);
|
|
@@ -243,6 +297,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
243
297
|
log.debug(`${this._peerConnectionId} addTransceiver`);
|
|
244
298
|
|
|
245
299
|
let src = {};
|
|
300
|
+
|
|
246
301
|
if (source === 'audio') {
|
|
247
302
|
src = { type: 'audio' };
|
|
248
303
|
} else if (source === 'video') {
|
|
@@ -250,44 +305,66 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
250
305
|
} else {
|
|
251
306
|
src = { trackId: source.id };
|
|
252
307
|
}
|
|
253
|
-
|
|
308
|
+
|
|
309
|
+
// Extract the stream ids
|
|
254
310
|
if (init && init.streams) {
|
|
255
|
-
init.streamIds = init.streams.map(
|
|
256
|
-
return stream.id;
|
|
257
|
-
});
|
|
311
|
+
init.streamIds = init.streams.map(stream => stream.id);
|
|
258
312
|
}
|
|
259
313
|
|
|
260
314
|
const result = WebRTCModule.peerConnectionAddTransceiver(this._peerConnectionId, { ...src, init: { ...init } });
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
throw new Error(
|
|
315
|
+
|
|
316
|
+
if (result === null) {
|
|
317
|
+
throw new Error('Transceiver could not be added');
|
|
264
318
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
319
|
+
|
|
320
|
+
const t = result.transceiver;
|
|
321
|
+
let track: MediaStreamTrack | null = null;
|
|
322
|
+
|
|
323
|
+
if (typeof source === 'string') {
|
|
324
|
+
if (t.sender.track) {
|
|
325
|
+
track = new MediaStreamTrack(t.sender.track);
|
|
326
|
+
}
|
|
327
|
+
} else {
|
|
328
|
+
// 'source' is a MediaStreamTrack
|
|
329
|
+
track = source;
|
|
268
330
|
}
|
|
269
|
-
|
|
331
|
+
|
|
332
|
+
const sender = new RTCRtpSender({ ...t.sender, track });
|
|
333
|
+
const remoteTrack = t.receiver.track ? new MediaStreamTrack(t.receiver.track) : null;
|
|
334
|
+
const receiver = new RTCRtpReceiver({ ...t.receiver, track: remoteTrack });
|
|
270
335
|
const transceiver = new RTCRtpTransceiver({
|
|
271
336
|
...result.transceiver,
|
|
272
337
|
sender,
|
|
273
338
|
receiver
|
|
274
339
|
});
|
|
340
|
+
|
|
275
341
|
this._insertTransceiverSorted(result.transceiverOrder, transceiver);
|
|
342
|
+
|
|
276
343
|
return transceiver;
|
|
277
344
|
}
|
|
278
345
|
|
|
279
346
|
removeTrack(sender: RTCRtpSender) {
|
|
280
347
|
log.debug(`${this._peerConnectionId} removeTrack`);
|
|
281
348
|
|
|
282
|
-
if (this._peerConnectionId !== sender._peerConnectionId)
|
|
283
|
-
throw new Error(
|
|
284
|
-
|
|
285
|
-
|
|
349
|
+
if (this._peerConnectionId !== sender._peerConnectionId) {
|
|
350
|
+
throw new Error('Sender does not belong to this peer connection');
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (this.connectionState === 'closed') {
|
|
354
|
+
throw new Error('Peer Connection is closed');
|
|
355
|
+
}
|
|
356
|
+
|
|
286
357
|
const existingSender = this
|
|
287
358
|
.getSenders()
|
|
288
|
-
.find(
|
|
289
|
-
|
|
290
|
-
if (existingSender
|
|
359
|
+
.find(s => s === sender);
|
|
360
|
+
|
|
361
|
+
if (!existingSender) {
|
|
362
|
+
throw new Error('Sender does not exist');
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (existingSender.track === null) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
291
368
|
|
|
292
369
|
WebRTCModule.peerConnectionRemoveTrack(this._peerConnectionId, sender.id);
|
|
293
370
|
}
|
|
@@ -295,7 +372,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
295
372
|
getStats() {
|
|
296
373
|
log.debug(`${this._peerConnectionId} getStats`);
|
|
297
374
|
|
|
298
|
-
return WebRTCModule.peerConnectionGetStats(this._peerConnectionId).then(data =>
|
|
375
|
+
return WebRTCModule.peerConnectionGetStats(this._peerConnectionId).then(data =>
|
|
299
376
|
/* On both Android and iOS it is faster to construct a single
|
|
300
377
|
JSON string representing the Map of StatsReports and have it
|
|
301
378
|
pass through the React Native bridge rather than the Map of
|
|
@@ -304,11 +381,11 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
304
381
|
Native bridge which is a bottleneck that tends to be visible in
|
|
305
382
|
the UI when there is congestion involving UI-related passing.
|
|
306
383
|
|
|
307
|
-
TODO Implement the logic for filtering the stats based on
|
|
384
|
+
TODO Implement the logic for filtering the stats based on
|
|
308
385
|
the sender/receiver
|
|
309
386
|
*/
|
|
310
|
-
|
|
311
|
-
|
|
387
|
+
new Map(JSON.parse(data))
|
|
388
|
+
);
|
|
312
389
|
}
|
|
313
390
|
|
|
314
391
|
getTransceivers(): RTCRtpTransceiver[] {
|
|
@@ -330,7 +407,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
330
407
|
// transceivers have to be stopped
|
|
331
408
|
this._transceivers.forEach(({ transceiver })=> {
|
|
332
409
|
transceiver.stop();
|
|
333
|
-
})
|
|
410
|
+
});
|
|
334
411
|
WebRTCModule.peerConnectionClose(this._peerConnectionId);
|
|
335
412
|
}
|
|
336
413
|
|
|
@@ -339,46 +416,59 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
339
416
|
}
|
|
340
417
|
|
|
341
418
|
_registerEvents(): void {
|
|
342
|
-
addListener(this, 'peerConnectionOnRenegotiationNeeded', ev => {
|
|
419
|
+
addListener(this, 'peerConnectionOnRenegotiationNeeded', (ev: any) => {
|
|
343
420
|
if (ev.id !== this._peerConnectionId) {
|
|
344
421
|
return;
|
|
345
422
|
}
|
|
423
|
+
|
|
346
424
|
// @ts-ignore
|
|
347
425
|
this.dispatchEvent(new RTCEvent('negotiationneeded'));
|
|
348
426
|
});
|
|
349
|
-
|
|
427
|
+
|
|
428
|
+
addListener(this, 'peerConnectionIceConnectionChanged', (ev: any) => {
|
|
350
429
|
if (ev.id !== this._peerConnectionId) {
|
|
351
430
|
return;
|
|
352
431
|
}
|
|
432
|
+
|
|
353
433
|
this.iceConnectionState = ev.iceConnectionState;
|
|
434
|
+
|
|
354
435
|
if (ev.iceConnectionState === 'closed') {
|
|
355
436
|
// This PeerConnection is done, clean up event handlers.
|
|
356
437
|
removeListener(this);
|
|
357
438
|
}
|
|
439
|
+
|
|
358
440
|
// @ts-ignore
|
|
359
441
|
this.dispatchEvent(new RTCEvent('iceconnectionstatechange'));
|
|
360
442
|
});
|
|
361
|
-
|
|
443
|
+
|
|
444
|
+
addListener(this, 'peerConnectionStateChanged', (ev: any) => {
|
|
362
445
|
if (ev.id !== this._peerConnectionId) {
|
|
363
446
|
return;
|
|
364
447
|
}
|
|
448
|
+
|
|
365
449
|
this.connectionState = ev.connectionState;
|
|
450
|
+
|
|
366
451
|
if (ev.connectionState === 'closed') {
|
|
367
452
|
// This PeerConnection is done, clean up event handlers.
|
|
368
453
|
removeListener(this);
|
|
369
454
|
}
|
|
455
|
+
|
|
370
456
|
// @ts-ignore
|
|
371
457
|
this.dispatchEvent(new RTCEvent('connectionstatechange'));
|
|
372
458
|
});
|
|
373
|
-
|
|
459
|
+
|
|
460
|
+
addListener(this, 'peerConnectionSignalingStateChanged', (ev: any) => {
|
|
374
461
|
if (ev.id !== this._peerConnectionId) {
|
|
375
462
|
return;
|
|
376
463
|
}
|
|
464
|
+
|
|
377
465
|
this.signalingState = ev.signalingState;
|
|
378
466
|
// @ts-ignore
|
|
379
467
|
this.dispatchEvent(new RTCEvent('signalingstatechange'));
|
|
380
|
-
})
|
|
381
|
-
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
// Consider moving away from this event: https://github.com/WebKit/WebKit/pull/3953
|
|
471
|
+
addListener(this, 'peerConnectionOnTrack', (ev: any) => {
|
|
382
472
|
if (ev.id !== this._peerConnectionId) {
|
|
383
473
|
return;
|
|
384
474
|
}
|
|
@@ -389,18 +479,16 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
389
479
|
let transceiver;
|
|
390
480
|
|
|
391
481
|
// Make sure transceivers are stored in timestamp order. Also, we have to make
|
|
392
|
-
// sure we do not add a transceiver if it exists.
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
let [{ transceiver: oldTransceiver } = { transceiver: null }] = this._transceivers.filter(({ transceiver }) => {
|
|
396
|
-
return transceiver.id === ev.transceiver.id;
|
|
397
|
-
});
|
|
482
|
+
// sure we do not add a transceiver if it exists.
|
|
483
|
+
const [ { transceiver: oldTransceiver } = { transceiver: null } ]
|
|
484
|
+
= this._transceivers.filter(({ transceiver }) => transceiver.id === ev.transceiver.id);
|
|
398
485
|
|
|
399
486
|
if (!oldTransceiver) {
|
|
400
487
|
// Creating objects out of the event data.
|
|
488
|
+
const sender = new RTCRtpSender({ ...ev.transceiver.sender });
|
|
401
489
|
const receiver = new RTCRtpReceiver({ ...ev.receiver, track });
|
|
402
490
|
|
|
403
|
-
transceiver = new RTCRtpTransceiver({ ...ev.transceiver, receiver });
|
|
491
|
+
transceiver = new RTCRtpTransceiver({ ...ev.transceiver, receiver, sender });
|
|
404
492
|
this._insertTransceiverSorted(ev.transceiverOrder, transceiver);
|
|
405
493
|
} else {
|
|
406
494
|
transceiver = oldTransceiver;
|
|
@@ -420,10 +508,14 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
420
508
|
streamReactTag: streamInfo.streamReactTag,
|
|
421
509
|
tracks: []
|
|
422
510
|
});
|
|
511
|
+
|
|
423
512
|
this._remoteStreams.set(streamInfo.streamId, stream);
|
|
424
513
|
}
|
|
514
|
+
|
|
425
515
|
const stream = this._remoteStreams.get(streamInfo.streamId);
|
|
516
|
+
|
|
426
517
|
stream?._tracks.push(track);
|
|
518
|
+
|
|
427
519
|
return stream;
|
|
428
520
|
});
|
|
429
521
|
|
|
@@ -438,7 +530,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
438
530
|
this.dispatchEvent(new RTCTrackEvent('track', eventData));
|
|
439
531
|
});
|
|
440
532
|
|
|
441
|
-
addListener(this, 'peerConnectionOnRemoveTrack', ev => {
|
|
533
|
+
addListener(this, 'peerConnectionOnRemoveTrack', (ev: any) => {
|
|
442
534
|
if (ev.peerConnectionId !== this._peerConnectionId) {
|
|
443
535
|
return;
|
|
444
536
|
}
|
|
@@ -447,22 +539,24 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
447
539
|
|
|
448
540
|
// Based on the W3C specs https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-removetrack,
|
|
449
541
|
// we need to remove the track from any media streams
|
|
450
|
-
// that were previously passed to the `track` event.
|
|
542
|
+
// that were previously passed to the `track` event.
|
|
451
543
|
for (const stream of this._remoteStreams.values()) {
|
|
452
544
|
const trackIdx = stream._tracks.findIndex(t => t.id === ev.trackId);
|
|
545
|
+
|
|
453
546
|
if (trackIdx !== -1) {
|
|
454
547
|
stream._tracks.splice(trackIdx, 1);
|
|
455
548
|
}
|
|
456
549
|
}
|
|
457
550
|
});
|
|
458
551
|
|
|
459
|
-
addListener(this, 'peerConnectionOnRemoveTrackSuccessful', ev => {
|
|
552
|
+
addListener(this, 'peerConnectionOnRemoveTrackSuccessful', (ev: any) => {
|
|
460
553
|
if (ev.peerConnectionId !== this._peerConnectionId) {
|
|
461
554
|
return;
|
|
462
555
|
}
|
|
463
|
-
|
|
556
|
+
|
|
557
|
+
const [ existingSender ] = this
|
|
464
558
|
.getSenders()
|
|
465
|
-
.filter(
|
|
559
|
+
.filter(s => s.id === ev.senderId);
|
|
466
560
|
|
|
467
561
|
const oldTrack = existingSender._track;
|
|
468
562
|
|
|
@@ -472,26 +566,30 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
472
566
|
|
|
473
567
|
existingSender._track = null;
|
|
474
568
|
|
|
475
|
-
const [existingTransceiver] = this
|
|
569
|
+
const [ existingTransceiver ] = this
|
|
476
570
|
.getTransceivers()
|
|
477
|
-
.filter(
|
|
571
|
+
.filter(t => t.sender.id === existingSender.id);
|
|
572
|
+
|
|
478
573
|
existingTransceiver._direction = existingTransceiver.direction === 'sendrecv' ? 'recvonly' : 'inactive';
|
|
479
574
|
});
|
|
480
575
|
|
|
481
|
-
addListener(this, 'peerConnectionGotICECandidate', ev => {
|
|
576
|
+
addListener(this, 'peerConnectionGotICECandidate', (ev: any) => {
|
|
482
577
|
if (ev.id !== this._peerConnectionId) {
|
|
483
578
|
return;
|
|
484
579
|
}
|
|
580
|
+
|
|
485
581
|
this.localDescription = new RTCSessionDescription(ev.sdp);
|
|
486
582
|
const candidate = new RTCIceCandidate(ev.candidate);
|
|
583
|
+
|
|
487
584
|
// @ts-ignore
|
|
488
585
|
this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', { candidate }));
|
|
489
586
|
});
|
|
490
587
|
|
|
491
|
-
addListener(this, 'peerConnectionIceGatheringChanged', ev => {
|
|
588
|
+
addListener(this, 'peerConnectionIceGatheringChanged', (ev: any) => {
|
|
492
589
|
if (ev.id !== this._peerConnectionId) {
|
|
493
590
|
return;
|
|
494
591
|
}
|
|
592
|
+
|
|
495
593
|
this.iceGatheringState = ev.iceGatheringState;
|
|
496
594
|
|
|
497
595
|
if (this.iceGatheringState === 'complete') {
|
|
@@ -504,11 +602,13 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
504
602
|
this.dispatchEvent(new RTCEvent('icegatheringstatechange'));
|
|
505
603
|
});
|
|
506
604
|
|
|
507
|
-
addListener(this, 'peerConnectionDidOpenDataChannel', ev => {
|
|
605
|
+
addListener(this, 'peerConnectionDidOpenDataChannel', (ev: any) => {
|
|
508
606
|
if (ev.id !== this._peerConnectionId) {
|
|
509
607
|
return;
|
|
510
608
|
}
|
|
609
|
+
|
|
511
610
|
const channel = new RTCDataChannel(ev.dataChannel);
|
|
611
|
+
|
|
512
612
|
// @ts-ignore
|
|
513
613
|
this.dispatchEvent(new RTCDataChannelEvent('datachannel', { channel }));
|
|
514
614
|
});
|
|
@@ -517,16 +617,34 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
517
617
|
// Asynchronously when the outer web API expects synchronous behaviour
|
|
518
618
|
// This is the only way to report error on operations for those who wish
|
|
519
619
|
// to handle them.
|
|
520
|
-
addListener(this, 'peerConnectionOnError', ev => {
|
|
620
|
+
addListener(this, 'peerConnectionOnError', (ev: any) => {
|
|
521
621
|
if (ev.info.peerConnectionId !== this._peerConnectionId) {
|
|
522
622
|
return;
|
|
523
623
|
}
|
|
524
|
-
|
|
624
|
+
|
|
525
625
|
log.error(`onerror: ${JSON.stringify(ev)}`);
|
|
526
626
|
|
|
527
627
|
// @ts-ignore
|
|
528
628
|
this.dispatchEvent(new RTCErrorEvent('error', ev.func, ev.message));
|
|
529
629
|
});
|
|
630
|
+
|
|
631
|
+
addListener(this, 'mediaStreamTrackMuteChanged', (ev: any) => {
|
|
632
|
+
if (ev.peerConnectionId !== this._peerConnectionId) {
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
const [
|
|
637
|
+
track
|
|
638
|
+
] = this.getReceivers().map(r => r.track).filter(t => t?.id === ev.trackId);
|
|
639
|
+
|
|
640
|
+
if (track) {
|
|
641
|
+
track._muted = ev.muted;
|
|
642
|
+
const eventName = ev.muted ? 'mute' : 'unmute';
|
|
643
|
+
|
|
644
|
+
// @ts-ignore
|
|
645
|
+
track.dispatchEvent(new MediaStreamTrackEvent(eventName, { track }));
|
|
646
|
+
}
|
|
647
|
+
});
|
|
530
648
|
}
|
|
531
649
|
|
|
532
650
|
/**
|
|
@@ -543,6 +661,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
543
661
|
createDataChannel(label: string, dataChannelDict?: RTCDataChannelInit): RTCDataChannel {
|
|
544
662
|
if (dataChannelDict && 'id' in dataChannelDict) {
|
|
545
663
|
const id = dataChannelDict.id;
|
|
664
|
+
|
|
546
665
|
if (typeof id !== 'number') {
|
|
547
666
|
throw new TypeError('DataChannel id must be a number: ' + id);
|
|
548
667
|
}
|
|
@@ -556,17 +675,18 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
556
675
|
|
|
557
676
|
return new RTCDataChannel(channelInfo);
|
|
558
677
|
}
|
|
559
|
-
|
|
678
|
+
|
|
560
679
|
/**
|
|
561
|
-
* Check whether a media stream track exists already in a sender.
|
|
680
|
+
* Check whether a media stream track exists already in a sender.
|
|
562
681
|
* See https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack for more information
|
|
563
682
|
*/
|
|
564
683
|
_trackExists(track: MediaStreamTrack): boolean {
|
|
565
|
-
const [sender] = this
|
|
684
|
+
const [ sender ] = this
|
|
566
685
|
.getSenders()
|
|
567
686
|
.filter(
|
|
568
|
-
|
|
569
|
-
)
|
|
687
|
+
sender => sender.track?.id === track.id
|
|
688
|
+
);
|
|
689
|
+
|
|
570
690
|
return sender? true : false;
|
|
571
691
|
}
|
|
572
692
|
|
|
@@ -574,12 +694,15 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
574
694
|
* updates transceivers after offer/answer updates if necessary
|
|
575
695
|
*/
|
|
576
696
|
_updateTransceivers(transceiverUpdates) {
|
|
577
|
-
for (
|
|
578
|
-
const [transceiver] = this
|
|
697
|
+
for (const update of transceiverUpdates) {
|
|
698
|
+
const [ transceiver ] = this
|
|
579
699
|
.getTransceivers()
|
|
580
|
-
.filter(
|
|
581
|
-
|
|
582
|
-
if (!transceiver)
|
|
700
|
+
.filter(t => t.id === update.transceiverId);
|
|
701
|
+
|
|
702
|
+
if (!transceiver) {
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
|
|
583
706
|
transceiver._currentDirection = update.currentDirection;
|
|
584
707
|
transceiver._mid = update.mid;
|
|
585
708
|
transceiver._sender._rtpParameters = new RTCRtpSendParameters(update.senderRtpParameters);
|
|
@@ -593,8 +716,6 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
593
716
|
*/
|
|
594
717
|
_insertTransceiverSorted(order: number, transceiver: RTCRtpTransceiver) {
|
|
595
718
|
this._transceivers.push({ order, transceiver });
|
|
596
|
-
this._transceivers.sort((a, b) =>
|
|
597
|
-
return a.order - b.order;
|
|
598
|
-
})
|
|
719
|
+
this._transceivers.sort((a, b) => a.order - b.order);
|
|
599
720
|
}
|
|
600
721
|
}
|
package/src/RTCRtcpParameters.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
|
|
2
2
|
export default class RTCRtcpParameters {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
readonly cname: string;
|
|
4
|
+
readonly reducedSize: boolean;
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
constructor(init: {
|
|
7
7
|
cname: string,
|
|
8
8
|
reducedSize: boolean
|
|
9
9
|
}) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
this.cname = init.cname;
|
|
11
|
+
this.reducedSize = init.reducedSize;
|
|
12
|
+
Object.freeze(this);
|
|
13
|
+
}
|
|
14
14
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {NativeModules} from 'react-native';
|
|
1
|
+
import { NativeModules } from 'react-native';
|
|
2
|
+
|
|
2
3
|
import RTCRtpCodecCapability from './RTCRtpCodecCapability';
|
|
3
4
|
const { WebRTCModule } = NativeModules;
|
|
4
5
|
|
|
@@ -13,7 +14,7 @@ export default class RTCRtpCapabilities {
|
|
|
13
14
|
this._codecs = codecs;
|
|
14
15
|
Object.freeze(this);
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
|
|
17
18
|
get codecs() {
|
|
18
19
|
return this._codecs;
|
|
19
20
|
}
|
|
@@ -24,14 +25,24 @@ function getCapabilities(endpoint: 'sender' | 'receiver'): RTCRtpCapabilities |
|
|
|
24
25
|
switch (endpoint) {
|
|
25
26
|
case 'sender': {
|
|
26
27
|
const capabilities = WebRTCModule.senderGetCapabilities();
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
if (!capabilities) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
28
33
|
return new RTCRtpCapabilities(capabilities.codecs);
|
|
29
34
|
}
|
|
35
|
+
|
|
30
36
|
case 'receiver': {
|
|
31
37
|
const capabilities = WebRTCModule.receiverGetCapabilities();
|
|
32
|
-
|
|
38
|
+
|
|
39
|
+
if (!capabilities) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
return new RTCRtpCapabilities(capabilities.codecs);
|
|
34
44
|
}
|
|
45
|
+
|
|
35
46
|
default:
|
|
36
47
|
throw new TypeError('Invalid endpoint: ' + endpoint);
|
|
37
48
|
}
|