react-native-webrtc 106.0.0-beta.5 → 106.0.0-beta.7
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/README.md +2 -2
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +18 -24
- package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +59 -68
- package/ios/RCTWebRTC/RCTConvert+WebRTC.m +10 -0
- package/ios/RCTWebRTC/SerializeUtils.m +4 -2
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +73 -60
- package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +23 -22
- package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.m +1 -1
- package/ios/RCTWebRTC/WebRTCModule.h +0 -8
- package/ios/RCTWebRTC/WebRTCModule.m +1 -20
- package/lib/commonjs/MediaStreamTrack.js +24 -7
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/RTCIceCandidate.js +14 -4
- package/lib/commonjs/RTCIceCandidate.js.map +1 -1
- package/lib/commonjs/RTCPeerConnection.js +129 -132
- package/lib/commonjs/RTCPeerConnection.js.map +1 -1
- package/lib/commonjs/RTCRtpSender.js +6 -5
- package/lib/commonjs/RTCRtpSender.js.map +1 -1
- package/lib/commonjs/RTCRtpTransceiver.js +11 -49
- 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 +3 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +25 -8
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/RTCIceCandidate.js +14 -4
- package/lib/module/RTCIceCandidate.js.map +1 -1
- package/lib/module/RTCPeerConnection.js +129 -130
- package/lib/module/RTCPeerConnection.js.map +1 -1
- package/lib/module/RTCRtpSender.js +6 -5
- package/lib/module/RTCRtpSender.js.map +1 -1
- package/lib/module/RTCRtpTransceiver.js +11 -44
- 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 +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/MediaStreamTrack.d.ts +11 -3
- package/lib/typescript/RTCIceCandidate.d.ts +5 -1
- package/lib/typescript/RTCPeerConnection.d.ts +5 -5
- package/lib/typescript/RTCRtpTransceiver.d.ts +2 -8
- package/lib/typescript/RTCView.d.ts +53 -46
- package/package.json +2 -2
- package/src/MediaStreamTrack.ts +23 -7
- package/src/RTCIceCandidate.ts +8 -5
- package/src/RTCPeerConnection.ts +133 -126
- package/src/RTCRtpSender.ts +6 -7
- package/src/RTCRtpTransceiver.ts +15 -45
- package/src/RTCView.ts +53 -49
- package/src/index.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["MediaStreamTrack.ts"],"names":["defineCustomEventTarget","NativeModules","deepClone","WebRTCModule","MEDIA_STREAM_TRACK_EVENTS","MediaStreamTrack","constructor","info","_constraints","constraints","_enabled","enabled","_settings","settings","_muted","_peerConnectionId","peerConnectionId","
|
|
1
|
+
{"version":3,"sources":["MediaStreamTrack.ts"],"names":["defineCustomEventTarget","Event","NativeModules","deepClone","WebRTCModule","MEDIA_STREAM_TRACK_EVENTS","MediaStreamTrack","constructor","info","_constraints","constraints","_enabled","enabled","_settings","settings","_muted","_peerConnectionId","peerConnectionId","_readyState","readyState","id","kind","remote","mediaStreamTrackSetEnabled","muted","stop","_switchCamera","Error","mediaStreamTrackSwitchCamera","_setVideoEffect","name","mediaStreamTrackSetVideoEffect","_setMutedInternal","dispatchEvent","applyConstraints","clone","getCapabilities","getConstraints","getSettings","release","mediaStreamTrackRelease"],"mappings":";;AACA,SAASA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AAEDS,EAAAA,eAAe,GAAU;AACrB,UAAM,IAAIT,KAAJ,CAAU,kBAAV,CAAN;AACH;;AAEDU,EAAAA,cAAc,GAAG;AACb,WAAOlC,SAAS,CAAC,KAAKM,YAAN,CAAhB;AACH;;AAED6B,EAAAA,WAAW,GAAG;AACV,WAAOnC,SAAS,CAAC,KAAKU,SAAN,CAAhB;AACH;;AAED0B,EAAAA,OAAO,GAAS;AACZnC,IAAAA,YAAY,CAACoC,uBAAb,CAAqC,KAAKpB,EAA1C;AACH;;AA3HgF;;AA8HrF,eAAed,gBAAf","sourcesContent":["\nimport { defineCustomEventTarget, Event } from 'event-target-shim';\nimport { NativeModules } from 'react-native';\n\nimport { deepClone } from './RTCUtil';\n\nconst { WebRTCModule } = NativeModules;\n\nconst MEDIA_STREAM_TRACK_EVENTS = [ 'ended', 'mute', 'unmute' ];\n\ntype MediaStreamTrackState = 'live' | 'ended';\n\nclass MediaStreamTrack extends defineCustomEventTarget(...MEDIA_STREAM_TRACK_EVENTS) {\n _constraints: object;\n _enabled: boolean;\n _settings: object;\n _muted: boolean;\n _peerConnectionId: number;\n _readyState: MediaStreamTrackState;\n\n readonly id: string;\n readonly kind: string;\n readonly label: string = '';\n readonly remote: boolean;\n\n constructor(info) {\n super();\n\n this._constraints = info.constraints || {};\n this._enabled = info.enabled;\n this._settings = info.settings || {};\n this._muted = false;\n this._peerConnectionId = info.peerConnectionId;\n this._readyState = info.readyState;\n\n this.id = info.id;\n this.kind = info.kind;\n this.remote = info.remote;\n }\n\n get enabled(): boolean {\n return this._enabled;\n }\n\n set enabled(enabled: boolean) {\n if (enabled === this._enabled) {\n return;\n }\n\n WebRTCModule.mediaStreamTrackSetEnabled(this.id, !this._enabled);\n this._enabled = !this._enabled;\n }\n\n get muted(): boolean {\n return this._muted;\n }\n\n get readyState(): string {\n return this._readyState;\n }\n\n stop(): void {\n WebRTCModule.mediaStreamTrackSetEnabled(this.id, false);\n this._readyState = 'ended';\n // TODO: save some stopped flag?\n }\n\n /**\n * Private / custom API for switching the cameras on the fly, without the\n * need for adding / removing tracks or doing any SDP renegotiation.\n *\n * This is how the reference application (AppRTCMobile) implements camera\n * switching.\n */\n _switchCamera(): void {\n if (this.remote) {\n throw new Error('Not implemented for remote tracks');\n }\n\n if (this.kind !== 'video') {\n throw new Error('Only implemented for video tracks');\n }\n\n WebRTCModule.mediaStreamTrackSwitchCamera(this.id);\n }\n\n _setVideoEffect(name:string) {\n if (this.remote) {\n throw new Error('Not implemented for remote tracks');\n }\n\n if (this.kind !== 'video') {\n throw new Error('Only implemented for video tracks');\n }\n\n WebRTCModule.mediaStreamTrackSetVideoEffect(this.id, name);\n }\n\n /**\n * Internal function which is used to set the muted state on remote tracks and\n * emit the mute / unmute event.\n *\n * @param muted Whether the track should be marked as muted / unmuted.\n */\n _setMutedInternal(muted: boolean) {\n if (!this.remote) {\n throw new Error('Track is not remote!');\n }\n\n this._muted = muted;\n this.dispatchEvent(new Event(muted ? 'mute' : 'unmute'));\n }\n\n applyConstraints(): never {\n throw new Error('Not implemented.');\n }\n\n clone(): never {\n throw new Error('Not implemented.');\n }\n\n getCapabilities(): never {\n throw new Error('Not implemented.');\n }\n\n getConstraints() {\n return deepClone(this._constraints);\n }\n\n getSettings() {\n return deepClone(this._settings);\n }\n\n release(): void {\n WebRTCModule.mediaStreamTrackRelease(this.id);\n }\n}\n\nexport default MediaStreamTrack;\n"]}
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
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; }
|
|
2
2
|
|
|
3
3
|
export default class RTCIceCandidate {
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(_ref) {
|
|
5
|
+
let {
|
|
6
|
+
candidate = '',
|
|
7
|
+
sdpMLineIndex = null,
|
|
8
|
+
sdpMid = null
|
|
9
|
+
} = _ref;
|
|
10
|
+
|
|
5
11
|
_defineProperty(this, "candidate", void 0);
|
|
6
12
|
|
|
7
13
|
_defineProperty(this, "sdpMLineIndex", void 0);
|
|
8
14
|
|
|
9
15
|
_defineProperty(this, "sdpMid", void 0);
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
if (sdpMLineIndex === null || sdpMid === null) {
|
|
18
|
+
throw new TypeError('`sdpMLineIndex` and `sdpMid` must not null');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
this.candidate = candidate;
|
|
22
|
+
this.sdpMLineIndex = sdpMLineIndex;
|
|
23
|
+
this.sdpMid = sdpMid;
|
|
14
24
|
}
|
|
15
25
|
|
|
16
26
|
toJSON() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["RTCIceCandidate.ts"],"names":["RTCIceCandidate","constructor","
|
|
1
|
+
{"version":3,"sources":["RTCIceCandidate.ts"],"names":["RTCIceCandidate","constructor","candidate","sdpMLineIndex","sdpMid","TypeError","toJSON"],"mappings":";;AAAA,eAAe,MAAMA,eAAN,CAAsB;AAKjCC,EAAAA,WAAW,OAA0D;AAAA,QAAzD;AAAEC,MAAAA,SAAS,GAAG,EAAd;AAAkBC,MAAAA,aAAa,GAAG,IAAlC;AAAwCC,MAAAA,MAAM,GAAG;AAAjD,KAAyD;;AAAA;;AAAA;;AAAA;;AACjE,QAAID,aAAa,KAAK,IAAlB,IAA0BC,MAAM,KAAK,IAAzC,EAA+C;AAC3C,YAAM,IAAIC,SAAJ,CAAc,4CAAd,CAAN;AACH;;AAED,SAAKH,SAAL,GAAiBA,SAAjB;AACA,SAAKC,aAAL,GAAqBA,aAArB;AACA,SAAKC,MAAL,GAAcA,MAAd;AACH;;AAEDE,EAAAA,MAAM,GAAG;AACL,WAAO;AACHJ,MAAAA,SAAS,EAAE,KAAKA,SADb;AAEHC,MAAAA,aAAa,EAAE,KAAKA,aAFjB;AAGHC,MAAAA,MAAM,EAAE,KAAKA;AAHV,KAAP;AAKH;;AArBgC","sourcesContent":["export default class RTCIceCandidate {\n candidate: string;\n sdpMLineIndex: number;\n sdpMid: string;\n\n constructor({ candidate = '', sdpMLineIndex = null, sdpMid = null }) {\n if (sdpMLineIndex === null || sdpMid === null) {\n throw new TypeError('`sdpMLineIndex` and `sdpMid` must not null');\n }\n\n this.candidate = candidate;\n this.sdpMLineIndex = sdpMLineIndex;\n this.sdpMid = sdpMid;\n }\n\n toJSON() {\n return {\n candidate: this.candidate,\n sdpMLineIndex: this.sdpMLineIndex,\n sdpMid: this.sdpMid\n };\n }\n}\n"]}
|
|
@@ -6,10 +6,8 @@ import { addListener, removeListener } from './EventEmitter';
|
|
|
6
6
|
import Logger from './Logger';
|
|
7
7
|
import MediaStream from './MediaStream';
|
|
8
8
|
import MediaStreamTrack from './MediaStreamTrack';
|
|
9
|
-
import MediaStreamTrackEvent from './MediaStreamTrackEvent';
|
|
10
9
|
import RTCDataChannel from './RTCDataChannel';
|
|
11
10
|
import RTCDataChannelEvent from './RTCDataChannelEvent';
|
|
12
|
-
import RTCErrorEvent from './RTCErrorEvent';
|
|
13
11
|
import RTCEvent from './RTCEvent';
|
|
14
12
|
import RTCIceCandidate from './RTCIceCandidate';
|
|
15
13
|
import RTCIceCandidateEvent from './RTCIceCandidateEvent';
|
|
@@ -43,32 +41,32 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
43
41
|
|
|
44
42
|
_defineProperty(this, "iceConnectionState", 'new');
|
|
45
43
|
|
|
46
|
-
_defineProperty(this, "
|
|
44
|
+
_defineProperty(this, "_pcId", void 0);
|
|
47
45
|
|
|
48
46
|
_defineProperty(this, "_transceivers", []);
|
|
49
47
|
|
|
50
48
|
_defineProperty(this, "_remoteStreams", new Map());
|
|
51
49
|
|
|
52
|
-
this.
|
|
53
|
-
WebRTCModule.peerConnectionInit(configuration, this.
|
|
50
|
+
this._pcId = nextPeerConnectionId++;
|
|
51
|
+
WebRTCModule.peerConnectionInit(configuration, this._pcId);
|
|
54
52
|
|
|
55
53
|
this._registerEvents();
|
|
56
54
|
|
|
57
|
-
log.debug(`${this.
|
|
55
|
+
log.debug(`${this._pcId} ctor`);
|
|
58
56
|
}
|
|
59
57
|
|
|
60
58
|
createOffer(options) {
|
|
61
|
-
log.debug(`${this.
|
|
59
|
+
log.debug(`${this._pcId} createOffer`);
|
|
62
60
|
return new Promise((resolve, reject) => {
|
|
63
|
-
WebRTCModule.peerConnectionCreateOffer(this.
|
|
61
|
+
WebRTCModule.peerConnectionCreateOffer(this._pcId, RTCUtil.normalizeOfferOptions(options), (successful, data) => {
|
|
64
62
|
if (successful) {
|
|
65
|
-
log.debug(`${this.
|
|
63
|
+
log.debug(`${this._pcId} createOffer OK`);
|
|
66
64
|
|
|
67
65
|
this._updateTransceivers(data.transceiversInfo);
|
|
68
66
|
|
|
69
67
|
resolve(data.sdpInfo);
|
|
70
68
|
} else {
|
|
71
|
-
log.debug(`${this.
|
|
69
|
+
log.debug(`${this._pcId} createOffer ERROR`);
|
|
72
70
|
reject(data);
|
|
73
71
|
}
|
|
74
72
|
});
|
|
@@ -76,17 +74,17 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
createAnswer() {
|
|
79
|
-
log.debug(`${this.
|
|
77
|
+
log.debug(`${this._pcId} createAnswer`);
|
|
80
78
|
return new Promise((resolve, reject) => {
|
|
81
|
-
WebRTCModule.peerConnectionCreateAnswer(this.
|
|
79
|
+
WebRTCModule.peerConnectionCreateAnswer(this._pcId, {}, (successful, data) => {
|
|
82
80
|
if (successful) {
|
|
83
|
-
log.debug(`${this.
|
|
81
|
+
log.debug(`${this._pcId} createAnswer OK`);
|
|
84
82
|
|
|
85
83
|
this._updateTransceivers(data.transceiversInfo);
|
|
86
84
|
|
|
87
85
|
resolve(data.sdpInfo);
|
|
88
86
|
} else {
|
|
89
|
-
log.debug(`${this.
|
|
87
|
+
log.debug(`${this._pcId} createAnswer ERROR`);
|
|
90
88
|
reject(data);
|
|
91
89
|
}
|
|
92
90
|
});
|
|
@@ -94,11 +92,11 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
setConfiguration(configuration) {
|
|
97
|
-
WebRTCModule.peerConnectionSetConfiguration(configuration, this.
|
|
95
|
+
WebRTCModule.peerConnectionSetConfiguration(configuration, this._pcId);
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
async setLocalDescription(sessionDescription) {
|
|
101
|
-
log.debug(`${this.
|
|
99
|
+
log.debug(`${this._pcId} setLocalDescription`);
|
|
102
100
|
let desc;
|
|
103
101
|
|
|
104
102
|
if (sessionDescription) {
|
|
@@ -119,18 +117,23 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
119
117
|
const {
|
|
120
118
|
sdpInfo,
|
|
121
119
|
transceiversInfo
|
|
122
|
-
} = await WebRTCModule.peerConnectionSetLocalDescription(this.
|
|
123
|
-
|
|
120
|
+
} = await WebRTCModule.peerConnectionSetLocalDescription(this._pcId, desc);
|
|
121
|
+
|
|
122
|
+
if (sdpInfo.type && sdpInfo.sdp) {
|
|
123
|
+
this.localDescription = new RTCSessionDescription(sdpInfo);
|
|
124
|
+
} else {
|
|
125
|
+
this.localDescription = null;
|
|
126
|
+
}
|
|
124
127
|
|
|
125
128
|
this._updateTransceivers(transceiversInfo);
|
|
126
129
|
|
|
127
|
-
log.debug(`${this.
|
|
130
|
+
log.debug(`${this._pcId} setLocalDescription OK`);
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
setRemoteDescription(sessionDescription) {
|
|
131
134
|
var _sessionDescription$s2, _desc$type;
|
|
132
135
|
|
|
133
|
-
log.debug(`${this.
|
|
136
|
+
log.debug(`${this._pcId} setRemoteDescription`);
|
|
134
137
|
|
|
135
138
|
if (!sessionDescription) {
|
|
136
139
|
return Promise.reject(new Error('No session description provided'));
|
|
@@ -146,19 +149,33 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
return new Promise((resolve, reject) => {
|
|
149
|
-
WebRTCModule.peerConnectionSetRemoteDescription(desc, this.
|
|
152
|
+
WebRTCModule.peerConnectionSetRemoteDescription(desc, this._pcId, (successful, data) => {
|
|
150
153
|
if (successful) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
log.debug(`${this._pcId} setRemoteDescription OK`);
|
|
155
|
+
const {
|
|
156
|
+
sdpInfo,
|
|
157
|
+
newTransceivers,
|
|
158
|
+
transceiversInfo
|
|
159
|
+
} = data;
|
|
160
|
+
|
|
161
|
+
if (sdpInfo.type && sdpInfo.sdp) {
|
|
162
|
+
this.remoteDescription = new RTCSessionDescription(sdpInfo);
|
|
163
|
+
} else {
|
|
164
|
+
this.remoteDescription = null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
newTransceivers === null || newTransceivers === void 0 ? void 0 : newTransceivers.forEach(t => {
|
|
156
168
|
const {
|
|
157
169
|
transceiverOrder,
|
|
158
170
|
transceiver
|
|
159
171
|
} = t;
|
|
160
|
-
const newSender = new RTCRtpSender(transceiver.sender
|
|
161
|
-
|
|
172
|
+
const newSender = new RTCRtpSender({ ...transceiver.sender,
|
|
173
|
+
track: null
|
|
174
|
+
});
|
|
175
|
+
const remoteTrack = transceiver.receiver.track ? new MediaStreamTrack(transceiver.receiver.track) : null;
|
|
176
|
+
const newReceiver = new RTCRtpReceiver({ ...transceiver.receiver,
|
|
177
|
+
track: remoteTrack
|
|
178
|
+
});
|
|
162
179
|
const newTransceiver = new RTCRtpTransceiver({ ...transceiver,
|
|
163
180
|
sender: newSender,
|
|
164
181
|
receiver: newReceiver
|
|
@@ -167,7 +184,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
167
184
|
this._insertTransceiverSorted(transceiverOrder, newTransceiver);
|
|
168
185
|
});
|
|
169
186
|
|
|
170
|
-
this._updateTransceivers(
|
|
187
|
+
this._updateTransceivers(transceiversInfo);
|
|
171
188
|
|
|
172
189
|
resolve();
|
|
173
190
|
} else {
|
|
@@ -178,29 +195,32 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
178
195
|
}
|
|
179
196
|
|
|
180
197
|
async addIceCandidate(candidate) {
|
|
181
|
-
log.debug(`${this.
|
|
198
|
+
log.debug(`${this._pcId} addIceCandidate`);
|
|
182
199
|
|
|
183
200
|
if (!candidate || !candidate.candidate) {
|
|
184
|
-
// XXX end-of
|
|
201
|
+
// XXX end-of candidates is not implemented: https://bugs.chromium.org/p/webrtc/issues/detail?id=9218
|
|
185
202
|
return;
|
|
186
203
|
}
|
|
187
204
|
|
|
188
|
-
|
|
205
|
+
if (candidate.sdpMLineIndex === null || candidate.sdpMLineIndex === undefined || candidate.sdpMid === null || candidate.sdpMid === undefined) {
|
|
206
|
+
throw new TypeError('`sdpMLineIndex` and `sdpMid` must not null or undefined');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const newSdp = await WebRTCModule.peerConnectionAddICECandidate(this._pcId, candidate.toJSON ? candidate.toJSON() : candidate);
|
|
189
210
|
this.remoteDescription = new RTCSessionDescription(newSdp);
|
|
190
211
|
}
|
|
191
212
|
/**
|
|
192
213
|
* @brief Adds a new track to the {@link RTCPeerConnection},
|
|
193
|
-
* and indicates that it is contained in the specified {@link MediaStream}
|
|
194
|
-
* This method has to be synchronous as the W3C API expects a track to be
|
|
214
|
+
* and indicates that it is contained in the specified {@link MediaStream}s.
|
|
215
|
+
* This method has to be synchronous as the W3C API expects a track to be returned
|
|
195
216
|
* @param {MediaStreamTrack} track The track to be added
|
|
196
|
-
* @param {MediaStream
|
|
217
|
+
* @param {...MediaStream} streams One or more {@link MediaStream}s the track needs to be added to
|
|
197
218
|
* https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack
|
|
198
219
|
*/
|
|
199
220
|
|
|
200
221
|
|
|
201
222
|
addTrack(track) {
|
|
202
|
-
|
|
203
|
-
log.debug(`${this._peerConnectionId} addTrack`);
|
|
223
|
+
log.debug(`${this._pcId} addTrack`);
|
|
204
224
|
|
|
205
225
|
if (this.connectionState === 'closed') {
|
|
206
226
|
throw new Error('Peer Connection is closed');
|
|
@@ -210,8 +230,12 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
210
230
|
throw new Error('Track already exists in a sender');
|
|
211
231
|
}
|
|
212
232
|
|
|
233
|
+
for (var _len = arguments.length, streams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
234
|
+
streams[_key - 1] = arguments[_key];
|
|
235
|
+
}
|
|
236
|
+
|
|
213
237
|
const streamIds = streams.map(s => s.id);
|
|
214
|
-
const result = WebRTCModule.peerConnectionAddTrack(this.
|
|
238
|
+
const result = WebRTCModule.peerConnectionAddTrack(this._pcId, track.id, {
|
|
215
239
|
streamIds
|
|
216
240
|
});
|
|
217
241
|
|
|
@@ -257,7 +281,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
257
281
|
}
|
|
258
282
|
|
|
259
283
|
addTransceiver(source, init) {
|
|
260
|
-
log.debug(`${this.
|
|
284
|
+
log.debug(`${this._pcId} addTransceiver`);
|
|
261
285
|
let src = {};
|
|
262
286
|
|
|
263
287
|
if (source === 'audio') {
|
|
@@ -279,7 +303,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
279
303
|
init.streamIds = init.streams.map(stream => stream.id);
|
|
280
304
|
}
|
|
281
305
|
|
|
282
|
-
const result = WebRTCModule.peerConnectionAddTransceiver(this.
|
|
306
|
+
const result = WebRTCModule.peerConnectionAddTransceiver(this._pcId, { ...src,
|
|
283
307
|
init: { ...init
|
|
284
308
|
}
|
|
285
309
|
});
|
|
@@ -318,9 +342,9 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
318
342
|
}
|
|
319
343
|
|
|
320
344
|
removeTrack(sender) {
|
|
321
|
-
log.debug(`${this.
|
|
345
|
+
log.debug(`${this._pcId} removeTrack`);
|
|
322
346
|
|
|
323
|
-
if (this.
|
|
347
|
+
if (this._pcId !== sender._peerConnectionId) {
|
|
324
348
|
throw new Error('Sender does not belong to this peer connection');
|
|
325
349
|
}
|
|
326
350
|
|
|
@@ -336,14 +360,18 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
336
360
|
|
|
337
361
|
if (existingSender.track === null) {
|
|
338
362
|
return;
|
|
339
|
-
}
|
|
363
|
+
} // Blocking!
|
|
340
364
|
|
|
341
|
-
|
|
365
|
+
|
|
366
|
+
WebRTCModule.peerConnectionRemoveTrack(this._pcId, sender.id);
|
|
367
|
+
existingSender._track = null;
|
|
368
|
+
const [existingTransceiver] = this.getTransceivers().filter(t => t.sender.id === existingSender.id);
|
|
369
|
+
existingTransceiver._direction = existingTransceiver.direction === 'sendrecv' ? 'recvonly' : 'inactive';
|
|
342
370
|
}
|
|
343
371
|
|
|
344
372
|
getStats() {
|
|
345
|
-
log.debug(`${this.
|
|
346
|
-
return WebRTCModule.peerConnectionGetStats(this.
|
|
373
|
+
log.debug(`${this._pcId} getStats`);
|
|
374
|
+
return WebRTCModule.peerConnectionGetStats(this._pcId).then(data =>
|
|
347
375
|
/* On both Android and iOS it is faster to construct a single
|
|
348
376
|
JSON string representing the Map of StatsReports and have it
|
|
349
377
|
pass through the React Native bridge rather than the Map of
|
|
@@ -370,26 +398,25 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
370
398
|
}
|
|
371
399
|
|
|
372
400
|
close() {
|
|
373
|
-
log.debug(`${this.
|
|
374
|
-
// transceivers
|
|
401
|
+
log.debug(`${this._pcId} close`);
|
|
402
|
+
WebRTCModule.peerConnectionClose(this._pcId); // Mark transceivers as stopped.
|
|
375
403
|
|
|
376
404
|
this._transceivers.forEach(_ref => {
|
|
377
405
|
let {
|
|
378
406
|
transceiver
|
|
379
407
|
} = _ref;
|
|
380
|
-
transceiver.stop();
|
|
381
|
-
});
|
|
382
408
|
|
|
383
|
-
|
|
409
|
+
transceiver._setStopped();
|
|
410
|
+
});
|
|
384
411
|
}
|
|
385
412
|
|
|
386
413
|
restartIce() {
|
|
387
|
-
WebRTCModule.peerConnectionRestartIce(this.
|
|
414
|
+
WebRTCModule.peerConnectionRestartIce(this._pcId);
|
|
388
415
|
}
|
|
389
416
|
|
|
390
417
|
_registerEvents() {
|
|
391
418
|
addListener(this, 'peerConnectionOnRenegotiationNeeded', ev => {
|
|
392
|
-
if (ev.
|
|
419
|
+
if (ev.pcId !== this._pcId) {
|
|
393
420
|
return;
|
|
394
421
|
} // @ts-ignore
|
|
395
422
|
|
|
@@ -397,7 +424,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
397
424
|
this.dispatchEvent(new RTCEvent('negotiationneeded'));
|
|
398
425
|
});
|
|
399
426
|
addListener(this, 'peerConnectionIceConnectionChanged', ev => {
|
|
400
|
-
if (ev.
|
|
427
|
+
if (ev.pcId !== this._pcId) {
|
|
401
428
|
return;
|
|
402
429
|
}
|
|
403
430
|
|
|
@@ -412,7 +439,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
412
439
|
this.dispatchEvent(new RTCEvent('iceconnectionstatechange'));
|
|
413
440
|
});
|
|
414
441
|
addListener(this, 'peerConnectionStateChanged', ev => {
|
|
415
|
-
if (ev.
|
|
442
|
+
if (ev.pcId !== this._pcId) {
|
|
416
443
|
return;
|
|
417
444
|
}
|
|
418
445
|
|
|
@@ -427,7 +454,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
427
454
|
this.dispatchEvent(new RTCEvent('connectionstatechange'));
|
|
428
455
|
});
|
|
429
456
|
addListener(this, 'peerConnectionSignalingStateChanged', ev => {
|
|
430
|
-
if (ev.
|
|
457
|
+
if (ev.pcId !== this._pcId) {
|
|
431
458
|
return;
|
|
432
459
|
}
|
|
433
460
|
|
|
@@ -437,29 +464,29 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
437
464
|
}); // Consider moving away from this event: https://github.com/WebKit/WebKit/pull/3953
|
|
438
465
|
|
|
439
466
|
addListener(this, 'peerConnectionOnTrack', ev => {
|
|
440
|
-
if (ev.
|
|
467
|
+
if (ev.pcId !== this._pcId) {
|
|
441
468
|
return;
|
|
442
469
|
}
|
|
443
470
|
|
|
444
|
-
log.debug(`${this.
|
|
445
|
-
|
|
446
|
-
let transceiver;
|
|
447
|
-
//
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
transceiver: oldTransceiver
|
|
451
|
-
} = {
|
|
452
|
-
transceiver: null
|
|
453
|
-
}] = this._transceivers.filter(_ref2 => {
|
|
454
|
-
let {
|
|
455
|
-
transceiver
|
|
456
|
-
} = _ref2;
|
|
457
|
-
return transceiver.id === ev.transceiver.id;
|
|
458
|
-
});
|
|
471
|
+
log.debug(`${this._pcId} ontrack`);
|
|
472
|
+
let track;
|
|
473
|
+
let transceiver;
|
|
474
|
+
const [oldTransceiver] = this.getTransceivers().filter(t => t.receiver.id === ev.receiver.id); // We need to fire this event for an existing track sometimes, like
|
|
475
|
+
// when the transceiver direction (on the sending side) switches from
|
|
476
|
+
// sendrecv to recvonly and then back.
|
|
459
477
|
|
|
460
|
-
if (
|
|
461
|
-
|
|
462
|
-
|
|
478
|
+
if (oldTransceiver) {
|
|
479
|
+
transceiver = oldTransceiver;
|
|
480
|
+
track = transceiver.receiver.track;
|
|
481
|
+
transceiver._mid = ev.transceiver.mid;
|
|
482
|
+
transceiver._currentDirection = ev.transceiver.currentDirection;
|
|
483
|
+
transceiver._direction = ev.transceiver.direction;
|
|
484
|
+
} else {
|
|
485
|
+
// TODO: re-evaluate if we need this branch at all. Since we now add new transceivers
|
|
486
|
+
// in sRD, we should always find them when this handler runs.
|
|
487
|
+
track = new MediaStreamTrack(ev.receiver.track);
|
|
488
|
+
const sender = new RTCRtpSender({ ...ev.transceiver,
|
|
489
|
+
track: null
|
|
463
490
|
});
|
|
464
491
|
const receiver = new RTCRtpReceiver({ ...ev.receiver,
|
|
465
492
|
track
|
|
@@ -470,12 +497,6 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
470
497
|
});
|
|
471
498
|
|
|
472
499
|
this._insertTransceiverSorted(ev.transceiverOrder, transceiver);
|
|
473
|
-
} else {
|
|
474
|
-
transceiver = oldTransceiver;
|
|
475
|
-
transceiver._receiver._track = track;
|
|
476
|
-
transceiver._mid = ev.transceiver.mid;
|
|
477
|
-
transceiver._currentDirection = ev.transceiver.currentDirection;
|
|
478
|
-
transceiver._direction = ev.transceiver.direction;
|
|
479
500
|
} // Get the stream object from the event. Create if necessary.
|
|
480
501
|
|
|
481
502
|
|
|
@@ -494,7 +515,10 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
494
515
|
|
|
495
516
|
const stream = this._remoteStreams.get(streamInfo.streamId);
|
|
496
517
|
|
|
497
|
-
stream
|
|
518
|
+
if (!(stream !== null && stream !== void 0 && stream._tracks.includes(track))) {
|
|
519
|
+
stream === null || stream === void 0 ? void 0 : stream._tracks.push(track);
|
|
520
|
+
}
|
|
521
|
+
|
|
498
522
|
return stream;
|
|
499
523
|
});
|
|
500
524
|
const eventData = {
|
|
@@ -504,43 +528,36 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
504
528
|
receiver: transceiver.receiver
|
|
505
529
|
}; // @ts-ignore
|
|
506
530
|
|
|
507
|
-
this.dispatchEvent(new RTCTrackEvent('track', eventData));
|
|
531
|
+
this.dispatchEvent(new RTCTrackEvent('track', eventData)); // Dispatch an unmute event for the track.
|
|
532
|
+
|
|
533
|
+
track._setMutedInternal(false);
|
|
508
534
|
});
|
|
509
535
|
addListener(this, 'peerConnectionOnRemoveTrack', ev => {
|
|
510
|
-
if (ev.
|
|
536
|
+
if (ev.pcId !== this._pcId) {
|
|
511
537
|
return;
|
|
512
538
|
}
|
|
513
539
|
|
|
514
|
-
log.debug(`${this.
|
|
515
|
-
//
|
|
516
|
-
//
|
|
540
|
+
log.debug(`${this._pcId} onremovetrack`); // As per the spec:
|
|
541
|
+
// - Remove the track from any media streams that were previously passed to the `track` event.
|
|
542
|
+
// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-removetrack,
|
|
543
|
+
// - Mark the track as muted:
|
|
544
|
+
// https://w3c.github.io/webrtc-pc/#process-remote-track-removal
|
|
517
545
|
|
|
518
546
|
for (const stream of this._remoteStreams.values()) {
|
|
519
|
-
const
|
|
547
|
+
const [track] = stream._tracks.filter(t => t.id === ev.trackId);
|
|
520
548
|
|
|
521
|
-
if (
|
|
522
|
-
stream._tracks.
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
addListener(this, 'peerConnectionOnRemoveTrackSuccessful', ev => {
|
|
527
|
-
if (ev.peerConnectionId !== this._peerConnectionId) {
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
549
|
+
if (track) {
|
|
550
|
+
const trackIdx = stream._tracks.indexOf(track);
|
|
530
551
|
|
|
531
|
-
|
|
532
|
-
const oldTrack = existingSender._track;
|
|
552
|
+
stream._tracks.splice(trackIdx, 1); // Dispatch a mute event for the track.
|
|
533
553
|
|
|
534
|
-
if (oldTrack) {
|
|
535
|
-
oldTrack._muted = true;
|
|
536
|
-
}
|
|
537
554
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
555
|
+
track._setMutedInternal(true);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
541
558
|
});
|
|
542
559
|
addListener(this, 'peerConnectionGotICECandidate', ev => {
|
|
543
|
-
if (ev.
|
|
560
|
+
if (ev.pcId !== this._pcId) {
|
|
544
561
|
return;
|
|
545
562
|
}
|
|
546
563
|
|
|
@@ -552,7 +569,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
552
569
|
}));
|
|
553
570
|
});
|
|
554
571
|
addListener(this, 'peerConnectionIceGatheringChanged', ev => {
|
|
555
|
-
if (ev.
|
|
572
|
+
if (ev.pcId !== this._pcId) {
|
|
556
573
|
return;
|
|
557
574
|
}
|
|
558
575
|
|
|
@@ -570,7 +587,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
570
587
|
this.dispatchEvent(new RTCEvent('icegatheringstatechange'));
|
|
571
588
|
});
|
|
572
589
|
addListener(this, 'peerConnectionDidOpenDataChannel', ev => {
|
|
573
|
-
if (ev.
|
|
590
|
+
if (ev.pcId !== this._pcId) {
|
|
574
591
|
return;
|
|
575
592
|
}
|
|
576
593
|
|
|
@@ -579,34 +596,16 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
579
596
|
this.dispatchEvent(new RTCDataChannelEvent('datachannel', {
|
|
580
597
|
channel
|
|
581
598
|
}));
|
|
582
|
-
}); // Since the current underlying architecture performs certain actions
|
|
583
|
-
// Asynchronously when the outer web API expects synchronous behaviour
|
|
584
|
-
// This is the only way to report error on operations for those who wish
|
|
585
|
-
// to handle them.
|
|
586
|
-
|
|
587
|
-
addListener(this, 'peerConnectionOnError', ev => {
|
|
588
|
-
if (ev.info.peerConnectionId !== this._peerConnectionId) {
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
log.error(`onerror: ${JSON.stringify(ev)}`); // @ts-ignore
|
|
593
|
-
|
|
594
|
-
this.dispatchEvent(new RTCErrorEvent('error', ev.func, ev.message));
|
|
595
599
|
});
|
|
596
600
|
addListener(this, 'mediaStreamTrackMuteChanged', ev => {
|
|
597
|
-
if (ev.
|
|
601
|
+
if (ev.pcId !== this._pcId) {
|
|
598
602
|
return;
|
|
599
603
|
}
|
|
600
604
|
|
|
601
605
|
const [track] = this.getReceivers().map(r => r.track).filter(t => (t === null || t === void 0 ? void 0 : t.id) === ev.trackId);
|
|
602
606
|
|
|
603
607
|
if (track) {
|
|
604
|
-
track.
|
|
605
|
-
const eventName = ev.muted ? 'mute' : 'unmute'; // @ts-ignore
|
|
606
|
-
|
|
607
|
-
track.dispatchEvent(new MediaStreamTrackEvent(eventName, {
|
|
608
|
-
track
|
|
609
|
-
}));
|
|
608
|
+
track._setMutedInternal(ev.muted);
|
|
610
609
|
}
|
|
611
610
|
});
|
|
612
611
|
}
|
|
@@ -632,7 +631,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
632
631
|
}
|
|
633
632
|
}
|
|
634
633
|
|
|
635
|
-
const channelInfo = WebRTCModule.createDataChannel(this.
|
|
634
|
+
const channelInfo = WebRTCModule.createDataChannel(this._pcId, label, dataChannelDict);
|
|
636
635
|
|
|
637
636
|
if (channelInfo === null) {
|
|
638
637
|
throw new TypeError('Failed to create new DataChannel');
|
|
@@ -661,7 +660,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
|
|
|
661
660
|
|
|
662
661
|
_updateTransceivers(transceiverUpdates) {
|
|
663
662
|
for (const update of transceiverUpdates) {
|
|
664
|
-
const [transceiver] = this.getTransceivers().filter(t => t.id === update.transceiverId);
|
|
663
|
+
const [transceiver] = this.getTransceivers().filter(t => t.sender.id === update.transceiverId);
|
|
665
664
|
|
|
666
665
|
if (!transceiver) {
|
|
667
666
|
continue;
|