Skip to content

Add enableSOCKSProxy option to pass to Starscream WebSockets #1049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Source/SocketIO/Client/SocketIOClientOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public enum SocketIOClientOption : ClientOption {

/// If passed `true`, the only transport that will be used will be WebSockets.
case forceWebsockets(Bool)

/// If passed `true`, the WebSocket stream will be configured with the enableSOCKSProxy `true`.
case enableSOCKSProxy(Bool)

/// The queue that all interaction with the client should occur on. This is the queue that event handlers are
/// called on.
Expand Down Expand Up @@ -133,6 +136,8 @@ public enum SocketIOClientOption : ClientOption {
description = "security"
case .sessionDelegate:
description = "sessionDelegate"
case .enableSOCKSProxy:
description = "enableSOCKSProxy"
}

return description
Expand Down Expand Up @@ -178,6 +183,8 @@ public enum SocketIOClientOption : ClientOption {
value = signed
case let .sessionDelegate(delegate):
value = delegate
case let .enableSOCKSProxy(enable):
value = enable
}

return value
Expand Down
9 changes: 8 additions & 1 deletion Source/SocketIO/Engine/SocketEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
/// If `true`, then the engine is currently in WebSockets mode.
@available(*, deprecated, message: "No longer needed, if we're not polling, then we must be doing websockets")
public private(set) var websocket = false

/// When `true`, the WebSocket `stream` will be configured with the enableSOCKSProxy `true`.
public private(set) var enableSOCKSProxy = false

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

addHeaders(to: &req)

ws = WebSocket(request: req)
let stream = FoundationStream()
stream.enableSOCKSProxy = enableSOCKSProxy
ws = WebSocket(request: req, stream: stream)
ws?.callbackQueue = engineQueue
ws?.enableCompression = compress
ws?.disableSSLCertValidation = selfSigned
Expand Down Expand Up @@ -588,6 +593,8 @@ open class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePollable, So
self.security = security
case .compress:
self.compress = true
case .enableSOCKSProxy:
self.enableSOCKSProxy = true
default:
continue
}
Expand Down
2 changes: 2 additions & 0 deletions Source/SocketIO/Util/SocketExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ extension Dictionary where Key == String, Value == Any {
return .sessionDelegate(delegate)
case let ("compress", compress as Bool):
return compress ? .compress : nil
case let ("enableSOCKSProxy", enable as Bool):
return .enableSOCKSProxy(enable)
default:
return nil
}
Expand Down