user3245587
user3245587

Reputation: 11

How to camera off in twilio javascript

I am using this code participant side video is off but the local side camera is not off

currentUser.localParticipant.videoTracks.forEach(publication => {
  publication.track.disable();
});

Upvotes: 0

Views: 2227

Answers (1)

philnash
philnash

Reputation: 73027

Twilio developer evangelist here.

When you disable a track in a Twilio Video room it stops broadcasting the media stream but it does not stop the camera being used. "disable" in this case behaves the same as "mute", it's a temporary stop and you may enable the track again in the future. For this reason, it keeps hold of the camera resource ready to be turned back on again.

If you want to completely stop a track and release the camera then you should first unpublish the TrackPublication object and then stop the track. Like this:

currentUser.localParticipant.videoTracks.forEach(publication => {
  publication.unpublish();
  publication.track.stop();
});

Note that if you completely stop a track you will have to request access to it again through navigator.mediaDevices.getUserMedia or createLocalVideoTrack.

Upvotes: 2

Related Questions