AngularJS XMPP 获取花名册
AngularJS XMPP Get Roster
我正在使用 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);
}
}
});
如果功能除了服务出现在花名册列表中。
在 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);
问题已解决
我正在使用 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);
}
}
});
如果功能除了服务出现在花名册列表中。
在 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);
问题已解决