From 85b9cdee8cde32bc0a069c623098415aed4597e8 Mon Sep 17 00:00:00 2001 From: nerzh Date: Thu, 18 Jan 2024 08:44:39 +0100 Subject: [PATCH] add socket configuration to default implementation --- Sources/ActionCableSwift/ActionCableSwift.swift | 7 ++++++- Sources/ActionCableSwift/WebSocketClient/WS.swift | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Sources/ActionCableSwift/ActionCableSwift.swift b/Sources/ActionCableSwift/ActionCableSwift.swift index 7241a34..7f8d75f 100644 --- a/Sources/ActionCableSwift/ActionCableSwift.swift +++ b/Sources/ActionCableSwift/ActionCableSwift.swift @@ -1,5 +1,7 @@ import Foundation +import WebSocketKit +import NIOCore public final class ACClient { @@ -37,11 +39,14 @@ public final class ACClient { } } + /// Default websocket implementation public init(stringURL: String, + configuration: WebSocketClient.Configuration = .init(), + coreCount: Int = System.coreCount, headers: [String: String]? = nil, options: ACClientOptions? = nil ) { - self.ws = WSS(stringURL: stringURL) + self.ws = WSS(stringURL: stringURL, configuration: configuration, coreCount: coreCount) self.headers = headers self.options = options ?? ACClientOptions() setupWSCallbacks() diff --git a/Sources/ActionCableSwift/WebSocketClient/WS.swift b/Sources/ActionCableSwift/WebSocketClient/WS.swift index 78c92b0..458e7ef 100644 --- a/Sources/ActionCableSwift/WebSocketClient/WS.swift +++ b/Sources/ActionCableSwift/WebSocketClient/WS.swift @@ -18,11 +18,13 @@ open class WSS: ACWebSocketProtocol { public var url: URL private var eventLoopGroup: EventLoopGroup + private var configuration: WebSocketClient.Configuration var ws: WebSocket? - init(stringURL: String, coreCount: Int = System.coreCount) { + init(stringURL: String, configuration: WebSocketClient.Configuration = .init(), coreCount: Int = System.coreCount) { url = URL(string: stringURL)! eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: coreCount) + self.configuration = configuration } public var onConnected: ((_ headers: [String : String]?) -> Void)? @@ -43,6 +45,7 @@ open class WSS: ACWebSocketProtocol { WebSocket.connect(to: url.absoluteString, headers: httpHeaders, + configuration: configuration, on: eventLoopGroup ) { ws in self.ws = ws