Merge remote-tracking branch 'socketio/master'
This commit is contained in:
commit
6cffbc2404
@ -2,4 +2,4 @@ language: objective-c
|
||||
xcode_project: Socket.IO-Client-Swift.xcodeproj # path to your xcodeproj folder
|
||||
xcode_scheme: SocketIO-iOS
|
||||
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
|
||||
37
README.md
37
README.md
@ -1,4 +1,4 @@
|
||||
[](https://travis-ci.org/socketio/socket.io-client-swift)
|
||||
[](https://travis-ci.org/socketio/socket.io-client-swift)
|
||||
|
||||
#Socket.IO-Client-Swift
|
||||
Socket.IO-client for iOS/OS X.
|
||||
@ -26,7 +26,7 @@ socket.connect()
|
||||
|
||||
##Objective-C Example
|
||||
```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*)) {
|
||||
NSLog(@"socket connected");
|
||||
@ -56,17 +56,18 @@ SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8
|
||||
##Installation
|
||||
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)
|
||||
|
||||
Carthage
|
||||
-----------------
|
||||
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+)
|
||||
-----------------
|
||||
@ -82,7 +83,7 @@ source 'https://github.com/CocoaPods/Specs.git'
|
||||
platform :ios, '8.0'
|
||||
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:
|
||||
@ -106,9 +107,7 @@ Objective-C:
|
||||
##API
|
||||
Constructors
|
||||
-----------
|
||||
`init(socketURL: String, opts:NSDictionary? = nil)` - Constructs a new client for the given URL. opts can be omitted (will use default values)
|
||||
|
||||
`convenience init(socketURL: String, options:NSDictionary?)` - Same as above, but meant for Objective-C. See Objective-C Example.
|
||||
`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.
|
||||
|
||||
Options
|
||||
-------
|
||||
@ -129,19 +128,21 @@ Options
|
||||
|
||||
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.
|
||||
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.
|
||||
4. `emit(event:String, _ items:AnyObject...)` - Sends a message. Can send multiple items.
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
9. `connect(#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.
|
||||
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()` - Closes the socket. Once a socket is closed it should not be reopened.
|
||||
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.
|
||||
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
|
||||
------
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
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.description = <<-DESC
|
||||
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.ios.deployment_target = '8.0'
|
||||
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.requires_arc = true
|
||||
# s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files
|
||||
|
||||
@ -12,6 +12,47 @@
|
||||
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 */; };
|
||||
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 */; };
|
||||
5764DF8A1B51F254004FF46E /* SocketAckManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7C1B51F254004FF46E /* SocketAckManager.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 */; };
|
||||
74781D5C1B7E83930042CACA /* 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 */; };
|
||||
94242BB81B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94242BB71B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.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 */; };
|
||||
945B65411B5FCEEA0081E995 /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF881B51F254004FF46E /* WebSocket.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 */; };
|
||||
94ADAC4B1B6632DD00FD79AE /* SocketAcknowledgementTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94ADAC4A1B6632DD00FD79AE /* SocketAcknowledgementTest.swift */; };
|
||||
94CB8F0B1B6E48B90019ED53 /* SocketTestCases.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94CB8F0A1B6E48B90019ED53 /* SocketTestCases.swift */; };
|
||||
@ -79,6 +125,13 @@
|
||||
remoteGlobalIDString = 572EF2371B51F18A00EEBB58;
|
||||
remoteInfo = "SocketIO-Mac";
|
||||
};
|
||||
57425FDA1BA3A4F100BDAAC1 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 572EF20E1B51F12F00EEBB58 /* Project object */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = 572EF2181B51F16C00EEBB58;
|
||||
remoteInfo = "SocketIO-iOS";
|
||||
};
|
||||
/* End PBXContainerItemProxy 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; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
@ -107,9 +162,12 @@
|
||||
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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
@ -147,6 +205,21 @@
|
||||
);
|
||||
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 */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
@ -169,6 +242,8 @@
|
||||
572EF2241B51F16C00EEBB58 /* SocketIO-iOSTests.xctest */,
|
||||
572EF2381B51F18A00EEBB58 /* SocketIO.framework */,
|
||||
572EF2421B51F18A00EEBB58 /* SocketIO-MacTests.xctest */,
|
||||
57425FB21BA3A46000BDAAC1 /* SocketIO.framework */,
|
||||
57425FFA1BA3A4F100BDAAC1 /* SocketIO-tvOSTests.xctest */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
@ -200,7 +275,9 @@
|
||||
941A4AB91B67A56C00C42318 /* TestKind.swift */,
|
||||
94CB8F0A1B6E48B90019ED53 /* SocketTestCases.swift */,
|
||||
94CB8F0C1B6E66E60019ED53 /* AbstractSocketTest.swift */,
|
||||
94A20D601B99E22F00BF9E44 /* SocketAckManagerTest.swift */,
|
||||
572EF2291B51F16C00EEBB58 /* Supporting Files */,
|
||||
949FAE8C1B9B94E600073BE9 /* SocketParserTest.swift */,
|
||||
);
|
||||
path = "SocketIO-iOSTests";
|
||||
sourceTree = "<group>";
|
||||
@ -261,6 +338,7 @@
|
||||
5764DF831B51F254004FF46E /* SocketLogger.swift */,
|
||||
5764DF841B51F254004FF46E /* SocketPacket.swift */,
|
||||
5764DF851B51F254004FF46E /* SocketParser.swift */,
|
||||
74D765611B9F0D870028551C /* SocketStringReader.swift */,
|
||||
5764DF861B51F254004FF46E /* SocketTypes.swift */,
|
||||
5764DF871B51F254004FF46E /* SwiftRegex.swift */,
|
||||
5764DF881B51F254004FF46E /* WebSocket.swift */,
|
||||
@ -287,6 +365,14 @@
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
57425FAC1BA3A46000BDAAC1 /* Headers */ = {
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
57425FAD1BA3A46000BDAAC1 /* SocketIO-iOS.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXHeadersBuildPhase section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
@ -362,6 +448,42 @@
|
||||
productReference = 572EF2421B51F18A00EEBB58 /* SocketIO-MacTests.xctest */;
|
||||
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 */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
@ -399,6 +521,8 @@
|
||||
targets = (
|
||||
572EF2181B51F16C00EEBB58 /* SocketIO-iOS */,
|
||||
572EF2231B51F16C00EEBB58 /* SocketIO-iOSTests */,
|
||||
57425F9A1BA3A46000BDAAC1 /* SocketIO-tvOS */,
|
||||
57425FD81BA3A4F100BDAAC1 /* SocketIO-tvOSTests */,
|
||||
572EF2371B51F18A00EEBB58 /* SocketIO-Mac */,
|
||||
572EF2411B51F18A00EEBB58 /* SocketIO-MacTests */,
|
||||
);
|
||||
@ -434,6 +558,20 @@
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
57425FAE1BA3A46000BDAAC1 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
57425FF61BA3A4F100BDAAC1 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
@ -441,6 +579,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
74D765631B9F0D9F0028551C /* SocketStringReader.swift in Sources */,
|
||||
5764DF8D1B51F254004FF46E /* SocketEngine.swift in Sources */,
|
||||
5764DF9B1B51F254004FF46E /* SocketParser.swift in Sources */,
|
||||
5764DF9D1B51F254004FF46E /* SocketTypes.swift in Sources */,
|
||||
@ -462,6 +601,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
74D765621B9F0D870028551C /* SocketStringReader.swift in Sources */,
|
||||
945B653E1B5FCEEA0081E995 /* SocketParser.swift in Sources */,
|
||||
945B653D1B5FCEEA0081E995 /* SocketPacket.swift in Sources */,
|
||||
945B653A1B5FCEEA0081E995 /* SocketFixUTF8.swift in Sources */,
|
||||
@ -474,12 +614,14 @@
|
||||
945B65431B63D9DB0081E995 /* SocketEmitTest.swift in Sources */,
|
||||
945B65401B5FCEEA0081E995 /* SwiftRegex.swift in Sources */,
|
||||
945B653C1B5FCEEA0081E995 /* SocketLogger.swift in Sources */,
|
||||
94A20D611B99E22F00BF9E44 /* SocketAckManagerTest.swift in Sources */,
|
||||
945B65381B5FCEEA0081E995 /* SocketEngineClient.swift in Sources */,
|
||||
945B65361B5FCEEA0081E995 /* SocketAnyEvent.swift in Sources */,
|
||||
94ADAC4B1B6632DD00FD79AE /* SocketAcknowledgementTest.swift in Sources */,
|
||||
945B653F1B5FCEEA0081E995 /* SocketTypes.swift in Sources */,
|
||||
74781D5B1B7E83930042CACA /* SocketIOClientStatus.swift in Sources */,
|
||||
945B653B1B5FCEEA0081E995 /* SocketIOClient.swift in Sources */,
|
||||
949FAE8D1B9B94E600073BE9 /* SocketParserTest.swift in Sources */,
|
||||
94ADAC491B652D3300FD79AE /* SocketNamespaceEmitTest.swift in Sources */,
|
||||
945B65411B5FCEEA0081E995 /* WebSocket.swift in Sources */,
|
||||
94242BB81B67B0E500AAAC9D /* SocketNamespaceAcknowledgementTest.swift in Sources */,
|
||||
@ -490,6 +632,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
74D765641B9F0DA40028551C /* SocketStringReader.swift in Sources */,
|
||||
5764DF8E1B51F254004FF46E /* SocketEngine.swift in Sources */,
|
||||
5764DF9C1B51F254004FF46E /* SocketParser.swift in Sources */,
|
||||
5764DF9E1B51F254004FF46E /* SocketTypes.swift in Sources */,
|
||||
@ -516,6 +659,59 @@
|
||||
);
|
||||
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 */
|
||||
|
||||
/* Begin PBXTargetDependency section */
|
||||
@ -529,6 +725,11 @@
|
||||
target = 572EF2371B51F18A00EEBB58 /* SocketIO-Mac */;
|
||||
targetProxy = 572EF2441B51F18A00EEBB58 /* PBXContainerItemProxy */;
|
||||
};
|
||||
57425FD91BA3A4F100BDAAC1 /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = 572EF2181B51F16C00EEBB58 /* SocketIO-iOS */;
|
||||
targetProxy = 57425FDA1BA3A4F100BDAAC1 /* PBXContainerItemProxy */;
|
||||
};
|
||||
/* End PBXTargetDependency section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
@ -943,6 +1144,203 @@
|
||||
};
|
||||
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 */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
@ -991,6 +1389,24 @@
|
||||
defaultConfigurationIsVisible = 0;
|
||||
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 */
|
||||
};
|
||||
rootObject = 572EF20E1B51F12F00EEBB58 /* Project object */;
|
||||
|
||||
@ -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>
|
||||
26
SocketIO-iOSTests/SocketAckManagerTest.swift
Normal file
26
SocketIO-iOSTests/SocketAckManagerTest.swift
Normal 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)
|
||||
|
||||
}
|
||||
}
|
||||
@ -21,11 +21,12 @@ class SocketAcknowledgementTest: AbstractSocketTest {
|
||||
"forcePolling": false,
|
||||
"forceWebsockets": false,// default false
|
||||
"path": ""])
|
||||
openConnection()
|
||||
}else {
|
||||
AbstractSocketTest.socket.leaveNamespace()
|
||||
}
|
||||
|
||||
openConnection()
|
||||
|
||||
}
|
||||
|
||||
func testConnectionStatus() {
|
||||
|
||||
@ -22,11 +22,12 @@ class SocketEmitTest: AbstractSocketTest {
|
||||
"forceWebsockets": false,// default false
|
||||
"path": ""]
|
||||
)
|
||||
openConnection()
|
||||
}else {
|
||||
AbstractSocketTest.socket.leaveNamespace()
|
||||
}
|
||||
|
||||
openConnection()
|
||||
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
|
||||
@ -22,11 +22,12 @@ class SocketNamespaceAcknowledgementTest: AbstractSocketTest {
|
||||
"forceWebsockets": false,// default false
|
||||
"path": "",
|
||||
"nsp": "/swift"])
|
||||
openConnection()
|
||||
}else {
|
||||
AbstractSocketTest.socket.joinNamespace("/swift")
|
||||
}
|
||||
|
||||
openConnection()
|
||||
|
||||
}
|
||||
|
||||
func testConnectionStatus() {
|
||||
|
||||
@ -22,13 +22,12 @@ class SocketNamespaceEmitTest: AbstractSocketTest {
|
||||
"forceWebsockets": false,// default false
|
||||
"path": "",
|
||||
"nsp": "/swift"])
|
||||
openConnection()
|
||||
}else {
|
||||
AbstractSocketTest.socket.joinNamespace("/swift")
|
||||
}
|
||||
|
||||
openConnection()
|
||||
}
|
||||
|
||||
|
||||
func testConnectionStatus() {
|
||||
super.checkConnectionStatus()
|
||||
}
|
||||
|
||||
105
SocketIO-iOSTests/SocketParserTest.swift
Normal file
105
SocketIO-iOSTests/SocketParserTest.swift
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -111,6 +111,8 @@ class SocketTestCases: NSObject {
|
||||
|
||||
static func testJSONWithBuffer(abstractSocketSend:SocketSendFunction) {
|
||||
let testName = "testJSONWithBuffer"
|
||||
let data = "0".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
|
||||
|
||||
func didGetResult(result:NSArray?, ack:AckEmitter?) {
|
||||
if let json = result?.firstObject as? NSDictionary {
|
||||
XCTAssertEqual((json.valueForKey("testString")! as! String), "test")
|
||||
@ -123,7 +125,7 @@ class SocketTestCases: NSObject {
|
||||
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)
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
|
||||
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 ProbeWaitQueue = [Probe]
|
||||
|
||||
@ -69,11 +69,11 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
|
||||
var urlWebSocket: String?
|
||||
var ws: WebSocket?
|
||||
|
||||
public enum PacketType: Int {
|
||||
@objc public enum PacketType: Int {
|
||||
case Open, Close, Ping, Pong, Message, Upgrade, Noop
|
||||
|
||||
init?(str: String?) {
|
||||
if let value = Int(str ?? ""), raw = PacketType(rawValue: value) {
|
||||
init?(str: String) {
|
||||
if let value = Int(str), raw = PacketType(rawValue: value) {
|
||||
self = raw
|
||||
} else {
|
||||
return nil
|
||||
@ -99,6 +99,19 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
|
||||
deinit {
|
||||
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) {
|
||||
Logger.log("Engine is being closed. Fast: %@", type: logType, args: fast)
|
||||
@ -154,7 +167,6 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
|
||||
}
|
||||
|
||||
if params != nil {
|
||||
|
||||
for (key, value) in params! {
|
||||
let keyEsc = key.stringByAddingPercentEncodingWithAllowedCharacters(
|
||||
allowedCharacterSet)!
|
||||
@ -350,8 +362,10 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
|
||||
// We had packets waiting for send when we upgraded
|
||||
// Send them raw
|
||||
private func flushWaitingForPostToWebSocket() {
|
||||
guard let ws = self.ws else {return}
|
||||
|
||||
for msg in postWait {
|
||||
ws?.writeString(msg)
|
||||
ws.writeString(msg)
|
||||
}
|
||||
|
||||
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) {
|
||||
client?.parseSocketMessage(message)
|
||||
}
|
||||
@ -483,60 +484,31 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
|
||||
doRequest(reqPolling)
|
||||
}
|
||||
|
||||
// Translatation of engine.io-parser#decodePayload
|
||||
private func parsePollingMessage(str:String) {
|
||||
private func parsePollingMessage(str: String) {
|
||||
guard str.characters.count != 1 else {
|
||||
return
|
||||
}
|
||||
// println(str)
|
||||
|
||||
let strArray = Array(str.characters)
|
||||
var length = ""
|
||||
var n = 0
|
||||
var msg = ""
|
||||
|
||||
func testLength(length:String, inout n:Int) -> Bool {
|
||||
if let num = Int(length) {
|
||||
n = num
|
||||
return false
|
||||
|
||||
var reader = SocketStringReader(message: str)
|
||||
|
||||
while reader.hasNext {
|
||||
if let n = Int(reader.readUntilStringOccurence(":")) {
|
||||
let str = reader.read(n)
|
||||
|
||||
dispatch_async(handleQueue) {
|
||||
self.parseEngineMessage(str, fromPolling: true)
|
||||
}
|
||||
} else {
|
||||
return 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
|
||||
dispatch_async(handleQueue) {
|
||||
self.parseEngineMessage(str, fromPolling: true)
|
||||
}
|
||||
|
||||
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 = ""
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func parseEngineData(data: NSData) {
|
||||
Logger.log("Got binary data: %@", type: "SocketEngine", args: data)
|
||||
client?.parseBinaryData(data.subdataWithRange(NSMakeRange(1, data.length - 1)))
|
||||
}
|
||||
|
||||
@ -547,9 +519,9 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
|
||||
fixDoubleUTF8(&message)
|
||||
}
|
||||
|
||||
let type = PacketType(str: (message["^(\\d)"].groups()?[1])) ?? {
|
||||
let type = PacketType(str: (message["^(\\d)"].groups()?[1]) ?? "") ?? {
|
||||
self.checkIfMessageIsBase64Binary(message)
|
||||
return PacketType.Noop
|
||||
return .Noop
|
||||
}()
|
||||
|
||||
switch type {
|
||||
@ -608,12 +580,10 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
|
||||
|
||||
postWait.append(strMsg)
|
||||
|
||||
if let datas = datas {
|
||||
for data in datas {
|
||||
let (_, b64Data) = createBinaryDataForSend(data)
|
||||
for data in datas ?? [] {
|
||||
let (_, b64Data) = createBinaryDataForSend(data)
|
||||
|
||||
postWait.append(b64Data!)
|
||||
}
|
||||
postWait.append(b64Data!)
|
||||
}
|
||||
|
||||
if !waitingForPost {
|
||||
@ -629,26 +599,22 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
|
||||
|
||||
ws?.writeString("\(type.rawValue)\(str)")
|
||||
|
||||
if let datas = datas {
|
||||
for data in datas {
|
||||
let (data, _) = createBinaryDataForSend(data)
|
||||
if data != nil {
|
||||
ws?.writeData(data!)
|
||||
}
|
||||
for data in datas ?? [] {
|
||||
let (data, _) = createBinaryDataForSend(data)
|
||||
if data != nil {
|
||||
ws?.writeData(data!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Starts the ping timer
|
||||
private func startPingTimer() {
|
||||
guard pingInterval != nil else {
|
||||
return
|
||||
}
|
||||
if let pingInterval = pingInterval {
|
||||
pingTimer?.invalidate()
|
||||
pingTimer = nil
|
||||
|
||||
pingTimer?.invalidate()
|
||||
dispatch_async(dispatch_get_main_queue()) {[weak self] in
|
||||
if let this = self {
|
||||
this.pingTimer = NSTimer.scheduledTimerWithTimeInterval(this.pingInterval!, target: this,
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
self.pingTimer = NSTimer.scheduledTimerWithTimeInterval(pingInterval, target: self,
|
||||
selector: Selector("sendPing"), userInfo: nil, repeats: true)
|
||||
}
|
||||
}
|
||||
@ -672,38 +638,21 @@ public final class SocketEngine: NSObject, WebSocketDelegate {
|
||||
Write a message, independent of transport.
|
||||
*/
|
||||
public func write(msg: String, withType type: PacketType, withData data: [NSData]?) {
|
||||
dispatch_async(emitQueue) {[weak self] in
|
||||
if let this = self where this.connected {
|
||||
if this.websocket {
|
||||
Logger.log("Writing ws: %@ has data: %@", type: this.logType, args: msg,
|
||||
dispatch_async(emitQueue) {
|
||||
if self.connected {
|
||||
if self.websocket {
|
||||
Logger.log("Writing ws: %@ has data: %@", type: self.logType, args: msg,
|
||||
data == nil ? false : true)
|
||||
this.sendWebSocketMessage(msg, withType: type, datas: data)
|
||||
self.sendWebSocketMessage(msg, withType: type, datas: data)
|
||||
} 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)
|
||||
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
|
||||
|
||||
public func websocketDidConnect(socket:WebSocket) {
|
||||
|
||||
@ -36,17 +36,20 @@ private func emitAckCallbackObjectiveC(socket: SocketIOClient?, num: Int?)
|
||||
|
||||
struct SocketEventHandler {
|
||||
let event: String
|
||||
let id: NSUUID
|
||||
let callback: NormalCallback?
|
||||
let callBackObjectiveC: NormalCallbackObjectiveC?
|
||||
|
||||
init(event: String, callback: NormalCallback) {
|
||||
init(event: String, id: NSUUID = NSUUID(), callback: NormalCallback) {
|
||||
self.event = event
|
||||
self.id = id
|
||||
self.callback = callback
|
||||
self.callBackObjectiveC = nil
|
||||
}
|
||||
|
||||
init(event: String, callback: NormalCallbackObjectiveC) {
|
||||
init(event: String, id: NSUUID = NSUUID(), callback: NormalCallbackObjectiveC) {
|
||||
self.event = event
|
||||
self.id = id
|
||||
self.callback = nil
|
||||
self.callBackObjectiveC = callback
|
||||
}
|
||||
|
||||
@ -25,10 +25,11 @@
|
||||
import Foundation
|
||||
|
||||
public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
public let emitQueue = dispatch_queue_create("emitQueue", DISPATCH_QUEUE_SERIAL)
|
||||
public let handleQueue: dispatch_queue_t!
|
||||
private let emitQueue = dispatch_queue_create("emitQueue", DISPATCH_QUEUE_SERIAL)
|
||||
private let handleQueue: dispatch_queue_t!
|
||||
|
||||
public let socketURL: String
|
||||
|
||||
|
||||
public private(set) var engine: SocketEngine?
|
||||
public private(set) var secure = false
|
||||
public private(set) var status = SocketIOClientStatus.NotConnected
|
||||
@ -49,9 +50,10 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
private var connectParams: [String: AnyObject]?
|
||||
private var reconnectTimer: NSTimer?
|
||||
|
||||
let reconnectAttempts: Int!
|
||||
var ackHandlers = SocketAckManager()
|
||||
var currentAck = -1
|
||||
private let reconnectAttempts: Int!
|
||||
private var ackHandlers = SocketAckManager()
|
||||
private var currentAck = -1
|
||||
|
||||
var waitingData = [SocketPacket]()
|
||||
|
||||
/**
|
||||
@ -112,10 +114,13 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
engine?.close(fast: true)
|
||||
}
|
||||
|
||||
private func addEngine() {
|
||||
private func addEngine() -> SocketEngine {
|
||||
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() {
|
||||
@ -128,12 +133,11 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
Will turn off automatic reconnects.
|
||||
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)
|
||||
|
||||
reconnects = false
|
||||
status = SocketIOClientStatus.Closed
|
||||
engine?.close(fast: fast)
|
||||
didDisconnect("Closed")
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,30 +150,32 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
/**
|
||||
Connect to the server. If we aren't connected after timeoutAfter, call handler
|
||||
*/
|
||||
public func connect(timeoutAfter timeoutAfter:Int,
|
||||
withTimeoutHandler handler:(() -> Void)?) {
|
||||
guard status != SocketIOClientStatus.Connected else {
|
||||
public func connect(timeoutAfter timeoutAfter: Int,
|
||||
withTimeoutHandler handler: (() -> Void)?) {
|
||||
assert(timeoutAfter >= 0, "Invalid timeout: \(timeoutAfter)")
|
||||
|
||||
guard status != .Connected else {
|
||||
return
|
||||
}
|
||||
if status == SocketIOClientStatus.Closed {
|
||||
|
||||
if status == .Closed {
|
||||
Logger.log("Warning! This socket was previously closed. This might be dangerous!",
|
||||
type: logType)
|
||||
}
|
||||
|
||||
status = SocketIOClientStatus.Connecting
|
||||
addEngine()
|
||||
engine?.open(connectParams)
|
||||
addEngine().open(connectParams)
|
||||
|
||||
guard timeoutAfter != 0 else {
|
||||
return
|
||||
}
|
||||
|
||||
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeoutAfter) * Int64(NSEC_PER_SEC))
|
||||
|
||||
dispatch_after(time, dispatch_get_main_queue()) {[weak self] in
|
||||
if let this = self where this.status != SocketIOClientStatus.Connected {
|
||||
this.status = SocketIOClientStatus.Closed
|
||||
this.engine?.close(fast: true)
|
||||
|
||||
dispatch_after(time, dispatch_get_main_queue()) {
|
||||
if self.status != .Connected {
|
||||
self.status = .Closed
|
||||
self.engine?.close(fast: true)
|
||||
|
||||
handler?()
|
||||
}
|
||||
@ -181,15 +187,15 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
if let this = self {
|
||||
this.ackHandlers.addAck(ack, callback: callback)
|
||||
|
||||
dispatch_async(this.emitQueue) {[weak this] in
|
||||
this?._emit(items, ack: ack)
|
||||
dispatch_async(this.emitQueue) {
|
||||
this._emit(items, ack: ack)
|
||||
}
|
||||
|
||||
if timeout != 0 {
|
||||
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeout * NSEC_PER_SEC))
|
||||
|
||||
dispatch_after(time, dispatch_get_main_queue()) {[weak this] in
|
||||
this?.ackHandlers.timeoutAck(ack)
|
||||
dispatch_after(time, dispatch_get_main_queue()) {
|
||||
this.ackHandlers.timeoutAck(ack)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -198,7 +204,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
|
||||
func didConnect() {
|
||||
Logger.log("Socket connected", type: logType)
|
||||
status = SocketIOClientStatus.Connected
|
||||
status = .Connected
|
||||
currentReconnectAttempt = 0
|
||||
clearReconnectTimer()
|
||||
|
||||
@ -208,14 +214,13 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
}
|
||||
|
||||
func didDisconnect(reason: String) {
|
||||
guard status != SocketIOClientStatus.Closed else {
|
||||
guard status != .Closed else {
|
||||
return
|
||||
}
|
||||
|
||||
Logger.log("Disconnected: %@", type: logType, args: reason)
|
||||
|
||||
status = SocketIOClientStatus.Closed
|
||||
|
||||
status = .Closed
|
||||
reconnects = false
|
||||
|
||||
// Make sure the engine is actually dead.
|
||||
@ -234,8 +239,8 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
/**
|
||||
Same as close
|
||||
*/
|
||||
public func disconnect(fast fast: Bool) {
|
||||
close(fast: fast)
|
||||
public func disconnect() {
|
||||
close()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -249,12 +254,12 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
Same as emit, but meant for Objective-C
|
||||
*/
|
||||
public func emit(event: String, withItems items: [AnyObject]) {
|
||||
guard status == SocketIOClientStatus.Connected else {
|
||||
guard status == .Connected else {
|
||||
return
|
||||
}
|
||||
|
||||
dispatch_async(emitQueue) {[weak self] in
|
||||
self?._emit([event] + items)
|
||||
|
||||
dispatch_async(emitQueue) {
|
||||
self._emit([event] + items)
|
||||
}
|
||||
}
|
||||
|
||||
@ -274,7 +279,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
}
|
||||
|
||||
private func _emit(data: [AnyObject], ack: Int? = nil) {
|
||||
guard status == SocketIOClientStatus.Connected else {
|
||||
guard status == .Connected else {
|
||||
return
|
||||
}
|
||||
|
||||
@ -283,7 +288,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
|
||||
Logger.log("Emitting: %@", type: logType, args: str)
|
||||
|
||||
if packet.type == SocketPacket.PacketType.BinaryEvent {
|
||||
if packet.type == .BinaryEvent {
|
||||
engine?.send(str, withData: packet.binary)
|
||||
} else {
|
||||
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
|
||||
func emitAck(ack: Int, withItems items: [AnyObject]) {
|
||||
dispatch_async(emitQueue) {[weak self] in
|
||||
if let this = self where this.status == SocketIOClientStatus.Connected {
|
||||
let packet = SocketPacket.packetFromEmit(items, id: ack ?? -1, nsp: this.nsp, ack: true)
|
||||
dispatch_async(emitQueue) {
|
||||
if self.status == .Connected {
|
||||
let packet = SocketPacket.packetFromEmit(items, id: ack ?? -1, nsp: self.nsp, ack: true)
|
||||
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 {
|
||||
this.engine?.send(str, withData: packet.binary)
|
||||
self.engine?.send(str, withData: packet.binary)
|
||||
} 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) {
|
||||
waitingData.removeAll()
|
||||
|
||||
if status == SocketIOClientStatus.Closed || !reconnects {
|
||||
if status == .Closed || !reconnects {
|
||||
didDisconnect(reason)
|
||||
} else if status != SocketIOClientStatus.Reconnecting {
|
||||
status = SocketIOClientStatus.Reconnecting
|
||||
} else if status != .Reconnecting {
|
||||
status = .Reconnecting
|
||||
handleEvent("reconnect", data: [reason], isInternalMessage: true)
|
||||
tryReconnect()
|
||||
}
|
||||
@ -334,22 +339,21 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
*/
|
||||
public func handleEvent(event: String, data: [AnyObject]?, isInternalMessage: Bool,
|
||||
wantsAck ack: Int? = nil) {
|
||||
guard status == SocketIOClientStatus.Connected || isInternalMessage else {
|
||||
guard status == .Connected || isInternalMessage else {
|
||||
return
|
||||
}
|
||||
// println("Should do event: \(event) with data: \(data)")
|
||||
|
||||
Logger.log("Handling event: %@ with data: %@", type: logType, args: event, data ?? "")
|
||||
|
||||
if anyHandler != nil {
|
||||
dispatch_async(handleQueue) {[weak self] in
|
||||
self?.anyHandler?(SocketAnyEvent(event: event, items: data))
|
||||
dispatch_async(handleQueue) {
|
||||
self.anyHandler?(SocketAnyEvent(event: event, items: data))
|
||||
}
|
||||
}
|
||||
|
||||
for handler in handlers where handler.event == event {
|
||||
if let ack = ack {
|
||||
dispatch_async(handleQueue) {[weak self] in
|
||||
dispatch_async(handleQueue) {
|
||||
handler.executeCallback(data, withAck: ack, withSocket: self)
|
||||
}
|
||||
} else {
|
||||
@ -395,7 +399,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
public func off(event: String) {
|
||||
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)
|
||||
}
|
||||
|
||||
/**
|
||||
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.
|
||||
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) {
|
||||
dispatch_async(handleQueue) {[weak self] in
|
||||
if let this = self {
|
||||
SocketParser.parseSocketMessage(msg, socket: this)
|
||||
}
|
||||
dispatch_async(handleQueue) {
|
||||
SocketParser.parseSocketMessage(msg, socket: self)
|
||||
}
|
||||
}
|
||||
|
||||
public func parseBinaryData(data: NSData) {
|
||||
dispatch_async(handleQueue) {[weak self] in
|
||||
if let this = self {
|
||||
SocketParser.parseBinaryData(data, socket: this)
|
||||
}
|
||||
dispatch_async(handleQueue) {
|
||||
SocketParser.parseBinaryData(data, socket: self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -468,19 +502,17 @@ public final class SocketIOClient: NSObject, SocketEngineClient {
|
||||
if reconnectTimer == nil {
|
||||
Logger.log("Starting reconnect", type: logType)
|
||||
|
||||
status = SocketIOClientStatus.Reconnecting
|
||||
status = .Reconnecting
|
||||
|
||||
dispatch_async(dispatch_get_main_queue()) {[weak self] in
|
||||
if let this = self {
|
||||
this.reconnectTimer = NSTimer.scheduledTimerWithTimeInterval(Double(this.reconnectWait),
|
||||
target: this, selector: "_tryReconnect", userInfo: nil, repeats: true)
|
||||
}
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
self.reconnectTimer = NSTimer.scheduledTimerWithTimeInterval(Double(self.reconnectWait),
|
||||
target: self, selector: "_tryReconnect", userInfo: nil, repeats: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@objc private func _tryReconnect() {
|
||||
if status == SocketIOClientStatus.Connected {
|
||||
if status == .Connected {
|
||||
clearReconnectTimer()
|
||||
|
||||
return
|
||||
|
||||
@ -25,8 +25,10 @@
|
||||
import Foundation
|
||||
|
||||
struct SocketPacket {
|
||||
private var currentPlace = 0
|
||||
private let placeholders: Int
|
||||
private var currentPlace = 0
|
||||
|
||||
private static let logType = "SocketPacket"
|
||||
|
||||
let nsp: String
|
||||
let id: Int
|
||||
@ -62,19 +64,12 @@ struct SocketPacket {
|
||||
var binary: [NSData]
|
||||
var data: [AnyObject]
|
||||
var description: String {
|
||||
var better = "SocketPacket {type: ~~0; data: ~~1; " +
|
||||
"id: ~~2; placeholders: ~~3;}"
|
||||
|
||||
better = better["~~0"] ~= String(type.rawValue)
|
||||
better = better["~~1"] ~= String(data)
|
||||
better = better["~~2"] ~= String(id)
|
||||
better = better["~~3"] ~= String(placeholders)
|
||||
|
||||
return better
|
||||
return "SocketPacket {type: \(String(type.rawValue)); data: " +
|
||||
"\(String(data)); id: \(id); placeholders: \(placeholders); nsp: \(nsp)}"
|
||||
}
|
||||
|
||||
var event: String {
|
||||
return data[0] as! String
|
||||
return data[0] as? String ?? String(data[0])
|
||||
}
|
||||
|
||||
var packetString: String {
|
||||
@ -121,7 +116,7 @@ struct SocketPacket {
|
||||
|
||||
message += jsonString! as String + ","
|
||||
} 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 {
|
||||
str = str["\n"] ~= "\\\\n"
|
||||
@ -212,17 +207,13 @@ struct SocketPacket {
|
||||
}
|
||||
|
||||
mutating func fillInPlaceholders() {
|
||||
let newArr = NSMutableArray(array: data)
|
||||
|
||||
for i in 0..<data.count {
|
||||
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 {
|
||||
newArr[i] = _fillInPlaceholders(data[i])
|
||||
data[i] = _fillInPlaceholders(data[i])
|
||||
}
|
||||
}
|
||||
|
||||
data = newArr as [AnyObject]
|
||||
}
|
||||
|
||||
private mutating func _fillInPlaceholders(data: AnyObject) -> AnyObject {
|
||||
@ -287,22 +278,20 @@ private extension SocketPacket {
|
||||
binary.append(bin)
|
||||
|
||||
return placeholder
|
||||
} else if let arr = data as? NSArray {
|
||||
let newArr = NSMutableArray(array: arr)
|
||||
|
||||
} else if var arr = data as? [AnyObject] {
|
||||
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 {
|
||||
let newDict = NSMutableDictionary(dictionary: dict)
|
||||
let mutDict = NSMutableDictionary(dictionary: dict)
|
||||
|
||||
for (key, value) in newDict {
|
||||
newDict[key as! NSCopying] = shred(value, binary: &binary)
|
||||
for (key, value) in dict {
|
||||
mutDict[key as! NSCopying] = shred(value, binary: &binary)
|
||||
}
|
||||
|
||||
return newDict
|
||||
return mutDict
|
||||
} else {
|
||||
return data
|
||||
}
|
||||
|
||||
@ -23,30 +23,26 @@
|
||||
import Foundation
|
||||
|
||||
class SocketParser {
|
||||
|
||||
private static func isCorrectNamespace(nsp: String, _ socket: SocketIOClient) -> Bool {
|
||||
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) {
|
||||
if !isCorrectNamespace(p.nsp, socket) {
|
||||
return
|
||||
}
|
||||
guard isCorrectNamespace(p.nsp, socket) else { return }
|
||||
|
||||
socket.handleAck(p.id, data: p.data)
|
||||
}
|
||||
|
||||
private static func handleBinaryAck(p: SocketPacket, socket: SocketIOClient) {
|
||||
if !isCorrectNamespace(p.nsp, socket) {
|
||||
return
|
||||
}
|
||||
|
||||
socket.waitingData.append(p)
|
||||
}
|
||||
|
||||
private static func handleBinaryEvent(p: SocketPacket, socket: SocketIOClient) {
|
||||
if !isCorrectNamespace(p.nsp, socket) {
|
||||
return
|
||||
}
|
||||
private static func handleBinary(p: SocketPacket, socket: SocketIOClient) {
|
||||
guard isCorrectNamespace(p.nsp, socket) else { return }
|
||||
|
||||
socket.waitingData.append(p)
|
||||
}
|
||||
@ -61,169 +57,115 @@ class SocketParser {
|
||||
}
|
||||
}
|
||||
|
||||
private static func handleEvent(p: SocketPacket, socket: SocketIOClient) {
|
||||
if !isCorrectNamespace(p.nsp, socket) {
|
||||
return
|
||||
static func parseString(message: String) -> SocketPacket? {
|
||||
var parser = SocketStringReader(message: message)
|
||||
|
||||
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,
|
||||
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 namespace: String?
|
||||
var placeholders = -1
|
||||
|
||||
if type == "5" || type == "6" {
|
||||
var buf = ""
|
||||
|
||||
while arr[++i] != "-" {
|
||||
buf += String(arr[i])
|
||||
if i == arr.count {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if let holders = Int(buf) where arr[i] == "-" {
|
||||
if type == .BinaryEvent || type == .BinaryAck {
|
||||
if let holders = Int(parser.readUntilStringOccurence("-")) {
|
||||
placeholders = holders
|
||||
} else {
|
||||
NSLog("Error parsing \(str)")
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if arr[i + 1] == "/" {
|
||||
nsp = ""
|
||||
|
||||
while ++i < arr.count {
|
||||
let c = arr[i]
|
||||
|
||||
if c == "," {
|
||||
break
|
||||
}
|
||||
|
||||
nsp! += String(c)
|
||||
if parser.currentCharacter == "/" {
|
||||
namespace = parser.readUntilStringOccurence(",") ?? parser.readUntilEnd()
|
||||
}
|
||||
|
||||
if !parser.hasNext {
|
||||
return SocketPacket(type: type, id: -1,
|
||||
nsp: namespace ?? "/", placeholders: placeholders)
|
||||
}
|
||||
|
||||
var idString = ""
|
||||
|
||||
while parser.hasNext {
|
||||
if let int = Int(parser.read(1)) {
|
||||
idString += String(int)
|
||||
} else {
|
||||
parser.advanceIndexBy(-2)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if i + 1 >= arr.count {
|
||||
return SocketPacket(type: SocketPacket.PacketType(str: type)!, id: id ?? -1,
|
||||
nsp: nsp ?? "/", placeholders: placeholders)
|
||||
}
|
||||
let d = message[parser.currentIndex.advancedBy(1)..<message.endIndex]
|
||||
let noPlaceholders = d["(\\{\"_placeholder\":true,\"num\":(\\d*)\\})"] ~= "\"~~$2\""
|
||||
let data = parseData(noPlaceholders) as? [AnyObject] ?? [noPlaceholders]
|
||||
|
||||
let next = String(arr[i + 1])
|
||||
|
||||
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
|
||||
return SocketPacket(type: type, data: data, id: Int(idString) ?? -1,
|
||||
nsp: namespace ?? "/", placeholders: placeholders)
|
||||
}
|
||||
|
||||
// Parses data for events
|
||||
static func parseData(data: String) -> AnyObject? {
|
||||
var err: NSError?
|
||||
let stringData = data.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
|
||||
let parsed: AnyObject?
|
||||
|
||||
do {
|
||||
parsed = try NSJSONSerialization.JSONObjectWithData(stringData!,
|
||||
return try NSJSONSerialization.JSONObjectWithData(stringData!,
|
||||
options: NSJSONReadingOptions.MutableContainers)
|
||||
} catch let error as NSError {
|
||||
err = error
|
||||
parsed = nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
// println(err)
|
||||
} catch {
|
||||
Logger.error("Parsing JSON: %@", type: "SocketParser", args: data)
|
||||
return nil
|
||||
}
|
||||
|
||||
return parsed
|
||||
}
|
||||
|
||||
// Parses messages recieved
|
||||
static func parseSocketMessage(stringMessage: String, socket: SocketIOClient) {
|
||||
if stringMessage == "" {
|
||||
static func parseSocketMessage(message: String, socket: SocketIOClient) {
|
||||
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
|
||||
}
|
||||
|
||||
Logger.log("Parsing %@", type: "SocketParser", args: stringMessage)
|
||||
Logger.log("Decoded packet as: %@", type: "SocketParser", args: pack.description)
|
||||
|
||||
let p: SocketPacket
|
||||
|
||||
if let pack = parseString(stringMessage) {
|
||||
p = pack
|
||||
} else {
|
||||
socket.didError("Error parsing packet")
|
||||
return
|
||||
}
|
||||
|
||||
Logger.log("Decoded packet as: %@", type: "SocketParser", args: p.description)
|
||||
|
||||
switch p.type {
|
||||
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:
|
||||
switch pack.type {
|
||||
case .Event:
|
||||
handleEvent(pack, socket: socket)
|
||||
case .Ack:
|
||||
handleAck(pack, socket: socket)
|
||||
case .BinaryEvent:
|
||||
handleBinary(pack, socket: socket)
|
||||
case .BinaryAck:
|
||||
handleBinary(pack, socket: socket)
|
||||
case .Connect:
|
||||
handleConnect(pack, socket: socket)
|
||||
case .Disconnect:
|
||||
socket.didDisconnect("Got Disconnect")
|
||||
case SocketPacket.PacketType.Error:
|
||||
socket.didError("Error: \(p.data)")
|
||||
case .Error:
|
||||
socket.didError("Error: \(pack.data)")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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")
|
||||
return
|
||||
}
|
||||
|
||||
let shouldExecute = socket.waitingData[0].addData(data)
|
||||
let shouldExecute = socket.waitingData[socket.waitingData.count - 1].addData(data)
|
||||
|
||||
if !shouldExecute {
|
||||
guard shouldExecute else {
|
||||
return
|
||||
}
|
||||
|
||||
var packet = socket.waitingData.removeAtIndex(0)
|
||||
var packet = socket.waitingData.removeLast()
|
||||
packet.fillInPlaceholders()
|
||||
|
||||
if packet.type != SocketPacket.PacketType.BinaryAck {
|
||||
if packet.type != .BinaryAck {
|
||||
socket.handleEvent(packet.event, data: packet.args,
|
||||
isInternalMessage: false, wantsAck: packet.id)
|
||||
} else {
|
||||
|
||||
68
SocketIOClientSwift/SocketStringReader.swift
Normal file
68
SocketIOClientSwift/SocketStringReader.swift
Normal 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))
|
||||
}
|
||||
}
|
||||
@ -13,9 +13,9 @@
|
||||
|
||||
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 regex: NSRegularExpression
|
||||
|
||||
@ -36,17 +36,16 @@ public class SwiftRegex: NSObject, BooleanType {
|
||||
}
|
||||
super.init()
|
||||
}
|
||||
|
||||
class func failure(message: String) {
|
||||
print("SwiftRegex: "+message)
|
||||
//assert(false,"SwiftRegex: failed")
|
||||
|
||||
private static func failure(message: String) {
|
||||
fatalError("SwiftRegex: \(message)")
|
||||
}
|
||||
|
||||
final var targetRange: NSRange {
|
||||
|
||||
private final var targetRange: NSRange {
|
||||
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 ) {
|
||||
return (target as NSString).substringWithRange(range)
|
||||
} 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
|
||||
}
|
||||
|
||||
public func range(options: NSMatchingOptions) -> NSRange {
|
||||
func range(options: NSMatchingOptions) -> NSRange {
|
||||
return regex.rangeOfFirstMatchInString(target as String, options: [], range: targetRange)
|
||||
}
|
||||
|
||||
public func match(options: NSMatchingOptions) -> String? {
|
||||
func match(options: NSMatchingOptions) -> String? {
|
||||
return substring(range(options))
|
||||
}
|
||||
|
||||
public func groups() -> [String]? {
|
||||
func groups() -> [String]? {
|
||||
return groupsForMatch(regex.firstMatchInString(target as String, options:
|
||||
NSMatchingOptions.WithoutAnchoringBounds, range: targetRange))
|
||||
}
|
||||
|
||||
func groupsForMatch(match: NSTextCheckingResult!) -> [String]? {
|
||||
private func groupsForMatch(match: NSTextCheckingResult!) -> [String]? {
|
||||
if match != nil {
|
||||
var groups = [String]()
|
||||
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 {
|
||||
return groups()?[groupno]
|
||||
}
|
||||
@ -116,19 +115,19 @@ public class SwiftRegex: NSObject, BooleanType {
|
||||
return matches
|
||||
}
|
||||
|
||||
public func ranges() -> [NSRange] {
|
||||
func ranges() -> [NSRange] {
|
||||
return matchResults().map { $0.range }
|
||||
}
|
||||
|
||||
public func matches() -> [String] {
|
||||
func matches() -> [String] {
|
||||
return matchResults().map( { self.substring($0.range)!})
|
||||
}
|
||||
|
||||
public func allGroups() -> [[String]?] {
|
||||
func allGroups() -> [[String]?] {
|
||||
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>()
|
||||
for match in matchResults() {
|
||||
out[substring(match.rangeAtIndex(1))!] = substring(match.rangeAtIndex(2))!
|
||||
@ -153,31 +152,31 @@ public class SwiftRegex: NSObject, BooleanType {
|
||||
return out as String
|
||||
}
|
||||
|
||||
public var boolValue: Bool {
|
||||
var boolValue: Bool {
|
||||
return doesMatch(nil)
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
public subscript(pattern: String, options: NSRegularExpressionOptions) -> SwiftRegex {
|
||||
subscript(pattern: String, options: NSRegularExpressionOptions) -> SwiftRegex {
|
||||
return SwiftRegex(target: self, pattern: pattern, options: options)
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
public subscript(pattern: String) -> SwiftRegex {
|
||||
subscript(pattern: String) -> SwiftRegex {
|
||||
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.regex.replacementStringForResult( match,
|
||||
inString: left.target as String, offset: 0, template: right )
|
||||
}, options: [])
|
||||
}
|
||||
|
||||
public func ~= (left: SwiftRegex, right: [String]) -> String {
|
||||
func ~= (left: SwiftRegex, right: [String]) -> String {
|
||||
var matchNumber = 0
|
||||
return left.substituteMatches({match, stop -> String in
|
||||
|
||||
@ -190,7 +189,7 @@ public func ~= (left: SwiftRegex, right: [String]) -> String {
|
||||
}, options: [])
|
||||
}
|
||||
|
||||
public func ~= (left: SwiftRegex, right: (String) -> String) -> String {
|
||||
func ~= (left: SwiftRegex, right: (String) -> String) -> String {
|
||||
// return right(left.substring(match.range))
|
||||
return left.substituteMatches(
|
||||
{match, stop -> String in
|
||||
@ -198,7 +197,7 @@ public func ~= (left: SwiftRegex, right: (String) -> String) -> String {
|
||||
}, options: [])
|
||||
}
|
||||
|
||||
public func ~= (left: SwiftRegex, right: ([String]?) -> String) -> String {
|
||||
func ~= (left: SwiftRegex, right: ([String]?) -> String) -> String {
|
||||
return left.substituteMatches({match, stop -> String in
|
||||
return right(left.groupsForMatch(match))
|
||||
}, options: [])
|
||||
|
||||
@ -133,12 +133,19 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
if isCreated {
|
||||
return
|
||||
}
|
||||
unowned let weakSelf = self
|
||||
|
||||
dispatch_async(queue,{
|
||||
|
||||
dispatch_async(queue, { [weak self] in
|
||||
guard let weakSelf = self else {
|
||||
return
|
||||
}
|
||||
|
||||
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.createHTTPRequest()
|
||||
weakSelf.isCreated = false
|
||||
@ -370,19 +377,18 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
}
|
||||
}
|
||||
if totalSize > 0 {
|
||||
unowned let weakSelf = self
|
||||
if validateResponse(buffer, bufferLen: totalSize) {
|
||||
dispatch_async(queue,{
|
||||
weakSelf.connected = true
|
||||
if let connectBlock = weakSelf.onConnect {
|
||||
dispatch_async(queue, {
|
||||
self.connected = true
|
||||
if let connectBlock = self.onConnect {
|
||||
connectBlock()
|
||||
}
|
||||
weakSelf.delegate?.websocketDidConnect(self)
|
||||
self.delegate?.websocketDidConnect(self)
|
||||
})
|
||||
totalSize += 1 //skip the last \n
|
||||
let restSize = bufferLen - totalSize
|
||||
if restSize > 0 {
|
||||
processRawMessage((buffer+totalSize),bufferLen: restSize)
|
||||
processRawMessage((buffer+totalSize), bufferLen: restSize)
|
||||
}
|
||||
return true
|
||||
}
|
||||
@ -515,10 +521,8 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
data = NSData(bytes: UnsafePointer<UInt8>((buffer+offset)), length: Int(len))
|
||||
}
|
||||
if receivedOpcode == OpCode.Pong.rawValue {
|
||||
dispatch_async(queue,{[unowned self] in
|
||||
if let pongBlock = self.onPong {
|
||||
pongBlock()
|
||||
}
|
||||
dispatch_async(queue, {
|
||||
self.onPong?()
|
||||
self.pongDelegate?.websocketDidReceivePong(self)
|
||||
})
|
||||
|
||||
@ -604,25 +608,24 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
dequeueWrite(data, code: OpCode.Pong)
|
||||
} else if response.code == .TextFrame {
|
||||
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)
|
||||
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 {
|
||||
let data = response.buffer! //local copy so it is perverse for writing
|
||||
dispatch_async(queue,{[unowned self] in
|
||||
if let dataBlock = self.onData {
|
||||
dataBlock(data)
|
||||
}
|
||||
dispatch_async(queue) {
|
||||
self.onData?(data)
|
||||
self.delegate?.websocketDidReceiveData(self, data: data)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
readStack.removeLast()
|
||||
return true
|
||||
}
|
||||
@ -723,13 +726,12 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
///used to preform the disconnect delegate
|
||||
private func doDisconnect(error: NSError?) {
|
||||
if !self.didDisconnect {
|
||||
dispatch_async(queue,{[unowned self] in
|
||||
dispatch_async(queue) {
|
||||
self.didDisconnect = true
|
||||
if let disconnect = self.onDisconnect {
|
||||
disconnect(error)
|
||||
}
|
||||
|
||||
self.onDisconnect?(error)
|
||||
self.delegate?.websocketDidDisconnect(self, error: error)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -748,7 +750,7 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
import Foundation
|
||||
import Security
|
||||
|
||||
public class SSLCert {
|
||||
private class SSLCert {
|
||||
var certData: NSData?
|
||||
var key: SecKeyRef?
|
||||
|
||||
@ -759,7 +761,7 @@ public class SSLCert {
|
||||
|
||||
:returns: a representation security object to be used with
|
||||
*/
|
||||
public init(data: NSData) {
|
||||
init(data: NSData) {
|
||||
self.certData = data
|
||||
}
|
||||
|
||||
@ -770,7 +772,7 @@ public class SSLCert {
|
||||
|
||||
:returns: a representation security object to be used with
|
||||
*/
|
||||
public init(key: SecKeyRef) {
|
||||
init(key: SecKeyRef) {
|
||||
self.key = key
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user