react-native-webrtc 106.0.0-beta.6 → 106.0.0-beta.8
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/android/src/main/java/com/oney/WebRTCModule/DataChannelWrapper.java +7 -1
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +145 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +45 -6
- package/ios/RCTWebRTC/DataChannelWrapper.h +2 -0
- package/ios/RCTWebRTC/DataChannelWrapper.m +6 -0
- package/ios/RCTWebRTC/RCTConvert+WebRTC.m +10 -0
- package/ios/RCTWebRTC/SerializeUtils.h +2 -1
- package/ios/RCTWebRTC/SerializeUtils.m +55 -7
- package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.m +8 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +91 -72
- package/ios/RCTWebRTC/WebRTCModule.h +1 -1
- package/ios/RCTWebRTC/WebRTCModule.m +1 -1
- package/lib/commonjs/EventEmitter.js +29 -6
- package/lib/commonjs/EventEmitter.js.map +1 -1
- package/lib/commonjs/MediaStreamTrack.js +8 -7
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/RTCDataChannel.js +28 -17
- package/lib/commonjs/RTCDataChannel.js.map +1 -1
- package/lib/commonjs/RTCIceCandidate.js +14 -4
- package/lib/commonjs/RTCIceCandidate.js.map +1 -1
- package/lib/commonjs/RTCPeerConnection.js +40 -26
- package/lib/commonjs/RTCPeerConnection.js.map +1 -1
- package/lib/commonjs/RTCRtpReceiver.js +19 -0
- package/lib/commonjs/RTCRtpReceiver.js.map +1 -1
- package/lib/commonjs/RTCRtpSender.js +13 -0
- package/lib/commonjs/RTCRtpSender.js.map +1 -1
- package/lib/commonjs/RTCRtpTransceiver.js +2 -9
- package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
- package/lib/commonjs/RTCView.js +0 -55
- package/lib/commonjs/RTCView.js.map +1 -1
- package/lib/commonjs/index.js +5 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/EventEmitter.js +25 -5
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +8 -7
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/RTCDataChannel.js +28 -17
- package/lib/module/RTCDataChannel.js.map +1 -1
- package/lib/module/RTCIceCandidate.js +14 -4
- package/lib/module/RTCIceCandidate.js.map +1 -1
- package/lib/module/RTCPeerConnection.js +40 -26
- package/lib/module/RTCPeerConnection.js.map +1 -1
- package/lib/module/RTCRtpReceiver.js +17 -0
- package/lib/module/RTCRtpReceiver.js.map +1 -1
- package/lib/module/RTCRtpSender.js +13 -0
- package/lib/module/RTCRtpSender.js.map +1 -1
- package/lib/module/RTCRtpTransceiver.js +2 -9
- package/lib/module/RTCRtpTransceiver.js.map +1 -1
- package/lib/module/RTCView.js +0 -49
- package/lib/module/RTCView.js.map +1 -1
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/EventEmitter.d.ts +2 -3
- package/lib/typescript/MediaStreamTrack.d.ts +2 -1
- package/lib/typescript/RTCDataChannel.d.ts +2 -4
- package/lib/typescript/RTCIceCandidate.d.ts +5 -1
- package/lib/typescript/RTCRtpReceiver.d.ts +1 -0
- package/lib/typescript/RTCRtpSender.d.ts +1 -0
- package/lib/typescript/RTCRtpTransceiver.d.ts +0 -3
- package/lib/typescript/RTCView.d.ts +53 -46
- package/package.json +1 -1
- package/src/EventEmitter.ts +36 -4
- package/src/MediaStreamTrack.ts +7 -6
- package/src/RTCDataChannel.ts +62 -47
- package/src/RTCIceCandidate.ts +8 -5
- package/src/RTCPeerConnection.ts +41 -14
- package/src/RTCRtpReceiver.ts +17 -0
- package/src/RTCRtpSender.ts +14 -0
- package/src/RTCRtpTransceiver.ts +2 -9
- package/src/RTCView.ts +53 -49
- package/src/index.ts +4 -0
|
@@ -4,14 +4,12 @@ export default class RTCRtpTransceiver {
|
|
|
4
4
|
_peerConnectionId: number;
|
|
5
5
|
_sender: RTCRtpSender;
|
|
6
6
|
_receiver: RTCRtpReceiver;
|
|
7
|
-
_id: string;
|
|
8
7
|
_mid: string | null;
|
|
9
8
|
_direction: string;
|
|
10
9
|
_currentDirection: string;
|
|
11
10
|
_stopped: boolean;
|
|
12
11
|
constructor(args: {
|
|
13
12
|
peerConnectionId: number;
|
|
14
|
-
id: string;
|
|
15
13
|
isStopped: boolean;
|
|
16
14
|
direction: string;
|
|
17
15
|
currentDirection: string;
|
|
@@ -19,7 +17,6 @@ export default class RTCRtpTransceiver {
|
|
|
19
17
|
sender: RTCRtpSender;
|
|
20
18
|
receiver: RTCRtpReceiver;
|
|
21
19
|
});
|
|
22
|
-
get id(): string;
|
|
23
20
|
get mid(): string | null;
|
|
24
21
|
get stopped(): boolean;
|
|
25
22
|
get direction(): string;
|
|
@@ -1,53 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
import { ViewProps } from 'react-native';
|
|
2
2
|
/**
|
|
3
3
|
* Native prop validation was removed from RN in:
|
|
4
4
|
* https://github.com/facebook/react-native/commit/8dc3ba0444c94d9bbb66295b5af885bff9b9cd34
|
|
5
5
|
*
|
|
6
6
|
* So we list them here for documentation purposes.
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
8
|
+
interface RTCVideoViewProps extends ViewProps {
|
|
9
|
+
/**
|
|
10
|
+
* Indicates whether the video specified by {@link #streamURL} should be
|
|
11
|
+
* mirrored during rendering. Commonly, applications choose to mirror the
|
|
12
|
+
* user-facing camera.
|
|
13
|
+
*
|
|
14
|
+
* mirror: boolean
|
|
15
|
+
*/
|
|
16
|
+
mirror?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* In the fashion of
|
|
19
|
+
* https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth
|
|
20
|
+
* and https://www.w3.org/TR/html5/rendering.html#video-object-fit,
|
|
21
|
+
* resembles the CSS style object-fit.
|
|
22
|
+
*
|
|
23
|
+
* objectFit: 'contain' | 'cover'
|
|
24
|
+
*/
|
|
25
|
+
objectFit?: 'contain' | 'cover';
|
|
26
|
+
/**
|
|
27
|
+
* URL / id of the stream that should be rendered.
|
|
28
|
+
*
|
|
29
|
+
* streamURL: string
|
|
30
|
+
*/
|
|
31
|
+
streamURL: string;
|
|
32
|
+
/**
|
|
33
|
+
* Similarly to the CSS property z-index, specifies the z-order of this
|
|
34
|
+
* RTCView in the stacking space of all RTCViews. When RTCViews overlap,
|
|
35
|
+
* zOrder determines which one covers the other. An RTCView with a larger
|
|
36
|
+
* zOrder generally covers an RTCView with a lower one.
|
|
37
|
+
*
|
|
38
|
+
* Non-overlapping RTCViews may safely share a z-order (because one does not
|
|
39
|
+
* have to cover the other).
|
|
40
|
+
*
|
|
41
|
+
* The support for zOrder is platform-dependent and/or
|
|
42
|
+
* implementation-specific. Thus, specifying a value for zOrder is to be
|
|
43
|
+
* thought of as giving a hint rather than as imposing a requirement. For
|
|
44
|
+
* example, video renderers such as RTCView are commonly implemented using
|
|
45
|
+
* OpenGL and OpenGL views may have different numbers of layers in their
|
|
46
|
+
* stacking space. Android has three: a layer bellow the window (aka
|
|
47
|
+
* default), a layer bellow the window again but above the previous layer
|
|
48
|
+
* (aka media overlay), and above the window. Consequently, it is advisable
|
|
49
|
+
* to limit the number of utilized layers in the stacking space to the
|
|
50
|
+
* minimum sufficient for the desired display. For example, a video call
|
|
51
|
+
* application usually needs a maximum of two zOrder values: 0 for the
|
|
52
|
+
* remote video(s) which appear in the background, and 1 for the local
|
|
53
|
+
* video(s) which appear above the remote video(s).
|
|
54
|
+
*
|
|
55
|
+
* zOrder: number
|
|
56
|
+
*/
|
|
57
|
+
zOrder?: number;
|
|
58
|
+
}
|
|
59
|
+
declare const _default: import("react-native").HostComponent<RTCVideoViewProps>;
|
|
53
60
|
export default _default;
|
package/package.json
CHANGED
package/src/EventEmitter.ts
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
1
|
import { NativeModules, NativeEventEmitter, EmitterSubscription } from 'react-native';
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter';
|
|
2
4
|
|
|
3
5
|
const { WebRTCModule } = NativeModules;
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
// This emitter is going to be used to listen to all the native events (once) and then
|
|
8
|
+
// re-emit them on a JS-only emitter.
|
|
9
|
+
const nativeEmitter = new NativeEventEmitter(WebRTCModule);
|
|
10
|
+
|
|
11
|
+
const NATIVE_EVENTS = [
|
|
12
|
+
'peerConnectionSignalingStateChanged',
|
|
13
|
+
'peerConnectionStateChanged',
|
|
14
|
+
'peerConnectionOnRenegotiationNeeded',
|
|
15
|
+
'peerConnectionIceConnectionChanged',
|
|
16
|
+
'peerConnectionIceGatheringChanged',
|
|
17
|
+
'peerConnectionGotICECandidate',
|
|
18
|
+
'peerConnectionDidOpenDataChannel',
|
|
19
|
+
'peerConnectionOnRemoveTrack',
|
|
20
|
+
'peerConnectionOnTrack',
|
|
21
|
+
'dataChannelStateChanged',
|
|
22
|
+
'dataChannelReceiveMessage',
|
|
23
|
+
'dataChannelDidChangeBufferedAmount',
|
|
24
|
+
'mediaStreamTrackMuteChanged',
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const eventEmitter = new EventEmitter();
|
|
28
|
+
|
|
29
|
+
export function setupNativeEvents() {
|
|
30
|
+
for (const eventName of NATIVE_EVENTS) {
|
|
31
|
+
nativeEmitter.addListener(eventName, (...args) => {
|
|
32
|
+
eventEmitter.emit(eventName, ...args);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
8
36
|
|
|
9
37
|
type EventHandler = (event: unknown) => void;
|
|
10
38
|
type Listener = unknown;
|
|
@@ -12,11 +40,15 @@ type Listener = unknown;
|
|
|
12
40
|
const _subscriptions: Map<Listener, EmitterSubscription[]> = new Map();
|
|
13
41
|
|
|
14
42
|
export function addListener(listener: Listener, eventName: string, eventHandler: EventHandler): void {
|
|
43
|
+
if (!NATIVE_EVENTS.includes(eventName)) {
|
|
44
|
+
throw new Error(`Invalid event: ${eventName}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
15
47
|
if (!_subscriptions.has(listener)) {
|
|
16
48
|
_subscriptions.set(listener, []);
|
|
17
49
|
}
|
|
18
50
|
|
|
19
|
-
_subscriptions.get(listener)?.push(
|
|
51
|
+
_subscriptions.get(listener)?.push(eventEmitter.addListener(eventName, eventHandler));
|
|
20
52
|
}
|
|
21
53
|
|
|
22
54
|
export function removeListener(listener: Listener): void {
|
package/src/MediaStreamTrack.ts
CHANGED
|
@@ -16,11 +16,11 @@ class MediaStreamTrack extends defineCustomEventTarget(...MEDIA_STREAM_TRACK_EVE
|
|
|
16
16
|
_settings: object;
|
|
17
17
|
_muted: boolean;
|
|
18
18
|
_peerConnectionId: number;
|
|
19
|
+
_readyState: MediaStreamTrackState;
|
|
19
20
|
|
|
20
21
|
readonly id: string;
|
|
21
22
|
readonly kind: string;
|
|
22
23
|
readonly label: string = '';
|
|
23
|
-
readyState: MediaStreamTrackState;
|
|
24
24
|
readonly remote: boolean;
|
|
25
25
|
|
|
26
26
|
constructor(info) {
|
|
@@ -31,14 +31,11 @@ class MediaStreamTrack extends defineCustomEventTarget(...MEDIA_STREAM_TRACK_EVE
|
|
|
31
31
|
this._settings = info.settings || {};
|
|
32
32
|
this._muted = false;
|
|
33
33
|
this._peerConnectionId = info.peerConnectionId;
|
|
34
|
+
this._readyState = info.readyState;
|
|
34
35
|
|
|
35
36
|
this.id = info.id;
|
|
36
37
|
this.kind = info.kind;
|
|
37
38
|
this.remote = info.remote;
|
|
38
|
-
|
|
39
|
-
const _readyState = info.readyState.toLowerCase();
|
|
40
|
-
|
|
41
|
-
this.readyState = _readyState === 'initializing' || _readyState === 'live' ? 'live' : 'ended';
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
get enabled(): boolean {
|
|
@@ -58,9 +55,13 @@ class MediaStreamTrack extends defineCustomEventTarget(...MEDIA_STREAM_TRACK_EVE
|
|
|
58
55
|
return this._muted;
|
|
59
56
|
}
|
|
60
57
|
|
|
58
|
+
get readyState(): string {
|
|
59
|
+
return this._readyState;
|
|
60
|
+
}
|
|
61
|
+
|
|
61
62
|
stop(): void {
|
|
62
63
|
WebRTCModule.mediaStreamTrackSetEnabled(this.id, false);
|
|
63
|
-
this.
|
|
64
|
+
this._readyState = 'ended';
|
|
64
65
|
// TODO: save some stopped flag?
|
|
65
66
|
}
|
|
66
67
|
|
package/src/RTCDataChannel.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
import * as base64 from 'base64-js';
|
|
3
3
|
import { defineCustomEventTarget } from 'event-target-shim';
|
|
4
|
-
import {
|
|
4
|
+
import { NativeModules } from 'react-native';
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { addListener, removeListener } from './EventEmitter';
|
|
7
7
|
import MessageEvent from './MessageEvent';
|
|
8
8
|
import RTCDataChannelEvent from './RTCDataChannelEvent';
|
|
9
9
|
|
|
@@ -16,6 +16,8 @@ const DATA_CHANNEL_EVENTS = [ 'open', 'message', 'bufferedamountlow', 'closing',
|
|
|
16
16
|
export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHANNEL_EVENTS) {
|
|
17
17
|
_peerConnectionId: number;
|
|
18
18
|
_reactTag: string;
|
|
19
|
+
|
|
20
|
+
_bufferedAmount: number;
|
|
19
21
|
_id: number;
|
|
20
22
|
_label: string;
|
|
21
23
|
_maxPacketLifeTime?: number;
|
|
@@ -24,10 +26,8 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
|
|
|
24
26
|
_ordered: boolean;
|
|
25
27
|
_protocol: string;
|
|
26
28
|
_readyState: RTCDataChannelState;
|
|
27
|
-
_subscriptions: EmitterSubscription[] = [];
|
|
28
29
|
|
|
29
30
|
binaryType = 'arraybuffer'; // we only support 'arraybuffer'
|
|
30
|
-
bufferedAmount = 0;
|
|
31
31
|
bufferedAmountLowThreshold = 0;
|
|
32
32
|
|
|
33
33
|
constructor(info) {
|
|
@@ -36,6 +36,7 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
|
|
|
36
36
|
this._peerConnectionId = info.peerConnectionId;
|
|
37
37
|
this._reactTag = info.reactTag;
|
|
38
38
|
|
|
39
|
+
this._bufferedAmount = 0;
|
|
39
40
|
this._label = info.label;
|
|
40
41
|
this._id = info.id === -1 ? null : info.id; // null until negotiated.
|
|
41
42
|
this._ordered = Boolean(info.ordered);
|
|
@@ -48,6 +49,10 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
|
|
|
48
49
|
this._registerEvents();
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
get bufferedAmount(): number {
|
|
53
|
+
return this._bufferedAmount;
|
|
54
|
+
}
|
|
55
|
+
|
|
51
56
|
get label(): string {
|
|
52
57
|
return this._label;
|
|
53
58
|
}
|
|
@@ -112,51 +117,61 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
|
|
|
112
117
|
WebRTCModule.dataChannelClose(this._peerConnectionId, this._reactTag);
|
|
113
118
|
}
|
|
114
119
|
|
|
115
|
-
_unregisterEvents(): void {
|
|
116
|
-
this._subscriptions.forEach(e => e.remove());
|
|
117
|
-
this._subscriptions = [];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
120
|
_registerEvents(): void {
|
|
121
|
-
this
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
121
|
+
addListener(this, 'dataChannelStateChanged', (ev: any) => {
|
|
122
|
+
if (ev.reactTag !== this._reactTag) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
this._readyState = ev.state;
|
|
127
|
+
|
|
128
|
+
if (this._id === null && ev.id !== -1) {
|
|
129
|
+
this._id = ev.id;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (this._readyState === 'open') {
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
this.dispatchEvent(new RTCDataChannelEvent('open', { channel: this }));
|
|
135
|
+
} else if (this._readyState === 'closing') {
|
|
136
|
+
// @ts-ignore
|
|
137
|
+
this.dispatchEvent(new RTCDataChannelEvent('closing', { channel: this }));
|
|
138
|
+
} else if (this._readyState === 'closed') {
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
this.dispatchEvent(new RTCDataChannelEvent('close', { channel: this }));
|
|
141
|
+
|
|
142
|
+
// This DataChannel is done, clean up event handlers.
|
|
143
|
+
removeListener(this);
|
|
144
|
+
|
|
145
|
+
WebRTCModule.dataChannelDispose(this._peerConnectionId, this._reactTag);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
addListener(this, 'dataChannelReceiveMessage', (ev: any) => {
|
|
150
|
+
if (ev.reactTag !== this._reactTag) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
let data = ev.data;
|
|
155
|
+
|
|
156
|
+
if (ev.type === 'binary') {
|
|
157
|
+
data = base64.toByteArray(ev.data).buffer;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// @ts-ignore
|
|
161
|
+
this.dispatchEvent(new MessageEvent('message', { data }));
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
addListener(this, 'dataChannelDidChangeBufferedAmount', (ev: any) => {
|
|
165
|
+
if (ev.reactTag !== this._reactTag) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
this._bufferedAmount = ev.bufferedAmount;
|
|
156
170
|
|
|
171
|
+
if (this._bufferedAmount < this.bufferedAmountLowThreshold) {
|
|
157
172
|
// @ts-ignore
|
|
158
|
-
this.dispatchEvent(new
|
|
159
|
-
}
|
|
160
|
-
|
|
173
|
+
this.dispatchEvent(new RTCDataChannelEvent('bufferedamountlow', { channel: this }));
|
|
174
|
+
}
|
|
175
|
+
});
|
|
161
176
|
}
|
|
162
177
|
}
|
package/src/RTCIceCandidate.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
1
|
export default class RTCIceCandidate {
|
|
3
2
|
candidate: string;
|
|
4
3
|
sdpMLineIndex: number;
|
|
5
4
|
sdpMid: string;
|
|
6
5
|
|
|
7
|
-
constructor(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
constructor({ candidate = '', sdpMLineIndex = null, sdpMid = null }) {
|
|
7
|
+
if (sdpMLineIndex === null || sdpMid === null) {
|
|
8
|
+
throw new TypeError('`sdpMLineIndex` and `sdpMid` must not null');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
this.candidate = candidate;
|
|
12
|
+
this.sdpMLineIndex = sdpMLineIndex;
|
|
13
|
+
this.sdpMid = sdpMid;
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
toJSON() {
|
package/src/RTCPeerConnection.ts
CHANGED
|
@@ -156,7 +156,12 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
156
156
|
transceiversInfo
|
|
157
157
|
} = await WebRTCModule.peerConnectionSetLocalDescription(this._pcId, desc);
|
|
158
158
|
|
|
159
|
-
|
|
159
|
+
if (sdpInfo.type && sdpInfo.sdp) {
|
|
160
|
+
this.localDescription = new RTCSessionDescription(sdpInfo);
|
|
161
|
+
} else {
|
|
162
|
+
this.localDescription = null;
|
|
163
|
+
}
|
|
164
|
+
|
|
160
165
|
this._updateTransceivers(transceiversInfo);
|
|
161
166
|
|
|
162
167
|
log.debug(`${this._pcId} setLocalDescription OK`);
|
|
@@ -186,12 +191,24 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
186
191
|
if (successful) {
|
|
187
192
|
log.debug(`${this._pcId} setRemoteDescription OK`);
|
|
188
193
|
|
|
189
|
-
|
|
194
|
+
const {
|
|
195
|
+
sdpInfo,
|
|
196
|
+
newTransceivers,
|
|
197
|
+
transceiversInfo
|
|
198
|
+
} = data;
|
|
199
|
+
|
|
200
|
+
if (sdpInfo.type && sdpInfo.sdp) {
|
|
201
|
+
this.remoteDescription = new RTCSessionDescription(sdpInfo);
|
|
202
|
+
} else {
|
|
203
|
+
this.remoteDescription = null;
|
|
204
|
+
}
|
|
190
205
|
|
|
191
|
-
|
|
206
|
+
newTransceivers?.forEach( t => {
|
|
192
207
|
const { transceiverOrder, transceiver } = t;
|
|
193
|
-
const newSender = new RTCRtpSender(transceiver.sender);
|
|
194
|
-
const
|
|
208
|
+
const newSender = new RTCRtpSender({ ...transceiver.sender, track: null });
|
|
209
|
+
const remoteTrack
|
|
210
|
+
= transceiver.receiver.track ? new MediaStreamTrack(transceiver.receiver.track) : null;
|
|
211
|
+
const newReceiver = new RTCRtpReceiver({ ...transceiver.receiver, track: remoteTrack });
|
|
195
212
|
const newTransceiver = new RTCRtpTransceiver({
|
|
196
213
|
...transceiver,
|
|
197
214
|
sender: newSender,
|
|
@@ -201,7 +218,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
201
218
|
this._insertTransceiverSorted(transceiverOrder, newTransceiver);
|
|
202
219
|
});
|
|
203
220
|
|
|
204
|
-
this._updateTransceivers(
|
|
221
|
+
this._updateTransceivers(transceiversInfo);
|
|
205
222
|
|
|
206
223
|
resolve();
|
|
207
224
|
} else {
|
|
@@ -216,10 +233,19 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
216
233
|
log.debug(`${this._pcId} addIceCandidate`);
|
|
217
234
|
|
|
218
235
|
if (!candidate || !candidate.candidate) {
|
|
219
|
-
// XXX end-of
|
|
236
|
+
// XXX end-of candidates is not implemented: https://bugs.chromium.org/p/webrtc/issues/detail?id=9218
|
|
220
237
|
return;
|
|
221
238
|
}
|
|
222
239
|
|
|
240
|
+
if (
|
|
241
|
+
candidate.sdpMLineIndex === null ||
|
|
242
|
+
candidate.sdpMLineIndex === undefined ||
|
|
243
|
+
candidate.sdpMid === null ||
|
|
244
|
+
candidate.sdpMid === undefined
|
|
245
|
+
) {
|
|
246
|
+
throw new TypeError('`sdpMLineIndex` and `sdpMid` must not null or undefined');
|
|
247
|
+
}
|
|
248
|
+
|
|
223
249
|
const newSdp = await WebRTCModule.peerConnectionAddICECandidate(
|
|
224
250
|
this._pcId,
|
|
225
251
|
candidate.toJSON ? candidate.toJSON() : candidate
|
|
@@ -486,10 +512,9 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
486
512
|
let track;
|
|
487
513
|
let transceiver;
|
|
488
514
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
= this._transceivers.filter(({ transceiver }) => transceiver.id === ev.transceiver.id);
|
|
515
|
+
const [ oldTransceiver ] = this
|
|
516
|
+
.getTransceivers()
|
|
517
|
+
.filter(t => t.receiver.id === ev.receiver.id);
|
|
493
518
|
|
|
494
519
|
// We need to fire this event for an existing track sometimes, like
|
|
495
520
|
// when the transceiver direction (on the sending side) switches from
|
|
@@ -497,13 +522,15 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
497
522
|
|
|
498
523
|
if (oldTransceiver) {
|
|
499
524
|
transceiver = oldTransceiver;
|
|
500
|
-
track = transceiver.
|
|
525
|
+
track = transceiver.receiver.track;
|
|
501
526
|
transceiver._mid = ev.transceiver.mid;
|
|
502
527
|
transceiver._currentDirection = ev.transceiver.currentDirection;
|
|
503
528
|
transceiver._direction = ev.transceiver.direction;
|
|
504
529
|
} else {
|
|
530
|
+
// TODO: re-evaluate if we need this branch at all. Since we now add new transceivers
|
|
531
|
+
// in sRD, we should always find them when this handler runs.
|
|
505
532
|
track = new MediaStreamTrack(ev.receiver.track);
|
|
506
|
-
const sender = new RTCRtpSender({ ...ev.transceiver
|
|
533
|
+
const sender = new RTCRtpSender({ ...ev.transceiver, track: null });
|
|
507
534
|
const receiver = new RTCRtpReceiver({ ...ev.receiver, track });
|
|
508
535
|
|
|
509
536
|
transceiver = new RTCRtpTransceiver({ ...ev.transceiver, receiver, sender });
|
|
@@ -678,7 +705,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
678
705
|
for (const update of transceiverUpdates) {
|
|
679
706
|
const [ transceiver ] = this
|
|
680
707
|
.getTransceivers()
|
|
681
|
-
.filter(t => t.id === update.transceiverId);
|
|
708
|
+
.filter(t => t.sender.id === update.transceiverId);
|
|
682
709
|
|
|
683
710
|
if (!transceiver) {
|
|
684
711
|
continue;
|
package/src/RTCRtpReceiver.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { NativeModules } from 'react-native';
|
|
2
|
+
|
|
1
3
|
import MediaStreamTrack from './MediaStreamTrack';
|
|
2
4
|
import RTCRtpCapabilities, { DEFAULT_AUDIO_CAPABILITIES, receiverCapabilities } from './RTCRtpCapabilities';
|
|
3
5
|
import { RTCRtpParametersInit } from './RTCRtpParameters';
|
|
4
6
|
import RTCRtpReceiveParameters from './RTCRtpReceiveParameters';
|
|
5
7
|
|
|
8
|
+
const { WebRTCModule } = NativeModules;
|
|
6
9
|
|
|
7
10
|
export default class RTCRtpReceiver {
|
|
8
11
|
_id: string;
|
|
@@ -37,6 +40,20 @@ export default class RTCRtpReceiver {
|
|
|
37
40
|
return receiverCapabilities;
|
|
38
41
|
}
|
|
39
42
|
|
|
43
|
+
getStats() {
|
|
44
|
+
return WebRTCModule.receiverGetStats(this._peerConnectionId, this._id).then(data =>
|
|
45
|
+
/* On both Android and iOS it is faster to construct a single
|
|
46
|
+
JSON string representing the Map of StatsReports and have it
|
|
47
|
+
pass through the React Native bridge rather than the Map of
|
|
48
|
+
StatsReports. While the implementations do try to be faster in
|
|
49
|
+
general, the stress is on being faster to pass through the React
|
|
50
|
+
Native bridge which is a bottleneck that tends to be visible in
|
|
51
|
+
the UI when there is congestion involving UI-related passing.
|
|
52
|
+
*/
|
|
53
|
+
new Map(JSON.parse(data))
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
40
57
|
getParameters(): RTCRtpReceiveParameters {
|
|
41
58
|
return this._rtpParameters;
|
|
42
59
|
}
|
package/src/RTCRtpSender.ts
CHANGED
|
@@ -62,6 +62,20 @@ export default class RTCRtpSender {
|
|
|
62
62
|
this._rtpParameters = new RTCRtpSendParameters(newParameters);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
getStats() {
|
|
66
|
+
return WebRTCModule.senderGetStats(this._peerConnectionId, this._id).then(data =>
|
|
67
|
+
/* On both Android and iOS it is faster to construct a single
|
|
68
|
+
JSON string representing the Map of StatsReports and have it
|
|
69
|
+
pass through the React Native bridge rather than the Map of
|
|
70
|
+
StatsReports. While the implementations do try to be faster in
|
|
71
|
+
general, the stress is on being faster to pass through the React
|
|
72
|
+
Native bridge which is a bottleneck that tends to be visible in
|
|
73
|
+
the UI when there is congestion involving UI-related passing.
|
|
74
|
+
*/
|
|
75
|
+
new Map(JSON.parse(data))
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
65
79
|
get track() {
|
|
66
80
|
return this._track;
|
|
67
81
|
}
|
package/src/RTCRtpTransceiver.ts
CHANGED
|
@@ -11,7 +11,6 @@ export default class RTCRtpTransceiver {
|
|
|
11
11
|
_sender: RTCRtpSender;
|
|
12
12
|
_receiver: RTCRtpReceiver;
|
|
13
13
|
|
|
14
|
-
_id: string;
|
|
15
14
|
_mid: string | null = null;
|
|
16
15
|
_direction: string;
|
|
17
16
|
_currentDirection: string;
|
|
@@ -19,7 +18,6 @@ export default class RTCRtpTransceiver {
|
|
|
19
18
|
|
|
20
19
|
constructor(args: {
|
|
21
20
|
peerConnectionId: number,
|
|
22
|
-
id: string,
|
|
23
21
|
isStopped: boolean,
|
|
24
22
|
direction: string,
|
|
25
23
|
currentDirection: string,
|
|
@@ -28,7 +26,6 @@ export default class RTCRtpTransceiver {
|
|
|
28
26
|
receiver: RTCRtpReceiver,
|
|
29
27
|
}) {
|
|
30
28
|
this._peerConnectionId = args.peerConnectionId;
|
|
31
|
-
this._id = args.id;
|
|
32
29
|
this._mid = args.mid ? args.mid : null;
|
|
33
30
|
this._direction = args.direction;
|
|
34
31
|
this._currentDirection = args.currentDirection;
|
|
@@ -37,10 +34,6 @@ export default class RTCRtpTransceiver {
|
|
|
37
34
|
this._receiver = args.receiver;
|
|
38
35
|
}
|
|
39
36
|
|
|
40
|
-
get id() {
|
|
41
|
-
return this._id;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
37
|
get mid() {
|
|
45
38
|
return this._mid;
|
|
46
39
|
}
|
|
@@ -68,7 +61,7 @@ export default class RTCRtpTransceiver {
|
|
|
68
61
|
|
|
69
62
|
const oldDirection = this._direction;
|
|
70
63
|
|
|
71
|
-
WebRTCModule.transceiverSetDirection(this._peerConnectionId, this.id, val)
|
|
64
|
+
WebRTCModule.transceiverSetDirection(this._peerConnectionId, this.sender.id, val)
|
|
72
65
|
.catch(() => {
|
|
73
66
|
this._direction = oldDirection;
|
|
74
67
|
});
|
|
@@ -93,7 +86,7 @@ export default class RTCRtpTransceiver {
|
|
|
93
86
|
return;
|
|
94
87
|
}
|
|
95
88
|
|
|
96
|
-
WebRTCModule.transceiverStop(this._peerConnectionId, this.id)
|
|
89
|
+
WebRTCModule.transceiverStop(this._peerConnectionId, this.sender.id)
|
|
97
90
|
.then(() => this._setStopped());
|
|
98
91
|
}
|
|
99
92
|
|