Crate armature_websocket

Crate armature_websocket 

Source
Expand description

§Armature WebSocket

WebSocket server and client support for the Armature framework using tokio-tungstenite.

§Features

  • WebSocket server with connection management
  • WebSocket client for outbound connections
  • Room-based message broadcasting
  • Connection state management
  • Heartbeat/ping-pong support
  • JSON message serialization

§Example

use armature_websocket::{WebSocketServer, WebSocketHandler, Message};
use async_trait::async_trait;

struct ChatHandler;

#[async_trait]
impl WebSocketHandler for ChatHandler {
    async fn on_connect(&self, connection_id: &str) {
        println!("Client connected: {}", connection_id);
    }

    async fn on_message(&self, connection_id: &str, message: Message) {
        println!("Received from {}: {:?}", connection_id, message);
    }

    async fn on_disconnect(&self, connection_id: &str) {
        println!("Client disconnected: {}", connection_id);
    }
}

Structs§

CloseFrame
A struct representing the close command.
Connection
A WebSocket connection.
LoggingHandler
A no-op handler that logs messages.
Message
A WebSocket message.
Room
A room for grouping WebSocket connections.
RoomManager
Manages rooms and their members.
WebSocketClient
WebSocket client for connecting to WebSocket servers.
WebSocketClientBuilder
Builder for WebSocket client.
WebSocketServer
WebSocket server.
WebSocketServerBuilder
Builder for WebSocket server configuration.
WebSocketServerConfig
WebSocket server configuration.

Enums§

ConnectionState
Connection state.
MessageType
Message type enumeration.
RawMessage
An enum representing the various forms of a WebSocket message.
WebSocketError
WebSocket error type.

Traits§

WebSocketHandler
Trait for handling WebSocket events.

Type Aliases§

ConnectionId
Unique identifier for a connection.
RoomId
Unique identifier for a room.
WebSocketResult
Result type for WebSocket operations.