Class: LocalMedia

LocalMedia

A LocalMedia object is a Media object representing LocalAudioTracks and LocalVideoTracks that your Client may share in a Room.


new Twilio.Video.LocalMedia()

Construct a LocalMedia object.

Properties:
Name Type Description
audioTracks Map.<Track.ID, LocalAudioTrack>

The LocalAudioTracks on this Media object

tracks Map.<Track.ID, LocalTrack>

The LocalAudioTracks and LocalVideoTracks on this Media object

videoTracks Map.<Track.ID, LocalVideoTrack>

The LocalVideoTracks on this Media object

Extends

Methods


<static> getLocalMedia( [options])

Get LocalMedia. By default, this requests a LocalAudioTrack and a LocalVideoTrack representing a microphone and camera.

This method calls getUserMedia internally. Pass in options to override the default behavior.

Parameters:
Name Type Argument Default Description
options LocalMedia.GetLocalMediaOptions <optional>
<nullable>
{audio:true,video:true}

Options to override LocalMedia.getLocalMedia's default behavior

Returns:
Type
Promise.<LocalMedia>

addCamera()

Adds a LocalVideoTrack representing your browser's camera to the LocalMedia object, if not already added.

Internally, this calls getUserMedia({ video: true }).

Fires:
Returns:
Type
Promise.<LocalVideoTrack>

addMicrophone()

Adds a LocalAudioTrack representing your browser's microphone to the LocalMedia object, if not already added.

Internally, this calls getUserMedia({ audio: true }).

Fires:
Returns:
Type
Promise.<LocalAudioTrack>

addStream(mediaStream)

Add a MediaStream to the LocalMedia object, constructing LocalTracks as necessary for each MediaStreamTrack contained within.

Parameters:
Name Type Description
mediaStream MediaStream

The MediaStream to add

Fires:
Returns:
Type
this

addTrack(track)

Adds a LocalTrack to the LocalMedia object, if not already added.

Parameters:
Name Type Description
track LocalTrack

The LocalTrack to add

Fires:
Returns:
Type
this

attach()

Attach the Media to a newly created <div> element.

Inherited From:
Overrides:
Returns:
Type
HTMLElement
Example
var remoteMediaEl = media.attach();
document.getElementById('div#remote-media-container').appendChild(remoteMediaEl);

detach()

Detach the Media from any and all previously attached HTMLElements.

Inherited From:
Overrides:
Returns:
Type
Array.<HTMLElement>
Example
var detachedMediaEls = media.detach();

mute()

Disable every LocalAudioTrack on this LocalMedia object.

Fires:
Returns:
Type
this

mute(enabled)

Disable or enable every LocalAudioTrack on this LocalMedia object.

Parameters:
Name Type Argument Description
enabled boolean <nullable>

Specify false to enable the LocalAudioTracks

Fires:
Returns:
Type
this

pause(enabled)

Disable or enable every LocalVideoTrack on this LocalMedia object.

Parameters:
Name Type Argument Description
enabled boolean <nullable>

Specify false to enable the LocalVideoTracks

Fires:
Returns:
Type
this

pause()

Disable every LocalVideoTrack on this LocalMedia object.

Fires:
Returns:
Type
this

removeCamera( [stop])

Removes the LocalVideoTrack representing your browser's camera, if it has been added.

Parameters:
Name Type Argument Default Description
stop boolean <optional>
<nullable>
true

Whether or not to call LocalTrack#stop on the corresponding LocalTrack

Fires:
Returns:
Type
LocalVideoTrack

removeMicrophone( [stop])

Removes the LocalAudioTrack representing your browser's microphone, if it has been added.

Parameters:
Name Type Argument Default Description
stop boolean <optional>
<nullable>
true

Whether or not to call LocalTrack#stop on the corresponding LocalTrack

Fires:
Returns:
Type
LocalAudioTrack

removeStream(mediaStream [, stop])

Remove a MediaStream from the LocalMedia object. This will remove any LocalTracks corresponding to MediaStreamTracks contained within the MediaStream.

Parameters:
Name Type Argument Default Description
mediaStream MediaStream

The MediaStream to remove

stop boolean <optional>
<nullable>
true

Whether or not to call LocalTrack#stop on the corresponding LocalTracks

Fires:
Returns:
Type
this

removeTrack(track [, stop])

Removes a LocalTrack from the LocalMedia object, if it was added.

Parameters:
Name Type Argument Default Description
track LocalTrack

The LocalTrack to remove

stop boolean <optional>
<nullable>
true

Whether or not to call LocalTrack#stop

Fires:
Returns:
Type
this

stop()

Stop all LocalAudioTracks and LocalVideoTracks on this LocalMedia object.

Returns:
Type
this

unmute()

Enable every LocalAudioTrack on this LocalMedia object.

Fires:
Returns:
Type
this

unpause()

Enable every LocalVideoTrack on this LocalMedia object.

Fires:
Returns:
Type
this

Type Definitions


GetLocalMediaOptions

You may pass these options to LocalMedia.getLocalMedia to override the default behavior.

Type:
  • object
Properties:
Name Type Argument Default Description
localMedia LocalMedia <optional>
<nullable>
null

Set to reuse an existing LocalMedia object

localStream MediaStream <optional>
<nullable>
null

Set to reuse an existing MediaStream

audio boolean <optional>
<nullable>
true

Whether or not to get local audio with getUserMedia when neither localMedia nor localStream are provided

video boolean <optional>
<nullable>
true

Whether or not to get local video with getUserMedia when neither localMedia nor localStream are provided

Events


trackAdded

A Track was added to this Media object.

Parameters:
Name Type Description
track Track

The Track that was added

Inherited From:

trackDimensionsChanged

The dimensions of a VideoTrack on this Media object changed.

Parameters:
Name Type Description
track VideoTrack

The VideoTrack whose dimensions changed

Inherited From:

trackDisabled

A Track on this Media object was disabled.

Parameters:
Name Type Description
track Track

The Track that was disabled

Inherited From:

trackEnabled

A Track on this Media object was enabled.

Parameters:
Name Type Description
track Track

The Track that was enabled

Inherited From:

trackRemoved

A Track was removed from this Media object.

Parameters:
Name Type Description
track Track

The Track that was removed

Inherited From:

trackStarted

A Track on this Media object was started.

Parameters:
Name Type Description
track Track

The Track that was started

Inherited From: