daltoniam / Starscream

Websockets in swift for iOS and OSX
Apache License 2.0
8.36k stars 1.21k forks source link

Getting viabilityChanged error while integration of Starscream Websocket lib #1007

Closed mbevanda closed 9 months ago

mbevanda commented 9 months ago

Describe the bug

I keep receiving viabilityChanged event whenever I try to connect to websocket.

Steps to Reproduce

It happens after connection request. Event I receive is viabilityChanged

    func didReceive(event: Starscream.WebSocketEvent, client: Starscream.WebSocketClient) {
        switch event {
        case .connected:
            isConnected = true
            if let message = messageInQueue {
                send(message)
                messageInQueue = nil
            }
        case .disconnected, .cancelled, .peerClosed:
            isConnected = false
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
                self.socket.connect()
            }
        case .text(let string):
            do {
                let decoder = JSONDecoder()
                let response = try decoder.decode(T.self, from: Data(string.utf8))
                if let mil = response as? MilistreamTickers, mil.hasQuoteWithProperties {
                    self.subject.send(response)
                }
            } catch {
                print("Unavailable", string)
            }
        case .binary, .pong, .ping, .error, .viabilityChanged, .reconnectSuggested:
            break
        }

    }

Expected behavior

I have same code base for months now and I expect web socket to connect as it was so far. But today I keep getting different event and no connection is established.

Environment: