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

Add Wasm build target #85

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Add Wasm build target #85

wants to merge 14 commits into from

Conversation

dougEfresh
Copy link

@dougEfresh dougEfresh commented Dec 3, 2024

Description

Adds support for wasm32-unknown-uknown target.

I made use of #[cfg(target_arch = "wasm32")] . Some features not support in wasm32:

  • TcpSocket
  • HttpRequest with headers

For example, since low-level sockets are not available, the is_terminated function always returns true. Functionality, this doesn't break much. An error will be thrown when the client publishes a message

#[cfg(target_arch = "wasm32")]
fn is_terminated(&self) -> bool {
      false
}

Resolves #84

How Has This Been Tested?

There is a wasm_websocket_demo which runs successfully

Due Diligence

  • Breaking change
  • [X ] Requires a documentation update
  • Requires a e2e/integration test update

@@ -104,6 +104,7 @@ impl ConnectionOptions {
Ok(url)
}

#[cfg(not(target_arch = "wasm32"))]
fn as_ws_request(&self) -> Result<HttpRequest<()>, RequestBuildError> {
use {
crate::websocket::WebsocketClientError,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tokio_tungstenite::tungstenite::client::IntoClientRequest, is not available in wasm target

inbound::*,
outbound::*,
stream::*,
tokio_tungstenite::tungstenite::protocol::CloseFrame,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CloseFrame from tokio_tungstenite has different structure when wasm

wasm_bindgen_futures::spawn_local(fut);

#[cfg(not(target_arch = "wasm32"))]
tokio::spawn(fut);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No support for tokio::spawn in wasm

#[cfg(target_arch = "wasm32")]
pub async fn create_stream(request: HttpRequest<()>) -> Result<ClientStream, WebsocketClientError> {
let url = format!("{}", request.uri());
let socket = connect_async(url)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connect function in wasm only support URL

fn is_terminated(&self) -> bool {
self.socket.is_terminated()
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No access to TcpSocket, so cannot determine if connected

@@ -67,7 +67,7 @@ impl Default for JwtHeader<'_> {
}
}

impl<'a> JwtHeader<'a> {
impl JwtHeader<'_> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy warned me about this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for target wasm32-unknown-unknown
1 participant