Skip to content

Commit

Permalink
Fix webrtc_datachannel example panic in Safari (#2616)
Browse files Browse the repository at this point in the history
* Fix webrtc_datachannel exapmle panic in Safari

* Run cargo fmt
  • Loading branch information
matthew-ch authored Jul 13, 2021
1 parent a8245bd commit d83d33c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/webrtc_datachannel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn FnMut()>);
dc2.set_onopen(Some(onopen_callback.as_ref().unchecked_ref()));
onopen_callback.forget();
}) as Box<dyn FnMut(RtcDataChannelEvent)>);
pc2.set_ondatachannel(Some(ondatachannel_callback.as_ref().unchecked_ref()));
ondatachannel_callback.forget();
Expand Down

0 comments on commit d83d33c

Please sign in to comment.