handle acks better
This commit is contained in:
parent
f2ef3344c0
commit
df2f149f85
@ -328,7 +328,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
|
|||||||
func emitAck(ack:Int, withData args:[AnyObject]) {
|
func emitAck(ack:Int, withData args:[AnyObject]) {
|
||||||
dispatch_async(emitQueue) {[weak self] in
|
dispatch_async(emitQueue) {[weak self] in
|
||||||
if let this = self where this.connected {
|
if let this = self where this.connected {
|
||||||
let packet = SocketPacket.packetFromEmitWithData(args, id: ack ?? -1, nsp: this.nsp)
|
let packet = SocketPacket.packetFromEmitAckWithData(args, id: ack ?? -1, nsp: this.nsp)
|
||||||
let str = packet.createAck()
|
let str = packet.createAck()
|
||||||
|
|
||||||
SocketLogger.log("Emitting Ack: %@", client: this, args: str)
|
SocketLogger.log("Emitting Ack: %@", client: this, args: str)
|
||||||
|
|||||||
@ -74,35 +74,19 @@ struct SocketPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static func packetFromEmitWithData(data:[AnyObject], id:Int, nsp:String) -> SocketPacket {
|
static func packetFromEmitWithData(data:[AnyObject], id:Int, nsp:String) -> SocketPacket {
|
||||||
func findType(num:Int) -> SocketPacket.PacketType {
|
|
||||||
switch num {
|
|
||||||
case 0:
|
|
||||||
return SocketPacket.PacketType.EVENT
|
|
||||||
default:
|
|
||||||
return SocketPacket.PacketType.BINARY_EVENT
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let (parsedData, binary) = deconstructData(data)
|
let (parsedData, binary) = deconstructData(data)
|
||||||
let packet = SocketPacket(type: findType(binary.count), data: parsedData,
|
let packet = SocketPacket(type: findType(binary.count, ack: false), data: parsedData,
|
||||||
id: id, nsp: nsp, placeholders: -1, binary: binary)
|
id: id, nsp: nsp, placeholders: -1, binary: binary)
|
||||||
|
|
||||||
return packet
|
return packet
|
||||||
}
|
}
|
||||||
|
|
||||||
func getEvent() -> String {
|
static func packetFromEmitAckWithData(data:[AnyObject], id:Int, nsp:String) -> SocketPacket {
|
||||||
return data[0] as! String
|
let (parsedData, binary) = deconstructData(data)
|
||||||
}
|
let packet = SocketPacket(type: findType(binary.count, ack: true), data: parsedData,
|
||||||
|
id: id, nsp: nsp, placeholders: -1, binary: binary)
|
||||||
func getArgs() -> [AnyObject]? {
|
|
||||||
var arr = data
|
|
||||||
|
|
||||||
if data.count == 0 {
|
return packet
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
arr.removeAtIndex(0)
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mutating func addData(data:NSData) -> Bool {
|
mutating func addData(data:NSData) -> Bool {
|
||||||
@ -162,7 +146,7 @@ struct SocketPacket {
|
|||||||
func createAck() -> String {
|
func createAck() -> String {
|
||||||
var msg:String
|
var msg:String
|
||||||
|
|
||||||
if binary.count == 0 {
|
if type == PacketType.ACK {
|
||||||
if nsp == "/" {
|
if nsp == "/" {
|
||||||
msg = "3\(id)["
|
msg = "3\(id)["
|
||||||
} else {
|
} else {
|
||||||
@ -183,7 +167,7 @@ struct SocketPacket {
|
|||||||
func createMessageForEvent(event:String) -> String {
|
func createMessageForEvent(event:String) -> String {
|
||||||
let message:String
|
let message:String
|
||||||
|
|
||||||
if binary.count == 0 {
|
if type == PacketType.EVENT {
|
||||||
if nsp == "/" {
|
if nsp == "/" {
|
||||||
if id == -1 {
|
if id == -1 {
|
||||||
message = "2[\"\(event)\""
|
message = "2[\"\(event)\""
|
||||||
@ -257,7 +241,36 @@ struct SocketPacket {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static func findType(binCount:Int, ack:Bool) -> PacketType {
|
||||||
|
switch binCount {
|
||||||
|
case 0 where !ack:
|
||||||
|
return PacketType.EVENT
|
||||||
|
case 0 where ack:
|
||||||
|
return PacketType.ACK
|
||||||
|
case _ where !ack:
|
||||||
|
return PacketType.BINARY_EVENT
|
||||||
|
case _ where ack:
|
||||||
|
return PacketType.BINARY_ACK
|
||||||
|
default:
|
||||||
|
return PacketType.BINARY_ACK
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEvent() -> String {
|
||||||
|
return data[0] as! String
|
||||||
|
}
|
||||||
|
|
||||||
|
func getArgs() -> [AnyObject]? {
|
||||||
|
var arr = data
|
||||||
|
|
||||||
|
if data.count == 0 {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
arr.removeAtIndex(0)
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static func shred(data:AnyObject, inout binary:[NSData]) -> AnyObject {
|
private static func shred(data:AnyObject, inout binary:[NSData]) -> AnyObject {
|
||||||
if let bin = data as? NSData {
|
if let bin = data as? NSData {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user