Skip to main content

shareCustomVideoTrack(videoTrack)

Share a custom video track in the meeting​

caution

join() must be called before calling this method

Call this method to share a custom video track instead of using the default camera. This is useful when you want to share video from a canvas element, a processed video stream, or any other custom video source.

JavaScript
await meeting.shareCustomVideoTrack(videoTrack)

Parameters​

ParameterDescriptionTypeRequired
videoTrackA MediaStreamTrack containing video dataMediaStreamTrackYes

Return Value​

Returns the provided MediaStreamTrack after it has been shared.

Events Emitted​

  • localTrackStarted - Emitted when sharing video for the first time
  • localTrackUpdated - Emitted when replacing an existing video track
  • localTrackStopped - Emitted when the video track ends

Example​

Sharing a Canvas Stream​

JavaScript
// Get a canvas element
const canvas = document.getElementById('myCanvas');

// Get the video track from canvas
const canvasStream = canvas.captureStream(30); // 30 FPS
const videoTrack = canvasStream.getVideoTracks()[0];

// Share the custom video track
await meeting.shareCustomVideoTrack(videoTrack);
info

If you are already sharing video, calling this method will replace the current video track with the new one without stopping and restarting the video producer.