Merge remote-tracking branch 'socketio/master'

This commit is contained in:
Lukas Schmidt 2015-09-18 17:34:39 +02:00
commit 6cffbc2404
20 changed files with 1077 additions and 428 deletions

View File

@ -2,4 +2,4 @@ language: objective-c
xcode_project: Socket.IO-Client-Swift.xcodeproj # path to your xcodeproj folder xcode_project: Socket.IO-Client-Swift.xcodeproj # path to your xcodeproj folder
xcode_scheme: SocketIO-iOS xcode_scheme: SocketIO-iOS
osx_image: xcode7 osx_image: xcode7
script: xctool -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-iOS -sdk iphonesimulator build test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO script: xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-iOS -sdk iphonesimulator build test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO

View File

@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/socketio/socket.io-client-swift.svg?branch=swift-2)](https://travis-ci.org/socketio/socket.io-client-swift) [![Build Status](https://travis-ci.org/socketio/socket.io-client-swift.svg?branch=master)](https://travis-ci.org/socketio/socket.io-client-swift)
#Socket.IO-Client-Swift #Socket.IO-Client-Swift
Socket.IO-client for iOS/OS X. Socket.IO-client for iOS/OS X.
@ -26,7 +26,7 @@ socket.connect()
##Objective-C Example ##Objective-C Example
```objective-c ```objective-c
SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" options:nil]; SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" opts:nil];
[socket onObjectiveC:@"connect" callback:^(NSArray* data, void (^ack)(NSArray*)) { [socket onObjectiveC:@"connect" callback:^(NSArray* data, void (^ack)(NSArray*)) {
NSLog(@"socket connected"); NSLog(@"socket connected");
@ -56,17 +56,18 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8
##Installation ##Installation
Requires Swift 2/Xcode 7 Requires Swift 2/Xcode 7
If you need Swift 1.2/Xcode 6.3/4 use v2 (Pre-Swift 2 support is no longer maintained) If you need Swift 1.2/Xcode 6.3/4 use v2.4.5 (Pre-Swift 2 support is no longer maintained)
If you need Swift 1.1/Xcode 6.2 use v1.5.2. (Pre-Swift 1.2 support is no longer maintained) If you need Swift 1.1/Xcode 6.2 use v1.5.2. (Pre-Swift 1.2 support is no longer maintained)
Carthage Carthage
----------------- -----------------
Add this line to your `Cartfile`: Add this line to your `Cartfile`:
``` ```
github "socketio/socket.io-client-swift" ~> 2.4.3 # Or latest version github "socketio/socket.io-client-swift" ~> 3.0.2 # Or latest version
``` ```
Run `carthage update`. Run `carthage update --platform ios,macosx`.
Manually (iOS 7+) Manually (iOS 7+)
----------------- -----------------
@ -82,7 +83,7 @@ source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0' platform :ios, '8.0'
use_frameworks! use_frameworks!
pod 'Socket.IO-Client-Swift', '~> 2.4.3' # Or latest version pod 'Socket.IO-Client-Swift', '~> 3.0.2' # Or latest version
``` ```
Install pods: Install pods:
@ -106,9 +107,7 @@ Objective-C:
##API ##API
Constructors Constructors
----------- -----------
`init(socketURL: String, opts:NSDictionary? = nil)` - Constructs a new client for the given URL. opts can be omitted (will use default values) `init(socketURL: String, opts: NSDictionary? = nil)` - Constructs a new client for the given URL. opts can be omitted (will use default values) note: If your socket.io server is secure, you need to specify `https` in your socketURL.
`convenience init(socketURL: String, options:NSDictionary?)` - Same as above, but meant for Objective-C. See Objective-C Example.
Options Options
------- -------
@ -129,19 +128,21 @@ Options
Methods Methods
------- -------
1. `on(name:String, callback:((data:NSArray?, ack:AckEmitter?) -> Void))` - Adds a handler for an event. Items are passed by an array. `ack` can be used to send an ack when one is requested. See example. 1. `on(name: String, callback: ((data: NSArray?, ack: AckEmitter?) -> Void))` - Adds a handler for an event. Items are passed by an array. `ack` can be used to send an ack when one is requested. See example.
2. `onObjectiveC(name:String, callback:((data:NSArray?, ack:AckEmitter?) -> Void))` - Adds a handler for an event. Items are passed by an array. `ack` can be used to send an ack when one is requested. See example. 2. `onObjectiveC(name: String, callback: ((data: NSArray?, ack: AckEmitter?) -> Void))` - Adds a handler for an event. Items are passed by an array. `ack` can be used to send an ack when one is requested. See example.
3. `onAny(callback:((event:String, items:AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event. 3. `onAny(callback:((event: String, items: AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event.
4. `emit(event:String, _ items:AnyObject...)` - Sends a message. Can send multiple items. 4. `emit(event: String, _ items: AnyObject...)` - Sends a message. Can send multiple items.
5. `emit(event:String, withItems items:[AnyObject])` - `emit` for Objective-C 5. `emit(event: String, withItems items: [AnyObject])` - `emit` for Objective-C
6. `emitWithAck(event:String, _ items:AnyObject...) -> (timeoutAfter:UInt64, callback:(NSArray?) -> Void) -> Void` - Sends a message that requests an acknowledgement from the server. Returns a function which you can use to add a handler. See example. Note: The message is not sent until you call the returned function. 6. `emitWithAck(event: String, _ items: AnyObject...) -> (timeoutAfter: UInt64, callback: (NSArray?) -> Void) -> Void` - Sends a message that requests an acknowledgement from the server. Returns a function which you can use to add a handler. See example. Note: The message is not sent until you call the returned function.
7. `emitWithAck(event:String, withItems items:[AnyObject]) -> (UInt64, (NSArray?) -> Void) -> Void` - `emitWithAck` for Objective-C. Note: The message is not sent until you call the returned function. 7. `emitWithAck(event: String, withItems items: [AnyObject]) -> (UInt64, (NSArray?) -> Void) -> Void` - `emitWithAck` for Objective-C. Note: The message is not sent until you call the returned function.
8. `connect()` - Establishes a connection to the server. A "connect" event is fired upon successful connection. 8. `connect()` - Establishes a connection to the server. A "connect" event is fired upon successful connection.
9. `connect(#timeoutAfter:Int, withTimeoutHandler handler:(() -> Void)?)` - Connect to the server. If it isn't connected after timeoutAfter seconds, the handler is called. 9. `connect(timeoutAfter timeoutAfter: Int, withTimeoutHandler handler: (() -> Void)?)` - Connect to the server. If it isn't connected after timeoutAfter seconds, the handler is called.
10. `close(#fast:Bool)` - Closes the socket. Once a socket is closed it should not be reopened. Pass true to fast if you're closing from a background task. 10. `close()` - Closes the socket. Once a socket is closed it should not be reopened.
11. `reconnect()` - Causes the client to reconnect to the server. 11. `reconnect()` - Causes the client to reconnect to the server.
12. `joinNamespace()` - Causes the client to join nsp. Shouldn't need to be called unless you change nsp manually. 12. `joinNamespace()` - Causes the client to join nsp. Shouldn't need to be called unless you change nsp manually.
13. `leaveNamespace()` - Causes the client to leave the nsp and go back to / 13. `leaveNamespace()` - Causes the client to leave the nsp and go back to /
14. `once(event: String, callback: NormalCallback)` - Adds a handler that will only be executed once.
15. `once(event event: String, callback: NormalCallbackObjectiveC)` - Adds a handler that will only be executed once.
Client Events Client Events
------ ------

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "Socket.IO-Client-Swift" s.name = "Socket.IO-Client-Swift"
s.version = "2.4.3" s.version = "3.0.2"
s.summary = "Socket.IO-client for iOS and OS X" s.summary = "Socket.IO-client for iOS and OS X"
s.description = <<-DESC s.description = <<-DESC
Socket.IO-client for iOS and OS X. Socket.IO-client for iOS and OS X.
@ -12,7 +12,7 @@ Pod::Spec.new do |s|
s.author = { "Erik" => "nuclear.ace@gmail.com" } s.author = { "Erik" => "nuclear.ace@gmail.com" }
s.ios.deployment_target = '8.0' s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.10' s.osx.deployment_target = '10.10'
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v2.4.3' } s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v3.0.2' }
s.source_files = "SocketIOClientSwift/**/*.swift" s.source_files = "SocketIOClientSwift/**/*.swift"
s.requires_arc = true s.requires_arc = true
# s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files # s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files

View File

@ -12,6 +12,47 @@
572EF23D1B51F18A00EEBB58 /* SocketIO-Mac.h in Headers */ = {isa = PBXBuildFile; fileRef = 572EF23C1B51F18A00EEBB58 /* SocketIO-Mac.h */; settings = {ATTRIBUTES = (Public, ); }; }; 572EF23D1B51F18A00EEBB58 /* SocketIO-Mac.h in Headers */ = {isa = PBXBuildFile; fileRef = 572EF23C1B51F18A00EEBB58 /* SocketIO-Mac.h */; settings = {ATTRIBUTES = (Public, ); }; };
572EF2431B51F18A00EEBB58 /* SocketIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 572EF2381B51F18A00EEBB58 /* SocketIO.framework */; }; 572EF2431B51F18A00EEBB58 /* SocketIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 572EF2381B51F18A00EEBB58 /* SocketIO.framework */; };
572EF24A1B51F18A00EEBB58 /* SocketIO_MacTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 572EF2491B51F18A00EEBB58 /* SocketIO_MacTests.swift */; }; 572EF24A1B51F18A00EEBB58 /* SocketIO_MacTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 572EF2491B51F18A00EEBB58 /* SocketIO_MacTests.swift */; };
57425F9C1BA3A46000BDAAC1 /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
57425F9D1BA3A46000BDAAC1 /* SocketEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7E1B51F254004FF46E /* SocketEngine.swift */; };
57425F9E1BA3A46000BDAAC1 /* SocketParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF851B51F254004FF46E /* SocketParser.swift */; };
57425F9F1BA3A46000BDAAC1 /* SocketTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF861B51F254004FF46E /* SocketTypes.swift */; };
57425FA01BA3A46000BDAAC1 /* SocketEngineClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7F1B51F254004FF46E /* SocketEngineClient.swift */; };
57425FA11BA3A46000BDAAC1 /* SocketEventHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF801B51F254004FF46E /* SocketEventHandler.swift */; };
57425FA21BA3A46000BDAAC1 /* SocketFixUTF8.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF811B51F254004FF46E /* SocketFixUTF8.swift */; };
57425FA31BA3A46000BDAAC1 /* SocketIOClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF821B51F254004FF46E /* SocketIOClient.swift */; };
57425FA41BA3A46000BDAAC1 /* SocketAnyEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */; };
57425FA51BA3A46000BDAAC1 /* SocketLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF831B51F254004FF46E /* SocketLogger.swift */; };
57425FA61BA3A46000BDAAC1 /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
57425FA71BA3A46000BDAAC1 /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF881B51F254004FF46E /* WebSocket.swift */; };
57425FA81BA3A46000BDAAC1 /* SocketPacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF841B51F254004FF46E /* SocketPacket.swift */; };
57425FA91BA3A46000BDAAC1 /* SocketAckManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7C1B51F254004FF46E /* SocketAckManager.swift */; };
57425FAA1BA3A46000BDAAC1 /* SwiftRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF871B51F254004FF46E /* SwiftRegex.swift */; };
57425FAD1BA3A46000BDAAC1 /* SocketIO-iOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 572EF21E1B51F16C00EEBB58 /* SocketIO-iOS.h */; settings = {ATTRIBUTES = (Public, ); }; };
57425FDC1BA3A4F100BDAAC1 /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
57425FDD1BA3A4F100BDAAC1 /* SocketParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF851B51F254004FF46E /* SocketParser.swift */; };
57425FDE1BA3A4F100BDAAC1 /* SocketPacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF841B51F254004FF46E /* SocketPacket.swift */; };
57425FDF1BA3A4F100BDAAC1 /* SocketFixUTF8.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF811B51F254004FF46E /* SocketFixUTF8.swift */; };
57425FE01BA3A4F100BDAAC1 /* SocketEventHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF801B51F254004FF46E /* SocketEventHandler.swift */; };
57425FE11BA3A4F100BDAAC1 /* SocketTestCases.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94CB8F0A1B6E48B90019ED53 /* SocketTestCases.swift */; };
57425FE21BA3A4F100BDAAC1 /* SocketEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7E1B51F254004FF46E /* SocketEngine.swift */; };
57425FE31BA3A4F100BDAAC1 /* SocketAckManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7C1B51F254004FF46E /* SocketAckManager.swift */; };
57425FE41BA3A4F100BDAAC1 /* TestKind.swift in Sources */ = {isa = PBXBuildFile; fileRef = 941A4AB91B67A56C00C42318 /* TestKind.swift */; };
57425FE51BA3A4F100BDAAC1 /* AbstractSocketTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94CB8F0C1B6E66E60019ED53 /* AbstractSocketTest.swift */; };
57425FE61BA3A4F100BDAAC1 /* SocketEmitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 945B65421B63D9DB0081E995 /* SocketEmitTest.swift */; };
57425FE71BA3A4F100BDAAC1 /* SwiftRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF871B51F254004FF46E /* SwiftRegex.swift */; };
57425FE81BA3A4F100BDAAC1 /* SocketLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF831B51F254004FF46E /* SocketLogger.swift */; };
57425FE91BA3A4F100BDAAC1 /* SocketAckManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */; };
57425FEA1BA3A4F100BDAAC1 /* SocketEngineClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7F1B51F254004FF46E /* SocketEngineClient.swift */; };
57425FEB1BA3A4F100BDAAC1 /* SocketAnyEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */; };
57425FEC1BA3A4F100BDAAC1 /* SocketAcknowledgementTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94ADAC4A1B6632DD00FD79AE /* SocketAcknowledgementTest.swift */; };
57425FED1BA3A4F100BDAAC1 /* SocketTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF861B51F254004FF46E /* SocketTypes.swift */; };
57425FEE1BA3A4F100BDAAC1 /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
57425FEF1BA3A4F100BDAAC1 /* SocketIOClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF821B51F254004FF46E /* SocketIOClient.swift */; };
57425FF01BA3A4F100BDAAC1 /* SocketParserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */; };
57425FF11BA3A4F100BDAAC1 /* SocketNamespaceEmitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94ADAC481B652D3300FD79AE /* SocketNamespaceEmitTest.swift */; };
57425FF21BA3A4F100BDAAC1 /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF881B51F254004FF46E /* WebSocket.swift */; };
57425FF31BA3A4F100BDAAC1 /* SocketNamespaceAcknowledgementTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift */; };
57425FF51BA3A4F100BDAAC1 /* SocketIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 572EF2191B51F16C00EEBB58 /* SocketIO.framework */; };
5764DF891B51F254004FF46E /* SocketAckManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7C1B51F254004FF46E /* SocketAckManager.swift */; }; 5764DF891B51F254004FF46E /* SocketAckManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7C1B51F254004FF46E /* SocketAckManager.swift */; };
5764DF8A1B51F254004FF46E /* SocketAckManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7C1B51F254004FF46E /* SocketAckManager.swift */; }; 5764DF8A1B51F254004FF46E /* SocketAckManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7C1B51F254004FF46E /* SocketAckManager.swift */; };
5764DF8B1B51F254004FF46E /* SocketAnyEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */; }; 5764DF8B1B51F254004FF46E /* SocketAnyEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */; };
@ -42,6 +83,9 @@
74781D5B1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; }; 74781D5B1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
74781D5C1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; }; 74781D5C1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
74781D5D1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; }; 74781D5D1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */; };
74D765621B9F0D870028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
74D765631B9F0D9F0028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
74D765641B9F0DA40028551C /* SocketStringReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74D765611B9F0D870028551C /* SocketStringReader.swift */; };
941A4ABA1B67A56C00C42318 /* TestKind.swift in Sources */ = {isa = PBXBuildFile; fileRef = 941A4AB91B67A56C00C42318 /* TestKind.swift */; }; 941A4ABA1B67A56C00C42318 /* TestKind.swift in Sources */ = {isa = PBXBuildFile; fileRef = 941A4AB91B67A56C00C42318 /* TestKind.swift */; };
94242BB81B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift */; }; 94242BB81B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift */; };
945B65351B5FCEEA0081E995 /* SocketAckManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7C1B51F254004FF46E /* SocketAckManager.swift */; }; 945B65351B5FCEEA0081E995 /* SocketAckManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7C1B51F254004FF46E /* SocketAckManager.swift */; };
@ -58,6 +102,8 @@
945B65401B5FCEEA0081E995 /* SwiftRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF871B51F254004FF46E /* SwiftRegex.swift */; }; 945B65401B5FCEEA0081E995 /* SwiftRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF871B51F254004FF46E /* SwiftRegex.swift */; };
945B65411B5FCEEA0081E995 /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF881B51F254004FF46E /* WebSocket.swift */; }; 945B65411B5FCEEA0081E995 /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF881B51F254004FF46E /* WebSocket.swift */; };
945B65431B63D9DB0081E995 /* SocketEmitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 945B65421B63D9DB0081E995 /* SocketEmitTest.swift */; }; 945B65431B63D9DB0081E995 /* SocketEmitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 945B65421B63D9DB0081E995 /* SocketEmitTest.swift */; };
949FAE8D1B9B94E600073BE9 /* SocketParserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */; };
94A20D611B99E22F00BF9E44 /* SocketAckManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */; };
94ADAC491B652D3300FD79AE /* SocketNamespaceEmitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94ADAC481B652D3300FD79AE /* SocketNamespaceEmitTest.swift */; }; 94ADAC491B652D3300FD79AE /* SocketNamespaceEmitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94ADAC481B652D3300FD79AE /* SocketNamespaceEmitTest.swift */; };
94ADAC4B1B6632DD00FD79AE /* SocketAcknowledgementTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94ADAC4A1B6632DD00FD79AE /* SocketAcknowledgementTest.swift */; }; 94ADAC4B1B6632DD00FD79AE /* SocketAcknowledgementTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94ADAC4A1B6632DD00FD79AE /* SocketAcknowledgementTest.swift */; };
94CB8F0B1B6E48B90019ED53 /* SocketTestCases.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94CB8F0A1B6E48B90019ED53 /* SocketTestCases.swift */; }; 94CB8F0B1B6E48B90019ED53 /* SocketTestCases.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94CB8F0A1B6E48B90019ED53 /* SocketTestCases.swift */; };
@ -79,6 +125,13 @@
remoteGlobalIDString = 572EF2371B51F18A00EEBB58; remoteGlobalIDString = 572EF2371B51F18A00EEBB58;
remoteInfo = "SocketIO-Mac"; remoteInfo = "SocketIO-Mac";
}; };
57425FDA1BA3A4F100BDAAC1 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 572EF20E1B51F12F00EEBB58 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 572EF2181B51F16C00EEBB58;
remoteInfo = "SocketIO-iOS";
};
/* End PBXContainerItemProxy section */ /* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
@ -93,6 +146,8 @@
572EF2421B51F18A00EEBB58 /* SocketIO-MacTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SocketIO-MacTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 572EF2421B51F18A00EEBB58 /* SocketIO-MacTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SocketIO-MacTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
572EF2481B51F18A00EEBB58 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 572EF2481B51F18A00EEBB58 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
572EF2491B51F18A00EEBB58 /* SocketIO_MacTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketIO_MacTests.swift; sourceTree = "<group>"; }; 572EF2491B51F18A00EEBB58 /* SocketIO_MacTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketIO_MacTests.swift; sourceTree = "<group>"; };
57425FB21BA3A46000BDAAC1 /* SocketIO.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SocketIO.framework; sourceTree = BUILT_PRODUCTS_DIR; };
57425FFA1BA3A4F100BDAAC1 /* SocketIO-tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SocketIO-tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
5764DF7C1B51F254004FF46E /* SocketAckManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketAckManager.swift; path = SocketIOClientSwift/SocketAckManager.swift; sourceTree = "<group>"; }; 5764DF7C1B51F254004FF46E /* SocketAckManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketAckManager.swift; path = SocketIOClientSwift/SocketAckManager.swift; sourceTree = "<group>"; };
5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketAnyEvent.swift; path = SocketIOClientSwift/SocketAnyEvent.swift; sourceTree = "<group>"; }; 5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketAnyEvent.swift; path = SocketIOClientSwift/SocketAnyEvent.swift; sourceTree = "<group>"; };
5764DF7E1B51F254004FF46E /* SocketEngine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketEngine.swift; path = SocketIOClientSwift/SocketEngine.swift; sourceTree = "<group>"; }; 5764DF7E1B51F254004FF46E /* SocketEngine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketEngine.swift; path = SocketIOClientSwift/SocketEngine.swift; sourceTree = "<group>"; };
@ -107,9 +162,12 @@
5764DF871B51F254004FF46E /* SwiftRegex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftRegex.swift; path = SocketIOClientSwift/SwiftRegex.swift; sourceTree = "<group>"; }; 5764DF871B51F254004FF46E /* SwiftRegex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftRegex.swift; path = SocketIOClientSwift/SwiftRegex.swift; sourceTree = "<group>"; };
5764DF881B51F254004FF46E /* WebSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WebSocket.swift; path = SocketIOClientSwift/WebSocket.swift; sourceTree = "<group>"; }; 5764DF881B51F254004FF46E /* WebSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WebSocket.swift; path = SocketIOClientSwift/WebSocket.swift; sourceTree = "<group>"; };
74781D591B7E83930042CACA /* SocketIOClientStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketIOClientStatus.swift; path = SocketIOClientSwift/SocketIOClientStatus.swift; sourceTree = "<group>"; }; 74781D591B7E83930042CACA /* SocketIOClientStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketIOClientStatus.swift; path = SocketIOClientSwift/SocketIOClientStatus.swift; sourceTree = "<group>"; };
74D765611B9F0D870028551C /* SocketStringReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SocketStringReader.swift; path = SocketIOClientSwift/SocketStringReader.swift; sourceTree = "<group>"; };
941A4AB91B67A56C00C42318 /* TestKind.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestKind.swift; sourceTree = "<group>"; }; 941A4AB91B67A56C00C42318 /* TestKind.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestKind.swift; sourceTree = "<group>"; };
94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketNamespaceAcknowledgementTest.swift; sourceTree = "<group>"; }; 94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketNamespaceAcknowledgementTest.swift; sourceTree = "<group>"; };
945B65421B63D9DB0081E995 /* SocketEmitTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketEmitTest.swift; sourceTree = "<group>"; }; 945B65421B63D9DB0081E995 /* SocketEmitTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketEmitTest.swift; sourceTree = "<group>"; };
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketParserTest.swift; sourceTree = "<group>"; };
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketAckManagerTest.swift; sourceTree = "<group>"; };
94ADAC481B652D3300FD79AE /* SocketNamespaceEmitTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketNamespaceEmitTest.swift; sourceTree = "<group>"; }; 94ADAC481B652D3300FD79AE /* SocketNamespaceEmitTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketNamespaceEmitTest.swift; sourceTree = "<group>"; };
94ADAC4A1B6632DD00FD79AE /* SocketAcknowledgementTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketAcknowledgementTest.swift; sourceTree = "<group>"; }; 94ADAC4A1B6632DD00FD79AE /* SocketAcknowledgementTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketAcknowledgementTest.swift; sourceTree = "<group>"; };
94CB8F0A1B6E48B90019ED53 /* SocketTestCases.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketTestCases.swift; sourceTree = "<group>"; }; 94CB8F0A1B6E48B90019ED53 /* SocketTestCases.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketTestCases.swift; sourceTree = "<group>"; };
@ -147,6 +205,21 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
57425FAB1BA3A46000BDAAC1 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
57425FF41BA3A4F100BDAAC1 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
57425FF51BA3A4F100BDAAC1 /* SocketIO.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */ /* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */ /* Begin PBXGroup section */
@ -169,6 +242,8 @@
572EF2241B51F16C00EEBB58 /* SocketIO-iOSTests.xctest */, 572EF2241B51F16C00EEBB58 /* SocketIO-iOSTests.xctest */,
572EF2381B51F18A00EEBB58 /* SocketIO.framework */, 572EF2381B51F18A00EEBB58 /* SocketIO.framework */,
572EF2421B51F18A00EEBB58 /* SocketIO-MacTests.xctest */, 572EF2421B51F18A00EEBB58 /* SocketIO-MacTests.xctest */,
57425FB21BA3A46000BDAAC1 /* SocketIO.framework */,
57425FFA1BA3A4F100BDAAC1 /* SocketIO-tvOSTests.xctest */,
); );
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
@ -200,7 +275,9 @@
941A4AB91B67A56C00C42318 /* TestKind.swift */, 941A4AB91B67A56C00C42318 /* TestKind.swift */,
94CB8F0A1B6E48B90019ED53 /* SocketTestCases.swift */, 94CB8F0A1B6E48B90019ED53 /* SocketTestCases.swift */,
94CB8F0C1B6E66E60019ED53 /* AbstractSocketTest.swift */, 94CB8F0C1B6E66E60019ED53 /* AbstractSocketTest.swift */,
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */,
572EF2291B51F16C00EEBB58 /* Supporting Files */, 572EF2291B51F16C00EEBB58 /* Supporting Files */,
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */,
); );
path = "SocketIO-iOSTests"; path = "SocketIO-iOSTests";
sourceTree = "<group>"; sourceTree = "<group>";
@ -261,6 +338,7 @@
5764DF831B51F254004FF46E /* SocketLogger.swift */, 5764DF831B51F254004FF46E /* SocketLogger.swift */,
5764DF841B51F254004FF46E /* SocketPacket.swift */, 5764DF841B51F254004FF46E /* SocketPacket.swift */,
5764DF851B51F254004FF46E /* SocketParser.swift */, 5764DF851B51F254004FF46E /* SocketParser.swift */,
74D765611B9F0D870028551C /* SocketStringReader.swift */,
5764DF861B51F254004FF46E /* SocketTypes.swift */, 5764DF861B51F254004FF46E /* SocketTypes.swift */,
5764DF871B51F254004FF46E /* SwiftRegex.swift */, 5764DF871B51F254004FF46E /* SwiftRegex.swift */,
5764DF881B51F254004FF46E /* WebSocket.swift */, 5764DF881B51F254004FF46E /* WebSocket.swift */,
@ -287,6 +365,14 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
57425FAC1BA3A46000BDAAC1 /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
57425FAD1BA3A46000BDAAC1 /* SocketIO-iOS.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */ /* End PBXHeadersBuildPhase section */
/* Begin PBXNativeTarget section */ /* Begin PBXNativeTarget section */
@ -362,6 +448,42 @@
productReference = 572EF2421B51F18A00EEBB58 /* SocketIO-MacTests.xctest */; productReference = 572EF2421B51F18A00EEBB58 /* SocketIO-MacTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test"; productType = "com.apple.product-type.bundle.unit-test";
}; };
57425F9A1BA3A46000BDAAC1 /* SocketIO-tvOS */ = {
isa = PBXNativeTarget;
buildConfigurationList = 57425FAF1BA3A46000BDAAC1 /* Build configuration list for PBXNativeTarget "SocketIO-tvOS" */;
buildPhases = (
57425F9B1BA3A46000BDAAC1 /* Sources */,
57425FAB1BA3A46000BDAAC1 /* Frameworks */,
57425FAC1BA3A46000BDAAC1 /* Headers */,
57425FAE1BA3A46000BDAAC1 /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = "SocketIO-tvOS";
productName = "SocketIO-iOS";
productReference = 57425FB21BA3A46000BDAAC1 /* SocketIO.framework */;
productType = "com.apple.product-type.framework";
};
57425FD81BA3A4F100BDAAC1 /* SocketIO-tvOSTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 57425FF71BA3A4F100BDAAC1 /* Build configuration list for PBXNativeTarget "SocketIO-tvOSTests" */;
buildPhases = (
57425FDB1BA3A4F100BDAAC1 /* Sources */,
57425FF41BA3A4F100BDAAC1 /* Frameworks */,
57425FF61BA3A4F100BDAAC1 /* Resources */,
);
buildRules = (
);
dependencies = (
57425FD91BA3A4F100BDAAC1 /* PBXTargetDependency */,
);
name = "SocketIO-tvOSTests";
productName = "SocketIO-iOSTests";
productReference = 57425FFA1BA3A4F100BDAAC1 /* SocketIO-tvOSTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */ /* End PBXNativeTarget section */
/* Begin PBXProject section */ /* Begin PBXProject section */
@ -399,6 +521,8 @@
targets = ( targets = (
572EF2181B51F16C00EEBB58 /* SocketIO-iOS */, 572EF2181B51F16C00EEBB58 /* SocketIO-iOS */,
572EF2231B51F16C00EEBB58 /* SocketIO-iOSTests */, 572EF2231B51F16C00EEBB58 /* SocketIO-iOSTests */,
57425F9A1BA3A46000BDAAC1 /* SocketIO-tvOS */,
57425FD81BA3A4F100BDAAC1 /* SocketIO-tvOSTests */,
572EF2371B51F18A00EEBB58 /* SocketIO-Mac */, 572EF2371B51F18A00EEBB58 /* SocketIO-Mac */,
572EF2411B51F18A00EEBB58 /* SocketIO-MacTests */, 572EF2411B51F18A00EEBB58 /* SocketIO-MacTests */,
); );
@ -434,6 +558,20 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
57425FAE1BA3A46000BDAAC1 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
57425FF61BA3A4F100BDAAC1 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */ /* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */
@ -441,6 +579,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
74D765631B9F0D9F0028551C /* SocketStringReader.swift in Sources */,
5764DF8D1B51F254004FF46E /* SocketEngine.swift in Sources */, 5764DF8D1B51F254004FF46E /* SocketEngine.swift in Sources */,
5764DF9B1B51F254004FF46E /* SocketParser.swift in Sources */, 5764DF9B1B51F254004FF46E /* SocketParser.swift in Sources */,
5764DF9D1B51F254004FF46E /* SocketTypes.swift in Sources */, 5764DF9D1B51F254004FF46E /* SocketTypes.swift in Sources */,
@ -462,6 +601,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
74D765621B9F0D870028551C /* SocketStringReader.swift in Sources */,
945B653E1B5FCEEA0081E995 /* SocketParser.swift in Sources */, 945B653E1B5FCEEA0081E995 /* SocketParser.swift in Sources */,
945B653D1B5FCEEA0081E995 /* SocketPacket.swift in Sources */, 945B653D1B5FCEEA0081E995 /* SocketPacket.swift in Sources */,
945B653A1B5FCEEA0081E995 /* SocketFixUTF8.swift in Sources */, 945B653A1B5FCEEA0081E995 /* SocketFixUTF8.swift in Sources */,
@ -474,12 +614,14 @@
945B65431B63D9DB0081E995 /* SocketEmitTest.swift in Sources */, 945B65431B63D9DB0081E995 /* SocketEmitTest.swift in Sources */,
945B65401B5FCEEA0081E995 /* SwiftRegex.swift in Sources */, 945B65401B5FCEEA0081E995 /* SwiftRegex.swift in Sources */,
945B653C1B5FCEEA0081E995 /* SocketLogger.swift in Sources */, 945B653C1B5FCEEA0081E995 /* SocketLogger.swift in Sources */,
94A20D611B99E22F00BF9E44 /* SocketAckManagerTest.swift in Sources */,
945B65381B5FCEEA0081E995 /* SocketEngineClient.swift in Sources */, 945B65381B5FCEEA0081E995 /* SocketEngineClient.swift in Sources */,
945B65361B5FCEEA0081E995 /* SocketAnyEvent.swift in Sources */, 945B65361B5FCEEA0081E995 /* SocketAnyEvent.swift in Sources */,
94ADAC4B1B6632DD00FD79AE /* SocketAcknowledgementTest.swift in Sources */, 94ADAC4B1B6632DD00FD79AE /* SocketAcknowledgementTest.swift in Sources */,
945B653F1B5FCEEA0081E995 /* SocketTypes.swift in Sources */, 945B653F1B5FCEEA0081E995 /* SocketTypes.swift in Sources */,
74781D5B1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */, 74781D5B1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */,
945B653B1B5FCEEA0081E995 /* SocketIOClient.swift in Sources */, 945B653B1B5FCEEA0081E995 /* SocketIOClient.swift in Sources */,
949FAE8D1B9B94E600073BE9 /* SocketParserTest.swift in Sources */,
94ADAC491B652D3300FD79AE /* SocketNamespaceEmitTest.swift in Sources */, 94ADAC491B652D3300FD79AE /* SocketNamespaceEmitTest.swift in Sources */,
945B65411B5FCEEA0081E995 /* WebSocket.swift in Sources */, 945B65411B5FCEEA0081E995 /* WebSocket.swift in Sources */,
94242BB81B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift in Sources */, 94242BB81B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift in Sources */,
@ -490,6 +632,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
74D765641B9F0DA40028551C /* SocketStringReader.swift in Sources */,
5764DF8E1B51F254004FF46E /* SocketEngine.swift in Sources */, 5764DF8E1B51F254004FF46E /* SocketEngine.swift in Sources */,
5764DF9C1B51F254004FF46E /* SocketParser.swift in Sources */, 5764DF9C1B51F254004FF46E /* SocketParser.swift in Sources */,
5764DF9E1B51F254004FF46E /* SocketTypes.swift in Sources */, 5764DF9E1B51F254004FF46E /* SocketTypes.swift in Sources */,
@ -516,6 +659,59 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
57425F9B1BA3A46000BDAAC1 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
57425F9C1BA3A46000BDAAC1 /* SocketStringReader.swift in Sources */,
57425F9D1BA3A46000BDAAC1 /* SocketEngine.swift in Sources */,
57425F9E1BA3A46000BDAAC1 /* SocketParser.swift in Sources */,
57425F9F1BA3A46000BDAAC1 /* SocketTypes.swift in Sources */,
57425FA01BA3A46000BDAAC1 /* SocketEngineClient.swift in Sources */,
57425FA11BA3A46000BDAAC1 /* SocketEventHandler.swift in Sources */,
57425FA21BA3A46000BDAAC1 /* SocketFixUTF8.swift in Sources */,
57425FA31BA3A46000BDAAC1 /* SocketIOClient.swift in Sources */,
57425FA41BA3A46000BDAAC1 /* SocketAnyEvent.swift in Sources */,
57425FA51BA3A46000BDAAC1 /* SocketLogger.swift in Sources */,
57425FA61BA3A46000BDAAC1 /* SocketIOClientStatus.swift in Sources */,
57425FA71BA3A46000BDAAC1 /* WebSocket.swift in Sources */,
57425FA81BA3A46000BDAAC1 /* SocketPacket.swift in Sources */,
57425FA91BA3A46000BDAAC1 /* SocketAckManager.swift in Sources */,
57425FAA1BA3A46000BDAAC1 /* SwiftRegex.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
57425FDB1BA3A4F100BDAAC1 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
57425FDC1BA3A4F100BDAAC1 /* SocketStringReader.swift in Sources */,
57425FDD1BA3A4F100BDAAC1 /* SocketParser.swift in Sources */,
57425FDE1BA3A4F100BDAAC1 /* SocketPacket.swift in Sources */,
57425FDF1BA3A4F100BDAAC1 /* SocketFixUTF8.swift in Sources */,
57425FE01BA3A4F100BDAAC1 /* SocketEventHandler.swift in Sources */,
57425FE11BA3A4F100BDAAC1 /* SocketTestCases.swift in Sources */,
57425FE21BA3A4F100BDAAC1 /* SocketEngine.swift in Sources */,
57425FE31BA3A4F100BDAAC1 /* SocketAckManager.swift in Sources */,
57425FE41BA3A4F100BDAAC1 /* TestKind.swift in Sources */,
57425FE51BA3A4F100BDAAC1 /* AbstractSocketTest.swift in Sources */,
57425FE61BA3A4F100BDAAC1 /* SocketEmitTest.swift in Sources */,
57425FE71BA3A4F100BDAAC1 /* SwiftRegex.swift in Sources */,
57425FE81BA3A4F100BDAAC1 /* SocketLogger.swift in Sources */,
57425FE91BA3A4F100BDAAC1 /* SocketAckManagerTest.swift in Sources */,
57425FEA1BA3A4F100BDAAC1 /* SocketEngineClient.swift in Sources */,
57425FEB1BA3A4F100BDAAC1 /* SocketAnyEvent.swift in Sources */,
57425FEC1BA3A4F100BDAAC1 /* SocketAcknowledgementTest.swift in Sources */,
57425FED1BA3A4F100BDAAC1 /* SocketTypes.swift in Sources */,
57425FEE1BA3A4F100BDAAC1 /* SocketIOClientStatus.swift in Sources */,
57425FEF1BA3A4F100BDAAC1 /* SocketIOClient.swift in Sources */,
57425FF01BA3A4F100BDAAC1 /* SocketParserTest.swift in Sources */,
57425FF11BA3A4F100BDAAC1 /* SocketNamespaceEmitTest.swift in Sources */,
57425FF21BA3A4F100BDAAC1 /* WebSocket.swift in Sources */,
57425FF31BA3A4F100BDAAC1 /* SocketNamespaceAcknowledgementTest.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */ /* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */ /* Begin PBXTargetDependency section */
@ -529,6 +725,11 @@
target = 572EF2371B51F18A00EEBB58 /* SocketIO-Mac */; target = 572EF2371B51F18A00EEBB58 /* SocketIO-Mac */;
targetProxy = 572EF2441B51F18A00EEBB58 /* PBXContainerItemProxy */; targetProxy = 572EF2441B51F18A00EEBB58 /* PBXContainerItemProxy */;
}; };
57425FD91BA3A4F100BDAAC1 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 572EF2181B51F16C00EEBB58 /* SocketIO-iOS */;
targetProxy = 57425FDA1BA3A4F100BDAAC1 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */ /* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */ /* Begin XCBuildConfiguration section */
@ -943,6 +1144,203 @@
}; };
name = Release; name = Release;
}; };
57425FB01BA3A46000BDAAC1 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = "SocketIO-iOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = 3;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
name = Debug;
};
57425FB11BA3A46000BDAAC1 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = "SocketIO-iOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = 3;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
name = Release;
};
57425FF81BA3A4F100BDAAC1 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = "SocketIO-iOSTests/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.4;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
};
name = Debug;
};
57425FF91BA3A4F100BDAAC1 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = "SocketIO-iOSTests/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.4;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
/* End XCBuildConfiguration section */ /* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */ /* Begin XCConfigurationList section */
@ -991,6 +1389,24 @@
defaultConfigurationIsVisible = 0; defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release; defaultConfigurationName = Release;
}; };
57425FAF1BA3A46000BDAAC1 /* Build configuration list for PBXNativeTarget "SocketIO-tvOS" */ = {
isa = XCConfigurationList;
buildConfigurations = (
57425FB01BA3A46000BDAAC1 /* Debug */,
57425FB11BA3A46000BDAAC1 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
57425FF71BA3A4F100BDAAC1 /* Build configuration list for PBXNativeTarget "SocketIO-tvOSTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
57425FF81BA3A4F100BDAAC1 /* Debug */,
57425FF91BA3A4F100BDAAC1 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */ /* End XCConfigurationList section */
}; };
rootObject = 572EF20E1B51F12F00EEBB58 /* Project object */; rootObject = 572EF20E1B51F12F00EEBB58 /* Project object */;

View File

@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "57425F9A1BA3A46000BDAAC1"
BuildableName = "SocketIO.framework"
BlueprintName = "SocketIO-tvOS"
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "57425FD81BA3A4F100BDAAC1"
BuildableName = "SocketIO-tvOSTests.xctest"
BlueprintName = "SocketIO-tvOSTests"
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "57425FD81BA3A4F100BDAAC1"
BuildableName = "SocketIO-tvOSTests.xctest"
BlueprintName = "SocketIO-tvOSTests"
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "57425F9A1BA3A46000BDAAC1"
BuildableName = "SocketIO.framework"
BlueprintName = "SocketIO-tvOS"
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "57425F9A1BA3A46000BDAAC1"
BuildableName = "SocketIO.framework"
BlueprintName = "SocketIO-tvOS"
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "57425F9A1BA3A46000BDAAC1"
BuildableName = "SocketIO.framework"
BlueprintName = "SocketIO-tvOS"
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,26 @@
//
// SocketAckManagerTest.swift
// Socket.IO-Client-Swift
//
// Created by Lukas Schmidt on 04.09.15.
//
//
import XCTest
class SocketAckManagerTest: XCTestCase {
var ackManager = SocketAckManager()
func testAddAcks() {
let callbackExpection = self.expectationWithDescription("callbackExpection")
let itemsArray = ["Hi", "ho"]
func callback(items: NSArray?) {
callbackExpection.fulfill()
items?.isEqualToArray(itemsArray)
}
ackManager.addAck(1, callback: callback)
ackManager.executeAck(1, items: itemsArray)
waitForExpectationsWithTimeout(3.0, handler: nil)
}
}

View File

@ -21,11 +21,12 @@ class SocketAcknowledgementTest: AbstractSocketTest {
"forcePolling": false, "forcePolling": false,
"forceWebsockets": false,// default false "forceWebsockets": false,// default false
"path": ""]) "path": ""])
openConnection()
}else { }else {
AbstractSocketTest.socket.leaveNamespace() AbstractSocketTest.socket.leaveNamespace()
} }
openConnection()
} }
func testConnectionStatus() { func testConnectionStatus() {

View File

@ -22,11 +22,12 @@ class SocketEmitTest: AbstractSocketTest {
"forceWebsockets": false,// default false "forceWebsockets": false,// default false
"path": ""] "path": ""]
) )
openConnection()
}else { }else {
AbstractSocketTest.socket.leaveNamespace() AbstractSocketTest.socket.leaveNamespace()
} }
openConnection()
} }
override func tearDown() { override func tearDown() {

View File

@ -22,11 +22,12 @@ class SocketNamespaceAcknowledgementTest: AbstractSocketTest {
"forceWebsockets": false,// default false "forceWebsockets": false,// default false
"path": "", "path": "",
"nsp": "/swift"]) "nsp": "/swift"])
openConnection()
}else { }else {
AbstractSocketTest.socket.joinNamespace("/swift") AbstractSocketTest.socket.joinNamespace("/swift")
} }
openConnection()
} }
func testConnectionStatus() { func testConnectionStatus() {

View File

@ -22,13 +22,12 @@ class SocketNamespaceEmitTest: AbstractSocketTest {
"forceWebsockets": false,// default false "forceWebsockets": false,// default false
"path": "", "path": "",
"nsp": "/swift"]) "nsp": "/swift"])
openConnection()
}else { }else {
AbstractSocketTest.socket.joinNamespace("/swift") AbstractSocketTest.socket.joinNamespace("/swift")
} }
openConnection()
} }
func testConnectionStatus() { func testConnectionStatus() {
super.checkConnectionStatus() super.checkConnectionStatus()
} }

View File

@ -0,0 +1,105 @@
//
// SocketParserTest.swift
// Socket.IO-Client-Swift
//
// Created by Lukas Schmidt on 05.09.15.
//
//
import XCTest
class SocketParserTest: XCTestCase {
//Format key: message; namespace-data-binary-id
static let packetTypes: Dictionary<String, (String, [AnyObject], [NSData], Int)> = [
"0": ("/", [], [], -1), "1": ("/", [], [], -1),
"2/swift,[\"testArrayEmitReturn\",[\"test3\",\"test4\"]]": ("/swift", ["testArrayEmitReturn", ["test3", "test4"]], [], -1),
"51-/swift,[\"testMultipleItemsWithBufferEmitReturn\",[1,2],{\"test\":\"bob\"},25,\"polo\",{\"_placeholder\":true,\"num\":0}]": ("/swift", ["testMultipleItemsWithBufferEmitReturn", [1, 2], ["test": "bob"], 25, "polo", "~~0"], [], -1),
"3/swift,0[[\"test3\",\"test4\"]]": ("/swift", [["test3", "test4"]], [], 0),
"61-/swift,19[[1,2],{\"test\":\"bob\"},25,\"polo\",{\"_placeholder\":true,\"num\":0}]": ("/swift", [ [1, 2], ["test": "bob"], 25, "polo", "~~0"], [], 19),
"4/swift,": ("/swift", [], [], -1),
"0/swift": ("/swift", [], [], -1),
"1/swift": ("/swift", [], [], -1)]
func testDisconnect() {
let message = "1"
validateParseResult(message)
}
func testConnect() {
let message = "0"
validateParseResult(message)
}
func testDisconnectNameSpace() {
let message = "1/swift"
validateParseResult(message)
}
func testConnecttNameSpace() {
let message = "0/swift"
validateParseResult(message)
}
func testNameSpaceArrayParse() {
let message = "2/swift,[\"testArrayEmitReturn\",[\"test3\",\"test4\"]]"
validateParseResult(message)
}
func testNameSpaceArrayAckParse() {
let message = "3/swift,0[[\"test3\",\"test4\"]]"
validateParseResult(message)
}
func testNameSpaceBinaryEventParse() {
let message = "51-/swift,[\"testMultipleItemsWithBufferEmitReturn\",[1,2],{\"test\":\"bob\"},25,\"polo\",{\"_placeholder\":true,\"num\":0}]"
validateParseResult(message)
}
func testNameSpaceBinaryAckParse() {
let message = "61-/swift,19[[1,2],{\"test\":\"bob\"},25,\"polo\",{\"_placeholder\":true,\"num\":0}]"
validateParseResult(message)
}
func testNamespaceErrorParse() {
let message = "4/swift,"
validateParseResult(message)
}
func testInvalidInput() {
let message = "8"
XCTAssertNil(SocketParser.parseString(message))
}
func testGenericParser() {
var parser = SocketStringReader(message: "61-/swift,")
XCTAssertEqual(parser.read(1), "6")
XCTAssertEqual(parser.currentCharacter, "1")
XCTAssertEqual(parser.readUntilStringOccurence("-"), "1")
XCTAssertEqual(parser.currentCharacter, "/")
}
func validateParseResult(message: String) {
let validValues = SocketParserTest.packetTypes[message]!
let packet = SocketParser.parseString(message)
let type = message.substringWithRange(Range<String.Index>(start: message.startIndex, end: message.startIndex.advancedBy(1)))
if let packet = packet {
XCTAssertEqual(packet.type, SocketPacket.PacketType(str:type)!)
XCTAssertEqual(packet.nsp, validValues.0)
XCTAssertTrue((packet.data as NSArray).isEqualToArray(validValues.1))
XCTAssertTrue((packet.binary as NSArray).isEqualToArray(validValues.2))
XCTAssertEqual(packet.id, validValues.3)
} else {
XCTFail()
}
}
func testParsePerformance() {
let keys = Array(SocketParserTest.packetTypes.keys)
measureBlock({
for item in keys.enumerate() {
SocketParser.parseString(item.element)
}
})
}
}

View File

@ -111,6 +111,8 @@ class SocketTestCases: NSObject {
static func testJSONWithBuffer(abstractSocketSend:SocketSendFunction) { static func testJSONWithBuffer(abstractSocketSend:SocketSendFunction) {
let testName = "testJSONWithBuffer" let testName = "testJSONWithBuffer"
let data = "0".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
func didGetResult(result:NSArray?, ack:AckEmitter?) { func didGetResult(result:NSArray?, ack:AckEmitter?) {
if let json = result?.firstObject as? NSDictionary { if let json = result?.firstObject as? NSDictionary {
XCTAssertEqual((json.valueForKey("testString")! as! String), "test") XCTAssertEqual((json.valueForKey("testString")! as! String), "test")
@ -123,7 +125,7 @@ class SocketTestCases: NSObject {
XCTFail("Should have NSDictionary as result") XCTFail("Should have NSDictionary as result")
} }
} }
let json = ["name": "test", "testArray": ["hallo"], "nestedTest": ["test": "test"], "number": 15] let json = ["name": "test", "testArray": ["hallo"], "nestedTest": ["test": "test"], "number": 15, "buf": data]
abstractSocketSend(testName: testName, emitData: json, callback: didGetResult) abstractSocketSend(testName: testName, emitData: json, callback: didGetResult)
} }

View File

@ -24,7 +24,7 @@
import Foundation import Foundation
public final class SocketEngine: NSObject, WebSocketDelegate { public final class SocketEngine: NSObject, WebSocketDelegate {
private typealias Probe = (msg: String, type: PacketType, data: [NSData]?) private typealias Probe = (msg: String, type: PacketType, data: [NSData]?)
private typealias ProbeWaitQueue = [Probe] private typealias ProbeWaitQueue = [Probe]
@ -69,11 +69,11 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
var urlWebSocket: String? var urlWebSocket: String?
var ws: WebSocket? var ws: WebSocket?
public enum PacketType: Int { @objc public enum PacketType: Int {
case Open, Close, Ping, Pong, Message, Upgrade, Noop case Open, Close, Ping, Pong, Message, Upgrade, Noop
init?(str: String?) { init?(str: String) {
if let value = Int(str ?? ""), raw = PacketType(rawValue: value) { if let value = Int(str), raw = PacketType(rawValue: value) {
self = raw self = raw
} else { } else {
return nil return nil
@ -99,6 +99,19 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
deinit { deinit {
Logger.log("Engine is being deinit", type: logType) Logger.log("Engine is being deinit", type: logType)
} }
private func checkIfMessageIsBase64Binary(var message: String) {
if message.hasPrefix("b4") {
// binary in base64 string
message.removeRange(Range<String.Index>(start: message.startIndex,
end: message.startIndex.advancedBy(2)))
if let data = NSData(base64EncodedString: message,
options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters) {
client?.parseBinaryData(data)
}
}
}
public func close(fast fast: Bool) { public func close(fast fast: Bool) {
Logger.log("Engine is being closed. Fast: %@", type: logType, args: fast) Logger.log("Engine is being closed. Fast: %@", type: logType, args: fast)
@ -154,7 +167,6 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
} }
if params != nil { if params != nil {
for (key, value) in params! { for (key, value) in params! {
let keyEsc = key.stringByAddingPercentEncodingWithAllowedCharacters( let keyEsc = key.stringByAddingPercentEncodingWithAllowedCharacters(
allowedCharacterSet)! allowedCharacterSet)!
@ -350,8 +362,10 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
// We had packets waiting for send when we upgraded // We had packets waiting for send when we upgraded
// Send them raw // Send them raw
private func flushWaitingForPostToWebSocket() { private func flushWaitingForPostToWebSocket() {
guard let ws = self.ws else {return}
for msg in postWait { for msg in postWait {
ws?.writeString(msg) ws.writeString(msg)
} }
postWait.removeAll(keepCapacity: true) postWait.removeAll(keepCapacity: true)
@ -363,19 +377,6 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
} }
} }
private func checkIfMessageIsBase64Binary(var message: String) {
if message.hasPrefix("b4") {
// binary in base64 string
message.removeRange(Range<String.Index>(start: message.startIndex,
end: message.startIndex.advancedBy(2)))
if let data = NSData(base64EncodedString: message,
options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters) {
client?.parseBinaryData(data)
}
}
}
private func handleMessage(message: String) { private func handleMessage(message: String) {
client?.parseSocketMessage(message) client?.parseSocketMessage(message)
} }
@ -483,60 +484,31 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
doRequest(reqPolling) doRequest(reqPolling)
} }
// Translatation of engine.io-parser#decodePayload private func parsePollingMessage(str: String) {
private func parsePollingMessage(str:String) {
guard str.characters.count != 1 else { guard str.characters.count != 1 else {
return return
} }
// println(str)
var reader = SocketStringReader(message: str)
let strArray = Array(str.characters)
var length = "" while reader.hasNext {
var n = 0 if let n = Int(reader.readUntilStringOccurence(":")) {
var msg = "" let str = reader.read(n)
func testLength(length:String, inout n:Int) -> Bool { dispatch_async(handleQueue) {
if let num = Int(length) { self.parseEngineMessage(str, fromPolling: true)
n = num }
return false
} else { } else {
return true dispatch_async(handleQueue) {
} self.parseEngineMessage(str, fromPolling: true)
}
for var i = 0, l = str.characters.count; i < l; i++ {
let chr = String(strArray[i])
if chr != ":" {
length += chr
} else {
if length == "" || testLength(length, n: &n) {
Logger.error("Parsing error: %@", type: logType, args: str)
handlePollingFailed("Error parsing XHR message")
return
} }
break
msg = String(strArray[i+1...i+n])
if let lengthInt = Int(length) where lengthInt != msg.characters.count {
Logger.error("Parsing error: %@", type: logType, args: str)
return
}
if msg.characters.count != 0 {
// Be sure to capture the value of the msg
dispatch_async(handleQueue) {[weak self, msg] in
self?.parseEngineMessage(msg, fromPolling: true)
}
}
i += n
length = ""
} }
} }
} }
private func parseEngineData(data: NSData) { private func parseEngineData(data: NSData) {
Logger.log("Got binary data: %@", type: "SocketEngine", args: data)
client?.parseBinaryData(data.subdataWithRange(NSMakeRange(1, data.length - 1))) client?.parseBinaryData(data.subdataWithRange(NSMakeRange(1, data.length - 1)))
} }
@ -547,9 +519,9 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
fixDoubleUTF8(&message) fixDoubleUTF8(&message)
} }
let type = PacketType(str: (message["^(\\d)"].groups()?[1])) ?? { let type = PacketType(str: (message["^(\\d)"].groups()?[1]) ?? "") ?? {
self.checkIfMessageIsBase64Binary(message) self.checkIfMessageIsBase64Binary(message)
return PacketType.Noop return .Noop
}() }()
switch type { switch type {
@ -608,12 +580,10 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
postWait.append(strMsg) postWait.append(strMsg)
if let datas = datas { for data in datas ?? [] {
for data in datas { let (_, b64Data) = createBinaryDataForSend(data)
let (_, b64Data) = createBinaryDataForSend(data)
postWait.append(b64Data!) postWait.append(b64Data!)
}
} }
if !waitingForPost { if !waitingForPost {
@ -629,26 +599,22 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
ws?.writeString("\(type.rawValue)\(str)") ws?.writeString("\(type.rawValue)\(str)")
if let datas = datas { for data in datas ?? [] {
for data in datas { let (data, _) = createBinaryDataForSend(data)
let (data, _) = createBinaryDataForSend(data) if data != nil {
if data != nil { ws?.writeData(data!)
ws?.writeData(data!)
}
} }
} }
} }
// Starts the ping timer // Starts the ping timer
private func startPingTimer() { private func startPingTimer() {
guard pingInterval != nil else { if let pingInterval = pingInterval {
return pingTimer?.invalidate()
} pingTimer = nil
pingTimer?.invalidate() dispatch_async(dispatch_get_main_queue()) {
dispatch_async(dispatch_get_main_queue()) {[weak self] in self.pingTimer = NSTimer.scheduledTimerWithTimeInterval(pingInterval, target: self,
if let this = self {
this.pingTimer = NSTimer.scheduledTimerWithTimeInterval(this.pingInterval!, target: this,
selector: Selector("sendPing"), userInfo: nil, repeats: true) selector: Selector("sendPing"), userInfo: nil, repeats: true)
} }
} }
@ -672,38 +638,21 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
Write a message, independent of transport. Write a message, independent of transport.
*/ */
public func write(msg: String, withType type: PacketType, withData data: [NSData]?) { public func write(msg: String, withType type: PacketType, withData data: [NSData]?) {
dispatch_async(emitQueue) {[weak self] in dispatch_async(emitQueue) {
if let this = self where this.connected { if self.connected {
if this.websocket { if self.websocket {
Logger.log("Writing ws: %@ has data: %@", type: this.logType, args: msg, Logger.log("Writing ws: %@ has data: %@", type: self.logType, args: msg,
data == nil ? false : true) data == nil ? false : true)
this.sendWebSocketMessage(msg, withType: type, datas: data) self.sendWebSocketMessage(msg, withType: type, datas: data)
} else { } else {
Logger.log("Writing poll: %@ has data: %@", type: this.logType, args: msg, Logger.log("Writing poll: %@ has data: %@", type: self.logType, args: msg,
data == nil ? false : true) data == nil ? false : true)
this.sendPollMessage(msg, withType: type, datas: data) self.sendPollMessage(msg, withType: type, datas: data)
} }
} }
} }
} }
/**
Write a message, independent of transport. For Objective-C. withData should be an NSArray of NSData
*/
public func writeObjc(msg: String, withType type: Int, withData data: NSArray?) {
if let pType = PacketType(rawValue: type) {
var arr = [NSData]()
if let data = data {
for d in data {
arr.append(d as! NSData)
}
}
write(msg, withType: pType, withData: arr)
}
}
// Delagate methods // Delagate methods
public func websocketDidConnect(socket:WebSocket) { public func websocketDidConnect(socket:WebSocket) {

View File

@ -36,17 +36,20 @@ private func emitAckCallbackObjectiveC(socket: SocketIOClient?, num: Int?)
struct SocketEventHandler { struct SocketEventHandler {
let event: String let event: String
let id: NSUUID
let callback: NormalCallback? let callback: NormalCallback?
let callBackObjectiveC: NormalCallbackObjectiveC? let callBackObjectiveC: NormalCallbackObjectiveC?
init(event: String, callback: NormalCallback) { init(event: String, id: NSUUID = NSUUID(), callback: NormalCallback) {
self.event = event self.event = event
self.id = id
self.callback = callback self.callback = callback
self.callBackObjectiveC = nil self.callBackObjectiveC = nil
} }
init(event: String, callback: NormalCallbackObjectiveC) { init(event: String, id: NSUUID = NSUUID(), callback: NormalCallbackObjectiveC) {
self.event = event self.event = event
self.id = id
self.callback = nil self.callback = nil
self.callBackObjectiveC = callback self.callBackObjectiveC = callback
} }

View File

@ -25,10 +25,11 @@
import Foundation import Foundation
public final class SocketIOClient: NSObject, SocketEngineClient { public final class SocketIOClient: NSObject, SocketEngineClient {
public let emitQueue = dispatch_queue_create("emitQueue", DISPATCH_QUEUE_SERIAL) private let emitQueue = dispatch_queue_create("emitQueue", DISPATCH_QUEUE_SERIAL)
public let handleQueue: dispatch_queue_t! private let handleQueue: dispatch_queue_t!
public let socketURL: String public let socketURL: String
public private(set) var engine: SocketEngine? public private(set) var engine: SocketEngine?
public private(set) var secure = false public private(set) var secure = false
public private(set) var status = SocketIOClientStatus.NotConnected public private(set) var status = SocketIOClientStatus.NotConnected
@ -49,9 +50,10 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
private var connectParams: [String: AnyObject]? private var connectParams: [String: AnyObject]?
private var reconnectTimer: NSTimer? private var reconnectTimer: NSTimer?
let reconnectAttempts: Int! private let reconnectAttempts: Int!
var ackHandlers = SocketAckManager() private var ackHandlers = SocketAckManager()
var currentAck = -1 private var currentAck = -1
var waitingData = [SocketPacket]() var waitingData = [SocketPacket]()
/** /**
@ -112,10 +114,13 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
engine?.close(fast: true) engine?.close(fast: true)
} }
private func addEngine() { private func addEngine() -> SocketEngine {
Logger.log("Adding engine", type: logType) Logger.log("Adding engine", type: logType)
engine = SocketEngine(client: self, opts: opts) let newEngine = SocketEngine(client: self, opts: opts)
engine = newEngine
return newEngine
} }
private func clearReconnectTimer() { private func clearReconnectTimer() {
@ -128,12 +133,11 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
Will turn off automatic reconnects. Will turn off automatic reconnects.
Pass true to fast if you're closing from a background task Pass true to fast if you're closing from a background task
*/ */
public func close(fast fast: Bool) { public func close() {
Logger.log("Closing socket", type: logType) Logger.log("Closing socket", type: logType)
reconnects = false reconnects = false
status = SocketIOClientStatus.Closed didDisconnect("Closed")
engine?.close(fast: fast)
} }
/** /**
@ -146,30 +150,32 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
/** /**
Connect to the server. If we aren't connected after timeoutAfter, call handler Connect to the server. If we aren't connected after timeoutAfter, call handler
*/ */
public func connect(timeoutAfter timeoutAfter:Int, public func connect(timeoutAfter timeoutAfter: Int,
withTimeoutHandler handler:(() -> Void)?) { withTimeoutHandler handler: (() -> Void)?) {
guard status != SocketIOClientStatus.Connected else { assert(timeoutAfter >= 0, "Invalid timeout: \(timeoutAfter)")
guard status != .Connected else {
return return
} }
if status == SocketIOClientStatus.Closed {
if status == .Closed {
Logger.log("Warning! This socket was previously closed. This might be dangerous!", Logger.log("Warning! This socket was previously closed. This might be dangerous!",
type: logType) type: logType)
} }
status = SocketIOClientStatus.Connecting status = SocketIOClientStatus.Connecting
addEngine() addEngine().open(connectParams)
engine?.open(connectParams)
guard timeoutAfter != 0 else { guard timeoutAfter != 0 else {
return return
} }
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeoutAfter) * Int64(NSEC_PER_SEC)) let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeoutAfter) * Int64(NSEC_PER_SEC))
dispatch_after(time, dispatch_get_main_queue()) {[weak self] in dispatch_after(time, dispatch_get_main_queue()) {
if let this = self where this.status != SocketIOClientStatus.Connected { if self.status != .Connected {
this.status = SocketIOClientStatus.Closed self.status = .Closed
this.engine?.close(fast: true) self.engine?.close(fast: true)
handler?() handler?()
} }
@ -181,15 +187,15 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
if let this = self { if let this = self {
this.ackHandlers.addAck(ack, callback: callback) this.ackHandlers.addAck(ack, callback: callback)
dispatch_async(this.emitQueue) {[weak this] in dispatch_async(this.emitQueue) {
this?._emit(items, ack: ack) this._emit(items, ack: ack)
} }
if timeout != 0 { if timeout != 0 {
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeout * NSEC_PER_SEC)) let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeout * NSEC_PER_SEC))
dispatch_after(time, dispatch_get_main_queue()) {[weak this] in dispatch_after(time, dispatch_get_main_queue()) {
this?.ackHandlers.timeoutAck(ack) this.ackHandlers.timeoutAck(ack)
} }
} }
} }
@ -198,7 +204,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
func didConnect() { func didConnect() {
Logger.log("Socket connected", type: logType) Logger.log("Socket connected", type: logType)
status = SocketIOClientStatus.Connected status = .Connected
currentReconnectAttempt = 0 currentReconnectAttempt = 0
clearReconnectTimer() clearReconnectTimer()
@ -208,14 +214,13 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
} }
func didDisconnect(reason: String) { func didDisconnect(reason: String) {
guard status != SocketIOClientStatus.Closed else { guard status != .Closed else {
return return
} }
Logger.log("Disconnected: %@", type: logType, args: reason) Logger.log("Disconnected: %@", type: logType, args: reason)
status = SocketIOClientStatus.Closed status = .Closed
reconnects = false reconnects = false
// Make sure the engine is actually dead. // Make sure the engine is actually dead.
@ -234,8 +239,8 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
/** /**
Same as close Same as close
*/ */
public func disconnect(fast fast: Bool) { public func disconnect() {
close(fast: fast) close()
} }
/** /**
@ -249,12 +254,12 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
Same as emit, but meant for Objective-C Same as emit, but meant for Objective-C
*/ */
public func emit(event: String, withItems items: [AnyObject]) { public func emit(event: String, withItems items: [AnyObject]) {
guard status == SocketIOClientStatus.Connected else { guard status == .Connected else {
return return
} }
dispatch_async(emitQueue) {[weak self] in dispatch_async(emitQueue) {
self?._emit([event] + items) self._emit([event] + items)
} }
} }
@ -274,7 +279,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
} }
private func _emit(data: [AnyObject], ack: Int? = nil) { private func _emit(data: [AnyObject], ack: Int? = nil) {
guard status == SocketIOClientStatus.Connected else { guard status == .Connected else {
return return
} }
@ -283,7 +288,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
Logger.log("Emitting: %@", type: logType, args: str) Logger.log("Emitting: %@", type: logType, args: str)
if packet.type == SocketPacket.PacketType.BinaryEvent { if packet.type == .BinaryEvent {
engine?.send(str, withData: packet.binary) engine?.send(str, withData: packet.binary)
} else { } else {
engine?.send(str, withData: nil) engine?.send(str, withData: nil)
@ -292,17 +297,17 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
// If the server wants to know that the client received data // If the server wants to know that the client received data
func emitAck(ack: Int, withItems items: [AnyObject]) { func emitAck(ack: Int, withItems items: [AnyObject]) {
dispatch_async(emitQueue) {[weak self] in dispatch_async(emitQueue) {
if let this = self where this.status == SocketIOClientStatus.Connected { if self.status == .Connected {
let packet = SocketPacket.packetFromEmit(items, id: ack ?? -1, nsp: this.nsp, ack: true) let packet = SocketPacket.packetFromEmit(items, id: ack ?? -1, nsp: self.nsp, ack: true)
let str = packet.packetString let str = packet.packetString
Logger.log("Emitting Ack: %@", type: this.logType, args: str) Logger.log("Emitting Ack: %@", type: self.logType, args: str)
if packet.type == SocketPacket.PacketType.BinaryAck { if packet.type == SocketPacket.PacketType.BinaryAck {
this.engine?.send(str, withData: packet.binary) self.engine?.send(str, withData: packet.binary)
} else { } else {
this.engine?.send(str, withData: nil) self.engine?.send(str, withData: nil)
} }
} }
@ -312,10 +317,10 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
public func engineDidClose(reason: String) { public func engineDidClose(reason: String) {
waitingData.removeAll() waitingData.removeAll()
if status == SocketIOClientStatus.Closed || !reconnects { if status == .Closed || !reconnects {
didDisconnect(reason) didDisconnect(reason)
} else if status != SocketIOClientStatus.Reconnecting { } else if status != .Reconnecting {
status = SocketIOClientStatus.Reconnecting status = .Reconnecting
handleEvent("reconnect", data: [reason], isInternalMessage: true) handleEvent("reconnect", data: [reason], isInternalMessage: true)
tryReconnect() tryReconnect()
} }
@ -334,22 +339,21 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
*/ */
public func handleEvent(event: String, data: [AnyObject]?, isInternalMessage: Bool, public func handleEvent(event: String, data: [AnyObject]?, isInternalMessage: Bool,
wantsAck ack: Int? = nil) { wantsAck ack: Int? = nil) {
guard status == SocketIOClientStatus.Connected || isInternalMessage else { guard status == .Connected || isInternalMessage else {
return return
} }
// println("Should do event: \(event) with data: \(data)")
Logger.log("Handling event: %@ with data: %@", type: logType, args: event, data ?? "") Logger.log("Handling event: %@ with data: %@", type: logType, args: event, data ?? "")
if anyHandler != nil { if anyHandler != nil {
dispatch_async(handleQueue) {[weak self] in dispatch_async(handleQueue) {
self?.anyHandler?(SocketAnyEvent(event: event, items: data)) self.anyHandler?(SocketAnyEvent(event: event, items: data))
} }
} }
for handler in handlers where handler.event == event { for handler in handlers where handler.event == event {
if let ack = ack { if let ack = ack {
dispatch_async(handleQueue) {[weak self] in dispatch_async(handleQueue) {
handler.executeCallback(data, withAck: ack, withSocket: self) handler.executeCallback(data, withAck: ack, withSocket: self)
} }
} else { } else {
@ -395,7 +399,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
public func off(event: String) { public func off(event: String) {
Logger.log("Removing handler for event: %@", type: logType, args: event) Logger.log("Removing handler for event: %@", type: logType, args: event)
handlers = ContiguousArray(handlers.filter {!($0.event == event)}) handlers = ContiguousArray(handlers.filter { $0.event != event })
} }
/** /**
@ -418,6 +422,40 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
handlers.append(handler) handlers.append(handler)
} }
/**
Adds a single-use handler for an event.
*/
public func once(event: String, callback: NormalCallback) {
Logger.log("Adding once handler for event: %@", type: logType, args: event)
let id = NSUUID()
let handler = SocketEventHandler(event: event, id: id) {[weak self] (data, ack: AckEmitter?) in
guard let this = self else {return}
this.handlers = ContiguousArray(this.handlers.filter {$0.id != id})
callback(data, ack)
}
handlers.append(handler)
}
/**
Adds a single-use handler for an event.
*/
public func once(event event: String, callback: NormalCallbackObjectiveC) {
Logger.log("Adding once handler for event: %@", type: logType, args: event)
let id = NSUUID()
let handler = SocketEventHandler(event: event, id: id) {[weak self] (data, ack: AckEmitterObjectiveC?) in
guard let this = self else {return}
this.handlers = ContiguousArray(this.handlers.filter {$0.id != id})
callback(data, ack)
}
handlers.append(handler)
}
/** /**
Removes all handlers. Removes all handlers.
Can be used after disconnecting to break any potential remaining retain cycles. Can be used after disconnecting to break any potential remaining retain cycles.
@ -441,18 +479,14 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
} }
public func parseSocketMessage(msg: String) { public func parseSocketMessage(msg: String) {
dispatch_async(handleQueue) {[weak self] in dispatch_async(handleQueue) {
if let this = self { SocketParser.parseSocketMessage(msg, socket: self)
SocketParser.parseSocketMessage(msg, socket: this)
}
} }
} }
public func parseBinaryData(data: NSData) { public func parseBinaryData(data: NSData) {
dispatch_async(handleQueue) {[weak self] in dispatch_async(handleQueue) {
if let this = self { SocketParser.parseBinaryData(data, socket: self)
SocketParser.parseBinaryData(data, socket: this)
}
} }
} }
@ -468,19 +502,17 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
if reconnectTimer == nil { if reconnectTimer == nil {
Logger.log("Starting reconnect", type: logType) Logger.log("Starting reconnect", type: logType)
status = SocketIOClientStatus.Reconnecting status = .Reconnecting
dispatch_async(dispatch_get_main_queue()) {[weak self] in dispatch_async(dispatch_get_main_queue()) {
if let this = self { self.reconnectTimer = NSTimer.scheduledTimerWithTimeInterval(Double(self.reconnectWait),
this.reconnectTimer = NSTimer.scheduledTimerWithTimeInterval(Double(this.reconnectWait), target: self, selector: "_tryReconnect", userInfo: nil, repeats: true)
target: this, selector: "_tryReconnect", userInfo: nil, repeats: true)
}
} }
} }
} }
@objc private func _tryReconnect() { @objc private func _tryReconnect() {
if status == SocketIOClientStatus.Connected { if status == .Connected {
clearReconnectTimer() clearReconnectTimer()
return return

View File

@ -25,8 +25,10 @@
import Foundation import Foundation
struct SocketPacket { struct SocketPacket {
private var currentPlace = 0
private let placeholders: Int private let placeholders: Int
private var currentPlace = 0
private static let logType = "SocketPacket"
let nsp: String let nsp: String
let id: Int let id: Int
@ -62,19 +64,12 @@ struct SocketPacket {
var binary: [NSData] var binary: [NSData]
var data: [AnyObject] var data: [AnyObject]
var description: String { var description: String {
var better = "SocketPacket {type: ~~0; data: ~~1; " + return "SocketPacket {type: \(String(type.rawValue)); data: " +
"id: ~~2; placeholders: ~~3;}" "\(String(data)); id: \(id); placeholders: \(placeholders); nsp: \(nsp)}"
better = better["~~0"] ~= String(type.rawValue)
better = better["~~1"] ~= String(data)
better = better["~~2"] ~= String(id)
better = better["~~3"] ~= String(placeholders)
return better
} }
var event: String { var event: String {
return data[0] as! String return data[0] as? String ?? String(data[0])
} }
var packetString: String { var packetString: String {
@ -121,7 +116,7 @@ struct SocketPacket {
message += jsonString! as String + "," message += jsonString! as String + ","
} catch { } catch {
print("Error creating JSON object in SocketPacket.completeMessage") Logger.error("Error creating JSON object in SocketPacket.completeMessage", type: SocketPacket.logType)
} }
} else if var str = arg as? String { } else if var str = arg as? String {
str = str["\n"] ~= "\\\\n" str = str["\n"] ~= "\\\\n"
@ -212,17 +207,13 @@ struct SocketPacket {
} }
mutating func fillInPlaceholders() { mutating func fillInPlaceholders() {
let newArr = NSMutableArray(array: data)
for i in 0..<data.count { for i in 0..<data.count {
if let str = data[i] as? String, num = str["~~(\\d)"].groups() { if let str = data[i] as? String, num = str["~~(\\d)"].groups() {
newArr[i] = binary[Int(num[1])!] data[i] = binary[Int(num[1])!]
} else if data[i] is NSDictionary || data[i] is NSArray { } else if data[i] is NSDictionary || data[i] is NSArray {
newArr[i] = _fillInPlaceholders(data[i]) data[i] = _fillInPlaceholders(data[i])
} }
} }
data = newArr as [AnyObject]
} }
private mutating func _fillInPlaceholders(data: AnyObject) -> AnyObject { private mutating func _fillInPlaceholders(data: AnyObject) -> AnyObject {
@ -287,22 +278,20 @@ private extension SocketPacket {
binary.append(bin) binary.append(bin)
return placeholder return placeholder
} else if let arr = data as? NSArray { } else if var arr = data as? [AnyObject] {
let newArr = NSMutableArray(array: arr)
for i in 0..<arr.count { for i in 0..<arr.count {
newArr[i] = shred(arr[i], binary: &binary) arr[i] = shred(arr[i], binary: &binary)
} }
return newArr return arr
} else if let dict = data as? NSDictionary { } else if let dict = data as? NSDictionary {
let newDict = NSMutableDictionary(dictionary: dict) let mutDict = NSMutableDictionary(dictionary: dict)
for (key, value) in newDict { for (key, value) in dict {
newDict[key as! NSCopying] = shred(value, binary: &binary) mutDict[key as! NSCopying] = shred(value, binary: &binary)
} }
return newDict return mutDict
} else { } else {
return data return data
} }

View File

@ -23,30 +23,26 @@
import Foundation import Foundation
class SocketParser { class SocketParser {
private static func isCorrectNamespace(nsp: String, _ socket: SocketIOClient) -> Bool { private static func isCorrectNamespace(nsp: String, _ socket: SocketIOClient) -> Bool {
return nsp == socket.nsp return nsp == socket.nsp
} }
private static func handleEvent(p: SocketPacket, socket: SocketIOClient) {
guard isCorrectNamespace(p.nsp, socket) else { return }
socket.handleEvent(p.event, data: p.args,
isInternalMessage: false, wantsAck: p.id)
}
private static func handleAck(p: SocketPacket, socket: SocketIOClient) { private static func handleAck(p: SocketPacket, socket: SocketIOClient) {
if !isCorrectNamespace(p.nsp, socket) { guard isCorrectNamespace(p.nsp, socket) else { return }
return
}
socket.handleAck(p.id, data: p.data) socket.handleAck(p.id, data: p.data)
} }
private static func handleBinaryAck(p: SocketPacket, socket: SocketIOClient) { private static func handleBinary(p: SocketPacket, socket: SocketIOClient) {
if !isCorrectNamespace(p.nsp, socket) { guard isCorrectNamespace(p.nsp, socket) else { return }
return
}
socket.waitingData.append(p)
}
private static func handleBinaryEvent(p: SocketPacket, socket: SocketIOClient) {
if !isCorrectNamespace(p.nsp, socket) {
return
}
socket.waitingData.append(p) socket.waitingData.append(p)
} }
@ -61,169 +57,115 @@ class SocketParser {
} }
} }
private static func handleEvent(p: SocketPacket, socket: SocketIOClient) { static func parseString(message: String) -> SocketPacket? {
if !isCorrectNamespace(p.nsp, socket) { var parser = SocketStringReader(message: message)
return
guard let type = SocketPacket.PacketType(str: parser.read(1))
else {return nil}
if !parser.hasNext {
return SocketPacket(type: type, nsp: "/")
} }
socket.handleEvent(p.event, data: p.args, var namespace: String?
isInternalMessage: false, wantsAck: p.id)
}
// Translation of socket.io-client#decodeString
static func parseString(str: String) -> SocketPacket? {
let arr = Array(str.characters)
let type = String(arr[0])
if arr.count == 1 {
return SocketPacket(type: SocketPacket.PacketType(str: type)!, nsp: "/")
}
var id: Int?
var nsp:String?
var i = 0
var placeholders = -1 var placeholders = -1
if type == "5" || type == "6" { if type == .BinaryEvent || type == .BinaryAck {
var buf = "" if let holders = Int(parser.readUntilStringOccurence("-")) {
while arr[++i] != "-" {
buf += String(arr[i])
if i == arr.count {
break
}
}
if let holders = Int(buf) where arr[i] == "-" {
placeholders = holders placeholders = holders
} else { } else {
NSLog("Error parsing \(str)") return nil
return nil
} }
} }
if arr[i + 1] == "/" { if parser.currentCharacter == "/" {
nsp = "" namespace = parser.readUntilStringOccurence(",") ?? parser.readUntilEnd()
}
while ++i < arr.count {
let c = arr[i] if !parser.hasNext {
return SocketPacket(type: type, id: -1,
if c == "," { nsp: namespace ?? "/", placeholders: placeholders)
break }
}
var idString = ""
nsp! += String(c)
while parser.hasNext {
if let int = Int(parser.read(1)) {
idString += String(int)
} else {
parser.advanceIndexBy(-2)
break
} }
} }
if i + 1 >= arr.count { let d = message[parser.currentIndex.advancedBy(1)..<message.endIndex]
return SocketPacket(type: SocketPacket.PacketType(str: type)!, id: id ?? -1, let noPlaceholders = d["(\\{\"_placeholder\":true,\"num\":(\\d*)\\})"] ~= "\"~~$2\""
nsp: nsp ?? "/", placeholders: placeholders) let data = parseData(noPlaceholders) as? [AnyObject] ?? [noPlaceholders]
}
let next = String(arr[i + 1]) return SocketPacket(type: type, data: data, id: Int(idString) ?? -1,
nsp: namespace ?? "/", placeholders: placeholders)
if Int(next) != nil {
var c = ""
while ++i < arr.count {
if let int = Int(String(arr[i])) {
c += String(int)
} else {
--i
break
}
}
id = Int(c)
}
if ++i < arr.count {
let d = str[str.startIndex.advancedBy(i)...str.startIndex.advancedBy(str.characters.count-1)]
let noPlaceholders = d["(\\{\"_placeholder\":true,\"num\":(\\d*)\\})"] ~= "\"~~$2\""
let data = SocketParser.parseData(noPlaceholders) as? [AnyObject] ?? [noPlaceholders]
return SocketPacket(type: SocketPacket.PacketType(str: type)!, data: data, id: id ?? -1,
nsp: nsp ?? "/", placeholders: placeholders)
}
return nil
} }
// Parses data for events // Parses data for events
static func parseData(data: String) -> AnyObject? { static func parseData(data: String) -> AnyObject? {
var err: NSError?
let stringData = data.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) let stringData = data.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
let parsed: AnyObject?
do { do {
parsed = try NSJSONSerialization.JSONObjectWithData(stringData!, return try NSJSONSerialization.JSONObjectWithData(stringData!,
options: NSJSONReadingOptions.MutableContainers) options: NSJSONReadingOptions.MutableContainers)
} catch let error as NSError { } catch {
err = error Logger.error("Parsing JSON: %@", type: "SocketParser", args: data)
parsed = nil
}
if err != nil {
// println(err)
return nil return nil
} }
return parsed
} }
// Parses messages recieved // Parses messages recieved
static func parseSocketMessage(stringMessage: String, socket: SocketIOClient) { static func parseSocketMessage(message: String, socket: SocketIOClient) {
if stringMessage == "" { guard !message.isEmpty else { return }
Logger.log("Parsing %@", type: "SocketParser", args: message)
guard let pack = parseString(message) else {
Logger.error("Parsing message: %@", type: "SocketParser", args: message)
return return
} }
Logger.log("Parsing %@", type: "SocketParser", args: stringMessage) Logger.log("Decoded packet as: %@", type: "SocketParser", args: pack.description)
let p: SocketPacket switch pack.type {
case .Event:
if let pack = parseString(stringMessage) { handleEvent(pack, socket: socket)
p = pack case .Ack:
} else { handleAck(pack, socket: socket)
socket.didError("Error parsing packet") case .BinaryEvent:
return handleBinary(pack, socket: socket)
} case .BinaryAck:
handleBinary(pack, socket: socket)
Logger.log("Decoded packet as: %@", type: "SocketParser", args: p.description) case .Connect:
handleConnect(pack, socket: socket)
switch p.type { case .Disconnect:
case SocketPacket.PacketType.Event:
handleEvent(p, socket: socket)
case SocketPacket.PacketType.Ack:
handleAck(p, socket: socket)
case SocketPacket.PacketType.BinaryEvent:
handleBinaryEvent(p, socket: socket)
case SocketPacket.PacketType.BinaryAck:
handleBinaryAck(p, socket: socket)
case SocketPacket.PacketType.Connect:
handleConnect(p, socket: socket)
case SocketPacket.PacketType.Disconnect:
socket.didDisconnect("Got Disconnect") socket.didDisconnect("Got Disconnect")
case SocketPacket.PacketType.Error: case .Error:
socket.didError("Error: \(p.data)") socket.didError("Error: \(pack.data)")
} }
} }
static func parseBinaryData(data: NSData, socket: SocketIOClient) { static func parseBinaryData(data: NSData, socket: SocketIOClient) {
if socket.waitingData.count == 0 { guard !socket.waitingData.isEmpty else {
Logger.error("Got data when not remaking packet", type: "SocketParser") Logger.error("Got data when not remaking packet", type: "SocketParser")
return return
} }
let shouldExecute = socket.waitingData[0].addData(data) let shouldExecute = socket.waitingData[socket.waitingData.count - 1].addData(data)
if !shouldExecute { guard shouldExecute else {
return return
} }
var packet = socket.waitingData.removeAtIndex(0) var packet = socket.waitingData.removeLast()
packet.fillInPlaceholders() packet.fillInPlaceholders()
if packet.type != SocketPacket.PacketType.BinaryAck { if packet.type != .BinaryAck {
socket.handleEvent(packet.event, data: packet.args, socket.handleEvent(packet.event, data: packet.args,
isInternalMessage: false, wantsAck: packet.id) isInternalMessage: false, wantsAck: packet.id)
} else { } else {

View File

@ -0,0 +1,68 @@
//
// SocketStringReader.swift
// Socket.IO-Client-Swift
//
// Created by Lukas Schmidt on 07.09.15.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
struct SocketStringReader {
let message: String
var currentIndex: String.Index
var hasNext: Bool {
return currentIndex != message.endIndex
}
var currentCharacter: String {
return String(message[currentIndex])
}
init(message: String) {
self.message = message
currentIndex = message.startIndex
}
mutating func advanceIndexBy(n: Int) {
currentIndex = currentIndex.advancedBy(n)
}
mutating func read(readLength: Int) -> String {
let readString = message[currentIndex..<currentIndex.advancedBy(readLength)]
advanceIndexBy(readLength)
return readString
}
mutating func readUntilStringOccurence(string: String) -> String {
let substring = message[currentIndex..<message.endIndex]
guard let foundRange = substring.rangeOfString(string) else {
currentIndex = message.endIndex
return substring
}
advanceIndexBy(message.startIndex.distanceTo(foundRange.startIndex) + 1)
return substring.substringToIndex(foundRange.startIndex)
}
mutating func readUntilEnd() -> String {
return read(currentIndex.distanceTo(message.endIndex))
}
}

View File

@ -13,9 +13,9 @@
import Foundation import Foundation
var swiftRegexCache = [String: NSRegularExpression]() private var swiftRegexCache = [String: NSRegularExpression]()
public class SwiftRegex: NSObject, BooleanType { internal class SwiftRegex: NSObject, BooleanType {
var target:String var target:String
var regex: NSRegularExpression var regex: NSRegularExpression
@ -36,17 +36,16 @@ public class SwiftRegex: NSObject, BooleanType {
} }
super.init() super.init()
} }
class func failure(message: String) { private static func failure(message: String) {
print("SwiftRegex: "+message) fatalError("SwiftRegex: \(message)")
//assert(false,"SwiftRegex: failed")
} }
final var targetRange: NSRange { private final var targetRange: NSRange {
return NSRange(location: 0,length: target.utf16.count) return NSRange(location: 0,length: target.utf16.count)
} }
final func substring(range: NSRange) -> String? { private final func substring(range: NSRange) -> String? {
if ( range.location != NSNotFound ) { if ( range.location != NSNotFound ) {
return (target as NSString).substringWithRange(range) return (target as NSString).substringWithRange(range)
} else { } else {
@ -54,24 +53,24 @@ public class SwiftRegex: NSObject, BooleanType {
} }
} }
public func doesMatch(options: NSMatchingOptions!) -> Bool { func doesMatch(options: NSMatchingOptions!) -> Bool {
return range(options).location != NSNotFound return range(options).location != NSNotFound
} }
public func range(options: NSMatchingOptions) -> NSRange { func range(options: NSMatchingOptions) -> NSRange {
return regex.rangeOfFirstMatchInString(target as String, options: [], range: targetRange) return regex.rangeOfFirstMatchInString(target as String, options: [], range: targetRange)
} }
public func match(options: NSMatchingOptions) -> String? { func match(options: NSMatchingOptions) -> String? {
return substring(range(options)) return substring(range(options))
} }
public func groups() -> [String]? { func groups() -> [String]? {
return groupsForMatch(regex.firstMatchInString(target as String, options: return groupsForMatch(regex.firstMatchInString(target as String, options:
NSMatchingOptions.WithoutAnchoringBounds, range: targetRange)) NSMatchingOptions.WithoutAnchoringBounds, range: targetRange))
} }
func groupsForMatch(match: NSTextCheckingResult!) -> [String]? { private func groupsForMatch(match: NSTextCheckingResult!) -> [String]? {
if match != nil { if match != nil {
var groups = [String]() var groups = [String]()
for groupno in 0...regex.numberOfCaptureGroups { for groupno in 0...regex.numberOfCaptureGroups {
@ -87,7 +86,7 @@ public class SwiftRegex: NSObject, BooleanType {
} }
} }
public subscript(groupno: Int) -> String? { subscript(groupno: Int) -> String? {
get { get {
return groups()?[groupno] return groups()?[groupno]
} }
@ -116,19 +115,19 @@ public class SwiftRegex: NSObject, BooleanType {
return matches return matches
} }
public func ranges() -> [NSRange] { func ranges() -> [NSRange] {
return matchResults().map { $0.range } return matchResults().map { $0.range }
} }
public func matches() -> [String] { func matches() -> [String] {
return matchResults().map( { self.substring($0.range)!}) return matchResults().map( { self.substring($0.range)!})
} }
public func allGroups() -> [[String]?] { func allGroups() -> [[String]?] {
return matchResults().map {self.groupsForMatch($0)} return matchResults().map {self.groupsForMatch($0)}
} }
public func dictionary(options: NSMatchingOptions!) -> Dictionary<String,String> { func dictionary(options: NSMatchingOptions!) -> Dictionary<String,String> {
var out = Dictionary<String,String>() var out = Dictionary<String,String>()
for match in matchResults() { for match in matchResults() {
out[substring(match.rangeAtIndex(1))!] = substring(match.rangeAtIndex(2))! out[substring(match.rangeAtIndex(1))!] = substring(match.rangeAtIndex(2))!
@ -153,31 +152,31 @@ public class SwiftRegex: NSObject, BooleanType {
return out as String return out as String
} }
public var boolValue: Bool { var boolValue: Bool {
return doesMatch(nil) return doesMatch(nil)
} }
} }
extension String { extension String {
public subscript(pattern: String, options: NSRegularExpressionOptions) -> SwiftRegex { subscript(pattern: String, options: NSRegularExpressionOptions) -> SwiftRegex {
return SwiftRegex(target: self, pattern: pattern, options: options) return SwiftRegex(target: self, pattern: pattern, options: options)
} }
} }
extension String { extension String {
public subscript(pattern: String) -> SwiftRegex { subscript(pattern: String) -> SwiftRegex {
return SwiftRegex(target: self, pattern: pattern, options: nil) return SwiftRegex(target: self, pattern: pattern, options: nil)
} }
} }
public func ~= (left: SwiftRegex, right: String) -> String { func ~= (left: SwiftRegex, right: String) -> String {
return left.substituteMatches({match, stop in return left.substituteMatches({match, stop in
return left.regex.replacementStringForResult( match, return left.regex.replacementStringForResult( match,
inString: left.target as String, offset: 0, template: right ) inString: left.target as String, offset: 0, template: right )
}, options: []) }, options: [])
} }
public func ~= (left: SwiftRegex, right: [String]) -> String { func ~= (left: SwiftRegex, right: [String]) -> String {
var matchNumber = 0 var matchNumber = 0
return left.substituteMatches({match, stop -> String in return left.substituteMatches({match, stop -> String in
@ -190,7 +189,7 @@ public func ~= (left: SwiftRegex, right: [String]) -> String {
}, options: []) }, options: [])
} }
public func ~= (left: SwiftRegex, right: (String) -> String) -> String { func ~= (left: SwiftRegex, right: (String) -> String) -> String {
// return right(left.substring(match.range)) // return right(left.substring(match.range))
return left.substituteMatches( return left.substituteMatches(
{match, stop -> String in {match, stop -> String in
@ -198,7 +197,7 @@ public func ~= (left: SwiftRegex, right: (String) -> String) -> String {
}, options: []) }, options: [])
} }
public func ~= (left: SwiftRegex, right: ([String]?) -> String) -> String { func ~= (left: SwiftRegex, right: ([String]?) -> String) -> String {
return left.substituteMatches({match, stop -> String in return left.substituteMatches({match, stop -> String in
return right(left.groupsForMatch(match)) return right(left.groupsForMatch(match))
}, options: []) }, options: [])

View File

@ -133,12 +133,19 @@ public class WebSocket : NSObject, NSStreamDelegate {
if isCreated { if isCreated {
return return
} }
unowned let weakSelf = self
dispatch_async(queue, { [weak self] in
dispatch_async(queue,{ guard let weakSelf = self else {
return
}
weakSelf.didDisconnect = false weakSelf.didDisconnect = false
}) })
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), { [weak self] in
guard let weakSelf = self else {
return
}
weakSelf.isCreated = true weakSelf.isCreated = true
weakSelf.createHTTPRequest() weakSelf.createHTTPRequest()
weakSelf.isCreated = false weakSelf.isCreated = false
@ -370,19 +377,18 @@ public class WebSocket : NSObject, NSStreamDelegate {
} }
} }
if totalSize > 0 { if totalSize > 0 {
unowned let weakSelf = self
if validateResponse(buffer, bufferLen: totalSize) { if validateResponse(buffer, bufferLen: totalSize) {
dispatch_async(queue,{ dispatch_async(queue, {
weakSelf.connected = true self.connected = true
if let connectBlock = weakSelf.onConnect { if let connectBlock = self.onConnect {
connectBlock() connectBlock()
} }
weakSelf.delegate?.websocketDidConnect(self) self.delegate?.websocketDidConnect(self)
}) })
totalSize += 1 //skip the last \n totalSize += 1 //skip the last \n
let restSize = bufferLen - totalSize let restSize = bufferLen - totalSize
if restSize > 0 { if restSize > 0 {
processRawMessage((buffer+totalSize),bufferLen: restSize) processRawMessage((buffer+totalSize), bufferLen: restSize)
} }
return true return true
} }
@ -515,10 +521,8 @@ public class WebSocket : NSObject, NSStreamDelegate {
data = NSData(bytes: UnsafePointer<UInt8>((buffer+offset)), length: Int(len)) data = NSData(bytes: UnsafePointer<UInt8>((buffer+offset)), length: Int(len))
} }
if receivedOpcode == OpCode.Pong.rawValue { if receivedOpcode == OpCode.Pong.rawValue {
dispatch_async(queue,{[unowned self] in dispatch_async(queue, {
if let pongBlock = self.onPong { self.onPong?()
pongBlock()
}
self.pongDelegate?.websocketDidReceivePong(self) self.pongDelegate?.websocketDidReceivePong(self)
}) })
@ -604,25 +608,24 @@ public class WebSocket : NSObject, NSStreamDelegate {
dequeueWrite(data, code: OpCode.Pong) dequeueWrite(data, code: OpCode.Pong)
} else if response.code == .TextFrame { } else if response.code == .TextFrame {
let str: NSString? = NSString(data: response.buffer!, encoding: NSUTF8StringEncoding) let str: NSString? = NSString(data: response.buffer!, encoding: NSUTF8StringEncoding)
if str == nil {
if let str = str as String? {
dispatch_async(queue, {
self.onText?(str)
self.delegate?.websocketDidReceiveMessage(self, text: str)
})
} else {
writeError(CloseCode.Encoding.rawValue) writeError(CloseCode.Encoding.rawValue)
return false return false
} }
dispatch_async(queue,{[unowned self] in
if let textBlock = self.onText {
textBlock(str! as String)
}
self.delegate?.websocketDidReceiveMessage(self, text: str! as String)
})
} else if response.code == .BinaryFrame { } else if response.code == .BinaryFrame {
let data = response.buffer! //local copy so it is perverse for writing let data = response.buffer! //local copy so it is perverse for writing
dispatch_async(queue,{[unowned self] in dispatch_async(queue) {
if let dataBlock = self.onData { self.onData?(data)
dataBlock(data)
}
self.delegate?.websocketDidReceiveData(self, data: data) self.delegate?.websocketDidReceiveData(self, data: data)
}) }
} }
readStack.removeLast() readStack.removeLast()
return true return true
} }
@ -723,13 +726,12 @@ public class WebSocket : NSObject, NSStreamDelegate {
///used to preform the disconnect delegate ///used to preform the disconnect delegate
private func doDisconnect(error: NSError?) { private func doDisconnect(error: NSError?) {
if !self.didDisconnect { if !self.didDisconnect {
dispatch_async(queue,{[unowned self] in dispatch_async(queue) {
self.didDisconnect = true self.didDisconnect = true
if let disconnect = self.onDisconnect {
disconnect(error) self.onDisconnect?(error)
}
self.delegate?.websocketDidDisconnect(self, error: error) self.delegate?.websocketDidDisconnect(self, error: error)
}) }
} }
} }
@ -748,7 +750,7 @@ public class WebSocket : NSObject, NSStreamDelegate {
import Foundation import Foundation
import Security import Security
public class SSLCert { private class SSLCert {
var certData: NSData? var certData: NSData?
var key: SecKeyRef? var key: SecKeyRef?
@ -759,7 +761,7 @@ public class SSLCert {
:returns: a representation security object to be used with :returns: a representation security object to be used with
*/ */
public init(data: NSData) { init(data: NSData) {
self.certData = data self.certData = data
} }
@ -770,7 +772,7 @@ public class SSLCert {
:returns: a representation security object to be used with :returns: a representation security object to be used with
*/ */
public init(key: SecKeyRef) { init(key: SecKeyRef) {
self.key = key self.key = key
} }
} }