react-native-webrtc 1.92.2 → 1.94.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.
- package/.prettierignore +9 -0
- package/.prettierrc.json +10 -0
- package/android/libs/.placeholder +0 -0
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +0 -5
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +199 -255
- package/apple/.placeholder +0 -0
- package/ios/RCTWebRTC/VideoCaptureController.m +5 -3
- 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/src/EventEmitter.js +1 -1
- package/src/MediaDevices.js +6 -12
- package/src/MediaStream.js +120 -131
- package/src/MediaStreamError.js +8 -10
- package/src/MediaStreamErrorEvent.js +6 -7
- package/src/MediaStreamEvent.js +6 -7
- package/src/MediaStreamTrack.js +89 -103
- package/src/MediaStreamTrackEvent.js +6 -7
- package/src/MessageEvent.js +7 -8
- package/src/Permissions.js +26 -23
- package/src/RTCDataChannel.js +127 -145
- package/src/RTCDataChannelEvent.js +6 -7
- package/src/RTCEvent.js +5 -6
- package/src/RTCIceCandidate.js +15 -16
- package/src/RTCIceCandidateEvent.js +8 -9
- package/src/RTCPeerConnection.js +295 -325
- package/src/RTCSessionDescription.js +15 -16
- package/src/RTCUtil.js +56 -57
- package/src/RTCView.js +59 -69
- package/src/ScreenCapturePickerView.js +2 -5
- package/src/getDisplayMedia.js +7 -6
- package/src/getUserMedia.js +85 -85
- package/src/index.js +28 -34
- package/tools/build-webrtc.py +61 -49
- package/tools/downloadBitcode.sh +4 -16
- package/tools/downloadWebRTC.js +100 -0
- package/android/libs/libjingle_peerconnection.so.jar +0 -0
- package/android/libs/libwebrtc.jar +0 -0
- package/apple/WebRTC.xcframework.tgz +0 -0
- 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
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
|
|
3
2
|
export default class RTCSessionDescription {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
sdp: string;
|
|
4
|
+
type: string;
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
constructor(info = { type: null, sdp: '' }) {
|
|
7
|
+
this._sdp = info.sdp;
|
|
8
|
+
this._type = info.type;
|
|
9
|
+
}
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
get sdp() {
|
|
12
|
+
return this._sdp;
|
|
13
|
+
}
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
get type() {
|
|
16
|
+
return this._type;
|
|
17
|
+
}
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
toJSON() {
|
|
20
|
+
return { sdp: this._sdp, type: this._type };
|
|
21
|
+
}
|
|
23
22
|
}
|
package/src/RTCUtil.js
CHANGED
|
@@ -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,56 +59,56 @@ 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
|
|
|
@@ -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 [
|
|
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 [
|
|
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
CHANGED
|
@@ -1,70 +1,60 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
renderToHardwareTextureAndroid: true,
|
|
63
|
-
accessibilityLabel: true,
|
|
64
|
-
accessibilityLiveRegion: true,
|
|
65
|
-
importantForAccessibility: true,
|
|
66
|
-
onLayout: true,
|
|
67
|
-
nativeID: true,
|
|
68
|
-
}});
|
|
69
|
-
|
|
70
|
-
export default View;
|
|
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,7 +1,4 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
|
|
3
|
-
import {
|
|
4
|
-
requireNativeComponent,
|
|
5
|
-
} from 'react-native';
|
|
2
|
+
import { requireNativeComponent } from 'react-native';
|
|
6
3
|
|
|
7
|
-
export default requireNativeComponent('ScreenCapturePickerView')
|
|
4
|
+
export default requireNativeComponent('ScreenCapturePickerView');
|
package/src/getDisplayMedia.js
CHANGED
|
@@ -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
|
}
|
package/src/getUserMedia.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
|
|
3
|
-
import {
|
|
2
|
+
import { NativeModules } from 'react-native';
|
|
4
3
|
import * as RTCUtil from './RTCUtil';
|
|
5
4
|
|
|
6
5
|
import MediaStream from './MediaStream';
|
|
@@ -9,90 +8,91 @@ import permissions from './Permissions';
|
|
|
9
8
|
|
|
10
9
|
const { WebRTCModule } = NativeModules;
|
|
11
10
|
|
|
12
|
-
|
|
13
11
|
export default function getUserMedia(constraints = {}) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
reqPermissions
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
audioPerm || (delete constraints.audio);
|
|
61
|
-
videoPerm || (delete constraints.video);
|
|
62
|
-
|
|
63
|
-
const success = (id, tracks) => {
|
|
64
|
-
// Store initial constraints.
|
|
65
|
-
for (const trackInfo of tracks) {
|
|
66
|
-
const c = constraints[trackInfo.kind];
|
|
67
|
-
if (typeof c === 'object') {
|
|
68
|
-
trackInfo.constraints = RTCUtil.deepClone(c);
|
|
12
|
+
// According to
|
|
13
|
+
// https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia,
|
|
14
|
+
// the constraints argument is a dictionary of type MediaStreamConstraints.
|
|
15
|
+
if (typeof constraints !== 'object') {
|
|
16
|
+
return Promise.reject(new TypeError('constraints is not a dictionary'));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (
|
|
20
|
+
(typeof constraints.audio === 'undefined' || !constraints.audio) &&
|
|
21
|
+
(typeof constraints.video === 'undefined' || !constraints.video)
|
|
22
|
+
) {
|
|
23
|
+
return Promise.reject(new TypeError('audio and/or video is required'));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Normalize constraints.
|
|
27
|
+
constraints = RTCUtil.normalizeConstraints(constraints);
|
|
28
|
+
|
|
29
|
+
// Request required permissions
|
|
30
|
+
const reqPermissions = [];
|
|
31
|
+
if (constraints.audio) {
|
|
32
|
+
reqPermissions.push(permissions.request({ name: 'microphone' }));
|
|
33
|
+
} else {
|
|
34
|
+
reqPermissions.push(Promise.resolve(false));
|
|
35
|
+
}
|
|
36
|
+
if (constraints.video) {
|
|
37
|
+
reqPermissions.push(permissions.request({ name: 'camera' }));
|
|
38
|
+
} else {
|
|
39
|
+
reqPermissions.push(Promise.resolve(false));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
Promise.all(reqPermissions).then(results => {
|
|
44
|
+
const [audioPerm, videoPerm] = results;
|
|
45
|
+
|
|
46
|
+
// Check permission results and remove unneeded permissions.
|
|
47
|
+
|
|
48
|
+
if (!audioPerm && !videoPerm) {
|
|
49
|
+
// https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia
|
|
50
|
+
// step 4
|
|
51
|
+
const error = {
|
|
52
|
+
message: 'Permission denied.',
|
|
53
|
+
name: 'SecurityError'
|
|
54
|
+
};
|
|
55
|
+
reject(new MediaStreamError(error));
|
|
56
|
+
|
|
57
|
+
return;
|
|
69
58
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
59
|
+
|
|
60
|
+
audioPerm || delete constraints.audio;
|
|
61
|
+
videoPerm || delete constraints.video;
|
|
62
|
+
|
|
63
|
+
const success = (id, tracks) => {
|
|
64
|
+
// Store initial constraints.
|
|
65
|
+
for (const trackInfo of tracks) {
|
|
66
|
+
const c = constraints[trackInfo.kind];
|
|
67
|
+
if (typeof c === 'object') {
|
|
68
|
+
trackInfo.constraints = RTCUtil.deepClone(c);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const info = {
|
|
73
|
+
streamId: id,
|
|
74
|
+
streamReactTag: id,
|
|
75
|
+
tracks
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
resolve(new MediaStream(info));
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const failure = (type, message) => {
|
|
82
|
+
let error;
|
|
83
|
+
switch (type) {
|
|
84
|
+
case 'TypeError':
|
|
85
|
+
error = new TypeError(message);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (!error) {
|
|
89
|
+
error = new MediaStreamError({ message, name: type });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
reject(error);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
WebRTCModule.getUserMedia(constraints, success, failure);
|
|
96
|
+
});
|
|
96
97
|
});
|
|
97
|
-
});
|
|
98
98
|
}
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
|
|
3
2
|
import ScreenCapturePickerView from './ScreenCapturePickerView';
|
|
4
3
|
import RTCPeerConnection from './RTCPeerConnection';
|
|
@@ -11,40 +10,35 @@ import mediaDevices from './MediaDevices';
|
|
|
11
10
|
import permissions from './Permissions';
|
|
12
11
|
|
|
13
12
|
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
ScreenCapturePickerView,
|
|
14
|
+
RTCPeerConnection,
|
|
15
|
+
RTCIceCandidate,
|
|
16
|
+
RTCSessionDescription,
|
|
17
|
+
RTCView,
|
|
18
|
+
MediaStream,
|
|
19
|
+
MediaStreamTrack,
|
|
20
|
+
mediaDevices,
|
|
21
|
+
permissions,
|
|
22
|
+
registerGlobals
|
|
24
23
|
};
|
|
25
24
|
|
|
26
25
|
function registerGlobals() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
global.RTCPeerConnection = RTCPeerConnection;
|
|
46
|
-
global.RTCIceCandidate = RTCIceCandidate;
|
|
47
|
-
global.RTCSessionDescription = RTCSessionDescription;
|
|
48
|
-
global.MediaStream = MediaStream;
|
|
49
|
-
global.MediaStreamTrack = MediaStreamTrack;
|
|
26
|
+
// Should not happen. React Native has a global navigator object.
|
|
27
|
+
if (typeof navigator !== 'object') {
|
|
28
|
+
throw new Error('navigator is not an object');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!navigator.mediaDevices) {
|
|
32
|
+
navigator.mediaDevices = {};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
navigator.mediaDevices.getUserMedia = mediaDevices.getUserMedia.bind(mediaDevices);
|
|
36
|
+
navigator.mediaDevices.getDisplayMedia = mediaDevices.getDisplayMedia.bind(mediaDevices);
|
|
37
|
+
navigator.mediaDevices.enumerateDevices = mediaDevices.enumerateDevices.bind(mediaDevices);
|
|
38
|
+
|
|
39
|
+
global.RTCPeerConnection = RTCPeerConnection;
|
|
40
|
+
global.RTCIceCandidate = RTCIceCandidate;
|
|
41
|
+
global.RTCSessionDescription = RTCSessionDescription;
|
|
42
|
+
global.MediaStream = MediaStream;
|
|
43
|
+
global.MediaStreamTrack = MediaStreamTrack;
|
|
50
44
|
}
|