Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea0fc9933e | ||
|
|
43827914b7 | ||
|
|
22b9a1e2f2 | ||
|
|
fd66a9fa62 | ||
|
|
998089df91 | ||
|
|
283644b75c | ||
|
|
846897157c | ||
|
|
a49f8f19cf | ||
|
|
531a9784da | ||
|
|
c34a660cae | ||
|
|
9484bc9614 | ||
|
|
d8f65c2804 | ||
|
|
ca3f3e810d | ||
|
|
63021eb995 | ||
|
|
d8e3408565 | ||
|
|
f17575b35c | ||
|
|
58571e5387 | ||
|
|
1a54decd51 | ||
|
|
d982cdc1b2 | ||
|
|
079063e396 | ||
|
|
33d5fd3f10 | ||
|
|
3be5621263 | ||
|
|
81ab71f519 | ||
|
|
bfeec57c04 | ||
|
|
0b09a1357c | ||
|
|
e8dfe589ac | ||
|
|
fcebc870c3 | ||
|
|
eeadccec94 | ||
|
|
fa0d5022cf | ||
|
|
2fdd1313a8 | ||
|
|
61b4628d3e | ||
|
|
77ed87d0d4 | ||
|
|
a6f68e7b70 | ||
|
|
2453f33191 | ||
|
|
bb3d7fbded | ||
|
|
f54153f3d4 | ||
|
|
709ecc30b3 | ||
|
|
72dd2ef364 | ||
|
|
9ec521a6de | ||
|
|
69c67a2b81 | ||
|
|
dd068cb480 | ||
|
|
3abb26565b | ||
|
|
d7d1da704f | ||
|
|
5a5dc70203 | ||
|
|
c049f62028 | ||
|
|
88c139ed0c | ||
|
|
fdfd4dbc4d | ||
|
|
9e0726d61f | ||
|
|
2ee104bb5e | ||
|
|
90bbc9521f | ||
|
|
7a1a0d91f9 | ||
|
|
6cb372e3b9 | ||
|
|
10ffe54b08 | ||
|
|
08d100b9ca | ||
|
|
1b05418674 | ||
|
|
75a4adfbbd | ||
|
|
9bc40fcae1 | ||
|
|
1aa1a83cea | ||
|
|
8a23960e20 | ||
|
|
a5b8202e45 | ||
|
|
918f176c56 | ||
|
|
ef39651bfa | ||
|
|
e7f8f9db1a | ||
|
|
0ccedfd0bf | ||
|
|
0416ecbaac | ||
|
|
21b295f8fa | ||
|
|
a7fb0f847a | ||
|
|
27a767746b | ||
|
|
59e068c853 | ||
|
|
922ed4b575 | ||
|
|
eab7311037 | ||
|
|
7c0c12ba0c | ||
|
|
306fc12cc5 | ||
|
|
7f35e3e1e4 | ||
|
|
cd48abe4cd | ||
|
|
acfbcb6fe1 | ||
|
|
47f5dcbbcd | ||
|
|
a161ed1756 | ||
|
|
3fda340ad1 | ||
|
|
e33309827f | ||
|
|
1753707bf8 | ||
|
|
cc99eae737 | ||
|
|
446cf57978 | ||
|
|
80cee820a4 | ||
|
|
e4c2da515b | ||
|
|
bb4d285928 | ||
|
|
5e5ec2f6b6 | ||
|
|
54aac236b8 | ||
|
|
8b05f922a6 | ||
|
|
f38cf9ed3a | ||
|
|
057be73990 | ||
|
|
ea3bd02f6a | ||
|
|
06f04a046d | ||
|
|
ae27d93464 | ||
|
|
406504b09d | ||
|
|
269bb5a943 | ||
|
|
4be6b58150 | ||
|
|
acefc89b0d | ||
|
|
85e1f31538 | ||
|
|
8d9580900f | ||
|
|
f87ed47723 | ||
|
|
d887c96550 | ||
|
|
6ec3861a4f | ||
|
|
43ec517156 | ||
|
|
f67d3b23bb | ||
|
|
e6ecf34507 | ||
|
|
a1bab214b4 | ||
|
|
1c3ea76829 | ||
|
|
18928c823c | ||
|
|
deac1bbe17 | ||
|
|
96fd2deb51 | ||
|
|
69339cbb65 | ||
|
|
7f7ae0b9f5 | ||
|
|
13718414da | ||
|
|
bfa967cc2a | ||
|
|
a3e5824c22 | ||
|
|
96484e7622 | ||
|
|
8205702afc | ||
|
|
156562902e | ||
|
|
1334b973b9 | ||
|
|
2a322ff5e5 | ||
|
|
20d1ad76af | ||
|
|
8fea5f25fd | ||
|
|
31e2f0ea4b | ||
|
|
7845251fc6 | ||
|
|
379912e280 | ||
|
|
a9cf6885aa | ||
|
|
332ff6f40b | ||
|
|
7adf624dca | ||
|
|
ca4e404125 | ||
|
|
67c41c0107 | ||
|
|
a01e85ba05 | ||
|
|
0588556c17 | ||
|
|
076bbfc782 | ||
|
|
01e5e22e0b | ||
|
|
14487a1beb | ||
|
|
eb5d03c88b | ||
|
|
903c578e75 | ||
|
|
31a41072c3 | ||
|
|
c325706228 | ||
|
|
a0dff2fea4 | ||
|
|
acdb29dca4 | ||
|
|
0c3e25ef3c | ||
|
|
d8ea3a3c11 | ||
|
|
be5764ce59 | ||
|
|
ac28c7541e | ||
|
|
c1eae5a500 | ||
|
|
473d422668 | ||
|
|
fcc202ab04 | ||
|
|
eb56a8de9c | ||
|
|
c2d488e35c | ||
|
|
eb9d2bc744 | ||
|
|
a4e81fee6a | ||
|
|
9489676009 | ||
|
|
6e56869ef0 | ||
|
|
dde941f4af | ||
|
|
3ebc596ab8 | ||
|
|
ce81bb2a33 | ||
|
|
1349b01b2b | ||
|
|
63cbf49448 | ||
|
|
a17f2b6e7a | ||
|
|
a1f24ff281 | ||
|
|
838dade0fa | ||
|
|
d4470a9084 | ||
|
|
affd792334 | ||
|
|
c1b0d3abeb | ||
|
|
38163d29cb | ||
|
|
2952120fc1 | ||
|
|
7641ffef41 | ||
|
|
58d2693910 | ||
|
|
dd28b1747c | ||
|
|
e90ecb81be | ||
|
|
060060f5c2 | ||
|
|
f7b064d80f | ||
|
|
918d40d68c | ||
|
|
01a699c7c6 | ||
|
|
5fffa685e9 | ||
|
|
7b7ccb87da | ||
|
|
93f1cfe9dc | ||
|
|
da1cf9eb89 | ||
|
|
a61f1c8484 | ||
|
|
57731bebf8 | ||
|
|
81d58fbd69 | ||
|
|
c4731dc298 | ||
|
|
18a561f78a | ||
|
|
85019cca09 | ||
|
|
a4361a04b6 | ||
|
|
ffcd841267 | ||
|
|
d308111a8f | ||
|
|
f669267f51 | ||
|
|
98e0c355f9 | ||
|
|
2cae405d29 | ||
|
|
f008f116a6 | ||
|
|
77532acbd3 | ||
|
|
9512c8b9ac | ||
|
|
b0020997c4 | ||
|
|
ce7c9c2c15 | ||
|
|
90f50a1c7e | ||
|
|
182ba0017b | ||
|
|
5b897ddfea | ||
|
|
4e6b686f37 | ||
|
|
78aba627a2 | ||
|
|
9044de53d9 | ||
|
|
e34cb61ae2 | ||
|
|
61ad14f23b | ||
|
|
03c24659f2 | ||
|
|
5e1a19f638 | ||
|
|
1d70305743 | ||
|
|
4c7b3175ca | ||
|
|
5533545adb | ||
|
|
8fa8944672 | ||
|
|
dee508c0f7 | ||
|
|
4de422e7f1 | ||
|
|
4629565aaf | ||
|
|
8b893ad85e | ||
|
|
8b3e4a2c43 | ||
|
|
504d0fbd18 | ||
|
|
6985efd7fb | ||
|
|
6ac69d1c2d | ||
|
|
b8b12313fa | ||
|
|
5388084c79 | ||
|
|
48bcada835 | ||
|
|
cf65f56a1d | ||
|
|
18b8f992d9 | ||
|
|
b576294232 | ||
|
|
d70db2a8be | ||
|
|
457a33c677 | ||
|
|
15954f36f5 | ||
|
|
84752b463a | ||
|
|
bb26dd05f8 | ||
|
|
07f2d7465a | ||
|
|
028afcaa2c | ||
|
|
3ebdd9f7eb | ||
|
|
3e260152cb | ||
|
|
937090458c | ||
|
|
c6d0331d50 | ||
|
|
7765e57a11 | ||
|
|
18c25fabdf | ||
|
|
94f3e3a6b9 | ||
|
|
4551cad9e1 | ||
|
|
560235353d | ||
|
|
f14d9ef5ff | ||
|
|
94d715aaf9 | ||
|
|
1ac05d9790 | ||
|
|
02b1314a3d | ||
|
|
211dc1dd22 | ||
|
|
e7973ba88f | ||
|
|
43ccf6dd45 | ||
|
|
3fbc396d85 | ||
|
|
ecd76d6106 | ||
|
|
50ac79e07e | ||
|
|
5b9537065f | ||
|
|
516d9b3eea | ||
|
|
306ac47168 | ||
|
|
170b1bc836 | ||
|
|
44de79d8c5 | ||
|
|
5d8479ed36 | ||
|
|
3754bd572a | ||
|
|
12b8f3ef1f | ||
|
|
308983c6c7 | ||
|
|
216d8cae1e | ||
|
|
c88febc5bc | ||
|
|
5f179ac278 | ||
|
|
f826ca4b8e | ||
|
|
b53d22f3a2 | ||
|
|
6d6ac0fc74 | ||
|
|
ca00926647 |
No files matched your search
+43
@@ -0,0 +1,43 @@
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# Xcode
|
||||
build/
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
!default.mode1v3
|
||||
*.mode2v3
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
xcuserdata
|
||||
*.xccheckout
|
||||
*.moved-aside
|
||||
DerivedData
|
||||
*.hmap
|
||||
*.ipa
|
||||
*.xcuserstate
|
||||
@@ -1,16 +1,74 @@
|
||||
Socket.IO-Client-Swift
|
||||
======================
|
||||
#Socket.IO-Client-Swift
|
||||
Socket.IO-client for iOS/OS X.
|
||||
|
||||
Socket.IO-client for Swift. Supports ws/wss/polling connections and binary. For socket.io 1.0+ and Swift 1.1.
|
||||
##Example
|
||||
```swift
|
||||
let socket = SocketIOClient(socketURL: "localhost:8080")
|
||||
|
||||
For Swift 1.2 use the 1.2 branch.
|
||||
socket.on("connect") {data, ack in
|
||||
println("socket connected")
|
||||
}
|
||||
|
||||
Installation
|
||||
============
|
||||
socket.on("currentAmount") {data, ack in
|
||||
if let cur = data?[0] as? Double {
|
||||
socket.emitWithAck("canUpdate", cur)(timeout: 0) {data in
|
||||
socket.emit("update", ["amount": cur + 2.50])
|
||||
}
|
||||
|
||||
ack?("Got your currentAmount", "dude")
|
||||
}
|
||||
}
|
||||
|
||||
socket.connect()
|
||||
```
|
||||
|
||||
##Objective-C Example
|
||||
```objective-c
|
||||
SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" options:nil];
|
||||
|
||||
[socket on:@"connect" callback:^(NSArray* data, void (^ack)(NSArray*)) {
|
||||
NSLog(@"socket connected");
|
||||
}];
|
||||
|
||||
[socket on:@"currentAmount" callback:^(NSArray* data, void (^ack)(NSArray*)) {
|
||||
double cur = [[data objectAtIndex:0] floatValue];
|
||||
|
||||
[socket emitWithAck:@"canUpdate" withItems:@[@(cur)]](0, ^(NSArray* data) {
|
||||
[socket emit:@"update" withItems:@[@{@"amount": @(cur + 2.50)}]];
|
||||
});
|
||||
|
||||
ack(@[@"Got your currentAmount, ", @"dude"]);
|
||||
}];
|
||||
|
||||
[socket connect];
|
||||
|
||||
```
|
||||
|
||||
##Features
|
||||
- Supports socket.io 1.0+
|
||||
- Supports binary
|
||||
- Supports Polling and WebSockets
|
||||
- Supports TLS/SSL
|
||||
- Can be used from Objective-C
|
||||
|
||||
##Installation
|
||||
Requires Swift 1.2/Xcode 6.3
|
||||
|
||||
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.3.8 # Or latest version
|
||||
```
|
||||
|
||||
Run `carthage update`.
|
||||
|
||||
Manually (iOS 7+)
|
||||
-----------------
|
||||
1. Copy the SwiftIO folder into your Xcode project!
|
||||
1. Copy the SocketIOClientSwift folder into your Xcode project. (Make sure you add the files to your target(s))
|
||||
2. If you plan on using this from Objective-C, read [this](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html) on exposing Swift code to Objective-C.
|
||||
|
||||
CocoaPods 0.36.0 or later (iOS 8+)
|
||||
------------------
|
||||
@@ -21,7 +79,7 @@ source 'https://github.com/CocoaPods/Specs.git'
|
||||
platform :ios, '8.0'
|
||||
use_frameworks!
|
||||
|
||||
pod 'Socket.IO-Client-Swift', '~> 1.3.2' # Or latest version
|
||||
pod 'Socket.IO-Client-Swift', '~> 2.3.8' # Or latest version
|
||||
```
|
||||
|
||||
Install pods:
|
||||
@@ -30,119 +88,65 @@ Install pods:
|
||||
$ pod install
|
||||
```
|
||||
|
||||
Import in your swift file:
|
||||
Import the module:
|
||||
|
||||
Swift:
|
||||
```swift
|
||||
import Socket_IO_Client_Swift
|
||||
```
|
||||
|
||||
API
|
||||
===
|
||||
Objective-C:
|
||||
```Objective-C
|
||||
#import <Socket_IO_Client_Swift/Socket_IO_Client_Swift-Swift.h>
|
||||
```
|
||||
|
||||
##API
|
||||
Constructors
|
||||
-----------
|
||||
`init(socketURL: String, opts:NSDictionary? = nil)` - Constructs a new client for the given URL. opts can be omitted (will use default values. See example)
|
||||
`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.
|
||||
|
||||
Options
|
||||
-------
|
||||
- `connectParams: [String: AnyObject]?` - Dictionary whose contents will be passed with the connection.
|
||||
- `reconnects: Bool` Default is `true`
|
||||
- `reconnectAttempts: Int` Default is `-1` (infinite tries)
|
||||
- `reconnectWait: Int` Default is `10`
|
||||
- `forcePolling: Bool` Default is `false`. `true` forces the client to use xhr-polling.
|
||||
- `forceWebsockets: Bool` Default is `false`. `true` forces the client to use WebSockets.
|
||||
- `nsp: String` Default is `"/"`. Connects to a namespace.
|
||||
- `cookies: [NSHTTPCookie]?` An array of NSHTTPCookies. Passed during the handshake. Default is nil.
|
||||
- `log: Bool` If `true` socket will log debug messages. Default is false.
|
||||
- `sessionDelegate: NSURLSessionDelegate` Sets an NSURLSessionDelegate for the underlying engine. Useful if you need to handle self-signed certs. Default is nil.
|
||||
- `path: String` - If the server uses a custom path. ex: `"/swift"`. Default is `""`
|
||||
- `extraHeaders: [String: String]?` - Adds custom headers to the initial request. Default is nil.
|
||||
|
||||
Methods
|
||||
-------
|
||||
1. `socket.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. `socket.onAny(callback:((event:String, items:AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event.
|
||||
3. `socket.emit(event:String, _ args:AnyObject...)` - Sends a message. Can send multiple args.
|
||||
4. `socket.emitObjc(event:String, withItems items:[AnyObject])` - `emit` for Objective-C
|
||||
5. `socket.emitWithAck(event:String, _ args:AnyObject...) -> SocketAckHandler` - Sends a message that requests an acknowledgement from the server. Returns a SocketAckHandler which you can use to add an onAck handler. See example.
|
||||
6. `socket.emitWithAckObjc(event:String, withItems items:[AnyObject]) -> SocketAckHandler` - `emitWithAck` for Objective-C.
|
||||
7. `socket.connect()` - Establishes a connection to the server. A "connect" event is fired upon successful connection.
|
||||
8. `socket.connectWithParams(params:[String: AnyObject])` - Establishes a connection to the server passing the specified params. A "connect" event is fired upon successful connection.
|
||||
9. `socket.close()` - Closes the socket. Once a socket is closed it should not be reopened.
|
||||
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. `onAny(callback:((event:String, items:AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event.
|
||||
3. `emit(event:String, _ items:AnyObject...)` - Sends a message. Can send multiple items.
|
||||
4. `emit(event:String, withItems items:[AnyObject])` - `emit` for Objective-C
|
||||
5. `emitWithAck(event:String, _ items:AnyObject...) -> (timeout:UInt64, callback:(NSArray?) -> Void) -> Void` - Sends a message that requests an acknowledgement from the server. Returns a function which you can use to add a handler. See example. Note: The message is not sent until you call the returned function.
|
||||
6. `emitWithAck(event:String, withItems items:[AnyObject]) -> (UInt64, (NSArray?) -> Void) -> Void` - `emitWithAck` for Objective-C. Note: The message is not sent until you call the returned function.
|
||||
7. `connect()` - Establishes a connection to the server. A "connect" event is fired upon successful connection.
|
||||
8. `connect(#timeoutAfter:Int, withTimeoutHandler handler:(() -> Void)?)` - Connect to the server. If it isn't connected after timeoutAfter seconds, the handler is called.
|
||||
9. `close(#fast:Bool)` - Closes the socket. Once a socket is closed it should not be reopened. Pass true to fast if you're closing from a background task.
|
||||
10. `reconnect()` - Causes the client to reconnect to the server.
|
||||
11. `joinNamespace()` - Causes the client to join nsp. Shouldn't need to be called unless you change nsp manually.
|
||||
12. `leaveNamespace()` - Causes the client to leave the nsp and go back to /
|
||||
|
||||
Events
|
||||
Client Events
|
||||
------
|
||||
1. `connect` - Emitted when on a successful connection.
|
||||
2. `disconnect` - Emitted when the connection is closed.
|
||||
3. `error` - Emitted if the websocket encounters an error.
|
||||
3. `error` - Emitted on an error.
|
||||
4. `reconnect` - Emitted when the connection is starting to reconnect.
|
||||
5. `reconnectAttempt` - Emitted when attempting to reconnect.
|
||||
|
||||
Example
|
||||
=======
|
||||
```swift
|
||||
// opts can be omitted, will use default values
|
||||
let socket = SocketIOClient(socketURL: "https://localhost:8080", opts: [
|
||||
"reconnects": true, // Default is true
|
||||
"reconnectAttempts": 5, // Default is -1 (infinite tries)
|
||||
"reconnectWait": 5, // Default is 10
|
||||
"nsp": "swift", // connects to the specified namespace. Default is /
|
||||
"forcePolling": true, // if true, the socket will only use XHR polling, Default is false (polling/WebSockets)
|
||||
"cookies": nil // An array of NSHTTPCookies. Passed during handshake. Default is nil
|
||||
])
|
||||
|
||||
// Called on every event
|
||||
socket.onAny {println("got event: \($0.event) with items \($0.items)")}
|
||||
|
||||
// Socket Events
|
||||
socket.on("connect") {data, ack in
|
||||
println("socket connected")
|
||||
|
||||
// Sending messages
|
||||
socket.emit("testEcho")
|
||||
|
||||
socket.emit("testObject", [
|
||||
"data": true
|
||||
])
|
||||
|
||||
// Sending multiple items per message
|
||||
socket.emit("multTest", [1], 1.4, 1, "true",
|
||||
true, ["test": "foo"], "bar")
|
||||
}
|
||||
|
||||
// Requesting acks, and responding to acks
|
||||
socket.on("ackEvent") {data, ack in
|
||||
if let str = data?[0] as? String {
|
||||
println("Got ackEvent")
|
||||
}
|
||||
|
||||
// data is an array
|
||||
if let int = data?[1] as? Int {
|
||||
println("Got int")
|
||||
}
|
||||
|
||||
// You can specify a custom timeout interval. 0 means no timeout.
|
||||
socket.emitWithAck("ackTest", "test").onAck(0) {data in
|
||||
println(data?[0])
|
||||
}
|
||||
|
||||
ack?("Got your event", "dude")
|
||||
}
|
||||
|
||||
socket.on("jsonTest") {data, ack in
|
||||
if let json = data?[0] as? NSDictionary {
|
||||
println(json["test"]!) // foo bar
|
||||
}
|
||||
}
|
||||
|
||||
// Connecting
|
||||
socket.connect()
|
||||
```
|
||||
|
||||
Objective-C Example
|
||||
===================
|
||||
```objective-c
|
||||
SocketIOClient* socket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" options:nil];
|
||||
|
||||
[socket on: @"connect" callback: ^(NSArray* data, void (^ack)(NSArray*)) {
|
||||
NSLog(@"connected");
|
||||
[socket emitObjc:@"echo" withItems:@[@"echo test"]];
|
||||
[[socket emitWithAckObjc:@"ackack" withItems:@[@"test"]] onAck:0 withCallback:^(NSArray* data) {
|
||||
NSLog(@"Got data");
|
||||
}];
|
||||
}];
|
||||
|
||||
```
|
||||
|
||||
Detailed Example
|
||||
================
|
||||
##Detailed Example
|
||||
A more detailed example can be found [here](https://github.com/nuclearace/socket.io-client-swift-example)
|
||||
|
||||
License
|
||||
=======
|
||||
##License
|
||||
MIT
|
||||
@@ -1,19 +1,19 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "Socket.IO-Client-Swift"
|
||||
s.version = "1.3.2"
|
||||
s.summary = "Socket.IO-client for Swift"
|
||||
s.version = "2.3.8"
|
||||
s.summary = "Socket.IO-client for iOS and OS X"
|
||||
s.description = <<-DESC
|
||||
Socket.IO-client for Swift.
|
||||
Socket.IO-client for iOS and OS X.
|
||||
Supports ws/wss/polling connections and binary.
|
||||
For socket.io 1.0+ and Swift 1.1.
|
||||
For socket.io 1.0+ and Swift 1.2.
|
||||
DESC
|
||||
s.homepage = "https://github.com/socketio/socket.io-client-swift"
|
||||
s.license = { :type => 'MIT' }
|
||||
s.author = { "Erik" => "nuclear.ace@gmail.com" }
|
||||
s.ios.deployment_target = '8.0'
|
||||
s.osx.deployment_target = '10.10'
|
||||
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v1.3.2' }
|
||||
s.source_files = "SwiftIO/**/*.swift"
|
||||
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v2.3.8' }
|
||||
s.source_files = "SocketIOClientSwift/**/*.swift"
|
||||
s.requires_arc = true
|
||||
# s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files
|
||||
end
|
||||
@@ -0,0 +1,935 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 46;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
572EF21F1B51F16C00EEBB58 /* SocketIO-iOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 572EF21E1B51F16C00EEBB58 /* SocketIO-iOS.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
572EF2251B51F16C00EEBB58 /* SocketIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 572EF2191B51F16C00EEBB58 /* SocketIO.framework */; };
|
||||
572EF22C1B51F16C00EEBB58 /* SocketIO_iOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 572EF22B1B51F16C00EEBB58 /* SocketIO_iOSTests.swift */; };
|
||||
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 */; };
|
||||
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 */; };
|
||||
5764DF8C1B51F254004FF46E /* SocketAnyEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */; };
|
||||
5764DF8D1B51F254004FF46E /* SocketEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7E1B51F254004FF46E /* SocketEngine.swift */; };
|
||||
5764DF8E1B51F254004FF46E /* SocketEngine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7E1B51F254004FF46E /* SocketEngine.swift */; };
|
||||
5764DF8F1B51F254004FF46E /* SocketEngineClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7F1B51F254004FF46E /* SocketEngineClient.swift */; };
|
||||
5764DF901B51F254004FF46E /* SocketEngineClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF7F1B51F254004FF46E /* SocketEngineClient.swift */; };
|
||||
5764DF911B51F254004FF46E /* SocketEventHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF801B51F254004FF46E /* SocketEventHandler.swift */; };
|
||||
5764DF921B51F254004FF46E /* SocketEventHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF801B51F254004FF46E /* SocketEventHandler.swift */; };
|
||||
5764DF931B51F254004FF46E /* SocketFixUTF8.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF811B51F254004FF46E /* SocketFixUTF8.swift */; };
|
||||
5764DF941B51F254004FF46E /* SocketFixUTF8.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF811B51F254004FF46E /* SocketFixUTF8.swift */; };
|
||||
5764DF951B51F254004FF46E /* SocketIOClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF821B51F254004FF46E /* SocketIOClient.swift */; };
|
||||
5764DF961B51F254004FF46E /* SocketIOClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF821B51F254004FF46E /* SocketIOClient.swift */; };
|
||||
5764DF971B51F254004FF46E /* SocketLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF831B51F254004FF46E /* SocketLogger.swift */; };
|
||||
5764DF981B51F254004FF46E /* SocketLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF831B51F254004FF46E /* SocketLogger.swift */; };
|
||||
5764DF991B51F254004FF46E /* SocketPacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF841B51F254004FF46E /* SocketPacket.swift */; };
|
||||
5764DF9A1B51F254004FF46E /* SocketPacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF841B51F254004FF46E /* SocketPacket.swift */; };
|
||||
5764DF9B1B51F254004FF46E /* SocketParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF851B51F254004FF46E /* SocketParser.swift */; };
|
||||
5764DF9C1B51F254004FF46E /* SocketParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF851B51F254004FF46E /* SocketParser.swift */; };
|
||||
5764DF9D1B51F254004FF46E /* SocketTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF861B51F254004FF46E /* SocketTypes.swift */; };
|
||||
5764DF9E1B51F254004FF46E /* SocketTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF861B51F254004FF46E /* SocketTypes.swift */; };
|
||||
5764DF9F1B51F254004FF46E /* SwiftRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF871B51F254004FF46E /* SwiftRegex.swift */; };
|
||||
5764DFA01B51F254004FF46E /* SwiftRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF871B51F254004FF46E /* SwiftRegex.swift */; };
|
||||
5764DFA11B51F254004FF46E /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF881B51F254004FF46E /* WebSocket.swift */; };
|
||||
5764DFA21B51F254004FF46E /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5764DF881B51F254004FF46E /* WebSocket.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
572EF2261B51F16C00EEBB58 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 572EF20E1B51F12F00EEBB58 /* Project object */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = 572EF2181B51F16C00EEBB58;
|
||||
remoteInfo = "SocketIO-iOS";
|
||||
};
|
||||
572EF2441B51F18A00EEBB58 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 572EF20E1B51F12F00EEBB58 /* Project object */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = 572EF2371B51F18A00EEBB58;
|
||||
remoteInfo = "SocketIO-Mac";
|
||||
};
|
||||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
572EF2191B51F16C00EEBB58 /* SocketIO.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SocketIO.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
572EF21D1B51F16C00EEBB58 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
572EF21E1B51F16C00EEBB58 /* SocketIO-iOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SocketIO-iOS.h"; sourceTree = "<group>"; };
|
||||
572EF2241B51F16C00EEBB58 /* SocketIO-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SocketIO-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
572EF22A1B51F16C00EEBB58 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
572EF22B1B51F16C00EEBB58 /* SocketIO_iOSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketIO_iOSTests.swift; sourceTree = "<group>"; };
|
||||
572EF2381B51F18A00EEBB58 /* SocketIO.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SocketIO.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
572EF23B1B51F18A00EEBB58 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
572EF23C1B51F18A00EEBB58 /* SocketIO-Mac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SocketIO-Mac.h"; sourceTree = "<group>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
5764DF7F1B51F254004FF46E /* SocketEngineClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketEngineClient.swift; path = SocketIOClientSwift/SocketEngineClient.swift; sourceTree = "<group>"; };
|
||||
5764DF801B51F254004FF46E /* SocketEventHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketEventHandler.swift; path = SocketIOClientSwift/SocketEventHandler.swift; sourceTree = "<group>"; };
|
||||
5764DF811B51F254004FF46E /* SocketFixUTF8.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketFixUTF8.swift; path = SocketIOClientSwift/SocketFixUTF8.swift; sourceTree = "<group>"; };
|
||||
5764DF821B51F254004FF46E /* SocketIOClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketIOClient.swift; path = SocketIOClientSwift/SocketIOClient.swift; sourceTree = "<group>"; };
|
||||
5764DF831B51F254004FF46E /* SocketLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketLogger.swift; path = SocketIOClientSwift/SocketLogger.swift; sourceTree = "<group>"; };
|
||||
5764DF841B51F254004FF46E /* SocketPacket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketPacket.swift; path = SocketIOClientSwift/SocketPacket.swift; sourceTree = "<group>"; };
|
||||
5764DF851B51F254004FF46E /* SocketParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketParser.swift; path = SocketIOClientSwift/SocketParser.swift; sourceTree = "<group>"; };
|
||||
5764DF861B51F254004FF46E /* SocketTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketTypes.swift; path = SocketIOClientSwift/SocketTypes.swift; sourceTree = "<group>"; };
|
||||
5764DF871B51F254004FF46E /* SwiftRegex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftRegex.swift; path = SocketIOClientSwift/SwiftRegex.swift; sourceTree = "<group>"; };
|
||||
5764DF881B51F254004FF46E /* WebSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WebSocket.swift; path = SocketIOClientSwift/WebSocket.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
572EF2151B51F16C00EEBB58 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
572EF2211B51F16C00EEBB58 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
572EF2251B51F16C00EEBB58 /* SocketIO.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
572EF2341B51F18A00EEBB58 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
572EF23F1B51F18A00EEBB58 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
572EF2431B51F18A00EEBB58 /* SocketIO.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
572EF20D1B51F12F00EEBB58 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
5764DF7B1B51F24A004FF46E /* Source */,
|
||||
572EF21B1B51F16C00EEBB58 /* SocketIO-iOS */,
|
||||
572EF2281B51F16C00EEBB58 /* SocketIO-iOSTests */,
|
||||
572EF2391B51F18A00EEBB58 /* SocketIO-Mac */,
|
||||
572EF2461B51F18A00EEBB58 /* SocketIO-MacTests */,
|
||||
572EF21A1B51F16C00EEBB58 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
572EF21A1B51F16C00EEBB58 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
572EF2191B51F16C00EEBB58 /* SocketIO.framework */,
|
||||
572EF2241B51F16C00EEBB58 /* SocketIO-iOSTests.xctest */,
|
||||
572EF2381B51F18A00EEBB58 /* SocketIO.framework */,
|
||||
572EF2421B51F18A00EEBB58 /* SocketIO-MacTests.xctest */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
572EF21B1B51F16C00EEBB58 /* SocketIO-iOS */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
572EF21E1B51F16C00EEBB58 /* SocketIO-iOS.h */,
|
||||
572EF21C1B51F16C00EEBB58 /* Supporting Files */,
|
||||
);
|
||||
path = "SocketIO-iOS";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
572EF21C1B51F16C00EEBB58 /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
572EF21D1B51F16C00EEBB58 /* Info.plist */,
|
||||
);
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
572EF2281B51F16C00EEBB58 /* SocketIO-iOSTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
572EF22B1B51F16C00EEBB58 /* SocketIO_iOSTests.swift */,
|
||||
572EF2291B51F16C00EEBB58 /* Supporting Files */,
|
||||
);
|
||||
path = "SocketIO-iOSTests";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
572EF2291B51F16C00EEBB58 /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
572EF22A1B51F16C00EEBB58 /* Info.plist */,
|
||||
);
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
572EF2391B51F18A00EEBB58 /* SocketIO-Mac */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
572EF23C1B51F18A00EEBB58 /* SocketIO-Mac.h */,
|
||||
572EF23A1B51F18A00EEBB58 /* Supporting Files */,
|
||||
);
|
||||
path = "SocketIO-Mac";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
572EF23A1B51F18A00EEBB58 /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
572EF23B1B51F18A00EEBB58 /* Info.plist */,
|
||||
);
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
572EF2461B51F18A00EEBB58 /* SocketIO-MacTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
572EF2491B51F18A00EEBB58 /* SocketIO_MacTests.swift */,
|
||||
572EF2471B51F18A00EEBB58 /* Supporting Files */,
|
||||
);
|
||||
path = "SocketIO-MacTests";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
572EF2471B51F18A00EEBB58 /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
572EF2481B51F18A00EEBB58 /* Info.plist */,
|
||||
);
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
5764DF7B1B51F24A004FF46E /* Source */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
5764DF7C1B51F254004FF46E /* SocketAckManager.swift */,
|
||||
5764DF7D1B51F254004FF46E /* SocketAnyEvent.swift */,
|
||||
5764DF7E1B51F254004FF46E /* SocketEngine.swift */,
|
||||
5764DF7F1B51F254004FF46E /* SocketEngineClient.swift */,
|
||||
5764DF801B51F254004FF46E /* SocketEventHandler.swift */,
|
||||
5764DF811B51F254004FF46E /* SocketFixUTF8.swift */,
|
||||
5764DF821B51F254004FF46E /* SocketIOClient.swift */,
|
||||
5764DF831B51F254004FF46E /* SocketLogger.swift */,
|
||||
5764DF841B51F254004FF46E /* SocketPacket.swift */,
|
||||
5764DF851B51F254004FF46E /* SocketParser.swift */,
|
||||
5764DF861B51F254004FF46E /* SocketTypes.swift */,
|
||||
5764DF871B51F254004FF46E /* SwiftRegex.swift */,
|
||||
5764DF881B51F254004FF46E /* WebSocket.swift */,
|
||||
);
|
||||
name = Source;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXHeadersBuildPhase section */
|
||||
572EF2161B51F16C00EEBB58 /* Headers */ = {
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
572EF21F1B51F16C00EEBB58 /* SocketIO-iOS.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
572EF2351B51F18A00EEBB58 /* Headers */ = {
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
572EF23D1B51F18A00EEBB58 /* SocketIO-Mac.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXHeadersBuildPhase section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
572EF2181B51F16C00EEBB58 /* SocketIO-iOS */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 572EF22D1B51F16C00EEBB58 /* Build configuration list for PBXNativeTarget "SocketIO-iOS" */;
|
||||
buildPhases = (
|
||||
572EF2141B51F16C00EEBB58 /* Sources */,
|
||||
572EF2151B51F16C00EEBB58 /* Frameworks */,
|
||||
572EF2161B51F16C00EEBB58 /* Headers */,
|
||||
572EF2171B51F16C00EEBB58 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = "SocketIO-iOS";
|
||||
productName = "SocketIO-iOS";
|
||||
productReference = 572EF2191B51F16C00EEBB58 /* SocketIO.framework */;
|
||||
productType = "com.apple.product-type.framework";
|
||||
};
|
||||
572EF2231B51F16C00EEBB58 /* SocketIO-iOSTests */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 572EF2301B51F16C00EEBB58 /* Build configuration list for PBXNativeTarget "SocketIO-iOSTests" */;
|
||||
buildPhases = (
|
||||
572EF2201B51F16C00EEBB58 /* Sources */,
|
||||
572EF2211B51F16C00EEBB58 /* Frameworks */,
|
||||
572EF2221B51F16C00EEBB58 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
572EF2271B51F16C00EEBB58 /* PBXTargetDependency */,
|
||||
);
|
||||
name = "SocketIO-iOSTests";
|
||||
productName = "SocketIO-iOSTests";
|
||||
productReference = 572EF2241B51F16C00EEBB58 /* SocketIO-iOSTests.xctest */;
|
||||
productType = "com.apple.product-type.bundle.unit-test";
|
||||
};
|
||||
572EF2371B51F18A00EEBB58 /* SocketIO-Mac */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 572EF24B1B51F18A00EEBB58 /* Build configuration list for PBXNativeTarget "SocketIO-Mac" */;
|
||||
buildPhases = (
|
||||
572EF2331B51F18A00EEBB58 /* Sources */,
|
||||
572EF2341B51F18A00EEBB58 /* Frameworks */,
|
||||
572EF2351B51F18A00EEBB58 /* Headers */,
|
||||
572EF2361B51F18A00EEBB58 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = "SocketIO-Mac";
|
||||
productName = "SocketIO-Mac";
|
||||
productReference = 572EF2381B51F18A00EEBB58 /* SocketIO.framework */;
|
||||
productType = "com.apple.product-type.framework";
|
||||
};
|
||||
572EF2411B51F18A00EEBB58 /* SocketIO-MacTests */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 572EF24E1B51F18A00EEBB58 /* Build configuration list for PBXNativeTarget "SocketIO-MacTests" */;
|
||||
buildPhases = (
|
||||
572EF23E1B51F18A00EEBB58 /* Sources */,
|
||||
572EF23F1B51F18A00EEBB58 /* Frameworks */,
|
||||
572EF2401B51F18A00EEBB58 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
572EF2451B51F18A00EEBB58 /* PBXTargetDependency */,
|
||||
);
|
||||
name = "SocketIO-MacTests";
|
||||
productName = "SocketIO-MacTests";
|
||||
productReference = 572EF2421B51F18A00EEBB58 /* SocketIO-MacTests.xctest */;
|
||||
productType = "com.apple.product-type.bundle.unit-test";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
572EF20E1B51F12F00EEBB58 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0700;
|
||||
LastUpgradeCheck = 0640;
|
||||
TargetAttributes = {
|
||||
572EF2181B51F16C00EEBB58 = {
|
||||
CreatedOnToolsVersion = 6.4;
|
||||
};
|
||||
572EF2231B51F16C00EEBB58 = {
|
||||
CreatedOnToolsVersion = 6.4;
|
||||
};
|
||||
572EF2371B51F18A00EEBB58 = {
|
||||
CreatedOnToolsVersion = 6.4;
|
||||
};
|
||||
572EF2411B51F18A00EEBB58 = {
|
||||
CreatedOnToolsVersion = 6.4;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 572EF2111B51F12F00EEBB58 /* Build configuration list for PBXProject "Socket.IO-Client-Swift" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
);
|
||||
mainGroup = 572EF20D1B51F12F00EEBB58;
|
||||
productRefGroup = 572EF21A1B51F16C00EEBB58 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
572EF2181B51F16C00EEBB58 /* SocketIO-iOS */,
|
||||
572EF2231B51F16C00EEBB58 /* SocketIO-iOSTests */,
|
||||
572EF2371B51F18A00EEBB58 /* SocketIO-Mac */,
|
||||
572EF2411B51F18A00EEBB58 /* SocketIO-MacTests */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
572EF2171B51F16C00EEBB58 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
572EF2221B51F16C00EEBB58 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
572EF2361B51F18A00EEBB58 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
572EF2401B51F18A00EEBB58 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
572EF2141B51F16C00EEBB58 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
5764DF8D1B51F254004FF46E /* SocketEngine.swift in Sources */,
|
||||
5764DF9B1B51F254004FF46E /* SocketParser.swift in Sources */,
|
||||
5764DF9D1B51F254004FF46E /* SocketTypes.swift in Sources */,
|
||||
5764DF8F1B51F254004FF46E /* SocketEngineClient.swift in Sources */,
|
||||
5764DF911B51F254004FF46E /* SocketEventHandler.swift in Sources */,
|
||||
5764DF931B51F254004FF46E /* SocketFixUTF8.swift in Sources */,
|
||||
5764DF951B51F254004FF46E /* SocketIOClient.swift in Sources */,
|
||||
5764DF8B1B51F254004FF46E /* SocketAnyEvent.swift in Sources */,
|
||||
5764DF971B51F254004FF46E /* SocketLogger.swift in Sources */,
|
||||
5764DFA11B51F254004FF46E /* WebSocket.swift in Sources */,
|
||||
5764DF991B51F254004FF46E /* SocketPacket.swift in Sources */,
|
||||
5764DF891B51F254004FF46E /* SocketAckManager.swift in Sources */,
|
||||
5764DF9F1B51F254004FF46E /* SwiftRegex.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
572EF2201B51F16C00EEBB58 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
572EF22C1B51F16C00EEBB58 /* SocketIO_iOSTests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
572EF2331B51F18A00EEBB58 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
5764DF8E1B51F254004FF46E /* SocketEngine.swift in Sources */,
|
||||
5764DF9C1B51F254004FF46E /* SocketParser.swift in Sources */,
|
||||
5764DF9E1B51F254004FF46E /* SocketTypes.swift in Sources */,
|
||||
5764DF901B51F254004FF46E /* SocketEngineClient.swift in Sources */,
|
||||
5764DF921B51F254004FF46E /* SocketEventHandler.swift in Sources */,
|
||||
5764DF941B51F254004FF46E /* SocketFixUTF8.swift in Sources */,
|
||||
5764DF961B51F254004FF46E /* SocketIOClient.swift in Sources */,
|
||||
5764DF8C1B51F254004FF46E /* SocketAnyEvent.swift in Sources */,
|
||||
5764DF981B51F254004FF46E /* SocketLogger.swift in Sources */,
|
||||
5764DFA21B51F254004FF46E /* WebSocket.swift in Sources */,
|
||||
5764DF9A1B51F254004FF46E /* SocketPacket.swift in Sources */,
|
||||
5764DF8A1B51F254004FF46E /* SocketAckManager.swift in Sources */,
|
||||
5764DFA01B51F254004FF46E /* SwiftRegex.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
572EF23E1B51F18A00EEBB58 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
572EF24A1B51F18A00EEBB58 /* SocketIO_MacTests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXTargetDependency section */
|
||||
572EF2271B51F16C00EEBB58 /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = 572EF2181B51F16C00EEBB58 /* SocketIO-iOS */;
|
||||
targetProxy = 572EF2261B51F16C00EEBB58 /* PBXContainerItemProxy */;
|
||||
};
|
||||
572EF2451B51F18A00EEBB58 /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = 572EF2371B51F18A00EEBB58 /* SocketIO-Mac */;
|
||||
targetProxy = 572EF2441B51F18A00EEBB58 /* PBXContainerItemProxy */;
|
||||
};
|
||||
/* End PBXTargetDependency section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
572EF2121B51F12F00EEBB58 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
PRODUCT_NAME = SocketIO;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
572EF2131B51F12F00EEBB58 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
PRODUCT_NAME = SocketIO;
|
||||
SWIFT_WHOLE_MODULE_OPTIMIZATION = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
572EF22E1B51F16C00EEBB58 /* 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 = iphoneos;
|
||||
SKIP_INSTALL = YES;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
572EF22F1B51F16C00EEBB58 /* 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 = iphoneos;
|
||||
SKIP_INSTALL = YES;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VALIDATE_PRODUCT = YES;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
572EF2311B51F16C00EEBB58 /* 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;
|
||||
};
|
||||
572EF2321B51F16C00EEBB58 /* 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;
|
||||
};
|
||||
572EF24C1B51F18A00EEBB58 /* 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;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
FRAMEWORK_VERSION = A;
|
||||
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-Mac/Info.plist";
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
SKIP_INSTALL = YES;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
572EF24D1B51F18A00EEBB58 /* 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;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
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;
|
||||
FRAMEWORK_VERSION = A;
|
||||
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-Mac/Info.plist";
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
SKIP_INSTALL = YES;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
572EF24F1B51F18A00EEBB58 /* 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;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(DEVELOPER_FRAMEWORKS_DIR)",
|
||||
"$(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-MacTests/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
572EF2501B51F18A00EEBB58 /* 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;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(DEVELOPER_FRAMEWORKS_DIR)",
|
||||
"$(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-MacTests/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
572EF2111B51F12F00EEBB58 /* Build configuration list for PBXProject "Socket.IO-Client-Swift" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
572EF2121B51F12F00EEBB58 /* Debug */,
|
||||
572EF2131B51F12F00EEBB58 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
572EF22D1B51F16C00EEBB58 /* Build configuration list for PBXNativeTarget "SocketIO-iOS" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
572EF22E1B51F16C00EEBB58 /* Debug */,
|
||||
572EF22F1B51F16C00EEBB58 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
572EF2301B51F16C00EEBB58 /* Build configuration list for PBXNativeTarget "SocketIO-iOSTests" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
572EF2311B51F16C00EEBB58 /* Debug */,
|
||||
572EF2321B51F16C00EEBB58 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
572EF24B1B51F18A00EEBB58 /* Build configuration list for PBXNativeTarget "SocketIO-Mac" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
572EF24C1B51F18A00EEBB58 /* Debug */,
|
||||
572EF24D1B51F18A00EEBB58 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
572EF24E1B51F18A00EEBB58 /* Build configuration list for PBXNativeTarget "SocketIO-MacTests" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
572EF24F1B51F18A00EEBB58 /* Debug */,
|
||||
572EF2501B51F18A00EEBB58 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 572EF20E1B51F12F00EEBB58 /* Project object */;
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:Socket.IO-Client-Swift.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
@@ -0,0 +1,110 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0640"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "572EF2371B51F18A00EEBB58"
|
||||
BuildableName = "SocketIO-Mac.framework"
|
||||
BlueprintName = "SocketIO-Mac"
|
||||
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "NO"
|
||||
buildForProfiling = "NO"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "572EF2411B51F18A00EEBB58"
|
||||
BuildableName = "SocketIO-MacTests.xctest"
|
||||
BlueprintName = "SocketIO-MacTests"
|
||||
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
buildConfiguration = "Debug">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "572EF2411B51F18A00EEBB58"
|
||||
BuildableName = "SocketIO-MacTests.xctest"
|
||||
BlueprintName = "SocketIO-MacTests"
|
||||
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "572EF2371B51F18A00EEBB58"
|
||||
BuildableName = "SocketIO-Mac.framework"
|
||||
BlueprintName = "SocketIO-Mac"
|
||||
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Debug"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "572EF2371B51F18A00EEBB58"
|
||||
BuildableName = "SocketIO-Mac.framework"
|
||||
BlueprintName = "SocketIO-Mac"
|
||||
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Release"
|
||||
debugDocumentVersioning = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "572EF2371B51F18A00EEBB58"
|
||||
BuildableName = "SocketIO-Mac.framework"
|
||||
BlueprintName = "SocketIO-Mac"
|
||||
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
@@ -0,0 +1,110 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0640"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "572EF2181B51F16C00EEBB58"
|
||||
BuildableName = "SocketIO-iOS.framework"
|
||||
BlueprintName = "SocketIO-iOS"
|
||||
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "NO"
|
||||
buildForProfiling = "NO"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "572EF2231B51F16C00EEBB58"
|
||||
BuildableName = "SocketIO-iOSTests.xctest"
|
||||
BlueprintName = "SocketIO-iOSTests"
|
||||
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
buildConfiguration = "Debug">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "572EF2231B51F16C00EEBB58"
|
||||
BuildableName = "SocketIO-iOSTests.xctest"
|
||||
BlueprintName = "SocketIO-iOSTests"
|
||||
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "572EF2181B51F16C00EEBB58"
|
||||
BuildableName = "SocketIO-iOS.framework"
|
||||
BlueprintName = "SocketIO-iOS"
|
||||
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Debug"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "572EF2181B51F16C00EEBB58"
|
||||
BuildableName = "SocketIO-iOS.framework"
|
||||
BlueprintName = "SocketIO-iOS"
|
||||
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Release"
|
||||
debugDocumentVersioning = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "572EF2181B51F16C00EEBB58"
|
||||
BuildableName = "SocketIO-iOS.framework"
|
||||
BlueprintName = "SocketIO-iOS"
|
||||
ReferencedContainer = "container:Socket.IO-Client-Swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>io.socket.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// SocketIO-Mac.h
|
||||
// SocketIO-Mac
|
||||
//
|
||||
// Created by Nacho Soto on 7/11/15.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
//! Project version number for SocketIO-Mac.
|
||||
FOUNDATION_EXPORT double SocketIO_MacVersionNumber;
|
||||
|
||||
//! Project version string for SocketIO-Mac.
|
||||
FOUNDATION_EXPORT const unsigned char SocketIO_MacVersionString[];
|
||||
|
||||
// In this header, you should import all the public headers of your framework using statements like #import <SocketIO_Mac/PublicHeader.h>
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>io.socket.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// SocketIO_MacTests.swift
|
||||
// SocketIO-MacTests
|
||||
//
|
||||
// Created by Nacho Soto on 7/11/15.
|
||||
//
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import XCTest
|
||||
|
||||
class SocketIO_MacTests: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testExample() {
|
||||
// This is an example of a functional test case.
|
||||
XCTAssert(true, "Pass")
|
||||
}
|
||||
|
||||
func testPerformanceExample() {
|
||||
// This is an example of a performance test case.
|
||||
self.measureBlock() {
|
||||
// Put the code you want to measure the time of here.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>io.socket.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// SocketIO-iOS.h
|
||||
// SocketIO-iOS
|
||||
//
|
||||
// Created by Nacho Soto on 7/11/15.
|
||||
//
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
//! Project version number for SocketIO-iOS.
|
||||
FOUNDATION_EXPORT double SocketIO_iOSVersionNumber;
|
||||
|
||||
//! Project version string for SocketIO-iOS.
|
||||
FOUNDATION_EXPORT const unsigned char SocketIO_iOSVersionString[];
|
||||
|
||||
// In this header, you should import all the public headers of your framework using statements like #import <SocketIO_iOS/PublicHeader.h>
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>io.socket.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// SocketIO_iOSTests.swift
|
||||
// SocketIO-iOSTests
|
||||
//
|
||||
// Created by Nacho Soto on 7/11/15.
|
||||
//
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import XCTest
|
||||
|
||||
class SocketIO_iOSTests: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testExample() {
|
||||
// This is an example of a functional test case.
|
||||
XCTAssert(true, "Pass")
|
||||
}
|
||||
|
||||
func testPerformanceExample() {
|
||||
// This is an example of a performance test case.
|
||||
self.measureBlock() {
|
||||
// Put the code you want to measure the time of here.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
//
|
||||
// SocketAckHandler.swift
|
||||
// Socket.IO-Swift
|
||||
// SocketAckManager.swift
|
||||
// SocketIO-Swift
|
||||
//
|
||||
// Created by Erik Little on 4/3/15.
|
||||
//
|
||||
// Created by Erik Little on 2/14/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
|
||||
@@ -24,46 +24,51 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public typealias AckCallback = (NSArray?) -> Void
|
||||
|
||||
@objc public class SocketAckHandler {
|
||||
let ackNum:Int!
|
||||
let event:String!
|
||||
var acked = false
|
||||
var callback:AckCallback?
|
||||
weak var socket:SocketIOClient?
|
||||
|
||||
|
||||
init(event:String, ackNum:Int = 0, socket:SocketIOClient) {
|
||||
self.ackNum = ackNum
|
||||
self.event = event
|
||||
self.socket = socket
|
||||
private struct SocketAck: Hashable, Equatable {
|
||||
let ack:Int
|
||||
var callback:AckCallback!
|
||||
var hashValue:Int {
|
||||
return ack.hashValue
|
||||
}
|
||||
|
||||
public func onAck(timeout:UInt64, withCallback callback:AckCallback) {
|
||||
init(ack:Int) {
|
||||
self.ack = ack
|
||||
}
|
||||
|
||||
init(ack:Int, callback:AckCallback) {
|
||||
self.ack = ack
|
||||
self.callback = callback
|
||||
|
||||
|
||||
if timeout != 0 {
|
||||
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeout * NSEC_PER_SEC))
|
||||
dispatch_after(time, dispatch_get_main_queue()) {[weak self] in
|
||||
if self == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !self!.acked {
|
||||
self?.executeAck(["No ACK"])
|
||||
self?.socket?.removeAck(self!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func <(lhs:SocketAck, rhs:SocketAck) -> Bool {
|
||||
return lhs.ack < rhs.ack
|
||||
}
|
||||
|
||||
private func ==(lhs:SocketAck, rhs:SocketAck) -> Bool {
|
||||
return lhs.ack == rhs.ack
|
||||
}
|
||||
|
||||
struct SocketAckManager {
|
||||
private var acks = Set<SocketAck>(minimumCapacity: 1)
|
||||
|
||||
mutating func addAck(ack:Int, callback:AckCallback) {
|
||||
acks.insert(SocketAck(ack: ack, callback: callback))
|
||||
}
|
||||
|
||||
mutating func executeAck(ack:Int, items:[AnyObject]?) {
|
||||
let callback = acks.remove(SocketAck(ack: ack))
|
||||
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
callback?.callback(items)
|
||||
}
|
||||
}
|
||||
|
||||
func executeAck(data:NSArray?) {
|
||||
dispatch_async(dispatch_get_main_queue()) {[weak self, cb = self.callback] in
|
||||
self?.acked = true
|
||||
cb?(data)
|
||||
return
|
||||
mutating func timeoutAck(ack:Int) {
|
||||
let callback = acks.remove(SocketAck(ack: ack))
|
||||
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
callback?.callback(["NO ACK"])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// SocketAnyEvent.swift
|
||||
// Socket.IO-Swift
|
||||
//
|
||||
// Created by Erik Little on 3/28/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.
|
||||
|
||||
import Foundation
|
||||
|
||||
@objc public final class SocketAnyEvent {
|
||||
public let event:String!
|
||||
public let items:NSArray?
|
||||
|
||||
init(event:String, items:NSArray?) {
|
||||
self.event = event
|
||||
self.items = items
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,778 @@
|
||||
//
|
||||
// SocketEngine.swift
|
||||
// Socket.IO-Swift
|
||||
//
|
||||
// Created by Erik Little on 3/3/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.
|
||||
|
||||
import Foundation
|
||||
|
||||
public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
|
||||
private typealias Probe = (msg:String, type:PacketType, data:ContiguousArray<NSData>?)
|
||||
private typealias ProbeWaitQueue = [Probe]
|
||||
|
||||
private let allowedCharacterSet = NSCharacterSet(charactersInString: "!*'();:@&=+$,/?%#[]\" {}").invertedSet
|
||||
private let workQueue = NSOperationQueue()
|
||||
private let emitQueue = dispatch_queue_create("engineEmitQueue", DISPATCH_QUEUE_SERIAL)
|
||||
private let parseQueue = dispatch_queue_create("engineParseQueue", DISPATCH_QUEUE_SERIAL)
|
||||
private let handleQueue = dispatch_queue_create("engineHandleQueue", DISPATCH_QUEUE_SERIAL)
|
||||
private let session:NSURLSession!
|
||||
|
||||
private var closed = false
|
||||
private var _connected = false
|
||||
private var extraHeaders:[String: String]?
|
||||
private var fastUpgrade = false
|
||||
private var forcePolling = false
|
||||
private var forceWebsockets = false
|
||||
private var pingInterval:Double?
|
||||
private var pingTimer:NSTimer?
|
||||
private var pingTimeout = 0.0 {
|
||||
didSet {
|
||||
pongsMissedMax = Int(pingTimeout / (pingInterval ?? 25))
|
||||
}
|
||||
}
|
||||
private var pongsMissed = 0
|
||||
private var pongsMissedMax = 0
|
||||
private var postWait = [String]()
|
||||
private var _polling = true
|
||||
private var probing = false
|
||||
private var probeWait = ProbeWaitQueue()
|
||||
private var waitingForPoll = false
|
||||
private var waitingForPost = false
|
||||
private var _websocket = false
|
||||
private var websocketConnected = false
|
||||
|
||||
let logType = "SocketEngine"
|
||||
|
||||
var connected:Bool {
|
||||
return _connected
|
||||
}
|
||||
weak var client:SocketEngineClient?
|
||||
var cookies:[NSHTTPCookie]?
|
||||
var log = false
|
||||
var polling:Bool {
|
||||
return _polling
|
||||
}
|
||||
var sid = ""
|
||||
var socketPath = ""
|
||||
var urlPolling:String?
|
||||
var urlWebSocket:String?
|
||||
var websocket:Bool {
|
||||
return _websocket
|
||||
}
|
||||
var ws:WebSocket?
|
||||
|
||||
public enum PacketType:Int {
|
||||
case OPEN = 0
|
||||
case CLOSE = 1
|
||||
case PING = 2
|
||||
case PONG = 3
|
||||
case MESSAGE = 4
|
||||
case UPGRADE = 5
|
||||
case NOOP = 6
|
||||
|
||||
init?(str:String?) {
|
||||
if let value = str?.toInt(), raw = PacketType(rawValue: value) {
|
||||
self = raw
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public init(client:SocketEngineClient, sessionDelegate:NSURLSessionDelegate?) {
|
||||
self.client = client
|
||||
self.session = NSURLSession(configuration: NSURLSessionConfiguration.ephemeralSessionConfiguration(),
|
||||
delegate: sessionDelegate, delegateQueue: workQueue)
|
||||
}
|
||||
|
||||
public convenience init(client:SocketEngineClient, opts:NSDictionary?) {
|
||||
self.init(client: client, sessionDelegate: opts?["sessionDelegate"] as? NSURLSessionDelegate)
|
||||
forceWebsockets = opts?["forceWebsockets"] as? Bool ?? false
|
||||
forcePolling = opts?["forcePolling"] as? Bool ?? false
|
||||
cookies = opts?["cookies"] as? [NSHTTPCookie]
|
||||
log = opts?["log"] as? Bool ?? false
|
||||
socketPath = opts?["path"] as? String ?? ""
|
||||
extraHeaders = opts?["extraHeaders"] as? [String: String]
|
||||
}
|
||||
|
||||
deinit {
|
||||
SocketLogger.log("Engine is being deinit", client: self)
|
||||
}
|
||||
|
||||
public func close(#fast:Bool) {
|
||||
SocketLogger.log("Engine is being closed. Fast: %@", client: self, args: fast)
|
||||
|
||||
pingTimer?.invalidate()
|
||||
closed = true
|
||||
|
||||
ws?.disconnect()
|
||||
|
||||
if fast || polling {
|
||||
write("", withType: PacketType.CLOSE, withData: nil)
|
||||
client?.engineDidClose("Disconnect")
|
||||
}
|
||||
|
||||
stopPolling()
|
||||
}
|
||||
|
||||
private func createBinaryDataForSend(data:NSData) -> (NSData?, String?) {
|
||||
if websocket {
|
||||
var byteArray = [UInt8](count: 1, repeatedValue: 0x0)
|
||||
byteArray[0] = 4
|
||||
var mutData = NSMutableData(bytes: &byteArray, length: 1)
|
||||
|
||||
mutData.appendData(data)
|
||||
|
||||
return (mutData, nil)
|
||||
} else {
|
||||
var str = "b4"
|
||||
str += data.base64EncodedStringWithOptions(
|
||||
NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
|
||||
|
||||
return (nil, str)
|
||||
}
|
||||
}
|
||||
|
||||
private func createURLs(params:[String: AnyObject]?) -> (String?, String?) {
|
||||
if client == nil {
|
||||
return (nil, nil)
|
||||
}
|
||||
|
||||
let path = socketPath == "" ? "/socket.io" : socketPath
|
||||
|
||||
var url = "\(client!.socketURL)\(path)/?transport="
|
||||
var urlPolling:String
|
||||
var urlWebSocket:String
|
||||
|
||||
if client!.secure {
|
||||
urlPolling = "https://" + url + "polling"
|
||||
urlWebSocket = "wss://" + url + "websocket"
|
||||
} else {
|
||||
urlPolling = "http://" + url + "polling"
|
||||
urlWebSocket = "ws://" + url + "websocket"
|
||||
}
|
||||
|
||||
if params != nil {
|
||||
|
||||
for (key, value) in params! {
|
||||
let keyEsc = key.stringByAddingPercentEncodingWithAllowedCharacters(
|
||||
allowedCharacterSet)!
|
||||
urlPolling += "&\(keyEsc)="
|
||||
urlWebSocket += "&\(keyEsc)="
|
||||
|
||||
if value is String {
|
||||
let valueEsc = (value as! String).stringByAddingPercentEncodingWithAllowedCharacters(
|
||||
allowedCharacterSet)!
|
||||
urlPolling += "\(valueEsc)"
|
||||
urlWebSocket += "\(valueEsc)"
|
||||
} else {
|
||||
urlPolling += "\(value)"
|
||||
urlWebSocket += "\(value)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (urlPolling, urlWebSocket)
|
||||
}
|
||||
|
||||
private func createWebsocket(andConnect connect:Bool) {
|
||||
ws = WebSocket(url: NSURL(string: urlWebSocket! + "&sid=\(sid)")!,
|
||||
cookies: cookies)
|
||||
|
||||
if extraHeaders != nil {
|
||||
for (headerName, value) in extraHeaders! {
|
||||
ws?.headers[headerName] = value
|
||||
}
|
||||
}
|
||||
|
||||
ws?.queue = handleQueue
|
||||
ws?.delegate = self
|
||||
|
||||
if connect {
|
||||
ws?.connect()
|
||||
}
|
||||
}
|
||||
|
||||
private func doFastUpgrade() {
|
||||
if waitingForPoll {
|
||||
SocketLogger.err("Outstanding poll when switched to WebSockets," +
|
||||
"we'll probably disconnect soon. You should report this.", client: self)
|
||||
}
|
||||
|
||||
sendWebSocketMessage("", withType: PacketType.UPGRADE, datas: nil)
|
||||
_websocket = true
|
||||
_polling = false
|
||||
fastUpgrade = false
|
||||
probing = false
|
||||
flushProbeWait()
|
||||
}
|
||||
|
||||
private func doPoll() {
|
||||
if websocket || waitingForPoll || !connected {
|
||||
return
|
||||
}
|
||||
|
||||
waitingForPoll = true
|
||||
let req = NSMutableURLRequest(URL: NSURL(string: urlPolling! + "&sid=\(sid)&b64=1")!)
|
||||
|
||||
if cookies != nil {
|
||||
let headers = NSHTTPCookie.requestHeaderFieldsWithCookies(cookies!)
|
||||
req.allHTTPHeaderFields = headers
|
||||
}
|
||||
|
||||
if extraHeaders != nil {
|
||||
for (headerName, value) in extraHeaders! {
|
||||
req.setValue(value, forHTTPHeaderField: headerName)
|
||||
}
|
||||
}
|
||||
|
||||
doRequest(req)
|
||||
}
|
||||
|
||||
private func doRequest(req:NSMutableURLRequest) {
|
||||
if !polling {
|
||||
return
|
||||
}
|
||||
|
||||
req.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData
|
||||
|
||||
SocketLogger.log("Doing polling request", client: self)
|
||||
|
||||
session.dataTaskWithRequest(req) {[weak self] data, res, err in
|
||||
if let this = self {
|
||||
if err != nil {
|
||||
if this.polling {
|
||||
this.handlePollingFailed(err.localizedDescription)
|
||||
} else {
|
||||
SocketLogger.err(err.localizedDescription, client: this)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
SocketLogger.log("Got polling response", client: this)
|
||||
|
||||
if let str = NSString(data: data, encoding: NSUTF8StringEncoding) as? String {
|
||||
dispatch_async(this.parseQueue) {[weak this] in
|
||||
this?.parsePollingMessage(str)
|
||||
}
|
||||
}
|
||||
|
||||
this.waitingForPoll = false
|
||||
|
||||
if this.fastUpgrade {
|
||||
this.doFastUpgrade()
|
||||
} else if !this.closed && this.polling {
|
||||
this.doPoll()
|
||||
}
|
||||
}}.resume()
|
||||
}
|
||||
|
||||
private func flushProbeWait() {
|
||||
SocketLogger.log("Flushing probe wait", client: self)
|
||||
|
||||
dispatch_async(emitQueue) {[weak self] in
|
||||
if let this = self {
|
||||
for waiter in this.probeWait {
|
||||
this.write(waiter.msg, withType: waiter.type, withData: waiter.data)
|
||||
}
|
||||
|
||||
this.probeWait.removeAll(keepCapacity: false)
|
||||
|
||||
if this.postWait.count != 0 {
|
||||
this.flushWaitingForPostToWebSocket()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func flushWaitingForPost() {
|
||||
if postWait.count == 0 || !connected {
|
||||
return
|
||||
} else if websocket {
|
||||
flushWaitingForPostToWebSocket()
|
||||
return
|
||||
}
|
||||
|
||||
var postStr = ""
|
||||
|
||||
for packet in postWait {
|
||||
let len = count(packet)
|
||||
|
||||
postStr += "\(len):\(packet)"
|
||||
}
|
||||
|
||||
postWait.removeAll(keepCapacity: false)
|
||||
|
||||
let req = NSMutableURLRequest(URL: NSURL(string: urlPolling! + "&sid=\(sid)")!)
|
||||
|
||||
if cookies != nil {
|
||||
let headers = NSHTTPCookie.requestHeaderFieldsWithCookies(cookies!)
|
||||
req.allHTTPHeaderFields = headers
|
||||
}
|
||||
|
||||
req.HTTPMethod = "POST"
|
||||
req.setValue("text/plain; charset=UTF-8", forHTTPHeaderField: "Content-Type")
|
||||
|
||||
let postData = postStr.dataUsingEncoding(NSUTF8StringEncoding,
|
||||
allowLossyConversion: false)!
|
||||
|
||||
req.HTTPBody = postData
|
||||
req.setValue(String(postData.length), forHTTPHeaderField: "Content-Length")
|
||||
|
||||
waitingForPost = true
|
||||
|
||||
SocketLogger.log("POSTing: %@", client: self, args: postStr)
|
||||
|
||||
session.dataTaskWithRequest(req) {[weak self] data, res, err in
|
||||
if let this = self {
|
||||
if err != nil && this.polling {
|
||||
this.handlePollingFailed(err.localizedDescription)
|
||||
return
|
||||
} else if err != nil {
|
||||
NSLog(err.localizedDescription)
|
||||
return
|
||||
}
|
||||
|
||||
this.waitingForPost = false
|
||||
|
||||
dispatch_async(this.emitQueue) {[weak this] in
|
||||
if !(this?.fastUpgrade ?? true) {
|
||||
this?.flushWaitingForPost()
|
||||
this?.doPoll()
|
||||
}
|
||||
}
|
||||
}}.resume()
|
||||
}
|
||||
|
||||
// We had packets waiting for send when we upgraded
|
||||
// Send them raw
|
||||
private func flushWaitingForPostToWebSocket() {
|
||||
for msg in postWait {
|
||||
ws?.writeString(msg)
|
||||
}
|
||||
|
||||
postWait.removeAll(keepCapacity: true)
|
||||
}
|
||||
|
||||
private func handleClose() {
|
||||
if polling {
|
||||
client?.engineDidClose("Disconnect")
|
||||
}
|
||||
}
|
||||
|
||||
private func checkIfMessageIsBase64Binary(var message:String) {
|
||||
if message.hasPrefix("b4") {
|
||||
// binary in base64 string
|
||||
message.removeRange(Range<String.Index>(start: message.startIndex,
|
||||
end: advance(message.startIndex, 2)))
|
||||
|
||||
if let data = NSData(base64EncodedString: message,
|
||||
options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters), client = client {
|
||||
dispatch_async(client.handleQueue) {[weak self] in
|
||||
self?.client?.parseBinaryData(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleMessage(message:String) {
|
||||
if let client = client {
|
||||
dispatch_async(client.handleQueue) {[weak client] in
|
||||
client?.parseSocketMessage(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleNOOP() {
|
||||
doPoll()
|
||||
}
|
||||
|
||||
private func handleOpen(openData:String) {
|
||||
var err:NSError?
|
||||
let mesData = openData.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
|
||||
|
||||
if let json = NSJSONSerialization.JSONObjectWithData(mesData,
|
||||
options: NSJSONReadingOptions.AllowFragments,
|
||||
error: &err) as? NSDictionary, sid = json["sid"] as? String {
|
||||
self.sid = sid
|
||||
_connected = true
|
||||
|
||||
if !forcePolling && !forceWebsockets {
|
||||
createWebsocket(andConnect: true)
|
||||
}
|
||||
|
||||
if let pingInterval = json["pingInterval"] as? Double, pingTimeout = json["pingTimeout"] as? Double {
|
||||
self.pingInterval = pingInterval / 1000.0
|
||||
self.pingTimeout = pingTimeout / 1000.0
|
||||
}
|
||||
} else {
|
||||
client?.didError("Engine failed to handshake")
|
||||
return
|
||||
}
|
||||
|
||||
startPingTimer()
|
||||
|
||||
if !forceWebsockets {
|
||||
doPoll()
|
||||
}
|
||||
}
|
||||
|
||||
private func handlePong(pongMessage:String) {
|
||||
pongsMissed = 0
|
||||
|
||||
// We should upgrade
|
||||
if pongMessage == "3probe" {
|
||||
upgradeTransport()
|
||||
}
|
||||
}
|
||||
|
||||
// A poll failed, tell the client about it
|
||||
private func handlePollingFailed(reason:String) {
|
||||
_connected = false
|
||||
ws?.disconnect()
|
||||
pingTimer?.invalidate()
|
||||
waitingForPoll = false
|
||||
waitingForPost = false
|
||||
|
||||
// If cancelled we were already closing
|
||||
if client == nil || reason == "cancelled" {
|
||||
return
|
||||
}
|
||||
|
||||
if !closed {
|
||||
client?.didError(reason)
|
||||
client?.engineDidClose(reason)
|
||||
}
|
||||
}
|
||||
|
||||
public func open(opts:[String: AnyObject]? = nil) {
|
||||
if connected {
|
||||
SocketLogger.err("Tried to open while connected", client: self)
|
||||
|
||||
client?.didError("Tried to open while connected")
|
||||
return
|
||||
}
|
||||
|
||||
SocketLogger.log("Starting engine", client: self)
|
||||
SocketLogger.log("Handshaking", client: self)
|
||||
|
||||
closed = false
|
||||
|
||||
(urlPolling, urlWebSocket) = createURLs(opts)
|
||||
|
||||
if forceWebsockets {
|
||||
_polling = false
|
||||
_websocket = true
|
||||
createWebsocket(andConnect: true)
|
||||
return
|
||||
}
|
||||
|
||||
let reqPolling = NSMutableURLRequest(URL: NSURL(string: urlPolling! + "&b64=1")!)
|
||||
|
||||
if cookies != nil {
|
||||
let headers = NSHTTPCookie.requestHeaderFieldsWithCookies(cookies!)
|
||||
reqPolling.allHTTPHeaderFields = headers
|
||||
}
|
||||
|
||||
if extraHeaders != nil {
|
||||
for (headerName, value) in extraHeaders! {
|
||||
reqPolling.setValue(value, forHTTPHeaderField: headerName)
|
||||
}
|
||||
}
|
||||
|
||||
doRequest(reqPolling)
|
||||
}
|
||||
|
||||
// Translatation of engine.io-parser#decodePayload
|
||||
private func parsePollingMessage(str:String) {
|
||||
if count(str) == 1 {
|
||||
return
|
||||
}
|
||||
|
||||
// println(str)
|
||||
|
||||
let strArray = Array(str)
|
||||
var length = ""
|
||||
var n = 0
|
||||
var msg = ""
|
||||
|
||||
func testLength(length:String, inout n:Int) -> Bool {
|
||||
if let num = length.toInt() {
|
||||
n = num
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for var i = 0, l = count(str); i < l; i++ {
|
||||
let chr = String(strArray[i])
|
||||
|
||||
if chr != ":" {
|
||||
length += chr
|
||||
} else {
|
||||
if length == "" || testLength(length, &n) {
|
||||
SocketLogger.err("Parsing error: %@", client: self, args: str)
|
||||
handlePollingFailed("Error parsing XHR message")
|
||||
return
|
||||
}
|
||||
|
||||
msg = String(strArray[i+1...i+n])
|
||||
|
||||
if let lengthInt = length.toInt() where lengthInt != count(msg) {
|
||||
SocketLogger.err("Parsing error: %@", client: self, args: str)
|
||||
return
|
||||
}
|
||||
|
||||
if count(msg) != 0 {
|
||||
// Be sure to capture the value of the msg
|
||||
dispatch_async(handleQueue) {[weak self, msg] in
|
||||
self?.parseEngineMessage(msg, fromPolling: true)
|
||||
}
|
||||
}
|
||||
|
||||
i += n
|
||||
length = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func parseEngineData(data:NSData) {
|
||||
if let client = client {
|
||||
dispatch_async(client.handleQueue) {[weak self] in
|
||||
self?.client?.parseBinaryData(data.subdataWithRange(NSMakeRange(1, data.length - 1)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func parseEngineMessage(var message:String, fromPolling:Bool) {
|
||||
SocketLogger.log("Got message: %@", client: self, args: message)
|
||||
|
||||
if fromPolling {
|
||||
fixDoubleUTF8(&message)
|
||||
}
|
||||
|
||||
let type = PacketType(str: (message["^(\\d)"].groups()?[1])) ?? {
|
||||
self.checkIfMessageIsBase64Binary(message)
|
||||
return PacketType.NOOP
|
||||
}()
|
||||
|
||||
switch type {
|
||||
case PacketType.MESSAGE:
|
||||
message.removeAtIndex(message.startIndex)
|
||||
handleMessage(message)
|
||||
case PacketType.NOOP:
|
||||
handleNOOP()
|
||||
case PacketType.PONG:
|
||||
handlePong(message)
|
||||
case PacketType.OPEN:
|
||||
message.removeAtIndex(message.startIndex)
|
||||
handleOpen(message)
|
||||
case PacketType.CLOSE:
|
||||
handleClose()
|
||||
default:
|
||||
SocketLogger.log("Got unknown packet type", client: self)
|
||||
}
|
||||
}
|
||||
|
||||
private func probeWebSocket() {
|
||||
if websocketConnected {
|
||||
sendWebSocketMessage("probe", withType: PacketType.PING)
|
||||
}
|
||||
}
|
||||
|
||||
/// Send an engine message (4)
|
||||
public func send(msg:String, withData datas:ContiguousArray<NSData>?) {
|
||||
if probing {
|
||||
probeWait.append((msg, PacketType.MESSAGE, datas))
|
||||
} else {
|
||||
write(msg, withType: PacketType.MESSAGE, withData: datas)
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func sendPing() {
|
||||
//Server is not responding
|
||||
if pongsMissed > pongsMissedMax {
|
||||
pingTimer?.invalidate()
|
||||
client?.engineDidClose("Ping timeout")
|
||||
return
|
||||
}
|
||||
|
||||
++pongsMissed
|
||||
write("", withType: PacketType.PING, withData: nil)
|
||||
}
|
||||
|
||||
/// Send polling message.
|
||||
/// Only call on emitQueue
|
||||
private func sendPollMessage(var msg:String, withType type:PacketType,
|
||||
datas:ContiguousArray<NSData>? = nil) {
|
||||
SocketLogger.log("Sending poll: %@ as type: %@", client: self, args: msg, type.rawValue)
|
||||
|
||||
doubleEncodeUTF8(&msg)
|
||||
let strMsg = "\(type.rawValue)\(msg)"
|
||||
|
||||
postWait.append(strMsg)
|
||||
|
||||
if datas != nil {
|
||||
for data in datas! {
|
||||
let (nilData, b64Data) = createBinaryDataForSend(data)
|
||||
|
||||
postWait.append(b64Data!)
|
||||
}
|
||||
}
|
||||
|
||||
if !waitingForPost {
|
||||
flushWaitingForPost()
|
||||
}
|
||||
}
|
||||
|
||||
/// Send message on WebSockets
|
||||
/// Only call on emitQueue
|
||||
private func sendWebSocketMessage(str:String, withType type:PacketType,
|
||||
datas:ContiguousArray<NSData>? = nil) {
|
||||
SocketLogger.log("Sending ws: %@ as type: %@", client: self, args: str, type.rawValue)
|
||||
|
||||
ws?.writeString("\(type.rawValue)\(str)")
|
||||
|
||||
if datas != nil {
|
||||
for data in datas! {
|
||||
let (data, nilString) = createBinaryDataForSend(data)
|
||||
if data != nil {
|
||||
ws?.writeData(data!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Starts the ping timer
|
||||
private func startPingTimer() {
|
||||
if pingInterval == nil {
|
||||
return
|
||||
}
|
||||
|
||||
pingTimer?.invalidate()
|
||||
dispatch_async(dispatch_get_main_queue()) {[weak self] in
|
||||
if let this = self {
|
||||
this.pingTimer = NSTimer.scheduledTimerWithTimeInterval(this.pingInterval!, target: this,
|
||||
selector: Selector("sendPing"), userInfo: nil, repeats: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func stopPolling() {
|
||||
session.invalidateAndCancel()
|
||||
}
|
||||
|
||||
private func upgradeTransport() {
|
||||
if websocketConnected {
|
||||
SocketLogger.log("Upgrading transport to WebSockets", client: self)
|
||||
|
||||
fastUpgrade = true
|
||||
sendPollMessage("", withType: PacketType.NOOP)
|
||||
// After this point, we should not send anymore polling messages
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Write a message, independent of transport.
|
||||
*/
|
||||
public func write(msg:String, withType type:PacketType, withData data:ContiguousArray<NSData>?) {
|
||||
dispatch_async(emitQueue) {[weak self] in
|
||||
if let this = self where this.connected {
|
||||
if this.websocket {
|
||||
SocketLogger.log("Writing ws: %@ has data: %@", client: this,
|
||||
args: msg, data == nil ? false : true)
|
||||
this.sendWebSocketMessage(msg, withType: type, datas: data)
|
||||
} else {
|
||||
SocketLogger.log("Writing poll: %@ has data: %@", client: this,
|
||||
args: msg, data == nil ? false : true)
|
||||
this.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 = ContiguousArray<NSData>()
|
||||
|
||||
if data != nil {
|
||||
for d in data! {
|
||||
arr.append(d as! NSData)
|
||||
}
|
||||
}
|
||||
|
||||
write(msg, withType: pType, withData: arr)
|
||||
}
|
||||
}
|
||||
|
||||
// Delagate methods
|
||||
|
||||
public func websocketDidConnect(socket:WebSocket) {
|
||||
websocketConnected = true
|
||||
|
||||
if !forceWebsockets {
|
||||
probing = true
|
||||
probeWebSocket()
|
||||
} else {
|
||||
_connected = true
|
||||
probing = false
|
||||
_polling = false
|
||||
}
|
||||
}
|
||||
|
||||
public func websocketDidDisconnect(socket:WebSocket, error:NSError?) {
|
||||
websocketConnected = false
|
||||
probing = false
|
||||
|
||||
if closed {
|
||||
client?.engineDidClose("Disconnect")
|
||||
return
|
||||
}
|
||||
|
||||
if websocket {
|
||||
pingTimer?.invalidate()
|
||||
_connected = false
|
||||
_websocket = false
|
||||
|
||||
let reason = error?.localizedDescription ?? "Socket Disconnected"
|
||||
|
||||
if error != nil {
|
||||
client?.didError(reason)
|
||||
}
|
||||
|
||||
client?.engineDidClose(reason)
|
||||
} else {
|
||||
flushProbeWait()
|
||||
}
|
||||
}
|
||||
|
||||
public func websocketDidReceiveMessage(socket:WebSocket, text:String) {
|
||||
parseEngineMessage(text, fromPolling: false)
|
||||
}
|
||||
|
||||
public func websocketDidReceiveData(socket:WebSocket, data:NSData) {
|
||||
parseEngineData(data)
|
||||
}
|
||||
}
|
||||
@@ -26,16 +26,12 @@
|
||||
import Foundation
|
||||
|
||||
@objc public protocol SocketEngineClient {
|
||||
var ackQueue:dispatch_queue_attr_t! {get}
|
||||
var handleQueue:dispatch_queue_attr_t! {get}
|
||||
var emitQueue:dispatch_queue_attr_t! {get}
|
||||
var reconnecting:Bool {get}
|
||||
var socketURL:String {get}
|
||||
var secure:Bool {get}
|
||||
|
||||
func didError(reason:AnyObject)
|
||||
func engineDidClose(reason:String)
|
||||
func parseSocketMessage(msg:String)
|
||||
func parseBinaryData(data:NSData)
|
||||
func pollingDidFail(err:NSError?)
|
||||
func webSocketDidCloseWithCode(code:Int, reason:String, wasClean:Bool)
|
||||
func webSocketDidFailWithError(error:NSError)
|
||||
}
|
||||
}
|
||||
@@ -24,17 +24,12 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public typealias NormalCallback = (NSArray?, AckEmitter?) -> Void
|
||||
public typealias AnyHandler = (event:String, items:AnyObject?)
|
||||
public typealias AckEmitter = (AnyObject...) -> Void
|
||||
|
||||
private func emitAckCallback(socket:SocketIOClient, num:Int, type:Int)
|
||||
// Curried
|
||||
private func emitAckCallback(socket:SocketIOClient, num:Int)
|
||||
(items:AnyObject...) -> Void {
|
||||
socket.emitAck(num, withData: items, withAckType: type)
|
||||
socket.emitAck(num, withData: items)
|
||||
}
|
||||
|
||||
class SocketEventHandler {
|
||||
final class SocketEventHandler {
|
||||
let event:String!
|
||||
let callback:NormalCallback?
|
||||
|
||||
@@ -46,8 +41,7 @@ class SocketEventHandler {
|
||||
func executeCallback(_ items:NSArray? = nil, withAck ack:Int? = nil, withAckType type:Int? = nil,
|
||||
withSocket socket:SocketIOClient? = nil) {
|
||||
dispatch_async(dispatch_get_main_queue()) {[weak self] in
|
||||
self?.callback?(items, ack != nil ? emitAckCallback(socket!, ack!, type!) : nil)
|
||||
return
|
||||
self?.callback?(items, ack != nil ? emitAckCallback(socket!, ack!) : nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
// Socket.IO-Swift
|
||||
//
|
||||
// Created by Erik Little on 3/16/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
|
||||
@@ -25,7 +26,7 @@
|
||||
import Foundation
|
||||
|
||||
func fixDoubleUTF8(inout name:String) {
|
||||
let utf8 = name.dataUsingEncoding(NSISOLatin1StringEncoding, allowLossyConversion: false)!
|
||||
let utf8 = name.dataUsingEncoding(NSISOLatin1StringEncoding)!
|
||||
let latin1 = NSString(data: utf8, encoding: NSUTF8StringEncoding)!
|
||||
name = latin1 as String
|
||||
}
|
||||
@@ -34,4 +35,4 @@ func doubleEncodeUTF8(inout str:String) {
|
||||
let latin1 = str.dataUsingEncoding(NSUTF8StringEncoding)!
|
||||
let utf8 = NSString(data: latin1, encoding: NSISOLatin1StringEncoding)!
|
||||
str = utf8 as String
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,519 @@
|
||||
//
|
||||
// SocketIOClient.swift
|
||||
// Socket.IO-Swift
|
||||
//
|
||||
// Created by Erik Little on 11/23/14.
|
||||
//
|
||||
// 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.
|
||||
|
||||
import Foundation
|
||||
|
||||
public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient {
|
||||
private var anyHandler:((SocketAnyEvent) -> Void)?
|
||||
private var _closed = false
|
||||
private var _connected = false
|
||||
private var _connecting = false
|
||||
private var currentReconnectAttempt = 0
|
||||
private var handlers = ContiguousArray<SocketEventHandler>()
|
||||
private var connectParams:[String: AnyObject]?
|
||||
private var _secure = false
|
||||
private var _reconnecting = false
|
||||
private var reconnectTimer:NSTimer?
|
||||
|
||||
let reconnectAttempts:Int!
|
||||
let logType = "SocketClient"
|
||||
var ackHandlers = SocketAckManager()
|
||||
var currentAck = -1
|
||||
var log = false
|
||||
var waitingData = ContiguousArray<SocketPacket>()
|
||||
var sessionDelegate:NSURLSessionDelegate?
|
||||
|
||||
public let socketURL:String
|
||||
public let handleAckQueue = dispatch_queue_create("handleAckQueue", DISPATCH_QUEUE_SERIAL)
|
||||
public let handleQueue = dispatch_queue_create("handleQueue", DISPATCH_QUEUE_SERIAL)
|
||||
public let emitQueue = dispatch_queue_create("emitQueue", DISPATCH_QUEUE_SERIAL)
|
||||
public var closed:Bool {
|
||||
return _closed
|
||||
}
|
||||
public var connected:Bool {
|
||||
return _connected
|
||||
}
|
||||
public var connecting:Bool {
|
||||
return _connecting
|
||||
}
|
||||
public var engine:SocketEngine?
|
||||
public var nsp = "/"
|
||||
public var opts:[String: AnyObject]?
|
||||
public var reconnects = true
|
||||
public var reconnecting:Bool {
|
||||
return _reconnecting
|
||||
}
|
||||
public var reconnectWait = 10
|
||||
public var secure:Bool {
|
||||
return _secure
|
||||
}
|
||||
public var sid:String? {
|
||||
return engine?.sid
|
||||
}
|
||||
|
||||
/**
|
||||
Create a new SocketIOClient. opts can be omitted
|
||||
*/
|
||||
public init(var socketURL:String, opts:[String: AnyObject]? = nil) {
|
||||
if socketURL["https://"].matches().count != 0 {
|
||||
self._secure = true
|
||||
}
|
||||
|
||||
socketURL = socketURL["http://"] ~= ""
|
||||
socketURL = socketURL["https://"] ~= ""
|
||||
|
||||
self.socketURL = socketURL
|
||||
self.opts = opts
|
||||
|
||||
// Set options
|
||||
if let sessionDelegate = opts?["sessionDelegate"] as? NSURLSessionDelegate {
|
||||
self.sessionDelegate = sessionDelegate
|
||||
}
|
||||
|
||||
if let connectParams = opts?["connectParams"] as? [String: AnyObject] {
|
||||
self.connectParams = connectParams
|
||||
}
|
||||
|
||||
if let log = opts?["log"] as? Bool {
|
||||
self.log = log
|
||||
}
|
||||
|
||||
if var nsp = opts?["nsp"] as? String {
|
||||
if nsp != "/" && nsp.hasPrefix("/") {
|
||||
nsp.removeAtIndex(nsp.startIndex)
|
||||
}
|
||||
|
||||
self.nsp = nsp
|
||||
}
|
||||
|
||||
if let reconnects = opts?["reconnects"] as? Bool {
|
||||
self.reconnects = reconnects
|
||||
}
|
||||
|
||||
if let reconnectAttempts = opts?["reconnectAttempts"] as? Int {
|
||||
self.reconnectAttempts = reconnectAttempts
|
||||
} else {
|
||||
self.reconnectAttempts = -1
|
||||
}
|
||||
|
||||
if let reconnectWait = opts?["reconnectWait"] as? Int {
|
||||
self.reconnectWait = abs(reconnectWait)
|
||||
}
|
||||
|
||||
super.init()
|
||||
}
|
||||
|
||||
public convenience init(socketURL:String, options:[String: AnyObject]?) {
|
||||
self.init(socketURL: socketURL, opts: options)
|
||||
}
|
||||
|
||||
deinit {
|
||||
SocketLogger.log("Client is being deinit", client: self)
|
||||
engine?.close(fast: true)
|
||||
}
|
||||
|
||||
private func addEngine() {
|
||||
SocketLogger.log("Adding engine", client: self)
|
||||
|
||||
engine = SocketEngine(client: self, opts: opts)
|
||||
}
|
||||
|
||||
private func clearReconnectTimer() {
|
||||
reconnectTimer?.invalidate()
|
||||
reconnectTimer = nil
|
||||
}
|
||||
|
||||
/**
|
||||
Closes the socket. Only reopen the same socket if you know what you're doing.
|
||||
Will turn off automatic reconnects.
|
||||
Pass true to fast if you're closing from a background task
|
||||
*/
|
||||
public func close(#fast:Bool) {
|
||||
SocketLogger.log("Closing socket", client: self)
|
||||
|
||||
reconnects = false
|
||||
_connecting = false
|
||||
_connected = false
|
||||
_reconnecting = false
|
||||
engine?.close(fast: fast)
|
||||
engine = nil
|
||||
}
|
||||
|
||||
/**
|
||||
Connect to the server.
|
||||
*/
|
||||
public func connect() {
|
||||
connect(timeoutAfter: 0, withTimeoutHandler: nil)
|
||||
}
|
||||
|
||||
/**
|
||||
Connect to the server. If we aren't connected after timeoutAfter, call handler
|
||||
*/
|
||||
public func connect(#timeoutAfter:Int, withTimeoutHandler handler:(() -> Void)?) {
|
||||
if closed {
|
||||
SocketLogger.log("Warning! This socket was previously closed. This might be dangerous!", client: self)
|
||||
_closed = false
|
||||
} else if connected {
|
||||
return
|
||||
}
|
||||
|
||||
_connecting = true
|
||||
addEngine()
|
||||
engine?.open(opts: connectParams)
|
||||
|
||||
if timeoutAfter == 0 {
|
||||
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.connected {
|
||||
this._closed = true
|
||||
this._connecting = false
|
||||
this.engine?.close(fast: true)
|
||||
|
||||
handler?()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func createOnAck(event:String, items:[AnyObject]) -> OnAckCallback {
|
||||
return {[weak self, ack = ++currentAck] timeout, callback in
|
||||
if let this = self {
|
||||
this.ackHandlers.addAck(ack, callback: callback)
|
||||
|
||||
dispatch_async(this.emitQueue) {[weak this] in
|
||||
this?._emit(event, 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func didConnect() {
|
||||
SocketLogger.log("Socket connected", client: self)
|
||||
|
||||
_closed = false
|
||||
_connected = true
|
||||
_connecting = false
|
||||
_reconnecting = false
|
||||
currentReconnectAttempt = 0
|
||||
clearReconnectTimer()
|
||||
|
||||
// Don't handle as internal because something crazy could happen where
|
||||
// we disconnect before it's handled
|
||||
handleEvent("connect", data: nil, isInternalMessage: false)
|
||||
}
|
||||
|
||||
func didDisconnect(reason:String) {
|
||||
if closed {
|
||||
return
|
||||
}
|
||||
|
||||
SocketLogger.log("Disconnected: %@", client: self, args: reason)
|
||||
|
||||
_closed = true
|
||||
_connected = false
|
||||
reconnects = false
|
||||
_connecting = false
|
||||
_reconnecting = false
|
||||
|
||||
// Make sure the engine is actually dead.
|
||||
engine?.close(fast: true)
|
||||
handleEvent("disconnect", data: [reason], isInternalMessage: true)
|
||||
}
|
||||
|
||||
/// error
|
||||
public func didError(reason:AnyObject) {
|
||||
SocketLogger.err("%@", client: self, args: reason)
|
||||
|
||||
handleEvent("error", data: reason as? [AnyObject] ?? [reason],
|
||||
isInternalMessage: true)
|
||||
}
|
||||
|
||||
/**
|
||||
Same as close
|
||||
*/
|
||||
public func disconnect(#fast:Bool) {
|
||||
close(fast: fast)
|
||||
}
|
||||
|
||||
/**
|
||||
Send a message to the server
|
||||
*/
|
||||
public func emit(event:String, _ items:AnyObject...) {
|
||||
if !connected {
|
||||
return
|
||||
}
|
||||
|
||||
dispatch_async(emitQueue) {[weak self] in
|
||||
self?._emit(event, items)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Same as emit, but meant for Objective-C
|
||||
*/
|
||||
public func emit(event:String, withItems items:[AnyObject]) {
|
||||
if !connected {
|
||||
return
|
||||
}
|
||||
|
||||
dispatch_async(emitQueue) {[weak self] in
|
||||
self?._emit(event, items)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Sends a message to the server, requesting an ack. Use the onAck method of SocketAckHandler to add
|
||||
an ack.
|
||||
*/
|
||||
public func emitWithAck(event:String, _ items:AnyObject...) -> OnAckCallback {
|
||||
if !connected {
|
||||
return createOnAck(event, items: items)
|
||||
}
|
||||
|
||||
return createOnAck(event, items: items)
|
||||
}
|
||||
|
||||
/**
|
||||
Same as emitWithAck, but for Objective-C
|
||||
*/
|
||||
public func emitWithAck(event:String, withItems items:[AnyObject]) -> OnAckCallback {
|
||||
if !connected {
|
||||
return createOnAck(event, items: items)
|
||||
}
|
||||
|
||||
return createOnAck(event, items: items)
|
||||
}
|
||||
|
||||
private func _emit(event:String, _ args:[AnyObject], ack:Int? = nil) {
|
||||
if !connected {
|
||||
return
|
||||
}
|
||||
|
||||
let packet = SocketPacket(type: nil, data: args, nsp: nsp, id: ack)
|
||||
let str:String
|
||||
|
||||
SocketParser.parseForEmit(packet)
|
||||
str = packet.createMessageForEvent(event)
|
||||
|
||||
SocketLogger.log("Emitting: %@", client: self, args: str)
|
||||
|
||||
if packet.type == SocketPacket.PacketType.BINARY_EVENT {
|
||||
engine?.send(str, withData: packet.binary)
|
||||
} else {
|
||||
engine?.send(str, withData: nil)
|
||||
}
|
||||
}
|
||||
|
||||
// If the server wants to know that the client received data
|
||||
func emitAck(ack:Int, withData args:[AnyObject]) {
|
||||
dispatch_async(emitQueue) {[weak self] in
|
||||
if let this = self where this.connected {
|
||||
let packet = SocketPacket(type: nil, data: args, nsp: this.nsp, id: ack)
|
||||
let str:String
|
||||
|
||||
SocketParser.parseForEmit(packet)
|
||||
str = packet.createAck()
|
||||
|
||||
SocketLogger.log("Emitting Ack: %@", client: this, args: str)
|
||||
|
||||
if packet.type == SocketPacket.PacketType.BINARY_ACK {
|
||||
this.engine?.send(str, withData: packet.binary)
|
||||
} else {
|
||||
this.engine?.send(str, withData: nil)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func engineDidClose(reason:String) {
|
||||
_connected = false
|
||||
_connecting = false
|
||||
|
||||
if closed || !reconnects {
|
||||
didDisconnect(reason)
|
||||
} else if !reconnecting {
|
||||
handleEvent("reconnect", data: [reason], isInternalMessage: true)
|
||||
tryReconnect()
|
||||
}
|
||||
}
|
||||
|
||||
// Called when the socket gets an ack for something it sent
|
||||
func handleAck(ack:Int, data:AnyObject?) {
|
||||
SocketLogger.log("Handling ack: %@ with data: %@", client: self,
|
||||
args: ack, data ?? "")
|
||||
|
||||
ackHandlers.executeAck(ack,
|
||||
items: (data as? [AnyObject]?) ?? (data != nil ? [data!] : nil))
|
||||
}
|
||||
|
||||
/**
|
||||
Causes an event to be handled. Only use if you know what you're doing.
|
||||
*/
|
||||
public func handleEvent(event:String, data:[AnyObject]?, isInternalMessage:Bool = false,
|
||||
wantsAck ack:Int? = nil) {
|
||||
// println("Should do event: \(event) with data: \(data)")
|
||||
if !connected && !isInternalMessage {
|
||||
return
|
||||
}
|
||||
|
||||
SocketLogger.log("Handling event: %@ with data: %@", client: self,
|
||||
args: event, data ?? "")
|
||||
|
||||
if anyHandler != nil {
|
||||
dispatch_async(dispatch_get_main_queue()) {[weak self] in
|
||||
self?.anyHandler?(SocketAnyEvent(event: event, items: data))
|
||||
}
|
||||
}
|
||||
|
||||
for handler in handlers {
|
||||
if handler.event == event {
|
||||
if ack != nil {
|
||||
handler.executeCallback(data, withAck: ack!, withSocket: self)
|
||||
} else {
|
||||
handler.executeCallback(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Leaves nsp and goes back to /
|
||||
*/
|
||||
public func leaveNamespace() {
|
||||
if nsp != "/" {
|
||||
engine?.send("1/\(nsp)", withData: nil)
|
||||
nsp = "/"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Joins nsp if it is not /
|
||||
*/
|
||||
public func joinNamespace() {
|
||||
SocketLogger.log("Joining namespace", client: self)
|
||||
|
||||
if nsp != "/" {
|
||||
engine?.send("0/\(nsp)", withData: nil)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Removes handler(s)
|
||||
*/
|
||||
public func off(event:String) {
|
||||
SocketLogger.log("Removing handler for event: %@", client: self, args: event)
|
||||
|
||||
handlers = handlers.filter {$0.event == event ? false : true}
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a handler for an event.
|
||||
*/
|
||||
public func on(event:String, callback:NormalCallback) {
|
||||
SocketLogger.log("Adding handler for event: %@", client: self, args: event)
|
||||
|
||||
let handler = SocketEventHandler(event: event, callback: callback)
|
||||
handlers.append(handler)
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a handler that will be called on every event.
|
||||
*/
|
||||
public func onAny(handler:(SocketAnyEvent) -> Void) {
|
||||
anyHandler = handler
|
||||
}
|
||||
|
||||
/**
|
||||
Same as connect
|
||||
*/
|
||||
public func open() {
|
||||
connect()
|
||||
}
|
||||
|
||||
public func parseSocketMessage(msg:String) {
|
||||
SocketParser.parseSocketMessage(msg, socket: self)
|
||||
}
|
||||
|
||||
public func parseBinaryData(data:NSData) {
|
||||
SocketParser.parseBinaryData(data, socket: self)
|
||||
}
|
||||
|
||||
/**
|
||||
Trieds to reconnect to the server.
|
||||
*/
|
||||
public func reconnect() {
|
||||
_connected = false
|
||||
_connecting = false
|
||||
_reconnecting = false
|
||||
|
||||
engine?.stopPolling()
|
||||
tryReconnect()
|
||||
}
|
||||
|
||||
// We lost connection and should attempt to reestablish
|
||||
@objc private func tryReconnect() {
|
||||
if reconnectAttempts != -1 && currentReconnectAttempt + 1 > reconnectAttempts || !reconnects {
|
||||
clearReconnectTimer()
|
||||
didDisconnect("Reconnect Failed")
|
||||
|
||||
return
|
||||
} else if connected {
|
||||
_connecting = false
|
||||
_reconnecting = false
|
||||
return
|
||||
}
|
||||
|
||||
if reconnectTimer == nil {
|
||||
SocketLogger.log("Starting reconnect", client: self)
|
||||
|
||||
_reconnecting = true
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SocketLogger.log("Trying to reconnect", client: self)
|
||||
handleEvent("reconnectAttempt", data: [reconnectAttempts - currentReconnectAttempt],
|
||||
isInternalMessage: true)
|
||||
|
||||
currentReconnectAttempt++
|
||||
connect()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
//
|
||||
// SocketLogger.swift
|
||||
// SocketIO-Swift
|
||||
//
|
||||
// Created by Erik Little on 4/11/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.
|
||||
|
||||
import Foundation
|
||||
|
||||
private let MESSAGE_LENGTH_MAX = 10000
|
||||
|
||||
protocol SocketLogClient {
|
||||
var log:Bool {get set}
|
||||
var logType:String {get}
|
||||
}
|
||||
|
||||
final class SocketLogger {
|
||||
private static let printQueue = dispatch_queue_create("printQueue", DISPATCH_QUEUE_SERIAL)
|
||||
|
||||
private static func shorten(item:AnyObject) -> CVarArgType {
|
||||
var str = toString(item)
|
||||
|
||||
if count(str) > MESSAGE_LENGTH_MAX {
|
||||
let endIndex = advance(str.startIndex, MESSAGE_LENGTH_MAX)
|
||||
|
||||
str = str.substringToIndex(endIndex)
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
static func log(message:String, client:SocketLogClient, altType:String? = nil, args:AnyObject...) {
|
||||
if !client.log {
|
||||
return
|
||||
}
|
||||
|
||||
dispatch_async(printQueue) {[type = client.logType] in
|
||||
let newArgs = args.map(SocketLogger.shorten)
|
||||
let replaced = String(format: message, arguments: newArgs)
|
||||
|
||||
NSLog("%@: %@", altType ?? type, replaced)
|
||||
}
|
||||
}
|
||||
|
||||
static func err(message:String, client:SocketLogClient, altType:String? = nil, args:AnyObject...) {
|
||||
if !client.log {
|
||||
return
|
||||
}
|
||||
|
||||
dispatch_async(printQueue) {[type = client.logType] in
|
||||
let newArgs = args.map(SocketLogger.shorten)
|
||||
let replaced = String(format: message, arguments: newArgs)
|
||||
|
||||
NSLog("ERROR %@: %@", altType ?? type, replaced)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
//
|
||||
// SocketPacket.swift
|
||||
// Socket.IO-Swift
|
||||
//
|
||||
// Created by Erik Little on 1/18/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.
|
||||
|
||||
import Foundation
|
||||
|
||||
final class SocketPacket: Printable {
|
||||
var binary = ContiguousArray<NSData>()
|
||||
var currentPlace = 0
|
||||
var data:[AnyObject]?
|
||||
var description:String {
|
||||
var better = "SocketPacket {type: ~~0; data: ~~1; " +
|
||||
"id: ~~2; placeholders: ~~3;}"
|
||||
|
||||
better = better["~~0"] ~= (type != nil ? String(type!.rawValue) : "nil")
|
||||
better = better["~~1"] ~= (data != nil ? "\(data!)" : "nil")
|
||||
better = better["~~2"] ~= (id != nil ? String(id!) : "nil")
|
||||
better = better["~~3"] ~= (placeholders != nil ? String(placeholders!) : "nil")
|
||||
|
||||
return better
|
||||
}
|
||||
var id:Int?
|
||||
var justAck = false
|
||||
var nsp = ""
|
||||
var placeholders:Int?
|
||||
var type:PacketType?
|
||||
|
||||
enum PacketType:Int {
|
||||
case CONNECT = 0
|
||||
case DISCONNECT = 1
|
||||
case EVENT = 2
|
||||
case ACK = 3
|
||||
case ERROR = 4
|
||||
case BINARY_EVENT = 5
|
||||
case BINARY_ACK = 6
|
||||
|
||||
init?(str:String) {
|
||||
if let int = str.toInt(), raw = PacketType(rawValue: int) {
|
||||
self = raw
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(type:PacketType?, data:[AnyObject]? = nil, nsp:String = "",
|
||||
placeholders:Int? = nil, id:Int? = nil) {
|
||||
self.type = type
|
||||
self.data = data
|
||||
self.nsp = nsp
|
||||
self.placeholders = placeholders
|
||||
self.id = id
|
||||
}
|
||||
|
||||
func getEvent() -> String {
|
||||
return data?.removeAtIndex(0) as! String
|
||||
}
|
||||
|
||||
func addData(data:NSData) -> Bool {
|
||||
if placeholders == currentPlace {
|
||||
return true
|
||||
}
|
||||
|
||||
binary.append(data)
|
||||
currentPlace++
|
||||
|
||||
if placeholders == currentPlace {
|
||||
currentPlace = 0
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func createMessageForEvent(event:String) -> String {
|
||||
let message:String
|
||||
|
||||
if binary.count == 0 {
|
||||
type = PacketType.EVENT
|
||||
|
||||
if nsp == "/" {
|
||||
if id == nil {
|
||||
message = "2[\"\(event)\""
|
||||
} else {
|
||||
message = "2\(id!)[\"\(event)\""
|
||||
}
|
||||
} else {
|
||||
if id == nil {
|
||||
message = "2/\(nsp),[\"\(event)\""
|
||||
} else {
|
||||
message = "2/\(nsp),\(id!)[\"\(event)\""
|
||||
}
|
||||
}
|
||||
} else {
|
||||
type = PacketType.BINARY_EVENT
|
||||
|
||||
if nsp == "/" {
|
||||
if id == nil {
|
||||
message = "5\(binary.count)-[\"\(event)\""
|
||||
} else {
|
||||
message = "5\(binary.count)-\(id!)[\"\(event)\""
|
||||
}
|
||||
} else {
|
||||
if id == nil {
|
||||
message = "5\(binary.count)-/\(nsp),[\"\(event)\""
|
||||
} else {
|
||||
message = "5\(binary.count)-/\(nsp),\(id!)[\"\(event)\""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return completeMessage(message)
|
||||
}
|
||||
|
||||
func createAck() -> String {
|
||||
var msg:String
|
||||
|
||||
if binary.count == 0 {
|
||||
type = PacketType.ACK
|
||||
|
||||
if nsp == "/" {
|
||||
msg = "3\(id!)["
|
||||
} else {
|
||||
msg = "3/\(nsp),\(id!)["
|
||||
}
|
||||
} else {
|
||||
type = PacketType.BINARY_ACK
|
||||
|
||||
if nsp == "/" {
|
||||
msg = "6\(binary.count)-\(id!)["
|
||||
} else {
|
||||
msg = "6\(binary.count)-/\(nsp),\(id!)["
|
||||
}
|
||||
}
|
||||
|
||||
return completeMessage(msg, ack: true)
|
||||
}
|
||||
|
||||
private func completeMessage(var message:String, ack:Bool = false) -> String {
|
||||
var err:NSError?
|
||||
|
||||
if data == nil || data!.count == 0 {
|
||||
return message + "]"
|
||||
} else if !ack {
|
||||
message += ","
|
||||
}
|
||||
|
||||
for arg in data! {
|
||||
if arg is NSDictionary || arg is [AnyObject] {
|
||||
let jsonSend = NSJSONSerialization.dataWithJSONObject(arg,
|
||||
options: NSJSONWritingOptions(0), error: &err)
|
||||
let jsonString = NSString(data: jsonSend!, encoding: NSUTF8StringEncoding)
|
||||
|
||||
message += jsonString! as String + ","
|
||||
} else if var str = arg as? String {
|
||||
str = str["\n"] ~= "\\\\n"
|
||||
str = str["\r"] ~= "\\\\r"
|
||||
|
||||
message += "\"\(str)\","
|
||||
} else if arg is NSNull {
|
||||
message += "null,"
|
||||
} else {
|
||||
message += "\(arg),"
|
||||
}
|
||||
}
|
||||
|
||||
if message != "" {
|
||||
message.removeAtIndex(message.endIndex.predecessor())
|
||||
}
|
||||
|
||||
return message + "]"
|
||||
}
|
||||
|
||||
func fillInPlaceholders() {
|
||||
var newArr = NSMutableArray(array: data!)
|
||||
|
||||
for i in 0..<data!.count {
|
||||
if let str = data?[i] as? String, num = str["~~(\\d)"].groups() {
|
||||
newArr[i] = binary[num[1].toInt()!]
|
||||
} else if data?[i] is NSDictionary || data?[i] is NSArray {
|
||||
newArr[i] = _fillInPlaceholders(data![i])
|
||||
}
|
||||
}
|
||||
|
||||
data = newArr as [AnyObject]
|
||||
}
|
||||
|
||||
private func _fillInPlaceholders(data:AnyObject) -> AnyObject {
|
||||
if let str = data as? String {
|
||||
if let num = str["~~(\\d)"].groups() {
|
||||
return binary[num[1].toInt()!]
|
||||
} else {
|
||||
return str
|
||||
}
|
||||
} else if let dict = data as? NSDictionary {
|
||||
var newDict = NSMutableDictionary(dictionary: dict)
|
||||
|
||||
for (key, value) in dict {
|
||||
newDict[key as! NSCopying] = _fillInPlaceholders(value)
|
||||
}
|
||||
|
||||
return newDict
|
||||
} else if let arr = data as? NSArray {
|
||||
var newArr = NSMutableArray(array: arr)
|
||||
|
||||
for i in 0..<arr.count {
|
||||
newArr[i] = _fillInPlaceholders(arr[i])
|
||||
}
|
||||
|
||||
return newArr
|
||||
} else {
|
||||
return data
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
//
|
||||
// SocketParser.swift
|
||||
// Socket.IO-Swift
|
||||
//
|
||||
// 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.
|
||||
|
||||
import Foundation
|
||||
|
||||
class SocketParser {
|
||||
private static let shredder = SocketParser.PacketShredder()
|
||||
|
||||
// Translation of socket.io-parser#deconstructPacket
|
||||
private final class PacketShredder {
|
||||
var buf = ContiguousArray<NSData>()
|
||||
|
||||
func shred(data:AnyObject) -> AnyObject {
|
||||
if let bin = data as? NSData {
|
||||
let placeholder = ["_placeholder" :true, "num": buf.count]
|
||||
|
||||
buf.append(bin)
|
||||
|
||||
return placeholder
|
||||
} else if let arr = data as? NSArray {
|
||||
var newArr = NSMutableArray(array: arr)
|
||||
|
||||
for i in 0..<arr.count {
|
||||
newArr[i] = shred(arr[i])
|
||||
}
|
||||
|
||||
return newArr
|
||||
} else if let dict = data as? NSDictionary {
|
||||
var newDict = NSMutableDictionary(dictionary: dict)
|
||||
|
||||
for (key, value) in newDict {
|
||||
newDict[key as! NSCopying] = shred(value)
|
||||
}
|
||||
|
||||
return newDict
|
||||
} else {
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
func deconstructPacket(packet:SocketPacket) {
|
||||
if packet.data == nil {
|
||||
return
|
||||
}
|
||||
|
||||
var data = packet.data!
|
||||
|
||||
for i in 0..<data.count {
|
||||
if data[i] is NSArray || data[i] is NSDictionary {
|
||||
data[i] = shred(data[i])
|
||||
} else if let bin = data[i] as? NSData {
|
||||
data[i] = ["_placeholder" :true, "num": buf.count]
|
||||
buf.append(bin)
|
||||
}
|
||||
}
|
||||
|
||||
packet.data = data
|
||||
packet.binary = buf
|
||||
buf.removeAll(keepCapacity: true)
|
||||
}
|
||||
}
|
||||
|
||||
// Translation of socket.io-client#decodeString
|
||||
static func parseString(str:String) -> SocketPacket? {
|
||||
let arr = Array(str)
|
||||
let type = String(arr[0])
|
||||
|
||||
if arr.count == 1 {
|
||||
return SocketPacket(type: SocketPacket.PacketType(str: type))
|
||||
}
|
||||
|
||||
var id = nil as Int?
|
||||
var nsp = ""
|
||||
var i = 0
|
||||
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 = buf.toInt() where arr[i] == "-" {
|
||||
placeholders = holders
|
||||
} else {
|
||||
NSLog("Error parsing \(str)")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if arr[i + 1] == "/" {
|
||||
while ++i < arr.count {
|
||||
let c = arr[i]
|
||||
|
||||
if c == "," {
|
||||
break
|
||||
}
|
||||
|
||||
nsp += String(c)
|
||||
}
|
||||
}
|
||||
|
||||
if i + 1 >= arr.count {
|
||||
return SocketPacket(type: SocketPacket.PacketType(str: type),
|
||||
nsp: nsp, placeholders: placeholders, id: id)
|
||||
}
|
||||
|
||||
let next = String(arr[i + 1])
|
||||
|
||||
if next.toInt() != nil {
|
||||
var c = ""
|
||||
while ++i < arr.count {
|
||||
if let int = String(arr[i]).toInt() {
|
||||
c += String(arr[i])
|
||||
} else {
|
||||
--i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
id = c.toInt()
|
||||
}
|
||||
|
||||
if ++i < arr.count {
|
||||
let d = str[advance(str.startIndex, i)...advance(str.startIndex, count(str)-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,
|
||||
nsp: nsp, placeholders: placeholders, id: id)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Parses data for events
|
||||
static func parseData(data:String) -> AnyObject? {
|
||||
var err:NSError?
|
||||
let stringData = data.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
|
||||
let parsed:AnyObject? = NSJSONSerialization.JSONObjectWithData(stringData!,
|
||||
options: NSJSONReadingOptions.MutableContainers, error: &err)
|
||||
|
||||
if err != nil {
|
||||
// println(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
return parsed
|
||||
}
|
||||
|
||||
static func parseForEmit(packet:SocketPacket) {
|
||||
shredder.deconstructPacket(packet)
|
||||
}
|
||||
|
||||
// Parses messages recieved
|
||||
static func parseSocketMessage(stringMessage:String, socket:SocketIOClient) {
|
||||
if stringMessage == "" {
|
||||
return
|
||||
}
|
||||
|
||||
func checkNSP(nsp:String) -> Bool {
|
||||
return nsp == "" && socket.nsp != "/"
|
||||
}
|
||||
|
||||
SocketLogger.log("Parsing %@", client: socket, altType: "SocketParser", args: stringMessage)
|
||||
|
||||
let p:SocketPacket
|
||||
|
||||
if let pack = parseString(stringMessage) {
|
||||
p = pack
|
||||
} else {
|
||||
socket.didError("Error parsing packet")
|
||||
return
|
||||
}
|
||||
|
||||
SocketLogger.log("Decoded packet as: %@", client: socket, altType: "SocketParser", args: p)
|
||||
|
||||
if p.type == SocketPacket.PacketType.EVENT {
|
||||
if checkNSP(p.nsp) {
|
||||
return
|
||||
}
|
||||
|
||||
socket.handleEvent(p.getEvent(), data: p.data,
|
||||
isInternalMessage: false, wantsAck: p.id)
|
||||
} else if p.type == SocketPacket.PacketType.ACK {
|
||||
if checkNSP(p.nsp) {
|
||||
return
|
||||
}
|
||||
|
||||
socket.handleAck(p.id!, data: p.data)
|
||||
} else if p.type == SocketPacket.PacketType.BINARY_EVENT {
|
||||
if checkNSP(p.nsp) {
|
||||
return
|
||||
}
|
||||
|
||||
socket.waitingData.append(p)
|
||||
} else if p.type == SocketPacket.PacketType.BINARY_ACK {
|
||||
if checkNSP(p.nsp) {
|
||||
return
|
||||
}
|
||||
|
||||
p.justAck = true
|
||||
socket.waitingData.append(p)
|
||||
} else if p.type == SocketPacket.PacketType.CONNECT {
|
||||
if p.nsp == "" && socket.nsp != "/" {
|
||||
socket.joinNamespace()
|
||||
} else if p.nsp != "" && socket.nsp == "/" {
|
||||
socket.didConnect()
|
||||
} else {
|
||||
socket.didConnect()
|
||||
}
|
||||
} else if p.type == SocketPacket.PacketType.DISCONNECT {
|
||||
socket.didDisconnect("Got Disconnect")
|
||||
} else if p.type == SocketPacket.PacketType.ERROR {
|
||||
socket.didError(p.data == nil ? "Error" : p.data!)
|
||||
}
|
||||
}
|
||||
|
||||
static func parseBinaryData(data:NSData, socket:SocketIOClient) {
|
||||
if socket.waitingData.count == 0 {
|
||||
SocketLogger.err("Got data when not remaking packet", client: socket, altType: "SocketParser")
|
||||
return
|
||||
}
|
||||
|
||||
let shouldExecute = socket.waitingData[0].addData(data)
|
||||
|
||||
if !shouldExecute {
|
||||
return
|
||||
}
|
||||
|
||||
let packet = socket.waitingData.removeAtIndex(0)
|
||||
packet.fillInPlaceholders()
|
||||
|
||||
if !packet.justAck {
|
||||
socket.handleEvent(packet.getEvent(), data: packet.data,
|
||||
wantsAck: packet.id)
|
||||
} else {
|
||||
socket.handleAck(packet.id!, data: packet.data)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// SocketTypes.swift
|
||||
// SocketIO-Swift
|
||||
//
|
||||
// Created by Erik Little on 4/8/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.
|
||||
|
||||
import Foundation
|
||||
|
||||
// @objc_block is undocumented, but is used because Swift assumes that all
|
||||
// Objective-C blocks are copied, but Objective-C assumes that Swift will copy it.
|
||||
// And the way things are done here, the bridging fails to copy the block in
|
||||
// SocketAckMap#addAck
|
||||
public typealias AckCallback = @objc_block (NSArray?) -> Void
|
||||
public typealias AckEmitter = (AnyObject...) -> Void
|
||||
public typealias NormalCallback = (NSArray?, AckEmitter?) -> Void
|
||||
public typealias OnAckCallback = (timeout:UInt64, callback:AckCallback) -> Void
|
||||
@@ -18,7 +18,7 @@ var swiftRegexCache = [String: NSRegularExpression]()
|
||||
public class SwiftRegex: NSObject, BooleanType {
|
||||
var target:String
|
||||
var regex: NSRegularExpression
|
||||
|
||||
|
||||
init(target:String, pattern:String, options:NSRegularExpressionOptions = nil) {
|
||||
self.target = target
|
||||
if let regex = swiftRegexCache[pattern] {
|
||||
@@ -36,16 +36,16 @@ public class SwiftRegex: NSObject, BooleanType {
|
||||
}
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
||||
class func failure(message: String) {
|
||||
println("SwiftRegex: "+message)
|
||||
//assert(false,"SwiftRegex: failed")
|
||||
}
|
||||
|
||||
|
||||
final var targetRange: NSRange {
|
||||
return NSRange(location: 0,length: countElements(target.utf16))
|
||||
return NSRange(location: 0,length: count(target.utf16))
|
||||
}
|
||||
|
||||
|
||||
final func substring(range: NSRange) -> String? {
|
||||
if ( range.location != NSNotFound ) {
|
||||
return (target as NSString).substringWithRange(range)
|
||||
@@ -53,23 +53,23 @@ public class SwiftRegex: NSObject, BooleanType {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func doesMatch(options: NSMatchingOptions = nil) -> Bool {
|
||||
return range(options: options).location != NSNotFound
|
||||
}
|
||||
|
||||
|
||||
public func range(options: NSMatchingOptions = nil) -> NSRange {
|
||||
return regex.rangeOfFirstMatchInString(target as String, options: nil, range: targetRange)
|
||||
}
|
||||
|
||||
|
||||
public func match(options: NSMatchingOptions = nil) -> String? {
|
||||
return substring(range(options: options))
|
||||
}
|
||||
|
||||
|
||||
public func groups(options: NSMatchingOptions = nil) -> [String]? {
|
||||
return groupsForMatch(regex.firstMatchInString(target as String, options: options, range: targetRange))
|
||||
}
|
||||
|
||||
|
||||
func groupsForMatch(match: NSTextCheckingResult!) -> [String]? {
|
||||
if match != nil {
|
||||
var groups = [String]()
|
||||
@@ -85,51 +85,51 @@ public class SwiftRegex: NSObject, BooleanType {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public subscript(groupno: Int) -> String? {
|
||||
get {
|
||||
return groups()?[groupno]
|
||||
}
|
||||
|
||||
|
||||
set(newValue) {
|
||||
if newValue == nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
for match in matchResults()!.reverse() {
|
||||
let replacement = regex.replacementStringForResult(match,
|
||||
inString: target as String, offset: 0, template: newValue!)
|
||||
let mut = NSMutableString(string: target)
|
||||
mut.replaceCharactersInRange(match.rangeAtIndex(groupno), withString: replacement)
|
||||
|
||||
|
||||
target = mut as String
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func matchResults(options: NSMatchingOptions = nil) -> [NSTextCheckingResult]? {
|
||||
let matches = regex.matchesInString(target as String, options: options, range: targetRange)
|
||||
as? [NSTextCheckingResult]
|
||||
|
||||
|
||||
if matches != nil {
|
||||
return matches!
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func ranges(options: NSMatchingOptions = nil) -> [NSRange] {
|
||||
return matchResults(options: options)!.map { $0.range }
|
||||
}
|
||||
|
||||
|
||||
public func matches(options: NSMatchingOptions = nil) -> [String] {
|
||||
return matchResults(options: options)!.map( { self.substring($0.range)!})
|
||||
}
|
||||
|
||||
|
||||
public func allGroups(options: NSMatchingOptions = nil) -> [[String]?] {
|
||||
return matchResults(options: options)!.map {self.groupsForMatch($0)}
|
||||
}
|
||||
|
||||
|
||||
public func dictionary(options: NSMatchingOptions = nil) -> Dictionary<String,String> {
|
||||
var out = Dictionary<String,String>()
|
||||
for match in matchResults(options: options)! {
|
||||
@@ -137,26 +137,26 @@ public class SwiftRegex: NSObject, BooleanType {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func substituteMatches(substitution: (NSTextCheckingResult, UnsafeMutablePointer<ObjCBool>) -> String,
|
||||
|
||||
func substituteMatches(substitution: ((NSTextCheckingResult, UnsafeMutablePointer<ObjCBool>) -> String),
|
||||
options:NSMatchingOptions = nil) -> String {
|
||||
let out = NSMutableString()
|
||||
var pos = 0
|
||||
|
||||
|
||||
regex.enumerateMatchesInString(target as String, options: options, range: targetRange ) {
|
||||
(match: NSTextCheckingResult!, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) in
|
||||
|
||||
|
||||
let matchRange = match.range
|
||||
out.appendString( self.substring(NSRange(location:pos, length:matchRange.location-pos))!)
|
||||
out.appendString( substitution(match, stop) )
|
||||
pos = matchRange.location + matchRange.length
|
||||
}
|
||||
|
||||
out.appendString(substring( NSRange(location:pos, length:targetRange.length-pos))!)
|
||||
|
||||
|
||||
out.appendString(substring(NSRange(location:pos, length:targetRange.length-pos))!)
|
||||
|
||||
return out as String
|
||||
}
|
||||
|
||||
|
||||
public var boolValue: Bool {
|
||||
return doesMatch()
|
||||
}
|
||||
@@ -184,11 +184,11 @@ public func ~= (left: SwiftRegex, right: String) -> String {
|
||||
public func ~= (left: SwiftRegex, right: [String]) -> String {
|
||||
var matchNumber = 0
|
||||
return left.substituteMatches({match, stop -> String in
|
||||
|
||||
|
||||
if ++matchNumber == right.count {
|
||||
stop.memory = true
|
||||
}
|
||||
|
||||
|
||||
return left.regex.replacementStringForResult( match,
|
||||
inString: left.target as String, offset: 0, template: right[matchNumber-1] )
|
||||
}, options: nil)
|
||||
@@ -7,7 +7,6 @@
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
import Foundation
|
||||
import CoreFoundation
|
||||
|
||||
public protocol WebSocketDelegate: class {
|
||||
func websocketDidConnect(socket: WebSocket)
|
||||
@@ -79,6 +78,7 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
var buffer: NSMutableData?
|
||||
}
|
||||
|
||||
private var cookies:[NSHTTPCookie]?
|
||||
public weak var delegate: WebSocketDelegate?
|
||||
private var url: NSURL
|
||||
private var inputStream: NSInputStream?
|
||||
@@ -104,6 +104,11 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
public init(url: NSURL) {
|
||||
self.url = url
|
||||
}
|
||||
public convenience init(url: NSURL, cookies:[NSHTTPCookie]?) {
|
||||
self.init(url: url)
|
||||
self.cookies = cookies
|
||||
|
||||
}
|
||||
//used for setting protocols.
|
||||
public convenience init(url: NSURL, protocols: Array<String>) {
|
||||
self.init(url: url)
|
||||
@@ -176,6 +181,14 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
port = 80
|
||||
}
|
||||
}
|
||||
|
||||
if self.cookies != nil {
|
||||
let headers = NSHTTPCookie.requestHeaderFieldsWithCookies(self.cookies!)
|
||||
for (key, value) in headers {
|
||||
self.addHeader(urlRequest, key: key as! String, val: value as! String)
|
||||
}
|
||||
}
|
||||
|
||||
self.addHeader(urlRequest, key: headerWSUpgradeName, val: headerWSUpgradeValue)
|
||||
self.addHeader(urlRequest, key: headerWSConnectionName, val: headerWSConnectionValue)
|
||||
if let protocols = optionalProtocols {
|
||||
@@ -236,8 +249,8 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
}
|
||||
if self.selfSignedSSL {
|
||||
let settings: Dictionary<NSObject, NSObject> = [kCFStreamSSLValidatesCertificateChain: NSNumber(bool:false), kCFStreamSSLPeerName: kCFNull]
|
||||
inputStream!.setProperty(settings, forKey: kCFStreamPropertySSLSettings)
|
||||
outputStream!.setProperty(settings, forKey: kCFStreamPropertySSLSettings)
|
||||
inputStream!.setProperty(settings, forKey: kCFStreamPropertySSLSettings as String)
|
||||
outputStream!.setProperty(settings, forKey: kCFStreamPropertySSLSettings as String)
|
||||
}
|
||||
isRunLoop = true
|
||||
inputStream!.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
|
||||
@@ -247,18 +260,18 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
let bytes = UnsafePointer<UInt8>(data.bytes)
|
||||
outputStream!.write(bytes, maxLength: data.length)
|
||||
while(isRunLoop) {
|
||||
NSRunLoop.currentRunLoop().runMode(NSDefaultRunLoopMode, beforeDate: NSDate.distantFuture() as NSDate)
|
||||
NSRunLoop.currentRunLoop().runMode(NSDefaultRunLoopMode, beforeDate: NSDate.distantFuture() as! NSDate)
|
||||
}
|
||||
}
|
||||
//delegate for the stream methods. Processes incoming bytes
|
||||
func stream(aStream: NSStream!, handleEvent eventCode: NSStreamEvent) {
|
||||
public func stream(aStream: NSStream, handleEvent eventCode: NSStreamEvent) {
|
||||
|
||||
if eventCode == .HasBytesAvailable {
|
||||
if(aStream == inputStream) {
|
||||
processInputStream()
|
||||
}
|
||||
} else if eventCode == .ErrorOccurred {
|
||||
disconnectStream(aStream!.streamError)
|
||||
disconnectStream(aStream.streamError)
|
||||
} else if eventCode == .EndEncountered {
|
||||
disconnectStream(nil)
|
||||
}
|
||||
@@ -333,7 +346,7 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
}
|
||||
///Finds the HTTP Packet in the TCP stream, by looking for the CRLF.
|
||||
private func processHTTP(buffer: UnsafePointer<UInt8>, bufferLen: Int) -> Bool {
|
||||
let CRLFBytes = [UInt8("\r"), UInt8("\n"), UInt8("\r"), UInt8("\n")]
|
||||
let CRLFBytes = [UInt8(ascii: "\r"), UInt8(ascii: "\n"), UInt8(ascii: "\r"), UInt8(ascii: "\n")]
|
||||
var k = 0
|
||||
var totalSize = 0
|
||||
for var i = 0; i < bufferLen; i++ {
|
||||
@@ -369,14 +382,14 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
|
||||
///validates the HTTP is a 101 as per the RFC spec
|
||||
private func validateResponse(buffer: UnsafePointer<UInt8>, bufferLen: Int) -> Bool {
|
||||
let response = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, 0)
|
||||
CFHTTPMessageAppendBytes(response.takeUnretainedValue(), buffer, bufferLen)
|
||||
if CFHTTPMessageGetResponseStatusCode(response.takeUnretainedValue()) != 101 {
|
||||
let response = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, 0).takeRetainedValue()
|
||||
CFHTTPMessageAppendBytes(response, buffer, bufferLen)
|
||||
if CFHTTPMessageGetResponseStatusCode(response) != 101 {
|
||||
return false
|
||||
}
|
||||
let cfHeaders = CFHTTPMessageCopyAllHeaderFields(response.takeUnretainedValue())
|
||||
let headers: NSDictionary = cfHeaders.takeUnretainedValue()
|
||||
let acceptKey = headers[headerWSAcceptName] as NSString
|
||||
let cfHeaders = CFHTTPMessageCopyAllHeaderFields(response)
|
||||
let headers: NSDictionary = cfHeaders.takeRetainedValue()
|
||||
let acceptKey = headers[headerWSAcceptName] as! NSString
|
||||
if acceptKey.length > 0 {
|
||||
return true
|
||||
}
|
||||
@@ -500,7 +513,7 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
data = NSData(bytes: UnsafePointer<UInt8>((buffer+offset)), length: Int(len))
|
||||
}
|
||||
if receivedOpcode == OpCode.Pong.rawValue {
|
||||
let step = Int(offset+len)
|
||||
let step = offset + Int(len)
|
||||
let extra = bufferLen-step
|
||||
if extra > 0 {
|
||||
processRawMessage((buffer+step), bufferLen: extra)
|
||||
@@ -565,7 +578,7 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
processResponse(response!)
|
||||
}
|
||||
|
||||
let step = Int(offset+len)
|
||||
let step = offset + Int(len)
|
||||
let extra = bufferLen-step
|
||||
if(extra > 0) {
|
||||
processExtra((buffer+step), bufferLen: extra)
|
||||
@@ -597,9 +610,9 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
}
|
||||
dispatch_async(queue,{
|
||||
if let textBlock = self.receivedTextBlock{
|
||||
textBlock(str!)
|
||||
textBlock(str! as String)
|
||||
}
|
||||
self.delegate?.websocketDidReceiveMessage(self, text: str!)
|
||||
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
|
||||
@@ -673,7 +686,7 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
}
|
||||
buffer[1] |= self.MaskMask
|
||||
var maskKey = UnsafeMutablePointer<UInt8>(buffer + offset)
|
||||
SecRandomCopyBytes(kSecRandomDefault, UInt(sizeof(UInt32)), maskKey)
|
||||
SecRandomCopyBytes(kSecRandomDefault, Int(sizeof(UInt32)), maskKey)
|
||||
offset += sizeof(UInt32)
|
||||
|
||||
for (var i = 0; i < dataLength; i++) {
|
||||
@@ -711,4 +724,4 @@ public class WebSocket : NSObject, NSStreamDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,609 +0,0 @@
|
||||
//
|
||||
// SocketEngine.swift
|
||||
// Socket.IO-Swift
|
||||
//
|
||||
// Created by Erik Little on 3/3/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.
|
||||
|
||||
import Foundation
|
||||
|
||||
extension String {
|
||||
private var length:Int {
|
||||
return countElements(self)
|
||||
}
|
||||
}
|
||||
|
||||
private typealias Probe = (msg:String, type:PacketType, data:[NSData]?)
|
||||
private typealias ProbeWaitQueue = [Probe]
|
||||
|
||||
public enum PacketType: String {
|
||||
case OPEN = "0"
|
||||
case CLOSE = "1"
|
||||
case PING = "2"
|
||||
case PONG = "3"
|
||||
case MESSAGE = "4"
|
||||
case UPGRADE = "5"
|
||||
case NOOP = "6"
|
||||
}
|
||||
|
||||
public class SocketEngine: NSObject, WebSocketDelegate {
|
||||
unowned let client:SocketEngineClient
|
||||
private let workQueue = NSOperationQueue()
|
||||
private let emitQueue = dispatch_queue_create(
|
||||
"emitQueue".cStringUsingEncoding(NSUTF8StringEncoding), DISPATCH_QUEUE_SERIAL)
|
||||
private let parseQueue = dispatch_queue_create(
|
||||
"parseQueue".cStringUsingEncoding(NSUTF8StringEncoding), DISPATCH_QUEUE_SERIAL)
|
||||
private let handleQueue = dispatch_queue_create(
|
||||
"handleQueue".cStringUsingEncoding(NSUTF8StringEncoding), DISPATCH_QUEUE_SERIAL)
|
||||
private let session:NSURLSession!
|
||||
private var _connected = false
|
||||
private var fastUpgrade = false
|
||||
private var forcePolling = false
|
||||
private var pingTimer:NSTimer?
|
||||
private var postWait = [String]()
|
||||
private var _polling = true
|
||||
private var probing = false
|
||||
private var probeWait = ProbeWaitQueue()
|
||||
private var waitingForPoll = false
|
||||
private var waitingForPost = false
|
||||
private var _websocket = false
|
||||
private var websocketConnected = false
|
||||
var connected:Bool {
|
||||
return self._connected
|
||||
}
|
||||
var cookies:[NSHTTPCookie]?
|
||||
var pingInterval:Int?
|
||||
var polling:Bool {
|
||||
return self._polling
|
||||
}
|
||||
var sid = ""
|
||||
var urlPolling:String?
|
||||
var urlWebSocket:String?
|
||||
var websocket:Bool {
|
||||
return self._websocket
|
||||
}
|
||||
var ws:WebSocket?
|
||||
|
||||
init(client:SocketEngineClient, forcePolling:Bool, withCookies cookies:[NSHTTPCookie]?) {
|
||||
self.client = client
|
||||
self.forcePolling = forcePolling
|
||||
self.cookies = cookies
|
||||
self.session = NSURLSession(configuration: NSURLSessionConfiguration.ephemeralSessionConfiguration(),
|
||||
delegate: nil, delegateQueue: self.workQueue)
|
||||
}
|
||||
|
||||
func close() {
|
||||
self.pingTimer?.invalidate()
|
||||
self.send(PacketType.CLOSE.rawValue)
|
||||
}
|
||||
|
||||
private func createBinaryDataForSend(data:NSData) -> (NSData?, String?) {
|
||||
if self.websocket {
|
||||
var byteArray = [UInt8](count: 1, repeatedValue: 0x0)
|
||||
byteArray[0] = 4
|
||||
var mutData = NSMutableData(bytes: &byteArray, length: 1)
|
||||
mutData.appendData(data)
|
||||
return (mutData, nil)
|
||||
} else {
|
||||
var str = "b4"
|
||||
str += data.base64EncodedStringWithOptions(
|
||||
NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
|
||||
|
||||
return (nil, str)
|
||||
}
|
||||
}
|
||||
|
||||
private func createURLs(params:[String: AnyObject]?) -> (String, String) {
|
||||
var url = "\(self.client.socketURL)/socket.io/?transport="
|
||||
var urlPolling:String
|
||||
var urlWebSocket:String
|
||||
|
||||
if self.client.secure {
|
||||
urlPolling = "https://" + url + "polling"
|
||||
urlWebSocket = "wss://" + url + "websocket"
|
||||
} else {
|
||||
urlPolling = "http://" + url + "polling"
|
||||
urlWebSocket = "ws://" + url + "websocket"
|
||||
}
|
||||
|
||||
if params != nil {
|
||||
for (key, value) in params! {
|
||||
let keyEsc = key.stringByAddingPercentEncodingWithAllowedCharacters(
|
||||
NSCharacterSet.URLHostAllowedCharacterSet())!
|
||||
urlPolling += "&\(keyEsc)="
|
||||
urlWebSocket += "&\(keyEsc)="
|
||||
|
||||
if value is String {
|
||||
let valueEsc = (value as String).stringByAddingPercentEncodingWithAllowedCharacters(
|
||||
NSCharacterSet.URLHostAllowedCharacterSet())!
|
||||
urlPolling += "\(valueEsc)"
|
||||
urlWebSocket += "\(valueEsc)"
|
||||
} else {
|
||||
urlPolling += "\(value)"
|
||||
urlWebSocket += "\(value)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (urlPolling, urlWebSocket)
|
||||
}
|
||||
|
||||
private func doFastUpgrade() {
|
||||
self.sendWebSocketMessage("", withType: PacketType.UPGRADE)
|
||||
self._websocket = true
|
||||
self._polling = false
|
||||
self.fastUpgrade = false
|
||||
self.flushProbeWait()
|
||||
}
|
||||
|
||||
private func doPoll() {
|
||||
if self.websocket || self.waitingForPoll || !self.connected {
|
||||
return
|
||||
}
|
||||
|
||||
self.waitingForPoll = true
|
||||
self.doRequest(self.parsePollingMessage)
|
||||
}
|
||||
|
||||
private func doRequest(callback:(String) -> Void) {
|
||||
if !self.polling {
|
||||
return
|
||||
}
|
||||
|
||||
let req = NSURLRequest(URL: NSURL(string: self.urlPolling! + "&sid=\(self.sid)")!)
|
||||
|
||||
self.session.dataTaskWithRequest(req) {[weak self] data, res, err in
|
||||
if self == nil {
|
||||
return
|
||||
} else if err != nil {
|
||||
if self!.polling {
|
||||
self?.handlePollingFailed(err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// println(data)
|
||||
|
||||
if let str = NSString(data: data, encoding: NSUTF8StringEncoding) as? String {
|
||||
dispatch_async(self!.parseQueue) {callback(str)}
|
||||
}
|
||||
|
||||
self?.waitingForPoll = false
|
||||
|
||||
if self!.fastUpgrade {
|
||||
self?.doFastUpgrade()
|
||||
return
|
||||
} else {
|
||||
self?.doPoll()
|
||||
}
|
||||
}.resume()
|
||||
}
|
||||
|
||||
private func flushProbeWait() {
|
||||
// println("flushing probe wait")
|
||||
dispatch_async(self.emitQueue) {[weak self] in
|
||||
if self == nil {
|
||||
return
|
||||
}
|
||||
|
||||
for waiter in self!.probeWait {
|
||||
self?.write(waiter.msg, withType: waiter.type, withData: waiter.data)
|
||||
}
|
||||
|
||||
self?.probeWait.removeAll(keepCapacity: false)
|
||||
}
|
||||
}
|
||||
|
||||
private func flushWaitingForPost() {
|
||||
if self.postWait.count == 0 || !self.connected {
|
||||
return
|
||||
} else if self.websocket {
|
||||
self.flushWaitingForPostToWebSocket()
|
||||
return
|
||||
}
|
||||
|
||||
var postStr = ""
|
||||
|
||||
for packet in self.postWait {
|
||||
let len = countElements(packet)
|
||||
|
||||
postStr += "\(len):\(packet)"
|
||||
}
|
||||
|
||||
self.postWait.removeAll(keepCapacity: false)
|
||||
|
||||
let req = NSMutableURLRequest(URL: NSURL(string: self.urlPolling! + "&sid=\(self.sid)")!)
|
||||
|
||||
req.HTTPMethod = "POST"
|
||||
req.setValue("text/plain; charset=UTF-8", forHTTPHeaderField: "Content-Type")
|
||||
|
||||
let postData = postStr.dataUsingEncoding(NSUTF8StringEncoding,
|
||||
allowLossyConversion: false)!
|
||||
|
||||
// NSLog("posting: \(postStr)")
|
||||
req.HTTPBody = postData
|
||||
req.setValue(String(postData.length), forHTTPHeaderField: "Content-Length")
|
||||
|
||||
self.waitingForPost = true
|
||||
self.session.dataTaskWithRequest(req) {[weak self] data, res, err in
|
||||
if self == nil {
|
||||
return
|
||||
} else if err != nil && self!.polling {
|
||||
self?.handlePollingFailed(err)
|
||||
return
|
||||
}
|
||||
|
||||
self?.waitingForPost = false
|
||||
dispatch_async(self!.emitQueue) {
|
||||
self?.flushWaitingForPost()
|
||||
self?.doPoll()
|
||||
return
|
||||
}}.resume()
|
||||
}
|
||||
|
||||
// We had packets waiting for send when we upgraded
|
||||
// Send them raw
|
||||
private func flushWaitingForPostToWebSocket() {
|
||||
for msg in self.postWait {
|
||||
self.ws?.writeString(msg)
|
||||
}
|
||||
|
||||
self.postWait.removeAll(keepCapacity: true)
|
||||
}
|
||||
|
||||
// A poll failed, tell the client about it
|
||||
private func handlePollingFailed(reason:NSError?) {
|
||||
assert(self.polling, "Polling failed when we're not polling")
|
||||
|
||||
if !self.client.reconnecting {
|
||||
self._connected = false
|
||||
self.ws?.disconnect()
|
||||
self.pingTimer?.invalidate()
|
||||
self.waitingForPoll = false
|
||||
self.waitingForPost = false
|
||||
self.client.pollingDidFail(reason)
|
||||
}
|
||||
}
|
||||
|
||||
func open(opts:[String: AnyObject]? = nil) {
|
||||
if self.connected {
|
||||
assert(false, "We're in a bad state, this shouldn't happen.")
|
||||
}
|
||||
|
||||
let (urlPolling, urlWebSocket) = self.createURLs(opts)
|
||||
self.urlPolling = urlPolling
|
||||
self.urlWebSocket = urlWebSocket
|
||||
let reqPolling = NSMutableURLRequest(URL: NSURL(string: urlPolling + "&b64=1")!)
|
||||
|
||||
if self.cookies != nil {
|
||||
let headers = NSHTTPCookie.requestHeaderFieldsWithCookies(self.cookies!)
|
||||
reqPolling.allHTTPHeaderFields = headers
|
||||
}
|
||||
|
||||
|
||||
self.session.dataTaskWithRequest(reqPolling) {[weak self] data, res, err in
|
||||
var err2:NSError?
|
||||
if self == nil {
|
||||
return
|
||||
} else if err != nil || data == nil {
|
||||
self?.handlePollingFailed(err)
|
||||
return
|
||||
}
|
||||
|
||||
if let dataString = NSString(data: data, encoding: NSUTF8StringEncoding) as? String {
|
||||
let parsed:[String]? = dataString["(\\d*):(\\d)(\\{.*\\})?"].groups()
|
||||
|
||||
if parsed == nil || parsed?.count != 4 {
|
||||
return
|
||||
}
|
||||
|
||||
let length = parsed![1]
|
||||
let type = parsed![2]
|
||||
let jsonData = parsed![3].dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
|
||||
|
||||
if type != "0" {
|
||||
NSLog("Error handshaking")
|
||||
return
|
||||
}
|
||||
|
||||
if let json = NSJSONSerialization.JSONObjectWithData(jsonData!,
|
||||
options: NSJSONReadingOptions.AllowFragments, error: &err2) as? NSDictionary {
|
||||
if let sid = json["sid"] as? String {
|
||||
// println(json)
|
||||
self?.sid = sid
|
||||
self?._connected = true
|
||||
|
||||
if !self!.forcePolling {
|
||||
self?.ws = WebSocket(url: NSURL(string: urlWebSocket + "&sid=\(self!.sid)")!)
|
||||
self?.ws?.queue = self?.handleQueue
|
||||
self?.ws?.delegate = self
|
||||
self?.ws?.connect()
|
||||
}
|
||||
} else {
|
||||
NSLog("Error handshaking")
|
||||
return
|
||||
}
|
||||
|
||||
if let pingInterval = json["pingInterval"] as? Int {
|
||||
self?.pingInterval = pingInterval / 1000
|
||||
}
|
||||
}
|
||||
|
||||
self?.doPoll()
|
||||
self?.startPingTimer()
|
||||
}}.resume()
|
||||
}
|
||||
|
||||
// Translatation of engine.io-parser#decodePayload
|
||||
private func parsePollingMessage(str:String) {
|
||||
if str.length == 1 {
|
||||
return
|
||||
}
|
||||
|
||||
// println(str)
|
||||
|
||||
let strArray = Array(str)
|
||||
var length = ""
|
||||
var n = 0
|
||||
var msg = ""
|
||||
|
||||
func testLength(length:String, inout n:Int) -> Bool {
|
||||
if let num = length.toInt() {
|
||||
n = num
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
for var i = 0, l = str.length; i < l; i = i &+ 1 {
|
||||
let chr = String(strArray[i])
|
||||
|
||||
if chr != ":" {
|
||||
length += chr
|
||||
} else {
|
||||
if length == "" || testLength(length, &n) {
|
||||
println("failure in parsePollingMessage")
|
||||
return
|
||||
}
|
||||
|
||||
msg = String(strArray[i&+1...i&+n])
|
||||
|
||||
if let lengthInt = length.toInt() {
|
||||
if lengthInt != msg.length {
|
||||
println("parsing error")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if msg.length != 0 {
|
||||
// Be sure to capture the value of the msg
|
||||
dispatch_async(self.handleQueue) {[weak self, msg] in
|
||||
self?.parseEngineMessage(msg)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
i += n
|
||||
length = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func parseEngineData(data:NSData) {
|
||||
dispatch_async(self.client.handleQueue) {[weak self] in
|
||||
self?.client.parseBinaryData(data.subdataWithRange(NSMakeRange(1, data.length - 1)))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
private func parseEngineMessage(var message:String) {
|
||||
// NSLog("Engine got message: \(message)")
|
||||
if self.polling {
|
||||
fixDoubleUTF8(&message)
|
||||
}
|
||||
|
||||
// We should upgrade
|
||||
if message == "3probe" {
|
||||
self.upgradeTransport()
|
||||
return
|
||||
}
|
||||
|
||||
let type = message["^(\\d)"].groups()?[1]
|
||||
|
||||
if type != PacketType.MESSAGE.rawValue {
|
||||
// TODO Handle other packets
|
||||
if message.hasPrefix("b4") {
|
||||
// binary in base64 string
|
||||
|
||||
message.removeRange(Range<String.Index>(start: message.startIndex,
|
||||
end: advance(message.startIndex, 2)))
|
||||
|
||||
if let data = NSData(base64EncodedString: message,
|
||||
options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters) {
|
||||
// println("sending \(data)")
|
||||
dispatch_async(self.client.handleQueue) {[weak self] in
|
||||
self?.client.parseBinaryData(data)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
} else if type == PacketType.NOOP.rawValue {
|
||||
self.doPoll()
|
||||
return
|
||||
} else if type == PacketType.PONG.rawValue {
|
||||
return
|
||||
}
|
||||
|
||||
if message == PacketType.CLOSE.rawValue {
|
||||
// do nothing
|
||||
return
|
||||
}
|
||||
// println("Got something idk what to do with")
|
||||
// println(messageString)
|
||||
}
|
||||
|
||||
// Remove message type
|
||||
message.removeAtIndex(message.startIndex)
|
||||
|
||||
dispatch_async(self.client.handleQueue) {[weak self] in
|
||||
self?.client.parseSocketMessage(message)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
private func probeWebSocket() {
|
||||
if self.websocketConnected {
|
||||
self.sendWebSocketMessage("probe", withType: PacketType.PING)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Send a message with type 4
|
||||
*/
|
||||
public func send(msg:String, datas:[NSData]? = nil) {
|
||||
if self.probing {
|
||||
self.probeWait.append((msg, PacketType.MESSAGE, datas))
|
||||
} else {
|
||||
self.write(msg, withType: PacketType.MESSAGE, withData: datas)
|
||||
}
|
||||
}
|
||||
|
||||
func sendPing() {
|
||||
if self.websocket {
|
||||
self.sendWebSocketMessage("", withType: PacketType.PING)
|
||||
} else {
|
||||
self.sendPollMessage("", withType: PacketType.PING)
|
||||
}
|
||||
}
|
||||
|
||||
private func sendPollMessage(var msg:String, withType type:PacketType,
|
||||
datas:[NSData]? = nil) {
|
||||
// println("Sending poll: \(msg) as type: \(type.rawValue)")
|
||||
|
||||
doubleEncodeUTF8(&msg)
|
||||
let strMsg = "\(type.rawValue)\(msg)"
|
||||
|
||||
self.postWait.append(strMsg)
|
||||
|
||||
if datas != nil {
|
||||
for data in datas! {
|
||||
let (nilData, b64Data) = self.createBinaryDataForSend(data)
|
||||
|
||||
self.postWait.append(b64Data!)
|
||||
}
|
||||
}
|
||||
|
||||
if !self.waitingForPost {
|
||||
self.flushWaitingForPost()
|
||||
}
|
||||
}
|
||||
|
||||
private func sendWebSocketMessage(str:String, withType type:PacketType, datas:[NSData]? = nil) {
|
||||
// println("Sending ws: \(str) as type: \(type.rawValue)")
|
||||
self.ws?.writeString("\(type.rawValue)\(str)")
|
||||
|
||||
if datas != nil {
|
||||
for data in datas! {
|
||||
let (data, nilString) = self.createBinaryDataForSend(data)
|
||||
if data != nil {
|
||||
self.ws?.writeData(data!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Starts the ping timer
|
||||
private func startPingTimer() {
|
||||
if self.pingInterval == nil {
|
||||
return
|
||||
}
|
||||
|
||||
self.pingTimer?.invalidate()
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
self.pingTimer = NSTimer.scheduledTimerWithTimeInterval(NSTimeInterval(self.pingInterval!),
|
||||
target: self,
|
||||
selector: Selector("sendPing"), userInfo: nil, repeats: true)
|
||||
}
|
||||
}
|
||||
|
||||
private func upgradeTransport() {
|
||||
if self.websocketConnected {
|
||||
// Do a fast upgrade
|
||||
self.fastUpgrade = true
|
||||
self.probing = false
|
||||
self.sendPollMessage("", withType: PacketType.NOOP)
|
||||
}
|
||||
}
|
||||
|
||||
public func write(msg:String, withType type:PacketType, withData data:[NSData]?) {
|
||||
dispatch_async(self.emitQueue) {[weak self] in
|
||||
if self == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !self!.connected {
|
||||
return
|
||||
}
|
||||
|
||||
if self!.websocket {
|
||||
// NSLog("writing ws: \(msg):\(datas)")
|
||||
self?.sendWebSocketMessage(msg, withType: type, datas: data)
|
||||
} else {
|
||||
// NSLog("writing poll: \(msg):\(datas)")
|
||||
self?.sendPollMessage(msg, withType: type, datas: data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delagate methods
|
||||
|
||||
public func websocketDidConnect(socket:WebSocket) {
|
||||
self.websocketConnected = true
|
||||
self.probing = true
|
||||
self.probeWebSocket()
|
||||
}
|
||||
|
||||
public func websocketDidDisconnect(socket:WebSocket, error:NSError?) {
|
||||
self.websocketConnected = false
|
||||
self.probing = false
|
||||
|
||||
if self.websocket {
|
||||
self.pingTimer?.invalidate()
|
||||
self._connected = false
|
||||
self._websocket = false
|
||||
self._polling = true
|
||||
self.client.webSocketDidCloseWithCode(1, reason: "Socket Disconnect", wasClean: true)
|
||||
} else {
|
||||
self.flushProbeWait()
|
||||
}
|
||||
}
|
||||
|
||||
public func websocketDidReceiveMessage(socket:WebSocket, text:String) {
|
||||
self.parseEngineMessage(text)
|
||||
}
|
||||
|
||||
public func websocketDidReceiveData(socket:WebSocket, data:NSData) {
|
||||
self.parseEngineData(data)
|
||||
}
|
||||
}
|
||||
@@ -1,250 +0,0 @@
|
||||
//
|
||||
// Event.swift
|
||||
// Socket.IO-Swift
|
||||
//
|
||||
// Created by Erik Little on 1/18/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.
|
||||
|
||||
import Foundation
|
||||
|
||||
class SocketEvent {
|
||||
let justAck:Bool!
|
||||
var ack:Int?
|
||||
var args:AnyObject!
|
||||
lazy var currentPlace = 0
|
||||
lazy var datas = [NSData]()
|
||||
var event:String!
|
||||
var placeholders:Int!
|
||||
|
||||
init(event:String, args:AnyObject?, placeholders:Int = 0, ackNum:Int? = nil, justAck:Bool = false) {
|
||||
self.event = event
|
||||
self.args = args
|
||||
self.placeholders = placeholders
|
||||
self.ack = ackNum
|
||||
self.justAck = justAck
|
||||
}
|
||||
|
||||
func addData(data:NSData) -> Bool {
|
||||
func checkDoEvent() -> Bool {
|
||||
if self.placeholders == self.currentPlace {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if checkDoEvent() {
|
||||
return true
|
||||
}
|
||||
|
||||
self.datas.append(data)
|
||||
self.currentPlace++
|
||||
|
||||
if checkDoEvent() {
|
||||
self.currentPlace = 0
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
class func createMessageForEvent(event:String, withArgs args:[AnyObject],
|
||||
hasBinary:Bool, withDatas datas:Int = 0, toNamespace nsp:String?, wantsAck ack:Int? = nil) -> String {
|
||||
|
||||
var message:String
|
||||
var jsonSendError:NSError?
|
||||
|
||||
if !hasBinary {
|
||||
if nsp == nil {
|
||||
if ack == nil {
|
||||
message = "2[\"\(event)\""
|
||||
} else {
|
||||
message = "2\(ack!)[\"\(event)\""
|
||||
}
|
||||
} else {
|
||||
if ack == nil {
|
||||
message = "2/\(nsp!),[\"\(event)\""
|
||||
} else {
|
||||
message = "2/\(nsp!),\(ack!)[\"\(event)\""
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if nsp == nil {
|
||||
if ack == nil {
|
||||
message = "5\(datas)-[\"\(event)\""
|
||||
} else {
|
||||
message = "5\(datas)-\(ack!)[\"\(event)\""
|
||||
}
|
||||
} else {
|
||||
if ack == nil {
|
||||
message = "5\(datas)-/\(nsp!),[\"\(event)\""
|
||||
} else {
|
||||
message = "5\(datas)-/\(nsp!),\(ack!)[\"\(event)\""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self.completeMessage(message, args: args)
|
||||
}
|
||||
|
||||
class func createAck(ack:Int, withArgs args:[AnyObject], withAckType ackType:Int,
|
||||
withNsp nsp:String, withBinary binary:Int = 0) -> String {
|
||||
var msg:String
|
||||
|
||||
if ackType == 3 {
|
||||
if nsp == "/" {
|
||||
msg = "3\(ack)["
|
||||
} else {
|
||||
msg = "3/\(nsp),\(ack)["
|
||||
}
|
||||
} else {
|
||||
if nsp == "/" {
|
||||
msg = "6\(binary)-\(ack)["
|
||||
} else {
|
||||
msg = "6\(binary)-/\(nsp),\(ack)["
|
||||
}
|
||||
}
|
||||
|
||||
return self.completeMessage(msg, args: args, ack: true)
|
||||
}
|
||||
|
||||
private class func completeMessage(var message:String, args:[AnyObject], ack:Bool = false) -> String {
|
||||
var err:NSError?
|
||||
|
||||
if args.count == 0 {
|
||||
return message + "]"
|
||||
} else if !ack {
|
||||
message += ","
|
||||
}
|
||||
|
||||
for arg in args {
|
||||
|
||||
if arg is NSDictionary || arg is [AnyObject] {
|
||||
let jsonSend = NSJSONSerialization.dataWithJSONObject(arg,
|
||||
options: NSJSONWritingOptions(0), error: &err)
|
||||
let jsonString = NSString(data: jsonSend!, encoding: NSUTF8StringEncoding)
|
||||
|
||||
message += jsonString! as String
|
||||
message += ","
|
||||
continue
|
||||
}
|
||||
|
||||
if arg is String {
|
||||
message += "\"\(arg)\""
|
||||
message += ","
|
||||
continue
|
||||
}
|
||||
|
||||
message += "\(arg)"
|
||||
message += ","
|
||||
}
|
||||
|
||||
if message != "" {
|
||||
message.removeAtIndex(message.endIndex.predecessor())
|
||||
}
|
||||
|
||||
return message + "]"
|
||||
}
|
||||
|
||||
private func fillInArray(arr:NSArray) -> NSArray {
|
||||
var newArr = [AnyObject](count: arr.count, repeatedValue: 0)
|
||||
// println(arr)
|
||||
|
||||
for i in 0..<arr.count {
|
||||
if let nest = arr[i] as? NSArray {
|
||||
newArr[i] = self.fillInArray(nest)
|
||||
} else if let dict = arr[i] as? NSDictionary {
|
||||
newArr[i] = self.fillInDict(dict)
|
||||
} else if let str = arr[i] as? String {
|
||||
if let num = str["~~(\\d)"].groups() {
|
||||
newArr[i] = self.datas[num[1].toInt()!]
|
||||
} else {
|
||||
newArr[i] = arr[i]
|
||||
}
|
||||
} else {
|
||||
newArr[i] = arr[i]
|
||||
}
|
||||
}
|
||||
|
||||
return newArr
|
||||
}
|
||||
|
||||
private func fillInDict(dict:NSDictionary) -> NSDictionary {
|
||||
var newDict = [String: AnyObject]()
|
||||
|
||||
for (key, value) in dict {
|
||||
newDict[key as String] = value
|
||||
|
||||
// If the value is a string we need to check
|
||||
// if it is a placeholder for data
|
||||
if let str = value as? String {
|
||||
if let num = str["~~(\\d)"].groups() {
|
||||
newDict[key as String] = self.datas[num[1].toInt()!]
|
||||
} else {
|
||||
newDict[key as String] = str
|
||||
}
|
||||
} else if let nestDict = value as? NSDictionary {
|
||||
newDict[key as String] = self.fillInDict(nestDict)
|
||||
} else if let arr = value as? NSArray {
|
||||
newDict[key as String] = self.fillInArray(arr)
|
||||
}
|
||||
}
|
||||
|
||||
return newDict
|
||||
}
|
||||
|
||||
func fillInPlaceholders(_ args:AnyObject = true) -> AnyObject {
|
||||
if let dict = args as? NSDictionary {
|
||||
return self.fillInDict(dict)
|
||||
} else if let arr = args as? NSArray {
|
||||
return self.fillInArray(args as NSArray)
|
||||
} else if let string = args as? String {
|
||||
if string == "~~\(self.currentPlace)" {
|
||||
return self.datas[0]
|
||||
}
|
||||
} else if args is Bool {
|
||||
// We have multiple items
|
||||
// Do it live
|
||||
let argsAsArray = "[\(self.args)]"
|
||||
if let parsedArr = SocketParser.parseData(argsAsArray) as? NSArray {
|
||||
var returnArr = [AnyObject](count: parsedArr.count, repeatedValue: 0)
|
||||
|
||||
for i in 0..<parsedArr.count {
|
||||
if let str = parsedArr[i] as? String {
|
||||
if let num = str["~~(\\d)"].groups() {
|
||||
returnArr[i] = self.datas[num[1].toInt()!]
|
||||
} else {
|
||||
returnArr[i] = str
|
||||
}
|
||||
} else if let arr = parsedArr[i] as? NSArray {
|
||||
returnArr[i] = self.fillInArray(arr)
|
||||
} else if let dict = parsedArr[i] as? NSDictionary {
|
||||
returnArr[i] = self.fillInDict(dict)
|
||||
} else {
|
||||
returnArr[i] = parsedArr[i]
|
||||
}
|
||||
}
|
||||
return returnArr
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -1,490 +0,0 @@
|
||||
//
|
||||
// SocketIOClient.swift
|
||||
// Socket.IO-Swift
|
||||
//
|
||||
// Created by Erik Little on 11/23/14.
|
||||
//
|
||||
// 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.
|
||||
|
||||
import Foundation
|
||||
|
||||
public class SocketIOClient: NSObject, SocketEngineClient {
|
||||
let reconnectAttempts:Int!
|
||||
private lazy var params = [String: AnyObject]()
|
||||
private var ackHandlers = [SocketAckHandler]()
|
||||
private var anyHandler:((AnyHandler) -> Void)?
|
||||
private var _closed = false
|
||||
private var _connected = false
|
||||
private var _connecting = false
|
||||
private var currentReconnectAttempt = 0
|
||||
private var forcePolling = false
|
||||
private var handlers = [SocketEventHandler]()
|
||||
private var paramConnect = false
|
||||
private var _secure = false
|
||||
private var _sid:String?
|
||||
private var _reconnecting = false
|
||||
private var reconnectTimer:NSTimer?
|
||||
|
||||
internal var currentAck = -1
|
||||
internal var waitingData = [SocketEvent]()
|
||||
|
||||
public let socketURL:String
|
||||
public let ackQueue = dispatch_queue_create("ackQueue".cStringUsingEncoding(NSUTF8StringEncoding),
|
||||
DISPATCH_QUEUE_SERIAL)
|
||||
public let handleQueue = dispatch_queue_create("handleQueue".cStringUsingEncoding(NSUTF8StringEncoding),
|
||||
DISPATCH_QUEUE_SERIAL)
|
||||
public let emitQueue = dispatch_queue_create("emitQueue".cStringUsingEncoding(NSUTF8StringEncoding),
|
||||
DISPATCH_QUEUE_SERIAL)
|
||||
public var closed:Bool {
|
||||
return self._closed
|
||||
}
|
||||
public var connected:Bool {
|
||||
return self._connected
|
||||
}
|
||||
public var connecting:Bool {
|
||||
return self._connecting
|
||||
}
|
||||
public var cookies:[NSHTTPCookie]?
|
||||
public var engine:SocketEngine?
|
||||
public var nsp:String?
|
||||
public var reconnects = true
|
||||
public var reconnecting:Bool {
|
||||
return self._reconnecting
|
||||
}
|
||||
public var reconnectWait = 10
|
||||
public var secure:Bool {
|
||||
return self._secure
|
||||
}
|
||||
public var sid:String? {
|
||||
return self._sid
|
||||
}
|
||||
|
||||
/**
|
||||
Create a new SocketIOClient. opts can be omitted
|
||||
*/
|
||||
public init(var socketURL:String, opts:NSDictionary? = nil) {
|
||||
if socketURL["https://"].matches().count != 0 {
|
||||
self._secure = true
|
||||
}
|
||||
|
||||
socketURL = socketURL["http://"] ~= ""
|
||||
socketURL = socketURL["https://"] ~= ""
|
||||
|
||||
self.socketURL = socketURL
|
||||
|
||||
// Set options
|
||||
if opts != nil {
|
||||
if let reconnects = opts!["reconnects"] as? Bool {
|
||||
self.reconnects = reconnects
|
||||
}
|
||||
|
||||
if let reconnectAttempts = opts!["reconnectAttempts"] as? Int {
|
||||
self.reconnectAttempts = reconnectAttempts
|
||||
} else {
|
||||
self.reconnectAttempts = -1
|
||||
}
|
||||
|
||||
if let reconnectWait = opts!["reconnectWait"] as? Int {
|
||||
self.reconnectWait = abs(reconnectWait)
|
||||
}
|
||||
|
||||
if let nsp = opts!["nsp"] as? String {
|
||||
self.nsp = nsp
|
||||
}
|
||||
|
||||
if let polling = opts!["forcePolling"] as? Bool {
|
||||
self.forcePolling = polling
|
||||
}
|
||||
|
||||
if let cookies = opts!["cookies"] as? [NSHTTPCookie] {
|
||||
self.cookies = cookies
|
||||
}
|
||||
} else {
|
||||
self.reconnectAttempts = -1
|
||||
}
|
||||
|
||||
super.init()
|
||||
|
||||
self.engine = SocketEngine(client: self,
|
||||
forcePolling: self.forcePolling,
|
||||
withCookies: self.cookies)
|
||||
}
|
||||
|
||||
public convenience init(socketURL:String, options:NSDictionary?) {
|
||||
self.init(socketURL: socketURL, opts: options)
|
||||
}
|
||||
|
||||
/**
|
||||
Closes the socket. Only reopen the same socket if you know what you're doing.
|
||||
*/
|
||||
public func close() {
|
||||
self._closed = true
|
||||
self._connecting = false
|
||||
self._connected = false
|
||||
self._reconnecting = false
|
||||
self.engine?.close()
|
||||
}
|
||||
|
||||
/**
|
||||
Connect to the server.
|
||||
*/
|
||||
public func connect() {
|
||||
if self.closed {
|
||||
println("Warning! This socket was previously closed. This might be dangerous!")
|
||||
self._closed = false
|
||||
}
|
||||
|
||||
self.engine?.open()
|
||||
}
|
||||
|
||||
/**
|
||||
Connect to the server with params that will be passed on connection.
|
||||
*/
|
||||
public func connectWithParams(params:[String: AnyObject]) {
|
||||
if self.closed {
|
||||
println("Warning! This socket was previously closed. This might be dangerous!")
|
||||
self._closed = false
|
||||
}
|
||||
|
||||
self.params = params
|
||||
self.paramConnect = true
|
||||
|
||||
self.engine?.open(opts: params)
|
||||
}
|
||||
|
||||
func didConnect() {
|
||||
self._closed = false
|
||||
self._connected = true
|
||||
self._connecting = false
|
||||
self._reconnecting = false
|
||||
self.currentReconnectAttempt = 0
|
||||
self.reconnectTimer?.invalidate()
|
||||
self.reconnectTimer = nil
|
||||
self._sid = self.engine?.sid
|
||||
|
||||
// Don't handle as internal because something crazy could happen where
|
||||
// we disconnect before it's handled
|
||||
self.handleEvent("connect", data: nil, isInternalMessage: false)
|
||||
}
|
||||
|
||||
/// Server wants us to die
|
||||
func didForceClose(#message:String) {
|
||||
self._closed = true
|
||||
self._connected = false
|
||||
self.reconnects = false
|
||||
self._connecting = false
|
||||
self._reconnecting = false
|
||||
self.handleEvent("disconnect", data: message, isInternalMessage: true)
|
||||
}
|
||||
|
||||
/**
|
||||
Send a message to the server
|
||||
*/
|
||||
public func emit(event:String, _ args:AnyObject...) {
|
||||
if !self.connected {
|
||||
return
|
||||
}
|
||||
|
||||
dispatch_async(self.emitQueue) {[weak self] in
|
||||
self?._emit(event, args)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Same as emit, but meant for Objective-C
|
||||
*/
|
||||
public func emitObjc(event:String, withItems items:[AnyObject]) {
|
||||
self.emit(event, items)
|
||||
}
|
||||
|
||||
/**
|
||||
Sends a message to the server, requesting an ack. Use the onAck method of SocketAckHandler to add
|
||||
an ack.
|
||||
*/
|
||||
public func emitWithAck(event:String, _ args:AnyObject...) -> SocketAckHandler {
|
||||
if !self.connected {
|
||||
return SocketAckHandler(event: "fail", socket: self)
|
||||
}
|
||||
|
||||
self.currentAck++
|
||||
let ackHandler = SocketAckHandler(event: event,
|
||||
ackNum: self.currentAck, socket: self)
|
||||
self.ackHandlers.append(ackHandler)
|
||||
|
||||
dispatch_async(self.emitQueue) {[weak self, ack = self.currentAck] in
|
||||
self?._emit(event, args, ack: ack)
|
||||
return
|
||||
}
|
||||
|
||||
return ackHandler
|
||||
}
|
||||
|
||||
/**
|
||||
Same as emitWithAck, but for Objective-C
|
||||
*/
|
||||
public func emitWithAckObjc(event:String, withItems items:[AnyObject]) -> SocketAckHandler {
|
||||
return self.emitWithAck(event, items)
|
||||
}
|
||||
|
||||
private func _emit(event:String, _ args:[AnyObject], ack:Int? = nil) {
|
||||
var frame:SocketEvent
|
||||
var str:String
|
||||
|
||||
let (items, hasBinary, emitDatas) = SocketParser.parseEmitArgs(args)
|
||||
|
||||
if !self.connected {
|
||||
return
|
||||
}
|
||||
|
||||
if hasBinary {
|
||||
if ack == nil {
|
||||
str = SocketEvent.createMessageForEvent(event, withArgs: items,
|
||||
hasBinary: true, withDatas: emitDatas.count, toNamespace: self.nsp)
|
||||
} else {
|
||||
str = SocketEvent.createMessageForEvent(event, withArgs: items,
|
||||
hasBinary: true, withDatas: emitDatas.count, toNamespace: self.nsp, wantsAck: ack)
|
||||
}
|
||||
|
||||
self.engine?.send(str, datas: emitDatas)
|
||||
} else {
|
||||
if ack == nil {
|
||||
str = SocketEvent.createMessageForEvent(event, withArgs: items, hasBinary: false,
|
||||
withDatas: 0, toNamespace: self.nsp)
|
||||
} else {
|
||||
str = SocketEvent.createMessageForEvent(event, withArgs: items, hasBinary: false,
|
||||
withDatas: 0, toNamespace: self.nsp, wantsAck: ack)
|
||||
}
|
||||
|
||||
self.engine?.send(str)
|
||||
}
|
||||
}
|
||||
|
||||
// If the server wants to know that the client received data
|
||||
func emitAck(ack:Int, withData data:[AnyObject]?, withAckType ackType:Int) {
|
||||
dispatch_async(self.ackQueue) {[weak self] in
|
||||
if self == nil || !self!.connected || data == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// println("sending ack: \(ack) \(data)")
|
||||
let (items, hasBinary, emitDatas) = SocketParser.parseEmitArgs(data!)
|
||||
var str:String
|
||||
|
||||
if !hasBinary {
|
||||
if self?.nsp == nil {
|
||||
str = SocketEvent.createAck(ack, withArgs: items,
|
||||
withAckType: 3, withNsp: "/")
|
||||
} else {
|
||||
str = SocketEvent.createAck(ack, withArgs: items,
|
||||
withAckType: 3, withNsp: self!.nsp!)
|
||||
}
|
||||
|
||||
self?.engine?.send(str)
|
||||
} else {
|
||||
if self?.nsp == nil {
|
||||
str = SocketEvent.createAck(ack, withArgs: items,
|
||||
withAckType: 6, withNsp: "/", withBinary: emitDatas.count)
|
||||
} else {
|
||||
str = SocketEvent.createAck(ack, withArgs: items,
|
||||
withAckType: 6, withNsp: self!.nsp!, withBinary: emitDatas.count)
|
||||
}
|
||||
|
||||
self?.engine?.send(str, datas: emitDatas)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Called when the socket gets an ack for something it sent
|
||||
func handleAck(ack:Int, data:AnyObject?) {
|
||||
self.ackHandlers = self.ackHandlers.filter {handler in
|
||||
if handler.ackNum != ack {
|
||||
return true
|
||||
} else {
|
||||
if data is NSArray {
|
||||
handler.executeAck(data as? NSArray)
|
||||
} else if data != nil {
|
||||
handler.executeAck([data!])
|
||||
} else {
|
||||
handler.executeAck(nil)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Causes an event to be handled. Only use if you know what you're doing.
|
||||
*/
|
||||
public func handleEvent(event:String, data:AnyObject?, isInternalMessage:Bool = false,
|
||||
wantsAck ack:Int? = nil, withAckType ackType:Int = 3) {
|
||||
// println("Should do event: \(event) with data: \(data)")
|
||||
if !self.connected && !isInternalMessage {
|
||||
return
|
||||
}
|
||||
|
||||
if self.anyHandler != nil {
|
||||
dispatch_async(dispatch_get_main_queue()) {[weak self] in
|
||||
self?.anyHandler?((event, data))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for handler in self.handlers {
|
||||
if handler.event == event {
|
||||
if data is NSArray {
|
||||
if ack != nil {
|
||||
handler.executeCallback(data as? NSArray, withAck: ack!,
|
||||
withAckType: ackType, withSocket: self)
|
||||
} else {
|
||||
handler.executeCallback(data as? NSArray)
|
||||
}
|
||||
} else {
|
||||
|
||||
// Trying to do a ternary expression in the executeCallback method
|
||||
// seemed to crash Swift
|
||||
var dataArr:NSArray? = nil
|
||||
|
||||
if let data:AnyObject = data {
|
||||
dataArr = [data]
|
||||
}
|
||||
|
||||
if ack != nil {
|
||||
handler.executeCallback(dataArr, withAck: ack!,
|
||||
withAckType: ackType, withSocket: self)
|
||||
} else {
|
||||
handler.executeCallback(dataArr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Should be removed and moved to SocketEngine
|
||||
func joinNamespace() {
|
||||
if self.nsp != nil {
|
||||
self.engine?.send("0/\(self.nsp!)")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a handler for an event.
|
||||
*/
|
||||
public func on(name:String, callback:NormalCallback) {
|
||||
let handler = SocketEventHandler(event: name, callback: callback)
|
||||
self.handlers.append(handler)
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a handler that will be called on every event.
|
||||
*/
|
||||
public func onAny(handler:(AnyHandler) -> Void) {
|
||||
self.anyHandler = handler
|
||||
}
|
||||
|
||||
/**
|
||||
Same as connect
|
||||
*/
|
||||
public func open() {
|
||||
self.connect()
|
||||
}
|
||||
|
||||
public func parseSocketMessage(msg:String) {
|
||||
SocketParser.parseSocketMessage(msg, socket: self)
|
||||
}
|
||||
|
||||
public func parseBinaryData(data:NSData) {
|
||||
SocketParser.parseBinaryData(data, socket: self)
|
||||
}
|
||||
|
||||
// Something happened while polling
|
||||
public func pollingDidFail(err:NSError?) {
|
||||
if !self.reconnecting {
|
||||
self._connected = false
|
||||
self.handleEvent("reconnect", data: err?.localizedDescription, isInternalMessage: true)
|
||||
self.tryReconnect()
|
||||
}
|
||||
}
|
||||
|
||||
func removeAck(ack:SocketAckHandler) {
|
||||
self.ackHandlers = self.ackHandlers.filter {$0 === ack ? false : true}
|
||||
}
|
||||
|
||||
// We lost connection and should attempt to reestablish
|
||||
func tryReconnect() {
|
||||
if self.reconnectAttempts != -1 && self.currentReconnectAttempt + 1 > self.reconnectAttempts {
|
||||
self.didForceClose(message: "Reconnect Failed")
|
||||
return
|
||||
} else if self.connected {
|
||||
self._connecting = false
|
||||
self._reconnecting = false
|
||||
return
|
||||
}
|
||||
|
||||
if self.reconnectTimer == nil {
|
||||
self._reconnecting = true
|
||||
|
||||
dispatch_async(dispatch_get_main_queue()) {[weak self] in
|
||||
if self == nil {
|
||||
return
|
||||
}
|
||||
|
||||
self?.reconnectTimer = NSTimer.scheduledTimerWithTimeInterval(Double(self!.reconnectWait),
|
||||
target: self!, selector: "tryReconnect", userInfo: nil, repeats: true)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
self.handleEvent("reconnectAttempt", data: self.reconnectAttempts - self.currentReconnectAttempt,
|
||||
isInternalMessage: true)
|
||||
|
||||
self.currentReconnectAttempt++
|
||||
if self.paramConnect {
|
||||
self.connectWithParams(self.params)
|
||||
} else {
|
||||
self.connect()
|
||||
}
|
||||
}
|
||||
|
||||
// Called when the socket is closed
|
||||
public func webSocketDidCloseWithCode(code:Int, reason:String, wasClean:Bool) {
|
||||
self._connected = false
|
||||
self._connecting = false
|
||||
if self.closed || !self.reconnects {
|
||||
self.didForceClose(message: "WebSocket closed")
|
||||
} else {
|
||||
self.handleEvent("reconnect", data: reason, isInternalMessage: true)
|
||||
self.tryReconnect()
|
||||
}
|
||||
}
|
||||
|
||||
// Called when an error occurs.
|
||||
public func webSocketDidFailWithError(error:NSError) {
|
||||
self._connected = false
|
||||
self._connecting = false
|
||||
self.handleEvent("error", data: error.localizedDescription, isInternalMessage: true)
|
||||
if self.closed || !self.reconnects {
|
||||
self.didForceClose(message: "WebSocket closed with an error \(error)")
|
||||
} else if !self.reconnecting {
|
||||
self.handleEvent("reconnect", data: error.localizedDescription, isInternalMessage: true)
|
||||
self.tryReconnect()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,376 +0,0 @@
|
||||
//
|
||||
// SocketParser.swift
|
||||
// Socket.IO-Swift
|
||||
//
|
||||
// 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.
|
||||
|
||||
import Foundation
|
||||
|
||||
class SocketParser {
|
||||
// Parse an NSArray looking for binary data
|
||||
class func parseArray(arr:NSArray, var currentPlaceholder:Int) -> (NSArray, Bool, [NSData]) {
|
||||
var replacementArr = [AnyObject](count: arr.count, repeatedValue: 1)
|
||||
var hasBinary = false
|
||||
var arrayDatas = [NSData]()
|
||||
|
||||
for g in 0..<arr.count {
|
||||
if arr[g] is NSData {
|
||||
hasBinary = true
|
||||
currentPlaceholder++
|
||||
let sendData = arr[g] as NSData
|
||||
|
||||
arrayDatas.append(sendData)
|
||||
replacementArr[g] = ["_placeholder": true,
|
||||
"num": currentPlaceholder]
|
||||
} else if let dict = arr[g] as? NSDictionary {
|
||||
let (nestDict, hadBinary, dictArrs) = self.parseNSDictionary(dict,
|
||||
currentPlaceholder: currentPlaceholder)
|
||||
|
||||
if hadBinary {
|
||||
hasBinary = true
|
||||
currentPlaceholder += dictArrs.count
|
||||
replacementArr[g] = nestDict
|
||||
arrayDatas.extend(dictArrs)
|
||||
} else {
|
||||
replacementArr[g] = dict
|
||||
}
|
||||
} else if let nestArr = arr[g] as? NSArray {
|
||||
// Recursive
|
||||
let (nested, hadBinary, nestDatas) = self.parseArray(nestArr,
|
||||
currentPlaceholder: currentPlaceholder)
|
||||
|
||||
if hadBinary {
|
||||
hasBinary = true
|
||||
currentPlaceholder += nestDatas.count
|
||||
replacementArr[g] = nested
|
||||
arrayDatas.extend(nestDatas)
|
||||
} else {
|
||||
replacementArr[g] = arr[g]
|
||||
}
|
||||
} else {
|
||||
replacementArr[g] = arr[g]
|
||||
}
|
||||
}
|
||||
|
||||
return (replacementArr, hasBinary, arrayDatas)
|
||||
}
|
||||
|
||||
// Parses data for events
|
||||
class func parseData(data:String?) -> AnyObject? {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err:NSError?
|
||||
let stringData = data!.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
|
||||
let parsed:AnyObject? = NSJSONSerialization.JSONObjectWithData(stringData!,
|
||||
options: NSJSONReadingOptions.AllowFragments, error: &err)
|
||||
|
||||
if err != nil {
|
||||
// println(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
return parsed
|
||||
}
|
||||
|
||||
class func parseEmitArgs(args:[AnyObject]) -> ([AnyObject], Bool, [NSData]) {
|
||||
var items = [AnyObject](count: args.count, repeatedValue: 1)
|
||||
var currentPlaceholder = -1
|
||||
var hasBinary = false
|
||||
var emitDatas = [NSData]()
|
||||
|
||||
for i in 0..<args.count {
|
||||
if let dict = args[i] as? NSDictionary {
|
||||
// Check for binary data
|
||||
let (newDict, hadBinary, binaryDatas) = self.parseNSDictionary(dict,
|
||||
currentPlaceholder: currentPlaceholder)
|
||||
if hadBinary {
|
||||
currentPlaceholder += binaryDatas.count
|
||||
emitDatas.extend(binaryDatas)
|
||||
hasBinary = true
|
||||
items[i] = newDict
|
||||
} else {
|
||||
items[i] = dict
|
||||
}
|
||||
} else if let arr = args[i] as? NSArray {
|
||||
// arg is array, check for binary
|
||||
let (replace, hadData, newDatas) = self.parseArray(arr,
|
||||
currentPlaceholder: currentPlaceholder)
|
||||
|
||||
if hadData {
|
||||
hasBinary = true
|
||||
currentPlaceholder += newDatas.count
|
||||
|
||||
for data in newDatas {
|
||||
emitDatas.append(data)
|
||||
}
|
||||
|
||||
items[i] = replace
|
||||
} else {
|
||||
items[i] = arr
|
||||
}
|
||||
} else if let binaryData = args[i] as? NSData {
|
||||
// args is just binary
|
||||
hasBinary = true
|
||||
|
||||
currentPlaceholder++
|
||||
items[i] = ["_placeholder": true, "num": currentPlaceholder]
|
||||
emitDatas.append(binaryData)
|
||||
} else {
|
||||
items[i] = args[i]
|
||||
}
|
||||
}
|
||||
|
||||
return (items, hasBinary, emitDatas)
|
||||
}
|
||||
|
||||
// Parses a NSDictionary, looking for NSData objects
|
||||
class func parseNSDictionary(dict:NSDictionary, var currentPlaceholder:Int) -> (NSDictionary, Bool, [NSData]) {
|
||||
var returnDict = NSMutableDictionary()
|
||||
var hasBinary = false
|
||||
var returnDatas = [NSData]()
|
||||
|
||||
for (key, value) in dict {
|
||||
if let binaryData = value as? NSData {
|
||||
currentPlaceholder++
|
||||
hasBinary = true
|
||||
returnDatas.append(binaryData)
|
||||
returnDict[key as String] = ["_placeholder": true, "num": currentPlaceholder]
|
||||
} else if let arr = value as? NSArray {
|
||||
let (replace, hadBinary, arrDatas) = self.parseArray(arr, currentPlaceholder: currentPlaceholder)
|
||||
|
||||
if hadBinary {
|
||||
hasBinary = true
|
||||
returnDict[key as String] = replace
|
||||
currentPlaceholder += arrDatas.count
|
||||
returnDatas.extend(arrDatas)
|
||||
} else {
|
||||
returnDict[key as String] = arr
|
||||
}
|
||||
} else if let dict = value as? NSDictionary {
|
||||
// Recursive
|
||||
let (nestDict, hadBinary, nestDatas) = self.parseNSDictionary(dict, currentPlaceholder: currentPlaceholder)
|
||||
|
||||
if hadBinary {
|
||||
hasBinary = true
|
||||
returnDict[key as String] = nestDict
|
||||
currentPlaceholder += nestDatas.count
|
||||
returnDatas.extend(nestDatas)
|
||||
} else {
|
||||
returnDict[key as String] = dict
|
||||
}
|
||||
} else {
|
||||
returnDict[key as String] = value
|
||||
}
|
||||
}
|
||||
|
||||
return (returnDict, hasBinary, returnDatas)
|
||||
}
|
||||
|
||||
// Parses messages recieved
|
||||
class func parseSocketMessage(var stringMessage:String, socket:SocketIOClient) {
|
||||
if stringMessage == "" {
|
||||
return
|
||||
}
|
||||
|
||||
// NSLog(stringMessage)
|
||||
|
||||
// Check for successful namepsace connect
|
||||
if socket.nsp != nil {
|
||||
if stringMessage == "0/\(socket.nsp!)" {
|
||||
socket.didConnect()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if stringMessage == "0" {
|
||||
if socket.nsp != nil {
|
||||
// Join namespace
|
||||
socket.joinNamespace()
|
||||
return
|
||||
} else {
|
||||
socket.didConnect()
|
||||
return
|
||||
}
|
||||
} else if stringMessage == "1" {
|
||||
socket.didForceClose(message: "Got disconnect")
|
||||
return
|
||||
}
|
||||
|
||||
if stringMessage.hasPrefix("5") || stringMessage.hasPrefix("6") {
|
||||
// Check for message with binary placeholders
|
||||
self.parseBinaryMessage(stringMessage, socket: socket)
|
||||
return
|
||||
}
|
||||
|
||||
let type = stringMessage.removeAtIndex(stringMessage.startIndex)
|
||||
|
||||
if type == "2" {
|
||||
if let groups = stringMessage["(\\/(\\w*))?,?(\\d*)?\\[\"(.*?)\",?(.*?)?\\]$",
|
||||
NSRegularExpressionOptions.DotMatchesLineSeparators].groups() {
|
||||
let namespace = groups[2]
|
||||
let ackNum = groups[3]
|
||||
let event = groups[4]
|
||||
let data = "[\(groups[5])]"
|
||||
|
||||
if namespace == "" && socket.nsp != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if let parsed:AnyObject = self.parseData(data) {
|
||||
if ackNum == "" {
|
||||
socket.handleEvent(event, data: parsed)
|
||||
} else {
|
||||
socket.currentAck = ackNum.toInt()!
|
||||
socket.handleEvent(event, data: parsed, isInternalMessage: false,
|
||||
wantsAck: ackNum.toInt(), withAckType: 3)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if type == "3" {
|
||||
if let ackGroup = stringMessage["(\\/(\\w*))?,?(\\d*)?\\[(.*?)?\\]$",
|
||||
NSRegularExpressionOptions.DotMatchesLineSeparators].groups() {
|
||||
let nsp = ackGroup[2]
|
||||
let ackNum = ackGroup[3]
|
||||
let ackData:AnyObject? = self.parseData("[\(ackGroup[4])]")
|
||||
|
||||
if nsp == "" && socket.nsp != nil {
|
||||
return
|
||||
}
|
||||
|
||||
socket.handleAck(ackNum.toInt()!, data: ackData)
|
||||
}
|
||||
} else {
|
||||
NSLog("Error in parsing message: %s", stringMessage)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Handles binary data
|
||||
class func parseBinaryData(data:NSData, socket:SocketIOClient) {
|
||||
// NSLog(data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.allZeros))
|
||||
|
||||
if socket.waitingData.count == 0 {
|
||||
NSLog("Got data when not remaking packet")
|
||||
return
|
||||
}
|
||||
|
||||
let shouldExecute = socket.waitingData[0].addData(data)
|
||||
|
||||
if shouldExecute {
|
||||
let socketEvent = socket.waitingData.removeAtIndex(0)
|
||||
var event = socketEvent.event
|
||||
var parsedArgs:AnyObject? = self.parseData(socketEvent.args as? String)
|
||||
|
||||
if let args:AnyObject = parsedArgs {
|
||||
let filledInArgs:AnyObject = socketEvent.fillInPlaceholders(args)
|
||||
|
||||
if socketEvent.justAck! {
|
||||
// Should handle ack
|
||||
socket.handleAck(socketEvent.ack!, data: filledInArgs)
|
||||
return
|
||||
}
|
||||
|
||||
// Should do event
|
||||
if socketEvent.ack != nil {
|
||||
socket.handleEvent(event, data: filledInArgs, isInternalMessage: false,
|
||||
wantsAck: socketEvent.ack!, withAckType: 6)
|
||||
} else {
|
||||
socket.handleEvent(event, data: filledInArgs)
|
||||
}
|
||||
} else {
|
||||
let filledInArgs:AnyObject = socketEvent.fillInPlaceholders()
|
||||
|
||||
// Should handle ack
|
||||
if socketEvent.justAck! {
|
||||
socket.handleAck(socketEvent.ack!, data: filledInArgs)
|
||||
return
|
||||
}
|
||||
|
||||
// Should handle ack
|
||||
if socketEvent.ack != nil {
|
||||
socket.handleEvent(event, data: filledInArgs, isInternalMessage: false,
|
||||
wantsAck: socketEvent.ack!, withAckType: 6)
|
||||
} else {
|
||||
socket.handleEvent(event, data: filledInArgs)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tries to parse a message that contains binary
|
||||
class func parseBinaryMessage(var message:String, socket:SocketIOClient) {
|
||||
// NSLog(message)
|
||||
|
||||
let type = message.removeAtIndex(message.startIndex)
|
||||
|
||||
if type == "5" {
|
||||
if let groups = message["^(\\d*)-(\\/(\\w*))?,?(\\d*)?\\[\"(.*?)\",?(.*)?\\]$",
|
||||
NSRegularExpressionOptions.DotMatchesLineSeparators].groups() {
|
||||
let numberOfPlaceholders = groups[1]
|
||||
let namespace = groups[3]
|
||||
let ackNum = groups[4]
|
||||
let event = groups[5]
|
||||
let mutMessageObject = groups[6]
|
||||
|
||||
if namespace == "" && socket.nsp != nil {
|
||||
return
|
||||
}
|
||||
|
||||
let placeholdersRemoved = mutMessageObject["(\\{\"_placeholder\":true,\"num\":(\\d*)\\})"]
|
||||
~= "\"~~$2\""
|
||||
|
||||
var mes:SocketEvent
|
||||
if ackNum == "" {
|
||||
mes = SocketEvent(event: event, args: placeholdersRemoved,
|
||||
placeholders: numberOfPlaceholders.toInt()!)
|
||||
} else {
|
||||
socket.currentAck = ackNum.toInt()!
|
||||
mes = SocketEvent(event: event, args: placeholdersRemoved,
|
||||
placeholders: numberOfPlaceholders.toInt()!, ackNum: ackNum.toInt())
|
||||
}
|
||||
|
||||
socket.waitingData.append(mes)
|
||||
}
|
||||
} else if type == "6" {
|
||||
if let groups = message["^(\\d*)-(\\/(\\w*))?,?(\\d*)?\\[(.*?)?\\]$",
|
||||
NSRegularExpressionOptions.DotMatchesLineSeparators].groups() {
|
||||
let numberOfPlaceholders = groups[1]
|
||||
let namespace = groups[3]
|
||||
let ackNum = groups[4]
|
||||
let mutMessageObject = groups[5]
|
||||
|
||||
if namespace == "" && socket.nsp != nil {
|
||||
return
|
||||
}
|
||||
let placeholdersRemoved = mutMessageObject["(\\{\"_placeholder\":true,\"num\":(\\d*)\\})"]
|
||||
~= "\"~~$2\""
|
||||
|
||||
let event = SocketEvent(event: "", args: placeholdersRemoved,
|
||||
placeholders: numberOfPlaceholders.toInt()!, ackNum: ackNum.toInt(), justAck: true)
|
||||
|
||||
socket.waitingData.append(event)
|
||||
}
|
||||
} else {
|
||||
NSLog("Error in parsing binary message: %s", message)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user