Skip to content

Commit 7ff10d1

Browse files
committed
Add compress option
1 parent 8399877 commit 7ff10d1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Source/SocketEngine.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
6060
/// `true` if this engine is closed.
6161
public private(set) var closed = false
6262

63+
/// If `true` the engine will attempt to use WebSocket compression.
64+
public private(set) var compress = false
65+
6366
/// `true` if this engine is connected. Connected means that the initial poll connect has succeeded.
6467
public private(set) var connected = false
6568

@@ -171,6 +174,8 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
171174
self.selfSigned = selfSigned
172175
case let .security(security):
173176
self.security = security
177+
case .compress:
178+
self.compress = true
174179
default:
175180
continue
176181
}
@@ -331,6 +336,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
331336
}
332337

333338
ws?.callbackQueue = engineQueue
339+
ws?.enableCompression = compress
334340
ws?.delegate = self
335341
ws?.disableSSLCertValidation = selfSigned
336342
ws?.security = security

Source/SocketIOClientOption.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ protocol ClientOption : CustomStringConvertible, Equatable {
3030

3131
/// The options for a client.
3232
public enum SocketIOClientOption : ClientOption {
33+
/// If given, the WebSocket transport will attempt to use compression.
34+
case compress
35+
3336
/// A dictionary of GET parameters that will be included in the connect url.
3437
case connectParams([String: Any])
3538

@@ -103,6 +106,8 @@ public enum SocketIOClientOption : ClientOption {
103106
let description: String
104107

105108
switch self {
109+
case .compress:
110+
description = "compress"
106111
case .connectParams:
107112
description = "connectParams"
108113
case .cookies:
@@ -152,6 +157,8 @@ public enum SocketIOClientOption : ClientOption {
152157
let value: Any
153158

154159
switch self {
160+
case .compress:
161+
value = true
155162
case let .connectParams(params):
156163
value = params
157164
case let .cookies(cookies):

0 commit comments

Comments
 (0)