在同一个浏览器中,聊天时Session id 每次都不一样。怎么会出现多个Session呢??

基本上是引用聊天demo中的代码

网页代码:
function chat() {
var username = "test1";
var target = "*";
var msg = $("#entry").val();
pomelo.init({
host: host,
port: port,
log: true
}, function () {
pomelo.request("gate.gateHandler.queryEntry", {uid: "hello pomelo"}, function (data) {
pomelo.init({
host: data.host,
port: data.port,
log: true
}, function () {
pomelo.request("rooms.roomHandler.send", {
rid: rid,
content: msg,
from: username,
target: target
}, function (data) {
alert(data.route);
});
});
});
});
}

发送消息代码:
handler.send = function(msg, session, next) {
console.log(session);
var rid = msg.rid;
var username = msg.username;
var channelService = this.app.get('channelService');
var param = {
msg: msg.content,
from: username,
target: msg.target
};
channel = channelService.getChannel(rid, false);
//the target is all users
if(msg.target == '') {
channel.pushMessage('onChat', param);
}
//the target is specific user
else {
var tuid = msg.target + '
' + rid;
var tsid = channel.getMember(tuid)['sid'];
channelService.pushMessageByUids('onChat', param, [{
uid: tuid,
sid: tsid
}]);
}
next(null, {
route: msg.route
});
};

标签: pomelo
xiaokandy 在 10-9 14:36发布 分享到 weibo
回到顶部