Skip to content

INVALID_STATE_ERR is causing the device to CRASH #23

@theSupermacy

Description

@theSupermacy

I am using this library for connecting to the MQTT sever. I am getting the INVALID_STATE_ERR. I am not able to replicate the error. How to handle this type of error?

I am pasting my error stack here

com.facebook.react.common.JavascriptException: INVALID_STATE_ERR, stack:
value@79:1340
_socket_send@557:21101
_on_socket_open@557:16408
<unknown>@557:628
value@63:1501
<unknown>@79:4566
value@32:1363
value@18:3559
<unknown>@18:1044
value@18:2986
value@18:1016

I am using socket only for receiving the message. Can any one help regarding this?. I am attaching my Code Snippet

// These are my Utility function.

_createClient (options) {
      const location = this._getLocation()
      const clientId = this.generateClientId()
      const port = this._getPort()
      const path = this._getPath()
      const client = new Paho.MQTT.Client(location, port, path, clientId)
      console.log('Connecting to client', location, port, path, clientId)
      this.client = client
      this.client.onMessageArrived = this._notifyListeners // in case of new Message Arrival
      this.client.onConnectionLost = this.retry
      return this.client
    }

initialize (cb) {
      return new Promise((resolve, reject) => {
        try {
          this._createClient()
          this.observers = []
          if (!this.connected) {
            return this.connect()
              .then(resolve)
              .catch(err => {
                reject(new SocketError(err))
              })
          } else {
            console.log('Already Connected')
            return Promise.resolve()
          }
        } catch (ex) {
          return reject(new SocketError(ex))
        }
      })
    }


subscribe (subscribeTopic) {
      return new Promise((resolve, reject) => {
        try {
          if (this.connected) {
            console.log('Subscribing for Topic', subscribeTopic)
            this.client.subscribe(subscribeTopic, {
              onSuccess: () => {
                return resolve()
              },
              onFailure: err => reject(new SocketError(err)),
              qos: 2
            })
          } else {
            return reject(
              new SocketError(
                'Unable To Connect to socket. Exponential BackOff Started'
              )
            )
          }
        } catch (ex) {
          return reject(new SocketError(ex))
        }
      })
    }

For connecting I am using -

MQTTSocket.initialize() .then(() => MQTTSocket.subscribe(_userId))

_userId is the userId.

How can i replicate the issue?.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions