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
|
@@ -2,21 +2,29 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
2
2
|
|
|
3
3
|
import { defineCustomEventTarget } from 'event-target-shim';
|
|
4
4
|
import { NativeModules } from 'react-native';
|
|
5
|
+
import Logger from './Logger';
|
|
5
6
|
import MediaStream from './MediaStream';
|
|
6
|
-
import
|
|
7
|
+
import MediaStreamTrack from './MediaStreamTrack';
|
|
7
8
|
import MediaStreamTrackEvent from './MediaStreamTrackEvent';
|
|
9
|
+
import RTCRtpTransceiver from './RTCRtpTransceiver';
|
|
8
10
|
import RTCDataChannel from './RTCDataChannel';
|
|
9
11
|
import RTCDataChannelEvent from './RTCDataChannelEvent';
|
|
12
|
+
import RTCTrackEvent from './RTCTrackEvent';
|
|
10
13
|
import RTCSessionDescription from './RTCSessionDescription';
|
|
11
14
|
import RTCIceCandidate from './RTCIceCandidate';
|
|
12
15
|
import RTCIceCandidateEvent from './RTCIceCandidateEvent';
|
|
16
|
+
import RTCErrorEvent from './RTCErrorEvent';
|
|
13
17
|
import RTCEvent from './RTCEvent';
|
|
14
18
|
import * as RTCUtil from './RTCUtil';
|
|
15
|
-
import
|
|
19
|
+
import { addListener, removeListener } from './EventEmitter';
|
|
20
|
+
import RTCRtpReceiver from './RTCRtpReceiver';
|
|
21
|
+
import RTCRtpSender from './RTCRtpSender';
|
|
22
|
+
import RTCRtpSendParameters from './RTCRtpSendParameters';
|
|
23
|
+
const log = new Logger('pc');
|
|
16
24
|
const {
|
|
17
25
|
WebRTCModule
|
|
18
26
|
} = NativeModules;
|
|
19
|
-
const PEER_CONNECTION_EVENTS = ['connectionstatechange', 'icecandidate', 'icecandidateerror', 'iceconnectionstatechange', 'icegatheringstatechange', 'negotiationneeded', 'signalingstatechange', 'datachannel', '
|
|
27
|
+
const PEER_CONNECTION_EVENTS = ['connectionstatechange', 'icecandidate', 'icecandidateerror', 'iceconnectionstatechange', 'icegatheringstatechange', 'negotiationneeded', 'signalingstatechange', 'datachannel', 'track', 'error'];
|
|
20
28
|
let nextPeerConnectionId = 0;
|
|
21
29
|
export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_CONNECTION_EVENTS) {
|
|
22
30
|
constructor(configuration) {
|
|
@@ -36,61 +44,50 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
36
44
|
|
|
37
45
|
_defineProperty(this, "_peerConnectionId", void 0);
|
|
38
46
|
|
|
39
|
-
_defineProperty(this, "
|
|
47
|
+
_defineProperty(this, "_subscriptions", []);
|
|
40
48
|
|
|
41
|
-
_defineProperty(this, "
|
|
49
|
+
_defineProperty(this, "_transceivers", []);
|
|
42
50
|
|
|
43
|
-
_defineProperty(this, "
|
|
51
|
+
_defineProperty(this, "_remoteStreams", new Map());
|
|
44
52
|
|
|
45
53
|
this._peerConnectionId = nextPeerConnectionId++;
|
|
46
54
|
WebRTCModule.peerConnectionInit(configuration, this._peerConnectionId);
|
|
47
55
|
|
|
48
56
|
this._registerEvents();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
addStream(stream) {
|
|
52
|
-
const index = this._localStreams.indexOf(stream);
|
|
53
|
-
|
|
54
|
-
if (index !== -1) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
WebRTCModule.peerConnectionAddStream(stream._reactTag, this._peerConnectionId);
|
|
59
57
|
|
|
60
|
-
this.
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
removeStream(stream) {
|
|
64
|
-
const index = this._localStreams.indexOf(stream);
|
|
65
|
-
|
|
66
|
-
if (index === -1) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
this._localStreams.splice(index, 1);
|
|
71
|
-
|
|
72
|
-
WebRTCModule.peerConnectionRemoveStream(stream._reactTag, this._peerConnectionId);
|
|
58
|
+
log.debug(`${this._peerConnectionId} ctor`);
|
|
73
59
|
}
|
|
74
60
|
|
|
75
61
|
createOffer(options) {
|
|
62
|
+
log.debug(`${this._peerConnectionId} createOffer`);
|
|
76
63
|
return new Promise((resolve, reject) => {
|
|
77
|
-
WebRTCModule.peerConnectionCreateOffer(this._peerConnectionId, RTCUtil.
|
|
64
|
+
WebRTCModule.peerConnectionCreateOffer(this._peerConnectionId, RTCUtil.normalizeOfferOptions(options), (successful, data) => {
|
|
78
65
|
if (successful) {
|
|
79
|
-
|
|
66
|
+
log.debug(`${this._peerConnectionId} createOffer OK`);
|
|
67
|
+
|
|
68
|
+
this._updateTransceivers(data.transceiversInfo);
|
|
69
|
+
|
|
70
|
+
resolve(data.sdpInfo);
|
|
80
71
|
} else {
|
|
81
|
-
|
|
72
|
+
log.debug(`${this._peerConnectionId} createOffer ERROR`);
|
|
73
|
+
reject(data);
|
|
82
74
|
}
|
|
83
75
|
});
|
|
84
76
|
});
|
|
85
77
|
}
|
|
86
78
|
|
|
87
79
|
createAnswer() {
|
|
88
|
-
|
|
80
|
+
log.debug(`${this._peerConnectionId} createAnswer`);
|
|
89
81
|
return new Promise((resolve, reject) => {
|
|
90
|
-
WebRTCModule.peerConnectionCreateAnswer(this._peerConnectionId,
|
|
82
|
+
WebRTCModule.peerConnectionCreateAnswer(this._peerConnectionId, {}, (successful, data) => {
|
|
91
83
|
if (successful) {
|
|
92
|
-
|
|
84
|
+
log.debug(`${this._peerConnectionId} createAnswer OK`);
|
|
85
|
+
|
|
86
|
+
this._updateTransceivers(data.transceiversInfo);
|
|
87
|
+
|
|
88
|
+
resolve(data.sdpInfo);
|
|
93
89
|
} else {
|
|
90
|
+
log.debug(`${this._peerConnectionId} createAnswer ERROR`);
|
|
94
91
|
reject(data);
|
|
95
92
|
}
|
|
96
93
|
});
|
|
@@ -102,16 +99,29 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
102
99
|
}
|
|
103
100
|
|
|
104
101
|
async setLocalDescription(sessionDescription) {
|
|
102
|
+
log.debug(`${this._peerConnectionId} setLocalDescription`);
|
|
105
103
|
const desc = sessionDescription ? sessionDescription.toJSON ? sessionDescription.toJSON() : sessionDescription : null;
|
|
106
|
-
const
|
|
107
|
-
|
|
104
|
+
const {
|
|
105
|
+
sdpInfo,
|
|
106
|
+
transceiversInfo
|
|
107
|
+
} = await WebRTCModule.peerConnectionSetLocalDescription(this._peerConnectionId, desc);
|
|
108
|
+
this.localDescription = new RTCSessionDescription(sdpInfo);
|
|
109
|
+
|
|
110
|
+
this._updateTransceivers(transceiversInfo);
|
|
111
|
+
|
|
112
|
+
log.debug(`${this._peerConnectionId} setLocalDescription OK`);
|
|
108
113
|
}
|
|
109
114
|
|
|
110
115
|
setRemoteDescription(sessionDescription) {
|
|
116
|
+
log.debug(`${this._peerConnectionId} setRemoteDescription`);
|
|
111
117
|
return new Promise((resolve, reject) => {
|
|
112
118
|
WebRTCModule.peerConnectionSetRemoteDescription(sessionDescription.toJSON ? sessionDescription.toJSON() : sessionDescription, this._peerConnectionId, (successful, data) => {
|
|
113
119
|
if (successful) {
|
|
114
|
-
this.
|
|
120
|
+
log.debug(`${this._peerConnectionId} setRemoteDescription OK`);
|
|
121
|
+
this.remoteDescription = new RTCSessionDescription(data.sdpInfo);
|
|
122
|
+
|
|
123
|
+
this._updateTransceivers(data.transceiversInfo);
|
|
124
|
+
|
|
115
125
|
resolve();
|
|
116
126
|
} else {
|
|
117
127
|
reject(data);
|
|
@@ -121,6 +131,8 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
121
131
|
}
|
|
122
132
|
|
|
123
133
|
async addIceCandidate(candidate) {
|
|
134
|
+
log.debug(`${this._peerConnectionId} addIceCandidate`);
|
|
135
|
+
|
|
124
136
|
if (!candidate || !candidate.candidate) {
|
|
125
137
|
// XXX end-of cantidates is not implemented: https://bugs.chromium.org/p/webrtc/issues/detail?id=9218
|
|
126
138
|
return;
|
|
@@ -129,8 +141,129 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
129
141
|
const newSdp = await WebRTCModule.peerConnectionAddICECandidate(this._peerConnectionId, candidate.toJSON ? candidate.toJSON() : candidate);
|
|
130
142
|
this.remoteDescription = new RTCSessionDescription(newSdp);
|
|
131
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* @brief Adds a new track to the {@link RTCPeerConnection},
|
|
146
|
+
* and indicates that it is contained in the specified {@link MediaStream} array.
|
|
147
|
+
* This method has to be synchronous as the W3C API expects a track to be return
|
|
148
|
+
* @param {MediaStreamTrack} track The track to be added
|
|
149
|
+
* @param {MediaStream[]} streams An array of streams the track needs to be added to
|
|
150
|
+
* https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
addTrack(track) {
|
|
155
|
+
let streams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
156
|
+
log.debug(`${this._peerConnectionId} addTrack`);
|
|
157
|
+
if (this.connectionState === 'closed') throw new Error("Peer Connection is closed");
|
|
158
|
+
if (this._trackExists(track)) throw new Error("Track already exists in a sender");
|
|
159
|
+
const streamIds = streams.map(s => s.id);
|
|
160
|
+
const result = WebRTCModule.peerConnectionAddTrack(this._peerConnectionId, track.id, {
|
|
161
|
+
streamIds
|
|
162
|
+
});
|
|
163
|
+
if (result == null) throw new Error("Could not add sender");
|
|
164
|
+
const {
|
|
165
|
+
transceiverOrder,
|
|
166
|
+
transceiver,
|
|
167
|
+
sender
|
|
168
|
+
} = result; // According to the W3C docs, the sender could have been reused, and
|
|
169
|
+
// so we check if that is the case, and update accordingly.
|
|
170
|
+
|
|
171
|
+
const [existingSender] = this.getSenders().filter(s => s.id === sender.id);
|
|
172
|
+
|
|
173
|
+
if (existingSender) {
|
|
174
|
+
// Update sender
|
|
175
|
+
existingSender._track = track; // Update the corresponding transceiver as well
|
|
176
|
+
|
|
177
|
+
const [existingTransceiver] = this.getTransceivers().filter(t => t.sender.id === existingSender.id);
|
|
178
|
+
existingTransceiver._direction = transceiver.direction;
|
|
179
|
+
existingTransceiver._currentDirection = transceiver.currentDirection;
|
|
180
|
+
return existingSender;
|
|
181
|
+
} // This is a new transceiver, should create a transceiver for it and add it
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
const newSender = new RTCRtpSender({ ...transceiver.sender,
|
|
185
|
+
track
|
|
186
|
+
});
|
|
187
|
+
const remoteTrack = transceiver.receiver.track ? new MediaStreamTrack(transceiver.receiver.track) : null;
|
|
188
|
+
const newReceiver = new RTCRtpReceiver({ ...transceiver.receiver,
|
|
189
|
+
track: remoteTrack
|
|
190
|
+
});
|
|
191
|
+
const newTransceiver = new RTCRtpTransceiver({ ...transceiver,
|
|
192
|
+
sender: newSender,
|
|
193
|
+
receiver: newReceiver
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
this._insertTransceiverSorted(transceiverOrder, newTransceiver);
|
|
197
|
+
|
|
198
|
+
return newSender;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
addTransceiver(source, init) {
|
|
202
|
+
log.debug(`${this._peerConnectionId} addTransceiver`);
|
|
203
|
+
let src = {};
|
|
204
|
+
|
|
205
|
+
if (source === 'audio') {
|
|
206
|
+
src = {
|
|
207
|
+
type: 'audio'
|
|
208
|
+
};
|
|
209
|
+
} else if (source === 'video') {
|
|
210
|
+
src = {
|
|
211
|
+
type: 'video'
|
|
212
|
+
};
|
|
213
|
+
} else {
|
|
214
|
+
src = {
|
|
215
|
+
trackId: source.id
|
|
216
|
+
};
|
|
217
|
+
} // Extract the stream ids
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
if (init && init.streams) {
|
|
221
|
+
init.streamIds = init.streams.map(stream => {
|
|
222
|
+
return stream.id;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const result = WebRTCModule.peerConnectionAddTransceiver(this._peerConnectionId, { ...src,
|
|
227
|
+
init: { ...init
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
if (result == null) {
|
|
232
|
+
console.log("Error adding transceiver");
|
|
233
|
+
throw new Error("Transceiver could not be added");
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const t = result.transceiver;
|
|
237
|
+
const track = typeof source === 'string' ? new MediaStreamTrack(t.sender.track) : source;
|
|
238
|
+
const sender = new RTCRtpSender({ ...t.sender,
|
|
239
|
+
track
|
|
240
|
+
});
|
|
241
|
+
const remoteTrack = t.receiver.track ? new MediaStreamTrack(t.receiver.track) : null;
|
|
242
|
+
const receiver = new RTCRtpReceiver({ ...t.receiver,
|
|
243
|
+
track: remoteTrack
|
|
244
|
+
});
|
|
245
|
+
const transceiver = new RTCRtpTransceiver({ ...result.transceiver,
|
|
246
|
+
sender,
|
|
247
|
+
receiver
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
this._insertTransceiverSorted(result.transceiverOrder, transceiver);
|
|
251
|
+
|
|
252
|
+
return transceiver;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
removeTrack(sender) {
|
|
256
|
+
log.debug(`${this._peerConnectionId} removeTrack`);
|
|
257
|
+
if (this._peerConnectionId !== sender._peerConnectionId) throw new Error("Sender does not belong to this peer connection");
|
|
258
|
+
if (this.connectionState === 'closed') throw new Error("Peer Connection is closed");
|
|
259
|
+
const existingSender = this.getSenders().find(s => s === sender);
|
|
260
|
+
if (!existingSender) throw new Error("Sender does not exist");
|
|
261
|
+
if (existingSender.track === null) return;
|
|
262
|
+
WebRTCModule.peerConnectionRemoveTrack(this._peerConnectionId, sender.id);
|
|
263
|
+
}
|
|
132
264
|
|
|
133
265
|
getStats() {
|
|
266
|
+
log.debug(`${this._peerConnectionId} getStats`);
|
|
134
267
|
return WebRTCModule.peerConnectionGetStats(this._peerConnectionId).then(data => {
|
|
135
268
|
/* On both Android and iOS it is faster to construct a single
|
|
136
269
|
JSON string representing the Map of StatsReports and have it
|
|
@@ -146,15 +279,29 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
146
279
|
});
|
|
147
280
|
}
|
|
148
281
|
|
|
149
|
-
|
|
150
|
-
return this.
|
|
282
|
+
getTransceivers() {
|
|
283
|
+
return this._transceivers.map(e => e.transceiver);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
getSenders() {
|
|
287
|
+
return this._transceivers.map(e => e.transceiver.sender);
|
|
151
288
|
}
|
|
152
289
|
|
|
153
|
-
|
|
154
|
-
return this.
|
|
290
|
+
getReceivers() {
|
|
291
|
+
return this._transceivers.map(e => e.transceiver.receiver);
|
|
155
292
|
}
|
|
156
293
|
|
|
157
294
|
close() {
|
|
295
|
+
log.debug(`${this._peerConnectionId} close`); // According to the W3C spec: https://w3c.github.io/webrtc-pc/#rtcpeerconnection-interface
|
|
296
|
+
// transceivers have to be stopped
|
|
297
|
+
|
|
298
|
+
this._transceivers.forEach(_ref => {
|
|
299
|
+
let {
|
|
300
|
+
transceiver
|
|
301
|
+
} = _ref;
|
|
302
|
+
transceiver.stop();
|
|
303
|
+
});
|
|
304
|
+
|
|
158
305
|
WebRTCModule.peerConnectionClose(this._peerConnectionId);
|
|
159
306
|
}
|
|
160
307
|
|
|
@@ -162,47 +309,46 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
162
309
|
WebRTCModule.peerConnectionRestartIce(this._peerConnectionId);
|
|
163
310
|
}
|
|
164
311
|
|
|
165
|
-
_unregisterEvents() {
|
|
166
|
-
this._subscriptions.forEach(e => e.remove());
|
|
167
|
-
|
|
168
|
-
this._subscriptions = [];
|
|
169
|
-
}
|
|
170
|
-
|
|
171
312
|
_registerEvents() {
|
|
172
|
-
this
|
|
313
|
+
addListener(this, 'peerConnectionOnRenegotiationNeeded', ev => {
|
|
173
314
|
if (ev.id !== this._peerConnectionId) {
|
|
174
315
|
return;
|
|
175
316
|
} // @ts-ignore
|
|
176
317
|
|
|
177
318
|
|
|
178
319
|
this.dispatchEvent(new RTCEvent('negotiationneeded'));
|
|
179
|
-
})
|
|
320
|
+
});
|
|
321
|
+
addListener(this, 'peerConnectionIceConnectionChanged', ev => {
|
|
180
322
|
if (ev.id !== this._peerConnectionId) {
|
|
181
323
|
return;
|
|
182
324
|
}
|
|
183
325
|
|
|
184
|
-
this.iceConnectionState = ev.iceConnectionState;
|
|
185
|
-
|
|
186
|
-
this.dispatchEvent(new RTCEvent('iceconnectionstatechange'));
|
|
326
|
+
this.iceConnectionState = ev.iceConnectionState;
|
|
187
327
|
|
|
188
328
|
if (ev.iceConnectionState === 'closed') {
|
|
189
329
|
// This PeerConnection is done, clean up event handlers.
|
|
190
|
-
this
|
|
191
|
-
}
|
|
192
|
-
|
|
330
|
+
removeListener(this);
|
|
331
|
+
} // @ts-ignore
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
this.dispatchEvent(new RTCEvent('iceconnectionstatechange'));
|
|
335
|
+
});
|
|
336
|
+
addListener(this, 'peerConnectionStateChanged', ev => {
|
|
193
337
|
if (ev.id !== this._peerConnectionId) {
|
|
194
338
|
return;
|
|
195
339
|
}
|
|
196
340
|
|
|
197
|
-
this.connectionState = ev.connectionState;
|
|
198
|
-
|
|
199
|
-
this.dispatchEvent(new RTCEvent('connectionstatechange'));
|
|
341
|
+
this.connectionState = ev.connectionState;
|
|
200
342
|
|
|
201
343
|
if (ev.connectionState === 'closed') {
|
|
202
344
|
// This PeerConnection is done, clean up event handlers.
|
|
203
|
-
this
|
|
204
|
-
}
|
|
205
|
-
|
|
345
|
+
removeListener(this);
|
|
346
|
+
} // @ts-ignore
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
this.dispatchEvent(new RTCEvent('connectionstatechange'));
|
|
350
|
+
});
|
|
351
|
+
addListener(this, 'peerConnectionSignalingStateChanged', ev => {
|
|
206
352
|
if (ev.id !== this._peerConnectionId) {
|
|
207
353
|
return;
|
|
208
354
|
}
|
|
@@ -210,64 +356,113 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
210
356
|
this.signalingState = ev.signalingState; // @ts-ignore
|
|
211
357
|
|
|
212
358
|
this.dispatchEvent(new RTCEvent('signalingstatechange'));
|
|
213
|
-
})
|
|
359
|
+
});
|
|
360
|
+
addListener(this, 'peerConnectionOnTrack', ev => {
|
|
214
361
|
if (ev.id !== this._peerConnectionId) {
|
|
215
362
|
return;
|
|
216
363
|
}
|
|
217
364
|
|
|
218
|
-
|
|
365
|
+
log.debug(`${this._peerConnectionId} ontrack`);
|
|
366
|
+
const track = new MediaStreamTrack(ev.receiver.track);
|
|
367
|
+
let transceiver; // Make sure transceivers are stored in timestamp order. Also, we have to make
|
|
368
|
+
// sure we do not add a transceiver if it exists.
|
|
369
|
+
// sure we do not add a transceiver if it exists.
|
|
370
|
+
// sure we do not add a transceiver if it exists.
|
|
371
|
+
|
|
372
|
+
let [{
|
|
373
|
+
transceiver: oldTransceiver
|
|
374
|
+
} = {
|
|
375
|
+
transceiver: null
|
|
376
|
+
}] = this._transceivers.filter(_ref2 => {
|
|
377
|
+
let {
|
|
378
|
+
transceiver
|
|
379
|
+
} = _ref2;
|
|
380
|
+
return transceiver.id === ev.transceiver.id;
|
|
381
|
+
});
|
|
219
382
|
|
|
220
|
-
|
|
383
|
+
if (!oldTransceiver) {
|
|
384
|
+
// Creating objects out of the event data.
|
|
385
|
+
const sender = new RTCRtpSender({ ...ev.transceiver.sender
|
|
386
|
+
});
|
|
387
|
+
const receiver = new RTCRtpReceiver({ ...ev.receiver,
|
|
388
|
+
track
|
|
389
|
+
});
|
|
390
|
+
transceiver = new RTCRtpTransceiver({ ...ev.transceiver,
|
|
391
|
+
receiver,
|
|
392
|
+
sender
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
this._insertTransceiverSorted(ev.transceiverOrder, transceiver);
|
|
396
|
+
} else {
|
|
397
|
+
transceiver = oldTransceiver;
|
|
398
|
+
transceiver._receiver._track = track;
|
|
399
|
+
transceiver._mid = ev.transceiver.mid;
|
|
400
|
+
transceiver._currentDirection = ev.transceiver.currentDirection;
|
|
401
|
+
transceiver._direction = ev.transceiver.direction;
|
|
402
|
+
} // Get the stream object from the event. Create if necessary.
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
const streams = ev.streams.map(streamInfo => {
|
|
406
|
+
// Here we are making sure that we don't create stream objects that already exist
|
|
407
|
+
// So that event listeners do get the same object if it has been created before.
|
|
408
|
+
if (!this._remoteStreams.has(streamInfo.streamId)) {
|
|
409
|
+
const stream = new MediaStream({
|
|
410
|
+
streamId: streamInfo.streamId,
|
|
411
|
+
streamReactTag: streamInfo.streamReactTag,
|
|
412
|
+
tracks: []
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
this._remoteStreams.set(streamInfo.streamId, stream);
|
|
416
|
+
}
|
|
221
417
|
|
|
222
|
-
|
|
418
|
+
const stream = this._remoteStreams.get(streamInfo.streamId);
|
|
223
419
|
|
|
224
|
-
|
|
225
|
-
stream
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
|
|
420
|
+
stream === null || stream === void 0 ? void 0 : stream._tracks.push(track);
|
|
421
|
+
return stream;
|
|
422
|
+
});
|
|
423
|
+
const eventData = {
|
|
424
|
+
streams,
|
|
425
|
+
transceiver,
|
|
426
|
+
track,
|
|
427
|
+
receiver: transceiver.receiver
|
|
428
|
+
}; // @ts-ignore
|
|
429
|
+
|
|
430
|
+
this.dispatchEvent(new RTCTrackEvent('track', eventData));
|
|
431
|
+
});
|
|
432
|
+
addListener(this, 'peerConnectionOnRemoveTrack', ev => {
|
|
433
|
+
if (ev.peerConnectionId !== this._peerConnectionId) {
|
|
229
434
|
return;
|
|
230
435
|
}
|
|
231
436
|
|
|
232
|
-
|
|
437
|
+
log.debug(`${this._peerConnectionId} onremovetrack`); // Based on the W3C specs https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-removetrack,
|
|
438
|
+
// we need to remove the track from any media streams
|
|
439
|
+
// that were previously passed to the `track` event.
|
|
233
440
|
|
|
234
|
-
|
|
235
|
-
const
|
|
441
|
+
for (const stream of this._remoteStreams.values()) {
|
|
442
|
+
const trackIdx = stream._tracks.findIndex(t => t.id === ev.trackId);
|
|
236
443
|
|
|
237
|
-
if (
|
|
238
|
-
|
|
444
|
+
if (trackIdx !== -1) {
|
|
445
|
+
stream._tracks.splice(trackIdx, 1);
|
|
239
446
|
}
|
|
240
447
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
this.dispatchEvent(new MediaStreamEvent('removestream', {
|
|
245
|
-
stream
|
|
246
|
-
}));
|
|
247
|
-
}), EventEmitter.addListener('mediaStreamTrackMuteChanged', ev => {
|
|
448
|
+
});
|
|
449
|
+
addListener(this, 'peerConnectionOnRemoveTrackSuccessful', ev => {
|
|
248
450
|
if (ev.peerConnectionId !== this._peerConnectionId) {
|
|
249
451
|
return;
|
|
250
452
|
}
|
|
251
453
|
|
|
252
|
-
|
|
454
|
+
const [existingSender] = this.getSenders().filter(s => s.id === ev.senderId);
|
|
455
|
+
const oldTrack = existingSender._track;
|
|
253
456
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
if (t) {
|
|
258
|
-
track = t;
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
457
|
+
if (oldTrack) {
|
|
458
|
+
oldTrack._muted = true;
|
|
261
459
|
}
|
|
262
460
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}));
|
|
269
|
-
}
|
|
270
|
-
}), EventEmitter.addListener('peerConnectionGotICECandidate', ev => {
|
|
461
|
+
existingSender._track = null;
|
|
462
|
+
const [existingTransceiver] = this.getTransceivers().filter(t => t.sender.id === existingSender.id);
|
|
463
|
+
existingTransceiver._direction = existingTransceiver.direction === 'sendrecv' ? 'recvonly' : 'inactive';
|
|
464
|
+
});
|
|
465
|
+
addListener(this, 'peerConnectionGotICECandidate', ev => {
|
|
271
466
|
if (ev.id !== this._peerConnectionId) {
|
|
272
467
|
return;
|
|
273
468
|
}
|
|
@@ -278,7 +473,8 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
278
473
|
this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', {
|
|
279
474
|
candidate
|
|
280
475
|
}));
|
|
281
|
-
})
|
|
476
|
+
});
|
|
477
|
+
addListener(this, 'peerConnectionIceGatheringChanged', ev => {
|
|
282
478
|
if (ev.id !== this._peerConnectionId) {
|
|
283
479
|
return;
|
|
284
480
|
}
|
|
@@ -295,7 +491,8 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
295
491
|
|
|
296
492
|
|
|
297
493
|
this.dispatchEvent(new RTCEvent('icegatheringstatechange'));
|
|
298
|
-
})
|
|
494
|
+
});
|
|
495
|
+
addListener(this, 'peerConnectionDidOpenDataChannel', ev => {
|
|
299
496
|
if (ev.id !== this._peerConnectionId) {
|
|
300
497
|
return;
|
|
301
498
|
}
|
|
@@ -305,7 +502,36 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
305
502
|
this.dispatchEvent(new RTCDataChannelEvent('datachannel', {
|
|
306
503
|
channel
|
|
307
504
|
}));
|
|
308
|
-
})
|
|
505
|
+
}); // Since the current underlying architecture performs certain actions
|
|
506
|
+
// Asynchronously when the outer web API expects synchronous behaviour
|
|
507
|
+
// This is the only way to report error on operations for those who wish
|
|
508
|
+
// to handle them.
|
|
509
|
+
|
|
510
|
+
addListener(this, 'peerConnectionOnError', ev => {
|
|
511
|
+
if (ev.info.peerConnectionId !== this._peerConnectionId) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
log.error(`onerror: ${JSON.stringify(ev)}`); // @ts-ignore
|
|
516
|
+
|
|
517
|
+
this.dispatchEvent(new RTCErrorEvent('error', ev.func, ev.message));
|
|
518
|
+
});
|
|
519
|
+
addListener(this, 'mediaStreamTrackMuteChanged', ev => {
|
|
520
|
+
if (ev.peerConnectionId !== this._peerConnectionId) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
const [track] = this.getReceivers().map(r => r.track).filter(t => (t === null || t === void 0 ? void 0 : t.id) === ev.trackId);
|
|
525
|
+
|
|
526
|
+
if (track) {
|
|
527
|
+
track._muted = ev.muted;
|
|
528
|
+
const eventName = ev.muted ? 'mute' : 'unmute'; // @ts-ignore
|
|
529
|
+
|
|
530
|
+
track.dispatchEvent(new MediaStreamTrackEvent(eventName, {
|
|
531
|
+
track
|
|
532
|
+
}));
|
|
533
|
+
}
|
|
534
|
+
});
|
|
309
535
|
}
|
|
310
536
|
/**
|
|
311
537
|
* Creates a new RTCDataChannel object with the given label. The
|
|
@@ -337,6 +563,51 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
337
563
|
|
|
338
564
|
return new RTCDataChannel(channelInfo);
|
|
339
565
|
}
|
|
566
|
+
/**
|
|
567
|
+
* Check whether a media stream track exists already in a sender.
|
|
568
|
+
* See https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack for more information
|
|
569
|
+
*/
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
_trackExists(track) {
|
|
573
|
+
const [sender] = this.getSenders().filter(sender => {
|
|
574
|
+
var _sender$track;
|
|
575
|
+
|
|
576
|
+
return ((_sender$track = sender.track) === null || _sender$track === void 0 ? void 0 : _sender$track.id) === track.id;
|
|
577
|
+
});
|
|
578
|
+
return sender ? true : false;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* updates transceivers after offer/answer updates if necessary
|
|
582
|
+
*/
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
_updateTransceivers(transceiverUpdates) {
|
|
586
|
+
for (var update of transceiverUpdates) {
|
|
587
|
+
const [transceiver] = this.getTransceivers().filter(t => t.id === update.transceiverId);
|
|
588
|
+
if (!transceiver) continue;
|
|
589
|
+
transceiver._currentDirection = update.currentDirection;
|
|
590
|
+
transceiver._mid = update.mid;
|
|
591
|
+
transceiver._sender._rtpParameters = new RTCRtpSendParameters(update.senderRtpParameters);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Inserts transceiver into the transceiver array in the order they are created (timestamp).
|
|
596
|
+
* @param order an index that refers to when it it was created relatively.
|
|
597
|
+
* @param transceiver the transceiver object to be inserted.
|
|
598
|
+
*/
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
_insertTransceiverSorted(order, transceiver) {
|
|
602
|
+
this._transceivers.push({
|
|
603
|
+
order,
|
|
604
|
+
transceiver
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
this._transceivers.sort((a, b) => {
|
|
608
|
+
return a.order - b.order;
|
|
609
|
+
});
|
|
610
|
+
}
|
|
340
611
|
|
|
341
612
|
}
|
|
342
613
|
//# sourceMappingURL=RTCPeerConnection.js.map
|