Skip to content

v0.6.0

Compare
Choose a tag to compare
@gbaranski gbaranski released this 16 Nov 14:11
· 5 commits to master since this release
  • change Client::close() to use reference instead of self; remove async qualifier
  • feat: loosen std::fmt::Debug constrain on Call by @qiujiangkun in #39
  • refactor: replace SessionExt::Args with http::Request by @qiujiangkun and @gbaranski in #42
  • add ClientExt::on_disconnect() for socket closure and return a ClientCloseCode from ClientExt::on_close()/on_disconnect() to control reconnect/full-close behavior by @UkoeHB
  • add Session::close() method by @UkoeHB
  • fix server bug that would cause the server to crash if ServerExt::on_connect() returned an error by @UkoeHB
  • return Err(Option<CloseFrame>) from ServerExt::on_connect() to reject connections by @UkoeHB
  • robustness: Server, Client, Session, Sink interfaces now return Result<(), tokio::sync::mpsc::error::SendError> instead of potentially panicking by @UkoeHB
  • add reason to ServerExt::on_disconnect() by @UkoeHB
  • improved tracing emitted during close sequences by @UkoeHB
  • add ClientConfig::query_parameter() so connection requests can pass data via the URI (since additional connection headers are not supported by the websockets spec, this method should be more compatible with other implementations) by @UkoeHB
  • removed panics from the internals by @UkoeHB
  • downgraded tracing errors to warnings by @UkoeHB
  • Return Ok(MessageSignal) from Client and Session .binary()/.text()/.close() endpoints instead of Ok(()). The MessageSignal::state() method will indicate the current state of the message (sending/sent/failed). by @UkoeHB
  • Clients attempt to reconnect immediately instead of after one full reconnect interval. by @UkoeHB
  • Incoming user messages are discarded while a client is reconnecting, to better match the usual behavior of a websocket connection. If you want messages to be buffered while reconnecting, you should implement your own buffer. by @UkoeHB
  • Rename socket::Config -> socket::SocketConfig and add a heartbeat_ping_msg_fn member variable in order to support custom Ping/Pong protocols. by @UkoeHB
    • Add ClientConfig::socket_config() setter so clients can define their socket's config.
    • Add ezsockets::axum::Upgrade::on_upgrade_with_config() that accepts a SocketConfig.
  • Refactor ezeockets::client::connect() to use a retry loop for the initial connection. Add max_initial_connect_attempts and max_reconnect_attempts options to the ClientConfig (they default to 'infinite'). by @UkoeHB
  • Move axum and tungstenite server runners into new submodule src/server_runners. by @UkoeHB
  • Update to tokio-tungstenite v0.20.0. by @UkoeHB
  • Fork axum-tungstenite crate into src/server_runners and refactor the axum runner to use that instead of axum::extract::ws. by @UkoeHB
  • Bug fix: remove race condition between sending a message and a socket connection closing that would cause a client to shut down instead of calling on_disconnect/on_close. by @UkoeHB
  • Use tokio-tungstenite-wasm errors internally to better support cross-platform clients. by @UkoeHB
  • Use enfync runtime handles internally to better support cross-platform clients. Default clients continue to use tokio. by @UkoeHB
  • Add ClientConnector abstraction for connecting clients and add ezsockets::client::connect_with. by @UkoeHB
  • Add ClientConnectorWasm and wasm_client feature. Added chat-client-wasm example to show a WASM client that compiles. It currently only listens to the chat and can't input anything since browser does not have a terminal. by @UkoeHB
  • Refactor Socket and Client to not depend on tokio when compiling to WASM. This is a breaking change as the Client API now exposes async_channel error types instead of tokio error types, and Client::call_with() now takes an async_channel::Sender instead of a tokio oneshot. by @UkoeHB
  • Add unimplemented socket close codes. by @UkoeHB
  • Add ClientExt::on_connect_fail() for custom handling of connection attempt failures. By default the client will continue trying to connect. by @UkoeHB

Migration guide:

impl ezsockets::SessionExt for MySession {
    type Args = (); // <----- 1. Remove Args on `SessionExt`
    // ...
}

impl ezsockets::ServerExt for ChatServer {
    // before
    async fn on_connect(
        &mut self,
        socket: Socket,
        address: SocketAddr,
        args: <Self::Session as ezsockets::SessionExt>::Args, // <----- 2. Remove `args` argument
    ) -> Result<Session, Error> { todo!() }

    // after
    async fn on_connect(
        &mut self,
        socket: Socket,
        request: ezsockets::Request, // <----- 3. Add `request: ezsockets::Request` argument.
        //                                        Note: `ezsockets::Request` is an alias for `http::Request`
        address: SocketAddr,
    ) -> Result<Session, Option<CloseFrame>> { todo!() } // <----- 4. Return `CloseFrame` if rejecting connection.

    // ...
}


// ONLY for `axum`

async fn websocket_handler(
    Extension(server): Extension<Server<ChatServer>>,
    ezsocket: Upgrade,
) -> impl IntoResponse {
    let session_args = get_session_args();
    // before:
        ezsocket.on_upgrade(server, session_args) // <----- 5. Remove `session_args` argument
    // after:
        ezsocket.on_upgrade(server)               // <----- Now you can customize the `Session` inside of `ServerExt::on_connect` via `ezsockets::Request`.
}

// ONLY for `tungstenite`

// before
ezsockets::tungstenite::run(
    server,
    "127.0.0.1:8080",
    |_| async move { Ok(()) } // <----- 6. Remove the last argument,
                              // Now you can customize the `Session` inside of `ServerExt::on_connect` via `ezsockets::Request`
).await.unwrap();

// after
ezsockets::tungstenite::run(server, "127.0.0.1:8080") // Now you can customize the `Session` inside of `ServerExt::on_connect` via `ezsockets::Request`
    .await
    .unwrap();