diff --git a/CHANGELOG.md b/CHANGELOG.md index 00f26d3..b13c430 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ `SseEvent` and `SseNext`. - Add `comment` for the server-sent events comment that keeps an idle stream from being closed by an intermediary. +- Rename `upgrade_websocket` to `websocket` matching `sse`. - Rename the `WebsocketMessage` variants to `TextFrame`, `BinaryFrame` and `UserMessage`. - In replacement of the `CloseCode` variants that each carried their own data diff --git a/dev/autobahn.gleam b/dev/autobahn.gleam index b10db4b..db6905e 100644 --- a/dev/autobahn.gleam +++ b/dev/autobahn.gleam @@ -25,7 +25,7 @@ pub fn main() -> Nil { fn handle_request( request: request.Request(ewe.Connection), ) -> response.Response(ewe.Body) { - ewe.upgrade_websocket( + ewe.websocket( request:, on_init: fn(_conn, messages) { #(Nil, messages) }, handler: echo_message, diff --git a/src/ewe.gleam b/src/ewe.gleam index 19e307e..8126557 100644 --- a/src/ewe.gleam +++ b/src/ewe.gleam @@ -1,3 +1,142 @@ +//// + import ewe/internal/connection import ewe/internal/file import ewe/internal/handler as handler_ @@ -582,8 +721,8 @@ pub fn read_body_chunk( } } -// TODO: obviously not the string reason variant but this is for later! -/// Why a write to the client did not go through. +/// Why a write to the client did not go through. TODO: obviously not the string +/// reason variant but this is for later! pub type SendError { SendError(reason: String) } @@ -942,7 +1081,7 @@ pub fn send_close_frame( /// - `handler` is called for each frame from the client and each message the /// selector picks up. /// - `on_close` is called once however the WebSocket ended. -pub fn upgrade_websocket( +pub fn websocket( request request: request.Request(Connection), on_init on_init: fn(WebsocketConnection, process.Selector(user_message)) -> #(user_state, process.Selector(user_message)),