All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
- Guarantee the internal
SessionActor
is dropped beforeServerExt::on_disconnect
is called. - Return
CloseCode::Abnormal
from keepalive timeouts instead ofCloseCode::Normal
. - Fix DDOS by honest clients when servers check capacity after clients connect.
- Allow users to use tokio v2.4.0 in their projects. See #106.
- Add
MessageSignal::new()
.
- Tighten cleanup guarantees for outgoing client messages in reconnect cycles.
- change
Client::close()
to use reference instead ofself
; removeasync
qualifier - feat: loosen
std::fmt::Debug
constrain onCall
by @qiujiangkun in #39 - refactor: replace
SessionExt::Args
withhttp::Request
by @qiujiangkun and @gbaranski in #42 - add
ClientExt::on_disconnect()
for socket closure and return aClientCloseCode
fromClientExt::on_close()/on_disconnect()
to control reconnect/full-close behavior - add
Session::close()
method - fix server bug that would cause the server to crash if
ServerExt::on_connect()
returned an error - return
Err(Option<CloseFrame>)
fromServerExt::on_connect()
to reject connections - robustness:
Server
,Client
,Session
,Sink
interfaces now returnResult<(), tokio::sync::mpsc::error::SendError>
instead of potentially panicking - add reason to
ServerExt::on_disconnect()
- improved tracing emitted during close sequences
- 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) - removed panics from the internals
- downgraded tracing errors to warnings
- Return
Ok(MessageSignal)
fromClient
andSession
.binary()/.text()/.close()
endpoints instead ofOk(())
. TheMessageSignal::state()
method will indicate the current state of the message (sending/sent/failed). - Clients attempt to reconnect immediately instead of after one full reconnect interval.
- 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.
- Rename
socket::Config
->socket::SocketConfig
and add aheartbeat_ping_msg_fn
member variable in order to support custom Ping/Pong protocols.- Add
ClientConfig::socket_config()
setter so clients can define their socket's config. - Add
ezsockets::axum::Upgrade::on_upgrade_with_config()
that accepts aSocketConfig
.
- Add
- Refactor
ezeockets::client::connect()
to use a retry loop for the initial connection. Addmax_initial_connect_attempts
andmax_reconnect_attempts
options to theClientConfig
(they default to 'infinite'). - Move
axum
andtungstenite
server runners into new submodulesrc/server_runners
. - Update to
tokio-tungstenite
v0.20.0. - Fork axum-tungstenite crate into
src/server_runners
and refactor theaxum
runner to use that instead ofaxum::extract::ws
. - 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
. - Use
tokio-tungstenite-wasm
errors internally to better support cross-platform clients. - Use
enfync
runtime handles internally to better support cross-platform clients. Default clients continue to use tokio. - Add
ClientConnector
abstraction for connecting clients and addezsockets::client::connect_with
. - Add
ClientConnectorWasm
andwasm_client
feature. Addedchat-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. - Refactor
Socket
andClient
to not depend ontokio
when compiling to WASM. This is a breaking change as theClient
API now exposesasync_channel
error types instead oftokio
error types, andClient::call_with()
now takes anasync_channel::Sender
instead of atokio
oneshot. - Add unimplemented socket close codes.
- Add
ClientExt::on_connect_fail()
for custom handling of connection attempt failures. By default the client will continue trying to connect.
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();
- fix examples links in README.md
- feat: add TLS support for servers(#31)
- refactor: rename methods and types for better distinction(#28)
Before | After |
---|---|
ClientExt::Params |
ClientExt::Call |
ClientExt::text(...) |
ClientExt::on_text(...) |
ClientExt::binary(...) |
ClientExt::on_binary(...) |
ClientExt::call(...) |
ClientExt::on_call(...) |
ClientExt::connected(...) |
ClientExt::on_connect(...) |
ClientExt::closed(...) |
ClientExt::closed(...) |
- | - |
ServerExt::Params |
ServerExt::Call |
ServerExt::accept(...) |
ServerExt::on_connect(...) |
ServerExt::disconnected(...) |
ServerExt::on_disconnect(...) |
ServerExt::call(...) |
ServerExt::on_call(...) |
- | - |
SessionExt::Params |
SessionExt::Call |
SessionExt::text(...) |
SessionExt::on_text(...) |
SessionExt::binary(...) |
SessionExt::on_binary(...) |
SessionExt::call(...) |
SessionExt::on_call(...) |
Additionally for the ezsockets::tungstenite::run_on
function you need to also pass an ezsockets::tungstenite::Acceptor
, if you don't use TLS, just pass ezsockets::tungstenite::Acceptor::Plain
.
- connect request customizability(#25) with bearer authorization and custom headers.
- allow passing String directly to
ClientConfig::new()
- client connection handlers.
ClientExt::closed()
andClientExt::connected()
- add
Client::close()
method - add benchmarks
- use biased non-random
tokio::select
- add
alive()
to check if connection is alive. - add
counter-server
example - more friendly panic messages
- make
Server::call
,Session::text
,Session::binary
andSession::call
synchronous
- Automatic GitHub workflows
- Integration tests
- Add
tungstenite::run_on
for alternative setups - Refactor the
Client<T>
T
generic logic
- fix panics
- close connection on heartbeat failure
- improve reconnection mechanism
- add basic authorization
- rename
Client::message()
toClient::call()
Client::call()
returnsResult<T, E>
- To/From Sender conversions on Client
- Custom calls on
Session
- Add
Args
for session creation - Add
call_with
for with-response call - improve logging
- remove
thiserror
usage
https://github.com/gbaranski/ezsockets/compare/v0.1.0...v0.2.0
First release!