react-native-webrtc 106.0.0-beta.5 → 106.0.0-beta.6

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.
Files changed (38) hide show
  1. package/README.md +2 -2
  2. package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +18 -24
  3. package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +1 -1
  4. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +39 -62
  5. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +54 -48
  6. package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +23 -22
  7. package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.m +1 -1
  8. package/ios/RCTWebRTC/WebRTCModule.h +0 -8
  9. package/ios/RCTWebRTC/WebRTCModule.m +1 -20
  10. package/lib/commonjs/MediaStreamTrack.js +16 -0
  11. package/lib/commonjs/MediaStreamTrack.js.map +1 -1
  12. package/lib/commonjs/RTCPeerConnection.js +92 -109
  13. package/lib/commonjs/RTCPeerConnection.js.map +1 -1
  14. package/lib/commonjs/RTCRtpSender.js +6 -5
  15. package/lib/commonjs/RTCRtpSender.js.map +1 -1
  16. package/lib/commonjs/RTCRtpTransceiver.js +11 -42
  17. package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
  18. package/lib/commonjs/index.js +3 -0
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/module/MediaStreamTrack.js +17 -1
  21. package/lib/module/MediaStreamTrack.js.map +1 -1
  22. package/lib/module/RTCPeerConnection.js +92 -107
  23. package/lib/module/RTCPeerConnection.js.map +1 -1
  24. package/lib/module/RTCRtpSender.js +6 -5
  25. package/lib/module/RTCRtpSender.js.map +1 -1
  26. package/lib/module/RTCRtpTransceiver.js +11 -37
  27. package/lib/module/RTCRtpTransceiver.js.map +1 -1
  28. package/lib/module/index.js +2 -0
  29. package/lib/module/index.js.map +1 -1
  30. package/lib/typescript/MediaStreamTrack.d.ts +9 -2
  31. package/lib/typescript/RTCPeerConnection.d.ts +5 -5
  32. package/lib/typescript/RTCRtpTransceiver.d.ts +2 -5
  33. package/package.json +2 -2
  34. package/src/MediaStreamTrack.ts +16 -1
  35. package/src/RTCPeerConnection.ts +94 -114
  36. package/src/RTCRtpSender.ts +6 -7
  37. package/src/RTCRtpTransceiver.ts +15 -38
  38. package/src/index.ts +2 -0
@@ -109,6 +109,22 @@ class MediaStreamTrack extends (0, _eventTargetShim.defineCustomEventTarget)(...
109
109
 
110
110
  WebRTCModule.mediaStreamTrackSetVideoEffect(this.id, name);
111
111
  }
112
+ /**
113
+ * Internal function which is used to set the muted state on remote tracks and
114
+ * emit the mute / unmute event.
115
+ *
116
+ * @param muted Whether the track should be marked as muted / unmuted.
117
+ */
118
+
119
+
120
+ _setMutedInternal(muted) {
121
+ if (!this.remote) {
122
+ throw new Error('Track is not remote!');
123
+ }
124
+
125
+ this._muted = muted;
126
+ this.dispatchEvent(new _eventTargetShim.Event(muted ? 'mute' : 'unmute'));
127
+ }
112
128
 
113
129
  applyConstraints() {
114
130
  throw new Error('Not implemented.');
@@ -1 +1 @@
1
- {"version":3,"sources":["MediaStreamTrack.ts"],"names":["WebRTCModule","NativeModules","MEDIA_STREAM_TRACK_EVENTS","MediaStreamTrack","constructor","info","_constraints","constraints","_enabled","enabled","_settings","settings","_muted","_peerConnectionId","peerConnectionId","id","kind","remote","_readyState","readyState","toLowerCase","mediaStreamTrackSetEnabled","muted","stop","_switchCamera","Error","mediaStreamTrackSwitchCamera","_setVideoEffect","name","mediaStreamTrackSetVideoEffect","applyConstraints","clone","getCapabilities","getConstraints","getSettings","release","mediaStreamTrackRelease"],"mappings":";;;;;;;AACA;;AACA;;AAEA;;;;AAEA,MAAM;AAAEA,EAAAA;AAAF,IAAmBC,0BAAzB;AAEA,MAAMC,yBAAyB,GAAG,CAAE,OAAF,EAAW,MAAX,EAAmB,QAAnB,CAAlC;;AAIA,MAAMC,gBAAN,SAA+B,8C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AACA;AACA;AACA;AACA;;;AACIK,EAAAA,aAAa,GAAS;AAClB,QAAI,KAAKP,MAAT,EAAiB;AACb,YAAM,IAAIQ,KAAJ,CAAU,mCAAV,CAAN;AACH;;AAED,QAAI,KAAKT,IAAL,KAAc,OAAlB,EAA2B;AACvB,YAAM,IAAIS,KAAJ,CAAU,mCAAV,CAAN;AACH;;AAEDzB,IAAAA,YAAY,CAAC0B,4BAAb,CAA0C,KAAKX,EAA/C;AACH;;AAEDY,EAAAA,eAAe,CAACC,IAAD,EAAc;AACzB,QAAI,KAAKX,MAAT,EAAiB;AACb,YAAM,IAAIQ,KAAJ,CAAU,mCAAV,CAAN;AACH;;AAED,QAAI,KAAKT,IAAL,KAAc,OAAlB,EAA2B;AACvB,YAAM,IAAIS,KAAJ,CAAU,mCAAV,CAAN;AACH;;AAEDzB,IAAAA,YAAY,CAAC6B,8BAAb,CAA4C,KAAKd,EAAjD,EAAqDa,IAArD;AACH;;AAEDE,EAAAA,gBAAgB,GAAU;AACtB,UAAM,IAAIL,KAAJ,CAAU,kBAAV,CAAN;AACH;;AAEDM,EAAAA,KAAK,GAAU;AACX,UAAM,IAAIN,KAAJ,CAAU,kBAAV,CAAN;AACH;;AAEDO,EAAAA,eAAe,GAAU;AACrB,UAAM,IAAIP,KAAJ,CAAU,kBAAV,CAAN;AACH;;AAEDQ,EAAAA,cAAc,GAAG;AACb,WAAO,wBAAU,KAAK3B,YAAf,CAAP;AACH;;AAED4B,EAAAA,WAAW,GAAG;AACV,WAAO,wBAAU,KAAKxB,SAAf,CAAP;AACH;;AAEDyB,EAAAA,OAAO,GAAS;AACZnC,IAAAA,YAAY,CAACoC,uBAAb,CAAqC,KAAKrB,EAA1C;AACH;;AA3GgF;;eA8GtEZ,gB","sourcesContent":["\nimport { defineCustomEventTarget } 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\n readonly id: string;\n readonly kind: string;\n readonly label: string = '';\n readyState: MediaStreamTrackState;\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\n this.id = info.id;\n this.kind = info.kind;\n this.remote = info.remote;\n\n const _readyState = info.readyState.toLowerCase();\n\n this.readyState = _readyState === 'initializing' || _readyState === 'live' ? 'live' : 'ended';\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 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 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
+ {"version":3,"sources":["MediaStreamTrack.ts"],"names":["WebRTCModule","NativeModules","MEDIA_STREAM_TRACK_EVENTS","MediaStreamTrack","constructor","info","_constraints","constraints","_enabled","enabled","_settings","settings","_muted","_peerConnectionId","peerConnectionId","id","kind","remote","_readyState","readyState","toLowerCase","mediaStreamTrackSetEnabled","muted","stop","_switchCamera","Error","mediaStreamTrackSwitchCamera","_setVideoEffect","name","mediaStreamTrackSetVideoEffect","_setMutedInternal","dispatchEvent","Event","applyConstraints","clone","getCapabilities","getConstraints","getSettings","release","mediaStreamTrackRelease"],"mappings":";;;;;;;AACA;;AACA;;AAEA;;;;AAEA,MAAM;AAAEA,EAAAA;AAAF,IAAmBC,0BAAzB;AAEA,MAAMC,yBAAyB,GAAG,CAAE,OAAF,EAAW,MAAX,EAAmB,QAAnB,CAAlC;;AAIA,MAAMC,gBAAN,SAA+B,8CAAwB,GAAGD,yBAA3B,CAA/B,CAAqF;AAajFE,EAAAA,WAAW,CAACC,IAAD,EAAO;AACd;;AADc;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,mCAJO,EAIP;;AAAA;;AAAA;;AAGd,SAAKC,YAAL,GAAoBD,IAAI,CAACE,WAAL,IAAoB,EAAxC;AACA,SAAKC,QAAL,GAAgBH,IAAI,CAACI,OAArB;AACA,SAAKC,SAAL,GAAiBL,IAAI,CAACM,QAAL,IAAiB,EAAlC;AACA,SAAKC,MAAL,GAAc,KAAd;AACA,SAAKC,iBAAL,GAAyBR,IAAI,CAACS,gBAA9B;AAEA,SAAKC,EAAL,GAAUV,IAAI,CAACU,EAAf;AACA,SAAKC,IAAL,GAAYX,IAAI,CAACW,IAAjB;A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V,CAAN;AACH;;AAEDzB,IAAAA,YAAY,CAAC6B,8BAAb,CAA4C,KAAKd,EAAjD,EAAqDa,IAArD;AACH;AAED;AACJ;AACA;AACA;AACA;AACA;;;AACIE,EAAAA,iBAAiB,CAACR,KAAD,EAAiB;AAC9B,QAAI,CAAC,KAAKL,MAAV,EAAkB;AACd,YAAM,IAAIQ,KAAJ,CAAU,sBAAV,CAAN;AACH;;AAED,SAAKb,MAAL,GAAcU,KAAd;AACA,SAAKS,aAAL,CAAmB,IAAIC,sBAAJ,CAAUV,KAAK,GAAG,MAAH,GAAY,QAA3B,CAAnB;AACH;;AAEDW,EAAAA,gBAAgB,GAAU;AACtB,UAAM,IAAIR,KAAJ,CAAU,kBAAV,CAAN;AACH;;AAEDS,EAAAA,KAAK,GAAU;AACX,UAAM,IAAIT,KAAJ,CAAU,kBAAV,CAAN;AACH;;AAEDU,EAAAA,eAAe,GAAU;AACrB,UAAM,IAAIV,KAAJ,CAAU,kBAAV,CAAN;AACH;;AAEDW,EAAAA,cAAc,GAAG;AACb,WAAO,wBAAU,KAAK9B,YAAf,CAAP;AACH;;AAED+B,EAAAA,WAAW,GAAG;AACV,WAAO,wBAAU,KAAK3B,SAAf,CAAP;AACH;;AAED4B,EAAAA,OAAO,GAAS;AACZtC,IAAAA,YAAY,CAACuC,uBAAb,CAAqC,KAAKxB,EAA1C;AACH;;AA1HgF;;eA6HtEZ,gB","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\n readonly id: string;\n readonly kind: string;\n readonly label: string = '';\n readyState: MediaStreamTrackState;\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\n this.id = info.id;\n this.kind = info.kind;\n this.remote = info.remote;\n\n const _readyState = info.readyState.toLowerCase();\n\n this.readyState = _readyState === 'initializing' || _readyState === 'live' ? 'live' : 'ended';\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 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"]}
@@ -17,14 +17,10 @@ var _MediaStream = _interopRequireDefault(require("./MediaStream"));
17
17
 
18
18
  var _MediaStreamTrack = _interopRequireDefault(require("./MediaStreamTrack"));
19
19
 
20
- var _MediaStreamTrackEvent = _interopRequireDefault(require("./MediaStreamTrackEvent"));
21
-
22
20
  var _RTCDataChannel = _interopRequireDefault(require("./RTCDataChannel"));
23
21
 
24
22
  var _RTCDataChannelEvent = _interopRequireDefault(require("./RTCDataChannelEvent"));
25
23
 
26
- var _RTCErrorEvent = _interopRequireDefault(require("./RTCErrorEvent"));
27
-
28
24
  var _RTCEvent = _interopRequireDefault(require("./RTCEvent"));
29
25
 
30
26
  var _RTCIceCandidate = _interopRequireDefault(require("./RTCIceCandidate"));
@@ -78,32 +74,32 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
78
74
 
79
75
  _defineProperty(this, "iceConnectionState", 'new');
80
76
 
81
- _defineProperty(this, "_peerConnectionId", void 0);
77
+ _defineProperty(this, "_pcId", void 0);
82
78
 
83
79
  _defineProperty(this, "_transceivers", []);
84
80
 
85
81
  _defineProperty(this, "_remoteStreams", new Map());
86
82
 
87
- this._peerConnectionId = nextPeerConnectionId++;
88
- WebRTCModule.peerConnectionInit(configuration, this._peerConnectionId);
83
+ this._pcId = nextPeerConnectionId++;
84
+ WebRTCModule.peerConnectionInit(configuration, this._pcId);
89
85
 
90
86
  this._registerEvents();
91
87
 
92
- log.debug(`${this._peerConnectionId} ctor`);
88
+ log.debug(`${this._pcId} ctor`);
93
89
  }
94
90
 
95
91
  createOffer(options) {
96
- log.debug(`${this._peerConnectionId} createOffer`);
92
+ log.debug(`${this._pcId} createOffer`);
97
93
  return new Promise((resolve, reject) => {
98
- WebRTCModule.peerConnectionCreateOffer(this._peerConnectionId, RTCUtil.normalizeOfferOptions(options), (successful, data) => {
94
+ WebRTCModule.peerConnectionCreateOffer(this._pcId, RTCUtil.normalizeOfferOptions(options), (successful, data) => {
99
95
  if (successful) {
100
- log.debug(`${this._peerConnectionId} createOffer OK`);
96
+ log.debug(`${this._pcId} createOffer OK`);
101
97
 
102
98
  this._updateTransceivers(data.transceiversInfo);
103
99
 
104
100
  resolve(data.sdpInfo);
105
101
  } else {
106
- log.debug(`${this._peerConnectionId} createOffer ERROR`);
102
+ log.debug(`${this._pcId} createOffer ERROR`);
107
103
  reject(data);
108
104
  }
109
105
  });
@@ -111,17 +107,17 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
111
107
  }
112
108
 
113
109
  createAnswer() {
114
- log.debug(`${this._peerConnectionId} createAnswer`);
110
+ log.debug(`${this._pcId} createAnswer`);
115
111
  return new Promise((resolve, reject) => {
116
- WebRTCModule.peerConnectionCreateAnswer(this._peerConnectionId, {}, (successful, data) => {
112
+ WebRTCModule.peerConnectionCreateAnswer(this._pcId, {}, (successful, data) => {
117
113
  if (successful) {
118
- log.debug(`${this._peerConnectionId} createAnswer OK`);
114
+ log.debug(`${this._pcId} createAnswer OK`);
119
115
 
120
116
  this._updateTransceivers(data.transceiversInfo);
121
117
 
122
118
  resolve(data.sdpInfo);
123
119
  } else {
124
- log.debug(`${this._peerConnectionId} createAnswer ERROR`);
120
+ log.debug(`${this._pcId} createAnswer ERROR`);
125
121
  reject(data);
126
122
  }
127
123
  });
@@ -129,11 +125,11 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
129
125
  }
130
126
 
131
127
  setConfiguration(configuration) {
132
- WebRTCModule.peerConnectionSetConfiguration(configuration, this._peerConnectionId);
128
+ WebRTCModule.peerConnectionSetConfiguration(configuration, this._pcId);
133
129
  }
134
130
 
135
131
  async setLocalDescription(sessionDescription) {
136
- log.debug(`${this._peerConnectionId} setLocalDescription`);
132
+ log.debug(`${this._pcId} setLocalDescription`);
137
133
  let desc;
138
134
 
139
135
  if (sessionDescription) {
@@ -154,18 +150,18 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
154
150
  const {
155
151
  sdpInfo,
156
152
  transceiversInfo
157
- } = await WebRTCModule.peerConnectionSetLocalDescription(this._peerConnectionId, desc);
153
+ } = await WebRTCModule.peerConnectionSetLocalDescription(this._pcId, desc);
158
154
  this.localDescription = new _RTCSessionDescription.default(sdpInfo);
159
155
 
160
156
  this._updateTransceivers(transceiversInfo);
161
157
 
162
- log.debug(`${this._peerConnectionId} setLocalDescription OK`);
158
+ log.debug(`${this._pcId} setLocalDescription OK`);
163
159
  }
164
160
 
165
161
  setRemoteDescription(sessionDescription) {
166
162
  var _sessionDescription$s2, _desc$type;
167
163
 
168
- log.debug(`${this._peerConnectionId} setRemoteDescription`);
164
+ log.debug(`${this._pcId} setRemoteDescription`);
169
165
 
170
166
  if (!sessionDescription) {
171
167
  return Promise.reject(new Error('No session description provided'));
@@ -181,11 +177,11 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
181
177
  }
182
178
 
183
179
  return new Promise((resolve, reject) => {
184
- WebRTCModule.peerConnectionSetRemoteDescription(desc, this._peerConnectionId, (successful, data) => {
180
+ WebRTCModule.peerConnectionSetRemoteDescription(desc, this._pcId, (successful, data) => {
185
181
  if (successful) {
186
182
  var _data$newTransceivers;
187
183
 
188
- log.debug(`${this._peerConnectionId} setRemoteDescription OK`);
184
+ log.debug(`${this._pcId} setRemoteDescription OK`);
189
185
  this.remoteDescription = new _RTCSessionDescription.default(data.sdpInfo);
190
186
  (_data$newTransceivers = data.newTransceivers) === null || _data$newTransceivers === void 0 ? void 0 : _data$newTransceivers.forEach(t => {
191
187
  const {
@@ -213,29 +209,28 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
213
209
  }
214
210
 
215
211
  async addIceCandidate(candidate) {
216
- log.debug(`${this._peerConnectionId} addIceCandidate`);
212
+ log.debug(`${this._pcId} addIceCandidate`);
217
213
 
218
214
  if (!candidate || !candidate.candidate) {
219
215
  // XXX end-of cantidates is not implemented: https://bugs.chromium.org/p/webrtc/issues/detail?id=9218
220
216
  return;
221
217
  }
222
218
 
223
- const newSdp = await WebRTCModule.peerConnectionAddICECandidate(this._peerConnectionId, candidate.toJSON ? candidate.toJSON() : candidate);
219
+ const newSdp = await WebRTCModule.peerConnectionAddICECandidate(this._pcId, candidate.toJSON ? candidate.toJSON() : candidate);
224
220
  this.remoteDescription = new _RTCSessionDescription.default(newSdp);
225
221
  }
226
222
  /**
227
223
  * @brief Adds a new track to the {@link RTCPeerConnection},
228
- * and indicates that it is contained in the specified {@link MediaStream} array.
229
- * This method has to be synchronous as the W3C API expects a track to be return
224
+ * and indicates that it is contained in the specified {@link MediaStream}s.
225
+ * This method has to be synchronous as the W3C API expects a track to be returned
230
226
  * @param {MediaStreamTrack} track The track to be added
231
- * @param {MediaStream[]} streams An array of streams the track needs to be added to
227
+ * @param {...MediaStream} streams One or more {@link MediaStream}s the track needs to be added to
232
228
  * https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack
233
229
  */
234
230
 
235
231
 
236
232
  addTrack(track) {
237
- let streams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
238
- log.debug(`${this._peerConnectionId} addTrack`);
233
+ log.debug(`${this._pcId} addTrack`);
239
234
 
240
235
  if (this.connectionState === 'closed') {
241
236
  throw new Error('Peer Connection is closed');
@@ -245,8 +240,12 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
245
240
  throw new Error('Track already exists in a sender');
246
241
  }
247
242
 
243
+ for (var _len = arguments.length, streams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
244
+ streams[_key - 1] = arguments[_key];
245
+ }
246
+
248
247
  const streamIds = streams.map(s => s.id);
249
- const result = WebRTCModule.peerConnectionAddTrack(this._peerConnectionId, track.id, {
248
+ const result = WebRTCModule.peerConnectionAddTrack(this._pcId, track.id, {
250
249
  streamIds
251
250
  });
252
251
 
@@ -292,7 +291,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
292
291
  }
293
292
 
294
293
  addTransceiver(source, init) {
295
- log.debug(`${this._peerConnectionId} addTransceiver`);
294
+ log.debug(`${this._pcId} addTransceiver`);
296
295
  let src = {};
297
296
 
298
297
  if (source === 'audio') {
@@ -314,7 +313,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
314
313
  init.streamIds = init.streams.map(stream => stream.id);
315
314
  }
316
315
 
317
- const result = WebRTCModule.peerConnectionAddTransceiver(this._peerConnectionId, { ...src,
316
+ const result = WebRTCModule.peerConnectionAddTransceiver(this._pcId, { ...src,
318
317
  init: { ...init
319
318
  }
320
319
  });
@@ -353,9 +352,9 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
353
352
  }
354
353
 
355
354
  removeTrack(sender) {
356
- log.debug(`${this._peerConnectionId} removeTrack`);
355
+ log.debug(`${this._pcId} removeTrack`);
357
356
 
358
- if (this._peerConnectionId !== sender._peerConnectionId) {
357
+ if (this._pcId !== sender._peerConnectionId) {
359
358
  throw new Error('Sender does not belong to this peer connection');
360
359
  }
361
360
 
@@ -371,14 +370,18 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
371
370
 
372
371
  if (existingSender.track === null) {
373
372
  return;
374
- }
373
+ } // Blocking!
375
374
 
376
- WebRTCModule.peerConnectionRemoveTrack(this._peerConnectionId, sender.id);
375
+
376
+ WebRTCModule.peerConnectionRemoveTrack(this._pcId, sender.id);
377
+ existingSender._track = null;
378
+ const [existingTransceiver] = this.getTransceivers().filter(t => t.sender.id === existingSender.id);
379
+ existingTransceiver._direction = existingTransceiver.direction === 'sendrecv' ? 'recvonly' : 'inactive';
377
380
  }
378
381
 
379
382
  getStats() {
380
- log.debug(`${this._peerConnectionId} getStats`);
381
- return WebRTCModule.peerConnectionGetStats(this._peerConnectionId).then(data =>
383
+ log.debug(`${this._pcId} getStats`);
384
+ return WebRTCModule.peerConnectionGetStats(this._pcId).then(data =>
382
385
  /* On both Android and iOS it is faster to construct a single
383
386
  JSON string representing the Map of StatsReports and have it
384
387
  pass through the React Native bridge rather than the Map of
@@ -405,26 +408,25 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
405
408
  }
406
409
 
407
410
  close() {
408
- log.debug(`${this._peerConnectionId} close`); // According to the W3C spec: https://w3c.github.io/webrtc-pc/#rtcpeerconnection-interface
409
- // transceivers have to be stopped
411
+ log.debug(`${this._pcId} close`);
412
+ WebRTCModule.peerConnectionClose(this._pcId); // Mark transceivers as stopped.
410
413
 
411
414
  this._transceivers.forEach(_ref => {
412
415
  let {
413
416
  transceiver
414
417
  } = _ref;
415
- transceiver.stop();
416
- });
417
418
 
418
- WebRTCModule.peerConnectionClose(this._peerConnectionId);
419
+ transceiver._setStopped();
420
+ });
419
421
  }
420
422
 
421
423
  restartIce() {
422
- WebRTCModule.peerConnectionRestartIce(this._peerConnectionId);
424
+ WebRTCModule.peerConnectionRestartIce(this._pcId);
423
425
  }
424
426
 
425
427
  _registerEvents() {
426
428
  (0, _EventEmitter.addListener)(this, 'peerConnectionOnRenegotiationNeeded', ev => {
427
- if (ev.id !== this._peerConnectionId) {
429
+ if (ev.pcId !== this._pcId) {
428
430
  return;
429
431
  } // @ts-ignore
430
432
 
@@ -432,7 +434,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
432
434
  this.dispatchEvent(new _RTCEvent.default('negotiationneeded'));
433
435
  });
434
436
  (0, _EventEmitter.addListener)(this, 'peerConnectionIceConnectionChanged', ev => {
435
- if (ev.id !== this._peerConnectionId) {
437
+ if (ev.pcId !== this._pcId) {
436
438
  return;
437
439
  }
438
440
 
@@ -447,7 +449,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
447
449
  this.dispatchEvent(new _RTCEvent.default('iceconnectionstatechange'));
448
450
  });
449
451
  (0, _EventEmitter.addListener)(this, 'peerConnectionStateChanged', ev => {
450
- if (ev.id !== this._peerConnectionId) {
452
+ if (ev.pcId !== this._pcId) {
451
453
  return;
452
454
  }
453
455
 
@@ -462,7 +464,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
462
464
  this.dispatchEvent(new _RTCEvent.default('connectionstatechange'));
463
465
  });
464
466
  (0, _EventEmitter.addListener)(this, 'peerConnectionSignalingStateChanged', ev => {
465
- if (ev.id !== this._peerConnectionId) {
467
+ if (ev.pcId !== this._pcId) {
466
468
  return;
467
469
  }
468
470
 
@@ -472,12 +474,12 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
472
474
  }); // Consider moving away from this event: https://github.com/WebKit/WebKit/pull/3953
473
475
 
474
476
  (0, _EventEmitter.addListener)(this, 'peerConnectionOnTrack', ev => {
475
- if (ev.id !== this._peerConnectionId) {
477
+ if (ev.pcId !== this._pcId) {
476
478
  return;
477
479
  }
478
480
 
479
- log.debug(`${this._peerConnectionId} ontrack`);
480
- const track = new _MediaStreamTrack.default(ev.receiver.track);
481
+ log.debug(`${this._pcId} ontrack`);
482
+ let track;
481
483
  let transceiver; // Make sure transceivers are stored in timestamp order. Also, we have to make
482
484
  // sure we do not add a transceiver if it exists.
483
485
 
@@ -490,10 +492,19 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
490
492
  transceiver
491
493
  } = _ref2;
492
494
  return transceiver.id === ev.transceiver.id;
493
- });
495
+ }); // We need to fire this event for an existing track sometimes, like
496
+ // when the transceiver direction (on the sending side) switches from
497
+ // sendrecv to recvonly and then back.
498
+
494
499
 
495
- if (!oldTransceiver) {
496
- // Creating objects out of the event data.
500
+ if (oldTransceiver) {
501
+ transceiver = oldTransceiver;
502
+ track = transceiver._receiver._track;
503
+ transceiver._mid = ev.transceiver.mid;
504
+ transceiver._currentDirection = ev.transceiver.currentDirection;
505
+ transceiver._direction = ev.transceiver.direction;
506
+ } else {
507
+ track = new _MediaStreamTrack.default(ev.receiver.track);
497
508
  const sender = new _RTCRtpSender.default({ ...ev.transceiver.sender
498
509
  });
499
510
  const receiver = new _RTCRtpReceiver.default({ ...ev.receiver,
@@ -505,12 +516,6 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
505
516
  });
506
517
 
507
518
  this._insertTransceiverSorted(ev.transceiverOrder, transceiver);
508
- } else {
509
- transceiver = oldTransceiver;
510
- transceiver._receiver._track = track;
511
- transceiver._mid = ev.transceiver.mid;
512
- transceiver._currentDirection = ev.transceiver.currentDirection;
513
- transceiver._direction = ev.transceiver.direction;
514
519
  } // Get the stream object from the event. Create if necessary.
515
520
 
516
521
 
@@ -529,7 +534,10 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
529
534
 
530
535
  const stream = this._remoteStreams.get(streamInfo.streamId);
531
536
 
532
- stream === null || stream === void 0 ? void 0 : stream._tracks.push(track);
537
+ if (!(stream !== null && stream !== void 0 && stream._tracks.includes(track))) {
538
+ stream === null || stream === void 0 ? void 0 : stream._tracks.push(track);
539
+ }
540
+
533
541
  return stream;
534
542
  });
535
543
  const eventData = {
@@ -539,43 +547,36 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
539
547
  receiver: transceiver.receiver
540
548
  }; // @ts-ignore
541
549
 
542
- this.dispatchEvent(new _RTCTrackEvent.default('track', eventData));
550
+ this.dispatchEvent(new _RTCTrackEvent.default('track', eventData)); // Dispatch an unmute event for the track.
551
+
552
+ track._setMutedInternal(false);
543
553
  });
544
554
  (0, _EventEmitter.addListener)(this, 'peerConnectionOnRemoveTrack', ev => {
545
- if (ev.peerConnectionId !== this._peerConnectionId) {
555
+ if (ev.pcId !== this._pcId) {
546
556
  return;
547
557
  }
548
558
 
549
- log.debug(`${this._peerConnectionId} onremovetrack`); // Based on the W3C specs https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-removetrack,
550
- // we need to remove the track from any media streams
551
- // that were previously passed to the `track` event.
559
+ log.debug(`${this._pcId} onremovetrack`); // As per the spec:
560
+ // - Remove the track from any media streams that were previously passed to the `track` event.
561
+ // https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-removetrack,
562
+ // - Mark the track as muted:
563
+ // https://w3c.github.io/webrtc-pc/#process-remote-track-removal
552
564
 
553
565
  for (const stream of this._remoteStreams.values()) {
554
- const trackIdx = stream._tracks.findIndex(t => t.id === ev.trackId);
566
+ const [track] = stream._tracks.filter(t => t.id === ev.trackId);
555
567
 
556
- if (trackIdx !== -1) {
557
- stream._tracks.splice(trackIdx, 1);
558
- }
559
- }
560
- });
561
- (0, _EventEmitter.addListener)(this, 'peerConnectionOnRemoveTrackSuccessful', ev => {
562
- if (ev.peerConnectionId !== this._peerConnectionId) {
563
- return;
564
- }
568
+ if (track) {
569
+ const trackIdx = stream._tracks.indexOf(track);
565
570
 
566
- const [existingSender] = this.getSenders().filter(s => s.id === ev.senderId);
567
- const oldTrack = existingSender._track;
571
+ stream._tracks.splice(trackIdx, 1); // Dispatch a mute event for the track.
568
572
 
569
- if (oldTrack) {
570
- oldTrack._muted = true;
571
- }
572
573
 
573
- existingSender._track = null;
574
- const [existingTransceiver] = this.getTransceivers().filter(t => t.sender.id === existingSender.id);
575
- existingTransceiver._direction = existingTransceiver.direction === 'sendrecv' ? 'recvonly' : 'inactive';
574
+ track._setMutedInternal(true);
575
+ }
576
+ }
576
577
  });
577
578
  (0, _EventEmitter.addListener)(this, 'peerConnectionGotICECandidate', ev => {
578
- if (ev.id !== this._peerConnectionId) {
579
+ if (ev.pcId !== this._pcId) {
579
580
  return;
580
581
  }
581
582
 
@@ -587,7 +588,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
587
588
  }));
588
589
  });
589
590
  (0, _EventEmitter.addListener)(this, 'peerConnectionIceGatheringChanged', ev => {
590
- if (ev.id !== this._peerConnectionId) {
591
+ if (ev.pcId !== this._pcId) {
591
592
  return;
592
593
  }
593
594
 
@@ -605,7 +606,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
605
606
  this.dispatchEvent(new _RTCEvent.default('icegatheringstatechange'));
606
607
  });
607
608
  (0, _EventEmitter.addListener)(this, 'peerConnectionDidOpenDataChannel', ev => {
608
- if (ev.id !== this._peerConnectionId) {
609
+ if (ev.pcId !== this._pcId) {
609
610
  return;
610
611
  }
611
612
 
@@ -614,34 +615,16 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
614
615
  this.dispatchEvent(new _RTCDataChannelEvent.default('datachannel', {
615
616
  channel
616
617
  }));
617
- }); // Since the current underlying architecture performs certain actions
618
- // Asynchronously when the outer web API expects synchronous behaviour
619
- // This is the only way to report error on operations for those who wish
620
- // to handle them.
621
-
622
- (0, _EventEmitter.addListener)(this, 'peerConnectionOnError', ev => {
623
- if (ev.info.peerConnectionId !== this._peerConnectionId) {
624
- return;
625
- }
626
-
627
- log.error(`onerror: ${JSON.stringify(ev)}`); // @ts-ignore
628
-
629
- this.dispatchEvent(new _RTCErrorEvent.default('error', ev.func, ev.message));
630
618
  });
631
619
  (0, _EventEmitter.addListener)(this, 'mediaStreamTrackMuteChanged', ev => {
632
- if (ev.peerConnectionId !== this._peerConnectionId) {
620
+ if (ev.pcId !== this._pcId) {
633
621
  return;
634
622
  }
635
623
 
636
624
  const [track] = this.getReceivers().map(r => r.track).filter(t => (t === null || t === void 0 ? void 0 : t.id) === ev.trackId);
637
625
 
638
626
  if (track) {
639
- track._muted = ev.muted;
640
- const eventName = ev.muted ? 'mute' : 'unmute'; // @ts-ignore
641
-
642
- track.dispatchEvent(new _MediaStreamTrackEvent.default(eventName, {
643
- track
644
- }));
627
+ track._setMutedInternal(ev.muted);
645
628
  }
646
629
  });
647
630
  }
@@ -667,7 +650,7 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
667
650
  }
668
651
  }
669
652
 
670
- const channelInfo = WebRTCModule.createDataChannel(this._peerConnectionId, label, dataChannelDict);
653
+ const channelInfo = WebRTCModule.createDataChannel(this._pcId, label, dataChannelDict);
671
654
 
672
655
  if (channelInfo === null) {
673
656
  throw new TypeError('Failed to create new DataChannel');