react-native-webrtc 1.94.1 → 1.100.0

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 (157) hide show
  1. package/README.md +2 -2
  2. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +21 -3
  3. package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +1 -1
  4. package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +17 -21
  5. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +3 -0
  6. package/ios/RCTWebRTC/RCTConvert+WebRTC.m +3 -0
  7. package/ios/RCTWebRTC/ScreenCapturer.m +1 -0
  8. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +1 -1
  9. package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.h +1 -1
  10. package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.m +3 -9
  11. package/lib/commonjs/EventEmitter.js +16 -0
  12. package/lib/commonjs/EventEmitter.js.map +1 -0
  13. package/lib/commonjs/MediaDevices.js +61 -0
  14. package/lib/commonjs/MediaDevices.js.map +1 -0
  15. package/lib/commonjs/MediaStream.js +158 -0
  16. package/lib/commonjs/MediaStream.js.map +1 -0
  17. package/lib/commonjs/MediaStreamError.js +26 -0
  18. package/lib/commonjs/MediaStreamError.js.map +1 -0
  19. package/lib/commonjs/MediaStreamErrorEvent.js +23 -0
  20. package/lib/commonjs/MediaStreamErrorEvent.js.map +1 -0
  21. package/lib/commonjs/MediaStreamEvent.js +23 -0
  22. package/lib/commonjs/MediaStreamEvent.js.map +1 -0
  23. package/lib/commonjs/MediaStreamTrack.js +127 -0
  24. package/lib/commonjs/MediaStreamTrack.js.map +1 -0
  25. package/lib/commonjs/MediaStreamTrackEvent.js +23 -0
  26. package/lib/commonjs/MediaStreamTrackEvent.js.map +1 -0
  27. package/lib/commonjs/MessageEvent.js +23 -0
  28. package/lib/commonjs/MessageEvent.js.map +1 -0
  29. package/lib/commonjs/Permissions.js +125 -0
  30. package/lib/commonjs/Permissions.js.map +1 -0
  31. package/lib/commonjs/RTCDataChannel.js +198 -0
  32. package/lib/commonjs/RTCDataChannel.js.map +1 -0
  33. package/lib/commonjs/RTCDataChannelEvent.js +23 -0
  34. package/lib/commonjs/RTCDataChannelEvent.js.map +1 -0
  35. package/lib/commonjs/RTCEvent.js +20 -0
  36. package/lib/commonjs/RTCEvent.js.map +1 -0
  37. package/lib/commonjs/RTCIceCandidate.js +34 -0
  38. package/lib/commonjs/RTCIceCandidate.js.map +1 -0
  39. package/lib/commonjs/RTCIceCandidateEvent.js +25 -0
  40. package/lib/commonjs/RTCIceCandidateEvent.js.map +1 -0
  41. package/lib/commonjs/RTCPeerConnection.js +371 -0
  42. package/lib/commonjs/RTCPeerConnection.js.map +1 -0
  43. package/lib/commonjs/RTCSessionDescription.js +43 -0
  44. package/lib/commonjs/RTCSessionDescription.js.map +1 -0
  45. package/lib/commonjs/RTCUtil.js +218 -0
  46. package/lib/commonjs/RTCUtil.js.map +1 -0
  47. package/lib/commonjs/RTCView.js +68 -0
  48. package/lib/commonjs/RTCView.js.map +1 -0
  49. package/lib/commonjs/ScreenCapturePickerView.js +13 -0
  50. package/lib/commonjs/ScreenCapturePickerView.js.map +1 -0
  51. package/lib/commonjs/getDisplayMedia.js +39 -0
  52. package/lib/commonjs/getDisplayMedia.js.map +1 -0
  53. package/lib/commonjs/getUserMedia.js +122 -0
  54. package/lib/commonjs/getUserMedia.js.map +1 -0
  55. package/lib/commonjs/index.js +101 -0
  56. package/lib/commonjs/index.js.map +1 -0
  57. package/lib/commonjs/typings.d.js +2 -0
  58. package/lib/commonjs/typings.d.js.map +1 -0
  59. package/lib/module/EventEmitter.js +7 -0
  60. package/lib/module/EventEmitter.js.map +1 -0
  61. package/lib/module/MediaDevices.js +46 -0
  62. package/lib/module/MediaDevices.js.map +1 -0
  63. package/lib/module/MediaStream.js +142 -0
  64. package/lib/module/MediaStream.js.map +1 -0
  65. package/lib/module/MediaStreamError.js +17 -0
  66. package/lib/module/MediaStreamError.js.map +1 -0
  67. package/lib/module/MediaStreamErrorEvent.js +14 -0
  68. package/lib/module/MediaStreamErrorEvent.js.map +1 -0
  69. package/lib/module/MediaStreamEvent.js +14 -0
  70. package/lib/module/MediaStreamEvent.js.map +1 -0
  71. package/lib/module/MediaStreamTrack.js +116 -0
  72. package/lib/module/MediaStreamTrack.js.map +1 -0
  73. package/lib/module/MediaStreamTrackEvent.js +14 -0
  74. package/lib/module/MediaStreamTrackEvent.js.map +1 -0
  75. package/lib/module/MessageEvent.js +14 -0
  76. package/lib/module/MessageEvent.js.map +1 -0
  77. package/lib/module/Permissions.js +115 -0
  78. package/lib/module/Permissions.js.map +1 -0
  79. package/lib/module/RTCDataChannel.js +176 -0
  80. package/lib/module/RTCDataChannel.js.map +1 -0
  81. package/lib/module/RTCDataChannelEvent.js +14 -0
  82. package/lib/module/RTCDataChannelEvent.js.map +1 -0
  83. package/lib/module/RTCEvent.js +11 -0
  84. package/lib/module/RTCEvent.js.map +1 -0
  85. package/lib/module/RTCIceCandidate.js +25 -0
  86. package/lib/module/RTCIceCandidate.js.map +1 -0
  87. package/lib/module/RTCIceCandidateEvent.js +16 -0
  88. package/lib/module/RTCIceCandidateEvent.js.map +1 -0
  89. package/lib/module/RTCPeerConnection.js +342 -0
  90. package/lib/module/RTCPeerConnection.js.map +1 -0
  91. package/lib/module/RTCSessionDescription.js +34 -0
  92. package/lib/module/RTCSessionDescription.js.map +1 -0
  93. package/lib/module/RTCUtil.js +207 -0
  94. package/lib/module/RTCUtil.js.map +1 -0
  95. package/lib/module/RTCView.js +59 -0
  96. package/lib/module/RTCView.js.map +1 -0
  97. package/lib/module/ScreenCapturePickerView.js +3 -0
  98. package/lib/module/ScreenCapturePickerView.js.map +1 -0
  99. package/lib/module/getDisplayMedia.js +26 -0
  100. package/lib/module/getDisplayMedia.js.map +1 -0
  101. package/lib/module/getUserMedia.js +103 -0
  102. package/lib/module/getUserMedia.js.map +1 -0
  103. package/lib/module/index.js +31 -0
  104. package/lib/module/index.js.map +1 -0
  105. package/lib/module/typings.d.js +2 -0
  106. package/lib/module/typings.d.js.map +1 -0
  107. package/lib/typescript/EventEmitter.d.ts +3 -0
  108. package/lib/typescript/MediaDevices.d.ts +27 -0
  109. package/lib/typescript/MediaStream.d.ts +39 -0
  110. package/lib/typescript/MediaStreamError.d.ts +6 -0
  111. package/lib/typescript/MediaStreamErrorEvent.d.ts +6 -0
  112. package/lib/typescript/MediaStreamEvent.d.ts +8 -0
  113. package/lib/typescript/MediaStreamTrack.d.ts +34 -0
  114. package/lib/typescript/MediaStreamTrackEvent.d.ts +8 -0
  115. package/lib/typescript/MessageEvent.d.ts +9 -0
  116. package/lib/typescript/Permissions.d.ts +55 -0
  117. package/lib/typescript/RTCDataChannel.d.ts +33 -0
  118. package/lib/typescript/RTCDataChannelEvent.d.ts +8 -0
  119. package/lib/typescript/RTCEvent.d.ts +4 -0
  120. package/lib/typescript/RTCIceCandidate.d.ts +11 -0
  121. package/lib/typescript/RTCIceCandidateEvent.d.ts +6 -0
  122. package/lib/typescript/RTCPeerConnection.d.ts +58 -0
  123. package/lib/typescript/RTCSessionDescription.d.ts +14 -0
  124. package/lib/typescript/RTCUtil.d.ts +28 -0
  125. package/lib/typescript/RTCView.d.ts +53 -0
  126. package/lib/typescript/ScreenCapturePickerView.d.ts +2 -0
  127. package/lib/typescript/getDisplayMedia.d.ts +1 -0
  128. package/lib/typescript/getUserMedia.d.ts +6 -0
  129. package/lib/typescript/index.d.ts +11 -0
  130. package/package.json +25 -10
  131. package/src/{EventEmitter.js → EventEmitter.ts} +0 -0
  132. package/src/{MediaDevices.js → MediaDevices.ts} +2 -3
  133. package/src/{MediaStream.js → MediaStream.ts} +3 -3
  134. package/src/{MediaStreamError.js → MediaStreamError.ts} +2 -2
  135. package/src/{MediaStreamErrorEvent.js → MediaStreamErrorEvent.ts} +1 -1
  136. package/src/{MediaStreamEvent.js → MediaStreamEvent.ts} +2 -2
  137. package/src/{MediaStreamTrack.js → MediaStreamTrack.ts} +9 -7
  138. package/src/{MediaStreamTrackEvent.js → MediaStreamTrackEvent.ts} +2 -2
  139. package/src/MessageEvent.ts +11 -0
  140. package/src/{Permissions.js → Permissions.ts} +6 -6
  141. package/src/{RTCDataChannel.js → RTCDataChannel.ts} +12 -8
  142. package/src/{RTCDataChannelEvent.js → RTCDataChannelEvent.ts} +2 -2
  143. package/src/{RTCEvent.js → RTCEvent.ts} +1 -2
  144. package/src/{RTCIceCandidate.js → RTCIceCandidate.ts} +0 -0
  145. package/src/{RTCIceCandidateEvent.js → RTCIceCandidateEvent.ts} +2 -6
  146. package/src/{RTCPeerConnection.js → RTCPeerConnection.ts} +28 -19
  147. package/src/{RTCSessionDescription.js → RTCSessionDescription.ts} +6 -3
  148. package/src/{RTCUtil.js → RTCUtil.ts} +26 -1
  149. package/src/{RTCView.js → RTCView.ts} +0 -0
  150. package/src/{ScreenCapturePickerView.js → ScreenCapturePickerView.ts} +0 -0
  151. package/src/{getDisplayMedia.js → getDisplayMedia.ts} +0 -0
  152. package/src/{getUserMedia.js → getUserMedia.ts} +7 -2
  153. package/src/{index.js → index.ts} +6 -7
  154. package/src/typings.d.ts +1 -0
  155. package/tools/build-webrtc.py +25 -19
  156. package/tsconfig.json +14 -0
  157. package/src/MessageEvent.js +0 -10
@@ -1,5 +1,5 @@
1
1
 
2
- import { NativeModules, PermissionsAndroid, Platform } from 'react-native';
2
+ import { NativeModules, Permission, PermissionsAndroid, Platform } from 'react-native';
3
3
 
4
4
  const { WebRTCModule } = NativeModules;
5
5
 
@@ -7,7 +7,7 @@ const { WebRTCModule } = NativeModules;
7
7
  * Type declaration for a permissions descriptor.
8
8
  */
9
9
  type PermissionDescriptor = {
10
- name: string
10
+ name: string;
11
11
  };
12
12
 
13
13
  /**
@@ -31,7 +31,7 @@ class Permissions {
31
31
  */
32
32
  VALID_PERMISSIONS = ['camera', 'microphone'];
33
33
 
34
- _lastReq = Promise.resolve();
34
+ _lastReq: Promise<any> = Promise.resolve();
35
35
 
36
36
  /**
37
37
  * Helper for requesting Android permissions. On Android only one permission
@@ -39,14 +39,14 @@ class Permissions {
39
39
  * but we are not using that for symmetry with the W3C API for querying)
40
40
  * so we'll queue them up.
41
41
  *
42
- * @param {string} perm - The requested permission from
42
+ * @param perm - The requested permission from
43
43
  * {@link PermissionsAndroid.PERMISSIONS}
44
44
  * https://facebook.github.io/react-native/docs/permissionsandroid#permissions-that-require-prompting-the-user
45
45
  */
46
- _requestPermissionAndroid(perm) {
46
+ _requestPermissionAndroid(perm: Permission) {
47
47
  return new Promise((resolve, reject) => {
48
48
  PermissionsAndroid.request(perm).then(
49
- granted => resolve(granted === true || granted === PermissionsAndroid.RESULTS.GRANTED),
49
+ granted => resolve(granted === PermissionsAndroid.RESULTS.GRANTED),
50
50
  () => resolve(false)
51
51
  );
52
52
  });
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { NativeModules } from 'react-native';
3
- import base64 from 'base64-js';
3
+ import * as base64 from 'base64-js';
4
4
  import { defineCustomEventTarget } from 'event-target-shim';
5
5
  import MessageEvent from './MessageEvent';
6
6
  import RTCDataChannelEvent from './RTCDataChannelEvent';
@@ -15,17 +15,17 @@ const DATA_CHANNEL_EVENTS = ['open', 'message', 'bufferedamountlow', 'closing',
15
15
  export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHANNEL_EVENTS) {
16
16
  _peerConnectionId: number;
17
17
  _reactTag: string;
18
-
19
18
  _id: number;
20
19
  _label: string;
21
- _maxPacketLifeTime: ?number;
22
- _maxRetransmits: ?number;
20
+ _maxPacketLifeTime?: number;
21
+ _maxRetransmits?: number;
23
22
  _negotiated: boolean;
24
23
  _ordered: boolean;
25
24
  _protocol: string;
26
25
  _readyState: RTCDataChannelState;
26
+ _subscriptions: Array<any> = [];
27
27
 
28
- binaryType: 'arraybuffer' = 'arraybuffer'; // we only support 'arraybuffer'
28
+ binaryType: string = 'arraybuffer'; // we only support 'arraybuffer'
29
29
  bufferedAmount: number = 0;
30
30
  bufferedAmountLowThreshold: number = 0;
31
31
 
@@ -59,11 +59,11 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
59
59
  return this._ordered;
60
60
  }
61
61
 
62
- get maxPacketLifeTime(): number {
62
+ get maxPacketLifeTime(): number | undefined {
63
63
  return this._maxPacketLifeTime;
64
64
  }
65
65
 
66
- get maxRetransmits(): number {
66
+ get maxRetransmits(): number | undefined {
67
67
  return this._maxRetransmits;
68
68
  }
69
69
 
@@ -93,7 +93,7 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
93
93
  } else {
94
94
  throw new TypeError('Data must be either string, ArrayBuffer, or ArrayBufferView');
95
95
  }
96
- WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, base64.fromByteArray(data), 'binary');
96
+ WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, base64.fromByteArray(data as Uint8Array), 'binary');
97
97
  }
98
98
 
99
99
  close() {
@@ -119,10 +119,13 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
119
119
  this._id = ev.id;
120
120
  }
121
121
  if (this._readyState === 'open') {
122
+ // @ts-ignore
122
123
  this.dispatchEvent(new RTCDataChannelEvent('open', { channel: this }));
123
124
  } else if (this._readyState === 'closing') {
125
+ // @ts-ignore
124
126
  this.dispatchEvent(new RTCDataChannelEvent('closing', { channel: this }));
125
127
  } else if (this._readyState === 'closed') {
128
+ // @ts-ignore
126
129
  this.dispatchEvent(new RTCDataChannelEvent('close', { channel: this }));
127
130
  this._unregisterEvents();
128
131
  WebRTCModule.dataChannelDispose(this._peerConnectionId, this._reactTag);
@@ -136,6 +139,7 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
136
139
  if (ev.type === 'binary') {
137
140
  data = base64.toByteArray(ev.data).buffer;
138
141
  }
142
+ // @ts-ignore
139
143
  this.dispatchEvent(new MessageEvent('message', { data }));
140
144
  })
141
145
  ];
@@ -4,8 +4,8 @@ import type RTCDataChannel from './RTCDataChannel';
4
4
  export default class RTCDataChannelEvent {
5
5
  type: string;
6
6
  channel: RTCDataChannel;
7
- constructor(type, eventInitDict) {
7
+ constructor(type, eventInitDict: { channel: RTCDataChannel }) {
8
8
  this.type = type.toString();
9
- Object.assign(this, eventInitDict);
9
+ this.channel = eventInitDict.channel;
10
10
  }
11
11
  }
@@ -1,8 +1,7 @@
1
1
 
2
2
  export default class RTCEvent {
3
3
  type: string;
4
- constructor(type, eventInitDict) {
4
+ constructor(type) {
5
5
  this.type = type.toString();
6
- Object.assign(this, eventInitDict);
7
6
  }
8
7
  }
File without changes
@@ -3,13 +3,9 @@ import type RTCIceCandidate from './RTCIceCandidate';
3
3
 
4
4
  export default class RTCIceCandidateEvent {
5
5
  type: string;
6
- candidate: RTCIceCandidate;
6
+ candidate: RTCIceCandidate | null;
7
7
  constructor(type, eventInitDict) {
8
8
  this.type = type.toString();
9
-
10
- this.candidate = null;
11
- if (eventInitDict && eventInitDict.candidate) {
12
- this.candidate = eventInitDict.candidate;
13
- }
9
+ this.candidate = eventInitDict?.candidate ?? null;
14
10
  }
15
11
  }
@@ -4,7 +4,6 @@ import { NativeModules } from 'react-native';
4
4
 
5
5
  import MediaStream from './MediaStream';
6
6
  import MediaStreamEvent from './MediaStreamEvent';
7
- import MediaStreamTrack from './MediaStreamTrack';
8
7
  import MediaStreamTrackEvent from './MediaStreamTrackEvent';
9
8
  import RTCDataChannel from './RTCDataChannel';
10
9
  import RTCDataChannelEvent from './RTCDataChannelEvent';
@@ -56,8 +55,8 @@ const PEER_CONNECTION_EVENTS = [
56
55
  let nextPeerConnectionId = 0;
57
56
 
58
57
  export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_CONNECTION_EVENTS) {
59
- localDescription: RTCSessionDescription;
60
- remoteDescription: RTCSessionDescription;
58
+ localDescription: RTCSessionDescription | null = null;
59
+ remoteDescription: RTCSessionDescription | null = null;
61
60
 
62
61
  signalingState: RTCSignalingState = 'stable';
63
62
  iceGatheringState: RTCIceGatheringState = 'new';
@@ -67,7 +66,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
67
66
  _peerConnectionId: number;
68
67
  _localStreams: Array<MediaStream> = [];
69
68
  _remoteStreams: Array<MediaStream> = [];
70
- _subscriptions: Array<any>;
69
+ _subscriptions: Array<any> = [];
71
70
 
72
71
  constructor(configuration) {
73
72
  super();
@@ -130,7 +129,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
130
129
  WebRTCModule.peerConnectionSetConfiguration(configuration, this._peerConnectionId);
131
130
  }
132
131
 
133
- async setLocalDescription(sessionDescription: ?RTCSessionDescription) {
132
+ async setLocalDescription(sessionDescription?: RTCSessionDescription): Promise<void> {
134
133
  const desc = sessionDescription
135
134
  ? sessionDescription.toJSON
136
135
  ? sessionDescription.toJSON()
@@ -141,7 +140,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
141
140
  this.localDescription = new RTCSessionDescription(newSdp);
142
141
  }
143
142
 
144
- setRemoteDescription(sessionDescription: RTCSessionDescription) {
143
+ setRemoteDescription(sessionDescription: RTCSessionDescription): Promise<void> {
145
144
  return new Promise((resolve, reject) => {
146
145
  WebRTCModule.peerConnectionSetRemoteDescription(
147
146
  sessionDescription.toJSON ? sessionDescription.toJSON() : sessionDescription,
@@ -158,7 +157,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
158
157
  });
159
158
  }
160
159
 
161
- async addIceCandidate(candidate) {
160
+ async addIceCandidate(candidate): Promise<void> {
162
161
  if (!candidate || !candidate.candidate) {
163
162
  // XXX end-of cantidates is not implemented: https://bugs.chromium.org/p/webrtc/issues/detail?id=9218
164
163
  return;
@@ -205,12 +204,6 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
205
204
  WebRTCModule.peerConnectionRestartIce(this._peerConnectionId);
206
205
  }
207
206
 
208
- _getTrack(streamReactTag, trackId): MediaStreamTrack {
209
- const stream = this._remoteStreams.find(stream => stream._reactTag === streamReactTag);
210
-
211
- return stream && stream._tracks.find(track => track.id === trackId);
212
- }
213
-
214
207
  _unregisterEvents(): void {
215
208
  this._subscriptions.forEach(e => e.remove());
216
209
  this._subscriptions = [];
@@ -222,6 +215,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
222
215
  if (ev.id !== this._peerConnectionId) {
223
216
  return;
224
217
  }
218
+ // @ts-ignore
225
219
  this.dispatchEvent(new RTCEvent('negotiationneeded'));
226
220
  }),
227
221
  EventEmitter.addListener('peerConnectionIceConnectionChanged', ev => {
@@ -229,6 +223,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
229
223
  return;
230
224
  }
231
225
  this.iceConnectionState = ev.iceConnectionState;
226
+ // @ts-ignore
232
227
  this.dispatchEvent(new RTCEvent('iceconnectionstatechange'));
233
228
  if (ev.iceConnectionState === 'closed') {
234
229
  // This PeerConnection is done, clean up event handlers.
@@ -240,6 +235,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
240
235
  return;
241
236
  }
242
237
  this.connectionState = ev.connectionState;
238
+ // @ts-ignore
243
239
  this.dispatchEvent(new RTCEvent('connectionstatechange'));
244
240
  if (ev.connectionState === 'closed') {
245
241
  // This PeerConnection is done, clean up event handlers.
@@ -251,6 +247,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
251
247
  return;
252
248
  }
253
249
  this.signalingState = ev.signalingState;
250
+ // @ts-ignore
254
251
  this.dispatchEvent(new RTCEvent('signalingstatechange'));
255
252
  }),
256
253
  EventEmitter.addListener('peerConnectionAddedStream', ev => {
@@ -260,6 +257,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
260
257
  const stream = new MediaStream(ev);
261
258
  this._remoteStreams.push(stream);
262
259
  this.remoteDescription = new RTCSessionDescription(ev.sdp);
260
+ // @ts-ignore
263
261
  this.dispatchEvent(new MediaStreamEvent('addstream', { stream }));
264
262
  }),
265
263
  EventEmitter.addListener('peerConnectionRemovedStream', ev => {
@@ -274,15 +272,23 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
274
272
  }
275
273
  }
276
274
  this.remoteDescription = new RTCSessionDescription(ev.sdp);
275
+ // @ts-ignore
277
276
  this.dispatchEvent(new MediaStreamEvent('removestream', { stream }));
278
277
  }),
279
278
  EventEmitter.addListener('mediaStreamTrackMuteChanged', ev => {
280
279
  if (ev.peerConnectionId !== this._peerConnectionId) {
281
280
  return;
282
281
  }
283
- const track = this._getTrack(ev.streamReactTag, ev.trackId);
282
+ let track;
283
+ for (const stream of this._remoteStreams) {
284
+ const t = stream._tracks.find(track => track.id === ev.trackId);
285
+ if (t) {
286
+ track = t;
287
+ break;
288
+ }
289
+ }
284
290
  if (track) {
285
- track.muted = ev.muted;
291
+ track._muted = ev.muted;
286
292
  const eventName = ev.muted ? 'mute' : 'unmute';
287
293
  track.dispatchEvent(new MediaStreamTrackEvent(eventName, { track }));
288
294
  }
@@ -293,8 +299,8 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
293
299
  }
294
300
  this.localDescription = new RTCSessionDescription(ev.sdp);
295
301
  const candidate = new RTCIceCandidate(ev.candidate);
296
- const event = new RTCIceCandidateEvent('icecandidate', { candidate });
297
- this.dispatchEvent(event);
302
+ // @ts-ignore
303
+ this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', { candidate }));
298
304
  }),
299
305
  EventEmitter.addListener('peerConnectionIceGatheringChanged', ev => {
300
306
  if (ev.id !== this._peerConnectionId) {
@@ -304,9 +310,11 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
304
310
 
305
311
  if (this.iceGatheringState === 'complete') {
306
312
  this.localDescription = new RTCSessionDescription(ev.sdp);
307
- this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', null));
313
+ // @ts-ignore
314
+ this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', { candidate: null }));
308
315
  }
309
316
 
317
+ // @ts-ignore
310
318
  this.dispatchEvent(new RTCEvent('icegatheringstatechange'));
311
319
  }),
312
320
  EventEmitter.addListener('peerConnectionDidOpenDataChannel', ev => {
@@ -314,6 +322,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
314
322
  return;
315
323
  }
316
324
  const channel = new RTCDataChannel(ev.dataChannel);
325
+ // @ts-ignore
317
326
  this.dispatchEvent(new RTCDataChannelEvent('datachannel', { channel }));
318
327
  })
319
328
  ];
@@ -330,7 +339,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
330
339
  * values with which to initialize corresponding attributes of the new
331
340
  * instance such as id
332
341
  */
333
- createDataChannel(label: string, dataChannelDict: ?RTCDataChannelInit) {
342
+ createDataChannel(label: string, dataChannelDict?: RTCDataChannelInit) {
334
343
  if (dataChannelDict && 'id' in dataChannelDict) {
335
344
  const id = dataChannelDict.id;
336
345
  if (typeof id !== 'number') {
@@ -1,7 +1,7 @@
1
1
 
2
2
  export default class RTCSessionDescription {
3
- sdp: string;
4
- type: string;
3
+ _sdp: string;
4
+ _type: string | null;
5
5
 
6
6
  constructor(info = { type: null, sdp: '' }) {
7
7
  this._sdp = info.sdp;
@@ -17,6 +17,9 @@ export default class RTCSessionDescription {
17
17
  }
18
18
 
19
19
  toJSON() {
20
- return { sdp: this._sdp, type: this._type };
20
+ return {
21
+ sdp: this._sdp,
22
+ type: this._type
23
+ };
21
24
  }
22
25
  }
@@ -112,6 +112,27 @@ function normalizeMediaConstraints(constraints, mediaType) {
112
112
  }
113
113
  }
114
114
 
115
+ /**
116
+ * Utility for creating short random strings from float point values.
117
+ * We take 4 characters from the end after converting to a string.
118
+ * Conversion to string gives us some letters as we don't want just numbers.
119
+ * Should be suitable to pass for enough randomness.
120
+ *
121
+ * @return {String} 4 random characters
122
+ */
123
+ function chr4() {
124
+ return Math.random().toString(16).slice(-4);
125
+ }
126
+
127
+ /**
128
+ * Put together a random string in UUIDv4 format {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
129
+ *
130
+ * @return {String} uuidv4
131
+ */
132
+ export function uniqueID() {
133
+ return `${chr4()}${chr4()}-${chr4()}-${chr4()}-${chr4()}-${chr4()}${chr4()}${chr4()}`;
134
+ }
135
+
115
136
  /**
116
137
  * Utility for deep cloning an object. Object.assign() only does a shallow copy.
117
138
  *
@@ -122,13 +143,17 @@ export function deepClone(obj) {
122
143
  return JSON.parse(JSON.stringify(obj));
123
144
  }
124
145
 
146
+ interface Constraints {
147
+ mandatory?: object;
148
+ }
149
+
125
150
  /**
126
151
  * Normalize options passed to createOffer() / createAnswer().
127
152
  *
128
153
  * @param {Object} options - user supplied options
129
154
  * @return {Object} newOptions - normalized options
130
155
  */
131
- export function normalizeOfferAnswerOptions(options = {}) {
156
+ export function normalizeOfferAnswerOptions(options: Constraints = {}) {
132
157
  const newOptions = {};
133
158
 
134
159
  if (!options) {
File without changes
File without changes
@@ -8,7 +8,12 @@ import permissions from './Permissions';
8
8
 
9
9
  const { WebRTCModule } = NativeModules;
10
10
 
11
- export default function getUserMedia(constraints = {}) {
11
+ interface Constraints {
12
+ audio?: boolean | object;
13
+ video?: boolean | object;
14
+ }
15
+
16
+ export default function getUserMedia(constraints: Constraints = {}) {
12
17
  // According to
13
18
  // https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia,
14
19
  // the constraints argument is a dictionary of type MediaStreamConstraints.
@@ -27,7 +32,7 @@ export default function getUserMedia(constraints = {}) {
27
32
  constraints = RTCUtil.normalizeConstraints(constraints);
28
33
 
29
34
  // Request required permissions
30
- const reqPermissions = [];
35
+ const reqPermissions: Array<Promise<boolean>> = [];
31
36
  if (constraints.audio) {
32
37
  reqPermissions.push(permissions.request({ name: 'microphone' }));
33
38
  } else {
@@ -1,4 +1,3 @@
1
-
2
1
  import ScreenCapturePickerView from './ScreenCapturePickerView';
3
2
  import RTCPeerConnection from './RTCPeerConnection';
4
3
  import RTCIceCandidate from './RTCIceCandidate';
@@ -24,17 +23,17 @@ export {
24
23
 
25
24
  function registerGlobals() {
26
25
  // Should not happen. React Native has a global navigator object.
27
- if (typeof navigator !== 'object') {
26
+ if (typeof global.navigator !== 'object') {
28
27
  throw new Error('navigator is not an object');
29
28
  }
30
29
 
31
- if (!navigator.mediaDevices) {
32
- navigator.mediaDevices = {};
30
+ if (!global.navigator.mediaDevices) {
31
+ global.navigator.mediaDevices = {};
33
32
  }
34
33
 
35
- navigator.mediaDevices.getUserMedia = mediaDevices.getUserMedia.bind(mediaDevices);
36
- navigator.mediaDevices.getDisplayMedia = mediaDevices.getDisplayMedia.bind(mediaDevices);
37
- navigator.mediaDevices.enumerateDevices = mediaDevices.enumerateDevices.bind(mediaDevices);
34
+ global.navigator.mediaDevices.getUserMedia = mediaDevices.getUserMedia.bind(mediaDevices);
35
+ global.navigator.mediaDevices.getDisplayMedia = mediaDevices.getDisplayMedia.bind(mediaDevices);
36
+ global.navigator.mediaDevices.enumerateDevices = mediaDevices.enumerateDevices.bind(mediaDevices);
38
37
 
39
38
  global.RTCPeerConnection = RTCPeerConnection;
40
39
  global.RTCIceCandidate = RTCIceCandidate;
@@ -0,0 +1 @@
1
+ declare var global: any;
@@ -37,12 +37,18 @@ def build_gn_args(platform_args):
37
37
  GN_COMMON_ARGS = [
38
38
  'is_component_build=false',
39
39
  'rtc_libvpx_build_vp9=true',
40
+ 'rtc_build_dcsctp=true',
41
+ 'rtc_build_usrsctp=false',
42
+ 'rtc_enable_protobuf=false',
43
+ 'rtc_include_tests=false',
40
44
  'is_debug=%s',
41
45
  'target_cpu="%s"'
42
46
  ]
43
47
 
44
48
  _GN_APPLE_COMMON = [
45
- 'enable_dsyms=true',
49
+ 'enable_dsyms=false',
50
+ 'enable_stripping=true',
51
+ 'rtc_enable_symbol_export=false',
46
52
  'rtc_enable_objc_symbol_export=true',
47
53
  'rtc_include_tests=false'
48
54
  ]
@@ -51,15 +57,15 @@ _GN_IOS_ARGS = [
51
57
  'enable_ios_bitcode=true',
52
58
  'ios_deployment_target="12.0"',
53
59
  'ios_enable_code_signing=false',
60
+ 'use_lld=false',
61
+ 'use_custom_libcxx=false',
54
62
  'target_os="ios"',
55
- 'use_xcode_clang=true',
56
63
  'target_environment="%s"'
57
64
  ]
58
65
  GN_IOS_ARGS = build_gn_args(_GN_APPLE_COMMON + _GN_IOS_ARGS)
59
66
 
60
67
  _GN_MACOS_ARGS = [
61
- 'target_os="mac"',
62
- 'use_xcode_clang=false'
68
+ 'target_os="mac"'
63
69
  ]
64
70
  GN_MACOS_ARGS = build_gn_args(_GN_APPLE_COMMON + _GN_MACOS_ARGS)
65
71
 
@@ -188,11 +194,11 @@ def build(target_dir, platform, debug):
188
194
  gn_args = GN_IOS_ARGS % (str(debug).lower(), arch, tenv)
189
195
  gn_cmd = 'gn gen %s %s' % (gn_out_dir, gn_args)
190
196
  sh(gn_cmd, env)
191
- for arch in MACOS_BUILD_ARCHS:
192
- gn_out_dir = 'out/%s-macos-%s' % (build_type, arch)
193
- gn_args = GN_MACOS_ARGS % (str(debug).lower(), arch)
194
- gn_cmd = 'gn gen %s %s' % (gn_out_dir, gn_args)
195
- sh(gn_cmd, env)
197
+ #for arch in MACOS_BUILD_ARCHS:
198
+ # gn_out_dir = 'out/%s-macos-%s' % (build_type, arch)
199
+ # gn_args = GN_MACOS_ARGS % (str(debug).lower(), arch)
200
+ # gn_cmd = 'gn gen %s %s' % (gn_out_dir, gn_args)
201
+ # sh(gn_cmd, env)
196
202
  else:
197
203
  for cpu in ANDROID_BUILD_CPUS:
198
204
  gn_out_dir = 'out/%s-%s' % (build_type, cpu)
@@ -207,10 +213,10 @@ def build(target_dir, platform, debug):
207
213
  gn_out_dir = 'out/%s-ios-%s-%s' % (build_type, tenv, arch)
208
214
  ninja_cmd = 'ninja -C %s framework_objc' % gn_out_dir
209
215
  sh(ninja_cmd, env)
210
- for arch in MACOS_BUILD_ARCHS:
211
- gn_out_dir = 'out/%s-macos-%s' % (build_type, arch)
212
- ninja_cmd = 'ninja -C %s mac_framework_objc' % gn_out_dir
213
- sh(ninja_cmd, env)
216
+ #for arch in MACOS_BUILD_ARCHS:
217
+ # gn_out_dir = 'out/%s-macos-%s' % (build_type, arch)
218
+ # ninja_cmd = 'ninja -C %s mac_framework_objc' % gn_out_dir
219
+ # sh(ninja_cmd, env)
214
220
  else:
215
221
  for cpu in ANDROID_BUILD_CPUS:
216
222
  gn_out_dir = 'out/%s-%s' % (build_type, cpu)
@@ -252,9 +258,9 @@ def build(target_dir, platform, debug):
252
258
  tenv, arch = item.split(':')
253
259
  gn_out_dir = 'out/%s-ios-%s-%s' % (build_type, tenv, arch)
254
260
  xcodebuild_cmd += ' -framework %s' % os.path.join(gn_out_dir, 'WebRTC.framework')
255
- for arch in MACOS_BUILD_ARCHS:
256
- gn_out_dir = 'out/%s-macos-%s' % (build_type, arch)
257
- xcodebuild_cmd += ' -framework %s' % os.path.join(gn_out_dir, 'WebRTC.framework')
261
+ #for arch in MACOS_BUILD_ARCHS:
262
+ # gn_out_dir = 'out/%s-macos-%s' % (build_type, arch)
263
+ # xcodebuild_cmd += ' -framework %s' % os.path.join(gn_out_dir, 'WebRTC.framework')
258
264
  sh(xcodebuild_cmd)
259
265
  sh('tar zcf WebRTC.xcframework-bitcode.tgz WebRTC.xcframework', cwd=build_dir)
260
266
  rmr(xcframework_path)
@@ -268,9 +274,9 @@ def build(target_dir, platform, debug):
268
274
  xcodebuild_cmd += ' -framework %s' % os.path.join(gn_out_dir, 'WebRTC.framework')
269
275
  framework_path = os.path.join(gn_out_dir, 'WebRTC.framework', 'WebRTC')
270
276
  sh(bitcode_strip_cmd % (framework_path, framework_path))
271
- for arch in MACOS_BUILD_ARCHS:
272
- gn_out_dir = 'out/%s-macos-%s' % (build_type, arch)
273
- xcodebuild_cmd += ' -framework %s' % os.path.join(gn_out_dir, 'WebRTC.framework')
277
+ #for arch in MACOS_BUILD_ARCHS:
278
+ # gn_out_dir = 'out/%s-macos-%s' % (build_type, arch)
279
+ # xcodebuild_cmd += ' -framework %s' % os.path.join(gn_out_dir, 'WebRTC.framework')
274
280
  sh(xcodebuild_cmd)
275
281
  sh('tar zcf WebRTC.xcframework.tgz WebRTC.xcframework', cwd=build_dir)
276
282
  rmr(xcframework_path)
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "include": ["src/**/*.ts"],
3
+ "compilerOptions": {
4
+ "target": "es6",
5
+ "module": "commonjs",
6
+ "strict": true,
7
+ "moduleResolution": "node",
8
+ "lib": ["es2015", "esnext"],
9
+ "jsx": "react-native",
10
+ "resolveJsonModule": true,
11
+ "noImplicitAny": false,
12
+ },
13
+ "exclude": ["node_modules"]
14
+ }
@@ -1,10 +0,0 @@
1
-
2
- export default class MessageEvent {
3
- type: string;
4
- data: string | ArrayBuffer | Blob;
5
- origin: string;
6
- constructor(type, eventInitDict) {
7
- this.type = type.toString();
8
- Object.assign(this, eventInitDict);
9
- }
10
- }