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,98 @@
|
|
|
1
|
+
|
|
2
|
+
import { NativeModules } from 'react-native';
|
|
3
|
+
import * as RTCUtil from './RTCUtil';
|
|
4
|
+
|
|
5
|
+
import MediaStream from './MediaStream';
|
|
6
|
+
import MediaStreamError from './MediaStreamError';
|
|
7
|
+
import permissions from './Permissions';
|
|
8
|
+
|
|
9
|
+
const { WebRTCModule } = NativeModules;
|
|
10
|
+
|
|
11
|
+
export default function getUserMedia(constraints = {}) {
|
|
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;
|
|
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);
|
|
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
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
import ScreenCapturePickerView from './ScreenCapturePickerView';
|
|
3
|
+
import RTCPeerConnection from './RTCPeerConnection';
|
|
4
|
+
import RTCIceCandidate from './RTCIceCandidate';
|
|
5
|
+
import RTCSessionDescription from './RTCSessionDescription';
|
|
6
|
+
import RTCView from './RTCView';
|
|
7
|
+
import MediaStream from './MediaStream';
|
|
8
|
+
import MediaStreamTrack from './MediaStreamTrack';
|
|
9
|
+
import mediaDevices from './MediaDevices';
|
|
10
|
+
import permissions from './Permissions';
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
ScreenCapturePickerView,
|
|
14
|
+
RTCPeerConnection,
|
|
15
|
+
RTCIceCandidate,
|
|
16
|
+
RTCSessionDescription,
|
|
17
|
+
RTCView,
|
|
18
|
+
MediaStream,
|
|
19
|
+
MediaStreamTrack,
|
|
20
|
+
mediaDevices,
|
|
21
|
+
permissions,
|
|
22
|
+
registerGlobals
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function registerGlobals() {
|
|
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;
|
|
44
|
+
}
|
package/tools/build-webrtc.py
CHANGED
|
@@ -22,17 +22,11 @@ ANDROID_BUILD_CPUS = [
|
|
|
22
22
|
'x86',
|
|
23
23
|
'x64'
|
|
24
24
|
]
|
|
25
|
-
IOS_ARCH_MAP = {
|
|
26
|
-
'arm64': 'ios-arm64',
|
|
27
|
-
'x64' : 'ios-x86_64-simulator'
|
|
28
|
-
}
|
|
29
25
|
IOS_BUILD_ARCHS = [
|
|
30
|
-
'arm64',
|
|
31
|
-
'
|
|
26
|
+
'device:arm64',
|
|
27
|
+
'simulator:arm64',
|
|
28
|
+
'simulator:x64'
|
|
32
29
|
]
|
|
33
|
-
MACOS_ARCH_MAP = {
|
|
34
|
-
'x64' : 'macos-x86_64'
|
|
35
|
-
}
|
|
36
30
|
MACOS_BUILD_ARCHS = [
|
|
37
31
|
'x64'
|
|
38
32
|
]
|
|
@@ -41,9 +35,6 @@ def build_gn_args(platform_args):
|
|
|
41
35
|
return "--args='" + ' '.join(GN_COMMON_ARGS + platform_args) + "'"
|
|
42
36
|
|
|
43
37
|
GN_COMMON_ARGS = [
|
|
44
|
-
# Xcode 12 Clang consider warning as error by default
|
|
45
|
-
# See https://bugs.chromium.org/p/webrtc/issues/detail?id=11729
|
|
46
|
-
'treat_warnings_as_errors=false',
|
|
47
38
|
'is_component_build=false',
|
|
48
39
|
'rtc_libvpx_build_vp9=true',
|
|
49
40
|
'is_debug=%s',
|
|
@@ -58,10 +49,11 @@ _GN_APPLE_COMMON = [
|
|
|
58
49
|
|
|
59
50
|
_GN_IOS_ARGS = [
|
|
60
51
|
'enable_ios_bitcode=true',
|
|
61
|
-
'ios_deployment_target="
|
|
52
|
+
'ios_deployment_target="12.0"',
|
|
62
53
|
'ios_enable_code_signing=false',
|
|
63
54
|
'target_os="ios"',
|
|
64
55
|
'use_xcode_clang=true',
|
|
56
|
+
'target_environment="%s"'
|
|
65
57
|
]
|
|
66
58
|
GN_IOS_ARGS = build_gn_args(_GN_APPLE_COMMON + _GN_IOS_ARGS)
|
|
67
59
|
|
|
@@ -72,18 +64,17 @@ _GN_MACOS_ARGS = [
|
|
|
72
64
|
GN_MACOS_ARGS = build_gn_args(_GN_APPLE_COMMON + _GN_MACOS_ARGS)
|
|
73
65
|
|
|
74
66
|
_GN_ANDROID_ARGS = [
|
|
75
|
-
'target_os="android"'
|
|
76
|
-
'strip_debug_info=%s',
|
|
67
|
+
'target_os="android"'
|
|
77
68
|
]
|
|
78
69
|
GN_ANDROID_ARGS = build_gn_args(_GN_ANDROID_ARGS)
|
|
79
70
|
|
|
80
71
|
|
|
81
72
|
# Utilities
|
|
82
73
|
|
|
83
|
-
def sh(cmd, env=None):
|
|
74
|
+
def sh(cmd, env=None, cwd=None):
|
|
84
75
|
print('Running cmd: %s' % cmd)
|
|
85
76
|
try:
|
|
86
|
-
subprocess.check_call(cmd, env=env, shell=True, stdin=sys.stdin, stdout=sys.stdout, stderr=subprocess.STDOUT)
|
|
77
|
+
subprocess.check_call(cmd, env=env, cwd=cwd, shell=True, stdin=sys.stdin, stdout=sys.stdout, stderr=subprocess.STDOUT)
|
|
87
78
|
except subprocess.CalledProcessError as e:
|
|
88
79
|
sys.exit(e.returncode)
|
|
89
80
|
except KeyboardInterrupt:
|
|
@@ -191,33 +182,35 @@ def build(target_dir, platform, debug):
|
|
|
191
182
|
|
|
192
183
|
# Run GN
|
|
193
184
|
if platform == 'ios':
|
|
185
|
+
for item in IOS_BUILD_ARCHS:
|
|
186
|
+
tenv, arch = item.split(':')
|
|
187
|
+
gn_out_dir = 'out/%s-ios-%s-%s' % (build_type, tenv, arch)
|
|
188
|
+
gn_args = GN_IOS_ARGS % (str(debug).lower(), arch, tenv)
|
|
189
|
+
gn_cmd = 'gn gen %s %s' % (gn_out_dir, gn_args)
|
|
190
|
+
sh(gn_cmd, env)
|
|
194
191
|
for arch in MACOS_BUILD_ARCHS:
|
|
195
192
|
gn_out_dir = 'out/%s-macos-%s' % (build_type, arch)
|
|
196
193
|
gn_args = GN_MACOS_ARGS % (str(debug).lower(), arch)
|
|
197
194
|
gn_cmd = 'gn gen %s %s' % (gn_out_dir, gn_args)
|
|
198
195
|
sh(gn_cmd, env)
|
|
199
|
-
for arch in IOS_BUILD_ARCHS:
|
|
200
|
-
gn_out_dir = 'out/%s-ios-%s' % (build_type, arch)
|
|
201
|
-
gn_args = GN_IOS_ARGS % (str(debug).lower(), arch)
|
|
202
|
-
gn_cmd = 'gn gen %s %s' % (gn_out_dir, gn_args)
|
|
203
|
-
sh(gn_cmd, env)
|
|
204
196
|
else:
|
|
205
197
|
for cpu in ANDROID_BUILD_CPUS:
|
|
206
198
|
gn_out_dir = 'out/%s-%s' % (build_type, cpu)
|
|
207
|
-
gn_args = GN_ANDROID_ARGS % (str(debug).lower(), cpu
|
|
199
|
+
gn_args = GN_ANDROID_ARGS % (str(debug).lower(), cpu)
|
|
208
200
|
gn_cmd = 'gn gen %s %s' % (gn_out_dir, gn_args)
|
|
209
201
|
sh(gn_cmd, env)
|
|
210
202
|
|
|
211
203
|
# Build with Ninja
|
|
212
204
|
if platform == 'ios':
|
|
205
|
+
for item in IOS_BUILD_ARCHS:
|
|
206
|
+
tenv, arch = item.split(':')
|
|
207
|
+
gn_out_dir = 'out/%s-ios-%s-%s' % (build_type, tenv, arch)
|
|
208
|
+
ninja_cmd = 'ninja -C %s framework_objc' % gn_out_dir
|
|
209
|
+
sh(ninja_cmd, env)
|
|
213
210
|
for arch in MACOS_BUILD_ARCHS:
|
|
214
211
|
gn_out_dir = 'out/%s-macos-%s' % (build_type, arch)
|
|
215
212
|
ninja_cmd = 'ninja -C %s mac_framework_objc' % gn_out_dir
|
|
216
213
|
sh(ninja_cmd, env)
|
|
217
|
-
for arch in IOS_BUILD_ARCHS:
|
|
218
|
-
gn_out_dir = 'out/%s-ios-%s' % (build_type, arch)
|
|
219
|
-
ninja_cmd = 'ninja -C %s framework_objc' % gn_out_dir
|
|
220
|
-
sh(ninja_cmd, env)
|
|
221
214
|
else:
|
|
222
215
|
for cpu in ANDROID_BUILD_CPUS:
|
|
223
216
|
gn_out_dir = 'out/%s-%s' % (build_type, cpu)
|
|
@@ -230,37 +223,57 @@ def build(target_dir, platform, debug):
|
|
|
230
223
|
|
|
231
224
|
# Copy build artifacts to build directory
|
|
232
225
|
if platform == 'ios':
|
|
226
|
+
# Fat simulators (we need a single slice for both simulators)
|
|
227
|
+
simulators = [item for item in IOS_BUILD_ARCHS if item.startswith('simulator')]
|
|
228
|
+
tenv, arch = simulators[0].split(':')
|
|
229
|
+
gn_out_dir = 'out/%s-ios-%s-%s' % (build_type, tenv, arch)
|
|
230
|
+
shutil.copytree(os.path.join(gn_out_dir, 'WebRTC.framework'), os.path.join(gn_out_dir, 'fat-WebRTC.framework'))
|
|
231
|
+
out_lib_path = os.path.join(gn_out_dir, 'fat-WebRTC.framework', 'WebRTC')
|
|
232
|
+
slice_paths = []
|
|
233
|
+
for item in simulators:
|
|
234
|
+
tenv, arch = item.split(':')
|
|
235
|
+
lib_path = os.path.join('out/%s-ios-%s-%s' % (build_type, tenv, arch), 'WebRTC.framework', 'WebRTC')
|
|
236
|
+
slice_paths.append(lib_path)
|
|
237
|
+
sh('lipo %s -create -output %s' % (' '.join(slice_paths), out_lib_path))
|
|
238
|
+
|
|
239
|
+
orig_framework_path = os.path.join(gn_out_dir, 'WebRTC.framework')
|
|
240
|
+
bak_framework_path = os.path.join(gn_out_dir, 'bak-WebRTC.framework')
|
|
241
|
+
fat_framework_path = os.path.join(gn_out_dir, 'fat-WebRTC.framework')
|
|
242
|
+
shutil.move(orig_framework_path, bak_framework_path)
|
|
243
|
+
shutil.move(fat_framework_path, orig_framework_path)
|
|
244
|
+
|
|
245
|
+
_IOS_BUILD_ARCHS = [item for item in IOS_BUILD_ARCHS if not item.startswith('simulator')]
|
|
246
|
+
_IOS_BUILD_ARCHS.append(simulators[0])
|
|
247
|
+
|
|
233
248
|
# XCFramework
|
|
234
|
-
|
|
249
|
+
xcframework_path = os.path.join(build_dir, 'WebRTC.xcframework')
|
|
250
|
+
xcodebuild_cmd = 'xcodebuild -create-xcframework -output %s' % xcframework_path
|
|
251
|
+
for item in _IOS_BUILD_ARCHS:
|
|
252
|
+
tenv, arch = item.split(':')
|
|
253
|
+
gn_out_dir = 'out/%s-ios-%s-%s' % (build_type, tenv, arch)
|
|
254
|
+
xcodebuild_cmd += ' -framework %s' % os.path.join(gn_out_dir, 'WebRTC.framework')
|
|
235
255
|
for arch in MACOS_BUILD_ARCHS:
|
|
236
256
|
gn_out_dir = 'out/%s-macos-%s' % (build_type, arch)
|
|
237
257
|
xcodebuild_cmd += ' -framework %s' % os.path.join(gn_out_dir, 'WebRTC.framework')
|
|
238
|
-
for arch in IOS_BUILD_ARCHS:
|
|
239
|
-
gn_out_dir = 'out/%s-ios-%s' % (build_type, arch)
|
|
240
|
-
xcodebuild_cmd += ' -framework %s' % os.path.join(gn_out_dir, 'WebRTC.framework')
|
|
241
258
|
sh(xcodebuild_cmd)
|
|
259
|
+
sh('tar zcf WebRTC.xcframework-bitcode.tgz WebRTC.xcframework', cwd=build_dir)
|
|
260
|
+
rmr(xcframework_path)
|
|
242
261
|
|
|
243
262
|
# XCFramework (stripped)
|
|
244
|
-
xcodebuild_cmd = 'xcodebuild -create-xcframework -output %s' %
|
|
263
|
+
xcodebuild_cmd = 'xcodebuild -create-xcframework -output %s' % xcframework_path
|
|
245
264
|
bitcode_strip_cmd = 'xcrun bitcode_strip -r %s -o %s'
|
|
246
|
-
for
|
|
247
|
-
|
|
265
|
+
for item in _IOS_BUILD_ARCHS:
|
|
266
|
+
tenv, arch = item.split(':')
|
|
267
|
+
gn_out_dir = 'out/%s-ios-%s-%s' % (build_type, tenv, arch)
|
|
248
268
|
xcodebuild_cmd += ' -framework %s' % os.path.join(gn_out_dir, 'WebRTC.framework')
|
|
249
|
-
for arch in IOS_BUILD_ARCHS:
|
|
250
|
-
gn_out_dir = 'out/%s-ios-%s' % (build_type, arch)
|
|
251
269
|
framework_path = os.path.join(gn_out_dir, 'WebRTC.framework', 'WebRTC')
|
|
252
270
|
sh(bitcode_strip_cmd % (framework_path, framework_path))
|
|
253
|
-
xcodebuild_cmd += ' -framework %s' % os.path.join(gn_out_dir, 'WebRTC.framework')
|
|
254
|
-
sh(xcodebuild_cmd)
|
|
255
|
-
|
|
256
|
-
# dSYMs
|
|
257
|
-
dsyms_dir = os.path.join(build_dir, 'WebRTC.dSYMs')
|
|
258
271
|
for arch in MACOS_BUILD_ARCHS:
|
|
259
272
|
gn_out_dir = 'out/%s-macos-%s' % (build_type, arch)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
273
|
+
xcodebuild_cmd += ' -framework %s' % os.path.join(gn_out_dir, 'WebRTC.framework')
|
|
274
|
+
sh(xcodebuild_cmd)
|
|
275
|
+
sh('tar zcf WebRTC.xcframework.tgz WebRTC.xcframework', cwd=build_dir)
|
|
276
|
+
rmr(xcframework_path)
|
|
264
277
|
else:
|
|
265
278
|
gn_out_dir = 'out/%s-%s' % (build_type, ANDROID_BUILD_CPUS[0])
|
|
266
279
|
shutil.copy(os.path.join(gn_out_dir, 'lib.java/sdk/android/libwebrtc.jar'), build_dir)
|
|
@@ -271,9 +284,9 @@ def build(target_dir, platform, debug):
|
|
|
271
284
|
gn_out_dir = 'out/%s-%s' % (build_type, cpu)
|
|
272
285
|
shutil.copy(os.path.join(gn_out_dir, 'libjingle_peerconnection_so.so'), lib_dir)
|
|
273
286
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
287
|
+
sh('jar cvfM libjingle_peerconnection.so.jar lib', cwd=build_dir)
|
|
288
|
+
rmr(os.path.join(build_dir, 'lib'))
|
|
289
|
+
sh('tar zcf android-webrtc.tgz *.jar', cwd=build_dir)
|
|
277
290
|
|
|
278
291
|
|
|
279
292
|
if __name__ == "__main__":
|
|
@@ -325,4 +338,3 @@ if __name__ == "__main__":
|
|
|
325
338
|
build(target_dir, platform, args.debug)
|
|
326
339
|
print('WebRTC build for %s completed in %s' % (platform, target_dir))
|
|
327
340
|
sys.exit(0)
|
|
328
|
-
|
package/tools/downloadBitcode.sh
CHANGED
|
@@ -3,24 +3,12 @@
|
|
|
3
3
|
set -euo pipefail
|
|
4
4
|
|
|
5
5
|
THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
|
|
6
|
-
PACKAGE_VERSION=$(cat "${THIS_DIR}/../package.json" \
|
|
7
|
-
| grep "\"version\":" \
|
|
8
|
-
| head -1 \
|
|
9
|
-
| awk -F: '{ print $2 }' \
|
|
10
|
-
| sed 's/[",]//g' \
|
|
11
|
-
| tr -d '[[:space:]]')
|
|
12
|
-
WEBRTC_DL="https://github.com/react-native-webrtc/react-native-webrtc/releases/download/${PACKAGE_VERSION}/WebRTC.tar.xz"
|
|
13
6
|
|
|
7
|
+
pushd ${THIS_DIR}
|
|
14
8
|
|
|
15
|
-
|
|
9
|
+
export RN_WEBRTC_BITCODE=1
|
|
10
|
+
export RN_WEBRTC_FORCE_DOWNLOAD=1
|
|
16
11
|
|
|
17
|
-
|
|
18
|
-
rm -rf WebRTC.xcframework WebRTC.dSYMs
|
|
19
|
-
|
|
20
|
-
# Download
|
|
21
|
-
echo "Downloading files..."
|
|
22
|
-
echo $PACKAGE_VERSION
|
|
23
|
-
curl -L -s ${WEBRTC_DL} | tar Jxf -
|
|
24
|
-
echo "Done!"
|
|
12
|
+
node downloadWebRTC.js
|
|
25
13
|
|
|
26
14
|
popd
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const https = require('https');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const process = require('process');
|
|
6
|
+
const tar = require('tar');
|
|
7
|
+
|
|
8
|
+
const pkg = require('../package.json');
|
|
9
|
+
const builds = pkg['webrtc-builds'];
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
async function download(url, filePath) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const request = https.get(url, response => {
|
|
15
|
+
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
16
|
+
resolve(download(response.headers.location, filePath));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (response.statusCode !== 200) {
|
|
21
|
+
reject(new Error(`Failed to get '${url}' (${response.statusCode})`));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const file = fs.createWriteStream(filePath);
|
|
26
|
+
|
|
27
|
+
file.on('finish', () => resolve());
|
|
28
|
+
|
|
29
|
+
file.on('error', err => {
|
|
30
|
+
fs.unlink(filePath, () => reject(err));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
response.pipe(file);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
request.on('error', err => {
|
|
37
|
+
fs.unlink(filePath, () => reject(err));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
request.end();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
(async () => {
|
|
45
|
+
if (process.env.RN_WEBRTC_SKIP_DOWNLOAD) {
|
|
46
|
+
console.log('Skipping WebRTC build downloads')
|
|
47
|
+
return process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const items = [];
|
|
51
|
+
|
|
52
|
+
// iOS
|
|
53
|
+
//
|
|
54
|
+
|
|
55
|
+
if (process.platform === 'darwin') {
|
|
56
|
+
const bitcode = process.env.RN_WEBRTC_BITCODE;
|
|
57
|
+
const url = bitcode ? builds['ios-bitcode'] : builds['ios'];
|
|
58
|
+
|
|
59
|
+
items.push({
|
|
60
|
+
url,
|
|
61
|
+
dstFileName: 'WebRTC.xcframework.tgz',
|
|
62
|
+
dstDir: `${__dirname}/../apple/`
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Android
|
|
67
|
+
//
|
|
68
|
+
|
|
69
|
+
items.push({
|
|
70
|
+
url: builds['android'],
|
|
71
|
+
dstFileName: 'android-webrtc.tgz',
|
|
72
|
+
dstDir: `${__dirname}/../android/libs/`
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Download them all!
|
|
76
|
+
//
|
|
77
|
+
|
|
78
|
+
for (const item of items) {
|
|
79
|
+
const { url, dstFileName, dstDir } = item;
|
|
80
|
+
const dstPath = path.join(dstDir, dstFileName);
|
|
81
|
+
|
|
82
|
+
if (fs.existsSync(dstPath) && process.env.RN_WEBRTC_FORCE_DOWNLOAD) {
|
|
83
|
+
console.log('Removing previously downloaded file')
|
|
84
|
+
fs.rmSync(dstPath);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
console.log(`Downloading ${url}...`);
|
|
88
|
+
|
|
89
|
+
await download(url, dstPath);
|
|
90
|
+
|
|
91
|
+
tar.extract({
|
|
92
|
+
file: dstPath,
|
|
93
|
+
cwd: dstDir,
|
|
94
|
+
sync: true,
|
|
95
|
+
strict: true
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
console.log('Done!');
|
|
99
|
+
}
|
|
100
|
+
})();
|
package/MediaStream.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import {NativeModules} from 'react-native';
|
|
4
|
-
import EventTarget from 'event-target-shim';
|
|
5
|
-
import uuid from 'uuid';
|
|
6
|
-
|
|
7
|
-
import MediaStreamTrack from './MediaStreamTrack';
|
|
8
|
-
|
|
9
|
-
const {WebRTCModule} = NativeModules;
|
|
10
|
-
|
|
11
|
-
const MEDIA_STREAM_EVENTS = [
|
|
12
|
-
'active',
|
|
13
|
-
'inactive',
|
|
14
|
-
'addtrack',
|
|
15
|
-
'removetrack',
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
export default class MediaStream extends EventTarget(MEDIA_STREAM_EVENTS) {
|
|
19
|
-
id: string;
|
|
20
|
-
active: boolean = true;
|
|
21
|
-
|
|
22
|
-
onactive: ?Function;
|
|
23
|
-
oninactive: ?Function;
|
|
24
|
-
onaddtrack: ?Function;
|
|
25
|
-
onremovetrack: ?Function;
|
|
26
|
-
|
|
27
|
-
_tracks: Array<MediaStreamTrack> = [];
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The identifier of this MediaStream unique within the associated
|
|
31
|
-
* WebRTCModule instance. As the id of a remote MediaStream instance is unique
|
|
32
|
-
* only within the associated RTCPeerConnection, it is not sufficiently unique
|
|
33
|
-
* to identify this MediaStream across multiple RTCPeerConnections and to
|
|
34
|
-
* unambiguously differentiate it from a local MediaStream instance not added
|
|
35
|
-
* to an RTCPeerConnection.
|
|
36
|
-
*/
|
|
37
|
-
_reactTag: string;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* A MediaStream can be constructed in several ways, depending on the paramters
|
|
41
|
-
* that are passed here.
|
|
42
|
-
*
|
|
43
|
-
* - undefined: just a new stream, with no tracks.
|
|
44
|
-
* - MediaStream instance: a new stream, with a copy of the tracks of the passed stream.
|
|
45
|
-
* - Array of MediaStreamTrack: a new stream with a copy of the tracks in the array.
|
|
46
|
-
* - object: a new stream instance, represented by the passed info object, this is always
|
|
47
|
-
* done internally, when the stream is first created in native and the JS wrapper is
|
|
48
|
-
* built afterwards.
|
|
49
|
-
*/
|
|
50
|
-
constructor(arg) {
|
|
51
|
-
super();
|
|
52
|
-
|
|
53
|
-
// Assigm a UUID to start with. It may get overridden for remote streams.
|
|
54
|
-
this.id = uuid.v4();
|
|
55
|
-
// Local MediaStreams are created by WebRTCModule to have their id and
|
|
56
|
-
// reactTag equal because WebRTCModule follows the respective standard's
|
|
57
|
-
// recommendation for id generation i.e. uses UUID which is unique enough
|
|
58
|
-
// for the purposes of reactTag.
|
|
59
|
-
this._reactTag = this.id;
|
|
60
|
-
|
|
61
|
-
if (typeof arg === 'undefined') {
|
|
62
|
-
WebRTCModule.mediaStreamCreate(this.id);
|
|
63
|
-
} else if (arg instanceof MediaStream) {
|
|
64
|
-
WebRTCModule.mediaStreamCreate(this.id);
|
|
65
|
-
for (const track of arg.getTracks()) {
|
|
66
|
-
this.addTrack(track);
|
|
67
|
-
}
|
|
68
|
-
} else if (Array.isArray(arg)) {
|
|
69
|
-
WebRTCModule.mediaStreamCreate(this.id);
|
|
70
|
-
for (const track of arg) {
|
|
71
|
-
this.addTrack(track);
|
|
72
|
-
}
|
|
73
|
-
} else if (typeof arg === 'object' && arg.streamId && arg.streamReactTag && arg.tracks) {
|
|
74
|
-
this.id = arg.streamId;
|
|
75
|
-
this._reactTag = arg.streamReactTag;
|
|
76
|
-
for (const trackInfo of arg.tracks) {
|
|
77
|
-
// We are not using addTrack here because the track is already part of the
|
|
78
|
-
// stream, so there is no need to add it on the native side.
|
|
79
|
-
this._tracks.push(new MediaStreamTrack(trackInfo));
|
|
80
|
-
}
|
|
81
|
-
} else {
|
|
82
|
-
throw new TypeError(`invalid type: ${typeof arg}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
addTrack(track: MediaStreamTrack) {
|
|
87
|
-
const index = this._tracks.indexOf(track);
|
|
88
|
-
if (index !== -1) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
this._tracks.push(track);
|
|
92
|
-
WebRTCModule.mediaStreamAddTrack(this._reactTag, track.id);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
removeTrack(track: MediaStreamTrack) {
|
|
96
|
-
const index = this._tracks.indexOf(track);
|
|
97
|
-
if (index === -1) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
this._tracks.splice(index, 1);
|
|
101
|
-
WebRTCModule.mediaStreamRemoveTrack(this._reactTag, track.id);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
getTracks(): Array<MediaStreamTrack> {
|
|
105
|
-
return this._tracks.slice();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
getTrackById(trackId): ?MediaStreamTrack {
|
|
109
|
-
return this._tracks.find(track => track.id === trackId);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
getAudioTracks(): Array<MediaStreamTrack> {
|
|
113
|
-
return this._tracks.filter(track => track.kind === 'audio');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
getVideoTracks(): Array<MediaStreamTrack> {
|
|
117
|
-
return this._tracks.filter(track => track.kind === 'video');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
clone() {
|
|
121
|
-
throw new Error('Not implemented.');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
toURL() {
|
|
125
|
-
return this._reactTag;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
release(releaseTracks = true) {
|
|
129
|
-
for (const track of this._tracks) {
|
|
130
|
-
this.removeTrack(track);
|
|
131
|
-
if (releaseTracks) {
|
|
132
|
-
track.release();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
WebRTCModule.mediaStreamRelease(this._reactTag);
|
|
137
|
-
}
|
|
138
|
-
}
|
package/MediaStreamError.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
export default class MediaStreamError {
|
|
4
|
-
|
|
5
|
-
name: string;
|
|
6
|
-
message: ?string;
|
|
7
|
-
constraintName: ?string;
|
|
8
|
-
|
|
9
|
-
constructor(error) {
|
|
10
|
-
this.name = error.name;
|
|
11
|
-
this.message = error.message;
|
|
12
|
-
this.constraintName = error.constraintName;
|
|
13
|
-
}
|
|
14
|
-
}
|
package/MediaStreamErrorEvent.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import type MediaStreamError from './MediaStreamError';
|
|
4
|
-
|
|
5
|
-
export default class MediaStreamErrorEvent {
|
|
6
|
-
type: string;
|
|
7
|
-
error: ?MediaStreamError;
|
|
8
|
-
constructor(type, eventInitDict) {
|
|
9
|
-
this.type = type.toString();
|
|
10
|
-
Object.assign(this, eventInitDict);
|
|
11
|
-
}
|
|
12
|
-
}
|
package/MediaStreamEvent.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import type MediaStream from './MediaStream';
|
|
4
|
-
|
|
5
|
-
export default class MediaStreamEvent {
|
|
6
|
-
type: string;
|
|
7
|
-
stream: MediaStream;
|
|
8
|
-
constructor(type, eventInitDict) {
|
|
9
|
-
this.type = type.toString();
|
|
10
|
-
Object.assign(this, eventInitDict);
|
|
11
|
-
}
|
|
12
|
-
}
|