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