lavalink_rs/player_context/
mod.rsmod context;
mod inner;
use crate::model::*;
use std::collections::VecDeque;
pub use context::PlayerContext;
pub use context::QueueRef;
pub(crate) use inner::PlayerContextInner;
#[derive(PartialEq, Debug, Clone, Default)]
#[cfg_attr(feature = "python", pyo3::pyclass)]
pub struct TrackInQueue {
pub track: track::TrackData,
pub start_time: Option<std::time::Duration>,
pub end_time: Option<std::time::Duration>,
pub volume: Option<u16>,
pub filters: Option<player::Filters>,
}
pub(crate) enum PlayerMessage {
GetPlayer(oneshot::Sender<player::Player>),
UpdatePlayer(player::Player),
UpdatePlayerTrack(Option<track::TrackData>),
UpdatePlayerState(player::State),
QueueMessage(QueueMessage),
TrackFinished(bool),
StartTrack,
Close,
}
#[derive(Debug)]
pub enum QueueMessage {
GetQueue(oneshot::Sender<VecDeque<TrackInQueue>>),
GetTrack(usize, oneshot::Sender<Option<TrackInQueue>>),
GetCount(oneshot::Sender<usize>),
PushToBack(TrackInQueue),
PushToFront(TrackInQueue),
Insert(usize, TrackInQueue),
Remove(usize),
Clear,
Replace(VecDeque<TrackInQueue>),
Append(VecDeque<TrackInQueue>),
Swap(usize, TrackInQueue),
}
impl TrackInQueue {
fn into_update_player(self) -> http::UpdatePlayer {
http::UpdatePlayer {
track: Some(http::UpdatePlayerTrack {
encoded: self.track.encoded.into(),
user_data: self.track.user_data,
..Default::default()
}),
position: self.start_time.map(|x| x.as_millis() as u64),
end_time: self.end_time.map(|x| x.as_millis() as u64),
volume: self.volume,
filters: self.filters,
..Default::default()
}
}
}
impl From<track::TrackData> for TrackInQueue {
fn from(track: track::TrackData) -> Self {
Self {
track,
..Default::default()
}
}
}