Class: LocalAudioTrack

twilio-video~ LocalAudioTrack

A LocalAudioTrack is an AudioTrack representing audio that your LocalParticipant can publish to a Room. It can be enabled and disabled with LocalAudioTrack#enable and LocalAudioTrack#disable or stopped completely with LocalAudioTrack#stop.


new LocalAudioTrack(mediaStreamTrack [, options])

Construct a LocalAudioTrack from a MediaStreamTrack.

Extends:
Parameters:
Name Type Argument Description
mediaStreamTrack MediaStreamTrack

An audio MediaStreamTrack

options LocalTrackOptions <optional>

LocalTrack options

Properties:
Name Type Description
isStopped boolean

Whether or not the LocalAudioTrack is stopped

Fires:

Extends

Members


id

The Track's ID.

Properties:
Type Description
Track.ID
Inherited From:
Overrides:

Methods


attach()

Create an HTMLAudioElement and attach the AudioTrack to it.

The HTMLAudioElement's srcObject will be set to a new MediaStream containing the AudioTrack's MediaStreamTrack.

Inherited From:
Overrides:
Returns:

audioElement

Type
HTMLAudioElement
Example
const Video = require('twilio-video');

Video.createLocalAudioTrack().then(function(audioTrack) {
  const audioElement = audioTrack.attach();
  document.body.appendChild(audioElement);
});
  

detach()

Detach the AudioTrack from all previously attached HTMLMediaElements.

Inherited From:
Overrides:
Returns:

mediaElements

Type
Array.<HTMLMediaElement>
Example
const mediaElements = audioTrack.detach();
mediaElements.forEach(mediaElement => mediaElement.remove());
  

disable()

Disable the LocalAudioTrack. This is effectively "mute".

Fires:
Returns:
Type
this

enable( [enabled])

Enable or disable the LocalAudioTrack. This is effectively "unmute" or "mute".

Parameters:
Name Type Argument Description
enabled boolean <optional>

Specify false to mute the LocalAudioTrack

Fires:
Returns:
Type
this

enable()

Enable the LocalAudioTrack. This is effectively "unmute".

Fires:
Returns:
Type
this

stop()

Calls stop on the underlying MediaStreamTrack. If you choose to stop a LocalAudioTrack, you should unpublish it after stopping.

Fires:
Returns:
Type
this

Events


disabled

The AudioTrack was disabled, i.e. "muted".

Parameters:
Name Type Description
track AudioTrack

The AudioTrack that was disabled

Inherited From:
Overrides:

enabled

The AudioTrack was enabled, i.e. "unmuted".

Parameters:
Name Type Description
track AudioTrack

The AudioTrack that was enabled

Inherited From:
Overrides:

started

The AudioTrack started. This means there is enough audio data to begin playback.

Parameters:
Name Type Description
track AudioTrack

The AudioTrack that started

Inherited From:
Overrides: