From 793435a9509fca991caa3b0bffb7752bfa20546b Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Thu, 9 Sep 2021 16:34:59 -0400 Subject: [PATCH] Add cases for network viablity changed, reconnect suggested, and cancelled. --- .../Internal/ClientPrivate.swift | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Sources/ParseLiveQuery/Internal/ClientPrivate.swift b/Sources/ParseLiveQuery/Internal/ClientPrivate.swift index df3075b1..30668c17 100644 --- a/Sources/ParseLiveQuery/Internal/ClientPrivate.swift +++ b/Sources/ParseLiveQuery/Internal/ClientPrivate.swift @@ -140,8 +140,32 @@ extension Client: WebSocketDelegate { if shouldPrintWebSocketLog { NSLog("ParseLiveQuery: Received binary data but we don't handle it...") } case .error(let error): NSLog("ParseLiveQuery: Error processing message: \(String(describing: error))") - default: - break + case .viabilityChanged(let isViable): + if shouldPrintWebSocketLog { NSLog("ParseLiveQuery: WebSocket viability channged to \(isViable ? "" : "not-")viable") } + if !isViable { + isConnecting = false + } + // TODO: Better retry logic, unless `disconnect()` was explicitly called + if !userDisconnected, isViable { + reconnect() + } + case .reconnectSuggested(let isSuggested): + if shouldPrintWebSocketLog { NSLog("ParseLiveQuery: WebSocket reconnect is \(isSuggested ? "" : "not ")suggested") } + // TODO: Better retry logic, unless `disconnect()` was explicitly called + if !userDisconnected, isSuggested { + reconnect() + } + case .cancelled: + isConnecting = false + if shouldPrintWebSocketLog { NSLog("ParseLiveQuery: WebSocket connection cancelled...") } + // TODO: Better retry logic, unless `disconnect()` was explicitly called + if !userDisconnected { + reconnect() + } + case .pong(_): + if shouldPrintWebSocketLog { NSLog("ParseLiveQuery: Received pong but we don't handle it...") } + case .ping(_): + if shouldPrintWebSocketLog { NSLog("ParseLiveQuery: Received ping but we don't handle it...") } } } }