From a362a3e4ffde1e7ffb60ead12e4c19bf12a7f596 Mon Sep 17 00:00:00 2001 From: restitux Date: Tue, 21 May 2024 23:53:40 -0600 Subject: [PATCH] It works now part 2 --- Cargo.lock | 345 +++++++++++++++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 9 +- index.js | 2 +- src/lib.rs | 143 +++++++++++++++++++++- 4 files changed, 484 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4e65407..e8049e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,6 +47,17 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d301b3b94cb4b2f23d7917810addbbaff90738e0ca2be692bd027e70d7e0330c" +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener 2.5.3", + "futures-core", +] + [[package]] name = "async-channel" version = "2.3.1" @@ -59,6 +70,82 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "async-executor" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b10202063978b3351199d68f8b22c4e47e4b1b822f8d43fd862d5ea8c006b29a" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand 2.1.0", + "futures-lite 2.3.0", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" +dependencies = [ + "async-channel 2.3.1", + "async-executor", + "async-io 2.3.2", + "async-lock 3.3.0", + "blocking", + "futures-lite 2.3.0", + "once_cell", +] + +[[package]] +name = "async-io" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" +dependencies = [ + "async-lock 2.8.0", + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-lite 1.13.0", + "log", + "parking", + "polling 2.8.0", + "rustix 0.37.27", + "slab", + "socket2 0.4.10", + "waker-fn", +] + +[[package]] +name = "async-io" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcccb0f599cfa2f8ace422d3555572f47424da5648a4382a9dd0310ff8210884" +dependencies = [ + "async-lock 3.3.0", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite 2.3.0", + "parking", + "polling 3.7.0", + "rustix 0.38.34", + "slab", + "tracing", + "windows-sys 0.52.0", +] + +[[package]] +name = "async-lock" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" +dependencies = [ + "event-listener 2.5.3", +] + [[package]] name = "async-lock" version = "3.3.0" @@ -70,6 +157,32 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "async-std" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +dependencies = [ + "async-channel 1.9.0", + "async-global-executor", + "async-io 1.13.0", + "async-lock 2.8.0", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite 1.13.0", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + [[package]] name = "async-task" version = "4.7.1" @@ -87,6 +200,19 @@ dependencies = [ "syn", ] +[[package]] +name = "asynchronous-codec" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4057f2c32adbb2fc158e22fb38433c8e9bbf76b75a4732c7c0cbaf695fb65568" +dependencies = [ + "bytes", + "futures-sink", + "futures-util", + "memchr", + "pin-project-lite", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -150,11 +276,11 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "495f7104e962b7356f0aeb34247aca1fe7d2e783b346582db7f2904cb5717e88" dependencies = [ - "async-channel", - "async-lock", + "async-channel 2.3.1", + "async-lock 3.3.0", "async-task", "futures-io", - "futures-lite", + "futures-lite 2.3.0", "piper", ] @@ -747,6 +873,12 @@ dependencies = [ "serde", ] +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + [[package]] name = "event-listener" version = "4.0.3" @@ -789,6 +921,15 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + [[package]] name = "fastrand" version = "2.1.0" @@ -879,13 +1020,31 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "fastrand 1.9.0", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + [[package]] name = "futures-lite" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" dependencies = [ + "fastrand 2.1.0", "futures-core", + "futures-io", + "parking", "pin-project-lite", ] @@ -1098,6 +1257,8 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" dependencies = [ + "futures-channel", + "futures-core", "js-sys", "wasm-bindgen", ] @@ -1184,6 +1345,12 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + [[package]] name = "home" version = "0.5.9" @@ -1255,7 +1422,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.5.7", "tokio", "tower-service", "tracing", @@ -1310,6 +1477,15 @@ dependencies = [ "cfb", ] +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + [[package]] name = "internment" version = "0.7.5" @@ -1346,6 +1522,17 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae52f28f45ac2bc96edb7714de995cffc174a395fb0abf5bff453587c980d7b9" +[[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "ipnet" version = "2.9.0" @@ -1391,6 +1578,15 @@ dependencies = [ "semver", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1403,6 +1599,12 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "linux-raw-sys" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -1424,6 +1626,9 @@ name = "log" version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +dependencies = [ + "value-bag", +] [[package]] name = "longest-increasing-subsequence" @@ -1492,6 +1697,15 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "merge-io" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6408da8cd05fb36af088c02c0d99c3dc1ece8fd062bcf30897a420fddd296357" +dependencies = [ + "futures-io", +] + [[package]] name = "mime" version = "0.3.17" @@ -1518,18 +1732,39 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "mumble-protocol-2x" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6e4417cbe77af1cf604a6b5c729621a1e3a2ccdaa154c5a38c8b0a1d5a093b2" +dependencies = [ + "asynchronous-codec", + "byteorder", + "bytes", + "cfg-if", + "protobuf", + "protobuf-codegen-pure", +] + [[package]] name = "mumble-webtransport" version = "0.1.0" dependencies = [ + "async-std", + "asynchronous-codec", "dioxus", "dioxus-web", + "futures", "manganis", + "merge-io", + "mumble-protocol-2x", "once_cell", "serde-wasm-bindgen 0.6.5", "serde_json", + "tokio-util", "wasm-bindgen", "wasm-bindgen-futures", + "wasm-streams", "web-sys", ] @@ -1728,7 +1963,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "464db0c665917b13ebb5d453ccdec4add5658ee1adc7affc7677615356a8afaf" dependencies = [ "atomic-waker", - "fastrand", + "fastrand 2.1.0", "futures-io", ] @@ -1738,6 +1973,37 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "polling" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +dependencies = [ + "autocfg", + "bitflags 1.3.2", + "cfg-if", + "concurrent-queue", + "libc", + "log", + "pin-project-lite", + "windows-sys 0.48.0", +] + +[[package]] +name = "polling" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645493cf344456ef24219d02a768cf1fb92ddf8c92161679ae3d91b91a637be3" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi", + "pin-project-lite", + "rustix 0.38.34", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "prettyplease" version = "0.2.20" @@ -1757,6 +2023,31 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "protobuf" +version = "2.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" + +[[package]] +name = "protobuf-codegen" +version = "2.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "033460afb75cf755fcfc16dfaed20b86468082a2ea24e05ac35ab4a099a017d6" +dependencies = [ + "protobuf", +] + +[[package]] +name = "protobuf-codegen-pure" +version = "2.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a29399fc94bcd3eeaa951c715f7bea69409b2445356b00519740bcd6ddd865" +dependencies = [ + "protobuf", + "protobuf-codegen", +] + [[package]] name = "quote" version = "1.0.36" @@ -1836,6 +2127,20 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.37.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys 0.3.8", + "windows-sys 0.48.0", +] + [[package]] name = "rustix" version = "0.38.34" @@ -1845,7 +2150,7 @@ dependencies = [ "bitflags 2.5.0", "errno", "libc", - "linux-raw-sys", + "linux-raw-sys 0.4.14", "windows-sys 0.52.0", ] @@ -2133,6 +2438,16 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "socket2" version = "0.5.7" @@ -2197,8 +2512,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", - "fastrand", - "rustix", + "fastrand 2.1.0", + "rustix 0.38.34", "windows-sys 0.52.0", ] @@ -2264,7 +2579,7 @@ dependencies = [ "libc", "mio", "pin-project-lite", - "socket2", + "socket2 0.5.7", "windows-sys 0.48.0", ] @@ -2457,6 +2772,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" + [[package]] name = "vcpkg" version = "0.2.15" @@ -2469,6 +2790,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "waker-fn" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" + [[package]] name = "want" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index 5b4008a..75e5268 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,15 @@ dioxus = { version = "0.5.1", features = ["web"] } dioxus-web = "0.5.1" manganis = "0.2.2" once_cell = "1.19.0" +asynchronous-codec = "0.6.2" +futures = "0.3.30" +merge-io = "0.3.0" +mumble-protocol = { version = "0.5.0", package = "mumble-protocol-2x", default-features = false, features = ["asynchronous-codec"]} serde-wasm-bindgen = "0.6.5" serde_json = "1.0.117" +tokio-util = { version = "0.7.11", features = ["codec"]} wasm-bindgen = "0.2.92" wasm-bindgen-futures = "0.4.42" -web-sys = { version = "0.3.69", features = ["WebTransport", "console", "WebTransportOptions", "WebTransportBidirectionalStream", "WebTransportSendStream", "WebTransportReceiveStream"] } +wasm-streams = "0.4.0" +web-sys = { version = "0.3.69", features = ["WebTransport", "console", "WebTransportOptions", "WebTransportBidirectionalStream", "WebTransportSendStream", "WebTransportReceiveStream", "Navigator"] } +async-std = "1.12.0" diff --git a/index.js b/index.js index 7177c09..0ecccc8 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ async function main() { await init() let x = await entrypoint() console.log(x); - await new Promise(r => setTimeout(r, 200000)); + await new Promise(r => setTimeout(r, 200000000)); //let y = { // algorithm: "sha-256", // value: new Uint8Array([14, 162, 111, 176, 34, 113, 218, 69, 177, 18, 13, 180, 232, 204, 49, 65, 161, 195, 36, 238, 23, 95, 174, 190, 24, 216, 105, 89, 236, 147, 206, 139]), diff --git a/src/lib.rs b/src/lib.rs index 75af3fe..c74f5c3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,17 +1,36 @@ pub mod app; +use std::cell::RefCell; +use std::pin::pin; +use std::rc::Rc; +use std::time::Duration; use app::STATE; + +use asynchronous_codec::Decoder; +use asynchronous_codec::Encoder; +use futures::AsyncRead; +use futures::AsyncWrite; +use futures::Sink; +use futures::SinkExt; +use futures::Stream; +use futures::StreamExt; +use mumble_protocol::control::ControlCodec; +use mumble_protocol::control::ControlPacket; +use mumble_protocol::control::{msgs, ClientControlCodec}; +use mumble_protocol::Clientbound; +use mumble_protocol::Serverbound; use wasm_bindgen::prelude::*; use web_sys::console; use web_sys::WebTransport; use web_sys::WebTransportOptions; +use wasm_bindgen_futures::spawn_local as spawn; + #[wasm_bindgen] extern "C" { pub fn alert(s: &str); } -//pub async fn entrypoint() -> std::result::Result<(), wasm_bindgen::JsValue> { pub async fn network_entrypoint() { console::log_1(&"Rust via WASM!".into()); @@ -30,7 +49,8 @@ pub async fn network_entrypoint() { ) .unwrap(); - web_sys::js_sys::Reflect::set(&object, &JsValue::from_str("value"), &hash).unwrap(); + //web_sys::js_sys::Reflect::set(&object, &JsValue::from_str("value"), &hash).unwrap(); + web_sys::js_sys::Reflect::set(&object, &"value".into(), &hash).unwrap(); let array = web_sys::js_sys::Array::new(); array.push(&object); @@ -78,11 +98,126 @@ pub async fn network_entrypoint() { } }; + let wasm_stream_readable = wasm_streams::ReadableStream::from_raw(stream.readable().into()); + let wasm_stream_writable = wasm_streams::WritableStream::from_raw(stream.writable().into()); + + let read_codec = ClientControlCodec::new(); + let write_codec = ClientControlCodec::new(); + + let mut reader = asynchronous_codec::FramedRead::new(wasm_stream_readable.into_async_read(), read_codec); + let mut writer = asynchronous_codec::FramedWrite::new(wasm_stream_writable.into_async_write(), write_codec); + + let (send_chan, writer_recv_chan) = async_std::channel::unbounded(); + + spawn(async move { + while let Ok(msg) = writer_recv_chan.recv().await { + if let Err(e) = writer.send(msg).await { + console::log_1(&e.to_string().into()); + break; + } + } + }); + + // Get version packet + let version = reader.next().await.unwrap().unwrap(); + console::log_1(&"Got version packet".into()); + console::log_1(&format!("{:#?}", version).into()); + + // Send version packet + let mut msg = msgs::Version::new(); + msg.set_version(0x000010204); + msg.set_release(format!("{} {}", "mumbleweb2", "6.9.0")); + //msg.set_os("Chrome".to_string()); + send_chan.send(msg.into()).await.unwrap(); + console::log_1(&"Sent version packet".into()); + + // Send authenticate packet + let mut msg = msgs::Authenticate::new(); + msg.set_username("mumbleweb2".to_string()); + send_chan.send(msg.into()).await.unwrap(); + console::log_1(&"Sent authenticate packet".into()); + + { + let send_chan = send_chan.clone(); + spawn(async move { + loop { + console::log_1(&"Sending ping".into()); + if let Err(e) = send_chan.send(msgs::Ping::new().into()).await { + console::log_1(&e.to_string().into()); + break; + } + + async_std::task::sleep(Duration::from_millis(3000)).await; + } + }); + } + + loop { + match reader.next().await { + Some(Ok(msg)) => { + console::log_1(&format!("{:#?}", msg).into()); + }, + None => { + break; + }, + Some(Err(e)) => { + console::log_1(&e.to_string().into()); + break; + }, + } + } + +//async fn handle_send( +// mut writer: Rc>>>, +// send_queue: Queue, +//) { +// loop { +// let msg = send_queue.get(); +// client.send(msg).await.unwrap(); +// } +//} + +//async fn handle_ping( +//) { +// //pin!(client); +// loop { +// let ping = msgs::Ping::new(); +// client.borrow_mut().send(ping.into()).await.unwrap(); +// console::log_1(&"Sent ping packet".into()); +// +// async_std::task::sleep(Duration::from_millis(3000)).await; +// } +//} + + //let queue_write, queue_read = Queue::new(); + + //spawn(handle_send(writer, queue_write)); + //spawn(handle_ping(queue_read)); + + //loop { + // let msg = reader.next().await.unwrap().unwrap(); + // console::log_1(&format!("{:#?}", msg).into()); + //} + + // let result: Option<(Version, u32)> = loop { + // match client.next().await { + // None => break None, + // Some(packet) => { + // let packet = packet.unwrap(); + + // } + // } + // }; + + //let client = ClientControlCodec::new().framed(stream); + //let client = ClientControlCodec::new().framed(stream); + //let reader = stream.readable(); //let writer = stream.writable(); - console::log_1(&"Created bidirectional stream!".into()); - console::log_1(&stream.into()); + //console::log_1(&stream.into()); //*STATE.status.write() = "Ready!".into(); + + //return stream.into(); }