0

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

应用程序.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);
        }
    }
});

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

4

1 回答 1

0

在 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);

问题解决了

于 2015-04-03T07:49:24.893 回答