如何让用户等待加入,直到会议组织者首先加入

How would I make user wait to join until meeting organizer joins first

本文关键字:会议 会议组织 组织者 用户 等待      更新时间:2023-09-26

我正在实现一个视频会议室,用户可以在其中创建视频会议并邀请其他用户。

现在我想确保用户不能加入会议,直到会议组织者打开房间。

我有以下代码,但它不工作。会议组织者可以打开会议室,但当用户点击"加入会议"时,它不会加入。

// https://github.com/muaz-khan/RTCMultiConnection
var rmc = new RTCMultiConnection();
rmc.userid = "<?php echo $user->fname . ' ' . $user->lname . ' (' . $user->username . ')' ; ?>";
rmc.session = {
    video: true,
    audio: true,
    data: true
};
var room_status = 0; //room closed
$('#open-room').click(function () {
    // http://www.rtcmulticonnection.org/docs/open/
    room_status = 1; //room opened
    rmc.open();
    rmc.streams.mute({video : true});
    document.getElementById("on-off-video").style.color= 'red';
});
$('#join-room').click(function () {
    if(room_status == 1) {
        // http://www.rtcmulticonnection.org/docs/connect/
        rmc.connect();
        rmc.streams.mute({video: true});
        document.getElementById("on-off-video").style.color= 'red';
    }
    console.log("Waiting for meeting organizer");
});
// display a notification box
window.addEventListener('beforeunload', function () {
    return 'Do you want to leave?';
}, false);
// leave here
window.addEventListener('unload', function () {
    rmc.leave();
}, false);
rmc.onMediaCaptured = function () {
    $('#share-screen').removeAttr('disabled');
    $('#open-room').attr('disabled', 'disabled');
    $('#join-room').attr('disabled', 'disabled');
};
//chat
rmc.onopen = function (event) {
    //alert('Text chat has been opened between you and ' + event.userid);
    document.getElementById('input-text-chat').disabled = false;
    room_status = 1;
};
//end of chat
$('#disconnect').click(function () {
    room_status = 0; //room closed
    rmc.leave();
    setTimeout("location.href = '../';",2000);
});
//to know the stream type
rmc.onstream = function (e) {
    if (e.type == 'local') {
        // alert("the stream is local");
    }
    if (e.type == 'remote') {
        // alert("the stream is remote");
    }
    if (e.isVideo) {
        var uibox = document.createElement("div");
        uibox.appendChild(document.createTextNode(e.userid));
        uibox.className = "userid";
        uibox.id = "uibox-" + e.userid.replace(/ |'(|')/g, '');
        document.getElementById('video-container').appendChild(e.mediaElement);
        document.getElementById('video-container').appendChild(uibox);
    }
    else if (e.isAudio) {
        document.getElementById('video-container').appendChild(e.mediaElement);
    }
    else if (e.isScreen) {
        $('#cotools-panel iframe').hide();
        $('#cotools-panel video').remove();
        document.getElementById('cotools-panel').appendChild(e.mediaElement);
    }
};
//removes the div containing the userid of the user who is leaving
rmc.onleave = function (e) {
    $('#' + "uibox-" + e.userid.replace(/ |'(|')/g, '')).remove();
};

看来你有三个问题。

1)首先,我认为你不能只使用一个RTCMultiConnection对象来打开和加入一个房间。你必须创建2个独立的对象。但是,您的代码不应该在打开和加入房间的同一窗口中运行。因此,如果您在一个窗口中运行一次以打开房间,在另一个窗口中运行一次以连接房间,则没有问题。

在这种情况下,你有一个更重要的问题。当您在一个窗口打开房间时,变量room_status被设置为1。但是在另一个窗口中,room_status仍然等于0,因此您不会调用$('#join-room')中的if()中的代码。点击函数。

这不是什么大问题,现在,让我们删除if语句以确保您的代码被执行(请阅读我的第3点以了解您的原始目标)。

2)我看看https://github.com/muaz-khan/RTCMultiConnection: https://jsfiddle.net/c46de0L8/上给出的简单例子,似乎你应该使用连接而不是连接。最重要的是,您应该使用通道ID和房间ID来连接2个用户。

所以我改变你的代码一点,它似乎工作得很好:

var CHANNEL_ID = "MYCHANNEL-" + window.RMCDefaultChannel;
var ROOM_ID = "MYROOM";
var SESSION = {
    video: true,
    audio: true,
    data: true
};
var USERID = "<?php echo $user->fname . ' ' . $user->lname . ' (' . $user->username . ')' ; ?>";
var rmc = undefined;
var room_status = 0; //room closed
$('#open-room').click(function () {
    // http://www.rtcmulticonnection.org/docs/open/
    room_status = 1; //room opened
    rmc = new RTCMultiConnection(CHANNEL_ID);
    rmc.userid = USERID;
    rmc.session = SESSION;
    rmc.open({
        dontTransmit: true,
        sessionid: ROOM_ID
    });
    rmc.streams.mute({video : true});
    document.getElementById("on-off-video").style.color= 'red';
});
$('#join-room').click(function () {
    //if(room_status == 1) {
        // http://www.rtcmulticonnection.org/docs/connect/
        rmc = new RTCMultiConnection(CHANNEL_ID);
        rmc.join({
            sessionid: ROOM_ID,
            userid: USERID,
            session: SESSION
        });
        rmc.streams.mute({video: true});
        document.getElementById("on-off-video").style.color= 'red';
    //}
    console.log("Waiting for meeting organizer");
});

其余代码保持不变。

我在JSFiddle中放置了一个粗略的工作代码:https://jsfiddle.net/sebdoncker/fjtkvnjq/2/

3)现在您仍然有问题:如何确保房间在能够加入它之前是打开的。我想你可以用房间号。当一个用户打开一个新房间时,您应该生成一个房间ID。现在,您必须将此ROOM ID发送给您的joiner用户(通过服务器通信或其他方式,具体取决于您的应用程序体系结构)。由于joiner用户没有房间ID,您可以禁用join按钮。

这只是一个引子,这取决于您的整体应用程序架构