Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
});
}