Skip to content

Commit ae536ca

Browse files
committed
Check for open socket before sending ping
1 parent 4ffc808 commit ae536ca

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ extension ParseLiveQuery {
525525
self.createTask()
526526
self.attempts += 1
527527
let error = ParseError(code: .unknownError,
528-
message: "Attempted to open socket \(self.attempts)")
528+
message: "Attempted to open socket \(self.attempts) time(s)")
529529
completion(error)
530530
}
531531
}
@@ -561,7 +561,13 @@ extension ParseLiveQuery {
561561
*/
562562
public func sendPing(pongReceiveHandler: @escaping (Error?) -> Void) {
563563
synchronizationQueue.sync {
564-
URLSession.liveQuery.sendPing(task, pongReceiveHandler: pongReceiveHandler)
564+
if isSocketEstablished {
565+
URLSession.liveQuery.sendPing(task, pongReceiveHandler: pongReceiveHandler)
566+
} else {
567+
let error = ParseError(code: .unknownError,
568+
message: "Need to open the websocket before it can be pinged.")
569+
pongReceiveHandler(error)
570+
}
565571
}
566572
}
567573

0 commit comments

Comments
 (0)