使用RTCMultiConnection-v3发送和接收私人聊天请求

时间:2017-10-10 10:19:24

标签: node.js webrtc rtcmulticonnection

我正在使用RTCMultiConnection-v3。我需要你的帮助来为私人聊天应用程序开发一个功能。 我想要做的是我的应用程序中有很多用户。单个用户可以一次与多个用户聊天。 但我想在下面的方案中做。

  

用户1:向用户2发送私人聊天请求用户2:将   获取Popup通知以接受/拒绝用户1的请求   用户2:如果接受私人聊天请求,则会开始一个会话   私人聊天,以后可以邀请新用户。

在单个页面中,单个用户可以启动与多个用户的私密聊天 我不明白如何从其他用户发送聊天请求和接收请求,然后接受另一个用户请求,然后开始聊天会话。

我尝试过使用RTCMultiConnection的Custom + Socket + Event,但它适用于一个用户而不是其他用户

public HttpResponseMessage GetByMsn(string msn, DateTime dt)
    {
        try
        {
            return Request.CreateResponse(HttpStatusCode.Found, medEntitites.tj_xhqd.Where(m=>(m.zdjh == msn)).Where(m=> (m.sjsj >= dt)).Select(m=> new { m.zdjh , m.sjsj, m.xhqd }).Distinct());
        }
        catch (Exception ex)
        {
            return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
        }
    }

1 个答案:

答案 0 :(得分:0)

以下是live demoits source code

这是一个片段。您需要修改它以适合您自己的应用程序:

connection.socketCustomEvent = 'unique-private-group-or-romm-id'; // don't change this line
connection.connectSocket(function(socket) {
    // listen for custom messaging event
    socket.on(connection.socketCustomEvent, function(event) {
        // check if someone sent you a custom message
        if (event.messageFor === connection.userid) {
            // this custom message is for me

            // check if someone requested for video chat
            if (event.message === 'join-for-video') {
                if (window.confirm(event.fullName + ' want to start video chat with you. Do you accept?') === true) {
                    connection.join(event.userid);
                }
            }

            // check if someone requested for text chat
            if (event.message === 'join-for-textchat') {
                if (window.confirm(event.fullName + ' want to start text chat with you. Do you accept?') === true) {
                    connection.session = {
                        data: true
                    };
                    connection.join(event.userid);
                }
            }
        }
    });
});

// below button click handler makes video call request
// remote user will receive this request
// remote user need to confirm/accept this request
btnMakeVideoChatRequest.onclick = function() {
    var socket = connection.socket;
    var userid = prompt('Enter userid. You will start video chat with this userid.');
    socket.emit(connection.socketCustomEvent, {
        messageFor: userid,
        message: 'join-for-video',
        fullName: 'Hey, My Full Name is XYZ',
        userid: connection.userid
    });
};

// below button click handler makes text chat request
// remote user will receive this request
// remote user need to confirm/accept this request
btnMakeVideoChatRequest.onclick = function() {
    var socket = connection.socket;
    var userid = prompt('Enter userid. You will start text chat with this userid.');
    socket.emit(connection.socketCustomEvent, {
        messageFor: userid,
        message: 'join-for-textchat',
        fullName: 'Hey, My Full Name is XYZ',
        userid: connection.userid
    });
};

// below two lines are important
// for each and every user
connection.session.broadcast = true;
connection.open(connection.userid);