hummingbird-websocket

1.1.0

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

What's New

v1.1.0

2023-07-12T09:27:46Z

Minor version changes

  • Add support to supply additional headers during initial HTTP connection when using client. PR #20
  • Add support for editing maxFrameSize. PR #23
  • Add read callback in HBWebSocketClient. If you add a readCallback after the client has been created it is possible to miss packets. This ensures you don't miss any packets. PR #25
  • Require Hummingbird 1.4.0
  • Add public API to send an unsolicited pong message. PR #28 from @tkrajacic

Patch version changes

  • Fix the masking key generation not generating 0x0. PR #16 from @Joannis

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

Dependencies

Last updated: Fri Mar 01 2024 10:12:46 GMT-1000 (Hawaii-Aleutian Standard Time)