Struct actix_web_actors::ws::WsResponseBuilder[][src]

pub struct WsResponseBuilder<'a, A, T> where
    A: Actor<Context = WebsocketContext<A>> + StreamHandler<Result<Message, ProtocolError>>,
    T: Stream<Item = Result<Bytes, PayloadError>> + 'static, 
{ /* fields omitted */ }
Expand description

Builder for Websocket session response.

Examples

Create a Websocket session response with default configuration.

WsResponseBuilder::new(WsActor, &req, stream).start()

Create a Websocket session with a specific max frame size, Codec, and protocols.

const MAX_FRAME_SIZE: usize = 16_384; // 16KiB

ws::WsResponseBuilder::new(WsActor, &req, stream)
    .codec(Codec::new())
    .protocols(&["A", "B"])
    .frame_size(MAX_FRAME_SIZE)
    .start()

Implementations

Construct a new WsResponseBuilder with actor, request, and payload stream.

For usage example, see docs on WsResponseBuilder struct.

Set the protocols for the session.

Set the max frame size for each message (in bytes).

Note: This will override any given Codec’s max frame size.

Set the Codec for the session. If Self::frame_size is also set, the given Codec’s max frame size will be overridden.

Perform WebSocket handshake and start actor.

req is an HttpRequest that should be requesting a websocket protocol change. stream should be a Bytes stream (such as actix_web::web::Payload) that contains a stream of the body request.

If there is a problem with the handshake, an error is returned.

If successful, consume the WsResponseBuilder and return a HttpResponse wrapped in a Result.

Perform WebSocket handshake and start actor.

req is an HttpRequest that should be requesting a websocket protocol change. stream should be a Bytes stream (such as actix_web::web::Payload) that contains a stream of the body request.

If there is a problem with the handshake, an error is returned.

If successful, returns a pair where the first item is an address for the created actor and the second item is the HttpResponse that should be returned from the websocket request.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more