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
impl<'a, A, T> WsResponseBuilder<'a, A, T> where
A: Actor<Context = WebsocketContext<A>> + StreamHandler<Result<Message, ProtocolError>>,
T: Stream<Item = Result<Bytes, PayloadError>> + 'static,
impl<'a, A, T> WsResponseBuilder<'a, A, T> where
A: Actor<Context = WebsocketContext<A>> + StreamHandler<Result<Message, ProtocolError>>,
T: Stream<Item = Result<Bytes, PayloadError>> + 'static,
Construct a new WsResponseBuilder
with actor, request, and payload stream.
For usage example, see docs on WsResponseBuilder
struct.
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
impl<'a, A, T> !RefUnwindSafe for WsResponseBuilder<'a, A, T>
impl<'a, A, T> !Send for WsResponseBuilder<'a, A, T>
impl<'a, A, T> !Sync for WsResponseBuilder<'a, A, T>
impl<'a, A, T> Unpin for WsResponseBuilder<'a, A, T> where
T: Unpin,
impl<'a, A, T> !UnwindSafe for WsResponseBuilder<'a, A, T>
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
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