Add support for fusing/unfusing JellyLMS zones into synchronized
multi-room groups, addressed by MAC (derived from the `lms-{mac}` device id).
This commit is contained in:
@@ -51,6 +51,22 @@ pub async fn playback_mode_transfer_to_remote(
|
||||
manager.0.transfer_to_remote(session_id, position).await
|
||||
}
|
||||
|
||||
/// Set the transferring flag on the playback mode manager.
|
||||
///
|
||||
/// Used by the frontend remote->local flow to mark the whole two-step sequence
|
||||
/// as a transfer, so `player_play_tracks` starts LOCAL playback instead of
|
||||
/// casting back to the remote session it's leaving. Always pair `true` with a
|
||||
/// later `false` (including on error) so the flag can't stick.
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn playback_mode_set_transferring(
|
||||
manager: State<'_, PlaybackModeManagerWrapper>,
|
||||
transferring: bool,
|
||||
) -> Result<(), String> {
|
||||
manager.0.set_transferring(transferring);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Transfer playback from remote session back to local device
|
||||
///
|
||||
/// Parameters:
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
use tauri::State;
|
||||
|
||||
use super::PlayerStateWrapper;
|
||||
use crate::jellyfin::client::LmsSyncGroup;
|
||||
|
||||
/// Play items on a remote Jellyfin session (casting)
|
||||
#[tauri::command]
|
||||
@@ -129,3 +130,92 @@ pub async fn remote_session_toggle_mute(
|
||||
Err("Jellyfin client not configured".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
// --- JellyLMS multi-room sync groups (fuse / unfuse LMS zones) --------------
|
||||
//
|
||||
// The frontend addresses LMS players by MAC address, which it derives from a
|
||||
// session's device id (`lms-{mac}`). These commands forward to the JellyLMS
|
||||
// plugin REST API via the configured JellyfinClient.
|
||||
|
||||
/// List current LMS sync groups.
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn lms_get_sync_groups(
|
||||
player: State<'_, PlayerStateWrapper>,
|
||||
) -> Result<Vec<LmsSyncGroup>, String> {
|
||||
let client_opt = {
|
||||
let controller = player.0.lock().await;
|
||||
controller.jellyfin_client().lock().map_err(|e| e.to_string())?.clone()
|
||||
};
|
||||
|
||||
if let Some(client) = client_opt {
|
||||
client.lms_get_sync_groups().await
|
||||
} else {
|
||||
Err("Jellyfin client not configured".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
/// Fuse LMS zones into a sync group. `master_mac` keeps playing and the
|
||||
/// `slave_macs` zones join it in sync.
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn lms_create_sync_group(
|
||||
player: State<'_, PlayerStateWrapper>,
|
||||
master_mac: String,
|
||||
slave_macs: Vec<String>,
|
||||
) -> Result<(), String> {
|
||||
log::info!("[LmsSync] Fusing zones: master={}, slaves={:?}", master_mac, slave_macs);
|
||||
|
||||
let client_opt = {
|
||||
let controller = player.0.lock().await;
|
||||
controller.jellyfin_client().lock().map_err(|e| e.to_string())?.clone()
|
||||
};
|
||||
|
||||
if let Some(client) = client_opt {
|
||||
client.lms_create_sync_group(&master_mac, slave_macs).await
|
||||
} else {
|
||||
Err("Jellyfin client not configured".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove a single LMS zone from its sync group (decouple one player).
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn lms_unsync_player(
|
||||
player: State<'_, PlayerStateWrapper>,
|
||||
mac: String,
|
||||
) -> Result<(), String> {
|
||||
log::info!("[LmsSync] Decoupling zone {}", mac);
|
||||
|
||||
let client_opt = {
|
||||
let controller = player.0.lock().await;
|
||||
controller.jellyfin_client().lock().map_err(|e| e.to_string())?.clone()
|
||||
};
|
||||
|
||||
if let Some(client) = client_opt {
|
||||
client.lms_unsync_player(&mac).await
|
||||
} else {
|
||||
Err("Jellyfin client not configured".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
/// Dissolve an entire LMS sync group, identified by its master's MAC.
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn lms_dissolve_sync_group(
|
||||
player: State<'_, PlayerStateWrapper>,
|
||||
master_mac: String,
|
||||
) -> Result<(), String> {
|
||||
log::info!("[LmsSync] Dissolving group with master {}", master_mac);
|
||||
|
||||
let client_opt = {
|
||||
let controller = player.0.lock().await;
|
||||
controller.jellyfin_client().lock().map_err(|e| e.to_string())?.clone()
|
||||
};
|
||||
|
||||
if let Some(client) = client_opt {
|
||||
client.lms_dissolve_sync_group(&master_mac).await
|
||||
} else {
|
||||
Err("Jellyfin client not configured".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,6 +384,82 @@ impl JellyfinClient {
|
||||
let sessions = self.get_sessions().await?;
|
||||
Ok(sessions.into_iter().find(|s| s.id.as_deref() == Some(session_id)))
|
||||
}
|
||||
|
||||
// --- JellyLMS multi-room sync groups -----------------------------------
|
||||
//
|
||||
// The JellyLMS plugin exposes a REST API under `/JellyLms` for grouping LMS
|
||||
// players ("zones") into synchronized multi-room sync groups. Players are
|
||||
// addressed by MAC address; JellyTau maps a Jellyfin session to a MAC by
|
||||
// stripping the `lms-` prefix off the session's device id (see
|
||||
// LmsDeviceDiscoveryService in the jellyLMS repo, which registers each player
|
||||
// with deviceId = "lms-{MacAddress}").
|
||||
|
||||
/// List current LMS sync groups.
|
||||
pub async fn lms_get_sync_groups(&self) -> Result<Vec<LmsSyncGroup>, String> {
|
||||
self.get("/JellyLms/SyncGroups").await
|
||||
}
|
||||
|
||||
/// Fuse LMS zones: create a sync group with `master_mac` as the sync master
|
||||
/// and `slave_macs` joining it. The master keeps playing; slaves follow.
|
||||
pub async fn lms_create_sync_group(
|
||||
&self,
|
||||
master_mac: &str,
|
||||
slave_macs: Vec<String>,
|
||||
) -> Result<(), String> {
|
||||
let payload = serde_json::json!({
|
||||
"MasterMac": master_mac,
|
||||
"SlaveMacs": slave_macs,
|
||||
});
|
||||
self.post("/JellyLms/SyncGroups", &payload).await
|
||||
}
|
||||
|
||||
/// Remove a single LMS player from whatever sync group it's in.
|
||||
pub async fn lms_unsync_player(&self, mac: &str) -> Result<(), String> {
|
||||
self.delete(&format!("/JellyLms/SyncGroups/Players/{}", mac)).await
|
||||
}
|
||||
|
||||
/// Dissolve an entire LMS sync group, identified by its master's MAC.
|
||||
pub async fn lms_dissolve_sync_group(&self, master_mac: &str) -> Result<(), String> {
|
||||
self.delete(&format!("/JellyLms/SyncGroups/{}", master_mac)).await
|
||||
}
|
||||
|
||||
/// Make a DELETE request to the Jellyfin API (used by the JellyLMS endpoints).
|
||||
async fn delete(&self, endpoint: &str) -> Result<(), String> {
|
||||
let url = format!("{}{}", self.config.server_url, endpoint);
|
||||
|
||||
log::debug!("[JellyfinClient] DELETE {}", endpoint);
|
||||
|
||||
let response = self.http_client
|
||||
.delete(&url)
|
||||
.header("X-Emby-Authorization", self.get_auth_header())
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("Network request failed: {}", e))?;
|
||||
|
||||
let status = response.status();
|
||||
if !status.is_success() {
|
||||
let error_text = response.text().await.unwrap_or_else(|_| "Unknown error".to_string());
|
||||
return Err(format!("Jellyfin API error {}: {}", status.as_u16(), error_text));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// An LMS multi-room sync group, as returned by JellyLMS `/JellyLms/SyncGroups`.
|
||||
///
|
||||
/// Mirrors the plugin's `SyncGroup` model. The master is the sync source; slaves
|
||||
/// follow it in lockstep.
|
||||
#[derive(specta::Type, Debug, Clone, Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct LmsSyncGroup {
|
||||
#[serde(alias = "MasterMac")]
|
||||
pub master_mac: String,
|
||||
#[serde(default, alias = "MasterName")]
|
||||
pub master_name: String,
|
||||
#[serde(default, alias = "SlaveMacs")]
|
||||
pub slave_macs: Vec<String>,
|
||||
#[serde(default, alias = "SlaveNames")]
|
||||
pub slave_names: Vec<String>,
|
||||
}
|
||||
|
||||
/// Default value for supports_remote_control when missing from API
|
||||
|
||||
@@ -52,11 +52,13 @@ use commands::{
|
||||
// Remote session control commands
|
||||
remote_play_on_session, remote_send_command, remote_session_seek, remote_session_set_volume,
|
||||
remote_session_toggle_mute,
|
||||
// LMS multi-room sync group commands
|
||||
lms_get_sync_groups, lms_create_sync_group, lms_unsync_player, lms_dissolve_sync_group,
|
||||
// Session polling commands
|
||||
sessions_set_polling_hint, sessions_poll_now, SessionPollerWrapper,
|
||||
// Playback mode commands
|
||||
playback_mode_get_current, playback_mode_set, playback_mode_is_transferring,
|
||||
playback_mode_transfer_to_remote, playback_mode_transfer_to_local,
|
||||
playback_mode_transfer_to_remote, playback_mode_transfer_to_local, playback_mode_set_transferring,
|
||||
playback_mode_get_remote_status,
|
||||
// Playback reporting commands
|
||||
playback_reporter_init, playback_reporter_destroy,
|
||||
@@ -417,6 +419,11 @@ fn specta_builder() -> Builder<tauri::Wry> {
|
||||
remote_session_seek,
|
||||
remote_session_set_volume,
|
||||
remote_session_toggle_mute,
|
||||
// LMS multi-room sync group commands
|
||||
lms_get_sync_groups,
|
||||
lms_create_sync_group,
|
||||
lms_unsync_player,
|
||||
lms_dissolve_sync_group,
|
||||
// Session polling commands
|
||||
sessions_set_polling_hint,
|
||||
sessions_poll_now,
|
||||
@@ -427,6 +434,7 @@ fn specta_builder() -> Builder<tauri::Wry> {
|
||||
playback_mode_transfer_to_remote,
|
||||
playback_mode_get_remote_status,
|
||||
playback_mode_transfer_to_local,
|
||||
playback_mode_set_transferring,
|
||||
// Playback reporting commands
|
||||
playback_reporter_init,
|
||||
playback_reporter_destroy,
|
||||
|
||||
@@ -81,6 +81,19 @@ impl PlaybackModeManager {
|
||||
self.is_transferring.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Set the transferring flag directly.
|
||||
///
|
||||
/// The remote->local transfer is driven from the frontend in two steps
|
||||
/// (`player_play_tracks` to start local playback, then
|
||||
/// `playback_mode_transfer_to_local` to stop the remote). The first step's
|
||||
/// routing depends on this flag: while it's set, `player_play_tracks` plays
|
||||
/// locally instead of casting back to the remote session. The frontend must
|
||||
/// raise the flag *before* that first call and lower it when the sequence is
|
||||
/// done (or aborts), so it can't be left stuck on.
|
||||
pub fn set_transferring(&self, transferring: bool) {
|
||||
self.is_transferring.store(transferring, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// Send volume command to remote session
|
||||
/// Commands: "SetVolume", "VolumeUp", "VolumeDown"
|
||||
#[allow(dead_code)] // Called from Android JNI callback
|
||||
|
||||
Reference in New Issue
Block a user