XMPP:AngularJS +的strophe [英] XMPP: AngularJS + Strophe

查看:336
本文介绍了XMPP:AngularJS +的strophe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用的strophe和JavaScript的基本XMPP要转换为AngularJS。

The basic XMPP with strophe and javascript wants to convert to 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对象的处理事件。是否有任何留在这个code或我应该办理strophes事件与angularJS办?

when i run this there is no error. But all handling events like on_presence() method called only once. this is handler event of Strophe Connection object. Is there is any remain in this code or what should i do for handling strophes event with angularJS?

我所指向此链接,但它不工作。

I refered This Link but it not works.

推荐答案

请参阅的的Strophe.js文档的addHandler操作

如果它要被再次调用的处理程序应当返回true;返回后,返回false将删除处理。

The handler should return true if it is to be invoked again; returning false will remove the handler after it returns.

因此​​,如果你希望它被再次调用您的ON_ presence code应该返回true:

Therefore, your on_presence code should return true if you want it to be invoked again:

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

这篇关于XMPP:AngularJS +的strophe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆