From 27124610445774ed76a596fbabd4f51c55707f80 Mon Sep 17 00:00:00 2001 From: Erik Date: Mon, 16 Mar 2015 17:58:12 -0400 Subject: [PATCH] fix #26 --- Socket.IO-Client-Swift.podspec | 4 ++-- SwiftIO/SocketParser.swift | 34 ++++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Socket.IO-Client-Swift.podspec b/Socket.IO-Client-Swift.podspec index 67b1fa52..e5877c94 100644 --- a/Socket.IO-Client-Swift.podspec +++ b/Socket.IO-Client-Swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Socket.IO-Client-Swift" - s.version = "1.2.0" + s.version = "1.2.1" s.summary = "Socket.IO-client for Swift" s.description = <<-DESC Socket.IO-client for Swift. @@ -12,7 +12,7 @@ Pod::Spec.new do |s| s.author = { "Erik" => "nuclear.ace@gmail.com" } s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.10' - s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v1.2.0' } + s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v1.2.1' } s.source_files = "SwiftIO/**/*.swift" s.requires_arc = true # s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files diff --git a/SwiftIO/SocketParser.swift b/SwiftIO/SocketParser.swift index 9791a5b0..bd0e29bf 100644 --- a/SwiftIO/SocketParser.swift +++ b/SwiftIO/SocketParser.swift @@ -211,7 +211,7 @@ class SocketParser { } } - if stringMessage.hasPrefix("5") { + if stringMessage.hasPrefix("5") || stringMessage.hasPrefix("6") { // Check for message with binary placeholders self.parseBinaryMessage(stringMessage, socket: socket) return @@ -220,10 +220,16 @@ class SocketParser { /** Begin check for message **/ - let messageGroups = stringMessage["(\\d*)\\/?(\\w*)?,?(\\d*)?\\[\"(.*?)\",?(.*?)?\\]$", - NSRegularExpressionOptions.DotMatchesLineSeparators].groups() - if messageGroups == nil { - NSLog("Error in groups") + var messageGroups:[String]? + + if let groups = stringMessage["(\\d*)\\/?(\\w*)?,?(\\d*)?\\[\"(.*?)\",?(.*?)?\\]$", + NSRegularExpressionOptions.DotMatchesLineSeparators].groups() { + messageGroups = groups + } else if let ackGroup = stringMessage["(\\d*)\\/?(\\w*)?,?(\\d*)?\\[(.*?)?\\]$", + NSRegularExpressionOptions.DotMatchesLineSeparators].groups() { + messageGroups = ackGroup + } else { + NSLog("Error parsing message: %s", stringMessage) return } @@ -289,6 +295,12 @@ class SocketParser { // Handles binary data class func parseBinaryData(data:NSData, socket:SocketIOClient) { // NSLog(data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.allZeros)) + + if socket.waitingData.count == 0 { + NSLog("Got data when not remaking packet") + return + } + let shouldExecute = socket.waitingData[0].addData(data) if shouldExecute { @@ -339,10 +351,16 @@ class SocketParser { /** Begin check for binary placeholders **/ - let binaryGroup = message["^(\\d*)-\\/?(\\w*)?,?(\\d*)?\\[(\".*?\")?,?(.*)?\\]$", - NSRegularExpressionOptions.DotMatchesLineSeparators].groups() + var binaryGroup:[String]? - if binaryGroup == nil { + if let groups = message["^(\\d*)-\\/?(\\w*)?,?(\\d*)?\\[(\".*?\")?,?(.*)?\\]$", + NSRegularExpressionOptions.DotMatchesLineSeparators].groups() { + binaryGroup = groups + } else if let groups = message["^(\\d*)-\\/?(\\w*)?,?(\\d*)?\\[(.*?)?\\]$", + NSRegularExpressionOptions.DotMatchesLineSeparators].groups() { + binaryGroup = groups + } else { + NSLog("Error in parsing binary message: %s", message) return }