checkPresence and automatically join rejoin rooms

Muaz Khan edited this page Aug 23, 2018 · 2 revisions

Join a room only if moderator is online or room is active.

Automatically rejoin same room if moderator comes back.

Here is complete example explaining how to check if owner (room moderator) leaves / left:

connection.sessionid = 'room-id';

connection.onleave = function(event) {
    if (event.userid === connection.sessionid && !isOwnerPesenceCheckingOn) {
        isOwnerPesenceCheckingOn = true;

var isOwnerPesenceCheckingOn = false;

function startCheckingForOwnerPresence() {
    connection.checkPresence(connection.sessionid, function(isOwnerOnline) {
        if (isOwnerOnline === true) {
            isOwnerPesenceCheckingOn = false;

        setTimeout(startCheckingForOwnerPresence, 2000); // recheck after 2 seconds

btnOpenRoon.onclick = function() {;

btnJoinRoon.onclick = function() {
    startCheckingForOwnerPresence(); // join moderator only if he is online

How this works?

  1. If someone joins a room, he keeps checking for room-moderator's presence until moderator comes online
  2. If room-moderator leaves, then participants starts rechecking for room-moderator's presence until room-moderator comes back

startCheckingForOwnerPresence runs top over checkPresence method to make sure that we join room-moderator only if he is online. If moderator leaves then we keep waiting for him until he comes back. So if owner comes back, we will automatically rejoin him again.

onleave event is used to detect if/when owner left the room. So that we can restart checking for his presence in a looping-method.

checkPresence | RTCMultiConnection

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.