/* eslint-disable camelcase */ import Block from "components/services/widget/block"; import Container from "components/services/widget/container"; import { useTranslation } from "next-i18next"; import { BsCpu, BsFillCpuFill, BsFillPlayFill, BsPauseFill } from "react-icons/bs"; import { MdOutlineSmartDisplay, MdSmartDisplay } from "react-icons/md"; import useWidgetAPI from "utils/proxy/use-widget-api"; function millisecondsToTime(milliseconds) { const seconds = Math.floor((milliseconds / 1000) % 60); const minutes = Math.floor((milliseconds / (1000 * 60)) % 60); const hours = Math.floor((milliseconds / (1000 * 60 * 60)) % 24); return { hours, minutes, seconds }; } function millisecondsToString(milliseconds) { const { hours, minutes, seconds } = millisecondsToTime(milliseconds); const parts = []; if (hours > 0) { parts.push(hours); } parts.push(minutes); parts.push(seconds); return parts.map((part) => part.toString().padStart(2, "0")).join(":"); } function generateStreamTitle(session, enableUser, showEpisodeNumber) { let stream_title = ""; const { mediaType, mediaTitle, showTitle, seasonNumber, episodeNumber, username } = session; if (mediaType === "episode" && showEpisodeNumber) { const season_str = `S${seasonNumber.toString().padStart(2, "0")}`; const episode_str = `E${episodeNumber.toString().padStart(2, "0")}`; stream_title = `${showTitle}: ${season_str} ยท ${episode_str} - ${mediaTitle}`; } else if (mediaType === "episode") { stream_title = `${showTitle} - ${mediaTitle}`; } else { stream_title = mediaTitle; } return enableUser ? `${stream_title} (${username})` : stream_title; } function SingleSessionEntry({ session, enableUser, showEpisodeNumber }) { const { durationMs, progressMs, state, videoDecision, audioDecision } = session; const progress_percent = durationMs > 0 ? (progressMs / durationMs) * 100 : 0; const stream_title = generateStreamTitle(session, enableUser, showEpisodeNumber); return ( <>
{stream_title}
{videoDecision === "directplay" && audioDecision === "directplay" && ( )} {videoDecision === "copy" && audioDecision === "copy" && } {videoDecision !== "copy" && videoDecision !== "directplay" && (audioDecision !== "copy" || audioDecision !== "directplay") && } {(videoDecision === "copy" || videoDecision === "directplay") && audioDecision !== "copy" && audioDecision !== "directplay" && }
{state === "paused" && ( )} {state !== "paused" && ( )}
{millisecondsToString(progressMs)} / {millisecondsToString(durationMs)}
); } function SessionEntry({ session, enableUser, showEpisodeNumber }) { const { durationMs, progressMs, state, videoDecision, audioDecision } = session; const progress_percent = durationMs > 0 ? (progressMs / durationMs) * 100 : 0; const stream_title = generateStreamTitle(session, enableUser, showEpisodeNumber); return (
{state === "paused" && ( )} {state !== "paused" && ( )}
{stream_title}
{videoDecision === "directplay" && audioDecision === "directplay" && } {videoDecision === "copy" && audioDecision === "copy" && } {videoDecision !== "copy" && videoDecision !== "directplay" && (audioDecision !== "copy" || audioDecision !== "directplay") && } {(videoDecision === "copy" || videoDecision === "directplay") && audioDecision !== "copy" && audioDecision !== "directplay" && }
{millisecondsToString(progressMs)}
); } function SummaryView({ service, summary, t }) { return ( ); } function DetailsView({ playing, enableUser, showEpisodeNumber, expandOneStreamToTwoRows, t }) { if (playing.length === 0) { return (
{t("tracearr.no_active")}
{expandOneStreamToTwoRows && (
-
)}
); } if (expandOneStreamToTwoRows && playing.length === 1) { const session = playing[0]; return (
); } return (
{playing.map((session) => ( ))}
); } export default function Component({ service }) { const { t } = useTranslation(); const { widget } = service; const { data: activityData, error: activityError } = useWidgetAPI(widget, "streams", { refreshInterval: 5000, }); const enableUser = !!service.widget?.enableUser; const expandOneStreamToTwoRows = service.widget?.expandOneStreamToTwoRows !== false; const showEpisodeNumber = !!service.widget?.showEpisodeNumber; const view = service.widget?.view ?? "details"; if (activityError) { return ; } // Loading state if (!activityData || !activityData.data) { if (view === "summary") { return ( ); } return (
-
{expandOneStreamToTwoRows && (
-
)}
); } const playing = activityData.data.sort((a, b) => a.progressMs - b.progressMs); const { summary } = activityData; if (view === "summary") { return ; } if (view === "both") { return ( <> ); } // Default: details view return ( ); }