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