reconnecting_websocket/state.rs
1use gloo::net::websocket::State as GlooState;
2
3/// The state of the websocket.
4///
5/// Copied from [`State`] to add [`PartialEq`]
6///
7/// See [`WebSocket.readyState` on MDN](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState)
8/// to learn more.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum State {
11 /// The connection has not yet been established.
12 Connecting,
13 /// The WebSocket connection is established and communication is possible.
14 Open,
15 /// The connection is going through the closing handshake, or the close() method has been
16 /// invoked.
17 Closing,
18 /// The connection has been closed or could not be opened.
19 Closed,
20}
21
22impl From<GlooState> for State {
23 fn from(value: GlooState) -> Self {
24 use GlooState::*;
25 match value {
26 Connecting => State::Connecting,
27 Open => State::Open,
28 Closing => State::Closing,
29 Closed => State::Closed,
30 }
31 }
32}