Skip to content

Instantly share code, notes, and snippets.

@EkaanshArora
Last active March 21, 2024 13:58
Show Gist options
  • Save EkaanshArora/5f4774f3b508150d93aae1701f52adcc to your computer and use it in GitHub Desktop.
Save EkaanshArora/5f4774f3b508150d93aae1701f52adcc to your computer and use it in GitHub Desktop.
await client.join(topic, token, username);
const mediaStream = client.getMediaStream();
await mediaStream.startVideo();
// render remote videos
const usersWithVideo = client.getAllUser().filter(e => e.bVideoOn);
const numberOfUser = usersWithVideo.length;
for await (const [index, user] of usersWithVideo.entries()) {
const { x, y } = getVideoXandY(index, numberOfUser);
// I'm using client.on("peer-video-state-change") event for to call this function, for example
if (event.userId === user.userId && user.bVideoOn) {
// if it's a new user, render the video
await mediaStream.renderVideo(videoCanvas, user.userId, vidWidth, vidHeight, x, y, 2);
} else if (user.bVideoOn) {
// if it's an existing user, adjust the position of the video
await mediaStream.adjustRenderedVideoPosition(videoCanvas, user.userId, vidWidth, vidHeight, x, y).catch(e => console.log(e));
}
}
// render self video at x:0, y:0
await mediaStream.renderVideo(videoCanvas, client.getCurrentUserInfo().userId, vidWidth, vidHeight, 0, 0, 2);
// or await mediaStream.adjustRenderedVideoPosition(videoCanvas, client.getCurrentUserInfo().userId, vidWidth, vidHeight, 0, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment