wasm_ws/
lib.rs

1// Copyright (c) 2019-2022 Naja Melan
2// Copyright (c) 2023-2024 Yuki Kishimoto
3// Distributed under the MIT software license
4
5#![forbid(unsafe_code)]
6
7use pharos::SharedPharos;
8use wasm_bindgen_futures::spawn_local;
9
10mod error;
11mod event;
12mod message;
13mod meta;
14mod state;
15mod stream;
16mod stream_io;
17
18pub use self::error::WsErr;
19pub use self::event::{CloseEvent, WsEvent};
20pub use self::message::WsMessage;
21pub use self::meta::WsMeta as WebSocket;
22pub use self::state::WsState;
23pub use self::stream::WsStream;
24pub use self::stream_io::WsStreamIo;
25
26/// Helper function to reduce code bloat
27pub(crate) fn notify(pharos: SharedPharos<WsEvent>, evt: WsEvent) {
28    let notify = async move {
29        pharos
30            .notify(evt)
31            .await
32            .map_err(|e| unreachable!("{:?}", e))
33            .unwrap(); // only happens if we closed it.
34    };
35
36    spawn_local(notify);
37}