Skip to content

Commit 46b63b5

Browse files
committed
Merge branch 'development'
* development: (24 commits) Add enum for client events. Resolves #675 Add client event for status changes. Closes #668 Remove from manager can be discarded Use xctool Go back to straight xcodebuild Try and fix travis Disable logging in tests, use xctool again Implement #672 Document SocketIOClientSwift Document SocketAnyEvent Move operators inside type Document ack types Fix #667 Make no ack an enum case remove refactor build Open client Make client single queued Make engine single queued add ignore for appcode Fix #657 Parsable doesn't have to be a client ...
2 parents 34d1e2f + 158bdfb commit 46b63b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+18249
-445
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ DerivedData
4646
*.xcuserstate
4747

4848
Socket.IO-Test-Server/node_modules/*
49+
50+
.idea/
51+
docs/docsets/
52+
docs/undocumented.json

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ branches:
99
before_install:
1010
- brew update
1111
- brew outdated xctool || brew upgrade xctool
12-
# script: xctool -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build test -parallelize
13-
script: xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build test
12+
script:
13+
- xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build-for-testing -quiet
14+
- xctool -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac run-tests --parallelize
15+
#script: xcodebuild -project Socket.IO-Client-Swift.xcodeproj -scheme SocketIO-Mac build test

README.md

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SocketIO
99

1010
let socket = SocketIOClient(socketURL: URL(string: "http://localhost:8080")!, config: [.log(true), .forcePolling(true)])
1111

12-
socket.on("connect") {data, ack in
12+
socket.on(clientEvent: .connect) {data, ack in
1313
print("socket connected")
1414
}
1515

@@ -70,13 +70,11 @@ If you need Swift 1.2 use v2.4.5 (Pre-Swift 2 support is no longer maintained)
7070
7171
If you need Swift 1.1 use v1.5.2. (Pre-Swift 1.2 support is no longer maintained)
7272
73-
Manually (iOS 7+)
74-
-----------------
73+
### Manually (iOS 7+)
7574
1. Copy the Source folder into your Xcode project. (Make sure you add the files to your target(s))
7675
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.
7776
78-
Swift Package Manager
79-
---------------------
77+
### Swift Package Manager
8078
Add the project as a dependency to your Package.swift:
8179
```swift
8280
import PackageDescription
@@ -91,17 +89,15 @@ let package = Package(
9189

9290
Then import `import SocketIO`.
9391

94-
Carthage
95-
-----------------
92+
### Carthage
9693
Add this line to your `Cartfile`:
9794
```
9895
github "socketio/socket.io-client-swift" ~> 8.3.3 # Or latest version
9996
```
10097

10198
Run `carthage update --platform ios,macosx`.
10299

103-
CocoaPods 1.0.0 or later
104-
------------------
100+
### CocoaPods 1.0.0 or later
105101
Create `Podfile` and add `pod 'Socket.IO-Client-Swift'`:
106102

107103
```ruby
@@ -131,8 +127,7 @@ Objective-C:
131127
@import SocketIO;
132128
```
133129

134-
CocoaSeeds
135-
-----------------
130+
### CocoaSeeds
136131

137132
Add this line to your `Seedfile`:
138133

@@ -150,8 +145,7 @@ Constructors
150145

151146
`convenience init(socketURL: NSURL, options: NSDictionary?)` - Same as above, but meant for Objective-C. See Options on how convert between SocketIOClientOptions and dictionary keys.
152147

153-
Options
154-
-------
148+
### Options
155149
All options are a case of SocketIOClientOption. To get the Objective-C Option, convert the name to lowerCamelCase.
156150

157151
```swift
@@ -176,8 +170,7 @@ case security(SSLSecurity) // Allows you to set which certs are valid. Useful fo
176170
case selfSigned(Bool) // Sets WebSocket.selfSignedSSL. Use this if you're using self-signed certs.
177171
case voipEnabled(Bool) // Only use this option if you're using the client with VoIP services. Changes the way the WebSocket is created. Default is false
178172
```
179-
Methods
180-
-------
173+
### Methods
181174
1. `on(_ event: String, callback: NormalCallback) -> NSUUID` - 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. Returns a unique id for the handler.
182175
2. `once(_ event: String, callback: NormalCallback) -> NSUUID` - Adds a handler that will only be executed once. Returns a unique id for the handler.
183176
3. `onAny(callback:((event: String, items: AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event.
@@ -195,8 +188,7 @@ Methods
195188
15. `off(id id: NSUUID)` - Removes the event that corresponds to id.
196189
16. `removeAllHandlers()` - Removes all handlers.
197190

198-
Client Events
199-
------
191+
### Client Events
200192
1. `connect` - Emitted when on a successful connection.
201193
2. `disconnect` - Emitted when the connection is closed.
202194
3. `error` - Emitted on an error.

SocketIO-MacTests/SocketAckManagerTest.swift

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,43 @@
99
import XCTest
1010
@testable import SocketIO
1111

12-
class SocketAckManagerTest: XCTestCase {
12+
class SocketAckManagerTest : XCTestCase {
1313
var ackManager = SocketAckManager()
1414

1515
func testAddAcks() {
16-
let callbackExpection = self.expectation(description: "callbackExpection")
16+
let callbackExpection = expectation(description: "callbackExpection")
1717
let itemsArray = ["Hi", "ho"]
18+
1819
func callback(_ items: [Any]) {
1920
callbackExpection.fulfill()
2021
}
22+
2123
ackManager.addAck(1, callback: callback)
2224
ackManager.executeAck(1, with: itemsArray, onQueue: DispatchQueue.main)
23-
25+
2426
waitForExpectations(timeout: 3.0, handler: nil)
2527
}
28+
29+
func testManagerTimeoutAck() {
30+
let callbackExpection = expectation(description: "Manager should timeout ack with noAck status")
31+
let itemsArray = ["Hi", "ho"]
32+
33+
func callback(_ items: [Any]) {
34+
XCTAssertEqual(items.count, 1, "Timed out ack should have one value")
35+
guard let timeoutReason = items[0] as? String else {
36+
XCTFail("Timeout reason should be a string")
37+
38+
return
39+
}
40+
41+
XCTAssertEqual(timeoutReason, SocketAckStatus.noAck.rawValue)
42+
43+
callbackExpection.fulfill()
44+
}
45+
46+
ackManager.addAck(1, callback: callback)
47+
ackManager.timeoutAck(1, onQueue: DispatchQueue.main)
48+
49+
waitForExpectations(timeout: 0.2, handler: nil)
50+
}
2651
}

SocketIO-MacTests/SocketObjectiveCTest.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ @implementation SocketObjectiveCTest
2121
- (void)setUp {
2222
[super setUp];
2323
NSURL* url = [[NSURL alloc] initWithString:@"http://localhost"];
24-
self.socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{@"log": @YES, @"forcePolling": @YES}];
24+
self.socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{@"log": @NO, @"forcePolling": @YES}];
2525
}
2626

2727
- (void)testOnSyntax {
@@ -36,7 +36,7 @@ - (void)testEmitSyntax {
3636

3737
- (void)testEmitWithAckSyntax {
3838
[[self.socket emitWithAck:@"testAckEmit" with:@[@YES]] timingOutAfter:0 callback:^(NSArray* data) {
39-
39+
4040
}];
4141
}
4242

0 commit comments

Comments
 (0)