Sign in

    moonbitstack/moonapi/socket does not have a README file

    WsHandler

    type WsHandler = async (WebSocket) -> Unit

    A WebSocket route's handler (← FastAPI's @app.websocket endpoint).

    Disconnected

    pub(all) suberror Disconnected {
    Disconnected(code~ : Int, reason~ : String?)
    } derive(Eq,
    Debug
    )

    The peer left: its close code and reason (← Starlette's WebSocketDisconnect). receive raises it; a handler that lets it propagate simply ends.

    Disconnected::equal

    Disconnected::not_equal

    fn Disconnected::not_equal(x : Disconnected, y : Disconnected) -> Bool

    WebSocket

    pub struct WebSocket {
    scope :
    WebSocketScope

    params : Map[String, String]
    // private fields
    }

    A WebSocket connection as a handler sees it.

    WebSocket::accept

    async fn WebSocket::accept(self : WebSocket, subprotocol? : String, headers? : Array[(String, String)]) -> Unit

    Take the connect, then accept with subprotocol and extra headers on the handshake.

    WebSocket::close

    async fn WebSocket::close(self : WebSocket, code? : Int, reason? : String) -> Unit

    Close with code and reason. Before accept this declines the handshake, which a server answers with 403.

    WebSocket::deny

    async fn WebSocket::deny(self : WebSocket, response :
    Response
    ) -> Unit

    Decline the handshake with response (← Starlette's send_denial_response): the client gets its status, headers and body instead of a WebSocket. That takes ASGI's websocket.http.response extension; a server without it is sent close code 1008 instead, which it answers with 403. After accept there is no handshake left to decline, and the connection is closed with 1008.

    WebSocket::header

    fn WebSocket::header(self : WebSocket, name : String) -> String?

    The first request header named name (lowercase, as ASGI carries them).

    WebSocket::new

    A WebSocket over an ASGI connection. The app makes one per connection; a driver of its own makes one over its receive and send.

    WebSocket::offered_subprotocols

    fn WebSocket::offered_subprotocols(self : WebSocket) -> Array[String]

    The subprotocols the client offered, in its order of preference.

    WebSocket::param

    fn WebSocket::param(self : WebSocket, name : String) -> String?

    A path parameter by name.

    WebSocket::receive

    async fn WebSocket::receive(self : WebSocket) -> WsMessage

    The next message. Raises Disconnected when the peer has left.

    WebSocket::receive_bytes

    async fn WebSocket::receive_bytes(self : WebSocket) -> Bytes

    The next message, which must be binary; a text message is taken as its UTF-8.

    WebSocket::receive_json

    async fn WebSocket::receive_json(self : WebSocket) -> Json

    The next message parsed as JSON.

    WebSocket::receive_text

    async fn WebSocket::receive_text(self : WebSocket) -> String

    The next message, which must be text; a binary message is taken as its UTF-8.

    WebSocket::send

    async fn WebSocket::send(self : WebSocket, message : WsMessage) -> Unit

    Send message.

    WebSocket::send_bytes

    async fn WebSocket::send_bytes(self : WebSocket, bytes : Bytes) -> Unit

    Send a binary message.

    WebSocket::send_json

    async fn WebSocket::send_json(self : WebSocket, value : Json) -> Unit

    Send value serialised as a text message.

    WebSocket::send_text

    async fn WebSocket::send_text(self : WebSocket, text : String) -> Unit

    Send a text message.

    WsMessage

    pub(all) enum WsMessage {
    WsText(String)
    WsBinary(Bytes)
    } derive(Eq,
    Debug
    )

    One WebSocket message: text or binary.

    WsMessage::equal

    fn WsMessage::equal(WsMessage, WsMessage) -> Bool

    WsMessage::not_equal

    fn WsMessage::not_equal(x : WsMessage, y : WsMessage) -> Bool

    Source Files