Cleanup
This commit is contained in:
+20
-101
@@ -1,39 +1,27 @@
|
||||
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 wasm_bindgen_futures::JsFuture;
|
||||
use web_sys::console;
|
||||
use web_sys::js_sys::Uint8Array;
|
||||
use web_sys::AudioData;
|
||||
use web_sys::AudioContext;
|
||||
use web_sys::AudioContextOptions;
|
||||
use web_sys::MediaStream;
|
||||
use web_sys::AudioData;
|
||||
use web_sys::AudioDecoder;
|
||||
use web_sys::AudioDecoderConfig;
|
||||
use web_sys::AudioDecoderInit;
|
||||
use web_sys::CodecState;
|
||||
use web_sys::EncodedAudioChunk;
|
||||
use web_sys::EncodedAudioChunkInit;
|
||||
use web_sys::EncodedAudioChunkType;
|
||||
use web_sys::MediaStream;
|
||||
use web_sys::MediaStreamTrackGenerator;
|
||||
use web_sys::MediaStreamTrackGeneratorInit;
|
||||
use web_sys::WebTransport;
|
||||
@@ -41,13 +29,9 @@ use web_sys::WebTransportOptions;
|
||||
|
||||
use wasm_bindgen_futures::spawn_local as spawn;
|
||||
|
||||
//#[wasm_bindgen]
|
||||
//extern "C" {
|
||||
//}
|
||||
|
||||
fn configure_audio_context(
|
||||
audio_stream_generator: &MediaStreamTrackGenerator,
|
||||
) -> AudioContext {
|
||||
// Borrowed from
|
||||
// https://github.com/security-union/videocall-rs/blob/main/videocall-client/src/decode/config.rs#L6
|
||||
fn configure_audio_context(audio_stream_generator: &MediaStreamTrackGenerator) -> AudioContext {
|
||||
let js_tracks = web_sys::js_sys::Array::new();
|
||||
js_tracks.push(audio_stream_generator);
|
||||
let media_stream = MediaStream::new_with_tracks(&js_tracks).unwrap();
|
||||
@@ -67,6 +51,9 @@ fn configure_audio_context(
|
||||
}
|
||||
|
||||
pub async fn network_entrypoint() {
|
||||
// This sleep is to allow the user to interact with the window so the MediaStream
|
||||
// can be created. This works around Chrome's autoplay policy rules. This will
|
||||
// eventually be unnecessary when we have a proper GUI.
|
||||
async_std::task::sleep(Duration::from_millis(3000)).await;
|
||||
|
||||
console::log_1(&"Rust via WASM!".into());
|
||||
@@ -177,6 +164,7 @@ pub async fn network_entrypoint() {
|
||||
send_chan.send(msg.into()).await.unwrap();
|
||||
console::log_1(&"Sent authenticate packet".into());
|
||||
|
||||
// Spawn worker to send pings
|
||||
{
|
||||
let send_chan = send_chan.clone();
|
||||
spawn(async move {
|
||||
@@ -192,10 +180,12 @@ pub async fn network_entrypoint() {
|
||||
});
|
||||
}
|
||||
|
||||
// Create callback functions for AudioDecoder
|
||||
let error = Closure::wrap(Box::new(move |e: JsValue| {
|
||||
console::log_1(&e);
|
||||
}) as Box<dyn FnMut(JsValue)>);
|
||||
|
||||
// Create MediaStreams to playback decoded audio
|
||||
let audio_stream_generator =
|
||||
MediaStreamTrackGenerator::new(&MediaStreamTrackGeneratorInit::new("audio")).unwrap();
|
||||
// The audio context is used to reproduce audio.
|
||||
@@ -226,17 +216,13 @@ pub async fn network_entrypoint() {
|
||||
let audio_decoder = AudioDecoder::new(&AudioDecoderInit::new(
|
||||
error.as_ref().unchecked_ref(),
|
||||
output.as_ref().unchecked_ref(),
|
||||
)).unwrap();
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
console::log_1(&"Created Audio Decoder".into());
|
||||
console::log_1(&audio_decoder);
|
||||
|
||||
audio_decoder.configure(&AudioDecoderConfig::new(
|
||||
"opus",
|
||||
1,
|
||||
48000,
|
||||
));
|
||||
|
||||
audio_decoder.configure(&AudioDecoderConfig::new("opus", 1, 48000));
|
||||
|
||||
loop {
|
||||
match reader.next().await {
|
||||
@@ -259,28 +245,15 @@ pub async fn network_entrypoint() {
|
||||
) = payload
|
||||
{
|
||||
let js_audio_payload = Uint8Array::from(audio_payload.as_ref());
|
||||
audio_decoder.decode(&EncodedAudioChunk::new(
|
||||
&EncodedAudioChunkInit::new(
|
||||
audio_decoder.decode(
|
||||
&EncodedAudioChunk::new(&EncodedAudioChunkInit::new(
|
||||
&js_audio_payload.into(),
|
||||
0.0,
|
||||
EncodedAudioChunkType::Key,
|
||||
),
|
||||
).unwrap());
|
||||
))
|
||||
.unwrap(),
|
||||
);
|
||||
console::log_1(&"Oueued audio chunk for decoding".into());
|
||||
|
||||
|
||||
//let mut encoded_audio_chunk_init =
|
||||
// web_sys::EncodedAudioChunkInit::new(
|
||||
// &js_audio_payload.into(),
|
||||
// 0.0,
|
||||
// web_sys::EncodedAudioChunkType::Delta,
|
||||
// );
|
||||
////encoded_audio_chunk_init.duration(1.0);
|
||||
//let encoded_audio_chunk =
|
||||
// web_sys::EncodedAudioChunk::new(&encoded_audio_chunk_init)
|
||||
// .unwrap();
|
||||
//console::log_1(&encoded_audio_chunk);
|
||||
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
@@ -305,58 +278,4 @@ pub async fn network_entrypoint() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//async fn handle_send(
|
||||
// mut writer: Rc<RefCell<asynchronous_codec::FramedWrite<impl AsyncRead + AsyncWrite + Unpin, ControlCodec<Serverbound, Clientbound>>>>,
|
||||
// send_queue: Queue<mumble_protocol::Serverbound>,
|
||||
//) {
|
||||
// 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(&stream.into());
|
||||
|
||||
//*STATE.status.write() = "Ready!".into();
|
||||
|
||||
//return stream.into();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user