react-native-webrtc 1.100.1 → 106.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ISSUE_TEMPLATE.md +17 -13
- package/README.md +46 -129
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +160 -165
- package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +279 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +361 -56
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +5 -1
- package/ios/RCTWebRTC/RCTConvert+WebRTC.m +2 -6
- package/ios/RCTWebRTC/ScreenCapturer.m +0 -1
- package/ios/RCTWebRTC/SerializeUtils.h +25 -0
- package/ios/RCTWebRTC/SerializeUtils.m +219 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +284 -128
- package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +216 -0
- package/ios/RCTWebRTC/WebRTCModule.h +15 -4
- package/ios/RCTWebRTC/WebRTCModule.m +26 -6
- package/lib/commonjs/EventEmitter.js +24 -0
- package/lib/commonjs/EventEmitter.js.map +1 -1
- package/lib/commonjs/Logger.js +65 -0
- package/lib/commonjs/Logger.js.map +1 -0
- package/lib/commonjs/MediaStream.js +1 -1
- package/lib/commonjs/MediaStream.js.map +1 -1
- package/lib/commonjs/MediaStreamTrack.js +4 -2
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/Permissions.js +1 -1
- package/lib/commonjs/Permissions.js.map +1 -1
- package/lib/commonjs/RTCDataChannel.js.map +1 -1
- package/lib/commonjs/RTCErrorEvent.js +33 -0
- package/lib/commonjs/RTCErrorEvent.js.map +1 -0
- package/lib/commonjs/RTCPeerConnection.js +354 -103
- package/lib/commonjs/RTCPeerConnection.js.map +1 -1
- package/lib/commonjs/RTCRtcpParameters.js +24 -0
- package/lib/commonjs/RTCRtcpParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpCapabilities.js +79 -0
- package/lib/commonjs/RTCRtpCapabilities.js.map +1 -0
- package/lib/commonjs/RTCRtpCodecCapability.js +25 -0
- package/lib/commonjs/RTCRtpCodecCapability.js.map +1 -0
- package/lib/commonjs/RTCRtpCodecParameters.js +33 -0
- package/lib/commonjs/RTCRtpCodecParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpEncodingParameters.js +81 -0
- package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpHeaderExtension.js +27 -0
- package/lib/commonjs/RTCRtpHeaderExtension.js.map +1 -0
- package/lib/commonjs/RTCRtpParameters.js +26 -0
- package/lib/commonjs/RTCRtpParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpReceiveParameters.js +20 -0
- package/lib/commonjs/RTCRtpReceiveParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpReceiver.js +51 -0
- package/lib/commonjs/RTCRtpReceiver.js.map +1 -0
- package/lib/commonjs/RTCRtpSendParameters.js +60 -0
- package/lib/commonjs/RTCRtpSendParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpSender.js +85 -0
- package/lib/commonjs/RTCRtpSender.js.map +1 -0
- package/lib/commonjs/RTCRtpTransceiver.js +141 -0
- package/lib/commonjs/RTCRtpTransceiver.js.map +1 -0
- package/lib/commonjs/RTCSessionDescription.js.map +1 -1
- package/lib/commonjs/RTCTrackEvent.js +32 -0
- package/lib/commonjs/RTCTrackEvent.js.map +1 -0
- package/lib/commonjs/RTCUtil.js +20 -37
- package/lib/commonjs/RTCUtil.js.map +1 -1
- package/lib/commonjs/getDisplayMedia.js.map +1 -1
- package/lib/commonjs/getUserMedia.js.map +1 -1
- package/lib/commonjs/index.js +127 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/EventEmitter.js +21 -0
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/Logger.js +53 -0
- package/lib/module/Logger.js.map +1 -0
- package/lib/module/MediaStream.js +1 -1
- package/lib/module/MediaStream.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +4 -2
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/Permissions.js +1 -1
- package/lib/module/Permissions.js.map +1 -1
- package/lib/module/RTCDataChannel.js.map +1 -1
- package/lib/module/RTCErrorEvent.js +22 -0
- package/lib/module/RTCErrorEvent.js.map +1 -0
- package/lib/module/RTCPeerConnection.js +348 -103
- package/lib/module/RTCPeerConnection.js.map +1 -1
- package/lib/module/RTCRtcpParameters.js +15 -0
- package/lib/module/RTCRtcpParameters.js.map +1 -0
- package/lib/module/RTCRtpCapabilities.js +63 -0
- package/lib/module/RTCRtpCapabilities.js.map +1 -0
- package/lib/module/RTCRtpCodecCapability.js +16 -0
- package/lib/module/RTCRtpCodecCapability.js.map +1 -0
- package/lib/module/RTCRtpCodecParameters.js +24 -0
- package/lib/module/RTCRtpCodecParameters.js.map +1 -0
- package/lib/module/RTCRtpEncodingParameters.js +72 -0
- package/lib/module/RTCRtpEncodingParameters.js.map +1 -0
- package/lib/module/RTCRtpHeaderExtension.js +18 -0
- package/lib/module/RTCRtpHeaderExtension.js.map +1 -0
- package/lib/module/RTCRtpParameters.js +17 -0
- package/lib/module/RTCRtpParameters.js.map +1 -0
- package/lib/module/RTCRtpReceiveParameters.js +8 -0
- package/lib/module/RTCRtpReceiveParameters.js.map +1 -0
- package/lib/module/RTCRtpReceiver.js +39 -0
- package/lib/module/RTCRtpReceiver.js.map +1 -0
- package/lib/module/RTCRtpSendParameters.js +49 -0
- package/lib/module/RTCRtpSendParameters.js.map +1 -0
- package/lib/module/RTCRtpSender.js +70 -0
- package/lib/module/RTCRtpSender.js.map +1 -0
- package/lib/module/RTCRtpTransceiver.js +125 -0
- package/lib/module/RTCRtpTransceiver.js.map +1 -0
- package/lib/module/RTCSessionDescription.js.map +1 -1
- package/lib/module/RTCTrackEvent.js +23 -0
- package/lib/module/RTCTrackEvent.js.map +1 -0
- package/lib/module/RTCUtil.js +18 -36
- package/lib/module/RTCUtil.js.map +1 -1
- package/lib/module/getDisplayMedia.js.map +1 -1
- package/lib/module/getUserMedia.js.map +1 -1
- package/lib/module/index.js +35 -4
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/EventEmitter.d.ts +3 -0
- package/lib/typescript/Logger.d.ts +13 -0
- package/lib/typescript/MediaDevices.d.ts +2 -2
- package/lib/typescript/MediaStream.d.ts +6 -6
- package/lib/typescript/MediaStreamTrack.d.ts +10 -9
- package/lib/typescript/RTCDataChannel.d.ts +4 -2
- package/lib/typescript/RTCErrorEvent.d.ts +12 -0
- package/lib/typescript/RTCPeerConnection.d.ts +42 -11
- package/lib/typescript/RTCRtcpParameters.d.ts +8 -0
- package/lib/typescript/RTCRtpCapabilities.d.ts +19 -0
- package/lib/typescript/RTCRtpCodecCapability.d.ts +7 -0
- package/lib/typescript/RTCRtpCodecParameters.d.ts +14 -0
- package/lib/typescript/RTCRtpEncodingParameters.d.ts +21 -0
- package/lib/typescript/RTCRtpHeaderExtension.d.ts +10 -0
- package/lib/typescript/RTCRtpParameters.d.ts +14 -0
- package/lib/typescript/RTCRtpReceiveParameters.d.ts +4 -0
- package/lib/typescript/RTCRtpReceiver.d.ts +15 -0
- package/lib/typescript/RTCRtpSendParameters.d.ts +17 -0
- package/lib/typescript/RTCRtpSender.d.ts +21 -0
- package/lib/typescript/RTCRtpTransceiver.d.ts +35 -0
- package/lib/typescript/RTCTrackEvent.d.ts +15 -0
- package/lib/typescript/RTCUtil.d.ts +5 -9
- package/lib/typescript/getDisplayMedia.d.ts +2 -1
- package/lib/typescript/getUserMedia.d.ts +2 -1
- package/lib/typescript/index.d.ts +16 -3
- package/package.json +6 -4
- package/react-native-webrtc.podspec +1 -1
- package/src/EventEmitter.ts +21 -1
- package/src/Logger.ts +49 -0
- package/src/MediaStream.ts +11 -11
- package/src/MediaStreamTrack.ts +14 -13
- package/src/Permissions.ts +1 -1
- package/src/RTCDataChannel.ts +11 -8
- package/src/RTCErrorEvent.ts +21 -0
- package/src/RTCPeerConnection.ts +400 -158
- package/src/RTCRtcpParameters.ts +14 -0
- package/src/RTCRtpCapabilities.ts +54 -0
- package/src/RTCRtpCodecCapability.ts +13 -0
- package/src/RTCRtpCodecParameters.ts +23 -0
- package/src/RTCRtpEncodingParameters.ts +67 -0
- package/src/RTCRtpHeaderExtension.ts +18 -0
- package/src/RTCRtpParameters.ts +21 -0
- package/src/RTCRtpReceiveParameters.ts +7 -0
- package/src/RTCRtpReceiver.ts +35 -0
- package/src/RTCRtpSendParameters.ts +51 -0
- package/src/RTCRtpSender.ts +72 -0
- package/src/RTCRtpTransceiver.ts +125 -0
- package/src/RTCSessionDescription.ts +3 -3
- package/src/RTCTrackEvent.ts +21 -0
- package/src/RTCUtil.ts +20 -40
- package/src/getDisplayMedia.ts +1 -1
- package/src/getUserMedia.ts +2 -2
- package/src/index.ts +51 -6
- package/tools/build-webrtc.py +32 -33
- package/tools/downloadBitcode.sh +2 -12
- package/tools/downloadWebRTC.js +21 -12
package/ISSUE_TEMPLATE.md
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
<!--
|
|
2
|
-
If you have a question
|
|
2
|
+
If you have a question then please ask it on our community Discourse: https://react-native-webrtc.discourse.group/
|
|
3
|
+
otherwise if you wanted to report a bug then you are in the right place!
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Please include as much information as possible and make the issue title
|
|
7
|
-
as descriptive as you can.
|
|
5
|
+
Please include as much information as possible and make the issue title as descriptive as you can.
|
|
8
6
|
-->
|
|
9
7
|
|
|
10
|
-
#### Expected
|
|
8
|
+
#### Expected Behavior
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
#### Observed Behavior
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
#### Steps to reproduce the issue
|
|
11
17
|
|
|
12
|
-
#### Observerd behavior
|
|
13
18
|
|
|
14
|
-
#### Steps to reproduce the problem
|
|
15
19
|
|
|
16
|
-
#### Platform
|
|
20
|
+
#### Platform Information
|
|
17
21
|
|
|
18
|
-
* **React Native
|
|
19
|
-
* **Plugin
|
|
20
|
-
* **OS**: <!-- Android / iOS -->
|
|
21
|
-
* **OS
|
|
22
|
+
* **React Native Version**:
|
|
23
|
+
* **Plugin Version**:
|
|
24
|
+
* **OS**: <!-- Android / iOS / macOS / Web / Expo -->
|
|
25
|
+
* **OS Version**:
|
package/README.md
CHANGED
|
@@ -1,151 +1,68 @@
|
|
|
1
|
-
|
|
1
|
+
[<img src="https://avatars.githubusercontent.com/u/42463376" alt="React Native WebRTC" style="height: 6em;" />](https://github.com/react-native-webrtc/react-native-webrtc)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://img.shields.io/npm/dm/react-native-webrtc.svg?maxAge=2592000)
|
|
3
|
+
# React-Native-WebRTC
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
> 🚨 Expo: This package is not available in the [Expo Go](https://expo.dev/client) app. Learn how you can use this package in [Custom Dev Clients](https://docs.expo.dev/development/getting-started/) via the out-of-tree [Expo Config Plugin](https://github.com/expo/config-plugins/tree/master/packages/react-native-webrtc).
|
|
11
|
-
|
|
12
|
-
## Community
|
|
13
|
-
|
|
14
|
-
Everyone is welcome to our [Discourse community](https://react-native-webrtc.discourse.group/) to discuss any React Native and WebRTC related topics.
|
|
15
|
-
|
|
16
|
-
## WebRTC Revision
|
|
17
|
-
|
|
18
|
-
* Currently used revision: [M100](https://github.com/jitsi/webrtc/releases/tag/v100.0.0)
|
|
19
|
-
* Supported architectures
|
|
20
|
-
* Android: armeabi-v7a, arm64-v8a, x86, x86_64
|
|
21
|
-
* iOS: arm64, x86_64 (for bitcode support, run [this script](https://github.com/react-native-webrtc/react-native-webrtc/blob/master/tools/downloadBitcode.sh))
|
|
22
|
-
* macOS: x86_64
|
|
23
|
-
|
|
24
|
-
## Installation
|
|
25
|
-
|
|
26
|
-
- [iOS](https://github.com/react-native-webrtc/react-native-webrtc/blob/master/Documentation/iOSInstallation.md)
|
|
27
|
-
- [Android](https://github.com/react-native-webrtc/react-native-webrtc/blob/master/Documentation/AndroidInstallation.md)
|
|
28
|
-
|
|
29
|
-
## Usage
|
|
30
|
-
Now, you can use WebRTC like in browser.
|
|
31
|
-
In your `index.ios.js`/`index.android.js`, you can require WebRTC to import RTCPeerConnection, RTCSessionDescription, etc.
|
|
32
|
-
|
|
33
|
-
```javascript
|
|
34
|
-
import {
|
|
35
|
-
RTCPeerConnection,
|
|
36
|
-
RTCIceCandidate,
|
|
37
|
-
RTCSessionDescription,
|
|
38
|
-
RTCView,
|
|
39
|
-
MediaStream,
|
|
40
|
-
MediaStreamTrack,
|
|
41
|
-
mediaDevices,
|
|
42
|
-
registerGlobals
|
|
43
|
-
} from 'react-native-webrtc';
|
|
44
|
-
```
|
|
45
|
-
Anything about using RTCPeerConnection, RTCSessionDescription and RTCIceCandidate is like browser.
|
|
46
|
-
Support most WebRTC APIs, please see the [Document](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection).
|
|
47
|
-
|
|
48
|
-
```javascript
|
|
49
|
-
const configuration = {"iceServers": [{"url": "stun:stun.l.google.com:19302"}]};
|
|
50
|
-
const pc = new RTCPeerConnection(configuration);
|
|
5
|
+
[](https://www.npmjs.com/package/react-native-webrtc)
|
|
6
|
+
[](https://www.npmjs.com/package/react-native-webrtc)
|
|
7
|
+
[](https://react-native-webrtc.discourse.group/)
|
|
51
8
|
|
|
52
|
-
|
|
53
|
-
mediaDevices.enumerateDevices().then(sourceInfos => {
|
|
54
|
-
console.log(sourceInfos);
|
|
55
|
-
let videoSourceId;
|
|
56
|
-
for (let i = 0; i < sourceInfos.length; i++) {
|
|
57
|
-
const sourceInfo = sourceInfos[i];
|
|
58
|
-
if(sourceInfo.kind == "videoinput" && sourceInfo.facing == (isFront ? "front" : "environment")) {
|
|
59
|
-
videoSourceId = sourceInfo.deviceId;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
mediaDevices.getUserMedia({
|
|
63
|
-
audio: true,
|
|
64
|
-
video: {
|
|
65
|
-
width: 640,
|
|
66
|
-
height: 480,
|
|
67
|
-
frameRate: 30,
|
|
68
|
-
facingMode: (isFront ? "user" : "environment"),
|
|
69
|
-
deviceId: videoSourceId
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
.then(stream => {
|
|
73
|
-
// Got stream!
|
|
74
|
-
})
|
|
75
|
-
.catch(error => {
|
|
76
|
-
// Log error
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
pc.createOffer().then(desc => {
|
|
81
|
-
pc.setLocalDescription(desc).then(() => {
|
|
82
|
-
// Send pc.localDescription to peer
|
|
83
|
-
});
|
|
84
|
-
});
|
|
9
|
+
A WebRTC module for React Native.
|
|
85
10
|
|
|
86
|
-
|
|
87
|
-
// send event.candidate to peer
|
|
88
|
-
};
|
|
11
|
+
## Feature Overview
|
|
89
12
|
|
|
90
|
-
|
|
13
|
+
| | Android | iOS | macOS | Windows* | Web* | Expo* |
|
|
14
|
+
| :-: | :-------: | :---: | :-----: | :--------: | :----: | :-----: |
|
|
15
|
+
| Audio/Video | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | - | :heavy_check_mark: | :heavy_check_mark: |
|
|
16
|
+
| Data Channels | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | - | :heavy_check_mark: | :heavy_check_mark: |
|
|
17
|
+
| Screen Capture | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | - | :heavy_check_mark: | :heavy_check_mark: |
|
|
18
|
+
| Plan B | - | - | - | - | - | - |
|
|
19
|
+
| Unified Plan* | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | - | :heavy_check_mark: | :heavy_check_mark: |
|
|
91
20
|
|
|
92
|
-
|
|
21
|
+
> **Windows** - We don't currently support the [react-native-windows](https://github.com/microsoft/react-native-windows) platform at this time.
|
|
22
|
+
Anyone interested in getting the ball rolling? We're open to contributions.
|
|
93
23
|
|
|
94
|
-
|
|
24
|
+
> **Web** - The [react-native-webrtc-web-shim](https://github.com/react-native-webrtc/react-native-webrtc-web-shim) project provides a shim for [react-native-web](https://github.com/necolas/react-native-web) support.
|
|
25
|
+
Which will allow you to use [(almost)](https://github.com/react-native-webrtc/react-native-webrtc-web-shim/tree/main#setup) the exact same code in your [react-native-web](https://github.com/necolas/react-native-web) project as you would with [react-native](https://reactnative.dev/) directly.
|
|
95
26
|
|
|
96
|
-
|
|
27
|
+
> **Expo** - Sadly this module is not available in the [Expo Go](https://expo.dev/client) app by default due to including much needed native code. However you can get things working via the [expo-dev-client](https://docs.expo.dev/development/getting-started/) library and out-of-tree [config-plugins/react-native-webrtc](https://github.com/expo/config-plugins/tree/master/packages/react-native-webrtc) package.
|
|
97
28
|
|
|
98
|
-
|
|
29
|
+
> **Unified Plan** - As of version 106.0.0 Unified Plan is the only supported mode. Those still in need of Plan B can use and old release.
|
|
99
30
|
|
|
100
|
-
|
|
101
|
-
<RTCView streamURL={this.state.stream.toURL()}/>
|
|
102
|
-
```
|
|
31
|
+
## WebRTC Revision
|
|
103
32
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
| zOrder | number | 0 | Similarly to zIndex |
|
|
33
|
+
* Currently used revision: [M106](https://github.com/jitsi/webrtc/tree/M106)
|
|
34
|
+
* Supported architectures
|
|
35
|
+
* Android: armeabi-v7a, arm64-v8a, x86, x86_64
|
|
36
|
+
* iOS: arm64, x86_64
|
|
37
|
+
* macOS: ~~~x86_64~~~ (temporarily disabled)
|
|
110
38
|
|
|
39
|
+
## Getting Started
|
|
111
40
|
|
|
112
|
-
|
|
41
|
+
Use one of the following preferred package install methods to immediately get going.
|
|
42
|
+
Don't forget to follow platform guides below to cover any extra required steps.
|
|
113
43
|
|
|
114
|
-
|
|
44
|
+
**npm:** `npm install react-native-webrtc --save`
|
|
45
|
+
**yarn:** `yarn add react-native-webrtc`
|
|
115
46
|
|
|
116
|
-
|
|
47
|
+
## Guides
|
|
117
48
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
* `window.RTCSessionDescription`
|
|
124
|
-
* `window.MediaStream`
|
|
125
|
-
* `window.MediaStreamTrack`
|
|
126
|
-
|
|
127
|
-
This is useful to make existing WebRTC JavaScript libraries (that expect those globals to exist) work with react-native-webrtc.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
#### MediaStreamTrack.prototype._switchCamera()
|
|
131
|
-
|
|
132
|
-
This function allows to switch the front / back cameras in a video track
|
|
133
|
-
on the fly, without the need for adding / removing tracks or renegotiating.
|
|
134
|
-
|
|
135
|
-
#### VideoTrack.enabled
|
|
136
|
-
|
|
137
|
-
Starting with version 1.67, when setting a local video track's enabled state to
|
|
138
|
-
`false`, the camera will be closed, but the track will remain alive. Setting
|
|
139
|
-
it back to `true` will re-enable the camera.
|
|
49
|
+
- [Android Install](./Documentation/AndroidInstallation.md)
|
|
50
|
+
- [iOS Install](./Documentation/iOSInstallation.md)
|
|
51
|
+
- [Basic Usage](./Documentation/BasicUsage.md)
|
|
52
|
+
- [Step by Step Call Guide](./Documentation/CallGuide.md)
|
|
53
|
+
- [Improving Call Reliability](./Documentation/ImprovingCallReliability.md)
|
|
140
54
|
|
|
141
|
-
##
|
|
55
|
+
## Example Projects
|
|
142
56
|
|
|
143
|
-
|
|
57
|
+
We have some very basic example projects included in the [examples](./examples) directory.
|
|
58
|
+
Don't worry, there are plans to include a much more broader example with backend included.
|
|
144
59
|
|
|
145
|
-
|
|
60
|
+
## Community
|
|
146
61
|
|
|
147
|
-
|
|
62
|
+
Come join our [Discourse Community](https://react-native-webrtc.discourse.group/) if you want to discuss any React Native and WebRTC related topics.
|
|
63
|
+
Everyone is welcome and every little helps.
|
|
148
64
|
|
|
149
|
-
|
|
65
|
+
## Related Projects
|
|
150
66
|
|
|
151
|
-
|
|
67
|
+
Looking for extra functionality coverage?
|
|
68
|
+
The [react-native-webrtc](https://github.com/react-native-webrtc) organization provides a number of packages which are more than useful when developing Real Time Communication applications.
|
|
@@ -9,6 +9,7 @@ import androidx.annotation.Nullable;
|
|
|
9
9
|
import com.facebook.react.bridge.Arguments;
|
|
10
10
|
import com.facebook.react.bridge.Promise;
|
|
11
11
|
import com.facebook.react.bridge.ReadableMap;
|
|
12
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
12
13
|
import com.facebook.react.bridge.WritableArray;
|
|
13
14
|
import com.facebook.react.bridge.WritableMap;
|
|
14
15
|
|
|
@@ -19,6 +20,8 @@ import org.webrtc.MediaStream;
|
|
|
19
20
|
import org.webrtc.MediaStreamTrack;
|
|
20
21
|
import org.webrtc.PeerConnection;
|
|
21
22
|
import org.webrtc.RtpReceiver;
|
|
23
|
+
import org.webrtc.RtpSender;
|
|
24
|
+
import org.webrtc.RtpTransceiver;
|
|
22
25
|
import org.webrtc.SessionDescription;
|
|
23
26
|
import org.webrtc.VideoTrack;
|
|
24
27
|
|
|
@@ -30,6 +33,7 @@ import java.util.HashMap;
|
|
|
30
33
|
import java.util.Iterator;
|
|
31
34
|
import java.util.List;
|
|
32
35
|
import java.util.Map;
|
|
36
|
+
import java.util.Objects;
|
|
33
37
|
import java.util.UUID;
|
|
34
38
|
|
|
35
39
|
class PeerConnectionObserver implements PeerConnection.Observer {
|
|
@@ -37,8 +41,9 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
37
41
|
|
|
38
42
|
private final Map<String, DataChannelWrapper> dataChannels;
|
|
39
43
|
private final int id;
|
|
44
|
+
private int transceiverNextId = 0;
|
|
45
|
+
|
|
40
46
|
private PeerConnection peerConnection;
|
|
41
|
-
final List<MediaStream> localStreams;
|
|
42
47
|
final Map<String, MediaStream> remoteStreams;
|
|
43
48
|
final Map<String, MediaStreamTrack> remoteTracks;
|
|
44
49
|
private final VideoTrackAdapter videoTrackAdapters;
|
|
@@ -48,49 +53,11 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
48
53
|
this.webRTCModule = webRTCModule;
|
|
49
54
|
this.id = id;
|
|
50
55
|
this.dataChannels = new HashMap<>();
|
|
51
|
-
this.localStreams = new ArrayList<>();
|
|
52
56
|
this.remoteStreams = new HashMap<>();
|
|
53
57
|
this.remoteTracks = new HashMap<>();
|
|
54
58
|
this.videoTrackAdapters = new VideoTrackAdapter(webRTCModule, id);
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
/**
|
|
58
|
-
* Adds a specific local <tt>MediaStream</tt> to the associated
|
|
59
|
-
* <tt>PeerConnection</tt>.
|
|
60
|
-
*
|
|
61
|
-
* @param localStream the local <tt>MediaStream</tt> to add to the
|
|
62
|
-
* associated <tt>PeerConnection</tt>
|
|
63
|
-
* @return <tt>true</tt> if the specified <tt>localStream</tt> was added to
|
|
64
|
-
* the associated <tt>PeerConnection</tt>; otherwise, <tt>false</tt>
|
|
65
|
-
*/
|
|
66
|
-
boolean addStream(MediaStream localStream) {
|
|
67
|
-
if (peerConnection != null && peerConnection.addStream(localStream)) {
|
|
68
|
-
localStreams.add(localStream);
|
|
69
|
-
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Removes a specific local <tt>MediaStream</tt> from the associated
|
|
78
|
-
* <tt>PeerConnection</tt>.
|
|
79
|
-
*
|
|
80
|
-
* @param localStream the local <tt>MediaStream</tt> from the associated
|
|
81
|
-
* <tt>PeerConnection</tt>
|
|
82
|
-
* @return <tt>true</tt> if removing the specified <tt>mediaStream</tt> from
|
|
83
|
-
* this instance resulted in a modification of its internal list of local
|
|
84
|
-
* <tt>MediaStream</tt>s; otherwise, <tt>false</tt>
|
|
85
|
-
*/
|
|
86
|
-
boolean removeStream(MediaStream localStream) {
|
|
87
|
-
if (peerConnection != null) {
|
|
88
|
-
peerConnection.removeStream(localStream);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return localStreams.remove(localStream);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
61
|
PeerConnection getPeerConnection() {
|
|
95
62
|
return peerConnection;
|
|
96
63
|
}
|
|
@@ -105,19 +72,10 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
105
72
|
// Close the PeerConnection first to stop any events.
|
|
106
73
|
peerConnection.close();
|
|
107
74
|
|
|
108
|
-
// PeerConnection.dispose() calls MediaStream.dispose() on all local
|
|
109
|
-
// MediaStreams added to it and the app may crash if a local MediaStream
|
|
110
|
-
// is added to multiple PeerConnections. In order to reduce the risks of
|
|
111
|
-
// an app crash, remove all local MediaStreams from the associated
|
|
112
|
-
// PeerConnection so that it doesn't attempt to dispose of them.
|
|
113
|
-
for (MediaStream localStream : new ArrayList<>(localStreams)) {
|
|
114
|
-
removeStream(localStream);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
75
|
// Remove video track adapters
|
|
118
|
-
for (
|
|
119
|
-
|
|
120
|
-
videoTrackAdapters.removeAdapter(
|
|
76
|
+
for (MediaStreamTrack track : this.remoteTracks.values()) {
|
|
77
|
+
if (track instanceof VideoTrack) {
|
|
78
|
+
videoTrackAdapters.removeAdapter((VideoTrack) track);
|
|
121
79
|
}
|
|
122
80
|
}
|
|
123
81
|
|
|
@@ -138,6 +96,54 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
138
96
|
dataChannels.clear();
|
|
139
97
|
}
|
|
140
98
|
|
|
99
|
+
|
|
100
|
+
public synchronized int getNextTransceiverId() {
|
|
101
|
+
return transceiverNextId++;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
RtpTransceiver addTransceiver(MediaStreamTrack.MediaType mediaType, RtpTransceiver.RtpTransceiverInit init) {
|
|
105
|
+
if (peerConnection == null) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return peerConnection.addTransceiver(mediaType, init);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
RtpTransceiver addTransceiver(MediaStreamTrack track, RtpTransceiver.RtpTransceiverInit init) {
|
|
113
|
+
if (peerConnection == null) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return peerConnection.addTransceiver(track, init);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
RtpSender getSender(String id) {
|
|
121
|
+
if (this.peerConnection == null) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
for (RtpSender sender: this.peerConnection.getSenders()) {
|
|
126
|
+
if (sender.id().equals(id)) {
|
|
127
|
+
return sender;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
RtpTransceiver getTransceiver(String id) {
|
|
135
|
+
if (this.peerConnection == null) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
for (RtpTransceiver transceiver: this.peerConnection.getTransceivers()) {
|
|
140
|
+
if (transceiver.getSender().id().equals(id)) {
|
|
141
|
+
return transceiver;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
141
147
|
WritableMap createDataChannel(String label, ReadableMap config) {
|
|
142
148
|
DataChannel.Init init = new DataChannel.Init();
|
|
143
149
|
if (config != null) {
|
|
@@ -294,120 +300,6 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
294
300
|
webRTCModule.sendEvent("peerConnectionIceGatheringChanged", params);
|
|
295
301
|
}
|
|
296
302
|
|
|
297
|
-
private String getReactTagForStream(MediaStream mediaStream) {
|
|
298
|
-
for (Iterator<Map.Entry<String, MediaStream>> i
|
|
299
|
-
= remoteStreams.entrySet().iterator();
|
|
300
|
-
i.hasNext(); ) {
|
|
301
|
-
Map.Entry<String, MediaStream> e = i.next();
|
|
302
|
-
if (e.getValue().equals(mediaStream)) {
|
|
303
|
-
return e.getKey();
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
return null;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
@Override
|
|
310
|
-
public void onAddStream(MediaStream mediaStream) {
|
|
311
|
-
String streamReactTag = null;
|
|
312
|
-
String streamId = mediaStream.getId();
|
|
313
|
-
// The native WebRTC implementation has a special concept of a default
|
|
314
|
-
// MediaStream instance with the label default that the implementation
|
|
315
|
-
// reuses.
|
|
316
|
-
if ("default".equals(streamId)) {
|
|
317
|
-
for (Map.Entry<String, MediaStream> e : remoteStreams.entrySet()) {
|
|
318
|
-
if (e.getValue().equals(mediaStream)) {
|
|
319
|
-
streamReactTag = e.getKey();
|
|
320
|
-
break;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
if (streamReactTag == null) {
|
|
326
|
-
streamReactTag = UUID.randomUUID().toString();
|
|
327
|
-
remoteStreams.put(streamReactTag, mediaStream);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
WritableMap params = Arguments.createMap();
|
|
331
|
-
params.putInt("id", id);
|
|
332
|
-
params.putString("streamId", streamId);
|
|
333
|
-
params.putString("streamReactTag", streamReactTag);
|
|
334
|
-
|
|
335
|
-
WritableArray tracks = Arguments.createArray();
|
|
336
|
-
|
|
337
|
-
for (int i = 0; i < mediaStream.videoTracks.size(); i++) {
|
|
338
|
-
VideoTrack track = mediaStream.videoTracks.get(i);
|
|
339
|
-
String trackId = track.id();
|
|
340
|
-
|
|
341
|
-
remoteTracks.put(trackId, track);
|
|
342
|
-
|
|
343
|
-
WritableMap trackInfo = Arguments.createMap();
|
|
344
|
-
trackInfo.putString("id", trackId);
|
|
345
|
-
trackInfo.putString("label", "Video");
|
|
346
|
-
trackInfo.putString("kind", track.kind());
|
|
347
|
-
trackInfo.putBoolean("enabled", track.enabled());
|
|
348
|
-
trackInfo.putString("readyState", track.state().toString());
|
|
349
|
-
trackInfo.putBoolean("remote", true);
|
|
350
|
-
tracks.pushMap(trackInfo);
|
|
351
|
-
|
|
352
|
-
videoTrackAdapters.addAdapter(track);
|
|
353
|
-
}
|
|
354
|
-
for (int i = 0; i < mediaStream.audioTracks.size(); i++) {
|
|
355
|
-
AudioTrack track = mediaStream.audioTracks.get(i);
|
|
356
|
-
String trackId = track.id();
|
|
357
|
-
|
|
358
|
-
remoteTracks.put(trackId, track);
|
|
359
|
-
|
|
360
|
-
WritableMap trackInfo = Arguments.createMap();
|
|
361
|
-
trackInfo.putString("id", trackId);
|
|
362
|
-
trackInfo.putString("label", "Audio");
|
|
363
|
-
trackInfo.putString("kind", track.kind());
|
|
364
|
-
trackInfo.putBoolean("enabled", track.enabled());
|
|
365
|
-
trackInfo.putString("readyState", track.state().toString());
|
|
366
|
-
trackInfo.putBoolean("remote", true);
|
|
367
|
-
tracks.pushMap(trackInfo);
|
|
368
|
-
}
|
|
369
|
-
params.putArray("tracks", tracks);
|
|
370
|
-
|
|
371
|
-
SessionDescription newSdp = peerConnection.getRemoteDescription();
|
|
372
|
-
WritableMap newSdpMap = Arguments.createMap();
|
|
373
|
-
newSdpMap.putString("type", newSdp.type.canonicalForm());
|
|
374
|
-
newSdpMap.putString("sdp", newSdp.description);
|
|
375
|
-
params.putMap("sdp", newSdpMap);
|
|
376
|
-
|
|
377
|
-
webRTCModule.sendEvent("peerConnectionAddedStream", params);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
@Override
|
|
381
|
-
public void onRemoveStream(MediaStream mediaStream) {
|
|
382
|
-
String streamReactTag = getReactTagForStream(mediaStream);
|
|
383
|
-
if (streamReactTag == null) {
|
|
384
|
-
Log.w(TAG, "onRemoveStream - no remote stream for id: " + mediaStream.getId());
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
for (VideoTrack track : mediaStream.videoTracks) {
|
|
389
|
-
this.videoTrackAdapters.removeAdapter(track);
|
|
390
|
-
this.remoteTracks.remove(track.id());
|
|
391
|
-
}
|
|
392
|
-
for (AudioTrack track : mediaStream.audioTracks) {
|
|
393
|
-
this.remoteTracks.remove(track.id());
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
this.remoteStreams.remove(streamReactTag);
|
|
397
|
-
|
|
398
|
-
WritableMap params = Arguments.createMap();
|
|
399
|
-
params.putInt("id", id);
|
|
400
|
-
params.putString("streamId", streamReactTag);
|
|
401
|
-
|
|
402
|
-
SessionDescription newSdp = peerConnection.getRemoteDescription();
|
|
403
|
-
WritableMap newSdpMap = Arguments.createMap();
|
|
404
|
-
newSdpMap.putString("type", newSdp.type.canonicalForm());
|
|
405
|
-
newSdpMap.putString("sdp", newSdp.description);
|
|
406
|
-
params.putMap("sdp", newSdpMap);
|
|
407
|
-
|
|
408
|
-
webRTCModule.sendEvent("peerConnectionRemovedStream", params);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
303
|
@Override
|
|
412
304
|
public void onDataChannel(DataChannel dataChannel) {
|
|
413
305
|
final String reactTag = UUID.randomUUID().toString();
|
|
@@ -452,9 +344,111 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
452
344
|
webRTCModule.sendEvent("peerConnectionSignalingStateChanged", params);
|
|
453
345
|
}
|
|
454
346
|
|
|
347
|
+
/**
|
|
348
|
+
* Triggered when a new track is signaled by the remote peer, as a result of
|
|
349
|
+
* setRemoteDescription.
|
|
350
|
+
*/
|
|
455
351
|
@Override
|
|
456
352
|
public void onAddTrack(final RtpReceiver receiver, final MediaStream[] mediaStreams) {
|
|
457
353
|
Log.d(TAG, "onAddTrack");
|
|
354
|
+
|
|
355
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
356
|
+
RtpTransceiver transceiver = null;
|
|
357
|
+
for(RtpTransceiver t: this.peerConnection.getTransceivers()) {
|
|
358
|
+
if (Objects.equals(t.getReceiver().id(), receiver.id())) {
|
|
359
|
+
transceiver = t;
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (transceiver == null) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
final MediaStreamTrack track = receiver.track();
|
|
369
|
+
|
|
370
|
+
if (remoteTracks.containsKey(track.id())) {
|
|
371
|
+
// Unlike in the WebRTC spec, the libwebrtc native implementation
|
|
372
|
+
// fires onTrack on every sRD which has an active receiving transceiver.
|
|
373
|
+
// So, if we are already keeping track of this transceiver, ignore the event.
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (track.kind().equals(MediaStreamTrack.VIDEO_TRACK_KIND)){
|
|
378
|
+
videoTrackAdapters.addAdapter((VideoTrack) track);
|
|
379
|
+
}
|
|
380
|
+
remoteTracks.put(track.id(), track);
|
|
381
|
+
|
|
382
|
+
WritableMap params = Arguments.createMap();
|
|
383
|
+
WritableArray streams = Arguments.createArray();
|
|
384
|
+
|
|
385
|
+
for (MediaStream stream : mediaStreams) {
|
|
386
|
+
// Getting the streamReactTag
|
|
387
|
+
String streamReactTag = null;
|
|
388
|
+
for (Map.Entry<String, MediaStream> e : remoteStreams.entrySet()) {
|
|
389
|
+
if (e.getValue().equals(stream)) {
|
|
390
|
+
streamReactTag = e.getKey();
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (streamReactTag == null) {
|
|
395
|
+
streamReactTag = UUID.randomUUID().toString();
|
|
396
|
+
remoteStreams.put(streamReactTag, stream);
|
|
397
|
+
}
|
|
398
|
+
streams.pushMap(SerializeUtils.serializeStream(id, streamReactTag, stream));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
params.putArray("streams", streams);
|
|
402
|
+
params.putMap("receiver", SerializeUtils.serializeReceiver(id, receiver));
|
|
403
|
+
params.putInt("transceiverOrder", getNextTransceiverId());
|
|
404
|
+
params.putMap("transceiver", SerializeUtils.serializeTransceiver(id, transceiver));
|
|
405
|
+
|
|
406
|
+
params.putInt("id", this.id);
|
|
407
|
+
|
|
408
|
+
webRTCModule.sendEvent("peerConnectionOnTrack", params);
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Triggered when the signaling from SetRemoteDescription indicates that a transceiver
|
|
414
|
+
* will be receiving media from a remote endpoint. This is only called if UNIFIED_PLAN
|
|
415
|
+
* semantics are specified. The transceiver will be disposed automatically.
|
|
416
|
+
*/
|
|
417
|
+
@Override
|
|
418
|
+
public void onTrack(final RtpTransceiver transceiver) {
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/*
|
|
422
|
+
* Triggered when a previously added remote track is removed by the remote
|
|
423
|
+
* peer, as a result of setRemoteDescription.
|
|
424
|
+
*/
|
|
425
|
+
@Override
|
|
426
|
+
public void onRemoveTrack(RtpReceiver receiver){
|
|
427
|
+
// According to the W3C spec, we need to send out
|
|
428
|
+
// the track Id so that we can remove it from the MediaStream objects stored
|
|
429
|
+
// at the JS layer, which are the same stream objects passed down to
|
|
430
|
+
// the `track` event.
|
|
431
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
432
|
+
MediaStreamTrack track = receiver.track();
|
|
433
|
+
WritableMap params = Arguments.createMap();
|
|
434
|
+
params.putInt("id", this.id);
|
|
435
|
+
params.putString("trackId", track.id());
|
|
436
|
+
|
|
437
|
+
webRTCModule.sendEvent("peerConnectionOnRemoveTrack", params);
|
|
438
|
+
|
|
439
|
+
});
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
// This is only added to compile. Plan B is not supported anymore.
|
|
443
|
+
@Override
|
|
444
|
+
public void onRemoveStream(MediaStream stream) {
|
|
445
|
+
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// This is only added to compile. Plan B is not supported anymore.
|
|
449
|
+
@Override
|
|
450
|
+
public void onAddStream(MediaStream stream) {
|
|
451
|
+
|
|
458
452
|
}
|
|
459
453
|
|
|
460
454
|
@Nullable
|
|
@@ -528,4 +522,5 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
528
522
|
}
|
|
529
523
|
return null;
|
|
530
524
|
}
|
|
525
|
+
|
|
531
526
|
}
|