开发者

XMPP strophe Connection attach process failed

开发者 https://www.devze.com 2023-04-04 06:48 出处:网络
I\'m able to create a XMPP connection on page load. However whenever I move to another pages, I want to use the same connection to remove recurring notifications in client. I\'ve used following code.

I'm able to create a XMPP connection on page load. However whenever I move to another pages, I want to use the same connection to remove recurring notifications in client. I've used following code.

$(document).bind('connect', function (ev, data) {
    var jid = $.jStorage.get('JID', null);
    var sid = $.jStorage.get('SID', null);
    var rid = $.jStorage.get('RID', null);
    if ((jid != null) && (sid != null) && (rid != null)) {
        var conn = new Strophe.Connection("http://localhost:5280/xmpp-httpbind");
        conn.attach(jid, sid, rid, function () {
            alert('Connection attach success.');
            Gab.connection = conn;
        });
    }
    else {
        var conn = new Strophe.Connection("http://localhost:5280/xmpp-httpbind");
        conn.connect(data.jid, data.password, function (status) {
            if (status === Strophe.Status.CONNECTED) {
                $(document).trigger('connected');
            } else if (status === Strophe.Status.DISCONNECTED) {
                $(document).trigger('disconnected');
            }
        });
        Gab.connection = conn;
    }
});

And in u开发者_如何学Gonload:

$(window).unload(function () {
    if (Gab.connection != null) {
        Gab.connection.pause();
        $.jStorage.set('JID', Gab.connection.jid);
        $.jStorage.set('SID', Gab.connection.sid);
        $.jStorage.set('RID', Gab.connection.rid);
    } else {
        $.jStorage.flush();
    }
//    Gab.connection = null;
    alert('paused/disconnected');
})

It attaches to connection, however as soon as it attaches, it says (POST http://localhost:5280/xmpp-httpbind 404 Not Found 36ms) in Firebug console. Any ideas?

Thanks in advance.


You should not trust unload. Instead store/update your RID on every cb from the xmpp server. Make sure your RID is getting incremented on each call as well.


Make sure to inspect the body of the message. Some XMPP servers return HTTP 404 on terminate.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号