Skip to content

Commit 2712461

Browse files
committed
fix #26
1 parent 44e2781 commit 2712461

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

Diff for: Socket.IO-Client-Swift.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "Socket.IO-Client-Swift"
3-
s.version = "1.2.0"
3+
s.version = "1.2.1"
44
s.summary = "Socket.IO-client for Swift"
55
s.description = <<-DESC
66
Socket.IO-client for Swift.
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
1212
s.author = { "Erik" => "[email protected]" }
1313
s.ios.deployment_target = '8.0'
1414
s.osx.deployment_target = '10.10'
15-
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v1.2.0' }
15+
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v1.2.1' }
1616
s.source_files = "SwiftIO/**/*.swift"
1717
s.requires_arc = true
1818
# s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files

Diff for: SwiftIO/SocketParser.swift

+26-8
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class SocketParser {
211211
}
212212
}
213213

214-
if stringMessage.hasPrefix("5") {
214+
if stringMessage.hasPrefix("5") || stringMessage.hasPrefix("6") {
215215
// Check for message with binary placeholders
216216
self.parseBinaryMessage(stringMessage, socket: socket)
217217
return
@@ -220,10 +220,16 @@ class SocketParser {
220220
/**
221221
Begin check for message
222222
**/
223-
let messageGroups = stringMessage["(\\d*)\\/?(\\w*)?,?(\\d*)?\\[\"(.*?)\",?(.*?)?\\]$",
224-
NSRegularExpressionOptions.DotMatchesLineSeparators].groups()
225-
if messageGroups == nil {
226-
NSLog("Error in groups")
223+
var messageGroups:[String]?
224+
225+
if let groups = stringMessage["(\\d*)\\/?(\\w*)?,?(\\d*)?\\[\"(.*?)\",?(.*?)?\\]$",
226+
NSRegularExpressionOptions.DotMatchesLineSeparators].groups() {
227+
messageGroups = groups
228+
} else if let ackGroup = stringMessage["(\\d*)\\/?(\\w*)?,?(\\d*)?\\[(.*?)?\\]$",
229+
NSRegularExpressionOptions.DotMatchesLineSeparators].groups() {
230+
messageGroups = ackGroup
231+
} else {
232+
NSLog("Error parsing message: %s", stringMessage)
227233
return
228234
}
229235

@@ -289,6 +295,12 @@ class SocketParser {
289295
// Handles binary data
290296
class func parseBinaryData(data:NSData, socket:SocketIOClient) {
291297
// NSLog(data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.allZeros))
298+
299+
if socket.waitingData.count == 0 {
300+
NSLog("Got data when not remaking packet")
301+
return
302+
}
303+
292304
let shouldExecute = socket.waitingData[0].addData(data)
293305

294306
if shouldExecute {
@@ -339,10 +351,16 @@ class SocketParser {
339351
/**
340352
Begin check for binary placeholders
341353
**/
342-
let binaryGroup = message["^(\\d*)-\\/?(\\w*)?,?(\\d*)?\\[(\".*?\")?,?(.*)?\\]$",
343-
NSRegularExpressionOptions.DotMatchesLineSeparators].groups()
354+
var binaryGroup:[String]?
344355

345-
if binaryGroup == nil {
356+
if let groups = message["^(\\d*)-\\/?(\\w*)?,?(\\d*)?\\[(\".*?\")?,?(.*)?\\]$",
357+
NSRegularExpressionOptions.DotMatchesLineSeparators].groups() {
358+
binaryGroup = groups
359+
} else if let groups = message["^(\\d*)-\\/?(\\w*)?,?(\\d*)?\\[(.*?)?\\]$",
360+
NSRegularExpressionOptions.DotMatchesLineSeparators].groups() {
361+
binaryGroup = groups
362+
} else {
363+
NSLog("Error in parsing binary message: %s", message)
346364
return
347365
}
348366

0 commit comments

Comments
 (0)