fix namespaces
This commit is contained in:
parent
b295561dcc
commit
1f1ba60574
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
typealias AckCallback = (AnyObject?) -> Void
|
typealias AckCallback = (NSArray?) -> Void
|
||||||
|
|
||||||
class SocketAckHandler {
|
class SocketAckHandler {
|
||||||
let ackNum:Int!
|
let ackNum:Int!
|
||||||
|
|||||||
@ -221,7 +221,7 @@ class SocketEngine: NSObject, SRWebSocketDelegate {
|
|||||||
self?.ws = SRWebSocket(URL:
|
self?.ws = SRWebSocket(URL:
|
||||||
NSURL(string: urlWebSocket + "&sid=\(self!.sid)")!)
|
NSURL(string: urlWebSocket + "&sid=\(self!.sid)")!)
|
||||||
self?.ws?.delegate = self
|
self?.ws?.delegate = self
|
||||||
self?.ws?.open()
|
// self?.ws?.open()
|
||||||
} else {
|
} else {
|
||||||
NSLog("Error handshaking")
|
NSLog("Error handshaking")
|
||||||
return
|
return
|
||||||
@ -278,8 +278,8 @@ class SocketEngine: NSObject, SRWebSocketDelegate {
|
|||||||
length += chr
|
length += chr
|
||||||
} else {
|
} else {
|
||||||
if testLength(length, &n) || length == "" {
|
if testLength(length, &n) || length == "" {
|
||||||
println("parsing error at testlength")
|
self.handlePollingFailed()
|
||||||
exit(1)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = String(strArray[i+1...i+n])
|
msg = String(strArray[i+1...i+n])
|
||||||
@ -287,7 +287,7 @@ class SocketEngine: NSObject, SRWebSocketDelegate {
|
|||||||
if let lengthInt = length.toInt() {
|
if let lengthInt = length.toInt() {
|
||||||
if lengthInt != msg.length {
|
if lengthInt != msg.length {
|
||||||
println("parsing error")
|
println("parsing error")
|
||||||
exit(1)
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -225,7 +225,14 @@ class SocketIOClient {
|
|||||||
if handler.ackNum != ack {
|
if handler.ackNum != ack {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
handler.callback?(data)
|
if data is NSArray {
|
||||||
|
handler.callback?(data as? NSArray)
|
||||||
|
} else if data != nil {
|
||||||
|
handler.callback?([data!])
|
||||||
|
} else {
|
||||||
|
handler.callback?(nil)
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -465,23 +472,23 @@ class SocketIOClient {
|
|||||||
|
|
||||||
if let stringMessage = message as? String {
|
if let stringMessage = message as? String {
|
||||||
// Check for successful namepsace connect
|
// Check for successful namepsace connect
|
||||||
|
if self.nsp != nil {
|
||||||
|
if stringMessage == "0/\(self.nsp!)" {
|
||||||
|
self.didConnect()
|
||||||
|
self.handleEvent("connect", data: nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if stringMessage == "0" {
|
if stringMessage == "0" {
|
||||||
// connected
|
|
||||||
self.didConnect()
|
|
||||||
|
|
||||||
if self.nsp != nil {
|
if self.nsp != nil {
|
||||||
// Join namespace
|
// Join namespace
|
||||||
self.joinNamespace()
|
self.joinNamespace()
|
||||||
return
|
return
|
||||||
}
|
} else {
|
||||||
|
// Don't handle as internal because something crazy could happen where
|
||||||
// Don't handle as internal because something crazy could happen where
|
// we disconnect before it's handled
|
||||||
// we disconnect before it's handled
|
self.didConnect()
|
||||||
self.handleEvent("connect", data: nil)
|
|
||||||
}
|
|
||||||
if self.nsp != nil {
|
|
||||||
if stringMessage == "0/\(self.nsp!)" {
|
|
||||||
self.handleEvent("connect", data: nil)
|
self.handleEvent("connect", data: nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -705,10 +712,12 @@ class SocketIOClient {
|
|||||||
let filledInArgs:AnyObject = self.lastSocketMessage!.fillInPlaceholders(args)
|
let filledInArgs:AnyObject = self.lastSocketMessage!.fillInPlaceholders(args)
|
||||||
|
|
||||||
if self.lastSocketMessage!.justAck! {
|
if self.lastSocketMessage!.justAck! {
|
||||||
|
// Should handle ack
|
||||||
self.handleAck(self.lastSocketMessage!.ack!, data: filledInArgs)
|
self.handleAck(self.lastSocketMessage!.ack!, data: filledInArgs)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Should do event
|
||||||
if self.lastSocketMessage!.ack != nil {
|
if self.lastSocketMessage!.ack != nil {
|
||||||
self.handleEvent(event, data: filledInArgs, isInternalMessage: false,
|
self.handleEvent(event, data: filledInArgs, isInternalMessage: false,
|
||||||
wantsAck: self.lastSocketMessage!.ack!, withAckType: 6)
|
wantsAck: self.lastSocketMessage!.ack!, withAckType: 6)
|
||||||
@ -718,11 +727,13 @@ class SocketIOClient {
|
|||||||
} else {
|
} else {
|
||||||
let filledInArgs:AnyObject = self.lastSocketMessage!.fillInPlaceholders()
|
let filledInArgs:AnyObject = self.lastSocketMessage!.fillInPlaceholders()
|
||||||
|
|
||||||
|
// Should handle ack
|
||||||
if self.lastSocketMessage!.justAck! {
|
if self.lastSocketMessage!.justAck! {
|
||||||
self.handleAck(self.lastSocketMessage!.ack!, data: filledInArgs)
|
self.handleAck(self.lastSocketMessage!.ack!, data: filledInArgs)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Should handle ack
|
||||||
if self.lastSocketMessage!.ack != nil {
|
if self.lastSocketMessage!.ack != nil {
|
||||||
self.handleEvent(event, data: filledInArgs, isInternalMessage: false,
|
self.handleEvent(event, data: filledInArgs, isInternalMessage: false,
|
||||||
wantsAck: self.lastSocketMessage!.ack!, withAckType: 6)
|
wantsAck: self.lastSocketMessage!.ack!, withAckType: 6)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user