更新
在尝试了解这个 rid 加 +1 等之后,我注意到 rid 正在改变存在,在花名册上发送的消息上的消息上 roster change 所以我在每个上都做了一个 XMLHttpRequest 以记住会话中的新 rid。出于某种原因,localstorage 有时工作有时不工作。
现在我已经摆脱了所有的时间。
我想我明白了。问题是摆脱和存在。
1)首先你必须从你的日志中弄清楚你的摆脱是增加还是减少。
我的减少了一个。所以我从我的 Chat.connection.rid 中减去 -1
2) 在我的 openfire 日志中,我发现我在页面刷新时发送了不可用状态,因此我更改了 window.unload 函数以将状态发送到在线。ñ
现在我正在刷新页面数百万次,而且我从未断开连接。
现在我只需要弄清楚如何为非 HTML 浏览器记住 connection.rid 到 localStorage。
要在调试模式下启动 openfire,您只需添加 ./openfire.sh -debug。然后您将能够在 debug.log 中查看所有内容
这对我有用。如果这对您有用,请+1并接受答案。
不要忘记在注销时终止会话:)
更新
这是我在 window.onunload 上的功能
window.onunload = function(ev){
var initialPresence = $pres().c('show').t("cao").up().c('status').t("sad");
Chat.connection.send(initialPresence);
store.set('session_rid', parseInt(Chat.connection.rid)-1);
//save rooster contacts state
var contacts = document.getElementById('records').getElementsByTagName('li');
var id_value;
var class_value;
var status;
var el;
for(i= 0; i < contacts.length; i++){
el = contacts[i].getElementsByClassName("mood")[0];
status = el.textContent || el.innerText;
Array.prototype.slice.call(contacts[i].attributes).forEach(function(item) {
if(item.name == "id"){
id_value = item.value;
}
if(item.name == "class"){
class_value = item.value;
}
store.set('user'+i, { id: id_value, class_name: class_value, status : status });
});
}
Chat.disconnect();
}
这是我的 window.onload 函数
window.onload = function(){
if(store.get("session_rid")){
var obj;
var id;
var class_name;
var status;
store.forEach(function(val, key) {
if(val !== "session_rid"){
setTimeout(function(){
obj = eval(key);
id = obj.id;
class_name = obj.class_name;
status = obj.status;
if(document.getElementById(id)){
document.getElementById(id).className = class_name;
document.getElementById(id).getElementsByClassName("mood")[0].innerHTML = "<span>"+status+"</span>";
}
}, 1000);
}
})
}
}
这对我有用。我使用store.js来存储数据,因此它可以在 IE 上运行。
我使用了附加会话。
//json is from ajax call on some php script that has started attached session on user login
var obj = JSON.parse(json);
connection = new Strophe.Connection(BOSH_SERVICE);
connection.attach(obj.fulljid,
obj.sid,
(store.get("session_rid") ? store.get("session_rid"):obj.rid),
justDoIt);
full_jid = obj.fulljid;