mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-13 06:20:02 -04:00
fix udp and tls tests, add send_bytes to ws
This commit is contained in:
parent
55d40aa32d
commit
19d9544e83
7 changed files with 64 additions and 35 deletions
|
@ -105,7 +105,8 @@ impl EpxWebSocket {
|
|||
let _ = onclose.call0(&JsValue::null());
|
||||
break;
|
||||
}
|
||||
_ => panic!("unknown opcode {:?}", frame.opcode),
|
||||
// ping/pong/continue
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -126,7 +127,7 @@ impl EpxWebSocket {
|
|||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub async fn send(&self, payload: String) -> Result<(), JsError> {
|
||||
pub async fn send_text(&self, payload: String) -> Result<(), JsError> {
|
||||
let onerr = self.onerror.clone();
|
||||
let ret = self
|
||||
.tx
|
||||
|
@ -135,7 +136,24 @@ impl EpxWebSocket {
|
|||
.write_frame(Frame::text(Payload::Owned(payload.as_bytes().to_vec())))
|
||||
.await;
|
||||
if let Err(ret) = ret {
|
||||
let _ = onerr.call1(&JsValue::null(), &jval!(format!("{}", ret)));
|
||||
let _ = onerr.call1(&JsValue::null(), &jval!(ret.to_string()));
|
||||
Err(ret.into())
|
||||
} else {
|
||||
Ok(ret?)
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub async fn send_binary(&self, payload: Uint8Array) -> Result<(), JsError> {
|
||||
let onerr = self.onerror.clone();
|
||||
let ret = self
|
||||
.tx
|
||||
.lock()
|
||||
.await
|
||||
.write_frame(Frame::binary(Payload::Owned(payload.to_vec())))
|
||||
.await;
|
||||
if let Err(ret) = ret {
|
||||
let _ = onerr.call1(&JsValue::null(), &jval!(ret.to_string()));
|
||||
Err(ret.into())
|
||||
} else {
|
||||
Ok(ret?)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue