hummingbird-websocket

1.0.1

Websocket upgrade support for Hummingbird
hummingbird-project/hummingbird-websocket

What's New

v1.0.1

2023-02-21T14:51:22Z

Patch release changes

  • When adding websocket upgrade use new HBChannelInitializer.addProtocolUpgrade
  • Cancel auto ping task when websocket channel is closed
  • Ensure websocket channel is fully closed when other side closes input.
  • InitiateAutoPing schedules the first ping instead of sending it immediately
  • HBWebSocketClient sets up HTTPDecoder with leftOverBytesStrategy to .forwardBytes to ensure any remaining data in channel is passed onto websocket channel handler.

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.

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

Last updated: Tue Mar 28 2023 09:55:49 GMT-0500 (GMT-05:00)