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.
Files changed (67) hide show
  1. package/.prettierignore +9 -0
  2. package/.prettierrc.json +10 -0
  3. package/README.md +2 -2
  4. package/android/libs/.placeholder +0 -0
  5. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +21 -8
  6. package/android/src/main/java/com/oney/WebRTCModule/StringUtils.java +24 -0
  7. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +199 -255
  8. package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +10 -2
  9. package/apple/.placeholder +0 -0
  10. package/ios/RCTWebRTC/VideoCaptureController.h +2 -2
  11. package/ios/RCTWebRTC/VideoCaptureController.m +131 -48
  12. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +39 -20
  13. package/metro.config.js +3 -4
  14. package/metro.config.macos.js +7 -8
  15. package/package.json +20 -12
  16. package/react-native.config.js +5 -6
  17. package/{EventEmitter.js → src/EventEmitter.js} +1 -1
  18. package/{MediaDevices.js → src/MediaDevices.js} +6 -12
  19. package/src/MediaStream.js +128 -0
  20. package/src/MediaStreamError.js +12 -0
  21. package/src/MediaStreamErrorEvent.js +11 -0
  22. package/src/MediaStreamEvent.js +11 -0
  23. package/src/MediaStreamTrack.js +104 -0
  24. package/src/MediaStreamTrackEvent.js +11 -0
  25. package/src/MessageEvent.js +10 -0
  26. package/{Permissions.js → src/Permissions.js} +26 -23
  27. package/src/RTCDataChannel.js +143 -0
  28. package/src/RTCDataChannelEvent.js +11 -0
  29. package/src/RTCEvent.js +8 -0
  30. package/src/RTCIceCandidate.js +20 -0
  31. package/src/RTCIceCandidateEvent.js +15 -0
  32. package/src/RTCPeerConnection.js +349 -0
  33. package/src/RTCSessionDescription.js +22 -0
  34. package/{RTCUtil.js → src/RTCUtil.js} +77 -57
  35. package/src/RTCView.js +60 -0
  36. package/src/ScreenCapturePickerView.js +4 -0
  37. package/{getDisplayMedia.js → src/getDisplayMedia.js} +7 -6
  38. package/src/getUserMedia.js +98 -0
  39. package/src/index.js +44 -0
  40. package/tools/build-webrtc.py +61 -49
  41. package/tools/downloadBitcode.sh +4 -16
  42. package/tools/downloadWebRTC.js +100 -0
  43. package/MediaStream.js +0 -138
  44. package/MediaStreamError.js +0 -14
  45. package/MediaStreamErrorEvent.js +0 -12
  46. package/MediaStreamEvent.js +0 -12
  47. package/MediaStreamTrack.js +0 -118
  48. package/MediaStreamTrackEvent.js +0 -12
  49. package/MessageEvent.js +0 -11
  50. package/RTCDataChannel.js +0 -161
  51. package/RTCDataChannelEvent.js +0 -12
  52. package/RTCEvent.js +0 -9
  53. package/RTCIceCandidate.js +0 -21
  54. package/RTCIceCandidateEvent.js +0 -16
  55. package/RTCPeerConnection.js +0 -379
  56. package/RTCSessionDescription.js +0 -23
  57. package/RTCView.js +0 -70
  58. package/ScreenCapturePickerView.js +0 -7
  59. package/android/libs/libjingle_peerconnection.so.jar +0 -0
  60. package/android/libs/libwebrtc.jar +0 -0
  61. package/apple/WebRTC.xcframework.tgz +0 -0
  62. package/getUserMedia.js +0 -98
  63. package/index.js +0 -50
  64. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  65. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  66. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  67. package/ios/RCTWebRTC.xcodeproj/xcuserdata/saghul.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
@@ -0,0 +1,104 @@
1
+
2
+ import { NativeModules } from 'react-native';
3
+ import { defineCustomEventTarget } from 'event-target-shim';
4
+
5
+ import { deepClone } from './RTCUtil';
6
+
7
+ const { WebRTCModule } = NativeModules;
8
+
9
+ const MEDIA_STREAM_TRACK_EVENTS = ['ended', 'mute', 'unmute'];
10
+
11
+ type MediaStreamTrackState = 'live' | 'ended';
12
+
13
+ class MediaStreamTrack extends defineCustomEventTarget(...MEDIA_STREAM_TRACK_EVENTS) {
14
+ _constraints: Object;
15
+ _enabled: boolean;
16
+ _settings: Object;
17
+
18
+ id: string;
19
+ kind: string;
20
+ label: string;
21
+ muted: boolean;
22
+ // readyState in java: INITIALIZING, LIVE, ENDED, FAILED
23
+ readyState: MediaStreamTrackState;
24
+ remote: boolean;
25
+
26
+ constructor(info) {
27
+ super();
28
+
29
+ this._constraints = info.constraints || {};
30
+ this._enabled = info.enabled;
31
+ this._settings = info.settings || {};
32
+
33
+ this.id = info.id;
34
+ this.kind = info.kind;
35
+ this.label = info.label;
36
+ this.muted = false;
37
+ this.remote = info.remote;
38
+
39
+ const _readyState = info.readyState.toLowerCase();
40
+ this.readyState = _readyState === 'initializing' || _readyState === 'live' ? 'live' : 'ended';
41
+ }
42
+
43
+ get enabled(): boolean {
44
+ return this._enabled;
45
+ }
46
+
47
+ set enabled(enabled: boolean): void {
48
+ if (enabled === this._enabled) {
49
+ return;
50
+ }
51
+ WebRTCModule.mediaStreamTrackSetEnabled(this.id, !this._enabled);
52
+ this._enabled = !this._enabled;
53
+ this.muted = !this._enabled;
54
+ }
55
+
56
+ stop() {
57
+ WebRTCModule.mediaStreamTrackSetEnabled(this.id, false);
58
+ this.readyState = 'ended';
59
+ // TODO: save some stopped flag?
60
+ }
61
+
62
+ /**
63
+ * Private / custom API for switching the cameras on the fly, without the
64
+ * need for adding / removing tracks or doing any SDP renegotiation.
65
+ *
66
+ * This is how the reference application (AppRTCMobile) implements camera
67
+ * switching.
68
+ */
69
+ _switchCamera() {
70
+ if (this.remote) {
71
+ throw new Error('Not implemented for remote tracks');
72
+ }
73
+ if (this.kind !== 'video') {
74
+ throw new Error('Only implemented for video tracks');
75
+ }
76
+ WebRTCModule.mediaStreamTrackSwitchCamera(this.id);
77
+ }
78
+
79
+ applyConstraints() {
80
+ throw new Error('Not implemented.');
81
+ }
82
+
83
+ clone() {
84
+ throw new Error('Not implemented.');
85
+ }
86
+
87
+ getCapabilities() {
88
+ throw new Error('Not implemented.');
89
+ }
90
+
91
+ getConstraints() {
92
+ return deepClone(this._constraints);
93
+ }
94
+
95
+ getSettings() {
96
+ return deepClone(this._settings);
97
+ }
98
+
99
+ release() {
100
+ WebRTCModule.mediaStreamTrackRelease(this.id);
101
+ }
102
+ }
103
+
104
+ export default MediaStreamTrack;
@@ -0,0 +1,11 @@
1
+
2
+ import type MediaStreamTrack from './MediaStreamTrack';
3
+
4
+ export default class MediaStreamTrackEvent {
5
+ type: string;
6
+ track: MediaStreamTrack;
7
+ constructor(type, eventInitDict) {
8
+ this.type = type.toString();
9
+ Object.assign(this, eventInitDict);
10
+ }
11
+ }
@@ -0,0 +1,10 @@
1
+
2
+ export default class MessageEvent {
3
+ type: string;
4
+ data: string | ArrayBuffer | Blob;
5
+ origin: string;
6
+ constructor(type, eventInitDict) {
7
+ this.type = type.toString();
8
+ Object.assign(this, eventInitDict);
9
+ }
10
+ }
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
 
3
2
  import { NativeModules, PermissionsAndroid, Platform } from 'react-native';
4
3
 
@@ -8,8 +7,8 @@ const { WebRTCModule } = NativeModules;
8
7
  * Type declaration for a permissions descriptor.
9
8
  */
10
9
  type PermissionDescriptor = {
11
- name: string;
12
- }
10
+ name: string
11
+ };
13
12
 
14
13
  /**
15
14
  * Class implementing a subset of W3C's Permissions API as defined by:
@@ -30,7 +29,7 @@ class Permissions {
30
29
  * This implementation only supports requesting these permissions, a subset
31
30
  * of: https://www.w3.org/TR/permissions/#permission-registry
32
31
  */
33
- VALID_PERMISSIONS = [ 'camera', 'microphone' ];
32
+ VALID_PERMISSIONS = ['camera', 'microphone'];
34
33
 
35
34
  _lastReq = Promise.resolve();
36
35
 
@@ -39,7 +38,7 @@ class Permissions {
39
38
  * can be requested at a time (unless the multi-permission API is used,
40
39
  * but we are not using that for symmetry with the W3C API for querying)
41
40
  * so we'll queue them up.
42
- *
41
+ *
43
42
  * @param {string} perm - The requested permission from
44
43
  * {@link PermissionsAndroid.PERMISSIONS}
45
44
  * https://facebook.github.io/react-native/docs/permissionsandroid#permissions-that-require-prompting-the-user
@@ -48,7 +47,8 @@ class Permissions {
48
47
  return new Promise((resolve, reject) => {
49
48
  PermissionsAndroid.request(perm).then(
50
49
  granted => resolve(granted === true || granted === PermissionsAndroid.RESULTS.GRANTED),
51
- () => resolve(false));
50
+ () => resolve(false)
51
+ );
52
52
  });
53
53
  }
54
54
 
@@ -56,14 +56,16 @@ class Permissions {
56
56
  * Validates the given permission descriptor.
57
57
  */
58
58
  _validatePermissionDescriptior(permissionDesc) {
59
- if (typeof permissionDesc !== "object") {
60
- throw new TypeError("Argument 1 of Permissions.query is not an object.");
59
+ if (typeof permissionDesc !== 'object') {
60
+ throw new TypeError('Argument 1 of Permissions.query is not an object.');
61
61
  }
62
- if (typeof permissionDesc.name === "undefined") {
62
+ if (typeof permissionDesc.name === 'undefined') {
63
63
  throw new TypeError("Missing required 'name' member of PermissionDescriptor.");
64
64
  }
65
65
  if (this.VALID_PERMISSIONS.indexOf(permissionDesc.name) === -1) {
66
- throw new TypeError("'name' member of PermissionDescriptor is not a valid value for enumeration PermissionName.");
66
+ throw new TypeError(
67
+ "'name' member of PermissionDescriptor is not a valid value for enumeration PermissionName."
68
+ );
67
69
  }
68
70
  }
69
71
 
@@ -78,18 +80,20 @@ class Permissions {
78
80
  return Promise.reject(e);
79
81
  }
80
82
  if (Platform.OS === 'android') {
81
- const perm = permissionDesc.name === 'camera'
82
- ? PermissionsAndroid.PERMISSIONS.CAMERA
83
- : PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;
83
+ const perm =
84
+ permissionDesc.name === 'camera'
85
+ ? PermissionsAndroid.PERMISSIONS.CAMERA
86
+ : PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;
84
87
  return new Promise((resolve, reject) => {
85
88
  PermissionsAndroid.check(perm).then(
86
89
  granted => resolve(granted ? this.RESULT.GRANTED : this.RESULT.PROMPT),
87
- () => resolve(this.RESULT.PROMPT));
90
+ () => resolve(this.RESULT.PROMPT)
91
+ );
88
92
  });
89
93
  } else if (Platform.OS === 'ios' || Platform.OS === 'macos') {
90
94
  return WebRTCModule.checkPermission(permissionDesc.name);
91
95
  } else {
92
- return Promise.reject(new TypeError("Unsupported platform."));
96
+ return Promise.reject(new TypeError('Unsupported platform.'));
93
97
  }
94
98
  }
95
99
 
@@ -104,18 +108,17 @@ class Permissions {
104
108
  return Promise.reject(e);
105
109
  }
106
110
  if (Platform.OS === 'android') {
107
- const perm = permissionDesc.name === 'camera'
108
- ? PermissionsAndroid.PERMISSIONS.CAMERA
109
- : PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;
110
- const requestPermission
111
- = () => this._requestPermissionAndroid(perm);
112
- this._lastReq
113
- = this._lastReq.then(requestPermission, requestPermission);
111
+ const perm =
112
+ permissionDesc.name === 'camera'
113
+ ? PermissionsAndroid.PERMISSIONS.CAMERA
114
+ : PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;
115
+ const requestPermission = () => this._requestPermissionAndroid(perm);
116
+ this._lastReq = this._lastReq.then(requestPermission, requestPermission);
114
117
  return this._lastReq;
115
118
  } else if (Platform.OS === 'ios' || Platform.OS === 'macos') {
116
119
  return WebRTCModule.requestPermission(permissionDesc.name);
117
120
  } else {
118
- return Promise.reject(new TypeError("Unsupported platform."));
121
+ return Promise.reject(new TypeError('Unsupported platform.'));
119
122
  }
120
123
  }
121
124
  }
@@ -0,0 +1,143 @@
1
+
2
+ import { NativeModules } from 'react-native';
3
+ import base64 from 'base64-js';
4
+ import { defineCustomEventTarget } from 'event-target-shim';
5
+ import MessageEvent from './MessageEvent';
6
+ import RTCDataChannelEvent from './RTCDataChannelEvent';
7
+ import EventEmitter from './EventEmitter';
8
+
9
+ const { WebRTCModule } = NativeModules;
10
+
11
+ type RTCDataChannelState = 'connecting' | 'open' | 'closing' | 'closed';
12
+
13
+ const DATA_CHANNEL_EVENTS = ['open', 'message', 'bufferedamountlow', 'closing', 'close', 'error'];
14
+
15
+ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHANNEL_EVENTS) {
16
+ _peerConnectionId: number;
17
+ _reactTag: string;
18
+
19
+ _id: number;
20
+ _label: string;
21
+ _maxPacketLifeTime: ?number;
22
+ _maxRetransmits: ?number;
23
+ _negotiated: boolean;
24
+ _ordered: boolean;
25
+ _protocol: string;
26
+ _readyState: RTCDataChannelState;
27
+
28
+ binaryType: 'arraybuffer' = 'arraybuffer'; // we only support 'arraybuffer'
29
+ bufferedAmount: number = 0;
30
+ bufferedAmountLowThreshold: number = 0;
31
+
32
+ constructor(info) {
33
+ super();
34
+
35
+ this._peerConnectionId = info.peerConnectionId;
36
+ this._reactTag = info.reactTag;
37
+
38
+ this._label = info.label;
39
+ this._id = info.id === -1 ? null : info.id; // null until negotiated.
40
+ this._ordered = Boolean(info.ordered);
41
+ this._maxPacketLifeTime = info.maxPacketLifeTime;
42
+ this._maxRetransmits = info.maxRetransmits;
43
+ this._protocol = info.protocol || '';
44
+ this._negotiated = Boolean(info.negotiated);
45
+ this._readyState = info.readyState;
46
+
47
+ this._registerEvents();
48
+ }
49
+
50
+ get label(): string {
51
+ return this._label;
52
+ }
53
+
54
+ get id(): number {
55
+ return this._id;
56
+ }
57
+
58
+ get ordered(): boolean {
59
+ return this._ordered;
60
+ }
61
+
62
+ get maxPacketLifeTime(): number {
63
+ return this._maxPacketLifeTime;
64
+ }
65
+
66
+ get maxRetransmits(): number {
67
+ return this._maxRetransmits;
68
+ }
69
+
70
+ get protocol(): string {
71
+ return this._protocol;
72
+ }
73
+
74
+ get negotiated(): boolean {
75
+ return this._negotiated;
76
+ }
77
+
78
+ get readyState(): string {
79
+ return this._readyState;
80
+ }
81
+
82
+ send(data: string | ArrayBuffer | ArrayBufferView) {
83
+ if (typeof data === 'string') {
84
+ WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, data, 'text');
85
+ return;
86
+ }
87
+
88
+ // Safely convert the buffer object to an Uint8Array for base64-encoding
89
+ if (ArrayBuffer.isView(data)) {
90
+ data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
91
+ } else if (data instanceof ArrayBuffer) {
92
+ data = new Uint8Array(data);
93
+ } else {
94
+ throw new TypeError('Data must be either string, ArrayBuffer, or ArrayBufferView');
95
+ }
96
+ WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, base64.fromByteArray(data), 'binary');
97
+ }
98
+
99
+ close() {
100
+ if (this._readyState === 'closing' || this._readyState === 'closed') {
101
+ return;
102
+ }
103
+ WebRTCModule.dataChannelClose(this._peerConnectionId, this._reactTag);
104
+ }
105
+
106
+ _unregisterEvents() {
107
+ this._subscriptions.forEach(e => e.remove());
108
+ this._subscriptions = [];
109
+ }
110
+
111
+ _registerEvents() {
112
+ this._subscriptions = [
113
+ EventEmitter.addListener('dataChannelStateChanged', ev => {
114
+ if (ev.reactTag !== this._reactTag) {
115
+ return;
116
+ }
117
+ this._readyState = ev.state;
118
+ if (this._id === null && ev.id !== -1) {
119
+ this._id = ev.id;
120
+ }
121
+ if (this._readyState === 'open') {
122
+ this.dispatchEvent(new RTCDataChannelEvent('open', { channel: this }));
123
+ } else if (this._readyState === 'closing') {
124
+ this.dispatchEvent(new RTCDataChannelEvent('closing', { channel: this }));
125
+ } else if (this._readyState === 'closed') {
126
+ this.dispatchEvent(new RTCDataChannelEvent('close', { channel: this }));
127
+ this._unregisterEvents();
128
+ WebRTCModule.dataChannelDispose(this._peerConnectionId, this._reactTag);
129
+ }
130
+ }),
131
+ EventEmitter.addListener('dataChannelReceiveMessage', ev => {
132
+ if (ev.reactTag !== this._reactTag) {
133
+ return;
134
+ }
135
+ let data = ev.data;
136
+ if (ev.type === 'binary') {
137
+ data = base64.toByteArray(ev.data).buffer;
138
+ }
139
+ this.dispatchEvent(new MessageEvent('message', { data }));
140
+ })
141
+ ];
142
+ }
143
+ }
@@ -0,0 +1,11 @@
1
+
2
+ import type RTCDataChannel from './RTCDataChannel';
3
+
4
+ export default class RTCDataChannelEvent {
5
+ type: string;
6
+ channel: RTCDataChannel;
7
+ constructor(type, eventInitDict) {
8
+ this.type = type.toString();
9
+ Object.assign(this, eventInitDict);
10
+ }
11
+ }
@@ -0,0 +1,8 @@
1
+
2
+ export default class RTCEvent {
3
+ type: string;
4
+ constructor(type, eventInitDict) {
5
+ this.type = type.toString();
6
+ Object.assign(this, eventInitDict);
7
+ }
8
+ }
@@ -0,0 +1,20 @@
1
+
2
+ export default class RTCIceCandidate {
3
+ candidate: string;
4
+ sdpMLineIndex: number;
5
+ sdpMid: string;
6
+
7
+ constructor(info) {
8
+ this.candidate = info.candidate;
9
+ this.sdpMLineIndex = info.sdpMLineIndex;
10
+ this.sdpMid = info.sdpMid;
11
+ }
12
+
13
+ toJSON() {
14
+ return {
15
+ candidate: this.candidate,
16
+ sdpMLineIndex: this.sdpMLineIndex,
17
+ sdpMid: this.sdpMid
18
+ };
19
+ }
20
+ }
@@ -0,0 +1,15 @@
1
+
2
+ import type RTCIceCandidate from './RTCIceCandidate';
3
+
4
+ export default class RTCIceCandidateEvent {
5
+ type: string;
6
+ candidate: RTCIceCandidate;
7
+ constructor(type, eventInitDict) {
8
+ this.type = type.toString();
9
+
10
+ this.candidate = null;
11
+ if (eventInitDict && eventInitDict.candidate) {
12
+ this.candidate = eventInitDict.candidate;
13
+ }
14
+ }
15
+ }