Skip to content

Commit

Permalink
Add close message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienDeepgram committed Jul 25, 2024
1 parent f251852 commit 7d837e9
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/listen/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,28 @@ where
match read.next().await {
None => break,
Some(Ok(msg)) => {
if let Message::Text(txt) = msg {
let resp = serde_json::from_str(&txt).map_err(DeepgramError::from);
if let Err(e) = tx.send(resp).await {
eprintln!("Failed to send message: {:?}", e);
// TODO Handle the error appropriately, e.g., log it, retry, or break the loop
match msg {
Message::Text(txt) => {
let resp = serde_json::from_str(&txt).map_err(DeepgramError::from);
if let Err(e) = tx.send(resp).await {
eprintln!("Failed to send message: {:?}", e);
// Handle the error appropriately, e.g., log it, retry, or break the loop
break;
}
}
Message::Close(close_frame) => {
println!("Received close frame: {:?}", close_frame);
// Send a close frame back to acknowledge the close request
let mut write = write.lock().await;
if let Err(e) = write.send(Message::Close(None)).await {
eprintln!("Failed to send close frame: {:?}", e);
}
break;
}
_ => {}
}
}
Some(e) => {
Some(Err(e)) => {
let _ = dbg!(e);
break;
}
Expand Down

0 comments on commit 7d837e9

Please sign in to comment.