Skip to content

Commit c1744e9

Browse files
authored
Merge pull request socketio#1049 from pdupris/enableSOCKSProxy
Add enableSOCKSProxy option to pass to Starscream WebSockets
2 parents 2fd9e4b + b48f1e9 commit c1744e9

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Source/SocketIO/Client/SocketIOClientOption.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public enum SocketIOClientOption : ClientOption {
5252

5353
/// If passed `true`, the only transport that will be used will be WebSockets.
5454
case forceWebsockets(Bool)
55+
56+
/// If passed `true`, the WebSocket stream will be configured with the enableSOCKSProxy `true`.
57+
case enableSOCKSProxy(Bool)
5558

5659
/// The queue that all interaction with the client should occur on. This is the queue that event handlers are
5760
/// called on.
@@ -143,6 +146,8 @@ public enum SocketIOClientOption : ClientOption {
143146
description = "security"
144147
case .sessionDelegate:
145148
description = "sessionDelegate"
149+
case .enableSOCKSProxy:
150+
description = "enableSOCKSProxy"
146151
}
147152

148153
return description
@@ -192,6 +197,8 @@ public enum SocketIOClientOption : ClientOption {
192197
value = signed
193198
case let .sessionDelegate(delegate):
194199
value = delegate
200+
case let .enableSOCKSProxy(enable):
201+
value = enable
195202
}
196203

197204
return value

Source/SocketIO/Engine/SocketEngine.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
113113
/// If `true`, then the engine is currently in WebSockets mode.
114114
@available(*, deprecated, message: "No longer needed, if we're not polling, then we must be doing websockets")
115115
public private(set) var websocket = false
116+
117+
/// When `true`, the WebSocket `stream` will be configured with the enableSOCKSProxy `true`.
118+
public private(set) var enableSOCKSProxy = false
116119

117120
/// The WebSocket for this engine.
118121
public private(set) var ws: WebSocket?
@@ -283,7 +286,9 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
283286

284287
addHeaders(to: &req, includingCookies: session?.configuration.httpCookieStorage?.cookies(for: urlPollingWithSid))
285288

286-
ws = WebSocket(request: req)
289+
let stream = FoundationStream()
290+
stream.enableSOCKSProxy = enableSOCKSProxy
291+
ws = WebSocket(request: req, stream: stream)
287292
ws?.callbackQueue = engineQueue
288293
ws?.enableCompression = compress
289294
ws?.disableSSLCertValidation = selfSigned
@@ -593,6 +598,8 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
593598
self.security = security
594599
case .compress:
595600
self.compress = true
601+
case .enableSOCKSProxy:
602+
self.enableSOCKSProxy = true
596603
default:
597604
continue
598605
}

Source/SocketIO/Util/SocketExtensions.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ extension Dictionary where Key == String, Value == Any {
8585
return .sessionDelegate(delegate)
8686
case let ("compress", compress as Bool):
8787
return compress ? .compress : nil
88+
case let ("enableSOCKSProxy", enable as Bool):
89+
return .enableSOCKSProxy(enable)
8890
default:
8991
return nil
9092
}

0 commit comments

Comments
 (0)