|
1 | | -use futures_lite::{Stream, StreamExt}; |
2 | | -use futures_sink::Sink; |
3 | | -use tungstenite::{self, protocol::CloseFrame}; |
| 1 | +#[cfg(feature = "tungstenite-0.23")] |
| 2 | +#[cfg_attr(docsrs, doc(cfg(feature = "tungstenite-0.23")))] |
| 3 | +mod tungstenite_0_23; |
4 | 4 |
|
5 | | -use crate::{Error, Message, sink_ext::SinkExt}; |
| 5 | +#[cfg(feature = "tungstenite-0.24")] |
| 6 | +#[cfg_attr(docsrs, doc(cfg(feature = "tungstenite-0.24")))] |
| 7 | +mod tungstenite_0_24; |
6 | 8 |
|
7 | | -#[cfg_attr(docsrs, doc(cfg(feature = "tungstenite")))] |
8 | | -impl<T> crate::client::Connection for T |
9 | | -where |
10 | | - T: Stream<Item = Result<tungstenite::Message, tungstenite::Error>> |
11 | | - + Sink<tungstenite::Message> |
12 | | - + Send |
13 | | - + Sync |
14 | | - + Unpin, |
15 | | - <T as Sink<tungstenite::Message>>::Error: std::fmt::Display, |
16 | | -{ |
17 | | - async fn receive(&mut self) -> Option<Message> { |
18 | | - loop { |
19 | | - match self.next().await? { |
20 | | - Ok(tungstenite::Message::Text(text)) => { |
21 | | - return Some(crate::client::Message::Text(text)); |
22 | | - } |
23 | | - Ok(tungstenite::Message::Ping(_)) => return Some(crate::client::Message::Ping), |
24 | | - Ok(tungstenite::Message::Pong(_)) => return Some(crate::client::Message::Pong), |
25 | | - Ok(tungstenite::Message::Close(frame)) => { |
26 | | - return Some(crate::client::Message::Close { |
27 | | - code: frame.as_ref().map(|frame| frame.code.into()), |
28 | | - reason: frame.map(|frame| frame.reason.to_string()), |
29 | | - }); |
30 | | - } |
31 | | - Ok(tungstenite::Message::Frame(_) | tungstenite::Message::Binary(_)) => continue, |
32 | | - Err(error) => { |
33 | | - #[allow(unused)] |
34 | | - let error = error; |
35 | | - crate::logging::warning!("error receiving message: {error:?}"); |
36 | | - return None; |
37 | | - } |
38 | | - } |
39 | | - } |
40 | | - } |
| 9 | +#[cfg(feature = "tungstenite-0.25")] |
| 10 | +#[cfg_attr(docsrs, doc(cfg(feature = "tungstenite-0.25")))] |
| 11 | +mod tungstenite_0_25; |
41 | 12 |
|
42 | | - async fn send(&mut self, message: crate::client::Message) -> Result<(), Error> { |
43 | | - <Self as SinkExt<tungstenite::Message>>::send( |
44 | | - self, |
45 | | - match message { |
46 | | - crate::client::Message::Text(text) => tungstenite::Message::Text(text), |
47 | | - crate::client::Message::Close { code, reason } => { |
48 | | - tungstenite::Message::Close(code.zip(reason).map(|(code, reason)| CloseFrame { |
49 | | - code: code.into(), |
50 | | - reason: reason.into(), |
51 | | - })) |
52 | | - } |
53 | | - crate::client::Message::Ping => tungstenite::Message::Ping(vec![]), |
54 | | - crate::client::Message::Pong => tungstenite::Message::Pong(vec![]), |
55 | | - }, |
56 | | - ) |
57 | | - .await |
58 | | - .map_err(|error| Error::Send(error.to_string())) |
59 | | - } |
60 | | -} |
| 13 | +#[cfg(feature = "tungstenite-0.26")] |
| 14 | +#[cfg_attr(docsrs, doc(cfg(feature = "tungstenite-0.26")))] |
| 15 | +mod tungstenite_0_26; |
| 16 | + |
| 17 | +#[cfg(feature = "tungstenite-0.27")] |
| 18 | +#[cfg_attr(docsrs, doc(cfg(feature = "tungstenite-0.27")))] |
| 19 | +mod tungstenite_0_27; |
| 20 | + |
| 21 | +#[cfg(feature = "tungstenite-0.28")] |
| 22 | +#[cfg_attr(docsrs, doc(cfg(feature = "tungstenite-0.28")))] |
| 23 | +mod tungstenite_0_28; |
0 commit comments