Skip to content

Commit d83d33c

Browse files
authored
Fix webrtc_datachannel example panic in Safari (#2616)
* Fix webrtc_datachannel exapmle panic in Safari * Run cargo fmt
1 parent a8245bd commit d83d33c

File tree

1 file changed

+6
-1
lines changed
  • examples/webrtc_datachannel/src

1 file changed

+6
-1
lines changed

examples/webrtc_datachannel/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ pub async fn start() -> Result<(), JsValue> {
7474
dc2.set_onmessage(Some(onmessage_callback.as_ref().unchecked_ref()));
7575
onmessage_callback.forget();
7676

77-
dc2.send_with_str("Ping from pc2.dc!").unwrap();
77+
let dc2_clone = dc2.clone();
78+
let onopen_callback = Closure::wrap(Box::new(move || {
79+
dc2_clone.send_with_str("Ping from pc2.dc!").unwrap();
80+
}) as Box<dyn FnMut()>);
81+
dc2.set_onopen(Some(onopen_callback.as_ref().unchecked_ref()));
82+
onopen_callback.forget();
7883
}) as Box<dyn FnMut(RtcDataChannelEvent)>);
7984
pc2.set_ondatachannel(Some(ondatachannel_callback.as_ref().unchecked_ref()));
8085
ondatachannel_callback.forget();

0 commit comments

Comments
 (0)