Skip to content

Commit 014ccd5

Browse files
authored
Deal with Sendable and clean up package in general (#158)
* Bump Swift minimum to 5.10, update CI, make API docs exist, update README * Deal with a bunch of Sendable issues * Fix errors, deprecations, and outdated URL behavior in tests * Disable Android tests, update tests from the original NIOSSL source of the SSL helpers * Address PR feedback
1 parent b49c321 commit 014ccd5

19 files changed

+243
-180
lines changed

.api-breakage/allowlist-branch-sendable-take-2.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

.api-breakage/allowlist-branch-update-for-new-niossl.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/api-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ jobs:
1111
with:
1212
package_name: websocket-kit
1313
modules: WebSocketKit
14-
pathsToInvalidate: /websocket-kit
14+
pathsToInvalidate: /websocketkit/*

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ concurrency:
55
on:
66
pull_request: { types: [opened, reopened, synchronize, ready_for_review] }
77
push: { branches: [ main ] }
8+
89
jobs:
910
vapor-integration:
1011
if: ${{ !(github.event.pull_request.draft || false) }}
1112
runs-on: ubuntu-latest
12-
container: swift:5.10-noble
13+
container: swift:6.1-noble
1314
steps:
1415
- name: Check out package
1516
uses: actions/checkout@v4
@@ -25,3 +26,5 @@ jobs:
2526
unit-tests:
2627
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
2728
secrets: inherit
29+
with:
30+
with_musl: true

Package.swift

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.7
1+
// swift-tools-version:5.10
22
import PackageDescription
33

44
let package = Package(
@@ -20,19 +20,36 @@ let package = Package(
2020
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.1.0"),
2121
],
2222
targets: [
23-
.target(name: "WebSocketKit", dependencies: [
24-
.product(name: "NIOCore", package: "swift-nio"),
25-
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
26-
.product(name: "NIOExtras", package: "swift-nio-extras"),
27-
.product(name: "NIOFoundationCompat", package: "swift-nio"),
28-
.product(name: "NIOHTTP1", package: "swift-nio"),
29-
.product(name: "NIOSSL", package: "swift-nio-ssl"),
30-
.product(name: "NIOWebSocket", package: "swift-nio"),
31-
.product(name: "NIOTransportServices", package: "swift-nio-transport-services"),
32-
.product(name: "Atomics", package: "swift-atomics")
33-
]),
34-
.testTarget(name: "WebSocketKitTests", dependencies: [
35-
.target(name: "WebSocketKit"),
36-
]),
23+
.target(
24+
name: "WebSocketKit",
25+
dependencies: [
26+
.product(name: "NIOCore", package: "swift-nio"),
27+
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
28+
.product(name: "NIOExtras", package: "swift-nio-extras"),
29+
.product(name: "NIOFoundationCompat", package: "swift-nio"),
30+
.product(name: "NIOHTTP1", package: "swift-nio"),
31+
.product(name: "NIOSSL", package: "swift-nio-ssl"),
32+
.product(name: "NIOWebSocket", package: "swift-nio"),
33+
.product(name: "NIOTransportServices", package: "swift-nio-transport-services"),
34+
.product(name: "Atomics", package: "swift-atomics"),
35+
],
36+
swiftSettings: swiftSettings
37+
),
38+
.testTarget(
39+
name: "WebSocketKitTests",
40+
dependencies: [
41+
.target(name: "WebSocketKit"),
42+
],
43+
swiftSettings: swiftSettings
44+
),
3745
]
3846
)
47+
48+
var swiftSettings: [SwiftSetting] { [
49+
.enableUpcomingFeature("ExistentialAny"),
50+
.enableUpcomingFeature("ConciseMagicFile"),
51+
.enableUpcomingFeature("ForwardTrailingClosures"),
52+
.enableUpcomingFeature("DisableOutwardActorInference"),
53+
.enableUpcomingFeature("MemberImportVisibility"),
54+
.enableExperimentalFeature("StrictConcurrency=complete"),
55+
] }

README.md

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
<p align="center">
2-
<img
3-
src="https://user-images.githubusercontent.com/1342803/75630258-105e9c00-5bb7-11ea-81b8-86afa000e188.png"
4-
height="64"
5-
alt="NIOWebSocketClient"
6-
>
7-
<br>
8-
<br>
9-
<a href="https://docs.vapor.codes/4.0/">
10-
<img src="http://img.shields.io/badge/read_the-docs-2196f3.svg" alt="API Docs">
11-
</a>
12-
<a href="http://vapor.team">
13-
<img src="https://img.shields.io/discord/431917998102675485.svg" alt="Team Chat">
14-
</a>
15-
<a href="LICENSE">
16-
<img src="http://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License">
17-
</a>
18-
<a href="https://github.com/vapor/websocket-kit/actions/workflows/test.yml">
19-
<img src="https://github.com/vapor/websocket-kit/actions/workflows/test.yml/badge.svg?event=push" alt="Continuous Integration">
20-
</a>
21-
<a href="https://swift.org">
22-
<img src="http://img.shields.io/badge/swift-5.6-brightgreen.svg" alt="Swift 5.6">
23-
</a>
24-
<a href="https://swift.org">
25-
<img src="http://img.shields.io/badge/swift-5.8-brightgreen.svg" alt="Swift 5.8">
26-
</a>
2+
<img src="https://design.vapor.codes/images/vapor-websocketkit.svg" height="96" alt="WebSocketKit">
3+
<br>
4+
<br>
5+
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
6+
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
7+
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
8+
<a href="https://github.com/vapor/websocket-kit/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/websocket-kit/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
9+
<a href="https://codecov.io/gh/vapor/websocket-kit"><img src="https://img.shields.io/codecov/c/gh/vapor/websocket-kit?style=plastic&logo=codecov&label=codecov&token=FroD9hgbSC"></a>
10+
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift510up.svg" alt="Swift 5.10+"></a>
2711
</p>
12+
13+
<br>
14+
15+
WebSocketKit provides an abstraction over [SwiftNIO's Websockets](https://github.com/apple/swift-nio.git) to make it easy to build websocket clients and servers in Swift. IT provides functionality to send and receive data, ping/pongs and text, connection handling and upgrade handling. It should be simpler to use than using SwiftNIO directly.

Sources/WebSocketKit/Concurrency/WebSocket+Concurrency.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ extension WebSocket {
110110
to url: String,
111111
headers: HTTPHeaders = [:],
112112
configuration: WebSocketClient.Configuration = .init(),
113-
on eventLoopGroup: EventLoopGroup,
113+
on eventLoopGroup: any EventLoopGroup,
114114
onUpgrade: @Sendable @escaping (WebSocket) async -> ()
115115
) async throws {
116116
return try await self.connect(
@@ -130,7 +130,7 @@ extension WebSocket {
130130
to url: URL,
131131
headers: HTTPHeaders = [:],
132132
configuration: WebSocketClient.Configuration = .init(),
133-
on eventLoopGroup: EventLoopGroup,
133+
on eventLoopGroup: any EventLoopGroup,
134134
onUpgrade: @Sendable @escaping (WebSocket) async -> ()
135135
) async throws {
136136
return try await self.connect(
@@ -154,7 +154,7 @@ extension WebSocket {
154154
query: String? = nil,
155155
headers: HTTPHeaders = [:],
156156
configuration: WebSocketClient.Configuration = .init(),
157-
on eventLoopGroup: EventLoopGroup,
157+
on eventLoopGroup: any EventLoopGroup,
158158
onUpgrade: @Sendable @escaping (WebSocket) async -> ()
159159
) async throws {
160160
return try await self.connect(
Lines changed: 32 additions & 0 deletions
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"theme": {
3+
"aside": { "border-radius": "16px", "border-style": "double", "border-width": "3px" },
4+
"border-radius": "0",
5+
"button": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" },
6+
"code": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" },
7+
"color": {
8+
"websocketkit": { "dark": "hsl(200, 0%, 100%)", "light": "hsl(200, 0%, 75%)" },
9+
"documentation-intro-fill": "radial-gradient(circle at top, var(--color-fluentkit) 30%, #000 100%)",
10+
"documentation-intro-accent": "var(--color-websocketkit)",
11+
"documentation-intro-eyebrow": "white",
12+
"documentation-intro-figure": "white",
13+
"documentation-intro-title": "white",
14+
"logo-base": { "dark": "#fff", "light": "#000" },
15+
"logo-shape": { "dark": "#000", "light": "#fff" },
16+
"fill": { "dark": "#000", "light": "#fff" }
17+
},
18+
"icons": { "technology": "/websocketkit/images/WebSocketKit/vapor-websocketkit-logo.svg" }
19+
},
20+
"features": {
21+
"quickNavigation": { "enable": true },
22+
"i18n": { "enable": true }
23+
}
24+
}

Sources/WebSocketKit/Exports.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#if swift(>=5.8)
2-
31
@_documentation(visibility: internal) @_exported import struct NIOCore.ByteBuffer
42
@_documentation(visibility: internal) @_exported import protocol NIOCore.Channel
53
@_documentation(visibility: internal) @_exported import protocol NIOCore.EventLoop
@@ -8,16 +6,3 @@
86
@_documentation(visibility: internal) @_exported import class NIOCore.EventLoopFuture
97
@_documentation(visibility: internal) @_exported import struct NIOHTTP1.HTTPHeaders
108
@_documentation(visibility: internal) @_exported import struct Foundation.URL
11-
12-
#else
13-
14-
@_exported import struct NIOCore.ByteBuffer
15-
@_exported import protocol NIOCore.Channel
16-
@_exported import protocol NIOCore.EventLoop
17-
@_exported import protocol NIOCore.EventLoopGroup
18-
@_exported import struct NIOCore.EventLoopPromise
19-
@_exported import class NIOCore.EventLoopFuture
20-
@_exported import struct NIOHTTP1.HTTPHeaders
21-
@_exported import struct Foundation.URL
22-
23-
#endif

Sources/WebSocketKit/HTTPUpgradeRequestHandler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import NIOConcurrencyHelpers
12
import NIOCore
23
import NIOHTTP1
34

@@ -81,7 +82,7 @@ final class HTTPUpgradeRequestHandler: ChannelInboundHandler, RemovableChannelHa
8182
}
8283
}
8384

84-
func errorCaught(context: ChannelHandlerContext, error: Error) {
85+
func errorCaught(context: ChannelHandlerContext, error: any Error) {
8586
self.upgradePromise.fail(error)
8687
context.close(promise: nil)
8788
}

Sources/WebSocketKit/WebSocket+Connect.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension WebSocket {
1717
to url: String,
1818
headers: HTTPHeaders = [:],
1919
configuration: WebSocketClient.Configuration = .init(),
20-
on eventLoopGroup: EventLoopGroup,
20+
on eventLoopGroup: any EventLoopGroup,
2121
onUpgrade: @Sendable @escaping (WebSocket) -> ()
2222
) -> EventLoopFuture<Void> {
2323
guard let url = URL(string: url) else {
@@ -46,7 +46,7 @@ extension WebSocket {
4646
to url: URL,
4747
headers: HTTPHeaders = [:],
4848
configuration: WebSocketClient.Configuration = .init(),
49-
on eventLoopGroup: EventLoopGroup,
49+
on eventLoopGroup: any EventLoopGroup,
5050
onUpgrade: @Sendable @escaping (WebSocket) -> ()
5151
) -> EventLoopFuture<Void> {
5252
let scheme = url.scheme ?? "ws"
@@ -85,7 +85,7 @@ extension WebSocket {
8585
query: String? = nil,
8686
headers: HTTPHeaders = [:],
8787
configuration: WebSocketClient.Configuration = .init(),
88-
on eventLoopGroup: EventLoopGroup,
88+
on eventLoopGroup: any EventLoopGroup,
8989
onUpgrade: @Sendable @escaping (WebSocket) -> ()
9090
) -> EventLoopFuture<Void> {
9191
return WebSocketClient(
@@ -132,7 +132,7 @@ extension WebSocket {
132132
proxyHeaders: HTTPHeaders = [:],
133133
proxyConnectDeadline: NIODeadline = NIODeadline.distantFuture,
134134
configuration: WebSocketClient.Configuration = .init(),
135-
on eventLoopGroup: EventLoopGroup,
135+
on eventLoopGroup: any EventLoopGroup,
136136
onUpgrade: @Sendable @escaping (WebSocket) -> ()
137137
) -> EventLoopFuture<Void> {
138138
return WebSocketClient(
@@ -175,7 +175,7 @@ extension WebSocket {
175175
proxyHeaders: HTTPHeaders = [:],
176176
proxyConnectDeadline: NIODeadline = NIODeadline.distantFuture,
177177
configuration: WebSocketClient.Configuration = .init(),
178-
on eventLoopGroup: EventLoopGroup,
178+
on eventLoopGroup: any EventLoopGroup,
179179
onUpgrade: @Sendable @escaping (WebSocket) -> ()
180180
) -> EventLoopFuture<Void> {
181181
guard let url = URL(string: url) else {

Sources/WebSocketKit/WebSocket.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public final class WebSocket: Sendable {
1212
case client
1313
}
1414

15-
public var eventLoop: EventLoop {
15+
public var eventLoop: any EventLoop {
1616
return channel.eventLoop
1717
}
1818

@@ -31,7 +31,7 @@ public final class WebSocket: Sendable {
3131

3232
@usableFromInline
3333
/* private but @usableFromInline */
34-
internal let channel: Channel
34+
internal let channel: any Channel
3535
private let onTextCallback: NIOLoopBoundBox<@Sendable (WebSocket, String) -> ()>
3636
private let onBinaryCallback: NIOLoopBoundBox<@Sendable (WebSocket, ByteBuffer) -> ()>
3737
private let onPongCallback: NIOLoopBoundBox<@Sendable (WebSocket, ByteBuffer) -> ()>
@@ -43,7 +43,7 @@ public final class WebSocket: Sendable {
4343
private let frameSequence: NIOLockedValueBox<WebSocketFrameSequence?>
4444
private let _pingInterval: NIOLockedValueBox<TimeAmount?>
4545

46-
init(channel: Channel, type: PeerType) {
46+
init(channel: any Channel, type: PeerType) {
4747
self.channel = channel
4848
self.type = type
4949
self.onTextCallback = .init({ _, _ in }, eventLoop: channel.eventLoop)

0 commit comments

Comments
 (0)