Notes
![]() ![]() Notes - notes.io |
let waitingRoomId;
let mainSessionId = "main-session"; // Main session ID
let participants = new Map(); // Map to track participants
// Initialize the SDK
client.init("en-US", "CDN");
// Join a session
async function joinSession(sessionName, userName, token) {
try {
await client.join(sessionName, token, userName);
document.getElementById("status").innerText = "Joined session as " + userName;
// Listen for participants joining
client.on("participant-joined", (participant) => {
if (participant.userId !== client.getCurrentUser().userId) {
participants.set(participant.userId, participant);
addToWaitingRoom(participant.userId);
}
});
// Listen for participants leaving
client.on("participant-left", (participant) => {
participants.delete(participant.userId);
});
} catch (error) {
console.error("Failed to join session:", error);
}
}
// Create a waiting room (subsession)
async function createWaitingRoom() {
try {
const subsessions = await client.createSubSessions([
{ sessionId: "waiting-room", name: "Waiting Room" },
{ sessionId: mainSessionId, name: "Main Session" },
]);
waitingRoomId = subsessions[0].sessionId;
console.log("Waiting room created with ID:", waitingRoomId);
document.getElementById("status").innerText = "Waiting room created.";
} catch (error) {
console.error("Failed to create waiting room:", error);
}
}
// Add participant to waiting room
async function addToWaitingRoom(userId) {
try {
if (waitingRoomId) {
await client.moveUserToSubSession(waitingRoomId, userId);
console.log(`Moved participant ${userId} to waiting room.`);
} else {
console.error("Waiting room not created yet.");
}
} catch (error) {
console.error("Failed to move participant to waiting room:", error);
}
}
// Admit participant to the main session
async function admitParticipant(userId) {
try {
if (mainSessionId) {
await client.moveUserToSubSession(mainSessionId, userId);
console.log(`Moved participant ${userId} to main session.`);
} else {
console.error("Main session not created yet.");
}
} catch (error) {
console.error("Failed to admit participant:", error);
}
}
// Example usage
document.getElementById("join-session").addEventListener("click", () => {
const sessionName = "your-session-id"; // Replace with your session ID
const userName = "Participant"; // Replace with dynamic user name
const token = "your-session-token"; // Replace with a valid JWT token
joinSession(sessionName, userName, token);
});
document.getElementById("create-waiting-room").addEventListener("click", createWaitingRoom);
document.getElementById("admit-participant").addEventListener("click", () => {
const participantId = prompt("Enter the participant ID to admit:");
admitParticipant(participantId);
});
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team