Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
sazid committed Jan 21, 2021
1 parent f9da241 commit 8a3e7a9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions actix-web-actors/src/ws.rs
Expand Up @@ -30,6 +30,24 @@ use futures_core::Stream;
use tokio::sync::oneshot::Sender;

/// Builder for Websocket Session response.
///
/// # Examples
///
/// Create a Websocket session response with default configs.
/// ```rust
/// WsResponseBuilder::new(WsActor, &req, stream).start()
/// ```
///
/// Create a Websocket session with a specific max frame size,
/// a [`Codec`] or protocols.
/// ```rust
/// const MAX_FRAME_SIZE: usize = 10_000; // in bytes.
/// ws::WsResponseBuilder::new(WsActor, &req, stream)
/// .codec(Codec::new()) // optional
/// .protocols(&["A", "B"]) // optional
/// .frame_size(MAX_FRAME_SIZE) // optional
/// .start()
/// ```
pub struct WsResponseBuilder<'a, A, T>
where
A: Actor<Context = WebsocketContext<A>>
Expand Down Expand Up @@ -61,16 +79,20 @@ where
}
}

/// Set the protocols for the session.
pub fn protocols(mut self, protocols: &'a [&'a str]) -> Self {
self.protocols = Some(protocols);
self
}

/// Set the max frame size for each message.
pub fn frame_size(mut self, frame_size: usize) -> Self {
self.frame_size = Some(frame_size);
self
}

/// Set the [`Codec`] for the session. If [`Self::frame_size`]
/// is also set, the given [`Codec`]'s max size will be overriden.
pub fn codec(mut self, codec: Codec) -> Self {
self.codec = Some(codec);
self
Expand Down

0 comments on commit 8a3e7a9

Please sign in to comment.