Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
thedtvn committed Dec 18, 2023
1 parent 384c6ce commit c46a542
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ struct InnerReceiver {

#[derive(Clone)]
struct CallbackR {
ws: UnboundedSender<Message>,
pub accumulator: DashMap<u32, Snippet>
ws: UnboundedSender<Message>
}


Expand All @@ -203,8 +202,7 @@ impl CallbackR {
// You can manage state here, such as a buffer of audio packet bytes so
// you can later store them in intervals.
Self {
ws,
accumulator: DashMap::default()
ws
}
}
}
Expand Down Expand Up @@ -238,7 +236,6 @@ impl EventHandler for CallbackR {
Ctx::VoiceTick(packet) => {
for i in &packet.speaking {
let data_out = &i.1.decoded_voice;
let old_data: Option<dashmap::mapref::one::RefMut<'_, u32, Snippet>> = self.accumulator.get_mut(i.0);
if data_out.is_some() {
let data = data_out.as_ref().unwrap();
let mut data_u8 = Vec::new();
Expand All @@ -255,6 +252,12 @@ impl EventHandler for CallbackR {
}
}
},
Ctx::DriverConnect(data) => {
let jdata = json!({
"t": "CONNECTED"
});
let _ = self.ws.send(Message::Text(jdata.to_string()));
},
_ => {
// We won't be registering this struct for any more event classes.
unimplemented!()
Expand Down Expand Up @@ -290,10 +293,11 @@ async fn accept_connection(ws_stream: WebSocket) {
});
let mut controler: Option<TrackHandle> = None;
let evt_receiver = CallbackR::new(send_s.clone());

dr.add_global_event(Event::Track(songbird::TrackEvent::End), Callback {ws: send_s.clone(), data: jdata.clone(), data_err: jdata_err.clone()});
dr.add_global_event(CoreEvent::SpeakingStateUpdate.into(), evt_receiver.clone());
dr.add_global_event(CoreEvent::VoiceTick.into(), evt_receiver.clone());
dr.add_global_event(CoreEvent::ClientDisconnect.into(), evt_receiver.clone());
dr.add_global_event(CoreEvent::DriverConnect.into(), evt_receiver.clone());
let mut volume = 100;
while let Some(msg) = read.next().await {
if msg.is_err() {
Expand Down

0 comments on commit c46a542

Please sign in to comment.