Skip to content

Commit

Permalink
add socket configuration to default implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Jan 18, 2024
1 parent bba38b5 commit 85b9cde
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Sources/ActionCableSwift/ActionCableSwift.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

import Foundation
import WebSocketKit
import NIOCore

public final class ACClient {

Expand Down Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion Sources/ActionCableSwift/WebSocketClient/WS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand All @@ -43,6 +45,7 @@ open class WSS: ACWebSocketProtocol {

WebSocket.connect(to: url.absoluteString,
headers: httpHeaders,
configuration: configuration,
on: eventLoopGroup
) { ws in
self.ws = ws
Expand Down

2 comments on commit 85b9cde

@lexuanquynh
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you.

@nerzh
Copy link
Owner Author

@nerzh nerzh commented on 85b9cde Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤝

Please sign in to comment.