Skip to content
Merged
Show file tree
Hide file tree
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: 0 additions & 14 deletions .api-breakage/allowlist-branch-sendable-take-2.txt

This file was deleted.

3 changes: 0 additions & 3 deletions .api-breakage/allowlist-branch-update-for-new-niossl.txt

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
with:
package_name: websocket-kit
modules: WebSocketKit
pathsToInvalidate: /websocket-kit
pathsToInvalidate: /websocketkit/*
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ concurrency:
on:
pull_request: { types: [opened, reopened, synchronize, ready_for_review] }
push: { branches: [ main ] }

jobs:
vapor-integration:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:5.10-noble
container: swift:6.1-noble
steps:
- name: Check out package
uses: actions/checkout@v4
Expand All @@ -25,3 +26,5 @@ jobs:
unit-tests:
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
secrets: inherit
with:
with_musl: true
47 changes: 32 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.10
import PackageDescription

let package = Package(
Expand All @@ -20,19 +20,36 @@ let package = Package(
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.1.0"),
],
targets: [
.target(name: "WebSocketKit", dependencies: [
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
.product(name: "NIOExtras", package: "swift-nio-extras"),
.product(name: "NIOFoundationCompat", package: "swift-nio"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOSSL", package: "swift-nio-ssl"),
.product(name: "NIOWebSocket", package: "swift-nio"),
.product(name: "NIOTransportServices", package: "swift-nio-transport-services"),
.product(name: "Atomics", package: "swift-atomics")
]),
.testTarget(name: "WebSocketKitTests", dependencies: [
.target(name: "WebSocketKit"),
]),
.target(
name: "WebSocketKit",
dependencies: [
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
.product(name: "NIOExtras", package: "swift-nio-extras"),
.product(name: "NIOFoundationCompat", package: "swift-nio"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOSSL", package: "swift-nio-ssl"),
.product(name: "NIOWebSocket", package: "swift-nio"),
.product(name: "NIOTransportServices", package: "swift-nio-transport-services"),
.product(name: "Atomics", package: "swift-atomics"),
],
swiftSettings: swiftSettings
),
.testTarget(
name: "WebSocketKitTests",
dependencies: [
.target(name: "WebSocketKit"),
],
swiftSettings: swiftSettings
),
]
)

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("MemberImportVisibility"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
38 changes: 13 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
<p align="center">
<img
src="https://user-images.githubusercontent.com/1342803/75630258-105e9c00-5bb7-11ea-81b8-86afa000e188.png"
height="64"
alt="NIOWebSocketClient"
>
<br>
<br>
<a href="https://docs.vapor.codes/4.0/">
<img src="http://img.shields.io/badge/read_the-docs-2196f3.svg" alt="API Docs">
</a>
<a href="http://vapor.team">
<img src="https://img.shields.io/discord/431917998102675485.svg" alt="Team Chat">
</a>
<a href="LICENSE">
<img src="http://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License">
</a>
<a href="https://github.com/vapor/websocket-kit/actions/workflows/test.yml">
<img src="https://github.com/vapor/websocket-kit/actions/workflows/test.yml/badge.svg?event=push" alt="Continuous Integration">
</a>
<a href="https://swift.org">
<img src="http://img.shields.io/badge/swift-5.6-brightgreen.svg" alt="Swift 5.6">
</a>
<a href="https://swift.org">
<img src="http://img.shields.io/badge/swift-5.8-brightgreen.svg" alt="Swift 5.8">
</a>
<img src="https://design.vapor.codes/images/vapor-websocketkit.svg" height="96" alt="WebSocketKit">
<br>
<br>
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
<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>
<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>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift510up.svg" alt="Swift 5.10+"></a>
</p>

<br>

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.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extension WebSocket {
to url: String,
headers: HTTPHeaders = [:],
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
on eventLoopGroup: any EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) async -> ()
) async throws {
return try await self.connect(
Expand All @@ -130,7 +130,7 @@ extension WebSocket {
to url: URL,
headers: HTTPHeaders = [:],
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
on eventLoopGroup: any EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) async -> ()
) async throws {
return try await self.connect(
Expand All @@ -154,7 +154,7 @@ extension WebSocket {
query: String? = nil,
headers: HTTPHeaders = [:],
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
on eventLoopGroup: any EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) async -> ()
) async throws {
return try await self.connect(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions Sources/WebSocketKit/Docs.docc/theme-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"theme": {
"aside": { "border-radius": "16px", "border-style": "double", "border-width": "3px" },
"border-radius": "0",
"button": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" },
"code": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" },
"color": {
"websocketkit": { "dark": "hsl(200, 0%, 100%)", "light": "hsl(200, 0%, 75%)" },
"documentation-intro-fill": "radial-gradient(circle at top, var(--color-fluentkit) 30%, #000 100%)",
"documentation-intro-accent": "var(--color-websocketkit)",
"documentation-intro-eyebrow": "white",
"documentation-intro-figure": "white",
"documentation-intro-title": "white",
"logo-base": { "dark": "#fff", "light": "#000" },
"logo-shape": { "dark": "#000", "light": "#fff" },
"fill": { "dark": "#000", "light": "#fff" }
},
"icons": { "technology": "/websocketkit/images/WebSocketKit/vapor-websocketkit-logo.svg" }
},
"features": {
"quickNavigation": { "enable": true },
"i18n": { "enable": true }
}
}
15 changes: 0 additions & 15 deletions Sources/WebSocketKit/Exports.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if swift(>=5.8)

@_documentation(visibility: internal) @_exported import struct NIOCore.ByteBuffer
@_documentation(visibility: internal) @_exported import protocol NIOCore.Channel
@_documentation(visibility: internal) @_exported import protocol NIOCore.EventLoop
Expand All @@ -8,16 +6,3 @@
@_documentation(visibility: internal) @_exported import class NIOCore.EventLoopFuture
@_documentation(visibility: internal) @_exported import struct NIOHTTP1.HTTPHeaders
@_documentation(visibility: internal) @_exported import struct Foundation.URL

#else

@_exported import struct NIOCore.ByteBuffer
@_exported import protocol NIOCore.Channel
@_exported import protocol NIOCore.EventLoop
@_exported import protocol NIOCore.EventLoopGroup
@_exported import struct NIOCore.EventLoopPromise
@_exported import class NIOCore.EventLoopFuture
@_exported import struct NIOHTTP1.HTTPHeaders
@_exported import struct Foundation.URL

#endif
3 changes: 2 additions & 1 deletion Sources/WebSocketKit/HTTPUpgradeRequestHandler.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import NIOConcurrencyHelpers
import NIOCore
import NIOHTTP1

Expand Down Expand Up @@ -81,7 +82,7 @@ final class HTTPUpgradeRequestHandler: ChannelInboundHandler, RemovableChannelHa
}
}

func errorCaught(context: ChannelHandlerContext, error: Error) {
func errorCaught(context: ChannelHandlerContext, error: any Error) {
self.upgradePromise.fail(error)
context.close(promise: nil)
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/WebSocketKit/WebSocket+Connect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension WebSocket {
to url: String,
headers: HTTPHeaders = [:],
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
on eventLoopGroup: any EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) -> ()
) -> EventLoopFuture<Void> {
guard let url = URL(string: url) else {
Expand Down Expand Up @@ -46,7 +46,7 @@ extension WebSocket {
to url: URL,
headers: HTTPHeaders = [:],
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
on eventLoopGroup: any EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) -> ()
) -> EventLoopFuture<Void> {
let scheme = url.scheme ?? "ws"
Expand Down Expand Up @@ -85,7 +85,7 @@ extension WebSocket {
query: String? = nil,
headers: HTTPHeaders = [:],
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
on eventLoopGroup: any EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) -> ()
) -> EventLoopFuture<Void> {
return WebSocketClient(
Expand Down Expand Up @@ -132,7 +132,7 @@ extension WebSocket {
proxyHeaders: HTTPHeaders = [:],
proxyConnectDeadline: NIODeadline = NIODeadline.distantFuture,
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
on eventLoopGroup: any EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) -> ()
) -> EventLoopFuture<Void> {
return WebSocketClient(
Expand Down Expand Up @@ -175,7 +175,7 @@ extension WebSocket {
proxyHeaders: HTTPHeaders = [:],
proxyConnectDeadline: NIODeadline = NIODeadline.distantFuture,
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
on eventLoopGroup: any EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) -> ()
) -> EventLoopFuture<Void> {
guard let url = URL(string: url) else {
Expand Down
6 changes: 3 additions & 3 deletions Sources/WebSocketKit/WebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class WebSocket: Sendable {
case client
}

public var eventLoop: EventLoop {
public var eventLoop: any EventLoop {
return channel.eventLoop
}

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

@usableFromInline
/* private but @usableFromInline */
internal let channel: Channel
internal let channel: any Channel
private let onTextCallback: NIOLoopBoundBox<@Sendable (WebSocket, String) -> ()>
private let onBinaryCallback: NIOLoopBoundBox<@Sendable (WebSocket, ByteBuffer) -> ()>
private let onPongCallback: NIOLoopBoundBox<@Sendable (WebSocket, ByteBuffer) -> ()>
Expand All @@ -43,7 +43,7 @@ public final class WebSocket: Sendable {
private let frameSequence: NIOLockedValueBox<WebSocketFrameSequence?>
private let _pingInterval: NIOLockedValueBox<TimeAmount?>

init(channel: Channel, type: PeerType) {
init(channel: any Channel, type: PeerType) {
self.channel = channel
self.type = type
self.onTextCallback = .init({ _, _ in }, eventLoop: channel.eventLoop)
Expand Down
Loading