我搜索了谷歌和堆棧溢出一些類似的問題。但我沒有得到任何解決方案。404(無效的SID值)在Strophe使用附加()
基本上,我想堅持跨應用程序中的網頁連接。爲此,我正在使用Cookie。我將SID和RID存儲在Cookie中,並將它們用於再次附加會話。
以下是我的代碼。
this.openConnection = function(){
if (chatObj.connection != null) return;
var jid = chatObj.userName + '@' + chatObj.openfireDomainURL; // Bare JID
var sid = Cookies.get(chatObj.userName + '_sid'); // Session Identifier
var rid = Cookies.get(chatObj.userName + '_rid'); // Request Identifier
var connection = new Strophe.Connection(chatObj.xmppHttpBindURL);
chatObj.connection = connection;
if(chatObj.isEmpty(sid) && chatObj.isEmpty(rid)){
connection.connect(jid, chatObj.password, chatObj.onConnection);
} else {
// parseInt(rid,10) + 1
var rid = parseInt(rid) + parseInt(1);
connection.attach(jid, sid, rid, chatObj.onConnection);
}
};
this.onConnection = function(status) {
if (status === Strophe.Status.CONNECTED) {
chatObj.log("CONNECTED ");
//Cookies.set(chatObj.userName + '_sid', chatObj.connection.sid);
//Cookies.set(chatObj.userName + '_rid', chatObj.connection.rid);
jQuery(document).trigger('connected');
} else if (status === Strophe.Status.DISCONNECTED) {
jQuery(document).trigger('disconnected');
chatObj.log("DISCONNECTED ");
} else if (status === Strophe.Status.CONNFAIL) {
chatObj.log("CONNFAIL ");
} else if (status === Strophe.Status.AUTHENTICATING) {
chatObj.log("AUTHENTICATING ");
} else if (status === Strophe.Status.AUTHFAIL) {
chatObj.log("AUTHFAIL ");
} else if (status === Strophe.Status.ERROR) {
chatObj.log("ERROR ");
} else if (status === Strophe.Status.ATTACHED){
chatObj.log("ATTACHED ");
jQuery(document).trigger('connected');
} else if (status === Strophe.Status.CONNFAIL){
chatObj.log("CONNFAIL ");
}
};
$(window).unload(function() {
console.log("widows unload ");
if(chatObj.connection != null){
console.log("set cookies ");
Cookies.set(chatObj.userName + '_sid', chatObj.connection.sid);
Cookies.set(chatObj.userName + '_rid', chatObj.connection.rid);
} else {
// Cookies.remove(chatObj.userName + '_sid');
// Cookies.remove(chatObj.userName + '_rid');
}
});
404 Invalid SID value in Strophe while using attach()
我嘗試使用Windows卸載,但它不工作。我仍然得到同樣的錯誤。
我確實得到了sid和rid值。即使這樣也行不通。 – ashishjmeshram
你的項目中使用了哪個版本的strophe.js? – beaver
我正在使用的strophe版本是1.2.14 – ashishjmeshram