Koder
Koder

Reputation: 1914

How can a user join a room as a spectator in Twilio Video?

I am using Twilio Programmable Video to build a prototype chat room.

I was able to connect users into a room as participant and video and audio are attached successfully. However when a user wants to join the room as spectator, That spectator is also joined as a video participant.

How can a user connect to a room as a spectator only ?

Here is my grant code:

var accessToken = new AccessToken(
            Settings.TwilioAccountSid,
            Settings.TwilioVideoSid,
            Settings.TwilioVideoSecret
        );

        // Set the Identity of this token
        accessToken.identity = "spectator";

        // Grant access to Video
        var grant = new VideoGrant();
        grant.room = roomId;

        accessToken.addGrant(grant);

        res.send({token: accessToken.toJwt()});

Here is my connect code with the token i am returning to client:

Twilio.Video.connect(result.token, {name: roomId}).then(function (room) {...

What can i do to make a user join a room as a spectator and not as a Video Participant ?

Upvotes: 1

Views: 1163

Answers (1)

philnash
philnash

Reputation: 73075

Twilio developer evangelist here.

To join a room as a spectator would mean that the user should not send audio or video. To do this, you pass the options to Video.connect to say not to get audio or video streams.

Twilio.Video.connect(result.token, {
  name: roomId,
  video: false,
  audio: false
}).then(function(room) { ... });

Let me know if that helps at all.

Upvotes: 3

Related Questions