Skip to content

Commit 270f408

Browse files
authored
Merge pull request #12 from http-rs/make-sending-ping-possible
expose sending Messages directly
2 parents 20a8b99 + abe4211 commit 270f408

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/websocket_connection.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ pub struct WebSocketConnection(
2020
);
2121

2222
impl WebSocketConnection {
23-
/// Sends a string message to the connected websocket client
24-
pub async fn send_string(&self, s: String) -> async_tungstenite::tungstenite::Result<()> {
25-
self.0.lock().send(Message::Text(s)).await?;
26-
Ok(())
23+
/// Sends a string message to the connected websocket client. This is equivalent to `.send(Message::Text(string))`
24+
pub async fn send_string(&self, string: String) -> async_tungstenite::tungstenite::Result<()> {
25+
self.send(Message::Text(string)).await
2726
}
2827

29-
/// Sends a binary message to the connected websocket client
28+
/// Sends a binary message to the connected websocket client. This is equivalent to `.send(Message::Binary(bytes))`
3029
pub async fn send_bytes(&self, bytes: Vec<u8>) -> async_tungstenite::tungstenite::Result<()> {
31-
self.0.lock().send(Message::Binary(bytes)).await?;
30+
self.send(Message::Binary(bytes)).await
31+
}
32+
33+
/// Sends a [`Message`] to the client
34+
pub async fn send(&self, message: Message) -> async_tungstenite::tungstenite::Result<()> {
35+
self.0.lock().send(message).await?;
3236
Ok(())
3337
}
3438

0 commit comments

Comments
 (0)