pub struct Connection(/* private fields */);Expand description
A websocket connection.
Implementations§
Source§impl Connection
impl Connection
Sourcepub async fn connect<'a>(auth: impl Into<Authentication<'a>>) -> Result<Self>
pub async fn connect<'a>(auth: impl Into<Authentication<'a>>) -> Result<Self>
Connects to the websocket, and authenticates, returning the socket or an error if it failed.
Sourcepub async fn connect_with_url<'a>(
auth: impl Into<Authentication<'a>>,
url: &str,
) -> Result<Self>
pub async fn connect_with_url<'a>( auth: impl Into<Authentication<'a>>, url: &str, ) -> Result<Self>
Connects to the websocket on the specified url, and authenticates, returning the socket or an error if it failed.
Use if connecting to a self-hosted instance of revolt; otherwise use Self::connect.
Sourcepub async fn run<C, H>(self, ctx: C, handler: H) -> Resultwhere
C: Context,
H: RawEventHandler<Context = C>,
pub async fn run<C, H>(self, ctx: C, handler: H) -> Resultwhere
C: Context,
H: RawEventHandler<Context = C>,
Runs the “main loop”, listening for events on the websocket and spawning tokio tasks to handle them, cloning the context, and giving it a messanger.
If you intend to implement this yourself, you can
use Connection::get_event to get events and Connection::hb
to “heartbeat”(send a ping message to the server so it doesn’t
close the socket).
Sourcepub async fn hb(&mut self) -> Result
pub async fn hb(&mut self) -> Result
Sends a ping message to the server, so it doesn’t close the connection.
Sourcepub async fn get_event(&mut self) -> Result<ServerToClientEvent>
pub async fn get_event(&mut self) -> Result<ServerToClientEvent>
Gets the next event from the server.
Sourcepub async fn start_typing(&mut self, channel: ChannelId) -> Result
pub async fn start_typing(&mut self, channel: ChannelId) -> Result
Sends a ClientToServerEvent::BeginTyping event, for the given channel.
Has a timeout of ~3 seconds, so if you want it to display “… is typing” for longer than that, you have to call it again.
Sourcepub async fn stop_typing(&mut self, channel: ChannelId) -> Result
pub async fn stop_typing(&mut self, channel: ChannelId) -> Result
Sends a ClientToServerEvent::EndTyping event, for the given channel.