react-native-webrtc 1.92.0 → 1.94.1

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 (68) hide show
  1. package/.prettierignore +9 -0
  2. package/.prettierrc.json +10 -0
  3. package/README.md +2 -1
  4. package/android/libs/.placeholder +0 -0
  5. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +0 -5
  6. package/android/src/main/java/com/oney/WebRTCModule/LibraryLoader.java +21 -0
  7. package/android/src/main/java/com/oney/WebRTCModule/StringUtils.java +24 -0
  8. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +222 -275
  9. package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +9 -84
  10. package/apple/.placeholder +0 -0
  11. package/ios/RCTWebRTC/VideoCaptureController.h +2 -2
  12. package/ios/RCTWebRTC/VideoCaptureController.m +131 -48
  13. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +39 -20
  14. package/metro.config.js +3 -4
  15. package/metro.config.macos.js +7 -8
  16. package/package.json +21 -12
  17. package/react-native.config.js +5 -6
  18. package/{EventEmitter.js → src/EventEmitter.js} +1 -1
  19. package/{MediaDevices.js → src/MediaDevices.js} +6 -12
  20. package/src/MediaStream.js +128 -0
  21. package/src/MediaStreamError.js +12 -0
  22. package/src/MediaStreamErrorEvent.js +11 -0
  23. package/src/MediaStreamEvent.js +11 -0
  24. package/src/MediaStreamTrack.js +104 -0
  25. package/src/MediaStreamTrackEvent.js +11 -0
  26. package/src/MessageEvent.js +10 -0
  27. package/{Permissions.js → src/Permissions.js} +26 -23
  28. package/src/RTCDataChannel.js +143 -0
  29. package/src/RTCDataChannelEvent.js +11 -0
  30. package/src/RTCEvent.js +8 -0
  31. package/src/RTCIceCandidate.js +20 -0
  32. package/src/RTCIceCandidateEvent.js +15 -0
  33. package/src/RTCPeerConnection.js +349 -0
  34. package/src/RTCSessionDescription.js +22 -0
  35. package/{RTCUtil.js → src/RTCUtil.js} +56 -57
  36. package/src/RTCView.js +60 -0
  37. package/src/ScreenCapturePickerView.js +4 -0
  38. package/{getDisplayMedia.js → src/getDisplayMedia.js} +8 -11
  39. package/src/getUserMedia.js +98 -0
  40. package/src/index.js +44 -0
  41. package/tools/build-webrtc.py +61 -49
  42. package/tools/downloadBitcode.sh +4 -16
  43. package/tools/downloadWebRTC.js +100 -0
  44. package/MediaStream.js +0 -138
  45. package/MediaStreamError.js +0 -14
  46. package/MediaStreamErrorEvent.js +0 -12
  47. package/MediaStreamEvent.js +0 -12
  48. package/MediaStreamTrack.js +0 -118
  49. package/MediaStreamTrackEvent.js +0 -12
  50. package/MessageEvent.js +0 -11
  51. package/RTCDataChannel.js +0 -161
  52. package/RTCDataChannelEvent.js +0 -12
  53. package/RTCEvent.js +0 -9
  54. package/RTCIceCandidate.js +0 -21
  55. package/RTCIceCandidateEvent.js +0 -16
  56. package/RTCPeerConnection.js +0 -379
  57. package/RTCSessionDescription.js +0 -23
  58. package/RTCView.js +0 -70
  59. package/ScreenCapturePickerView.js +0 -7
  60. package/android/libs/libjingle_peerconnection.so.jar +0 -0
  61. package/android/libs/libwebrtc.jar +0 -0
  62. package/apple/WebRTC.xcframework.tgz +0 -0
  63. package/getUserMedia.js +0 -98
  64. package/index.js +0 -47
  65. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  66. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  67. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  68. package/ios/RCTWebRTC.xcodeproj/xcuserdata/saghul.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
@@ -0,0 +1,349 @@
1
+
2
+ import { defineCustomEventTarget } from 'event-target-shim';
3
+ import { NativeModules } from 'react-native';
4
+
5
+ import MediaStream from './MediaStream';
6
+ import MediaStreamEvent from './MediaStreamEvent';
7
+ import MediaStreamTrack from './MediaStreamTrack';
8
+ import MediaStreamTrackEvent from './MediaStreamTrackEvent';
9
+ import RTCDataChannel from './RTCDataChannel';
10
+ import RTCDataChannelEvent from './RTCDataChannelEvent';
11
+ import RTCSessionDescription from './RTCSessionDescription';
12
+ import RTCIceCandidate from './RTCIceCandidate';
13
+ import RTCIceCandidateEvent from './RTCIceCandidateEvent';
14
+ import RTCEvent from './RTCEvent';
15
+ import * as RTCUtil from './RTCUtil';
16
+ import EventEmitter from './EventEmitter';
17
+
18
+ const { WebRTCModule } = NativeModules;
19
+
20
+ type RTCSignalingState =
21
+ | 'stable'
22
+ | 'have-local-offer'
23
+ | 'have-remote-offer'
24
+ | 'have-local-pranswer'
25
+ | 'have-remote-pranswer'
26
+ | 'closed';
27
+
28
+ type RTCIceGatheringState = 'new' | 'gathering' | 'complete';
29
+
30
+ type RTCPeerConnectionState = 'new' | 'connecting' | 'connected' | 'disconnected' | 'failed' | 'closed';
31
+
32
+ type RTCIceConnectionState = 'new' | 'checking' | 'connected' | 'completed' | 'failed' | 'disconnected' | 'closed';
33
+
34
+ type RTCDataChannelInit = {
35
+ ordered?: boolean,
36
+ maxPacketLifeTime?: number,
37
+ maxRetransmits?: number,
38
+ protocol?: string,
39
+ negotiated?: boolean,
40
+ id?: number
41
+ };
42
+
43
+ const PEER_CONNECTION_EVENTS = [
44
+ 'connectionstatechange',
45
+ 'icecandidate',
46
+ 'icecandidateerror',
47
+ 'iceconnectionstatechange',
48
+ 'icegatheringstatechange',
49
+ 'negotiationneeded',
50
+ 'signalingstatechange',
51
+ 'datachannel',
52
+ 'addstream',
53
+ 'removestream'
54
+ ];
55
+
56
+ let nextPeerConnectionId = 0;
57
+
58
+ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_CONNECTION_EVENTS) {
59
+ localDescription: RTCSessionDescription;
60
+ remoteDescription: RTCSessionDescription;
61
+
62
+ signalingState: RTCSignalingState = 'stable';
63
+ iceGatheringState: RTCIceGatheringState = 'new';
64
+ connectionState: RTCPeerConnectionState = 'new';
65
+ iceConnectionState: RTCIceConnectionState = 'new';
66
+
67
+ _peerConnectionId: number;
68
+ _localStreams: Array<MediaStream> = [];
69
+ _remoteStreams: Array<MediaStream> = [];
70
+ _subscriptions: Array<any>;
71
+
72
+ constructor(configuration) {
73
+ super();
74
+ this._peerConnectionId = nextPeerConnectionId++;
75
+ WebRTCModule.peerConnectionInit(configuration, this._peerConnectionId);
76
+ this._registerEvents();
77
+ }
78
+
79
+ addStream(stream: MediaStream) {
80
+ const index = this._localStreams.indexOf(stream);
81
+ if (index !== -1) {
82
+ return;
83
+ }
84
+ WebRTCModule.peerConnectionAddStream(stream._reactTag, this._peerConnectionId);
85
+ this._localStreams.push(stream);
86
+ }
87
+
88
+ removeStream(stream: MediaStream) {
89
+ const index = this._localStreams.indexOf(stream);
90
+ if (index === -1) {
91
+ return;
92
+ }
93
+ this._localStreams.splice(index, 1);
94
+ WebRTCModule.peerConnectionRemoveStream(stream._reactTag, this._peerConnectionId);
95
+ }
96
+
97
+ createOffer(options) {
98
+ return new Promise((resolve, reject) => {
99
+ WebRTCModule.peerConnectionCreateOffer(
100
+ this._peerConnectionId,
101
+ RTCUtil.normalizeOfferAnswerOptions(options),
102
+ (successful, data) => {
103
+ if (successful) {
104
+ resolve(data);
105
+ } else {
106
+ reject(data); // TODO: convert to NavigatorUserMediaError
107
+ }
108
+ }
109
+ );
110
+ });
111
+ }
112
+
113
+ createAnswer(options = {}) {
114
+ return new Promise((resolve, reject) => {
115
+ WebRTCModule.peerConnectionCreateAnswer(
116
+ this._peerConnectionId,
117
+ RTCUtil.normalizeOfferAnswerOptions(options),
118
+ (successful, data) => {
119
+ if (successful) {
120
+ resolve(data);
121
+ } else {
122
+ reject(data);
123
+ }
124
+ }
125
+ );
126
+ });
127
+ }
128
+
129
+ setConfiguration(configuration) {
130
+ WebRTCModule.peerConnectionSetConfiguration(configuration, this._peerConnectionId);
131
+ }
132
+
133
+ async setLocalDescription(sessionDescription: ?RTCSessionDescription) {
134
+ const desc = sessionDescription
135
+ ? sessionDescription.toJSON
136
+ ? sessionDescription.toJSON()
137
+ : sessionDescription
138
+ : null;
139
+ const newSdp = await WebRTCModule.peerConnectionSetLocalDescription(this._peerConnectionId, desc);
140
+
141
+ this.localDescription = new RTCSessionDescription(newSdp);
142
+ }
143
+
144
+ setRemoteDescription(sessionDescription: RTCSessionDescription) {
145
+ return new Promise((resolve, reject) => {
146
+ WebRTCModule.peerConnectionSetRemoteDescription(
147
+ sessionDescription.toJSON ? sessionDescription.toJSON() : sessionDescription,
148
+ this._peerConnectionId,
149
+ (successful, data) => {
150
+ if (successful) {
151
+ this.remoteDescription = new RTCSessionDescription(data);
152
+ resolve();
153
+ } else {
154
+ reject(data);
155
+ }
156
+ }
157
+ );
158
+ });
159
+ }
160
+
161
+ async addIceCandidate(candidate) {
162
+ if (!candidate || !candidate.candidate) {
163
+ // XXX end-of cantidates is not implemented: https://bugs.chromium.org/p/webrtc/issues/detail?id=9218
164
+ return;
165
+ }
166
+
167
+ const newSdp = await WebRTCModule.peerConnectionAddICECandidate(
168
+ this._peerConnectionId,
169
+ candidate.toJSON ? candidate.toJSON() : candidate
170
+ );
171
+
172
+ this.remoteDescription = new RTCSessionDescription(newSdp);
173
+ }
174
+
175
+ getStats() {
176
+ return WebRTCModule.peerConnectionGetStats(this._peerConnectionId).then(data => {
177
+ /* On both Android and iOS it is faster to construct a single
178
+ JSON string representing the Map of StatsReports and have it
179
+ pass through the React Native bridge rather than the Map of
180
+ StatsReports. While the implementations do try to be faster in
181
+ general, the stress is on being faster to pass through the React
182
+ Native bridge which is a bottleneck that tends to be visible in
183
+ the UI when there is congestion involving UI-related passing.
184
+
185
+ TODO Implement the logic for filtering the stats based on
186
+ the sender/receiver
187
+ */
188
+ return new Map(JSON.parse(data));
189
+ });
190
+ }
191
+
192
+ getLocalStreams() {
193
+ return this._localStreams.slice();
194
+ }
195
+
196
+ getRemoteStreams() {
197
+ return this._remoteStreams.slice();
198
+ }
199
+
200
+ close() {
201
+ WebRTCModule.peerConnectionClose(this._peerConnectionId);
202
+ }
203
+
204
+ restartIce() {
205
+ WebRTCModule.peerConnectionRestartIce(this._peerConnectionId);
206
+ }
207
+
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
+ _unregisterEvents(): void {
215
+ this._subscriptions.forEach(e => e.remove());
216
+ this._subscriptions = [];
217
+ }
218
+
219
+ _registerEvents(): void {
220
+ this._subscriptions = [
221
+ EventEmitter.addListener('peerConnectionOnRenegotiationNeeded', ev => {
222
+ if (ev.id !== this._peerConnectionId) {
223
+ return;
224
+ }
225
+ this.dispatchEvent(new RTCEvent('negotiationneeded'));
226
+ }),
227
+ EventEmitter.addListener('peerConnectionIceConnectionChanged', ev => {
228
+ if (ev.id !== this._peerConnectionId) {
229
+ return;
230
+ }
231
+ this.iceConnectionState = ev.iceConnectionState;
232
+ this.dispatchEvent(new RTCEvent('iceconnectionstatechange'));
233
+ if (ev.iceConnectionState === 'closed') {
234
+ // This PeerConnection is done, clean up event handlers.
235
+ this._unregisterEvents();
236
+ }
237
+ }),
238
+ EventEmitter.addListener('peerConnectionStateChanged', ev => {
239
+ if (ev.id !== this._peerConnectionId) {
240
+ return;
241
+ }
242
+ this.connectionState = ev.connectionState;
243
+ this.dispatchEvent(new RTCEvent('connectionstatechange'));
244
+ if (ev.connectionState === 'closed') {
245
+ // This PeerConnection is done, clean up event handlers.
246
+ this._unregisterEvents();
247
+ }
248
+ }),
249
+ EventEmitter.addListener('peerConnectionSignalingStateChanged', ev => {
250
+ if (ev.id !== this._peerConnectionId) {
251
+ return;
252
+ }
253
+ this.signalingState = ev.signalingState;
254
+ this.dispatchEvent(new RTCEvent('signalingstatechange'));
255
+ }),
256
+ EventEmitter.addListener('peerConnectionAddedStream', ev => {
257
+ if (ev.id !== this._peerConnectionId) {
258
+ return;
259
+ }
260
+ const stream = new MediaStream(ev);
261
+ this._remoteStreams.push(stream);
262
+ this.remoteDescription = new RTCSessionDescription(ev.sdp);
263
+ this.dispatchEvent(new MediaStreamEvent('addstream', { stream }));
264
+ }),
265
+ EventEmitter.addListener('peerConnectionRemovedStream', ev => {
266
+ if (ev.id !== this._peerConnectionId) {
267
+ return;
268
+ }
269
+ const stream = this._remoteStreams.find(s => s._reactTag === ev.streamId);
270
+ if (stream) {
271
+ const index = this._remoteStreams.indexOf(stream);
272
+ if (index !== -1) {
273
+ this._remoteStreams.splice(index, 1);
274
+ }
275
+ }
276
+ this.remoteDescription = new RTCSessionDescription(ev.sdp);
277
+ this.dispatchEvent(new MediaStreamEvent('removestream', { stream }));
278
+ }),
279
+ EventEmitter.addListener('mediaStreamTrackMuteChanged', ev => {
280
+ if (ev.peerConnectionId !== this._peerConnectionId) {
281
+ return;
282
+ }
283
+ const track = this._getTrack(ev.streamReactTag, ev.trackId);
284
+ if (track) {
285
+ track.muted = ev.muted;
286
+ const eventName = ev.muted ? 'mute' : 'unmute';
287
+ track.dispatchEvent(new MediaStreamTrackEvent(eventName, { track }));
288
+ }
289
+ }),
290
+ EventEmitter.addListener('peerConnectionGotICECandidate', ev => {
291
+ if (ev.id !== this._peerConnectionId) {
292
+ return;
293
+ }
294
+ this.localDescription = new RTCSessionDescription(ev.sdp);
295
+ const candidate = new RTCIceCandidate(ev.candidate);
296
+ const event = new RTCIceCandidateEvent('icecandidate', { candidate });
297
+ this.dispatchEvent(event);
298
+ }),
299
+ EventEmitter.addListener('peerConnectionIceGatheringChanged', ev => {
300
+ if (ev.id !== this._peerConnectionId) {
301
+ return;
302
+ }
303
+ this.iceGatheringState = ev.iceGatheringState;
304
+
305
+ if (this.iceGatheringState === 'complete') {
306
+ this.localDescription = new RTCSessionDescription(ev.sdp);
307
+ this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', null));
308
+ }
309
+
310
+ this.dispatchEvent(new RTCEvent('icegatheringstatechange'));
311
+ }),
312
+ EventEmitter.addListener('peerConnectionDidOpenDataChannel', ev => {
313
+ if (ev.id !== this._peerConnectionId) {
314
+ return;
315
+ }
316
+ const channel = new RTCDataChannel(ev.dataChannel);
317
+ this.dispatchEvent(new RTCDataChannelEvent('datachannel', { channel }));
318
+ })
319
+ ];
320
+ }
321
+
322
+ /**
323
+ * Creates a new RTCDataChannel object with the given label. The
324
+ * RTCDataChannelInit dictionary can be used to configure properties of the
325
+ * underlying channel such as data reliability.
326
+ *
327
+ * @param {string} label - the value with which the label attribute of the new
328
+ * instance is to be initialized
329
+ * @param {RTCDataChannelInit} dataChannelDict - an optional dictionary of
330
+ * values with which to initialize corresponding attributes of the new
331
+ * instance such as id
332
+ */
333
+ createDataChannel(label: string, dataChannelDict: ?RTCDataChannelInit) {
334
+ if (dataChannelDict && 'id' in dataChannelDict) {
335
+ const id = dataChannelDict.id;
336
+ if (typeof id !== 'number') {
337
+ throw new TypeError('DataChannel id must be a number: ' + id);
338
+ }
339
+ }
340
+
341
+ const channelInfo = WebRTCModule.createDataChannel(this._peerConnectionId, label, dataChannelDict);
342
+
343
+ if (channelInfo === null) {
344
+ throw new TypeError('Failed to create new DataChannel');
345
+ }
346
+
347
+ return new RTCDataChannel(channelInfo);
348
+ }
349
+ }
@@ -0,0 +1,22 @@
1
+
2
+ export default class RTCSessionDescription {
3
+ sdp: string;
4
+ type: string;
5
+
6
+ constructor(info = { type: null, sdp: '' }) {
7
+ this._sdp = info.sdp;
8
+ this._type = info.type;
9
+ }
10
+
11
+ get sdp() {
12
+ return this._sdp;
13
+ }
14
+
15
+ get type() {
16
+ return this._type;
17
+ }
18
+
19
+ toJSON() {
20
+ return { sdp: this._sdp, type: this._type };
21
+ }
22
+ }
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
 
3
2
  const DEFAULT_AUDIO_CONSTRAINTS = {};
4
3
 
@@ -19,13 +18,13 @@ const STANDARD_OA_OPTIONS = {
19
18
  };
20
19
 
21
20
  function getDefaultMediaConstraints(mediaType) {
22
- switch(mediaType) {
23
- case 'audio':
24
- return DEFAULT_AUDIO_CONSTRAINTS;
25
- case 'video':
26
- return DEFAULT_VIDEO_CONSTRAINTS;
27
- default:
28
- throw new TypeError(`Invalid media type: ${mediaType}`);
21
+ switch (mediaType) {
22
+ case 'audio':
23
+ return DEFAULT_AUDIO_CONSTRAINTS;
24
+ case 'video':
25
+ return DEFAULT_VIDEO_CONSTRAINTS;
26
+ default:
27
+ throw new TypeError(`Invalid media type: ${mediaType}`);
29
28
  }
30
29
  }
31
30
 
@@ -34,7 +33,7 @@ function extractString(constraints, prop) {
34
33
  const type = typeof value;
35
34
 
36
35
  if (type === 'object') {
37
- for (const v of [ 'exact', 'ideal' ]) {
36
+ for (const v of ['exact', 'ideal']) {
38
37
  if (value[v]) {
39
38
  return value[v];
40
39
  }
@@ -51,7 +50,7 @@ function extractNumber(constraints, prop) {
51
50
  if (type === 'number') {
52
51
  return Number.parseInt(value);
53
52
  } else if (type === 'object') {
54
- for (const v of [ 'exact', 'ideal', 'min', 'max' ]) {
53
+ for (const v of ['exact', 'ideal', 'min', 'max']) {
55
54
  if (value[v]) {
56
55
  return Number.parseInt(value[v]);
57
56
  }
@@ -60,56 +59,56 @@ function extractNumber(constraints, prop) {
60
59
  }
61
60
 
62
61
  function normalizeMediaConstraints(constraints, mediaType) {
63
- switch(mediaType) {
64
- case 'audio':
65
- return constraints;
66
- case 'video': {
67
- let c;
68
- if (constraints.mandatory) {
69
- // Old style.
70
- c = {
71
- deviceId: extractString(constraints.optional || {}, 'sourceId'),
72
- facingMode: extractString(constraints, 'facingMode'),
73
- frameRate: extractNumber(constraints.mandatory, 'minFrameRate'),
74
- height: extractNumber(constraints.mandatory, 'minHeight'),
75
- width: extractNumber(constraints.mandatory, 'minWidth')
76
- };
77
- } else {
78
- // New style.
79
- c = {
80
- deviceId: extractString(constraints, 'deviceId'),
81
- facingMode: extractString(constraints, 'facingMode'),
82
- frameRate: extractNumber(constraints, 'frameRate'),
83
- height: extractNumber(constraints, 'height'),
84
- width: extractNumber(constraints, 'width')
85
- };
86
- }
62
+ switch (mediaType) {
63
+ case 'audio':
64
+ return constraints;
65
+ case 'video': {
66
+ let c;
67
+ if (constraints.mandatory) {
68
+ // Old style.
69
+ c = {
70
+ deviceId: extractString(constraints.optional || {}, 'sourceId'),
71
+ facingMode: extractString(constraints, 'facingMode'),
72
+ frameRate: extractNumber(constraints.mandatory, 'minFrameRate'),
73
+ height: extractNumber(constraints.mandatory, 'minHeight'),
74
+ width: extractNumber(constraints.mandatory, 'minWidth')
75
+ };
76
+ } else {
77
+ // New style.
78
+ c = {
79
+ deviceId: extractString(constraints, 'deviceId'),
80
+ facingMode: extractString(constraints, 'facingMode'),
81
+ frameRate: extractNumber(constraints, 'frameRate'),
82
+ height: extractNumber(constraints, 'height'),
83
+ width: extractNumber(constraints, 'width')
84
+ };
85
+ }
87
86
 
88
- if (!c.deviceId) {
89
- delete c.deviceId;
90
- }
87
+ if (!c.deviceId) {
88
+ delete c.deviceId;
89
+ }
91
90
 
92
- if (!c.facingMode || (c.facingMode !== 'user' && c.facingMode !== 'environment')) {
93
- c.facingMode = DEFAULT_VIDEO_CONSTRAINTS.facingMode;
94
- }
91
+ if (!c.facingMode || (c.facingMode !== 'user' && c.facingMode !== 'environment')) {
92
+ c.facingMode = DEFAULT_VIDEO_CONSTRAINTS.facingMode;
93
+ }
95
94
 
96
- if (!c.frameRate) {
97
- c.frameRate = DEFAULT_VIDEO_CONSTRAINTS.frameRate;
98
- }
95
+ if (!c.frameRate) {
96
+ c.frameRate = DEFAULT_VIDEO_CONSTRAINTS.frameRate;
97
+ }
99
98
 
100
- if (!c.height && !c.width) {
101
- c.height = DEFAULT_VIDEO_CONSTRAINTS.height;
102
- c.width = DEFAULT_VIDEO_CONSTRAINTS.width;
103
- } else if (!c.height) {
104
- c.height = Math.round(c.width / ASPECT_RATIO);
105
- } else if (!c.width) {
106
- c.width = Math.round(c.height * ASPECT_RATIO);
107
- }
99
+ if (!c.height && !c.width) {
100
+ c.height = DEFAULT_VIDEO_CONSTRAINTS.height;
101
+ c.width = DEFAULT_VIDEO_CONSTRAINTS.width;
102
+ } else if (!c.height) {
103
+ c.height = Math.round(c.width / ASPECT_RATIO);
104
+ } else if (!c.width) {
105
+ c.width = Math.round(c.height * ASPECT_RATIO);
106
+ }
108
107
 
109
- return c;
110
- }
111
- default:
112
- throw new TypeError(`Invalid media type: ${mediaType}`);
108
+ return c;
109
+ }
110
+ default:
111
+ throw new TypeError(`Invalid media type: ${mediaType}`);
113
112
  }
114
113
  }
115
114
 
@@ -143,7 +142,7 @@ export function normalizeOfferAnswerOptions(options = {}) {
143
142
 
144
143
  // Convert standard options into WebRTC internal constant names.
145
144
  // See: https://github.com/jitsi/webrtc/blob/0cd6ce4de669bed94ba47b88cb71b9be0341bb81/sdk/media_constraints.cc#L113
146
- for (const [ key, value ] of Object.entries(options)) {
145
+ for (const [key, value] of Object.entries(options)) {
147
146
  const newKey = STANDARD_OA_OPTIONS[key.toLowerCase()];
148
147
  if (newKey) {
149
148
  newOptions[newKey] = String(Boolean(value));
@@ -159,7 +158,7 @@ export function normalizeOfferAnswerOptions(options = {}) {
159
158
  export function normalizeConstraints(constraints) {
160
159
  const c = deepClone(constraints);
161
160
 
162
- for (const mediaType of [ 'audio', 'video' ]) {
161
+ for (const mediaType of ['audio', 'video']) {
163
162
  const mediaTypeConstraints = c[mediaType];
164
163
  const typeofMediaTypeConstraints = typeof mediaTypeConstraints;
165
164
 
package/src/RTCView.js ADDED
@@ -0,0 +1,60 @@
1
+
2
+ import { requireNativeComponent } from 'react-native';
3
+
4
+ /**
5
+ * Native prop validation was removed from RN in:
6
+ * https://github.com/facebook/react-native/commit/8dc3ba0444c94d9bbb66295b5af885bff9b9cd34
7
+ *
8
+ * So we list them here for documentation purposes.
9
+ */
10
+
11
+ /**
12
+ * Indicates whether the video specified by {@link #streamURL} should be
13
+ * mirrored during rendering. Commonly, applications choose to mirror the
14
+ * user-facing camera.
15
+ *
16
+ * mirror: boolean
17
+ */
18
+
19
+ /**
20
+ * In the fashion of
21
+ * https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth
22
+ * and https://www.w3.org/TR/html5/rendering.html#video-object-fit,
23
+ * resembles the CSS style object-fit.
24
+ *
25
+ * objectFit: 'contain' | 'cover'
26
+ */
27
+
28
+ /**
29
+ * URL / id of the stream that should be rendered.
30
+ *
31
+ * streamURL: string
32
+ */
33
+
34
+ /**
35
+ * Similarly to the CSS property z-index, specifies the z-order of this
36
+ * RTCView in the stacking space of all RTCViews. When RTCViews overlap,
37
+ * zOrder determines which one covers the other. An RTCView with a larger
38
+ * zOrder generally covers an RTCView with a lower one.
39
+ *
40
+ * Non-overlapping RTCViews may safely share a z-order (because one does not
41
+ * have to cover the other).
42
+ *
43
+ * The support for zOrder is platform-dependent and/or
44
+ * implementation-specific. Thus, specifying a value for zOrder is to be
45
+ * thought of as giving a hint rather than as imposing a requirement. For
46
+ * example, video renderers such as RTCView are commonly implemented using
47
+ * OpenGL and OpenGL views may have different numbers of layers in their
48
+ * stacking space. Android has three: a layer bellow the window (aka
49
+ * default), a layer bellow the window again but above the previous layer
50
+ * (aka media overlay), and above the window. Consequently, it is advisable
51
+ * to limit the number of utilized layers in the stacking space to the
52
+ * minimum sufficient for the desired display. For example, a video call
53
+ * application usually needs a maximum of two zOrder values: 0 for the
54
+ * remote video(s) which appear in the background, and 1 for the local
55
+ * video(s) which appear above the remote video(s).
56
+ *
57
+ * zOrder: number
58
+ */
59
+
60
+ export default requireNativeComponent('RTCVideoView');
@@ -0,0 +1,4 @@
1
+
2
+ import { requireNativeComponent } from 'react-native';
3
+
4
+ export default requireNativeComponent('ScreenCapturePickerView');
@@ -1,20 +1,15 @@
1
- 'use strict';
2
1
 
3
- import { Platform, NativeModules } from 'react-native';
2
+ import { NativeModules } from 'react-native';
4
3
 
5
4
  import MediaStream from './MediaStream';
6
5
  import MediaStreamError from './MediaStreamError';
7
6
 
8
7
  const { WebRTCModule } = NativeModules;
9
8
 
10
- export default function getDisplayMedia(constraints) {
11
- if (!constraints || !constraints.video) {
12
- return Promise.reject(new TypeError());
13
- }
14
-
9
+ export default function getDisplayMedia() {
15
10
  return new Promise((resolve, reject) => {
16
- WebRTCModule.getDisplayMedia()
17
- .then(data => {
11
+ WebRTCModule.getDisplayMedia().then(
12
+ data => {
18
13
  const { streamId, track } = data;
19
14
 
20
15
  const info = {
@@ -26,8 +21,10 @@ export default function getDisplayMedia(constraints) {
26
21
  const stream = new MediaStream(info);
27
22
 
28
23
  resolve(stream);
29
- }, error => {
24
+ },
25
+ error => {
30
26
  reject(new MediaStreamError(error));
31
- });
27
+ }
28
+ );
32
29
  });
33
30
  }