Swiftpack.co -  Package - hummingbird-project/hummingbird-websocket
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
hummingbird-project/hummingbird-websocket
Websocket upgrade support for Hummingbird
.package(url: "https://github.com/hummingbird-project/hummingbird-websocket.git", from: "0.2.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: 4
Last commit: 5 days ago

Release Notes

v0.2.0
2 weeks ago
  • Added new library HummingbirdWSClient which includes WebSocket client HBWebSocketClient
  • Added tests for both server and client
  • HBApplication.WebSocket.on parameter onUpgrade is no longing a throwing function.

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