AngularJS XMPP获取名册

时间:2015-03-20 22:23:27

标签: angularjs xmpp jsjac

我使用的是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);
        }
    }
});

如果该服务除了名单列表之外的其他功能。

1 个答案:

答案 0 :(得分: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);

问题解决了