diff --git a/Source/SocketEngine.swift b/Source/SocketEngine.swift index fc43ea3..da5e017 100644 --- a/Source/SocketEngine.swift +++ b/Source/SocketEngine.swift @@ -60,6 +60,9 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll /// `true` if this engine is closed. public private(set) var closed = false + /// If `true` the engine will attempt to use WebSocket compression. + public private(set) var compress = false + /// `true` if this engine is connected. Connected means that the initial poll connect has succeeded. public private(set) var connected = false @@ -171,6 +174,8 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll self.selfSigned = selfSigned case let .security(security): self.security = security + case .compress: + self.compress = true default: continue } @@ -331,6 +336,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll } ws?.callbackQueue = engineQueue + ws?.enableCompression = compress ws?.delegate = self ws?.disableSSLCertValidation = selfSigned ws?.security = security diff --git a/Source/SocketIOClientOption.swift b/Source/SocketIOClientOption.swift index f594b6b..6802fa0 100644 --- a/Source/SocketIOClientOption.swift +++ b/Source/SocketIOClientOption.swift @@ -30,6 +30,9 @@ protocol ClientOption : CustomStringConvertible, Equatable { /// The options for a client. public enum SocketIOClientOption : ClientOption { + /// If given, the WebSocket transport will attempt to use compression. + case compress + /// A dictionary of GET parameters that will be included in the connect url. case connectParams([String: Any]) @@ -103,6 +106,8 @@ public enum SocketIOClientOption : ClientOption { let description: String switch self { + case .compress: + description = "compress" case .connectParams: description = "connectParams" case .cookies: @@ -152,6 +157,8 @@ public enum SocketIOClientOption : ClientOption { let value: Any switch self { + case .compress: + value = true case let .connectParams(params): value = params case let .cookies(cookies):