muaz-khan / RTCMultiConnection

RTCMultiConnection is a WebRTC JavaScript library for peer-to-peer applications (screen sharing, audio/video conferencing, file sharing, media streaming etc.)
https://muazkhan.com:9001/
MIT License
2.56k stars 1.37k forks source link

Disable join button if there is no initiator #216

Open nasr18 opened 8 years ago

nasr18 commented 8 years ago

I am developing a video class app. Once the staff started the class means, i will send mail to all students who are all subscribed to that class. How do i disable the Join button in Student side if the Staff is not available, i mean if video class is not started. I'm using RTCMultiConnection V2.2.2

muaz-khan commented 8 years ago

v3 users can use checkPresence method:

<button id="btn-join-room" disabled></button>
<script>
connection.checkPresence('room-id', function(isRoomExists, roomid) {
    if (isRoomExists === false) {
        document.querySelector('#btn-join-room').disabled = true;
    } else {
        document.querySelector('#btn-join-room').disabled = false;
    }
});
</script>

And v2 users can use sendCustomMessage:

<button id="btn-join-room" disabled></button>
<script>
var isRoomOpened = false;
connection.onCustomMessage = function(message) {
    if (message.isRoomExists === false) {
        document.querySelector('#btn-join-room').disabled = true;
        isRoomOpened = true;
    } else if (message.isRoomExists === true) {
        document.querySelector('#btn-join-room').disabled = false;
        isRoomOpened = true;
    }

    if (connection.isInitiator && message.checkIfRoomExists === true && message.roomid === connection.sessionid) {
        connection.sendCustomMessage({
            isRoomExists: true,
            roomid: 'room-id'
        });
    }
};

connection.connect();

(function looper() {
    if(connection.isInitiator) return;

    connection.sendCustomMessage({
        checkIfRoomExists: true,
        roomid: 'room-id'
    });

    if (isRoomOpened === true) return;

    setTimeout(looper, 3000); // check after every 3-seconds
})();
</script>
nasr18 commented 8 years ago

One more question. How do i rejoin the student if he come back again???