react-native-webrtc 106.0.0-beta.2 → 106.0.0-beta.4

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