How to use the twilio-video.LocalVideoTrack function in twilio-video

To help you get started, we’ve selected a few twilio-video examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ksocha / twilio-screensharing / client / src / components / App / AppContainer.js View on Github external
shareScreen = async () => {
    try {
      const { videoRoom, localVideoTrack, screenTrack } = this.state;

      if (!screenTrack) {
        const stream = await navigator.mediaDevices.getDisplayMedia({
          video: true
        });
        const newScreenTrack = first(stream.getVideoTracks());

        this.setState({
          screenTrack: new TwilioVideo.LocalVideoTrack(newScreenTrack)
        });

        videoRoom.localParticipant.publishTrack(newScreenTrack);
        videoRoom.localParticipant.unpublishTrack(localVideoTrack);
      } else {
        videoRoom.localParticipant.unpublishTrack(screenTrack);
        videoRoom.localParticipant.publishTrack(localVideoTrack);
        this.stopScreenTrack();
      }
    } catch (error) {
      this.stopScreenTrack();

      this.setState({
        errorMessage: error.message
      });
    }