diff --git a/README.md b/README.md index 8a5111a..7dbcef2 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ Options - `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 `""` Methods ------- diff --git a/SocketIOClientSwift/SocketEngine.swift b/SocketIOClientSwift/SocketEngine.swift index e55a5c3..0e05b90 100644 --- a/SocketIOClientSwift/SocketEngine.swift +++ b/SocketIOClientSwift/SocketEngine.swift @@ -68,6 +68,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient { return self._polling } var sid = "" + var socketPath = "" var urlPolling:String? var urlWebSocket:String? var websocket:Bool { @@ -94,13 +95,14 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient { } public init(client:SocketEngineClient, forcePolling:Bool, - forceWebsockets:Bool, withCookies cookies:[NSHTTPCookie]?, logging:Bool, - withSessionDelegate sessionDelegate:NSURLSessionDelegate?) { + forceWebsockets:Bool, cookies:[NSHTTPCookie]?, logging:Bool, + sessionDelegate:NSURLSessionDelegate?, path:String) { self.client = client self.forcePolling = forcePolling self.forceWebsockets = forceWebsockets self.cookies = cookies self.log = logging + self.socketPath = path self.session = NSURLSession(configuration: NSURLSessionConfiguration.ephemeralSessionConfiguration(), delegate: sessionDelegate, delegateQueue: self.workQueue) } @@ -146,7 +148,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient { return ("", "") } - var url = "\(self.client!.socketURL)/socket.io/?transport=" + var url = "\(self.client!.socketURL)\(self.socketPath)/socket.io/?transport=" var urlPolling:String var urlWebSocket:String diff --git a/SocketIOClientSwift/SocketIOClient.swift b/SocketIOClientSwift/SocketIOClient.swift index 733dbcf..b5c3fea 100644 --- a/SocketIOClientSwift/SocketIOClient.swift +++ b/SocketIOClientSwift/SocketIOClient.swift @@ -75,6 +75,8 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient public var sid:String? { return self._sid } + public var socketPath = "" + /** Create a new SocketIOClient. opts can be omitted @@ -103,6 +105,10 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient self.log = log } + if let path = opts!["path"] as? String { + self.socketPath = path + } + if let polling = opts!["forcePolling"] as? Bool { self.forcePolling = polling } @@ -153,9 +159,11 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient self.engine = SocketEngine(client: self, forcePolling: self.forcePolling, forceWebsockets: self.forceWebsockets, - withCookies: self.cookies, + cookies: self.cookies, logging: self.log, - withSessionDelegate: self.sessionDelegate) + sessionDelegate: self.sessionDelegate, + path: self.socketPath + ) } /**