Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b9becebae | ||
|
|
ffbe1e4ec4 | ||
|
|
e792006245 | ||
|
|
67f57daaab | ||
|
|
11730b5fcd | ||
|
|
47a839b934 |
No files matched your search
@@ -11,7 +11,7 @@ socket.on("connect") {data, ack in
|
||||
|
||||
socket.on("currentAmount") {data, ack in
|
||||
if let cur = data?[0] as? Double {
|
||||
socket.emitWithAck("canUpdate", cur)(timeout: 0) {data in
|
||||
socket.emitWithAck("canUpdate", cur)(timeoutAfter: 0) {data in
|
||||
socket.emit("update", ["amount": cur + 2.50])
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ Carthage
|
||||
-----------------
|
||||
Add this line to your `Cartfile`:
|
||||
```
|
||||
github "socketio/socket.io-client-swift" ~> 2.3.10 # Or latest version
|
||||
github "socketio/socket.io-client-swift" ~> 2.4.1 # Or latest version
|
||||
```
|
||||
|
||||
Run `carthage update`.
|
||||
@@ -79,7 +79,7 @@ source 'https://github.com/CocoaPods/Specs.git'
|
||||
platform :ios, '8.0'
|
||||
use_frameworks!
|
||||
|
||||
pod 'Socket.IO-Client-Swift', '~> 2.3.10' # Or latest version
|
||||
pod 'Socket.IO-Client-Swift', '~> 2.4.1' # Or latest version
|
||||
```
|
||||
|
||||
Install pods:
|
||||
@@ -121,6 +121,7 @@ Options
|
||||
- `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.
|
||||
- `handleQueue: dispatch_queue_t` - The dispatch queue that handlers are run on. Default is the main queue.
|
||||
|
||||
Methods
|
||||
-------
|
||||
@@ -128,7 +129,7 @@ Methods
|
||||
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.
|
||||
5. `emitWithAck(event:String, _ items:AnyObject...) -> (timeoutAfter:UInt64, callback:(NSArray?) -> Void) -> Void` - Sends a message that requests an acknowledgement from the server. Returns a function which you can use to add a handler. See example. Note: The message is not sent until you call the returned function.
|
||||
6. `emitWithAck(event:String, 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.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "Socket.IO-Client-Swift"
|
||||
s.version = "2.3.10"
|
||||
s.version = "2.4.1"
|
||||
s.summary = "Socket.IO-client for iOS and OS X"
|
||||
s.description = <<-DESC
|
||||
Socket.IO-client for iOS and OS X.
|
||||
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
|
||||
s.author = { "Erik" => "nuclear.ace@gmail.com" }
|
||||
s.ios.deployment_target = '8.0'
|
||||
s.osx.deployment_target = '10.10'
|
||||
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v2.3.10' }
|
||||
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v2.4.1' }
|
||||
s.source_files = "SocketIOClientSwift/**/*.swift"
|
||||
s.requires_arc = true
|
||||
# s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files
|
||||
|
||||
@@ -99,7 +99,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
|
||||
|
||||
public init(client:SocketEngineClient, sessionDelegate:NSURLSessionDelegate?) {
|
||||
self.client = client
|
||||
self.session = NSURLSession(configuration: NSURLSessionConfiguration.ephemeralSessionConfiguration(),
|
||||
self.session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration(),
|
||||
delegate: sessionDelegate, delegateQueue: workQueue)
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,6 @@ final 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!) : nil)
|
||||
}
|
||||
self.callback?(items, ack != nil ? emitAckCallback(socket!, ack!) : nil)
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
|
||||
|
||||
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 handleQueue: dispatch_queue_t!
|
||||
public let emitQueue = dispatch_queue_create("emitQueue", DISPATCH_QUEUE_SERIAL)
|
||||
public var closed:Bool {
|
||||
return _closed
|
||||
@@ -121,6 +121,12 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
|
||||
self.reconnectWait = abs(reconnectWait)
|
||||
}
|
||||
|
||||
if let handleQueue = opts?["handleQueue"] as? dispatch_queue_t {
|
||||
self.handleQueue = handleQueue
|
||||
} else {
|
||||
self.handleQueue = dispatch_get_main_queue()
|
||||
}
|
||||
|
||||
super.init()
|
||||
}
|
||||
|
||||
@@ -393,7 +399,7 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
|
||||
args: event, data ?? "")
|
||||
|
||||
if anyHandler != nil {
|
||||
dispatch_async(dispatch_get_main_queue()) {[weak self] in
|
||||
dispatch_async(handleQueue) {[weak self] in
|
||||
self?.anyHandler?(SocketAnyEvent(event: event, items: data))
|
||||
}
|
||||
}
|
||||
@@ -401,9 +407,13 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
|
||||
for handler in handlers {
|
||||
if handler.event == event {
|
||||
if ack != nil {
|
||||
handler.executeCallback(data, withAck: ack!, withSocket: self)
|
||||
dispatch_async(handleQueue) {[weak self] in
|
||||
handler.executeCallback(data, withAck: ack!, withSocket: self)
|
||||
}
|
||||
} else {
|
||||
handler.executeCallback(data)
|
||||
dispatch_async(handleQueue) {[weak self] in
|
||||
handler.executeCallback(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -448,14 +458,14 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
|
||||
let handler = SocketEventHandler(event: event, callback: callback)
|
||||
handlers.append(handler)
|
||||
}
|
||||
|
||||
/**
|
||||
Removes all handlers.
|
||||
Can be used after disconnecting to break any potential remaining retain cycles.
|
||||
*/
|
||||
public func removeAllHandlers() {
|
||||
handlers.removeAll(keepCapacity: false)
|
||||
}
|
||||
|
||||
/**
|
||||
Removes all handlers.
|
||||
Can be used after disconnecting to break any potential remaining retain cycles.
|
||||
*/
|
||||
public func removeAllHandlers() {
|
||||
handlers.removeAll(keepCapacity: false)
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a handler that will be called on every event.
|
||||
|
||||
@@ -31,4 +31,4 @@ import Foundation
|
||||
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
|
||||
public typealias OnAckCallback = (timeoutAfter:UInt64, callback:AckCallback) -> Void
|
||||
Reference in new issue
Block a user