Skip to content

Commit 45cc6b9

Browse files
committed
Added a useCustomEngine option to control if WebSocket is initialized to use the custom engine or native URLSession web tasks.
1 parent 173def3 commit 45cc6b9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Source/SocketIO/Client/SocketIOClientOption.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public enum SocketIOClientOption : ClientOption {
108108
/// Sets an NSURLSessionDelegate for the underlying engine. Useful if you need to handle self-signed certs.
109109
case sessionDelegate(URLSessionDelegate)
110110

111+
/// If passed `false`, the WebSocket stream will be configured with the useCustomEngine `false`.
112+
case useCustomEngine(Bool)
113+
111114
/// The version of socket.io being used. This should match the server version. Default is 3.
112115
case version(SocketIOVersion)
113116

@@ -160,6 +163,8 @@ public enum SocketIOClientOption : ClientOption {
160163
description = "sessionDelegate"
161164
case .enableSOCKSProxy:
162165
description = "enableSOCKSProxy"
166+
case .useCustomEngine:
167+
description = "customEngine"
163168
case .version:
164169
description = "version"
165170
}
@@ -213,6 +218,8 @@ public enum SocketIOClientOption : ClientOption {
213218
value = delegate
214219
case let .enableSOCKSProxy(enable):
215220
value = enable
221+
case let .useCustomEngine(enable):
222+
value = enable
216223
case let.version(versionNum):
217224
value = versionNum
218225
}

Source/SocketIO/Engine/SocketEngine.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ open class SocketEngine:
111111
/// The url for WebSockets.
112112
public private(set) var urlWebSocket = URL(string: "http://localhost/")!
113113

114+
/// When `false`, the WebSocket `stream` will be configured with the useCustomEngine `false`.
115+
public private(set) var useCustomEngine = true
116+
114117
/// The version of engine.io being used. Default is three.
115118
public private(set) var version: SocketIOVersion = .three
116119

@@ -307,7 +310,7 @@ open class SocketEngine:
307310
includingCookies: session?.configuration.httpCookieStorage?.cookies(for: urlPollingWithSid)
308311
)
309312

310-
ws = WebSocket(request: req, certPinner: certPinner, compressionHandler: compress ? WSCompression() : nil)
313+
ws = WebSocket(request: req, certPinner: certPinner, compressionHandler: compress ? WSCompression() : nil, useCustomEngine: useCustomEngine)
311314
ws?.callbackQueue = engineQueue
312315
ws?.delegate = self
313316

@@ -624,6 +627,8 @@ open class SocketEngine:
624627
self.compress = true
625628
case .enableSOCKSProxy:
626629
self.enableSOCKSProxy = true
630+
case let .useCustomEngine(enable):
631+
self.useCustomEngine = enable
627632
case let .version(num):
628633
version = num
629634
default:

0 commit comments

Comments
 (0)