【问题标题】:AngularJS XMPP Get RosterAngularJS XMPP 获取名册
【发布时间】:2015-05-24 11:07:29
【问题描述】:

我正在使用 XMPP JSJAC 库和 AngularJS 编程聊天应用程序。我可以连接到服务器,但它没有列出名册。

app.js

var app = angular.module("app", ["ngRoute"]).config(["$routeProvider", function($routeProvider) {
    $routeProvider
        .when("/login", {
            templateUrl: "view/login.html",
            controller: "LoginController"
        })
        .when("/main", {
            templateUrl: "view/main.html",
            controller: "MainController"
        })
        .otherwise({
            redirectTo: "/login"
        });
}]);

XMPPService.js

app.service("XMPPService", function() {
    return {
        conParams: null,
        auth: function (userId, password) {
            this.conParams = {
                httpbase: ConnectionConfig.HttpBase,
                timerval: ConnectionConfig.timerval
            };
            con = new JSJaCHttpBindingConnection(this.conParams);
            con.registerHandler('onconnect', this.onConnect);
            con.registerHandler('onerror', this.onConnectFail);
            this.conParams =  {
                username: userId,
                pass: password,
                domain: ConnectionConfig.ServerDomain,
                resource: ConnectionConfig.Resource,
                register: false
            };
            con.connect(this.conParams); // this.onRoster is function
        },
        onConnect: function() {
            alert("connected");
            //window.location = "#/main";
            con.send(getRosterIqPacket(), this.onRoster); // onRoster undefined after connected
        },
        onConnectFail: function(error) {
            alert("error");
            console.log(error);
        },
        onRoster: function(iq) {
            alert("roster");
            console.log(iq);
        }
    }
});

如果该功能除了如果服务来自名册列表。

【问题讨论】:

  • 请向我们提供有关正在发生的事情的更多信息。是没有返回数据还是出现某种错误?
  • 角度服务中的功能然后不起作用

标签: angularjs xmpp jsjac


【解决方案1】:

在 XMPPService 中添加代码

con.registerHandler('presence',     this.onPresence);
con.registerHandler('iq',           this.handleIQSet);
con.registerHandler('message',      this.handleMessage);
con.registerHandler('message',      this.handleMessageError);
con.registerHandler('ondisconnect', this.handleDisconnect);
con.registerHandler('onerror',      this.handleConError);

问题解决了

【讨论】:

    猜你喜欢
    • 2014-04-12
    • 2014-07-27
    • 2015-09-19
    • 2013-10-21
    • 2016-01-30
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多