Compare commits

...
6 Commits
Author SHA1 Message Date
Erik 9ec521a6de bump version. Changes to connect 2015-05-11 12:40:05 -04:00
Erik 69c67a2b81 Merge branch 'master' into redoconnects 2015-05-11 09:21:03 -04:00
Erik dd068cb480 clarify what nsp does 2015-05-11 09:20:47 -04:00
Erik 3abb26565b tweak closing engine 2015-05-11 09:19:46 -04:00
Erik d7d1da704f document connect method 2015-05-09 15:30:39 -04:00
Erik 5a5dc70203 fix nuclearace/Socket.IO-Client-Swift#46 2015-05-09 15:20:03 -04:00
4 changed files with 37 additions and 34 deletions

No files matched your search

+3 -2
View File
@@ -88,12 +88,13 @@ Constructors
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 `"/"`
- `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.
@@ -108,7 +109,7 @@ Methods
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. `connectWithParams(params:[String: AnyObject])` - Establishes a connection to the server passing the specified params. 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.
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Socket.IO-Client-Swift"
s.version = "2.2.3"
s.version = "2.3.0"
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.2.3' }
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v2.3.0' }
s.source_files = "SocketIOClientSwift/**/*.swift"
s.requires_arc = true
# s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files
+3 -2
View File
@@ -119,13 +119,14 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
self.pingTimer?.invalidate()
self.closed = true
self.write("", withType: PacketType.CLOSE, withData: nil)
self.ws?.disconnect()
self.stopPolling()
if fast || self.polling {
self.write("", withType: PacketType.CLOSE, withData: nil)
self.client?.engineDidClose("Disconnect")
}
self.stopPolling()
}
private func createBinaryDataForSend(data:NSData) -> (NSData?, String?) {
+29 -28
View File
@@ -25,14 +25,13 @@
import Foundation
public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient {
private lazy var params = [String: AnyObject]()
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 paramConnect = false
private var params:[String: AnyObject]?
private var _secure = false
private var _sid:String?
private var _reconnecting = false
@@ -88,11 +87,16 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
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.params = connectParams
}
if let log = opts?["log"] as? Bool {
self.log = log
}
@@ -156,37 +160,38 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
Connect to the server.
*/
public func connect() {
if self.closed {
println("Warning! This socket was previously closed. This might be dangerous!")
self._closed = false
}
if self.connected {
return
}
self.addEngine()
self.engine?.open()
self.connect(timeoutAfter: 0, withTimeoutHandler: nil)
}
/**
Connect to the server with params that will be passed on connection.
Connect to the server. If we aren't connected after timeoutAfter, call handler
*/
public func connectWithParams(params:[String: AnyObject]) {
public func connect(#timeoutAfter:Int, withTimeoutHandler handler:(() -> Void)?) {
if self.closed {
println("Warning! This socket was previously closed. This might be dangerous!")
SocketLogger.log("Warning! This socket was previously closed. This might be dangerous!", client: self)
self._closed = false
}
if self.connected {
} else if self.connected {
return
}
self.params = params
self.paramConnect = true
self.addEngine()
self.engine?.open(opts: params)
self.engine?.open(opts: self.params)
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 {
@@ -489,10 +494,6 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
isInternalMessage: true)
self.currentReconnectAttempt++
if self.paramConnect {
self.connectWithParams(self.params)
} else {
self.connect()
}
self.connect()
}
}