|
1 | 1 | use std::sync::Arc; |
2 | 2 |
|
3 | 3 | use async_graphql::*; |
| 4 | +use futures_util::{lock::Mutex, Stream}; |
4 | 5 | use music_player_playback::player::PlayerCommand; |
5 | | -use music_player_tracklist::Tracklist; |
6 | | -use tokio::sync::{mpsc::UnboundedSender, Mutex}; |
| 6 | +use music_player_tracklist::{PlaybackState, Tracklist}; |
| 7 | +use tokio::sync::mpsc::UnboundedSender; |
7 | 8 |
|
8 | | -use super::objects::current_track::CurrentlyPlayingSong; |
| 9 | +use crate::simple_broker::SimpleBroker; |
| 10 | + |
| 11 | +use super::objects::{ |
| 12 | + current_track::CurrentlyPlayingSong, player_state::PlayerState, track::Track, |
| 13 | +}; |
9 | 14 |
|
10 | 15 | #[derive(Default)] |
11 | 16 | pub struct PlaybackQuery; |
@@ -50,7 +55,7 @@ impl PlaybackQuery { |
50 | 55 | }) |
51 | 56 | } |
52 | 57 |
|
53 | | - async fn get_playback_state(&self, ctx: &Context<'_>) -> bool { |
| 58 | + async fn get_player_state(&self, ctx: &Context<'_>) -> PlayerState { |
54 | 59 | let _tracklist = ctx.data::<Arc<Mutex<Tracklist>>>().unwrap(); |
55 | 60 | todo!() |
56 | 61 | } |
@@ -133,3 +138,33 @@ impl PlaybackMutation { |
133 | 138 | Ok(true) |
134 | 139 | } |
135 | 140 | } |
| 141 | + |
| 142 | +#[derive(Clone)] |
| 143 | +pub struct PositionMilliseconds { |
| 144 | + pub position_ms: u32, |
| 145 | +} |
| 146 | + |
| 147 | +#[Object] |
| 148 | +impl PositionMilliseconds { |
| 149 | + async fn position_ms(&self) -> u32 { |
| 150 | + self.position_ms |
| 151 | + } |
| 152 | +} |
| 153 | + |
| 154 | +#[derive(Default)] |
| 155 | +pub struct PlaybackSubscription; |
| 156 | + |
| 157 | +#[Subscription] |
| 158 | +impl PlaybackSubscription { |
| 159 | + async fn player_state(&self) -> impl Stream<Item = PlayerState> { |
| 160 | + SimpleBroker::<PlayerState>::subscribe() |
| 161 | + } |
| 162 | + |
| 163 | + async fn currently_playing_song(&self) -> impl Stream<Item = Track> { |
| 164 | + SimpleBroker::<Track>::subscribe() |
| 165 | + } |
| 166 | + |
| 167 | + async fn track_time_position(&self) -> impl Stream<Item = PositionMilliseconds> { |
| 168 | + SimpleBroker::<PositionMilliseconds>::subscribe() |
| 169 | + } |
| 170 | +} |
0 commit comments