3

I am using twilio video.

I want the room to be destroyed when the local participant(the one that created the room) leaves it.

So far, when the first user who created leaves the room then other users(inside the room) can still see each other's feed and can chat.

So how to destroy a video room in above scenario?

Aspl Test
  • 133
  • 1
  • 10

3 Answers3

6

Twilio developer evangelist here.

You can do this using status callbacks and the REST API.

What you need to do is somehow note which user is your room's owner. Then, register to receive video room status callbacks. You can then wait for the participant-disconnected event and if the participant that disconnected is the room's owner, then use the Room resource in the REST API to set the room to completed which will disconnect all the remaining participants.

Let me know if that helps at all.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Thanks phil, i was thinking the same, about noting the room creator.I will let you know once i do it. – Aspl Test Jan 31 '18 at 10:38
  • i have used room resource rest api from my php server end which completes the room when i call it and room status shows as completed in twilio console also but i am not getting any events in onDisconnected() method in android sdk end . – Aspl Test Jan 31 '18 at 12:43
  • You're saying that the room is completed but your participants continue to see video and are able to chat to one another still? – philnash Feb 01 '18 at 01:40
  • Philnash, I totally agree with what you said, but is it possible that Twilio sends the status of who created the room i.e: room.creathor, or somewhere Twilio records this information? On my site, I intend to query all the attributes of the list of participants and consider that whoever has the oldest start_time is the creator of the room – Lemayzeur Mar 29 '18 at 02:14
  • Twilio doesn’t record who started the room, rooms can be started either in the client or on the server. If you need someone to specifically start a room, you can do so with the REST API and then only generate tokens for that room after it’s created. If you don’t mind who created it, then your technique will likely work fine. – philnash Mar 29 '18 at 02:36
0

You just need to detach the tracks of active room.

room.on('disconnected', function () {
    log('Left');
    if (previewTracks) {
        previewTracks.forEach(function (track) {
            track.stop();
        });
    }
    detachParticipantTracks(room.localParticipant);
    room.participants.forEach(detachParticipantTracks);
    activeRoom = null;
    document.getElementById('button-join').style.display = 'inline';
    document.getElementById('button-leave').style.display = 'none';
});

function detachParticipantTracks(participant) {
var tracks = Array.from(participant.tracks.values());
detachTracks(tracks);

}

0

You can do it using DataTrack API provided by the Twilio. This allows you to send messages between Participants connected to a Room.

Create the instance for the LocalDataTrack

private var mLocalDataTrack = LocalDataTrack.create(mActivity)

Create the room and set mLocalDataTrack

val connectOptionsBuilder = Builder(accessToken)
        .dataTracks(Collections.singletonList(mLocalDataTrack))
        .roomName(roomId.toString())

Implement the RemoteParticipant.Listener in your view. Listener contains onDataTrackSubscribed method which you need to override and set listener

override fun onDataTrackSubscribed(
        remoteParticipant: RemoteParticipant,
        remoteDataTrackPublication: RemoteDataTrackPublication,
        remoteDataTrack: RemoteDataTrack
    ) {
        Timber.e("onDataTrackSubscribed")

        remoteDataTrack.setListener(this)
    }

then implement RemoteDataTrack.Listener interface in your activity.

override fun onMessage(remoteDataTrack: RemoteDataTrack, messageBuffer: ByteBuffer) {

        Timber.e("Message is %s", messageBuffer)

    }

    override fun onMessage(remoteDataTrack: RemoteDataTrack, message: String) {

        if (message == "disconnect") {
            mRoom?.disconnect()
        }

    }

And send a message when the host disconnect from the room.

mLocalDataTrack?.send("disconnect")

When the host leaves from the room by pressing button the message will send to the rest of the participants of the room and disconnected.

Jaymin
  • 2,879
  • 3
  • 19
  • 35