refactors

This commit is contained in:
Erik 2016-04-26 15:28:08 -04:00
parent 6efeb7d5b2
commit 44ee94d2ac
3 changed files with 12 additions and 21 deletions

View File

@ -34,6 +34,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe
(urlPolling, urlWebSocket) = createURLs() (urlPolling, urlWebSocket) = createURLs()
} }
} }
public var postWait = [String]() public var postWait = [String]()
public var waitingForPoll = false public var waitingForPoll = false
public var waitingForPost = false public var waitingForPost = false
@ -133,23 +134,16 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe
allowLossyConversion: false) else { return } allowLossyConversion: false) else { return }
do { do {
if let dict = try NSJSONSerialization.JSONObjectWithData(stringData, if let dict = try NSJSONSerialization.JSONObjectWithData(stringData, options: .MutableContainers) as? NSDictionary {
options: NSJSONReadingOptions.MutableContainers) as? NSDictionary { guard let error = dict["message"] as? String else { return }
guard let code = dict["code"] as? Int else { return }
guard let error = dict["message"] as? String else { return } /*
0: Unknown transport
switch code { 1: Unknown sid
case 0: // Unknown transport 2: Bad handshake request
didError(error) 3: Bad request
case 1: // Unknown sid. */
didError(error) didError(error)
case 2: // Bad handshake request
didError(error)
case 3: // Bad request
didError(error)
default:
didError(error)
}
} }
} catch { } catch {
didError("Got unknown error from server \(msg)") didError("Got unknown error from server \(msg)")
@ -393,7 +387,6 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe
} }
} catch { } catch {
didError("Error parsing open packet") didError("Error parsing open packet")
return
} }
} }

View File

@ -46,7 +46,7 @@ import Foundation
var urlPolling: NSURL { get } var urlPolling: NSURL { get }
var urlWebSocket: NSURL { get } var urlWebSocket: NSURL { get }
var websocket: Bool { get } var websocket: Bool { get }
optional var ws: WebSocket? { get } var ws: WebSocket? { get }
init(client: SocketEngineClient, url: NSURL, options: NSDictionary?) init(client: SocketEngineClient, url: NSURL, options: NSDictionary?)

View File

@ -27,8 +27,6 @@ import Foundation
/// Protocol that is used to implement socket.io WebSocket support /// Protocol that is used to implement socket.io WebSocket support
public protocol SocketEngineWebsocket : SocketEngineSpec, WebSocketDelegate { public protocol SocketEngineWebsocket : SocketEngineSpec, WebSocketDelegate {
var ws: WebSocket? { get }
func sendWebSocketMessage(str: String, withType type: SocketEnginePacketType, withData datas: [NSData]) func sendWebSocketMessage(str: String, withType type: SocketEnginePacketType, withData datas: [NSData])
} }