Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wasm): support ws #1481

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
cache-on-failure: true
- name: cargo hack
run: |
cargo hack build --workspace --target wasm32-unknown-unknown \
cargo hack build --workspace --ignore-unknown-features --features ws --target wasm32-unknown-unknown \
--exclude alloy-contract \
--exclude alloy-network \
--exclude alloy-node-bindings \
Expand Down
1 change: 0 additions & 1 deletion crates/transport-ws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ rustls = { workspace = true, features = ["ring"] }
# WASM only
[target.'cfg(target_arch = "wasm32")'.dependencies]
ws_stream_wasm = "0.7.4"
wasmtimer.workspace = true
7 changes: 7 additions & 0 deletions crates/transport-ws/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ pub struct WsConnect {
pub url: String,
}

impl WsConnect {
/// Creates a new websocket connection configuration.
pub fn new<S: Into<String>>(url: S) -> Self {
Self { url: url.into() }
}
}

impl PubSubConnect for WsConnect {
fn is_local(&self) -> bool {
alloy_transport::utils::guess_local_url(&self.url)
Expand Down
4 changes: 4 additions & 0 deletions crates/transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ thiserror.workspace = true
tower.workspace = true
url.workspace = true
tracing.workspace = true

# non-WASM only
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { workspace = true, features = ["rt", "time"] }

# WASM only
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = { version = "0.4", optional = true }
wasmtimer.workspace = true
Expand Down