SDK Usage
Leave Room

Leaving the Room

Once the call is finished or when a user decides to exit the room, it is essential to provide a mechanism for them to leave the room gracefully. This ensures that resources are released, and the user is properly disconnected from the session.

Closing the Room

A moderator(room admin) can decide to close a room at any point in time. In case of room close, all users are forced to leave the room, all server side resources are released, and the room is brought back to the original state. As we now support multiple user roles(Moderator/Participant/Attendee), this can be useful feature for the moderator to close the room when a meeting is over. When all users leave room, we implicitely trigger a room closure even if this functionality is not explicitely used.

Sample Code for Leaving / Closing a Room

Here’s a simple asynchronous function that allows a user to leave the room:

async function leaveRoom(samvyoInstance) {
  await samvyoInstance.leaveRoom(); // Leave the room
  console.log("Left the room");
}
 
async function closeRoom(samvyoInstance) {
  await samvyoInstance.closeRoom(); // Leave the room
  console.log("Left the room");
}

Usage Example

You can call this function in response to a user action, such as clicking a "Leave Room" button:

// Example usage
const samvyoInstance = /* initialized samvyo instance */;
 
// Leave room on button click
document.getElementById("leaveButton").addEventListener("click", async () => {
    await leaveRoom(samvyoInstance);
});
 
// close room on button click
document.getElementById("closeButton").addEventListener("click", async () => {
    await closeRoom(samvyoInstance);
});

Summary

By implementing the leaveRoom/closeRoom function, you complete the lifecycle of a room in your application. This allows users to exit the room gracefully, ensuring that all necessary cleanup is performed. This concludes the basic functionality for managing a video call using the samvyo SDK. With the ability to join a room, manage media streams, and leave/close the room, you have the essential building blocks for a robust video conferencing application.