Skip to content

Commit

Permalink
Add conditional compilation directive
Browse files Browse the repository at this point in the history
  • Loading branch information
cham-s committed Apr 23, 2024
1 parent 4b73088 commit 1c3de79
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Sources/WebSocketKit/WebSocket+Connect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extension WebSocket {
on eventLoopGroup: EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) -> ()
) -> EventLoopFuture<Void> {
#if canImport(Foundation)
let optionalURL: URL?
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) {
optionalURL = URL(string: url, encodingInvalidCharacters: false)
Expand All @@ -37,8 +38,20 @@ extension WebSocket {
on: eventLoopGroup,
onUpgrade: onUpgrade
)
#else
guard let url = URL(string: url) else {
return eventLoopGroup.any().makeFailedFuture(WebSocketClient.Error.invalidURL)
}
return self.connect(
to: url,
headers: headers,
configuration: configuration,
on: eventLoopGroup,
onUpgrade: onUpgrade
)
#endif
}

/// Establish a WebSocket connection.
///
/// - Parameters:
Expand Down Expand Up @@ -69,7 +82,7 @@ extension WebSocket {
onUpgrade: onUpgrade
)
}

/// Establish a WebSocket connection.
///
/// - Parameters:
Expand Down Expand Up @@ -108,7 +121,7 @@ extension WebSocket {
onUpgrade: onUpgrade
)
}

/// Establish a WebSocket connection via a proxy server.
///
/// - Parameters:
Expand Down Expand Up @@ -159,8 +172,8 @@ extension WebSocket {
onUpgrade: onUpgrade
)
}


/// Description
/// - Parameters:
/// - url: URL for the origin server.
Expand Down

0 comments on commit 1c3de79

Please sign in to comment.