-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: main
Are you sure you want to change the base?
Conversation
@@ -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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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() | ||
} | ||
|
There was a problem hiding this comment.
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<'_> { |
There was a problem hiding this comment.
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
Description
Adds support for wasm32-unknown-uknown target.
I made use of
#[cfg(target_arch = "wasm32")]
. Some features not support in wasm32: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 messageResolves #84
How Has This Been Tested?
There is a wasm_websocket_demo which runs successfully
Due Diligence