【问题标题】:XMPP: AngularJS + StropheXMPP:AngularJS + Strophe
【发布时间】:2014-08-06 13:40:59
【问题描述】:

带有 strophe 和 javascript 的基本 XMPP 想要转换为 AngularJS。

.controller('loginCtrl', function(xmppAuth) {

    xmppAuth.auth(login, password);

})

并在服务中:

    .service('xmppAuth', function() {

.return {

    auth: function(login, password) {
       connect = new Strophe.Connection(domain);
       connect.connect(login, password, function (status) {
           if (status === Strophe.Status.CONNECTED) {
               connect.addHandler(on_roster_changed,"jabber:iq:roster", "iq", "set");
               connect.addHandler(on_iq, null, "iq","");
               connect.addHandler(on_presence, null, "presence");
               connect.addHandler(on_message, null, 'message', '');
           }
       }
    }

    }

})

在js文件中

var on_presence = function(presence){
    code
}

当我运行它时没有错误。但是所有处理事件,如 on_presence() 方法只调用一次。这是 Strophe Connection 对象的处理程序事件。这段代码中是否有任何剩余,或者我应该如何使用 angularJS 处理 strophes 事件?

我推荐了This Link,但它不起作用。

【问题讨论】:

    标签: javascript angularjs xmpp strophe


    【解决方案1】:

    the Strophe.js docs for addHandler:

    如果要再次调用,处理程序应该返回true;返回 false 将在它返回后移除处理程序。

    因此,如果您希望再次调用 on_presence 代码,则应该返回 true:

    var on_presence = function(presence) {
        // do some stuff
        return true;
    };
    

    【讨论】:

    • 是的,正如邮件列表中所说:文档没有充分强调这一事实。许多 Strophe.js 用户最初也犯了这个错误,包括我。我现在添加了一个 PR 来改进文档:github.com/strophe/strophejs/pull/86
    猜你喜欢
    • 2014-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-16
    • 2018-04-11
    • 2020-07-04
    相关资源
    最近更新 更多