Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

Commit e8cfb4d

Browse files
authored
Add cases for network viablity changed, reconnect suggested, and cancelled. (#250)
1 parent 4fb87cb commit e8cfb4d

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Sources/ParseLiveQuery/Internal/ClientPrivate.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,32 @@ extension Client: WebSocketDelegate {
140140
if shouldPrintWebSocketLog { NSLog("ParseLiveQuery: Received binary data but we don't handle it...") }
141141
case .error(let error):
142142
NSLog("ParseLiveQuery: Error processing message: \(String(describing: error))")
143-
default:
144-
break
143+
case .viabilityChanged(let isViable):
144+
if shouldPrintWebSocketLog { NSLog("ParseLiveQuery: WebSocket viability channged to \(isViable ? "" : "not-")viable") }
145+
if !isViable {
146+
isConnecting = false
147+
}
148+
// TODO: Better retry logic, unless `disconnect()` was explicitly called
149+
if !userDisconnected, isViable {
150+
reconnect()
151+
}
152+
case .reconnectSuggested(let isSuggested):
153+
if shouldPrintWebSocketLog { NSLog("ParseLiveQuery: WebSocket reconnect is \(isSuggested ? "" : "not ")suggested") }
154+
// TODO: Better retry logic, unless `disconnect()` was explicitly called
155+
if !userDisconnected, isSuggested {
156+
reconnect()
157+
}
158+
case .cancelled:
159+
isConnecting = false
160+
if shouldPrintWebSocketLog { NSLog("ParseLiveQuery: WebSocket connection cancelled...") }
161+
// TODO: Better retry logic, unless `disconnect()` was explicitly called
162+
if !userDisconnected {
163+
reconnect()
164+
}
165+
case .pong(_):
166+
if shouldPrintWebSocketLog { NSLog("ParseLiveQuery: Received pong but we don't handle it...") }
167+
case .ping(_):
168+
if shouldPrintWebSocketLog { NSLog("ParseLiveQuery: Received ping but we don't handle it...") }
145169
}
146170
}
147171
}

0 commit comments

Comments
 (0)