Swiftpack.co - hummingbird-project/hummingbird-websocket as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by hummingbird-project.
hummingbird-project/hummingbird-websocket 0.4.0
Websocket upgrade support for Hummingbird
⭐️ 6
🕓 10 weeks ago
iOS tvOS linux macOS iOS
.package(url: "https://github.com/hummingbird-project/hummingbird-websocket.git", from: "0.4.0")

Hummingbird Websocket

Adds support for upgrading HTTP connections to WebSocket.

Usage

let app = HBApplication()
// add HTTP to WebSocket upgrade
app.ws.addUpgrade()
// add middleware to websocket initial requests
app.ws.add(middleware: HBLogRequestsMiddleware(.info))
// on websocket connect. 
app.ws.on("/ws") { req, ws in
    // send ping and wait for pong and repeat every 60 seconds
    ws.initiateAutoPing(interval: .seconds(60))
    // on read from client send the same data back
    ws.onRead { data, ws in
        ws.write(data)
    }
}
app.start()
app.wait()

Documentation

You can find reference documentation for HummingbirdWebSocket here. The hummingbird-examples repository has a number of examples of different uses of the library.

GitHub

link
Stars: 6
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

v0.4.0
10 weeks ago

Minor release updates

  • Using hummingbird v0.13.0

Patch release updates

  • Fix websocket URLs that include query strings

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics