XMPP strope 连接附加过程失败

发布于 2024-12-04 05:20:04 字数 1629 浏览 0 评论 0原文

我能够在页面加载时创建 XMPP 连接。但是,每当我移动到其他页面时,我想使用相同的连接来删除客户端中的重复通知。我使用了以下代码。

$(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;
    }
});

在卸载中:

$(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');
})

它附加到连接,但是一旦附加,它就会说 (POST http://localhost:5280 Firebug 控制台中的 /xmpp-httpbind 404 Not Found 36ms)。有什么想法吗?

提前致谢。

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 unload:

$(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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

递刀给你 2024-12-11 05:20:04

您不应该信任卸载。而是从 xmpp 服务器在每个 cb 上存储/更新您的 RID。确保您的 RID 在每次调用时也会增加。

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.

沫尐诺 2024-12-11 05:20:04

请务必检查邮件正文。某些 XMPP 服务器在终止时返回 HTTP 404。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文