react-native-webrtc 1.100.1 → 106.0.0-beta.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/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 +380 -102
- 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 +373 -102
- 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 +423 -156
- 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
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
export default class RTCRtcpParameters {
|
|
3
|
+
readonly cname: string;
|
|
4
|
+
readonly reducedSize: boolean;
|
|
5
|
+
|
|
6
|
+
constructor(init: {
|
|
7
|
+
cname: string,
|
|
8
|
+
reducedSize: boolean
|
|
9
|
+
}) {
|
|
10
|
+
this.cname = init.cname;
|
|
11
|
+
this.reducedSize = init.reducedSize;
|
|
12
|
+
Object.freeze(this);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {NativeModules} from 'react-native';
|
|
2
|
+
import RTCRtpCodecCapability from './RTCRtpCodecCapability';
|
|
3
|
+
const { WebRTCModule } = NativeModules;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @brief represents codec capabilities for senders and receivers. Currently
|
|
7
|
+
* this only supports codec names and does not have other
|
|
8
|
+
* fields like clockRate and numChannels and such.
|
|
9
|
+
*/
|
|
10
|
+
export default class RTCRtpCapabilities {
|
|
11
|
+
_codecs: RTCRtpCodecCapability[] = [];
|
|
12
|
+
constructor(codecs: RTCRtpCodecCapability[]) {
|
|
13
|
+
this._codecs = codecs;
|
|
14
|
+
Object.freeze(this);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get codecs() {
|
|
18
|
+
return this._codecs;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function getCapabilities(endpoint: 'sender' | 'receiver'): RTCRtpCapabilities | null {
|
|
24
|
+
switch (endpoint) {
|
|
25
|
+
case 'sender': {
|
|
26
|
+
const capabilities = WebRTCModule.senderGetCapabilities();
|
|
27
|
+
if (!capabilities) return null;
|
|
28
|
+
return new RTCRtpCapabilities(capabilities.codecs);
|
|
29
|
+
}
|
|
30
|
+
case 'receiver': {
|
|
31
|
+
const capabilities = WebRTCModule.receiverGetCapabilities();
|
|
32
|
+
if (!capabilities) return null;
|
|
33
|
+
return new RTCRtpCapabilities(capabilities.codecs);
|
|
34
|
+
}
|
|
35
|
+
default:
|
|
36
|
+
throw new TypeError('Invalid endpoint: ' + endpoint);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Hardcoded audio capabilities based on the WebRTC native documentation:
|
|
43
|
+
* https://webrtc.github.io/webrtc-org/faq/. The mime type is specified in
|
|
44
|
+
* https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-2.
|
|
45
|
+
*/
|
|
46
|
+
export const DEFAULT_AUDIO_CAPABILITIES = new RTCRtpCapabilities([
|
|
47
|
+
new RTCRtpCodecCapability({ mimeType: 'audio/G722' }),
|
|
48
|
+
new RTCRtpCodecCapability({ mimeType: 'audio/iLBC' }),
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
// Initialize capabilities on module import
|
|
52
|
+
export const senderCapabilities = getCapabilities('sender');
|
|
53
|
+
export const receiverCapabilities = getCapabilities('receiver');
|
|
54
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
export default class RTCRtpCodecParameters {
|
|
3
|
+
readonly payloadType: number;
|
|
4
|
+
readonly clockRate: number;
|
|
5
|
+
readonly channels: number;
|
|
6
|
+
readonly mimeType: string;
|
|
7
|
+
readonly sdpFmtpLine: Map<String, String>;
|
|
8
|
+
|
|
9
|
+
constructor(init: {
|
|
10
|
+
payloadType: number,
|
|
11
|
+
clockRate: number,
|
|
12
|
+
channels: number,
|
|
13
|
+
mimeType: string,
|
|
14
|
+
sdpFmtpLine: Map<String, String>
|
|
15
|
+
}) {
|
|
16
|
+
this.payloadType = init.payloadType;
|
|
17
|
+
this.clockRate = init.clockRate;
|
|
18
|
+
this.channels = init.channels;
|
|
19
|
+
this.mimeType = init.mimeType;
|
|
20
|
+
this.sdpFmtpLine = init.sdpFmtpLine;
|
|
21
|
+
Object.freeze(this);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
|
|
2
|
+
export default class RTCRtpEncodingParameters {
|
|
3
|
+
readonly active: boolean;
|
|
4
|
+
_maxFramerate: number | null;
|
|
5
|
+
_maxBitrate: number | null;
|
|
6
|
+
_scaleResolutionDownBy: number | null;
|
|
7
|
+
|
|
8
|
+
constructor(init: {
|
|
9
|
+
active: boolean,
|
|
10
|
+
maxFramerate?: number;
|
|
11
|
+
maxBitrate?: number;
|
|
12
|
+
scaleResolutionDownBy?: number;
|
|
13
|
+
}) {
|
|
14
|
+
this.active = init.active;
|
|
15
|
+
this._maxBitrate = init.maxBitrate ?? null;
|
|
16
|
+
this._maxFramerate = init.maxFramerate ?? null;
|
|
17
|
+
this._scaleResolutionDownBy = init.scaleResolutionDownBy ?? null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get maxFramerate() {
|
|
21
|
+
return this._maxFramerate;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get maxBitrate() {
|
|
25
|
+
return this._maxBitrate;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get scaleResolutionDownBy() {
|
|
29
|
+
return this._scaleResolutionDownBy;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
set maxFramerate(framerate) {
|
|
33
|
+
if (framerate && framerate > 0) {
|
|
34
|
+
this._maxFramerate = framerate;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
set maxBitrate(bitrate) {
|
|
39
|
+
if (bitrate && bitrate > 0) {
|
|
40
|
+
this._maxBitrate = bitrate;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
set scaleResolutionDownBy(resolutionScale) {
|
|
45
|
+
if (resolutionScale && resolutionScale >= 1) {
|
|
46
|
+
this._scaleResolutionDownBy = resolutionScale;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
toJSON() {
|
|
51
|
+
let obj = {
|
|
52
|
+
active: this.active,
|
|
53
|
+
}
|
|
54
|
+
if (this._maxBitrate !== null) {
|
|
55
|
+
obj['maxBitrate'] = this._maxBitrate;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (this._maxFramerate !== null) {
|
|
59
|
+
obj['maxFramerate'] = this._maxFramerate;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (this._scaleResolutionDownBy !== null) {
|
|
63
|
+
obj['scaleResolutionDownBy'] = this._scaleResolutionDownBy;
|
|
64
|
+
}
|
|
65
|
+
return obj;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
export default class RTCRtpHeaderExtension {
|
|
3
|
+
readonly id: number;
|
|
4
|
+
readonly uri: string;
|
|
5
|
+
readonly encrypted: boolean;
|
|
6
|
+
|
|
7
|
+
constructor(init: {
|
|
8
|
+
id: number,
|
|
9
|
+
uri: string,
|
|
10
|
+
encrypted: boolean
|
|
11
|
+
}) {
|
|
12
|
+
this.id = init.id;
|
|
13
|
+
this.uri = init.uri;
|
|
14
|
+
this.encrypted = init.encrypted;
|
|
15
|
+
Object.freeze(this);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import RTCRtcpParameters from "./RTCRtcpParameters";
|
|
2
|
+
import RTCRtpCodecParameters from "./RTCRtpCodecParameters";
|
|
3
|
+
import RTCRtpHeaderExtension from "./RTCRtpHeaderExtension";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export type RTCRtpParametersInit = {
|
|
7
|
+
codecs: RTCRtpCodecParameters[],
|
|
8
|
+
headerExtensions: RTCRtpHeaderExtension[],
|
|
9
|
+
rtcp: RTCRtcpParameters
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default class RTCRtpParameters {
|
|
13
|
+
readonly codecs: RTCRtpCodecParameters[] = [];
|
|
14
|
+
readonly headerExtensions: RTCRtpHeaderExtension[] = [];
|
|
15
|
+
readonly rtcp: RTCRtcpParameters;
|
|
16
|
+
constructor(init: RTCRtpParametersInit) {
|
|
17
|
+
this.codecs = init.codecs;
|
|
18
|
+
this.headerExtensions = init.headerExtensions;
|
|
19
|
+
this.rtcp = init.rtcp;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { NativeModules } from 'react-native';
|
|
2
|
+
import MediaStreamTrack from './MediaStreamTrack';
|
|
3
|
+
import RTCRtpCapabilities, {DEFAULT_AUDIO_CAPABILITIES, receiverCapabilities } from './RTCRtpCapabilities';
|
|
4
|
+
|
|
5
|
+
const { WebRTCModule } = NativeModules;
|
|
6
|
+
|
|
7
|
+
export default class RTCRtpReceiver {
|
|
8
|
+
_id: string;
|
|
9
|
+
_peerConnectionId: number;
|
|
10
|
+
_track: MediaStreamTrack;
|
|
11
|
+
|
|
12
|
+
constructor(info: { peerConnectionId: number, id: string, track: MediaStreamTrack }) {
|
|
13
|
+
this._id = info.id;
|
|
14
|
+
this._peerConnectionId = info.peerConnectionId;
|
|
15
|
+
this._track = info.track;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static getCapabilities(kind: "audio" | "video"): RTCRtpCapabilities {
|
|
19
|
+
if (kind == "audio") {
|
|
20
|
+
return DEFAULT_AUDIO_CAPABILITIES;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!receiverCapabilities)
|
|
24
|
+
throw new Error('Receiver Capabilities is null');
|
|
25
|
+
return receiverCapabilities;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get id() {
|
|
29
|
+
return this._id;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get track() {
|
|
33
|
+
return this._track;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import RTCRtpParameters, { RTCRtpParametersInit } from "./RTCRtpParameters";
|
|
2
|
+
import RTCRtpEncodingParameters from "./RTCRtpEncodingParameters";
|
|
3
|
+
|
|
4
|
+
type DegradationPreferenceType = 'maintain-framerate'
|
|
5
|
+
| 'maintain-resolution'
|
|
6
|
+
| 'balanced'
|
|
7
|
+
| 'disabled'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Class to convert degradation preference format. Native has a format such as
|
|
12
|
+
* MAINTAIN_FRAMERATE whereas the web APIs expect maintain-framerate
|
|
13
|
+
*/
|
|
14
|
+
class DegradationPreference {
|
|
15
|
+
static fromNative(nativeFormat: string): DegradationPreferenceType {
|
|
16
|
+
const stringFormat = nativeFormat.toLowerCase().replace('_', '-');
|
|
17
|
+
return stringFormat as DegradationPreferenceType;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static toNative(format: DegradationPreferenceType): string {
|
|
21
|
+
return format.toUpperCase().replace('-', '_');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default class RTCRtpSendParameters extends RTCRtpParameters {
|
|
26
|
+
|
|
27
|
+
readonly transactionId: string;
|
|
28
|
+
readonly encodings: RTCRtpEncodingParameters[];
|
|
29
|
+
degradationPreference: DegradationPreferenceType | null;
|
|
30
|
+
constructor(init: RTCRtpParametersInit & {
|
|
31
|
+
transactionId: string,
|
|
32
|
+
encodings: RTCRtpEncodingParameters[],
|
|
33
|
+
degradationPreference?: string
|
|
34
|
+
}) {
|
|
35
|
+
super(init);
|
|
36
|
+
this.transactionId = init.transactionId;
|
|
37
|
+
this.encodings = init.encodings;
|
|
38
|
+
this.degradationPreference = init.degradationPreference ?
|
|
39
|
+
DegradationPreference.fromNative(init.degradationPreference) : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
toJSON() {
|
|
43
|
+
let obj = {
|
|
44
|
+
encodings: this.encodings,
|
|
45
|
+
};
|
|
46
|
+
if (this.degradationPreference !== null) {
|
|
47
|
+
obj['degradationPreference'] = DegradationPreference.toNative(this.degradationPreference);
|
|
48
|
+
}
|
|
49
|
+
return obj
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {NativeModules} from 'react-native';
|
|
2
|
+
import MediaStreamTrack from './MediaStreamTrack';
|
|
3
|
+
import RTCRtpCapabilities, { senderCapabilities, DEFAULT_AUDIO_CAPABILITIES } from './RTCRtpCapabilities';
|
|
4
|
+
import RTCRtpSendParameters from './RTCRtpSendParameters';
|
|
5
|
+
|
|
6
|
+
const {WebRTCModule} = NativeModules;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export default class RTCRtpSender {
|
|
10
|
+
_id: string;
|
|
11
|
+
_track: MediaStreamTrack | null = null;
|
|
12
|
+
_peerConnectionId: number;
|
|
13
|
+
_rtpParameters: RTCRtpSendParameters;
|
|
14
|
+
|
|
15
|
+
constructor(info: {
|
|
16
|
+
peerConnectionId: number,
|
|
17
|
+
id: string,
|
|
18
|
+
track?: MediaStreamTrack,
|
|
19
|
+
rtpParameters: RTCRtpSendParameters
|
|
20
|
+
}) {
|
|
21
|
+
this._peerConnectionId = info.peerConnectionId;
|
|
22
|
+
this._id = info.id;
|
|
23
|
+
this._rtpParameters = info.rtpParameters;
|
|
24
|
+
|
|
25
|
+
if (info.track) {
|
|
26
|
+
this._track = info.track;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async replaceTrack(track: MediaStreamTrack | null): Promise<void> {
|
|
31
|
+
try {
|
|
32
|
+
await WebRTCModule.senderReplaceTrack(this._peerConnectionId, this._id, track ? track.id : null);
|
|
33
|
+
} catch(e) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
this._track = track;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static getCapabilities(kind: "audio" | "video"): RTCRtpCapabilities {
|
|
41
|
+
if (kind === "audio") {
|
|
42
|
+
return DEFAULT_AUDIO_CAPABILITIES;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!senderCapabilities) {
|
|
46
|
+
throw new Error("sender Capabilities are null");
|
|
47
|
+
}
|
|
48
|
+
return senderCapabilities;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getParameters(): RTCRtpSendParameters {
|
|
52
|
+
return this._rtpParameters;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
setParameters(parameters: RTCRtpSendParameters): Promise<void> {
|
|
56
|
+
return WebRTCModule.senderSetParameters(this._peerConnectionId,
|
|
57
|
+
this._id,
|
|
58
|
+
JSON.parse(JSON.stringify(parameters)))// This allows us to get rid of private "underscore properties"
|
|
59
|
+
.then((newParameters) => {
|
|
60
|
+
this._rtpParameters = new RTCRtpSendParameters(newParameters);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
get track() {
|
|
66
|
+
return this._track;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
get id() {
|
|
70
|
+
return this._id;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { defineCustomEventTarget } from 'event-target-shim';
|
|
2
|
+
import { NativeModules } from 'react-native';
|
|
3
|
+
import { addListener, removeListener } from './EventEmitter';
|
|
4
|
+
import RTCRtpSender from './RTCRtpSender';
|
|
5
|
+
import RTCErrorEvent from './RTCErrorEvent';
|
|
6
|
+
import RTCRtpReceiver from './RTCRtpReceiver';
|
|
7
|
+
|
|
8
|
+
const {WebRTCModule} = NativeModules;
|
|
9
|
+
|
|
10
|
+
const TRANSCEIVER_EVENTS = [
|
|
11
|
+
'error'
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
export default class RTCRtpTransceiver extends defineCustomEventTarget(...TRANSCEIVER_EVENTS) {
|
|
15
|
+
_peerConnectionId: number;
|
|
16
|
+
_sender: RTCRtpSender;
|
|
17
|
+
_receiver: RTCRtpReceiver;
|
|
18
|
+
|
|
19
|
+
_id: string;
|
|
20
|
+
_mid: string | null = null;
|
|
21
|
+
_direction: string;
|
|
22
|
+
_currentDirection: string;
|
|
23
|
+
_stopped: boolean;
|
|
24
|
+
|
|
25
|
+
constructor(args: {
|
|
26
|
+
peerConnectionId: number,
|
|
27
|
+
id: string,
|
|
28
|
+
isStopped: boolean,
|
|
29
|
+
direction: string,
|
|
30
|
+
currentDirection: string,
|
|
31
|
+
mid?: string,
|
|
32
|
+
sender: RTCRtpSender,
|
|
33
|
+
receiver: RTCRtpReceiver,
|
|
34
|
+
}) {
|
|
35
|
+
super();
|
|
36
|
+
this._peerConnectionId = args.peerConnectionId;
|
|
37
|
+
this._id = args.id;
|
|
38
|
+
this._mid = args.mid ? args.mid : null;
|
|
39
|
+
this._direction = args.direction;
|
|
40
|
+
this._currentDirection = args.currentDirection;
|
|
41
|
+
this._stopped = args.isStopped;
|
|
42
|
+
this._sender = args.sender;
|
|
43
|
+
this._receiver = args.receiver;
|
|
44
|
+
this._registerEvents();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get id() {
|
|
48
|
+
return this._id;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get mid() {
|
|
52
|
+
return this._mid;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get stopped() {
|
|
56
|
+
return this._stopped;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get direction() {
|
|
60
|
+
return this._direction;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
set direction(val) {
|
|
64
|
+
if (!['sendonly', 'recvonly', 'sendrecv', 'inactive'].includes(val)) {
|
|
65
|
+
throw new TypeError('Invalid direction provided');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (this._stopped) {
|
|
69
|
+
throw Error('Transceiver Stopped');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (this._direction === val) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
WebRTCModule.transceiverSetDirection(this._peerConnectionId, this.id, val)
|
|
77
|
+
this._direction = val;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get currentDirection() {
|
|
81
|
+
return this._currentDirection;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
get sender() {
|
|
85
|
+
return this._sender;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
get receiver() {
|
|
89
|
+
return this._receiver;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
stop() {
|
|
93
|
+
if (this._stopped) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
WebRTCModule.transceiverStop(this._peerConnectionId, this.id);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
_registerEvents(): void {
|
|
100
|
+
addListener(this, 'transceiverStopSuccessful', ev => {
|
|
101
|
+
if (ev.peerConnectionId !== this._peerConnectionId || ev.transceiverId !== this._id) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
this._stopped = true;
|
|
105
|
+
this._direction = 'stopped'
|
|
106
|
+
this._currentDirection = 'stopped';
|
|
107
|
+
this._mid = null;
|
|
108
|
+
removeListener(this);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
addListener(this, 'transceiverOnError', ev => {
|
|
112
|
+
if (ev.info.peerConnectionId !== this._peerConnectionId || ev.info.transceiverId !== this._id) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (ev.func === 'stopTransceiver') {
|
|
116
|
+
this._stopped = false;
|
|
117
|
+
} else if (ev.func === 'setDirection') {
|
|
118
|
+
this._direction = ev.info.oldDirection;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
this.dispatchEvent(new RTCErrorEvent('error', ev.func, ev.message));
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -8,15 +8,15 @@ export default class RTCSessionDescription {
|
|
|
8
8
|
this._type = info.type;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
get sdp() {
|
|
11
|
+
get sdp(): string {
|
|
12
12
|
return this._sdp;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
get type() {
|
|
15
|
+
get type(): string | null {
|
|
16
16
|
return this._type;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
toJSON() {
|
|
19
|
+
toJSON(): { sdp: string, type: string | null } {
|
|
20
20
|
return {
|
|
21
21
|
sdp: this._sdp,
|
|
22
22
|
type: this._type
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
import MediaStream from './MediaStream';
|
|
3
|
+
import type MediaStreamTrack from './MediaStreamTrack';
|
|
4
|
+
import RTCRtpReceiver from './RTCRtpReceiver';
|
|
5
|
+
import RTCRtpTransceiver from './RTCRtpTransceiver';
|
|
6
|
+
|
|
7
|
+
export default class RTCTrackEvent {
|
|
8
|
+
type: string;
|
|
9
|
+
readonly streams: MediaStream[] = [];
|
|
10
|
+
readonly transceiver: RTCRtpTransceiver;
|
|
11
|
+
readonly receiver: RTCRtpReceiver | null;
|
|
12
|
+
readonly track: MediaStreamTrack | null;
|
|
13
|
+
|
|
14
|
+
constructor(type: string, eventInitDict: { streams: MediaStream[], transceiver: RTCRtpTransceiver }) {
|
|
15
|
+
this.type = type.toString();
|
|
16
|
+
this.streams = eventInitDict.streams;
|
|
17
|
+
this.transceiver = eventInitDict.transceiver;
|
|
18
|
+
this.receiver = eventInitDict.transceiver.receiver;
|
|
19
|
+
this.track = eventInitDict.transceiver.receiver ? eventInitDict.transceiver.receiver.track : null;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/RTCUtil.ts
CHANGED
|
@@ -8,9 +8,11 @@ const DEFAULT_VIDEO_CONSTRAINTS = {
|
|
|
8
8
|
width: 1280
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
const FACING_MODES = [ 'user', 'environment' ];
|
|
12
|
+
|
|
11
13
|
const ASPECT_RATIO = 16 / 9;
|
|
12
14
|
|
|
13
|
-
const
|
|
15
|
+
const STANDARD_OFFER_OPTIONS = {
|
|
14
16
|
icerestart: 'IceRestart',
|
|
15
17
|
offertoreceiveaudio: 'OfferToReceiveAudio',
|
|
16
18
|
offertoreceivevideo: 'OfferToReceiveVideo',
|
|
@@ -63,32 +65,19 @@ function normalizeMediaConstraints(constraints, mediaType) {
|
|
|
63
65
|
case 'audio':
|
|
64
66
|
return constraints;
|
|
65
67
|
case 'video': {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
}
|
|
68
|
+
const c = {
|
|
69
|
+
deviceId: extractString(constraints, 'deviceId'),
|
|
70
|
+
facingMode: extractString(constraints, 'facingMode'),
|
|
71
|
+
frameRate: extractNumber(constraints, 'frameRate'),
|
|
72
|
+
height: extractNumber(constraints, 'height'),
|
|
73
|
+
width: extractNumber(constraints, 'width')
|
|
74
|
+
};
|
|
86
75
|
|
|
87
76
|
if (!c.deviceId) {
|
|
88
77
|
delete c.deviceId;
|
|
89
78
|
}
|
|
90
79
|
|
|
91
|
-
if (!
|
|
80
|
+
if (!FACING_MODES.includes(c.facingMode)) {
|
|
92
81
|
c.facingMode = DEFAULT_VIDEO_CONSTRAINTS.facingMode;
|
|
93
82
|
}
|
|
94
83
|
|
|
@@ -99,9 +88,9 @@ function normalizeMediaConstraints(constraints, mediaType) {
|
|
|
99
88
|
if (!c.height && !c.width) {
|
|
100
89
|
c.height = DEFAULT_VIDEO_CONSTRAINTS.height;
|
|
101
90
|
c.width = DEFAULT_VIDEO_CONSTRAINTS.width;
|
|
102
|
-
} else if (!c.height) {
|
|
91
|
+
} else if (!c.height && c.width) {
|
|
103
92
|
c.height = Math.round(c.width / ASPECT_RATIO);
|
|
104
|
-
} else if (!c.width) {
|
|
93
|
+
} else if (!c.width && c.height) {
|
|
105
94
|
c.width = Math.round(c.height * ASPECT_RATIO);
|
|
106
95
|
}
|
|
107
96
|
|
|
@@ -129,7 +118,7 @@ function chr4() {
|
|
|
129
118
|
*
|
|
130
119
|
* @return {String} uuidv4
|
|
131
120
|
*/
|
|
132
|
-
export function uniqueID() {
|
|
121
|
+
export function uniqueID(): string {
|
|
133
122
|
return `${chr4()}${chr4()}-${chr4()}-${chr4()}-${chr4()}-${chr4()}${chr4()}${chr4()}`;
|
|
134
123
|
}
|
|
135
124
|
|
|
@@ -139,36 +128,27 @@ export function uniqueID() {
|
|
|
139
128
|
* @param {Object} obj - object to be cloned
|
|
140
129
|
* @return {Object} cloned obj
|
|
141
130
|
*/
|
|
142
|
-
export function deepClone(obj) {
|
|
131
|
+
export function deepClone<T>(obj: T): T {
|
|
143
132
|
return JSON.parse(JSON.stringify(obj));
|
|
144
133
|
}
|
|
145
134
|
|
|
146
|
-
interface Constraints {
|
|
147
|
-
mandatory?: object;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
135
|
/**
|
|
151
|
-
* Normalize options passed to createOffer()
|
|
136
|
+
* Normalize options passed to createOffer().
|
|
152
137
|
*
|
|
153
|
-
* @param
|
|
154
|
-
* @return
|
|
138
|
+
* @param options - user supplied options
|
|
139
|
+
* @return Normalized options
|
|
155
140
|
*/
|
|
156
|
-
export function
|
|
141
|
+
export function normalizeOfferOptions(options: object = {}): object {
|
|
157
142
|
const newOptions = {};
|
|
158
143
|
|
|
159
144
|
if (!options) {
|
|
160
145
|
return newOptions;
|
|
161
146
|
}
|
|
162
147
|
|
|
163
|
-
// Support legacy constraints.
|
|
164
|
-
if (options.mandatory) {
|
|
165
|
-
options = options.mandatory;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
148
|
// Convert standard options into WebRTC internal constant names.
|
|
169
149
|
// See: https://github.com/jitsi/webrtc/blob/0cd6ce4de669bed94ba47b88cb71b9be0341bb81/sdk/media_constraints.cc#L113
|
|
170
150
|
for (const [key, value] of Object.entries(options)) {
|
|
171
|
-
const newKey =
|
|
151
|
+
const newKey = STANDARD_OFFER_OPTIONS[key.toLowerCase()];
|
|
172
152
|
if (newKey) {
|
|
173
153
|
newOptions[newKey] = String(Boolean(value));
|
|
174
154
|
}
|
package/src/getDisplayMedia.ts
CHANGED
|
@@ -6,7 +6,7 @@ import MediaStreamError from './MediaStreamError';
|
|
|
6
6
|
|
|
7
7
|
const { WebRTCModule } = NativeModules;
|
|
8
8
|
|
|
9
|
-
export default function getDisplayMedia() {
|
|
9
|
+
export default function getDisplayMedia(): Promise<MediaStream> {
|
|
10
10
|
return new Promise((resolve, reject) => {
|
|
11
11
|
WebRTCModule.getDisplayMedia().then(
|
|
12
12
|
data => {
|