use std::{fmt, pin::Pin};
use futures_core::Stream;
use futures_sink::Sink;
use super::{Bytes, TransportError};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WsFrame {
Text(String),
Binary(Bytes),
Ping(Bytes),
Pong(Bytes),
Close(Option<WsClose>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WsClose {
pub code: u16,
pub reason: String,
}
#[cfg(not(target_arch = "wasm32"))]
pub type WsReceiver = Pin<Box<dyn Stream<Item = Result<WsFrame, TransportError>> + Send + 'static>>;
#[cfg(target_arch = "wasm32")]
pub type WsReceiver = Pin<Box<dyn Stream<Item = Result<WsFrame, TransportError>> + 'static>>;
#[cfg(not(target_arch = "wasm32"))]
pub type WsSender = Pin<Box<dyn Sink<WsFrame, Error = TransportError> + Send + 'static>>;
#[cfg(target_arch = "wasm32")]
pub type WsSender = Pin<Box<dyn Sink<WsFrame, Error = TransportError> + 'static>>;
pub struct WebSocket {
pub incoming: WsReceiver,
pub outgoing: WsSender,
}
impl fmt::Debug for WebSocket {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("WebSocket { incoming: .., outgoing: .. }")
}
}