From 44ee94d2ac0ddcfeddabd72aba0bd15be6dba243 Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 26 Apr 2016 15:28:08 -0400 Subject: [PATCH] refactors --- Source/SocketEngine.swift | 29 +++++++++++------------------ Source/SocketEngineSpec.swift | 2 +- Source/SocketEngineWebsocket.swift | 2 -- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/Source/SocketEngine.swift b/Source/SocketEngine.swift index e886cad..857e6d8 100644 --- a/Source/SocketEngine.swift +++ b/Source/SocketEngine.swift @@ -34,6 +34,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe (urlPolling, urlWebSocket) = createURLs() } } + public var postWait = [String]() public var waitingForPoll = false public var waitingForPost = false @@ -133,23 +134,16 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe allowLossyConversion: false) else { return } do { - if let dict = try NSJSONSerialization.JSONObjectWithData(stringData, - options: NSJSONReadingOptions.MutableContainers) as? NSDictionary { - guard let code = dict["code"] as? Int else { return } - guard let error = dict["message"] as? String else { return } - - switch code { - case 0: // Unknown transport - didError(error) - case 1: // Unknown sid. - didError(error) - case 2: // Bad handshake request - didError(error) - case 3: // Bad request - didError(error) - default: - didError(error) - } + if let dict = try NSJSONSerialization.JSONObjectWithData(stringData, options: .MutableContainers) as? NSDictionary { + guard let error = dict["message"] as? String else { return } + + /* + 0: Unknown transport + 1: Unknown sid + 2: Bad handshake request + 3: Bad request + */ + didError(error) } } catch { didError("Got unknown error from server \(msg)") @@ -393,7 +387,6 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe } } catch { didError("Error parsing open packet") - return } } diff --git a/Source/SocketEngineSpec.swift b/Source/SocketEngineSpec.swift index 2fde9f3..58b5450 100644 --- a/Source/SocketEngineSpec.swift +++ b/Source/SocketEngineSpec.swift @@ -46,7 +46,7 @@ import Foundation var urlPolling: NSURL { get } var urlWebSocket: NSURL { get } var websocket: Bool { get } - optional var ws: WebSocket? { get } + var ws: WebSocket? { get } init(client: SocketEngineClient, url: NSURL, options: NSDictionary?) diff --git a/Source/SocketEngineWebsocket.swift b/Source/SocketEngineWebsocket.swift index a173250..e1b0ba8 100644 --- a/Source/SocketEngineWebsocket.swift +++ b/Source/SocketEngineWebsocket.swift @@ -27,8 +27,6 @@ import Foundation /// Protocol that is used to implement socket.io WebSocket support public protocol SocketEngineWebsocket : SocketEngineSpec, WebSocketDelegate { - var ws: WebSocket? { get } - func sendWebSocketMessage(str: String, withType type: SocketEnginePacketType, withData datas: [NSData]) }