From ffcd841267e1ccfd365cb84a4ab48bcec9853868 Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 27 Mar 2015 12:13:06 -0400 Subject: [PATCH] Fix binary acks --- SwiftIO/SocketEngine.swift | 6 +++--- SwiftIO/SocketIOClient.swift | 5 ++--- SwiftIO/SocketPacket.swift | 6 ++++-- SwiftIO/SocketParser.swift | 5 +++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/SwiftIO/SocketEngine.swift b/SwiftIO/SocketEngine.swift index 744720e..5d3689c 100644 --- a/SwiftIO/SocketEngine.swift +++ b/SwiftIO/SocketEngine.swift @@ -460,17 +460,17 @@ public class SocketEngine: NSObject, WebSocketDelegate { if let pingInterval = json["pingInterval"] as? Int { self.pingInterval = pingInterval / 1000 - } + } } else { fatalError("Error parsing engine connect") } + self.startPingTimer() + if !self.forceWebsockets { self.doPoll() } - self.startPingTimer() - return } else if type == PacketType.CLOSE.rawValue { if self.polling { diff --git a/SwiftIO/SocketIOClient.swift b/SwiftIO/SocketIOClient.swift index 89ddd95..dd78211 100644 --- a/SwiftIO/SocketIOClient.swift +++ b/SwiftIO/SocketIOClient.swift @@ -348,7 +348,7 @@ public class SocketIOClient: NSObject, SocketEngineClient { Causes an event to be handled. Only use if you know what you're doing. */ public func handleEvent(event:String, data:[AnyObject]?, isInternalMessage:Bool = false, - wantsAck ack:Int? = nil, withAckType ackType:Int = 3) { + wantsAck ack:Int? = nil) { // println("Should do event: \(event) with data: \(data)") if !self.connected && !isInternalMessage { return @@ -364,8 +364,7 @@ public class SocketIOClient: NSObject, SocketEngineClient { for handler in self.handlers { if handler.event == event { if ack != nil { - handler.executeCallback(data, withAck: ack!, - withAckType: ackType, withSocket: self) + handler.executeCallback(data, withAck: ack!, withSocket: self) } else { handler.executeCallback(data) } diff --git a/SwiftIO/SocketPacket.swift b/SwiftIO/SocketPacket.swift index ccbe0b5..997e032 100644 --- a/SwiftIO/SocketPacket.swift +++ b/SwiftIO/SocketPacket.swift @@ -134,12 +134,16 @@ class SocketPacket { var msg:String if self.binary.count == 0 { + self.type = SocketPacketType.ACK + if nsp == "/" { msg = "3\(self.id!)[" } else { msg = "3/\(self.nsp),\(self.id!)[" } } else { + self.type = SocketPacketType.BINARY_ACK + if nsp == "/" { msg = "6\(self.binary.count)-\(self.id!)[" } else { @@ -195,8 +199,6 @@ class SocketPacket { if let str = self.data?[i] as? String { if let num = str["~~(\\d)"].groups() { newArr[i] = self.binary[num[1].toInt()!] - } else { - newArr[i] = str } } else if self.data?[i] is NSDictionary || self.data?[i] is NSArray { newArr[i] = self._fillInPlaceholders(self.data![i]) diff --git a/SwiftIO/SocketParser.swift b/SwiftIO/SocketParser.swift index 84976e3..b30eff4 100644 --- a/SwiftIO/SocketParser.swift +++ b/SwiftIO/SocketParser.swift @@ -197,7 +197,8 @@ class SocketParser { return } - socket.handleEvent(p.getEvent(), data: p.data, isInternalMessage: false, wantsAck: p.id, withAckType: 3) + socket.handleEvent(p.getEvent(), data: p.data, isInternalMessage: false, + wantsAck: p.id) } else if p.type == SocketPacketType.ACK { if checkNSP(p.nsp) { return @@ -250,7 +251,7 @@ class SocketParser { if !packet.justAck { socket.handleEvent(packet.getEvent(), data: packet.data, - wantsAck: packet.id, withAckType: 6) + wantsAck: packet.id) } else { socket.handleAck(packet.id!, data: packet.data) }