Disconnect block does not fire
danipralea opened this issue · comments
Hello again. I've setup my client, but the the onDisconnected
block is not getting called.
My setup:
func connect(appId:String?, token: String?) {
guard let applicationId = appId, let token = token else {
print("cannot connect to the web socket server without an app id AND a token!")
return
}
let baseURL = "..."
let urlString = "\(baseURL)?application_id=\(applicationId)&authentication_token=\(token)"
client = ActionCableClient(url: URL(string: urlString)!)
let reconnectionStrategy : RetryStrategy = .logarithmicBackoff(maxRetries: 30, maxIntervalTime: 30.0)
client.reconnectionStrategy = reconnectionStrategy
client.onConnected = {
print("\(self.className) : Connected!")
}
client.onDisconnected = {(error: Error?) in
print("\(self.className) : Disconnected!")
}
client.connect()
}
I just tried on a brand new project and I can say it's the exact same behaviour
Ah I see where the gotcha here is. So what's going on is that it's not going to fire onDisconnected
until it has completely failed at trying to reconnect, there was some other sort of error, or you manually disconnect. One reason for this decision is that you don't necessarily want the disconnect to fire every time the connection stops, but before the client has had a chance to try and reconnect. onDisconnected
fires when it's disconnected and it's not going to try again.
After looking at another socket sort of library, I might change this up to add more information so you can get a better idea of what is going on.