diff --git a/src-tauri/src/jellyfin/client.rs b/src-tauri/src/jellyfin/client.rs index 7786e69..b8f1dd0 100644 --- a/src-tauri/src/jellyfin/client.rs +++ b/src-tauri/src/jellyfin/client.rs @@ -302,24 +302,42 @@ impl JellyfinClient { self.post(&format!("/Sessions/{}/Playing/Seek", session_id), &request).await } + /// Send a full GeneralCommand to a remote session. + /// Uses POST /Sessions/{id}/Command with a body containing Name and Arguments. + /// This is required for commands that need arguments (e.g. SetVolume). + async fn send_general_command( + &self, + session_id: &str, + command_name: &str, + arguments: Option, + ) -> Result<(), String> { + let mut payload = serde_json::json!({ + "Name": command_name, + }); + + if let Some(args) = arguments { + payload["Arguments"] = args; + } + + log::info!("[JellyfinClient] Sending GeneralCommand '{}' to session {} with payload: {}", + command_name, session_id, serde_json::to_string(&payload).unwrap_or_default()); + + self.post( + &format!("/Sessions/{}/Command", session_id), + &payload + ).await + } + /// Set volume on a remote session pub async fn session_set_volume( &self, session_id: String, volume: i32, ) -> Result<(), String> { - let payload = serde_json::json!({ - "Arguments": { - "Volume": volume.to_string() - } - }); - - log::info!("[JellyfinClient] Setting volume on session {} to {} with payload: {}", - session_id, volume, serde_json::to_string(&payload).unwrap_or_default()); - - self.post( - &format!("/Sessions/{}/Command/SetVolume", session_id), - &payload + self.send_general_command( + &session_id, + "SetVolume", + Some(serde_json::json!({ "Volume": volume.to_string() })), ).await } @@ -330,9 +348,10 @@ impl JellyfinClient { ) -> Result<(), String> { log::info!("[JellyfinClient] Toggling mute on session {}", session_id); - self.post( - &format!("/Sessions/{}/Command/ToggleMute", session_id), - &serde_json::json!({}) + self.send_general_command( + &session_id, + "ToggleMute", + None, ).await }