mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-12 22:10:01 -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
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -354,7 +354,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "epoxy-client"
|
name = "epoxy-client"
|
||||||
version = "1.3.0"
|
version = "1.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-compression",
|
"async-compression",
|
||||||
"async_io_stream",
|
"async_io_stream",
|
||||||
|
@ -1849,7 +1849,7 @@ checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wisp-mux"
|
name = "wisp-mux"
|
||||||
version = "1.2.0"
|
version = "1.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async_io_stream",
|
"async_io_stream",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "epoxy-client"
|
name = "epoxy-client"
|
||||||
version = "1.3.0"
|
version = "1.4.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "LGPL-3.0-only"
|
license = "LGPL-3.0-only"
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,7 @@ onmessage = async (msg) => {
|
||||||
);
|
);
|
||||||
while (true) {
|
while (true) {
|
||||||
log("sending `data`");
|
log("sending `data`");
|
||||||
await ws.send("data");
|
await ws.send_text("data");
|
||||||
await (new Promise((res, _) => setTimeout(res, 50)));
|
await (new Promise((res, _) => setTimeout(res, 50)));
|
||||||
}
|
}
|
||||||
} else if (should_tls_test) {
|
} else if (should_tls_test) {
|
||||||
|
@ -181,14 +181,14 @@ onmessage = async (msg) => {
|
||||||
() => log("closed"),
|
() => log("closed"),
|
||||||
err => console.error(err),
|
err => console.error(err),
|
||||||
msg => { console.log(msg); log(decoder.decode(msg)) },
|
msg => { console.log(msg); log(decoder.decode(msg)) },
|
||||||
"alicesworld.tech:443",
|
"google.com:443",
|
||||||
);
|
);
|
||||||
await ws.send("GET / HTTP 1.1\r\nHost: alicesworld.tech\r\nConnection: close\r\n\r\n");
|
await ws.send((new TextEncoder()).encode("GET / HTTP 1.1\r\nHost: google.com\r\nConnection: close\r\n\r\n"));
|
||||||
await (new Promise((res, _) => setTimeout(res, 500)));
|
await (new Promise((res, _) => setTimeout(res, 500)));
|
||||||
await ws.close();
|
await ws.close();
|
||||||
} else if (should_udp_test) {
|
} else if (should_udp_test) {
|
||||||
let decoder = new TextDecoder();
|
let decoder = new TextDecoder();
|
||||||
// nc -ulp 5000
|
// tokio example: `cargo r --example echo-udp -- 127.0.0.1:5000`
|
||||||
let ws = await epoxy_client.connect_udp(
|
let ws = await epoxy_client.connect_udp(
|
||||||
() => log("opened"),
|
() => log("opened"),
|
||||||
() => log("closed"),
|
() => log("closed"),
|
||||||
|
@ -196,8 +196,11 @@ onmessage = async (msg) => {
|
||||||
msg => { console.log(msg); log(decoder.decode(msg)) },
|
msg => { console.log(msg); log(decoder.decode(msg)) },
|
||||||
"127.0.0.1:5000",
|
"127.0.0.1:5000",
|
||||||
);
|
);
|
||||||
await (new Promise((res, _) => setTimeout(res, 5000)));
|
while (true) {
|
||||||
await ws.close();
|
log("sending `data`");
|
||||||
|
await ws.send((new TextEncoder()).encode("data"));
|
||||||
|
await (new Promise((res, _) => setTimeout(res, 50)));
|
||||||
|
}
|
||||||
} else if (should_reconnect_test) {
|
} else if (should_reconnect_test) {
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@mercuryworkshop/epoxy-tls",
|
"name": "@mercuryworkshop/epoxy-tls",
|
||||||
"version": "1.3.0",
|
"version": "1.4.0",
|
||||||
"description": "A wasm library for using raw encrypted tls/ssl/https/websocket streams on the browser",
|
"description": "A wasm library for using raw encrypted tls/ssl/https/websocket streams on the browser",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "./build.sh"
|
"build": "./build.sh"
|
||||||
|
|
|
@ -105,7 +105,8 @@ impl EpxWebSocket {
|
||||||
let _ = onclose.call0(&JsValue::null());
|
let _ = onclose.call0(&JsValue::null());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_ => panic!("unknown opcode {:?}", frame.opcode),
|
// ping/pong/continue
|
||||||
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -126,7 +127,7 @@ impl EpxWebSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[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 onerr = self.onerror.clone();
|
||||||
let ret = self
|
let ret = self
|
||||||
.tx
|
.tx
|
||||||
|
@ -135,7 +136,24 @@ impl EpxWebSocket {
|
||||||
.write_frame(Frame::text(Payload::Owned(payload.as_bytes().to_vec())))
|
.write_frame(Frame::text(Payload::Owned(payload.as_bytes().to_vec())))
|
||||||
.await;
|
.await;
|
||||||
if let Err(ret) = ret {
|
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())
|
Err(ret.into())
|
||||||
} else {
|
} else {
|
||||||
Ok(ret?)
|
Ok(ret?)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "wisp-mux"
|
name = "wisp-mux"
|
||||||
version = "1.2.0"
|
version = "1.2.1"
|
||||||
license = "LGPL-3.0-only"
|
license = "LGPL-3.0-only"
|
||||||
description = "A library for easily creating Wisp servers and clients."
|
description = "A library for easily creating Wisp servers and clients."
|
||||||
homepage = "https://github.com/MercuryWorkshop/epoxy-tls/tree/multiplexed/wisp"
|
homepage = "https://github.com/MercuryWorkshop/epoxy-tls/tree/multiplexed/wisp"
|
||||||
|
|
|
@ -182,7 +182,12 @@ impl<W: ws::WebSocketWrite + Send + 'static> ServerMuxInner<W> {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let packet: Packet = rx.wisp_read_frame(&self.tx).await?.try_into()?;
|
let frame = rx.wisp_read_frame(&self.tx).await?;
|
||||||
|
if frame.opcode == ws::OpCode::Close {
|
||||||
|
break Ok(());
|
||||||
|
}
|
||||||
|
let packet = Packet::try_from(frame)?;
|
||||||
|
|
||||||
use PacketType::*;
|
use PacketType::*;
|
||||||
match packet.packet_type {
|
match packet.packet_type {
|
||||||
Connect(inner_packet) => {
|
Connect(inner_packet) => {
|
||||||
|
@ -368,7 +373,11 @@ impl<W: ws::WebSocketWrite + Send> ClientMuxInner<W> {
|
||||||
{
|
{
|
||||||
loop {
|
loop {
|
||||||
let frame = rx.wisp_read_frame(&self.tx).await?;
|
let frame = rx.wisp_read_frame(&self.tx).await?;
|
||||||
if let Ok(packet) = Packet::try_from(frame) {
|
if frame.opcode == ws::OpCode::Close {
|
||||||
|
break Ok(());
|
||||||
|
}
|
||||||
|
let packet = Packet::try_from(frame)?;
|
||||||
|
|
||||||
use PacketType::*;
|
use PacketType::*;
|
||||||
match packet.packet_type {
|
match packet.packet_type {
|
||||||
Connect(_) => unreachable!(),
|
Connect(_) => unreachable!(),
|
||||||
|
@ -394,7 +403,6 @@ impl<W: ws::WebSocketWrite + Send> ClientMuxInner<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Client side multiplexor.
|
/// Client side multiplexor.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue