keep trying

This commit is contained in:
Erik Little 2017-09-17 11:11:56 -04:00
parent bcaf7ba62d
commit ecf9336132
No known key found for this signature in database
GPG Key ID: 4930B7C5FBC1A69D

View File

@ -100,19 +100,32 @@ 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",
hostname: url.host ?? "localhost",
port: Port(url.port ?? 80))
let stream: ClientStream = secure ? try TLS.InternetSocket(socket, TLS.Context(.client)) : socket
try WebSocket.background(to: urlWebSocketWithSid.absoluteString, using: stream) {[weak self] ws in
guard let this = self else { return }
this.ws = ws
if secure {
let stream = try TLS.InternetSocket(socket, TLS.Context(.client))
try WebSocket.background(to: urlWebSocketWithSid.absoluteString, using: stream) {[weak self] ws in
guard let this = self else { return }
this.attachWebSocketHandlers()
this.handleWSConnect()
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)
}
}
} catch {
DefaultSocketLogger.Logger.error("Error connecting socket", type: "SocketEngineWebsocket")