|
@@ -189,16 +189,51 @@ export default class RTC extends Listenable {
|
189
|
189
|
// The last N change listener.
|
190
|
190
|
this._lastNChangeListener = this._onLastNChanged.bind(this);
|
191
|
191
|
|
|
192
|
+ this._onDeviceListChanged = this._onDeviceListChanged.bind(this);
|
|
193
|
+ this._updateAudioOutputForAudioTracks
|
|
194
|
+ = this._updateAudioOutputForAudioTracks.bind(this);
|
|
195
|
+
|
192
|
196
|
// Switch audio output device on all remote audio tracks. Local audio
|
193
|
197
|
// tracks handle this event by themselves.
|
194
|
198
|
if (RTCUtils.isDeviceChangeAvailable('output')) {
|
195
|
|
- RTCUtils.addListener(RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
|
196
|
|
- deviceId => this._updateAudioOutputForAudioTracks(deviceId));
|
|
199
|
+ RTCUtils.addListener(
|
|
200
|
+ RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
|
|
201
|
+ this._updateAudioOutputForAudioTracks
|
|
202
|
+ );
|
197
|
203
|
|
198
|
204
|
RTCUtils.addListener(
|
199
|
205
|
RTCEvents.DEVICE_LIST_CHANGED,
|
200
|
|
- () => this._updateAudioOutputForAudioTracks(
|
201
|
|
- RTCUtils.getAudioOutputDevice()));
|
|
206
|
+ this._onDeviceListChanged
|
|
207
|
+ );
|
|
208
|
+ }
|
|
209
|
+ }
|
|
210
|
+
|
|
211
|
+ /**
|
|
212
|
+ * Removes any listeners and stored state from this {@code RTC} instance.
|
|
213
|
+ *
|
|
214
|
+ * @returns {void}
|
|
215
|
+ */
|
|
216
|
+ destroy() {
|
|
217
|
+ RTCUtils.removeListener(
|
|
218
|
+ RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
|
|
219
|
+ this._updateAudioOutputForAudioTracks
|
|
220
|
+ );
|
|
221
|
+
|
|
222
|
+ RTCUtils.removeListener(
|
|
223
|
+ RTCEvents.DEVICE_LIST_CHANGED,
|
|
224
|
+ this._onDeviceListChanged
|
|
225
|
+ );
|
|
226
|
+
|
|
227
|
+ this.removeListener(
|
|
228
|
+ RTCEvents.LASTN_ENDPOINT_CHANGED,
|
|
229
|
+ this._lastNChangeListener
|
|
230
|
+ );
|
|
231
|
+
|
|
232
|
+ if (this._channelOpenListener) {
|
|
233
|
+ this.removeListener(
|
|
234
|
+ RTCEvents.DATA_CHANNEL_OPEN,
|
|
235
|
+ this._channelOpenListener
|
|
236
|
+ );
|
202
|
237
|
}
|
203
|
238
|
}
|
204
|
239
|
|
|
@@ -302,6 +337,18 @@ export default class RTC extends Listenable {
|
302
|
337
|
this._lastNChangeListener);
|
303
|
338
|
}
|
304
|
339
|
|
|
340
|
+ /**
|
|
341
|
+ * Callback invoked when the list of known audio and video devices has
|
|
342
|
+ * been updated. Attempts to update the known available audio output
|
|
343
|
+ * devices.
|
|
344
|
+ *
|
|
345
|
+ * @private
|
|
346
|
+ * @returns {void}
|
|
347
|
+ */
|
|
348
|
+ _onDeviceListChanged() {
|
|
349
|
+ this._updateAudioOutputForAudioTracks(RTCUtils.getAudioOutputDevice());
|
|
350
|
+ }
|
|
351
|
+
|
305
|
352
|
/**
|
306
|
353
|
* Receives events when Last N had changed.
|
307
|
354
|
* @param {array} lastNEndpoints The new Last N endpoints.
|