react-native-webrtc 1.92.1 → 1.94.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +9 -0
- package/.prettierrc.json +10 -0
- package/README.md +2 -2
- package/android/libs/.placeholder +0 -0
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +21 -8
- package/android/src/main/java/com/oney/WebRTCModule/StringUtils.java +24 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +199 -255
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +10 -2
- package/apple/.placeholder +0 -0
- package/ios/RCTWebRTC/VideoCaptureController.h +2 -2
- package/ios/RCTWebRTC/VideoCaptureController.m +131 -48
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +39 -20
- package/metro.config.js +3 -4
- package/metro.config.macos.js +7 -8
- package/package.json +20 -12
- package/react-native.config.js +5 -6
- package/{EventEmitter.js → src/EventEmitter.js} +1 -1
- package/{MediaDevices.js → src/MediaDevices.js} +6 -12
- package/src/MediaStream.js +128 -0
- package/src/MediaStreamError.js +12 -0
- package/src/MediaStreamErrorEvent.js +11 -0
- package/src/MediaStreamEvent.js +11 -0
- package/src/MediaStreamTrack.js +104 -0
- package/src/MediaStreamTrackEvent.js +11 -0
- package/src/MessageEvent.js +10 -0
- package/{Permissions.js → src/Permissions.js} +26 -23
- package/src/RTCDataChannel.js +143 -0
- package/src/RTCDataChannelEvent.js +11 -0
- package/src/RTCEvent.js +8 -0
- package/src/RTCIceCandidate.js +20 -0
- package/src/RTCIceCandidateEvent.js +15 -0
- package/src/RTCPeerConnection.js +349 -0
- package/src/RTCSessionDescription.js +22 -0
- package/{RTCUtil.js → src/RTCUtil.js} +77 -57
- package/src/RTCView.js +60 -0
- package/src/ScreenCapturePickerView.js +4 -0
- package/{getDisplayMedia.js → src/getDisplayMedia.js} +7 -6
- package/src/getUserMedia.js +98 -0
- package/src/index.js +44 -0
- package/tools/build-webrtc.py +61 -49
- package/tools/downloadBitcode.sh +4 -16
- package/tools/downloadWebRTC.js +100 -0
- package/MediaStream.js +0 -138
- package/MediaStreamError.js +0 -14
- package/MediaStreamErrorEvent.js +0 -12
- package/MediaStreamEvent.js +0 -12
- package/MediaStreamTrack.js +0 -118
- package/MediaStreamTrackEvent.js +0 -12
- package/MessageEvent.js +0 -11
- package/RTCDataChannel.js +0 -161
- package/RTCDataChannelEvent.js +0 -12
- package/RTCEvent.js +0 -9
- package/RTCIceCandidate.js +0 -21
- package/RTCIceCandidateEvent.js +0 -16
- package/RTCPeerConnection.js +0 -379
- package/RTCSessionDescription.js +0 -23
- package/RTCView.js +0 -70
- package/ScreenCapturePickerView.js +0 -7
- package/android/libs/libjingle_peerconnection.so.jar +0 -0
- package/android/libs/libwebrtc.jar +0 -0
- package/apple/WebRTC.xcframework.tgz +0 -0
- package/getUserMedia.js +0 -98
- package/index.js +0 -50
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- 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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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 [
|
|
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 [
|
|
53
|
+
for (const v of ['exact', 'ideal', 'min', 'max']) {
|
|
55
54
|
if (value[v]) {
|
|
56
55
|
return Number.parseInt(value[v]);
|
|
57
56
|
}
|
|
@@ -60,59 +59,80 @@ function extractNumber(constraints, prop) {
|
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
function normalizeMediaConstraints(constraints, mediaType) {
|
|
63
|
-
switch(mediaType) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
if (!c.deviceId) {
|
|
88
|
+
delete c.deviceId;
|
|
89
|
+
}
|
|
91
90
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
if (!c.facingMode || (c.facingMode !== 'user' && c.facingMode !== 'environment')) {
|
|
92
|
+
c.facingMode = DEFAULT_VIDEO_CONSTRAINTS.facingMode;
|
|
93
|
+
}
|
|
95
94
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
if (!c.frameRate) {
|
|
96
|
+
c.frameRate = DEFAULT_VIDEO_CONSTRAINTS.frameRate;
|
|
97
|
+
}
|
|
99
98
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
return c;
|
|
109
|
+
}
|
|
110
|
+
default:
|
|
111
|
+
throw new TypeError(`Invalid media type: ${mediaType}`);
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
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
|
+
|
|
116
136
|
/**
|
|
117
137
|
* Utility for deep cloning an object. Object.assign() only does a shallow copy.
|
|
118
138
|
*
|
|
@@ -143,7 +163,7 @@ export function normalizeOfferAnswerOptions(options = {}) {
|
|
|
143
163
|
|
|
144
164
|
// Convert standard options into WebRTC internal constant names.
|
|
145
165
|
// See: https://github.com/jitsi/webrtc/blob/0cd6ce4de669bed94ba47b88cb71b9be0341bb81/sdk/media_constraints.cc#L113
|
|
146
|
-
for (const [
|
|
166
|
+
for (const [key, value] of Object.entries(options)) {
|
|
147
167
|
const newKey = STANDARD_OA_OPTIONS[key.toLowerCase()];
|
|
148
168
|
if (newKey) {
|
|
149
169
|
newOptions[newKey] = String(Boolean(value));
|
|
@@ -159,7 +179,7 @@ export function normalizeOfferAnswerOptions(options = {}) {
|
|
|
159
179
|
export function normalizeConstraints(constraints) {
|
|
160
180
|
const c = deepClone(constraints);
|
|
161
181
|
|
|
162
|
-
for (const mediaType of [
|
|
182
|
+
for (const mediaType of ['audio', 'video']) {
|
|
163
183
|
const mediaTypeConstraints = c[mediaType];
|
|
164
184
|
const typeofMediaTypeConstraints = typeof mediaTypeConstraints;
|
|
165
185
|
|
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');
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
|
|
3
|
-
import {
|
|
2
|
+
import { NativeModules } from 'react-native';
|
|
4
3
|
|
|
5
4
|
import MediaStream from './MediaStream';
|
|
6
5
|
import MediaStreamError from './MediaStreamError';
|
|
@@ -9,8 +8,8 @@ const { WebRTCModule } = NativeModules;
|
|
|
9
8
|
|
|
10
9
|
export default function getDisplayMedia() {
|
|
11
10
|
return new Promise((resolve, reject) => {
|
|
12
|
-
WebRTCModule.getDisplayMedia()
|
|
13
|
-
|
|
11
|
+
WebRTCModule.getDisplayMedia().then(
|
|
12
|
+
data => {
|
|
14
13
|
const { streamId, track } = data;
|
|
15
14
|
|
|
16
15
|
const info = {
|
|
@@ -22,8 +21,10 @@ export default function getDisplayMedia() {
|
|
|
22
21
|
const stream = new MediaStream(info);
|
|
23
22
|
|
|
24
23
|
resolve(stream);
|
|
25
|
-
},
|
|
24
|
+
},
|
|
25
|
+
error => {
|
|
26
26
|
reject(new MediaStreamError(error));
|
|
27
|
-
}
|
|
27
|
+
}
|
|
28
|
+
);
|
|
28
29
|
});
|
|
29
30
|
}
|