Local stays the default and the cheap path; mesh asks each partner for its own sessions over SSH, live rather than cached, because a stream is true for minutes and a cached one would be confidently wrong about the only thing the card exists to say.
52 lines
2.8 KiB
PHP
52 lines
2.8 KiB
PHP
<?php
|
|
// ═══════════════════════════════════════════════════════════════════════════════════════════════
|
|
// PURPOSE
|
|
// Active media sessions endpoint. Normalised now-playing across every Emby, Jellyfin and
|
|
// Plex instance configured for this host, for the monitor page's session panel.
|
|
//
|
|
// DESIGN PRINCIPLES
|
|
// Thin transport. Discovery, per-server API dialects and normalisation all live in
|
|
// include/media.php; this file only sets the content type and encodes the result.
|
|
//
|
|
// No parameters. Which servers to ask is derived from conf, not from the request, so the
|
|
// browser cannot point this endpoint at an arbitrary URL.
|
|
//
|
|
// OPERATIONAL SAFEGUARDS
|
|
// Bounded by the library's 3s per-request timeout.
|
|
// A wedged media server cannot hold this endpoint open, because every fetch inside
|
|
// vv_media_sessions() carries a stream-context timeout. This is the only thing between
|
|
// a hung Emby and a poll that never returns.
|
|
//
|
|
// Failure is an empty list, not an error.
|
|
// Unreachable servers, non-JSON bodies and unexpected shapes all resolve to [] inside
|
|
// the library. The panel renders empty and the rest of the monitor page is unaffected.
|
|
//
|
|
// Read-only. Sessions are observed. Nothing here stops a stream, forces a transcode, or
|
|
// messages a client.
|
|
//
|
|
// REQUEST
|
|
// GET, no parameters
|
|
//
|
|
// RESPONSE
|
|
// vv_media_sessions() verbatim — a flat list of normalised sessions across all servers
|
|
//
|
|
// REQUEST
|
|
// GET this host's sessions
|
|
// GET ?scope=mesh every node's sessions, each row tagged with the host it is playing on
|
|
//
|
|
// Local is the default and stays the cheap path: one call per configured media server here.
|
|
// Mesh adds one bounded SSH hop per partner and is only requested while the operator is looking
|
|
// at the mesh view, so a dashboard left open on the default costs exactly what it did before.
|
|
//
|
|
// DEPENDS ON
|
|
// include/media.php vv_media_sessions(), vv_media_sessions_mesh()
|
|
// ═══════════════════════════════════════════════════════════════════════════════════════════════
|
|
header('Content-Type: application/json');
|
|
require_once dirname(__DIR__) . '/include/media.php';
|
|
|
|
// Anything that is not the literal "mesh" is local. Fail-closed on the expensive path, matching
|
|
// how every other toggle in this plugin reads its value.
|
|
echo json_encode(($_GET['scope'] ?? '') === 'mesh'
|
|
? vv_media_sessions_mesh()
|
|
: vv_media_sessions() + ['scope' => 'local']);
|