Skip to main content
Version: 0.0.x

Invite Guest on Stage - Javascript

This guide explains the process of inviting a viewer to join a livestream using the changeMode() method.

note

Before proceeding with this guide, ensure that all attendees join the meeting with the mode set to VIEWER, while the host joins with the mode set to CONFERENCE.

The diagram below illustrates the utilization of the PubSub mechanism to facilitate the requesting and switching of the participant's mode.

invite-guest-pubsub

Step 1: Loading Viewer List

First, the host will be presented with a list of participants who have joined as VIEWER, accompanied by a button that, when selected, will invite that user to join the livestream.

const participants = meeting.participants;

// Filtering only viewer participant
const viewers = [...participants.values()].filter((participant) => {
return participant.mode == VideoSDK.Constants.modes.VIEWER;
});

viewers.map((participant) => {
const name = participant.displayName;
const participantId = participant.id;

const textEle = document.createElement("p");
textEle.textContent = name;

// Create the button
var button = document.createElement("button");
button.innerHTML = "Request to join Livestream";

// Append elements to your viewers list
});

invite-guest-pubsub

Step 2: Requesting a Viewer to Join Livestream

Now, with the Viewer list in place, handle the click event for the "Join Livestream" button by utilizing CHANGE_MODE_$participantId as the topic for PubSub.

const participants = meeting.participants;

// Filtering only viewer participant
const viewers = [...participants.values()].filter((participant) => {
return participant.mode == VideoSDK.Constants.modes.VIEWER;
});

viewers.map((participant) => {
const name = participant.displayName;
const participantId = participant.id;

const textEle = document.createElement("p");
textEle.textContent = name;

// Create the button
var button = document.createElement("button");
button.innerHTML = "Request to join Livestream";

// Append elements to your viewers list

const topic = `CHANGE_MODE_${participantId}`;

// Publishing the pubsub message with new mode
button.addEventListener("click", function () {
meeting?.pubSub.publish(topic, VideoSDK.Constants.modes.CONFERENCE);
});
});

Step 3: Showing Viewer Request Dialog

After implementing the host's request for a viewer to join the livestream, display the viewer's request dialogue and switch the mode from VIEWER to CONFERENCE.

function onMessageReceived(data) {
let { message, senderId, senderName } = data;
const textEle = document.createElement("p");
textEle.textContent = `${senderName} requested you to join Livestream`;

// Create the button
var acceptButton = document.createElement("button");
acceptButton.innerHTML = "Accept";

acceptButton.addEventListener("click", function () {
meeting?.changeMode(message);
});

var rejectButton = document.createElement("button");
rejectButton.innerHTML = "Reject";
rejectButton.addEventListener("click", function () {
//
});
}

meeting?.pubSub?.subscribe("CHAT", onMessageReceived);

react_ils_cohost_join_request

API Reference

The API references for all the methods utilized in this guide are provided below.

Got a Question? Ask us on discord