XMPP多用户聊天室断开连接错误

时间:2013-11-17 15:46:51

标签: javascript xmpp openfire strophe

我能够使用javascript,XMPP,Strophe和openFire创建一个MUC聊天室。房间已创建,不同的用户可以加入。以下是用于创建房间的代码:

function onConnected(status)
{
    if (status === Strophe.Status.CONNECTED) 
    {
        con.addHandler(on_presence, null, "presence");
        con.addHandler(on_public_message, null, "message", "groupchat");
        con.addHandler(on_private_message, null, "message", "chat");

        con.muc.init(con);
        var d = $pres({"from":"louis@louis-tosh","to":"myroom@conference.louis-tosh/Louis"})
        .c("x",{"xmlns":"http://jabber.org/protocol/muc"});

        con.send(d.tree());
        con.muc.createInstantRoom("myroom@conference.louis-tosh");
    }
}

" myroom"现在已经创建并自动生成" louis @ louis-tosh"加入了房间。 等了几秒钟,louis @ louis-tosh的用户突然断开了(离开了房间)。当此用户断开连接时,会提示on presence节。在线状态代码如下:

function on_presence (presence)
{
    var from = $(presence).attr('from');
    var room = Strophe.getBareJidFromJid(from);
    var nick = Strophe.getResourceFromJid(from);

    var show = $(presence).find("show").text();
    if (show === "" || show === "chat") 
    {
        alert('Presence From: ' + from + "(Online)");
    } 
    else if(show === "dnd")
    {
        alert('Presence From: ' + from + "(Busy)");
    }
    else
    {
        alert('Presence From: ' + from + "(Away)");
    }

    return true;
}

我需要知道为什么会发生这种断开连接的问题,以及它们是否对上述代码有任何建议。任何帮助或建议都非常有用。

0 个答案:

没有答案