问题
In my ionic 4 application, I am using strophe.js to connect to Ejabbered server. In the application after status connected I am able to see chats successfully but after sometime it gets disconnected on its own and chats disappear without doing any thing.
In the logs,Strophe is disconnecting with following status:
EjabService [Connection] Unknown status received: and status is 10
Also on few devices, not able to see chats due to connection problem.
Ejabbered version installed: 20.03
Here is the code to connect to Ejabbered Server using Strophe.js:
/*Function
Connects the client from the Jabber server.
Parameters:
(String) jid - Jabber id.
(String) pass - Password.
Returns:
*/
login(jId, password, callback) {
try {
this.connection = new Strophe.Connection(this.BOSH_SERVICE, {
keepalive: true,
});
this.connection.connect(jId + "@" + this.host, password, (status) => {
this.onConnect(status, callback);
});
} catch (error) {
console.log(`error connecting to bosh service ${error}`);
}
}
/*Function
Connect XMPP.
Parameters:
Returns:
status - Status of connection.
*/
onConnect(status, callback) {
try {
var self = this;
switch (status) {
case Strophe.Status.CONNECTED:
this.logger.info(
`EjabService [Connection] Strophe is Connected with status ${status}`);
callback();
self.connection.addHandler(
(msg) => {
return self.onMessage(msg);
},
null,
"message",
null,
null,
null
);
self.connection.addHandler(
(ping) => {
return self.onPing(ping);
},
Strophe.NS.PING,
"iq",
"get"
);
self.connection.send($pres().tree());
break;
case Strophe.Status.ATTACHED:
this.logger.info(
`EjabService [Connection] Strophe is Attached with status ${status}`);
break;
case Strophe.Status.DISCONNECTED:
this.logger.info(
`EjabService [Connection] Strophe is Disconnected with status ${status}`);
break;
case Strophe.Status.AUTHFAIL:
this.logger.info(
`EjabService [Connection] Strophe is Authentication failed with status ${status}`);
break;
case Strophe.Status.CONNECTING:
this.logger.info(
`EjabService [Connection] Strophe is Connecting with status ${status}`);
break;
case Strophe.Status.DISCONNECTING:
this.logger.info(
`EjabService [Connection] Strophe is Disconnecting with status ${status}`);
break;
case Strophe.Status.AUTHENTICATING:
this.logger.info(
`EjabService [Connection] Strophe is Authenticating with status ${status}`);
break;
case Strophe.Status.ERROR:
case Strophe.Status.CONNFAIL:
this.logger.info(
`EjabService [Connection] Failed with status ${status}` );
break;
default:
this.logger.info(
`EjabService [Connection] Unknown status received: and status is ${status}`
);
break;
}
} catch (error) {
this.logger.info(`connection error ${error}`);
}
}
来源:https://stackoverflow.com/questions/62714012/strophe-disconnecting-from-ejabbered-with-status-10