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

Change ErrorEvent to Event. Closes #7 #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wasm-sockets"
version = "1.0.0"
version = "1.0.1"
authors = ["scratchyone <[email protected]>"]
edition = "2018"
license = "MIT"
Expand Down Expand Up @@ -34,7 +34,7 @@ web-sys = { version = "0.3.22", features = [
"BinaryType",
"Blob",
"CloseEvent",
"ErrorEvent",
"Event",
"FileReader",
"MessageEvent",
"ProgressEvent",
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ use thiserror::Error;
use wasm_bindgen::prelude::*;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::JsCast;
use web_sys::{CloseEvent, ErrorEvent, MessageEvent, WebSocket};
use web_sys::{CloseEvent, Event, MessageEvent, WebSocket};

#[cfg(not(target_arch = "wasm32"))]
compile_error!("wasm-sockets can only compile to WASM targets");
Expand Down Expand Up @@ -239,7 +239,7 @@ pub struct EventClient {
/// The current connection status
pub status: Rc<RefCell<ConnectionStatus>>,
/// The function bound to the on_error event
pub on_error: Rc<RefCell<Option<Box<dyn Fn(ErrorEvent)>>>>,
pub on_error: Rc<RefCell<Option<Box<dyn Fn(Event)>>>>,
/// The function bound to the on_connection event
pub on_connection: Rc<RefCell<Option<Box<dyn Fn(&EventClient)>>>>,
/// The function bound to the on_message event
Expand Down Expand Up @@ -270,15 +270,15 @@ impl EventClient {
let status = Rc::new(RefCell::new(ConnectionStatus::Connecting));
let ref_status = status.clone();

let on_error: Rc<RefCell<Option<Box<dyn Fn(ErrorEvent)>>>> = Rc::new(RefCell::new(None));
let on_error: Rc<RefCell<Option<Box<dyn Fn(Event)>>>> = Rc::new(RefCell::new(None));
let on_error_ref = on_error.clone();

let onerror_callback = Closure::wrap(Box::new(move |e: ErrorEvent| {
let onerror_callback = Closure::wrap(Box::new(move |e: Event| {
*ref_status.borrow_mut() = ConnectionStatus::Error;
if let Some(f) = &*on_error_ref.borrow() {
f.as_ref()(e);
}
}) as Box<dyn Fn(ErrorEvent)>);
}) as Box<dyn Fn(Event)>);
ws.set_onerror(Some(onerror_callback.as_ref().unchecked_ref()));
onerror_callback.forget();

Expand Down Expand Up @@ -394,7 +394,7 @@ impl EventClient {
/// panic!("Error: {:#?}", error);
/// })));
/// ```
pub fn set_on_error(&mut self, f: Option<Box<dyn Fn(ErrorEvent)>>) {
pub fn set_on_error(&mut self, f: Option<Box<dyn Fn(Event)>>) {
*self.on_error.borrow_mut() = f;
}
/// Set an on_connection event handler.
Expand Down