twilio-video
Version:
Twilio Video JavaScript Library
107 lines (94 loc) • 3.66 kB
JavaScript
;
const AudioTrack = require('./audiotrack');
const mixinRemoteMediaTrack = require('./remotemediatrack');
const RemoteMediaAudioTrack = mixinRemoteMediaTrack(AudioTrack);
/**
* A {@link RemoteAudioTrack} represents an {@link AudioTrack} published to a
* {@link Room} by a {@link RemoteParticipant}.
* @extends AudioTrack
* @property {boolean} isEnabled - Whether the {@link RemoteAudioTrack} is enabled
* @property {boolean} isSwitchedOff - Whether the {@link RemoteAudioTrack} is switched off
* @property {Track.SID} sid - The {@link RemoteAudioTrack}'s SID
* @property {?Track.Priority} priority - The subscribe priority of the {@link RemoteAudioTrack}
* @emits RemoteAudioTrack#disabled
* @emits RemoteAudioTrack#enabled
* @emits RemoteAudioTrack#started
* @emits RemoteAudioTrack#switchedOff
* @emits RemoteAudioTrack#switchedOn
*/
class RemoteAudioTrack extends RemoteMediaAudioTrack {
/**
* Construct a {@link RemoteAudioTrack}.
* @param {Track.SID} sid - The {@link RemoteAudioTrack}'s SID
* @param {MediaTrackReceiver} mediaTrackReceiver - An audio MediaStreamTrack container
* @param {boolean} isEnabled - Whether the {@link RemoteAudioTrack} is enabled
* @param {boolean} isSwitchedOff - Whether the {@link RemoteAudioTrack} is switched off
* @param {function(?Track.Priority): void} setPriority - Set or clear the subscribe
* {@link Track.Priority} of the {@link RemoteAudioTrack}
* @param {function(ClientRenderHint): void} setRenderHint - Set render hints.
* @param {{log: Log}} options - The {@link RemoteTrack} options
*/
constructor(sid, mediaTrackReceiver, isEnabled, isSwitchedOff, setPriority, setRenderHint, options) {
super(sid, mediaTrackReceiver, isEnabled, isSwitchedOff, setPriority, setRenderHint, options);
}
toString() {
return `[RemoteAudioTrack #${this._instanceId}: ${this.sid}]`;
}
/**
* @private
*/
_start() {
super._start();
if (this._dummyEl) {
// NOTE(mpatwardhan): To fix VIDEO-6336, clear dummy element after the
// RemoteAudioTrack has started.
if (this._disposeMediaElement) {
this._disposeMediaElement(this._dummyEl);
} else {
this._dummyEl.srcObject = null;
}
this._dummyEl = null;
}
}
/**
* Update the subscribe {@link Track.Priority} of the {@link RemoteAudioTrack}.
* @param {?Track.Priority} priority - the new subscribe {@link Track.Priority};
* Currently setPriority has no effect on audio tracks.
* @returns {this}
* @throws {RangeError}
*/
setPriority(priority) {
return super.setPriority(priority);
}
}
/**
* The {@link RemoteAudioTrack} was disabled, i.e. "muted".
* @param {RemoteAudioTrack} track - The {@link RemoteAudioTrack} that was
* disabled
* @event RemoteAudioTrack#disabled
*/
/**
* The {@link RemoteAudioTrack} was enabled, i.e. "unmuted".
* @param {RemoteAudioTrack} track - The {@link RemoteAudioTrack} that was
* enabled
* @event RemoteAudioTrack#enabled
*/
/**
* The {@link RemoteAudioTrack} started. This means there is enough audio data
* to begin playback.
* @param {RemoteAudioTrack} track - The {@link RemoteAudioTrack} that started
* @event RemoteAudioTrack#started
*/
/**
* A {@link RemoteAudioTrack} was switched off.
* @param {RemoteAudioTrack} track - The {@link RemoteAudioTrack} that was
* switched off
* @event RemoteAudioTrack#switchedOff
*/
/**
* A {@link RemoteAudioTrack} was switched on.
* @param {RemoteAudioTrack} track - The {@link RemoteAudioTrack} that was
* switched on
* @event RemoteAudioTrack#switchedOn
*/
module.exports = RemoteAudioTrack;