Skip to content

Commit b48f1e9

Browse files
committed
expose Starscream WebSocket enableSOCKSProxy option to socket.io-client-swift options
1 parent 6cfea5a commit b48f1e9

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.
@@ -133,6 +136,8 @@ public enum SocketIOClientOption : ClientOption {
133136
description = "security"
134137
case .sessionDelegate:
135138
description = "sessionDelegate"
139+
case .enableSOCKSProxy:
140+
description = "enableSOCKSProxy"
136141
}
137142

138143
return description
@@ -178,6 +183,8 @@ public enum SocketIOClientOption : ClientOption {
178183
value = signed
179184
case let .sessionDelegate(delegate):
180185
value = delegate
186+
case let .enableSOCKSProxy(enable):
187+
value = enable
181188
}
182189

183190
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)
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
@@ -588,6 +593,8 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
588593
self.security = security
589594
case .compress:
590595
self.compress = true
596+
case .enableSOCKSProxy:
597+
self.enableSOCKSProxy = true
591598
default:
592599
continue
593600
}

Source/SocketIO/Util/SocketExtensions.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ extension Dictionary where Key == String, Value == Any {
8181
return .sessionDelegate(delegate)
8282
case let ("compress", compress as Bool):
8383
return compress ? .compress : nil
84+
case let ("enableSOCKSProxy", enable as Bool):
85+
return .enableSOCKSProxy(enable)
8486
default:
8587
return nil
8688
}

0 commit comments

Comments
 (0)