Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Sources/NWWebSocket/Model/Client/NWWebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ open class NWWebSocket: WebSocketConnection {
public convenience init(request: URLRequest,
connectAutomatically: Bool = false,
options: NWProtocolWebSocket.Options = NWWebSocket.defaultOptions,
parameters: NWParameters? = nil,
connectionQueue: DispatchQueue = .main) {

guard let url = request.url else {
Expand All @@ -57,13 +58,15 @@ open class NWWebSocket: WebSocketConnection {
self.init(url: invalidURL,
connectAutomatically: connectAutomatically,
options: options,
parameters: parameters,
connectionQueue: connectionQueue)
return
}

self.init(url: url,
connectAutomatically: connectAutomatically,
options: options,
parameters: parameters,
connectionQueue: connectionQueue)
}

Expand All @@ -77,17 +80,20 @@ open class NWWebSocket: WebSocketConnection {
public init(url: URL,
connectAutomatically: Bool = false,
options: NWProtocolWebSocket.Options = NWWebSocket.defaultOptions,
parameters: NWParameters? = nil,
connectionQueue: DispatchQueue = .main) {

endpoint = .url(url)

if url.scheme == "ws" {
parameters = NWParameters.tcp
if let parameters {
self.parameters = parameters
} else if url.scheme == "ws" {
self.parameters = NWParameters.tcp
} else {
parameters = NWParameters.tls
self.parameters = NWParameters.tls
}

parameters.defaultProtocolStack.applicationProtocols.insert(options, at: 0)
self.parameters.defaultProtocolStack.applicationProtocols.insert(options, at: 0)

self.connectionQueue = connectionQueue

Expand Down