-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This unblocks us from updating `tunstenite` to fix RUSTSEC-2023-0065 This also removes a few dependencies, thanks to: * rerun-io/ewebsock#24 I've tested that it still works. ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3729) (if applicable) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/3729) - [Docs preview](https://rerun.io/preview/1378634af462a895fea11b44a2dd08e766ed7176/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/1378634af462a895fea11b44a2dd08e766ed7176/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://ref.rerun.io/dev/bench/) - [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
- Loading branch information
Showing
8 changed files
with
50 additions
and
100 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,51 @@ | ||
use std::ops::ControlFlow; | ||
|
||
use ewebsock::{WsEvent, WsMessage, WsSender}; | ||
use ewebsock::{WsEvent, WsMessage}; | ||
|
||
// TODO(jleibs): use thiserror | ||
pub type Result<T> = anyhow::Result<T>; | ||
|
||
/// Represents a connection to the server. | ||
/// Disconnects on drop. | ||
#[must_use] | ||
pub struct Connection(WsSender); | ||
|
||
impl Connection { | ||
/// Connect viewer to server | ||
pub fn viewer_to_server( | ||
url: String, | ||
on_binary_msg: impl Fn(Vec<u8>) -> ControlFlow<()> + Send + 'static, | ||
) -> Result<Self> { | ||
re_log::info!("Connecting to {url:?}…"); | ||
let sender = ewebsock::ws_connect( | ||
url, | ||
Box::new(move |event: WsEvent| match event { | ||
WsEvent::Opened => { | ||
re_log::info!("Connection established"); | ||
/// Connect viewer to server | ||
pub fn viewer_to_server( | ||
url: String, | ||
on_binary_msg: impl Fn(Vec<u8>) -> ControlFlow<()> + Send + 'static, | ||
) -> Result<()> { | ||
re_log::info!("Connecting to {url:?}…"); | ||
ewebsock::ws_receive( | ||
url, | ||
Box::new(move |event: WsEvent| match event { | ||
WsEvent::Opened => { | ||
re_log::info!("Connection established"); | ||
ControlFlow::Continue(()) | ||
} | ||
WsEvent::Message(message) => match message { | ||
WsMessage::Binary(binary) => on_binary_msg(binary), | ||
WsMessage::Text(text) => { | ||
re_log::warn!("Unexpected text message: {text:?}"); | ||
ControlFlow::Continue(()) | ||
} | ||
WsMessage::Unknown(text) => { | ||
re_log::warn!("Unknown message: {text:?}"); | ||
ControlFlow::Continue(()) | ||
} | ||
WsEvent::Message(message) => match message { | ||
WsMessage::Binary(binary) => on_binary_msg(binary), | ||
WsMessage::Text(text) => { | ||
re_log::warn!("Unexpected text message: {text:?}"); | ||
ControlFlow::Continue(()) | ||
} | ||
WsMessage::Unknown(text) => { | ||
re_log::warn!("Unknown message: {text:?}"); | ||
ControlFlow::Continue(()) | ||
} | ||
WsMessage::Ping(_data) => { | ||
re_log::warn!("Unexpected PING"); | ||
ControlFlow::Continue(()) | ||
} | ||
WsMessage::Pong(_data) => { | ||
re_log::warn!("Unexpected PONG"); | ||
ControlFlow::Continue(()) | ||
} | ||
}, | ||
WsEvent::Error(error) => { | ||
re_log::error!("Connection error: {error}"); | ||
ControlFlow::Break(()) | ||
WsMessage::Ping(_data) => { | ||
re_log::warn!("Unexpected PING"); | ||
ControlFlow::Continue(()) | ||
} | ||
WsEvent::Closed => { | ||
re_log::info!("Connection to server closed."); | ||
ControlFlow::Break(()) | ||
WsMessage::Pong(_data) => { | ||
re_log::warn!("Unexpected PONG"); | ||
ControlFlow::Continue(()) | ||
} | ||
}), | ||
) | ||
.map_err(|err| anyhow::format_err!("ewebsock: {err}"))?; | ||
|
||
Ok(Self(sender)) | ||
} | ||
}, | ||
WsEvent::Error(error) => { | ||
re_log::error!("Connection error: {error}"); | ||
ControlFlow::Break(()) | ||
} | ||
WsEvent::Closed => { | ||
re_log::info!("Connection to server closed."); | ||
ControlFlow::Break(()) | ||
} | ||
}), | ||
) | ||
.map_err(|err| anyhow::format_err!("ewebsock: {err}")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters