Class: Room

Room

A Room represents communication between your Client and one or more Participants sharing AudioTracks and VideoTracks.

You can connect to a Room by calling Client#connect.


Properties:
Name Type Description
isRecording boolean

Whether or not the Room is being recorded

localParticipant LocalParticipant

Your Client's LocalParticipant in the Room.

name string

The Room's name

participants Map.<Participant.SID, Participant>

The Participants participating in this Room

sid Room.SID

The Room's SID

state string

"connected" or "disconnected"

Fires:
Throws:

Methods


disconnect()

Disconnect from the Room.

Returns:
Type
this

getStats()

Get the Room's media statistics.

Returns:
Type
Promise.<Array.<StatsReport>>

Type Definitions


SID

A Room.SID is a 34-character string starting with "RM" that uniquely identifies a Room.

Type:
  • string

Events


disconnected

Your Client was disconnected from the Room and all other Participants.

Parameters:
Name Type Argument Description
room Room

The Room your Client was disconnected from

error TwilioError <nullable>

Present when the Client got disconnected from the Room unexpectedly

Example
myRoom.on('disconnected', function(room, error) {
  if (error) {
    console.log('Unexpectedly disconnected:', error);
  }
  myRoom.localParticipant.tracks.forEach(function(track) {
    track.stop();
    track.detach();
  });
});

participantConnected

A Participant joined the Room.

Parameters:
Name Type Description
participant Participant

The Participant who joined

Example
myRoom.on('participantConnected', function(participant) {
  console.log(participant.identity + ' joined the Room');
});

participantDisconnected

A Participant left the Room.

Parameters:
Name Type Description
participant Participant

The Participant who left

Example
myRoom.on('participantDisconnected', function(participant) {
  console.log(participant.identity + ' left the Room');
  participant.tracks.forEach(function(track) {
    track.detach().forEach(function(mediaElement) {
      mediaElement.remove();
    });
  });
});

recordingStarted

The Room is now being recorded


recordingStopped

The Room is no longer being recorded


trackAdded

A Track was added by a Participant in the Room.

Parameters:
Name Type Description
track Track

The Track that was added

participant Participant

The Participant who added the Track

Example
room.on('trackAdded', function(track, participant) {
  var participantView = document.getElementById('participant-view-' + participant.identity);
  participantView.appendChild(track.attach());
});

trackDimensionsChanged

One of the Participant's VideoTrack's dimensions changed.

Parameters:
Name Type Description
track VideoTrack

The VideoTrack whose dimensions changed

participant Participant

The Participant whose VideoTrack's dimensions changed


trackDisabled

A Track was disabled by a Participant in the Room.

Parameters:
Name Type Description
track Track

The Track that was disabled

participant Participant

The Participant who disabled the Track


trackEnabled

A Track was enabled by a Participant in the Room.

Parameters:
Name Type Description
track Track

The Track that was enabled

participant Participant

The Participant who enabled the Track


trackRemoved

A Track was removed by a Participant in the Room.

Parameters:
Name Type Description
track Track

The Track that was removed

participant Participant

The Participant who removed the Track

Example
room.on('trackRemoved', function(track, participant) {
  track.detach().forEach(function(mediaElement) {
    mediaElement.remove();
  });
});

trackStarted

One of a Participant's Tracks in the Room started.

Parameters:
Name Type Description
track Track

The Track that started

participant Participant

The Participant whose Track started