Skip to content

Commit 842d9e3

Browse files
authored
Fix: Invoke onClose handler upon receiving a notification (#666)
1 parent fd88278 commit 842d9e3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

webrtc/src/data_channel/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,18 @@ impl RTCDataChannel {
316316
let mut buffer = vec![0u8; DATA_CHANNEL_BUFFER_SIZE as usize];
317317
loop {
318318
let (n, is_string) = tokio::select! {
319-
_ = notify_rx.notified() => break,
319+
_ = notify_rx.notified() => {
320+
ready_state.store(RTCDataChannelState::Closed as u8, Ordering::SeqCst);
321+
let on_close_handler2 = Arc::clone(&on_close_handler);
322+
tokio::spawn(async move {
323+
if let Some(handler) = &*on_close_handler2.load() {
324+
let mut f = handler.lock().await;
325+
f().await;
326+
}
327+
});
328+
329+
break;
330+
}
320331
result = data_channel.read_data_channel(&mut buffer) => {
321332
match result{
322333
// EOF (`data_channel` was either closed or the underlying stream got

0 commit comments

Comments
 (0)