hummingbird-websocket

1.2.0

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

What's New

v1.2.0

2023-10-13T18:07:01Z

Minor release changes

  • Add support for WebSocket extensions and implement permessage-deflate extension as described in https://www.rfc-editor.org/rfc/rfc7692. PR #27
  • Make HBWebSocket conform to Sendable. Split auto ping code off into a separate internally managed type. PR #30
  • Minimum supported version of Swift is now 5.7

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.7.0
View More Packages from this Author

Dependencies

Last updated: Fri Mar 29 2024 00:43:14 GMT-0900 (Hawaii-Aleutian Daylight Time)