Strophe disconnecting from Ejabbered with Status 10

。_饼干妹妹 提交于 2021-01-28 08:59:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!