Files
zed/crates/cloud_api_client/src/websocket.rs
T
Lukas WirthandGaauwe Rombouts 875042b698 cloud_api_client: Implement Wasm support (#61328)
Release Notes:

- N/A or Added/Fixed/Improved ...

---------

Co-authored-by: Gaauwe Rombouts <mail@grombouts.nl>
2026-07-21 13:20:31 +00:00

25 lines
748 B
Rust

use std::pin::Pin;
use anyhow::Result;
use cloud_api_types::websocket_protocol::MessageToClient;
use futures::Stream;
use futures::channel::mpsc::UnboundedSender;
use yawc::frame::{Frame, OpCode};
#[cfg(not(target_family = "wasm"))]
mod native;
#[cfg(target_family = "wasm")]
mod web;
pub type MessageStream = Pin<Box<dyn Stream<Item = Result<MessageToClient>>>>;
fn forward_frame(frame: Frame, message_tx: &UnboundedSender<Result<MessageToClient>>) -> bool {
match frame.opcode() {
OpCode::Binary => message_tx
.unbounded_send(MessageToClient::deserialize(frame.payload()))
.is_ok(),
OpCode::Close => false,
OpCode::Continuation | OpCode::Text | OpCode::Ping | OpCode::Pong => true,
}
}