Introvertuous / react-native-mqtt

Mqtt client for react native.
MIT License
156 stars 31 forks source link

INVALID_STATE_ERR is causing the device to CRASH #23

Open theSupermacy opened 5 years ago

theSupermacy commented 5 years ago

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?.

Nishit-Chauhan commented 5 years ago

hello, i am also trying to connect with mqtt with this library but got false in connected

screenshot 2019-02-13 at 11 14 13 am

can you please tell me what is your location and path? const client = new Paho.MQTT.Client(location, port, path, clientId) is location your aws END_POINT?

theSupermacy commented 5 years ago

Location is vernemq.mintpro.in and path is /mqtt

Is implementing some kind of retry mechanism manually required. Or library will do that for us ?

sjpeter commented 4 years ago

Do you solve the problem?

I find start mqtt. the app crash. I try no run mqtt , the app no problem. I don't find other problem.