small refactor

This commit is contained in:
Erik Little 2017-09-17 11:23:06 -04:00
parent 239b30f2c8
commit c20c286864
No known key found for this signature in database
GPG Key ID: 4930B7C5FBC1A69D

View File

@ -100,13 +100,6 @@ extension SocketEngineWebsocket {
ws?.connect()
#else
func onConnect(ws: WebSocket) {
self.ws = ws
attachWebSocketHandlers()
handleWSConnect()
}
let url = urlWebSocketWithSid
do {
let socket = try TCPInternetSocket(scheme: url.scheme ?? "http",
@ -118,13 +111,13 @@ extension SocketEngineWebsocket {
try WebSocket.background(to: urlWebSocketWithSid.absoluteString, using: stream) {[weak self] ws in
guard let this = self else { return }
onConnect(ws: ws)
this.onConnect(ws: ws)
}
} else {
try WebSocket.background(to: urlWebSocketWithSid.absoluteString, using: socket) {[weak self] ws in
guard let this = self else { return }
onConnect(ws: ws)
this.onConnect(ws: ws)
}
}
} catch {
@ -133,6 +126,15 @@ extension SocketEngineWebsocket {
#endif
}
#if os(Linux)
func onConnect(ws: WebSocket) {
self.ws = ws
attachWebSocketHandlers()
handleWSConnect()
}
#endif
func probeWebSocket() {
if ws?.isConnected ?? false {
sendWebSocketMessage("probe", withType: .ping, withData: [])