Skip to content

Commit 918f176

Browse files
committed
fix #65
1 parent ef39651 commit 918f176

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Options
9797
- `cookies: [NSHTTPCookie]?` An array of NSHTTPCookies. Passed during the handshake. Default is nil.
9898
- `log: Bool` If `true` socket will log debug messages. Default is false.
9999
- `sessionDelegate: NSURLSessionDelegate` Sets an NSURLSessionDelegate for the underlying engine. Useful if you need to handle self-signed certs. Default is nil.
100+
- `path: String` - If the server uses a custom path. ex: `"/swift"`. Default is `""`
100101

101102
Methods
102103
-------

SocketIOClientSwift/SocketEngine.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
6868
return self._polling
6969
}
7070
var sid = ""
71+
var socketPath = ""
7172
var urlPolling:String?
7273
var urlWebSocket:String?
7374
var websocket:Bool {
@@ -94,13 +95,14 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
9495
}
9596

9697
public init(client:SocketEngineClient, forcePolling:Bool,
97-
forceWebsockets:Bool, withCookies cookies:[NSHTTPCookie]?, logging:Bool,
98-
withSessionDelegate sessionDelegate:NSURLSessionDelegate?) {
98+
forceWebsockets:Bool, cookies:[NSHTTPCookie]?, logging:Bool,
99+
sessionDelegate:NSURLSessionDelegate?, path:String) {
99100
self.client = client
100101
self.forcePolling = forcePolling
101102
self.forceWebsockets = forceWebsockets
102103
self.cookies = cookies
103104
self.log = logging
105+
self.socketPath = path
104106
self.session = NSURLSession(configuration: NSURLSessionConfiguration.ephemeralSessionConfiguration(),
105107
delegate: sessionDelegate, delegateQueue: self.workQueue)
106108
}
@@ -146,7 +148,7 @@ public final class SocketEngine: NSObject, WebSocketDelegate, SocketLogClient {
146148
return ("", "")
147149
}
148150

149-
var url = "\(self.client!.socketURL)/socket.io/?transport="
151+
var url = "\(self.client!.socketURL)\(self.socketPath)/socket.io/?transport="
150152
var urlPolling:String
151153
var urlWebSocket:String
152154

SocketIOClientSwift/SocketIOClient.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
7575
public var sid:String? {
7676
return self._sid
7777
}
78+
public var socketPath = ""
79+
7880

7981
/**
8082
Create a new SocketIOClient. opts can be omitted
@@ -103,6 +105,10 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
103105
self.log = log
104106
}
105107

108+
if let path = opts!["path"] as? String {
109+
self.socketPath = path
110+
}
111+
106112
if let polling = opts!["forcePolling"] as? Bool {
107113
self.forcePolling = polling
108114
}
@@ -153,9 +159,11 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketLogClient
153159
self.engine = SocketEngine(client: self,
154160
forcePolling: self.forcePolling,
155161
forceWebsockets: self.forceWebsockets,
156-
withCookies: self.cookies,
162+
cookies: self.cookies,
157163
logging: self.log,
158-
withSessionDelegate: self.sessionDelegate)
164+
sessionDelegate: self.sessionDelegate,
165+
path: self.socketPath
166+
)
159167
}
160168

161169
/**

0 commit comments

Comments
 (0)