pub fn run() -> Result<(), JsValue> {
    // Initialize debugging for when/if something goes wrong.
    console_error_panic_hook::set_once();

    // Get the document's container to render the virtual dom component.
    let window = web_sys::window().expect("error: web_sys::window");
    let document = window.document().expect("error: window.document");
    let div_for_virtual_dom = document
        .get_element_by_id("div_for_virtual_dom")
        .expect("No #div_for_virtual_dom");

    let mut rng = SmallRng::from_entropy();
    //gen_range is lower inclusive, upper exclusive 26 + 1
    let my_ws_uid: usize = rng.gen_range(1, 9999);

    //find out URL
    let location_href = window.location().href().expect("href not known");

    //websocket connection
    let ws = setup_ws_connection(location_href.as_str());
    //I don't know why is needed to clone the websocket connection
    let ws_c = ws.clone();

    // Construct a new `RootRenderingComponent`.
    //I added ws_c so that I can send messages on websocket

    let root_rendering_component = RootRenderingComponent::new(ws_c, my_ws_uid);

    // Mount the component to the `<div id="div_for_virtual_dom">`.
    let vdom = dodrio::Vdom::new(&div_for_virtual_dom, root_rendering_component);

    //websocket on receive message callback
    setup_ws_msg_recv(&ws, &vdom);

    // Run the component forever. Forget to drop the memory.
    vdom.forget();

    Ok(())
}
///wasm_bindgen runs this functions at start
wasm_bindgen runs this functions at start
wasm_bindgen runs this functions at start
pub fn run() -> Result<(), JsValue> {
    // Initialize debugging for when/if something goes wrong.
    console_error_panic_hook::set_once();
    // Get the document's container to render the virtual dom component.
    let window = web_sys::window().expect("error: web_sys::window");
    let document = window.document().expect("error: window.document");
    let div_for_virtual_dom = document
        .get_element_by_id("div_for_virtual_dom")
        .expect("No #div_for_virtual_dom");
    let mut rng = SmallRng::from_entropy();
    //gen_range is lower inclusive, upper exclusive 26 + 1
    let my_ws_uid: usize = rng.gen_range(1, 9999);
    //find out URL
    let location_href = window.location().href().expect("href not known");
    //websocket connection
    let ws = setup_ws_connection(location_href.as_str());
    //I don't know why is needed to clone the websocket connection
    let ws_c = ws.clone();
    // Construct a new `RootRenderingComponent`.
    //I added ws_c so that I can send messages on websocket
    let root_rendering_component = RootRenderingComponent::new(ws_c, my_ws_uid);
    // Mount the component to the `<div id="div_for_virtual_dom">`.
    let vdom = dodrio::Vdom::new(&div_for_virtual_dom, root_rendering_component);
    //websocket on receive message callback
    setup_ws_msg_recv(&ws, &vdom);
    // Run the component forever. Forget to drop the memory.
    vdom.forget();
    Ok(())
}
pub fn run ( ) -> Result < ( ) , JsValue > { // Initialize debugging for when/if something goes wrong. console_error_panic_hook :: set_once ( ) ; // Get the document's container to render the virtual dom component. let window = web_sys :: window ( ) . expect ( " " ) ; let document = window . document ( ) . expect ( " " ) ; let div_for_virtual_dom = document . get_element_by_id ( " " ) . expect ( " " ) ; let mut rng = SmallRng :: from_entropy ( ) ; //gen_range is lower inclusive, upper exclusive 26 + 1 let my_ws_uid : usize = rng . gen_range ( 1 , 9999 ) ; //find out URL let location_href = window . location ( ) . href ( ) . expect ( " " ) ; //websocket connection let ws = setup_ws_connection ( location_href . as_str ( ) ) ; //I don't know why is needed to clone the websocket connection let ws_c = ws . clone ( ) ; // Construct a new `RootRenderingComponent`. //I added ws_c so that I can send messages on websocket let root_rendering_component = RootRenderingComponent :: new ( ws_c , my_ws_uid ) ; // Mount the component to the `<div id="div_for_virtual_dom">`. let vdom = dodrio :: Vdom :: new ( & div_for_virtual_dom , root_rendering_component ) ; //websocket on receive message callback setup_ws_msg_recv ( & ws , & vdom ) ; // Run the component forever. Forget to drop the memory. vdom . forget ( ) ; Ok ( ( ) ) }
wasm_bindgen runs this functions at start
wasm_bindgen runs this functions at start