Initialise Meeting
To configure a VideoSDK meeting you require two things, first the token
which will be used for Authentication purpose and a meetingId
which will be used to specify where a participant will join. Let's see each of the steps closely.
Generating Token
You can generate a token
in two ways:
Temporary Token
: You can visit Dashboard's API Key section and generate the temporary token from there.Server
: You can setup JWT in backend and make an API call to get the token from your server.
To learn more about Authentication and token in detail you can follow this guide.
// With Temporary Token
const getToken = async () => {
// Update the token here from the VideoSDK dashboard
let token = "YOUR_TOKEN";
};
// Server
const getToken = async () => {
const response = await fetch(`http://localhost:3000/get-token`, {
method: "GET",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
});
const { token } = await response.json();
return token;
};
Generating Meeting Id
With the token ready, we can get the meetingId
from the VideoSDK's rooms API.
const getMeetingId = async (token) => {
try {
//We will use VideoSDK rooms API endpoint to create a meetingId
const VIDEOSDK_API_ENDPOINT = `https://api.videosdk.live/v2/rooms`;
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
// We will pass the token in the headers
Authorization: token,
},
};
const meetingId = await fetch(VIDEOSDK_API_ENDPOINT, options)
.then(async (result) => {
const { roomId } = await result.json();
return roomId;
})
.catch((error) => console.log("error", error));
//we will return the meetingId which we got from the response of the api
return meetingId;
} catch (e) {
console.log(e);
}
};
Initialization of Meeting
We can initialize the meeting using the initMeeting
method of the VideoSDK
class. The initMeeting
is responsible for initializing the meeting with the provided configuration, which includes the meetingId
, participantId
and many more.
Let's take a deeper look at the available configuration options first.
VideoSDK.config(token);
const meeting = VideoSDK.initMeeting({
meetingId: "<Id-of-meeting>",
name: "<Name-of-participant>",
micEnabled: "<Flag-to-enable-mic>",
webcamEnabled: "<Flag-to-enable-webcam>",
participantId: "Id-of-participant", // optional, default: SDK will generate
});
meetingId
:- meetingId is unique identifiers that allow participants to join a specific meeting or room.
- It will be in the format of
xxx-yyy-zzz
and will be generated using the VideoSDK's Room API.
name
:- This will represent the name of the participant in the meeting.
- It will accept
String
type value.
micEnabled
:- This is a
boolean
flag, indicating whether a participant's microphone will be automatically enabled when they join a meeting.
- This is a
webcamEnabled
:- This is a
boolean
flag, indicating whether a participant's webcam will be automatically enabled when they join a meeting.
- This is a
participantId
:This will be the unique identifier for the participant inside the meeting.
- It can be used to specify the unique identifier which can be linked with your own database service.
- It has to be of
String
type. - This is an
OPTIONAL
parameter. By default VideoSDK will generate unique id for each participant.
You must ensure that the participantId
is not repeated in the same meeting or room, It will enable VideoSDK to eliminate any participant respect to that participantId
.
To know more about other properties, you can follow our API Reference.
import { VideoSDK } from "@videosdk.live/js-sdk";
let meeting;
const getToken = async () => {
...
};
const getMeetingId = async (token) => {
...
};
async function startMeeting() {
const token = await getToken();
const meetingId = await getMeetingId(token);
// Configure authentication token
VideoSDK.config(token);
// Initialise meeting
meeting = VideoSDK.initMeeting({
meetingId: meetingId,
name: "YOUR_NAME",
micEnabled: true,
webcamEnabled: true,
});
}
API Reference
The API references for all the methods utilized in this guide are provided below.
Got a Question? Ask us on discord