diff --git a/ext/websocket/01_websocket.js b/ext/websocket/01_websocket.js index 200bb86590..e11a2c55f3 100644 --- a/ext/websocket/01_websocket.js +++ b/ext/websocket/01_websocket.js @@ -417,6 +417,7 @@ }); break; } + case "closed": case "close": { this[_readyState] = CLOSED; diff --git a/ext/websocket/02_websocketstream.js b/ext/websocket/02_websocketstream.js index 82f3063333..246ddb1e3b 100644 --- a/ext/websocket/02_websocketstream.js +++ b/ext/websocket/02_websocketstream.js @@ -261,6 +261,7 @@ }); break; } + case "closed": case "close": { if (this[_closing]) { this[_closed].resolve(value); diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs index 32ac4cf038..d469b5aaf1 100644 --- a/ext/websocket/lib.rs +++ b/ext/websocket/lib.rs @@ -82,7 +82,8 @@ pub struct WsStreamResource { impl WsStreamResource { async fn send(self: &Rc, message: Message) -> Result<(), AnyError> { - match self.stream { + use tokio_tungstenite::tungstenite::Error; + let res = match self.stream { WebSocketStreamType::Client { .. } => { let mut tx = RcRef::map(self, |r| match &r.stream { WebSocketStreamType::Client { tx, .. } => tx, @@ -90,7 +91,7 @@ impl WsStreamResource { }) .borrow_mut() .await; - tx.send(message).await?; + tx.send(message).await } WebSocketStreamType::Server { .. } => { let mut tx = RcRef::map(self, |r| match &r.stream { @@ -99,11 +100,15 @@ impl WsStreamResource { }) .borrow_mut() .await; - tx.send(message).await?; + tx.send(message).await } - } + }; - Ok(()) + match res { + Ok(()) => Ok(()), + Err(Error::ConnectionClosed) => Ok(()), + Err(err) => Err(err.into()), + } } async fn next_message(