The Missing Rustlang pusher crate.
Bot releases are visible (Hide)
The previous WS implementation had several limitations that affected the reliability and maintainability of the Pusher client:
WebSocketClient
struct that holds all WS-related functionality.pub struct WebSocketClient {
url: Url,
socket: Option<WebSocketStream<MaybeTlsStream<TcpStream>>>,
state: Arc<RwLock<ConnectionState>>,
event_tx: mpsc::Sender<Event>,
command_rx: mpsc::Receiver<WebSocketCommand>,
}
pub enum WebSocketCommand {
Send(String),
Close,
}
const PING_INTERVAL: Duration = Duration::from_secs(30);
const PONG_TIMEOUT: Duration = Duration::from_secs(10);
run
method in WebSocketClient
uses tokio::select!
for efficient handling of multiple asynchronous operations.pub async fn run(&mut self) {
let mut ping_interval = interval(PING_INTERVAL);
let mut pong_timeout = Box::pin(sleep(Duration::from_secs(0)));
let mut waiting_for_pong = false;
while let Some(socket) = &mut self.socket {
tokio::select! {
// ... handle various async events ...
}
}
// ... handle disconnection ...
}
WebSocketClient
API has changed significantly. If you were directly interacting with WebSocket internals, you'll need to update your code.PusherClient
method signatures related to WebSocket operations have been updated to use the new format.Published by chmod77 about 2 months ago
BatchEvent
struct for representing individual events in a batchtrigger_batch
method to PusherClient
for sending multiple events in a single API callPusherClient
struct to support batch event operations