Closed messense closed 6 months ago
I've added support for this in 0.6.1
.
The provide_websocket
function now returns a web_sys::WebSocket
.
ServerSignalWebSocket
is also public now, so you can use use_context::<ServerSignalWebSocket>().unwrap().ws()
to get access to the websocket.
let websocket = provide_websocket("ws://localhost:3000/ws").unwrap();
if let Some(websocket) = websocket {
websocket.set_onclose(Some(&js_sys::Function::new_no_args("alert('closed')")));
}
For example I'd like to call
set_onclose
on it so I can display a warning on page when the websocket disconnects.