'Join to the room without enabling mic/camera in twilio

How to join to the room to share the screen without enabling mic/camera.I'm working on the below code https://github.com/twilio/video-quickstart-js

Thanks



Solution 1:[1]

When you connect to the room, use an empty tracks option:

Twilio.Video.connect(token, { tracks: [] });

Specifically in the application you are referring to, you need to do a few things to remove local video and audio tracks.

First thing, you don't want to start the camera and microphone requests when the page loads. So at the bottom of index.js change the window load listener to:

window.addEventListener(
  "load",
  isSupported
    ? () => selectAndJoinRoom()
    : () => {
        showError($showErrorModal, new Error("This browser is not supported."));
      }
);

Still in index.js, in the connectOptions constant you can remove all of the properties and replace it with the empty tracks array:

const connectOptions = {
  tracks: [];
}

Finally, we need to remove mention of cameras and microphones from the selectAndJoinRoom function. After removing all that, the function should look like this:

async function selectAndJoinRoom(error = null) {
  const formData = await selectRoom($joinRoomModal, error);
  const { identity, roomName } = formData;

  try {
    // Fetch an AccessToken to join the Room.
    const response = await fetch(`/token?identity=${identity}`);

    // Extract the AccessToken from the Response.
    const token = await response.text();
    connectOptions.name = roomName;

    // Join the Room.
    await joinRoom(token, connectOptions);

    // After the video session, display the room selection modal.
    return selectAndJoinRoom();
  } catch (error) {
    return selectAndJoinRoom(error);
  }
}

Then in joinroom.js remove anything to do with localVideoTrack.

Now when you rebuild the project, and reload the page you should not be asked for camera or microphone at all, and when you join the call you will not send any camera or audio feed.

There will be a bunch of code left lying around that was used to request camera and microphone, starting with the selectCamera and selectMicrophone functions in index.js, but I leave clearing that up as an exercise for you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1