From d83d33ce9a41f49b2ffb90138899c5a3834764db Mon Sep 17 00:00:00 2001 From: ch stands for cheng Date: Tue, 13 Jul 2021 22:05:42 +0800 Subject: [PATCH] Fix webrtc_datachannel example panic in Safari (#2616) * Fix webrtc_datachannel exapmle panic in Safari * Run cargo fmt --- examples/webrtc_datachannel/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/webrtc_datachannel/src/lib.rs b/examples/webrtc_datachannel/src/lib.rs index 5f7242ccba0..89f747849f5 100644 --- a/examples/webrtc_datachannel/src/lib.rs +++ b/examples/webrtc_datachannel/src/lib.rs @@ -74,7 +74,12 @@ pub async fn start() -> Result<(), JsValue> { dc2.set_onmessage(Some(onmessage_callback.as_ref().unchecked_ref())); onmessage_callback.forget(); - dc2.send_with_str("Ping from pc2.dc!").unwrap(); + let dc2_clone = dc2.clone(); + let onopen_callback = Closure::wrap(Box::new(move || { + dc2_clone.send_with_str("Ping from pc2.dc!").unwrap(); + }) as Box); + dc2.set_onopen(Some(onopen_callback.as_ref().unchecked_ref())); + onopen_callback.forget(); }) as Box); pc2.set_ondatachannel(Some(ondatachannel_callback.as_ref().unchecked_ref())); ondatachannel_callback.forget();