diff --git a/.dockerignore b/.dockerignore index 7478707..8c2a663 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,4 +5,5 @@ npm-debug.log* .env .DS_Store Dockerfile +data public/_smoke.avi diff --git a/.gitignore b/.gitignore index 0c97d47..adcc854 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ +data/recent-urls.json .env .DS_Store npm-debug.log* diff --git a/Dockerfile b/Dockerfile index e0cc450..6778f9f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,8 @@ COPY public ./public COPY server ./server COPY README.md ./ -RUN chown -R node:node /app +RUN mkdir -p /app/data \ + && chown -R node:node /app USER node diff --git a/README.md b/README.md index 7fb8553..d842ee8 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ docker compose -f docker-compose-example.yml up --build The app uses CPU decoding by default, so no video device is required. The compose example includes commented VAAPI/NVIDIA passthrough options for future hardware-accelerated `ffmpeg` setups. +Recently played URLs are stored globally by the backend. In Docker Compose, they are persisted in the `frame-stream-data` named volume. + ## Tuning The UI intentionally hides these settings, but the backend still supports them through `POST /api/session`. diff --git a/docker-compose-example.yml b/docker-compose-example.yml index 74192aa..1c591e9 100644 --- a/docker-compose-example.yml +++ b/docker-compose-example.yml @@ -9,8 +9,11 @@ services: environment: PORT: "3000" NODE_ENV: production + RECENT_URLS_PATH: /app/data/recent-urls.json extra_hosts: - "host.docker.internal:host-gateway" + volumes: + - frame-stream-data:/app/data # CPU decoding is the default and does not need device passthrough. # @@ -20,3 +23,6 @@ services: # # Optional NVIDIA passthrough with Docker Compose v2: # gpus: all + +volumes: + frame-stream-data: diff --git a/public/app.js b/public/app.js index 2d8165f..346eb74 100644 --- a/public/app.js +++ b/public/app.js @@ -5,6 +5,8 @@ const elements = { url: document.querySelector('#stream-url'), next: document.querySelector('#next'), entryMessage: document.querySelector('#entry-message'), + recentPanel: document.querySelector('#recent-panel'), + recentList: document.querySelector('#recent-list'), audio: document.querySelector('#audio'), canvas: document.querySelector('#screen'), stage: document.querySelector('#video-stage'), @@ -28,8 +30,11 @@ const state = { frameCount: 0, controlsVisible: true, hideControlsTimer: 0, + recentUrls: [], }; +void loadRecentUrls(); + elements.form.addEventListener('submit', async (event) => { event.preventDefault(); setEntryMessage(''); @@ -51,6 +56,7 @@ elements.form.addEventListener('submit', async (event) => { } showPlayer(); + void loadRecentUrls(); startSession(payload); } catch (error) { stopSession(); @@ -60,6 +66,23 @@ elements.form.addEventListener('submit', async (event) => { } }); +elements.recentList.addEventListener('click', (event) => { + const button = event.target.closest('[data-recent-index]'); + + if (!button) { + return; + } + + const item = state.recentUrls[Number(button.dataset.recentIndex)]; + + if (!item) { + return; + } + + elements.url.value = item.url; + elements.form.requestSubmit(); +}); + elements.stage.addEventListener('pointerup', (event) => { if (!state.session || event.target.closest('.controls')) { return; @@ -387,6 +410,7 @@ function syncControlLabels() { function showEntry() { elements.playerScreen.hidden = true; elements.entryScreen.hidden = false; + void loadRecentUrls(); elements.url.focus(); } @@ -410,4 +434,40 @@ function setEntryMessage(message) { function setFormBusy(isBusy) { elements.url.disabled = isBusy; elements.next.disabled = isBusy; + + for (const button of elements.recentList.querySelectorAll('button')) { + button.disabled = isBusy; + } +} + +async function loadRecentUrls() { + try { + const response = await fetch('/api/recent-urls', { cache: 'no-store' }); + + if (!response.ok) { + throw new Error('Failed to load recent URLs.'); + } + + const payload = await response.json(); + state.recentUrls = Array.isArray(payload.urls) ? payload.urls : []; + renderRecentUrls(); + } catch { + state.recentUrls = []; + renderRecentUrls(); + } +} + +function renderRecentUrls() { + elements.recentList.replaceChildren( + ...state.recentUrls.map((item, index) => { + const button = document.createElement('button'); + button.type = 'button'; + button.className = 'recent-url'; + button.dataset.recentIndex = String(index); + button.textContent = item.displayUrl || item.url; + return button; + }), + ); + + elements.recentPanel.hidden = state.recentUrls.length === 0; } diff --git a/public/index.html b/public/index.html index 59815ed..628f447 100644 --- a/public/index.html +++ b/public/index.html @@ -9,18 +9,23 @@