Class: LocalAudioTrack

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 Twilio.Video.LocalAudioTrack(mediaStreamTrack [, options])

Construct a LocalAudioTrack from a MediaStreamTrack.

Parameters:
Name Type Argument Description
mediaStreamTrack MediaStreamTrack

An audio MediaStreamTrack

options LocalTrackOptions <optional>

LocalTrack options

Properties:
Name Type Description
id Track.ID

The LocalAudioTrack's ID

isStopped boolean

Whether or not the LocalAudioTrack is stopped

Fires:

Extends

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()

Enable the LocalAudioTrack. This is effectively "unmute".

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

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 LocalAudioTrack was disabled, i.e. "muted".

Parameters:
Name Type Description
track LocalAudioTrack

The LocalAudioTrack that was disabled

Overrides:

enabled

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

Parameters:
Name Type Description
track LocalAudioTrack

The LocalAudioTrack that was enabled

Overrides:

started

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

Parameters:
Name Type Description
track LocalAudioTrack

The LocalAudioTrack that started

Overrides:

stopped

The LocalAudioTrack stopped, either because LocalAudioTrack#stop was called or because the underlying MediaStreamTrack ended).

Parameters:
Name Type Description
track LocalAudioTrack

The LocalAudioTrack that stopped