Class: Conversation

Conversation

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

You can join a Conversation by first creating an OutgoingInvite with Client#inviteToConversation or by accepting an IncomingInvite with IncomingInvite#accept.

Methods

disconnect() → {this}

Disconnect from the Conversation.

Source:
Returns:
Type
this

invite(identity) → {this}

Add a Participant to the Conversation.

Parameters:
Name Type Description
identity string

The identity of the Participant to add

Source:
Throws:

INVALID_ARGUMENT

Type
Error
Returns:
Type
this
Example
var initialToken = getAccessToken();
var manager = new Twilio.AccessManager(initialToken);
var client = new Twilio.Conversations.Client(manager);

 client.inviteToConversation('alice').then(function(conversation) {
   conversation.invite('bob');

   conversation.on('participantConnected', function(participant) {
     if (participant.identity === 'bob') {
       console.log('Bob has connected');
     }
   });
 });

invite(identities) → {this}

Add Participants to the Conversation.

Parameters:
Name Type Description
identities Array.<string>

The identities of the Participants to add

Source:
Throws:

INVALID_ARGUMENT

Type
Error
Returns:
Type
this
Example
var initialToken = getAccessToken();
var manager = new Twilio.AccessManager(initialToken);
var client = new Twilio.Conversations.Client(manager);

 client.inviteToConversation('alice').then(function(conversation) {
   conversation.invite(['bob', 'charlie']);

   conversation.on('participantConnected', function() {
     if (participant.identity === 'bob') {
       console.log('Bob has connected');
     } else if (participant.identity === 'charlie') {
       console.log('Charlie has connected');
     }
   });
 });

Type Definitions

SID

A Conversation.SID is a 34-character string starting with "CV" that uniquely identifies a Conversation.

Type:
  • string
Source:

Events

disconnected

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

Parameters:
Name Type Description
conversation Conversation

The Conversation your Client was disconnected from

Source:
Example
myConversation.on('disconnected', function() {
  myConversation.localMedia.detach();
});

participantConnected

A Participant joined the Conversation.

Parameters:
Name Type Description
participant Participant

The Participant who joined

Source:
Example
myConversation.on('participantConnected', function(participant) {
  console.log(participant.identity + ' joined the Conversation');

  // Get the participant's Media,
  var participantMedia = participant.media;

  // And attach it to your application's view.
  var participantView = document.getElementById('participant-view');
  participantMedia.attach(participantView);
  participantVideos.appendChild(participantView);
});

participantDisconnected

Parameters:
Name Type Description
participant Participant

The Participant who left

Source:
Example
myConversation.on('participantDisconnected', function(participant) {
  console.log(participant.identity + ' left the Conversation');
});

participantFailed

A Participant failed to join Conversation.

Parameters:
Name Type Description
participant Participant

The Participant that failed to join

Source:
Example
myConversation.on('participantFailed', function(participant) {
  console.log(participant.identity + ' failed to join the Conversation');
});

trackAdded

A Track was added by a Participant in the Conversation.

Parameters:
Name Type Description
track Track

The Track that was added

participant Participant

The Participant who added the Track

Source:

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

Source:

trackDisabled

A Track was disabled by a Participant in the Conversation.

Parameters:
Name Type Description
track Track

The Track that was disabled

participant Participant

The Participant who disabled the Track

Source:

trackEnabled

A Track was enabled by a Participant in the Conversation.

Parameters:
Name Type Description
track Track

The Track that was enabled

participant Participant

The Participant who enabled the Track

Source:

trackEnded

One of a Participant's Tracks in the Conversation ended.

Parameters:
Name Type Description
track Track

The Track that ended

participant Participant

The Participant whose Track ended

Source:

trackRemoved

A Track was removed by a Participant in the Conversation.

Parameters:
Name Type Description
track Track

The Track that was removed

participant Participant

The Participant who removed the Track

Source:

trackStarted

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

Parameters:
Name Type Description
track Track

The Track that started

participant Participant

The Participant whose Track started

Source: