-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Give tungstenite types distinct names * reorganize files * Better feature locking, add wasm.rs * Implement wasm Backend * add wasm-bindgen-test * Build & Test for wasm * Add macos safari wasm test * Add wasm32 target * Add wasm.rs test * Move wasm-pack installation before test execution * Fix build on wasm32 * Fix examples depending on tokio::time * fix clippy warn * Add example wasm bindgen test * Add wasm-bindgen to Cargo.toml * Add wasm test configuration * Install wasm-bindgen-cli on linux * Add wasm-bindgen-cli to macos * Correct "vers" to "version" * Attempt to locate correct geckodriver * Run wasm tests first * maybe this will fix ci :clueless: * Move wasm-bindgen-cli install * Add cargo-binstall installation script for wasm-bindgen-cli * Try using only one browser * remove geckodriver * Move all wasm related tests to macos * Rename macOS test step for clarity * Try out combined coverage report * try different strategy to skip coverage on forks * Revert "try different strategy to skip coverage on forks" This reverts commit fb46ab8. * Revert "Try out combined coverage report" This reverts commit d34a813.
- Loading branch information
Showing
14 changed files
with
190 additions
and
35 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[target.wasm32-unknown-unknown] | ||
runner = 'wasm-bindgen-test-runner' |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] | ||
pub mod tungstenite; | ||
#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] | ||
pub use tungstenite::*; | ||
|
||
#[cfg(all(target_arch = "wasm32", feature = "client"))] | ||
pub mod wasm; | ||
#[cfg(all(target_arch = "wasm32", feature = "client"))] | ||
pub use wasm::*; | ||
|
||
#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] | ||
pub type Sink = tungstenite::TungsteniteSink; | ||
#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] | ||
pub type Stream = tungstenite::TungsteniteStream; | ||
#[cfg(all(not(target_arch = "wasm32"), feature = "client"))] | ||
pub type WebSocketBackend = tungstenite::TungsteniteBackend; | ||
|
||
#[cfg(all(target_arch = "wasm32", feature = "client"))] | ||
pub type Sink = wasm::WasmSink; | ||
#[cfg(all(target_arch = "wasm32", feature = "client"))] | ||
pub type Stream = wasm::WasmStream; | ||
#[cfg(all(target_arch = "wasm32", feature = "client"))] | ||
pub type WebSocketBackend = wasm::WasmBackend; |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use futures_util::{ | ||
stream::{SplitSink, SplitStream}, | ||
StreamExt, | ||
}; | ||
|
||
use ws_stream_wasm::*; | ||
|
||
use crate::errors::GatewayError; | ||
use crate::gateway::GatewayMessage; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct WasmBackend; | ||
|
||
// These could be made into inherent associated types when that's stabilized | ||
pub type WasmSink = SplitSink<WsStream, WsMessage>; | ||
pub type WasmStream = SplitStream<WsStream>; | ||
|
||
impl WasmBackend { | ||
pub async fn connect( | ||
websocket_url: &str, | ||
) -> Result<(WasmSink, WasmStream), crate::errors::GatewayError> { | ||
let (_, websocket_stream) = match WsMeta::connect(websocket_url, None).await { | ||
Ok(stream) => Ok(stream), | ||
Err(e) => Err(GatewayError::CannotConnect { | ||
error: e.to_string(), | ||
}), | ||
}?; | ||
|
||
Ok(websocket_stream.split()) | ||
} | ||
} | ||
|
||
impl From<GatewayMessage> for WsMessage { | ||
fn from(message: GatewayMessage) -> Self { | ||
Self::Text(message.0) | ||
} | ||
} | ||
|
||
impl From<WsMessage> for GatewayMessage { | ||
fn from(value: WsMessage) -> Self { | ||
match value { | ||
WsMessage::Text(text) => Self(text), | ||
WsMessage::Binary(bin) => { | ||
let mut text = String::new(); | ||
let _ = bin.iter().map(|v| text.push_str(&v.to_string())); | ||
Self(text) | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.