Merge branch 'master' into 1.2
This commit is contained in:
commit
f669267f51
@ -47,9 +47,9 @@ 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.
|
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.
|
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.
|
3. `socket.emit(event:String, _ items:AnyObject...)` - Sends a message. Can send multiple items.
|
||||||
4. `socket.emitObjc(event:String, withItems items:[AnyObject])` - `emit` for Objective-C
|
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.
|
5. `socket.emitWithAck(event:String, _ items: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.
|
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.
|
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.
|
8. `socket.connectWithParams(params:[String: AnyObject])` - Establishes a connection to the server passing the specified params. A "connect" event is fired upon successful connection.
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = "Socket.IO-Client-Swift"
|
s.name = "Socket.IO-Client-Swift"
|
||||||
s.version = "1.4.0"
|
s.version = "1.4.2"
|
||||||
s.summary = "Socket.IO-client for Swift"
|
s.summary = "Socket.IO-client for Swift"
|
||||||
s.description = <<-DESC
|
s.description = <<-DESC
|
||||||
Socket.IO-client for Swift.
|
Socket.IO-client for Swift.
|
||||||
@ -12,7 +12,7 @@ Pod::Spec.new do |s|
|
|||||||
s.author = { "Erik" => "nuclear.ace@gmail.com" }
|
s.author = { "Erik" => "nuclear.ace@gmail.com" }
|
||||||
s.ios.deployment_target = '8.0'
|
s.ios.deployment_target = '8.0'
|
||||||
s.osx.deployment_target = '10.10'
|
s.osx.deployment_target = '10.10'
|
||||||
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v1.4.0' }
|
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v1.4.2' }
|
||||||
s.source_files = "SwiftIO/**/*.swift"
|
s.source_files = "SwiftIO/**/*.swift"
|
||||||
s.requires_arc = true
|
s.requires_arc = true
|
||||||
# s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files
|
# s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files
|
||||||
|
|||||||
@ -118,16 +118,18 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
self.engine = SocketEngine(client: self,
|
|
||||||
forcePolling: self.forcePolling,
|
|
||||||
withCookies: self.cookies)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public convenience init(socketURL:String, options:NSDictionary?) {
|
public convenience init(socketURL:String, options:NSDictionary?) {
|
||||||
self.init(socketURL: socketURL, opts: options)
|
self.init(socketURL: socketURL, opts: options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func addEngine() {
|
||||||
|
self.engine = SocketEngine(client: self,
|
||||||
|
forcePolling: self.forcePolling,
|
||||||
|
withCookies: self.cookies)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Closes the socket. Only reopen the same socket if you know what you're doing.
|
Closes the socket. Only reopen the same socket if you know what you're doing.
|
||||||
Will turn off automatic reconnects.
|
Will turn off automatic reconnects.
|
||||||
@ -150,6 +152,7 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
self._closed = false
|
self._closed = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.addEngine()
|
||||||
self.engine?.open()
|
self.engine?.open()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,6 +168,7 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
self.params = params
|
self.params = params
|
||||||
self.paramConnect = true
|
self.paramConnect = true
|
||||||
|
|
||||||
|
self.addEngine()
|
||||||
self.engine?.open(opts: params)
|
self.engine?.open(opts: params)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,13 +204,13 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
/**
|
/**
|
||||||
Send a message to the server
|
Send a message to the server
|
||||||
*/
|
*/
|
||||||
public func emit(event:String, _ args:AnyObject...) {
|
public func emit(event:String, _ items:AnyObject...) {
|
||||||
if !self.connected {
|
if !self.connected {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_async(self.emitQueue) {[weak self] in
|
dispatch_async(self.emitQueue) {[weak self] in
|
||||||
self?._emit(event, args)
|
self?._emit(event, items)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,14 +219,21 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
Same as emit, but meant for Objective-C
|
Same as emit, but meant for Objective-C
|
||||||
*/
|
*/
|
||||||
public func emitObjc(event:String, withItems items:[AnyObject]) {
|
public func emitObjc(event:String, withItems items:[AnyObject]) {
|
||||||
self.emit(event, items)
|
if !self.connected {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch_async(self.emitQueue) {[weak self] in
|
||||||
|
self?._emit(event, items)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Sends a message to the server, requesting an ack. Use the onAck method of SocketAckHandler to add
|
Sends a message to the server, requesting an ack. Use the onAck method of SocketAckHandler to add
|
||||||
an ack.
|
an ack.
|
||||||
*/
|
*/
|
||||||
public func emitWithAck(event:String, _ args:AnyObject...) -> SocketAckHandler {
|
public func emitWithAck(event:String, _ items:AnyObject...) -> SocketAckHandler {
|
||||||
if !self.connected {
|
if !self.connected {
|
||||||
return SocketAckHandler(event: "fail", socket: self)
|
return SocketAckHandler(event: "fail", socket: self)
|
||||||
}
|
}
|
||||||
@ -233,7 +244,7 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
self.ackHandlers.append(ackHandler)
|
self.ackHandlers.append(ackHandler)
|
||||||
|
|
||||||
dispatch_async(self.emitQueue) {[weak self, ack = self.currentAck] in
|
dispatch_async(self.emitQueue) {[weak self, ack = self.currentAck] in
|
||||||
self?._emit(event, args, ack: ack)
|
self?._emit(event, items, ack: ack)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +255,21 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
|||||||
Same as emitWithAck, but for Objective-C
|
Same as emitWithAck, but for Objective-C
|
||||||
*/
|
*/
|
||||||
public func emitWithAckObjc(event:String, withItems items:[AnyObject]) -> SocketAckHandler {
|
public func emitWithAckObjc(event:String, withItems items:[AnyObject]) -> SocketAckHandler {
|
||||||
return self.emitWithAck(event, items)
|
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, items, ack: ack)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return ackHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
private func _emit(event:String, _ args:[AnyObject], ack:Int? = nil) {
|
private func _emit(event:String, _ args:[AnyObject], ack:Int? = nil) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user