sroebert / mqtt-nio

Non-blocking, event-driven Swift client for MQTT (3.1.1 and 5.0).
MIT License
53 stars 13 forks source link

wss signed url: Disconnected while waiting for 'Connect Acknowledgment' #3

Closed JavierRefuerzo closed 2 years ago

JavierRefuerzo commented 2 years ago

Hi,

I've been testing MQTT libraries for Swift for the past two days and this repo appears to be the only Swift library which supports wss. Nice work!

Issues: I received the log: "notice nl.roebert.MQTTNio : Disconnected while waiting for 'Connect Acknowledgement'"

1) Is there a callback to alert the application when an error like this occurs?

2) I'm not sure how to resolve the issue. The url is a pre-signed AWS url with query string. I have the same working on Android with Eclipse.Paho. Looking at the MQTTConfiguration.swift I don't believe the query string is being included, is this a correct assumption? If that is correct is there any way to add the query string?

var client: MQTTClient! ..... //signed url url = wss://a2xxxxxxxx.iot.us-east-1.amazonaws.com/mqtt?X-Amz-Algori....... ... client = MQTTClient(configuration: .init(url: url, clientId: clientId)) client.connect() Thanks

sroebert commented 2 years ago

Hey, sorry for the late response, I somehow did not get or missed the notification for this issue.

  1. When you call connect() you get an EventLoopFuture back. You can add a closure for when the connection fails.

    client.connect().whenFailure { error in
    print("Failed to connect: \(error)")
    }
  2. Currently when using url directly with the configuration, it seems that I am ignoring the query part of the url. I have added a fix for this in release 2.2.1.