diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index 7c24447ab5..458c472ce7 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -37,7 +37,7 @@ How to read this: | **NASA 3D Resources** (`public/models/iss.glb`) | The ISS drawn as a 3D model when the camera is near it (satellites layer): NASA/JSC IGOAL's "International Space Station (ISS) (D)" (https://science.nasa.gov/3d-resources/international-space-station-iss-d-igoal/), reduced and re-rigged as `public/models/README.md` records. Its moving parts are computed by the app unless the telemetry relay in the next row is switched on: arrays and radiators from the Sun's position, the Ku-band dishes toward the TDRS fleet's nominal slots (41°W, 171°W, 85°E), the robotic arms as an illustrative sway | NASA media, not subject to copyright in the United States; NASA's Images and Media Usage Guidelines (https://www.nasa.gov/nasa-brand-center/images-and-media) ask that use not imply endorsement and that the insignia not be used | "ISS model: NASA 3D Resources" | | **Project model** (`public/models/tiangong.glb`) | Tiangong drawn as a 3D model when the camera is near it (satellites layer): an original model of the station's T configuration (Tianhe, Wentian, Mengtian, a Shenzhou forward and nadir, a Tianzhou aft) made for God's Eye View from primitives with procedurally generated textures; dimensions from Wang, Zhang & Wang 2023, "Design and Application Prospect of China's Tiangong Space Station", Space: Science & Technology (https://doi.org/10.34133/space.0035, CC BY 4.0) and eoPortal's Tiangong page, the approximate parts listed in `public/models/README.md`. Its moving parts are computed by the app: the wings from the Sun's position, the high-gain antenna toward the Tianlian II nominal slots (79.9°E, 171.04°E, 10.5°E), the two arms as an illustrative sway; China publishes no live telemetry for the station | MIT, with the rest of the project's own work (`LICENSE`): an original asset with no third-party geometry, textures or images; the published dimensions are facts taken from a CC BY 4.0 paper and eoPortal | "Tiangong model: made for God's Eye View; dimensions from Wang, Zhang & Wang 2023 (CC BY 4.0) and eoPortal" | | **NASA ISSLive telemetry** (`push.lightstreamer.com`, adapter set `ISSLIVE`) | **Off by default.** With `ISS_TELEMETRY_ENABLED=1` the server holds one connection to NASA's public ISS telemetry stream, open only while a browser has the ISS model on screen, and relays the latest joint angles at `/api/iss-telemetry`: the two alpha joints, the eight array beta joints, the two radiator joints and the Ku-band dish (Canadarm2's joints are relayed but not used yet). While the station has signal the ISS model takes those angles in place of the computed ones. The app stores nothing from it | The public subset of ISS telemetry NASA released as the ISSLive project, served for NASA by Lightstreamer. No terms of use are published for the feed, so it is opt-in and no request is made by default | "ISS joint telemetry: NASA ISSLive, via Lightstreamer" | -| **NASA ISS live streams on YouTube** (`youtube-nocookie.com/embed/ROboUHfPUrU`, `.../M3HKLzjvKPc`) | NASA's official live video from the ISS, two broadcasts ("Live High-Definition Views from the International Space Station" from the exterior cameras, and the live video with space-to-ground audio), offered in a LIVE section of Context, and on the Cockpit briefing's LIVE page, while the ISS is selected on the map and played, muted, in YouTube's own embedded player, which loads as soon as the station is selected; collapsing the section hides the player without stopping it; the app stores nothing from it (`src/data/liveStreams.js`) | NASA video, not subject to copyright in the United States, distributed through YouTube under YouTube's Terms of Service, which permit embedding with the public embeddable player; the privacy-enhanced host is used and the viewer's IP address reaches YouTube as soon as the station is selected | "NASA video, via YouTube", with a link to the stream's own page | +| **NASA ISS live streams on YouTube** (`youtube-nocookie.com/embed/ROboUHfPUrU`, `.../M3HKLzjvKPc`) | NASA's official live video from the ISS, two broadcasts ("Live High-Definition Views from the International Space Station" from the exterior cameras, and the live video with space-to-ground audio), offered in a LIVE section of Context, and on the Cockpit briefing's LIVE page, while the ISS is selected on the map, and played, muted, in YouTube's own embedded player only after the viewer presses Play; collapsing the section, closing Context or leaving the Cockpit page removes the player; the app stores nothing from it (`src/data/liveStreams.js`) | NASA video, not subject to copyright in the United States, distributed through YouTube under YouTube's Terms of Service, which permit embedding with the public embeddable player; the player API script loads from `www.youtube.com` and the video from the privacy-enhanced host `www.youtube-nocookie.com`, and the viewer's IP address reaches YouTube only once they press Play, under a line that says so | "NASA video, via YouTube", with a link to the stream's own page | | **The Space Devs — Launch Library 2 v2.3** | Recent launch, payload, stage, and recovery metadata for Space Missions (30d) | [The Space Devs terms of use](https://github.com/TheSpaceDevs/Tutorials/blob/main/faqs/faq_TSD.md#terms-of-use): data may be used and shared in any form; avoid forwarding it without added value; attribution is encouraged (not mandatory). [Official API limits](https://ll.thespacedevs.com/docs/): 15 unauthenticated calls/hour; optional token | "Launch Library 2 — The Space Devs" (courtesy attribution) | | **Esri World Imagery** (ArcGIS Online tile service) | The keyless satellite basemap — the default landing when no Google/ion credential is configured, and the "Esri Satellite" map stack | [Esri Master Agreement](https://www.esri.com/en-us/legal/terms/full-master-agreement): the public World Imagery service is usable in public-facing apps with attribution; no key is required for this classic endpoint, but Esri governs and can change access — an app at scale should review current ArcGIS Location Platform terms | "Powered by Esri — Source: Esri, Maxar, Earthstar Geographics, and the GIS User Community" (provider carries the service's own credit line) | | **USGS** | Earthquakes | U.S. public domain | "Data courtesy of the U.S. Geological Survey" | diff --git a/SECURITY.md b/SECURITY.md index e67186d648..ccbcde08cb 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -72,6 +72,8 @@ The data proxies under `server/providers/` are written so the browser cannot tur - **Live HLS is bounded and origin-pinned.** Registered HTTP(S) HLS sources use a Node puller that rejects redirects and off-origin playlist references, bounds playlists to 256 KiB and segment bodies to 8 MiB while streaming, and aborts timed-out or released sessions. At most two sessions retain 12 segments/24 MiB each, plus bounded download buffers. Stores are memory-only and idle sessions expire after 15 seconds. RTMP/ffmpeg execution is not enabled. Locally configured source URLs remain an operator trust boundary. - **Radio is not an audio relay.** `/api/radio/stations` contacts only allowlisted Radio Browser HTTPS hosts and paths, rejects redirects, rejects any hostname with a loopback/private/link-local/metadata/non-public A or AAAA result, and pins each TLS connection to a validated address. It returns normalized public HTTPS stream URLs; `/api/radio/click/:uuid` applies the same destination policy and accepts only station IDs from the current bounded catalog. The browser then connects directly to the broadcaster after an explicit playback action, so the broadcaster sees the listener's IP address. GEV never proxies, caches, records, or redistributes audio. - **Québec 511 video plays in the browser, opt-in and after Play.** With `CCTV_QUEBEC_VIDEO_ENABLED=1`, `/api/cctv/sources` lists, for each MTQ camera, one URL built server-side from its numeric id on `https://www.quebec511.info/Carte/Fenetres/camera.ashx`; the overlay accepts no other host, path or format. The browser loads that clip only after the viewer presses Play for the selected camera, so Québec 511 sees the viewer's IP address, and the panel says so before Play. Selecting a camera by click, auto-hop, a scene or voice never loads it, and switching cameras stops playback. GEV never proxies, caches or reads the video's pixels. With the flag unset (the default) the browser makes no request to Québec 511. +- **Station live video plays only after Play.** The LIVE section of Context and the Cockpit briefing's LIVE page load YouTube's player (the IFrame API from `www.youtube.com`, the video on `www.youtube-nocookie.com`) only after the viewer presses Play, under a line saying that YouTube sees their IP address. Selecting a station by click, a share link that follows it, a scene or voice shows the poster and loads nothing. The player goes when the section is collapsed, Context is closed or collapsed, the Cockpit leaves its LIVE page, the Cockpit is entered or left, or the selection moves to an object without that stream. GEV never proxies, caches or reads the video's pixels. +- **The ISS telemetry relay is opt-in, keyless and read-only.** With `ISS_TELEMETRY_ENABLED=1`, `/api/iss-telemetry` answers from one shared WebSocket the server opens to NASA's public ISSLive feed (`wss://push.lightstreamer.com`), only while a browser has asked in the last two minutes; every byte from the feed is parsed as untrusted text, frames over 64 KB are dropped, and only the listed joint and clock items are kept. The route uses the keyless same-site checks and a per-client rate limit; with the flag unset (the default) it answers `{ configured: false }` and the server opens no socket. - **No verbatim client headers upstream.** The CCTV media route is the one route that relays a request header (`Range`, for video seeking). It is parsed and canonicalized before it is forwarded: one `bytes=` range only, with every accepted form — explicit span, open-ended and suffix — bounded to the same 64 MiB ceiling the relay applies to a declared response body. Multi-range, malformed, inverted and non-`bytes` values are dropped and the request proceeds without a `Range`, as RFC 7233 §3.1 prescribes. Bounding the request bounds what is asked for: a response that declares no length — live streamed media, or a chunked body from an upstream that ignores the `Range` — has no ceiling. An upstream request the browser has stopped waiting for is cancelled rather than left running, whether the viewer leaves before the headers arrive or during the body. - **The Data Library proxy fetches manifest upstreams only.** `/api/library/data/`, `/api/library/tile////` and `/api/library/index/` (a partitioned GeoParquet entry's file index, built from an S3 ListObjectsV2 listing and one ranged footer read per file, cached in memory for the entry's `cacheSeconds`) resolve the id against the validated manifests in `src/library/entries/`; the browser never supplies a URL, and every derived request must stay on the manifest's https host. Redirects are refused, dataset bodies are capped while streaming at the manifest's `maxBytes` (at most 32 MiB) and tiles at 2 MiB of `image/png`, `image/jpeg` or `image/webp`, responses are cached in memory only (at most 512 tiles), requests are rate-limited per client, and upstream error text is never returned. A keyed entry must be proxied; its key is read from this server's environment through the key registry and its routes refuse cross-site and forwarded requests like the other cost-bearing routes. Browser-direct entries are fetched by the browser with no cookies or referrer. - **Transit fetches registered feeds only.** `/api/transit/vehicles/` resolves the id against `src/data/transitFeeds.js`; the browser never supplies a URL, and a feed that is registered but disabled does not resolve at all. Redirects are followed manually and each hop is validated against the feed's own https origin before it is requested, so an off-origin or downgraded hop is refused rather than contacted. Bodies are capped at 8 MB, the protobuf is decoded server-side under entity-count and string-length ceilings, a differential feed is refused, and snapshots live 15 s in memory with no disk cache. A per-feed admission limiter and a failure cooldown ladder bound what this process can ask of any operator. diff --git a/build/vite.js b/build/vite.js index 29918290e3..02a11bf659 100644 --- a/build/vite.js +++ b/build/vite.js @@ -55,7 +55,8 @@ function photonEndpointSetting(value) { * Content-Security-Policy for every document the dev/preview server serves. * No inline script is permitted, and the only foreign script origins are the * three that the Bhote Koshi event's embedded media needs (YouTube, Facebook - * and X), which frame-src matches for their players and posts. 'unsafe-eval' is + * and X), which frame-src matches for their players and posts; the stations' + * LIVE video uses the same YouTube player, after the viewer presses Play. 'unsafe-eval' is * required: Knockout (bundled inside @cesium/widgets) resolves the global * object with `(0, eval)("this")` at module load, and without it the Cesium * widget never initializes (verified in headless Chrome). It also covers @@ -66,9 +67,10 @@ function photonEndpointSetting(value) { */ export const BROWSER_CSP = [ "default-src 'self'", - // The Bhote Koshi event's embedded media: the YouTube player API, the - // Facebook video SDK and X's post widget (src/data/bhoteKoshiEmbeddedMedia.js); - // and the Maps JavaScript API that Street Level's Google Street View runs on. + // The Bhote Koshi event's embedded media: the YouTube player API (also the + // stations' LIVE video, src/data/youtubeLivePlayer.js), the Facebook video + // SDK and X's post widget (src/data/bhoteKoshiEmbeddedMedia.js); and the + // Maps JavaScript API that Street Level's Google Street View runs on. "script-src 'self' 'unsafe-eval' blob: https://www.youtube.com https://connect.facebook.net https://platform.twitter.com https://maps.googleapis.com", "style-src 'self' 'unsafe-inline' https://fonts.googleapis.com", "font-src 'self' data: https://fonts.gstatic.com", diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index c51660710c..4fa4fc8301 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -2081,27 +2081,32 @@ which no stream is listed for yet), and the keys are read again every 2 s while something is selected, since a docked entry is judged so only once both orbits have been compared. The section shows the subject, the stream's name with two arrows when there are several, a screen and a status line. It -starts collapsed, and the player loads as soon as a station is selected: -`youtubeLivePlayer.js` builds YouTube's player on the privacy-enhanced host, -muted, with the IFrame API, and reads its state back (the views ask for the -stream whenever one is chosen and nothing plays, `src/ui/liveScreen.js`). -The section's +/- only hides and shows the body; the stream plays on, muted, -underneath. ON AIR with a blinking red dot while it plays; an amber dot -while it starts; an offline card ("Stream is offline", with Try again) when +starts collapsed, and nothing loads on selection: the screen is a poster +with Play, under the line "Video plays from YouTube, which sees your IP +address." Play is the one thing that loads the player: +`youtubeLivePlayer.js` builds YouTube's player (the IFrame API from +`www.youtube.com`, the video on `www.youtube-nocookie.com`), muted, and reads +its state back. Collapsing the section, collapsing or closing Context, or the +section leaving the page removes the player, so nothing plays unseen. ON AIR +with a blinking red dot while it plays; LOADING with an amber dot while it +starts; an offline card ("Stream is offline", with Try again) when the player reports the video ended, errored or did not start within 25 s, which is how an off-air broadcast shows; "This stream cannot play here" when the owner refuses embedding or the API does not load. Stepping to another -stream hands a playing one over; a new selection, clearing it or turning the -layer off removes the player. In the Cockpit the rail is hidden, so the +stream hands a playing one over; a selection that moves to an object +without that stream, clearing it or turning the layer off removes the +player, while another entry of the same station (a module, a docked vehicle, +the Cockpit stepping between views) keeps it. In the Cockpit the rail is hidden, so the briefing card gains a fourth page, LIVE (SIG / NEWS / LOCAL / LIVE, `CockpitLivePage.vue`), with the same subject line, arrows, screen, states -and credit; it is offered only while the ridden subject has a stream, and -with none the briefing keeps its three pages. There is one player: on entry -it is built again in the page's screen, on exit in the section's (an embedded -player cannot change parents without reloading). Previous, Next and the tabs -reach the LIVE page; the automatic 9-second cycle never turns to it and -waits while it is shown. The credit links the owner and the stream's own -page, and the section's note says the video plays from YouTube. +and credit, and the same poster with Play under the IP line; it is offered +only while the ridden subject has a stream, and with none the briefing keeps +its three pages. There is one player: entering or leaving the Cockpit +removes it (an embedded player cannot change parents without reloading, and +the view it was in is hidden), and so does leaving the LIVE page; the view +now shown offers Play again. Previous, Next and the tabs reach the LIVE page; +the automatic 9-second cycle never turns to it and waits while it is shown. +The credit links the owner and the stream's own page. The model is NASA/JSC IGOAL's current-configuration station, reduced to 3 MB with its joints kept as nodes (`public/models/README.md`), fetched only once the camera nears its range, and drawn as an item of a `models` set of the diff --git a/src/data/liveStreams.js b/src/data/liveStreams.js index f331fe658d..3e530df701 100644 --- a/src/data/liveStreams.js +++ b/src/data/liveStreams.js @@ -65,9 +65,9 @@ export function youtubeWatchUrl(videoId) { /** * The parameters the live player is created with: starts on creation (the - * player is built as soon as a subject with a stream is selected), muted so - * the browser lets it, inline on phones, no related videos, and the page's - * origin so the player API may be spoken to. + * player is built only when the viewer presses Play), muted so the browser + * lets it start once the player API has loaded, inline on phones, no related + * videos, and the page's origin so the player API may be spoken to. * @param {string} origin The page's origin. * @returns {Record} */ diff --git a/src/ui/cockpitBriefing.test.mjs b/src/ui/cockpitBriefing.test.mjs index ae6f259038..3f9423af14 100644 --- a/src/ui/cockpitBriefing.test.mjs +++ b/src/ui/cockpitBriefing.test.mjs @@ -71,6 +71,7 @@ function fixture(t) { playLive: () => liveActed.push(['play']), stopLive: () => liveActed.push(['stop']), retryLive: () => liveActed.push(['retry']), + hideLive: (where) => liveActed.push(['hide', where]), }); const offerLive = async (view) => { liveStore.publish( @@ -209,7 +210,12 @@ test('with a stream the LIVE page is the fourth, reached by the arrows and its t assert.ok($('#cockpit-live-previous')); assert.ok($('#cockpit-live-next')); assert.equal(text('#cockpit-live-badge-text'), 'OFF'); - assert.equal(text('#cockpit-live-status'), 'Starting…'); + assert.equal(text('#cockpit-live-status'), 'Click to play'); + assert.ok($('#cockpit-live-play'), 'Play, under the IP notice'); + assert.match( + page.querySelector('.cockpit-live-privacy').textContent, + /sees your IP address/, + ); assert.equal( $('#cockpit-live-watch-link').getAttribute('href'), 'https://www.youtube.com/watch?v=ROboUHfPUrU', @@ -221,15 +227,14 @@ test('with a stream the LIVE page is the fourth, reached by the arrows and its t assert.equal(text('#cockpit-brief-position'), '1 / 4'); }); -test('the LIVE page asks for the stream as soon as it is offered, and its controls reach LiveControls', async (t) => { +test('the LIVE page loads the stream only on Play, stops it when left, and its controls reach LiveControls', async (t) => { const { $, owner, offerLive, liveActed } = fixture(t); await offerLive({}); - assert.deepEqual( - liveActed, - [['play']], - 'the player starts on selection, whichever page is shown', - ); + assert.deepEqual(liveActed, [], 'riding the station loads no player'); showBriefPage.call(owner, 3); + await nextTick(); + $('#cockpit-live-play').click(); + assert.deepEqual(liveActed, [['play']]); await offerLive({ state: 'playing' }); const page = $('[data-cockpit-brief-page="live"]'); assert.equal($('#cockpit-live-badge-text').textContent, 'ON AIR'); @@ -245,6 +250,12 @@ test('the LIVE page asks for the stream as soon as it is offered, and its contro $('#cockpit-live-next').click(); $('#cockpit-live-previous').click(); assert.deepEqual(liveActed, [['play'], ['cycle', 1], ['cycle', -1]]); + // Leaving the page stops what plays there. + showBriefPage.call(owner, 0); + await nextTick(); + assert.deepEqual(liveActed.at(-1), ['hide', 'cockpit']); + showBriefPage.call(owner, 3); + await nextTick(); await offerLive({ state: 'offline', reason: 'timeout' }); const card = page.querySelector('.live-card'); assert.equal(card.classList.contains('offline'), true); diff --git a/src/ui/liveControls.js b/src/ui/liveControls.js index 810f734ce0..711057c473 100644 --- a/src/ui/liveControls.js +++ b/src/ui/liveControls.js @@ -27,12 +27,14 @@ export const LIVE_SUBJECT_REFRESH_MS = 2000; * Own the live video: which object is selected (the tracking layers' * `gev:awareness-subject-selected`), which streams the list attaches to it, * and the one player. The views (the LIVE section in Context and the Cockpit - * briefing's LIVE page) render what this publishes and ask for the stream to - * start (`playLive`) as soon as one is chosen; the player is built into - * whichever view is shown, the section's outside the Cockpit and the page's - * inside it, and built again in the other when the Cockpit is entered or - * left (an embedded player cannot change parents without reloading). It goes - * when the selection changes or clears. + * briefing's LIVE page) render what this publishes, and the player is built + * only when the viewer presses Play in one of them (`playLive`): YouTube sees + * the viewer's IP address, so selecting a station by click, a link, a scene + * or voice never loads it. The player is built into the view that is shown, + * the section's outside the Cockpit and the page's inside it, and goes when + * that view is hidden (the section collapsed, Context closed, the Cockpit + * page left: `hideLive`), when the Cockpit is entered or left, and when the + * selection moves to an object without that stream or clears. */ export class LiveControls { /** @@ -72,6 +74,8 @@ export class LiveControls { this.cockpitActive = documentRef?.body?.classList?.contains?.('cockpit-mode') === true; this.timer = null; + /** The stop held back for one tick after a clear (see `_onCleared`). */ + this.clearGrace = null; this.listeners = new AbortController(); const { signal } = this.listeners; const target = globalRef.addEventListener ? globalRef : null; @@ -95,48 +99,88 @@ export class LiveControls { playLive: () => this.play(), stopLive: () => this.stop(), retryLive: () => this.play({ restart: true }), + hideLive: (where) => this.hide(where), }); store.publish(null); } + /** + * A new selection. A player that is on keeps playing when the new subject + * offers the same stream (another entry of the same station: a module, a + * docked vehicle, the Cockpit stepping between views on it); otherwise it + * goes. + */ _onSelected(detail) { if (this.destroyed || !detail?.layerId || detail.id == null) return; - const same = - this.subject && - this.subject.layerId === detail.layerId && - String(this.subject.id) === String(detail.id); + this._cancelClearGrace(); this.subject = { layerId: detail.layerId, id: detail.id, label: String(detail.label ?? detail.id), }; - if (!same) this.stop(); + if (this.player) { + const offered = liveStreamsFor(this._subjectKeys(), this.streams); + if (offered.some((stream) => stream.id === this.playerStreamId)) + this.currentId = this.playerStreamId; + else this.stop(); + } this._refresh(); this._arm(); } + /** + * The selection cleared. With a player on, the stop waits one tick: the + * Cockpit stepping between views on a station clears the selection and + * selects the next entry at once, and a player for the same stream should + * not be torn down and rebuilt between the two. + */ _onCleared(detail) { if (this.destroyed || !this.subject) return; if (detail?.layerId && detail.layerId !== this.subject.layerId) return; this.subject = null; - this.stop(); this._disarm(); + if (this.player && this.globalRef.setTimeout) { + this._cancelClearGrace(); + this.clearGrace = this.globalRef.setTimeout(() => { + this.clearGrace = null; + if (this.destroyed || this.subject) return; + this.stop(); + this._refresh(); + }, 0); + return; + } + this.stop(); this._refresh(); } + _cancelClearGrace() { + if (this.clearGrace !== null) + this.globalRef.clearTimeout?.(this.clearGrace); + this.clearGrace = null; + } + /** - * The Cockpit went on or off: the view shown changed, so a player that is - * loading or playing is built again in the host now shown. With no such - * host in the page the player goes, and the view starts it again once its - * screen is there. + * The Cockpit went on or off: the view the player was in is hidden now, + * so the player goes. The view now shown offers Play again. */ _onCockpitMode(active) { if (this.destroyed || active === this.cockpitActive) return; this.cockpitActive = active; - if (this.player === null) return; - const host = this._host(); - if (host && host === this.playerHost) return; - if (!this.play({ restart: true })) this.stop(); + this.stop(); + } + + /** + * A view was hidden (`section`: the LIVE section collapsed or Context + * closed; `cockpit`: the briefing left its LIVE page or went): the player + * goes if it was in that view's screen, so nothing plays unseen. + * @param {'section'|'cockpit'} where + * @returns {boolean} True when a player was removed. + */ + hide(where) { + const id = + where === 'cockpit' ? COCKPIT_LIVE_PLAYER_HOST_ID : LIVE_PLAYER_HOST_ID; + if (!this.player || this.playerHost?.id !== id) return false; + return this.stop(); } /** The element the player belongs in now: the Cockpit page's, or the section's. */ @@ -254,8 +298,8 @@ export class LiveControls { /** * Start the chosen stream in the host now shown: the one call that loads - * the player. A player already loading or playing that stream in that host - * is left alone, so the views may ask whenever they see nothing playing; + * the player, made only by the viewer's Play (or Try again). A player + * already loading or playing that stream in that host is left alone; * `restart` (Try again) builds a fresh one regardless. * @returns {boolean} True when a player is loading or playing afterwards. */ @@ -309,6 +353,7 @@ export class LiveControls { destroy() { if (this.destroyed) return; + this._cancelClearGrace(); this.stop(); this.destroyed = true; this._disarm(); diff --git a/src/ui/liveControls.test.mjs b/src/ui/liveControls.test.mjs index f832ccf2ad..8eecb2a774 100644 --- a/src/ui/liveControls.test.mjs +++ b/src/ui/liveControls.test.mjs @@ -59,6 +59,19 @@ function fixture({ const timer = intervals.find((entry) => entry.id === id); if (timer) timer.cleared = true; }; + const timeouts = []; + globalRef.setTimeout = (callback, ms) => { + timeouts.push({ callback, ms, done: false }); + return timeouts.length; + }; + globalRef.clearTimeout = (id) => { + if (timeouts[id - 1]) timeouts[id - 1].done = true; + }; + /** Run the timeouts due now, as the next tick would. */ + const tick = () => { + for (const timeout of timeouts.splice(0)) + if (!timeout.done) timeout.callback(); + }; const host = { id: LIVE_PLAYER_HOST_ID }; const cockpitHost = { id: COCKPIT_LIVE_PLAYER_HOST_ID }; const documentRef = { @@ -125,6 +138,7 @@ function fixture({ layouts, intervals, running, + tick, host, cockpitHost, }; @@ -276,12 +290,37 @@ test('clearing the selection takes the section down; another layer clearing does f.dispatch('gev:awareness-subject-cleared', { layerId: 'flights' }); assert.equal(f.view().count, 2, 'another layer clearing is not ours'); f.dispatch('gev:awareness-subject-cleared', { layerId: 'satellites' }); + assert.equal(f.running().length, 0, 'the timer stops with the selection'); + // The stop waits a tick, for a selection that moves straight on. + assert.equal(f.players[0].destroyed, 0); + f.tick(); assert.equal(f.view(), null); assert.equal(f.players[0].destroyed, 1); - assert.equal(f.running().length, 0, 'the timer stops with the selection'); }); -test("entering the Cockpit builds the player again in the briefing page's screen, and leaving it in the section's", () => { +test('a selection that moves straight on to an entry with the same stream keeps the player', () => { + const f = fixture(); + f.setKeys(['station:test']); + f.select(); + f.store.act('playLive'); + // The Cockpit stepping to the next view on the station: cleared, then the + // next entry selected, in one go. + f.dispatch('gev:awareness-subject-cleared', { layerId: 'satellites' }); + f.select({ id: 49044, label: 'ISS (NAUKA)' }); + f.tick(); + assert.equal(f.players.length, 1, 'not rebuilt'); + assert.equal(f.players[0].destroyed, 0); + assert.equal(f.view().label, 'ISS (NAUKA)'); + assert.equal(f.view().current.id, 'one'); + // One without that stream stops it. + f.dispatch('gev:awareness-subject-cleared', { layerId: 'satellites' }); + f.setKeys(['station:other']); + f.select({ id: 99999, label: 'OTHER' }); + f.tick(); + assert.equal(f.players[0].destroyed, 1); +}); + +test('entering or leaving the Cockpit removes the player: the view now shown offers Play again', () => { const f = fixture(); f.setKeys(['station:test']); f.select(); @@ -289,20 +328,43 @@ test("entering the Cockpit builds the player again in the briefing page's screen f.players[0].options.onChange({ state: 'playing', reason: null }); f.dispatch('gev:cockpit-mode-changed', { active: true }); assert.equal(f.players[0].destroyed, 1, 'the rail is hidden in the Cockpit'); - assert.equal(f.players.length, 2); - assert.equal(f.players[1].options.host, f.cockpitHost); - assert.equal(f.players[1].options.videoId, 'AAAAAAAAAAA'); - assert.equal(f.view().state, 'loading', 'a fresh player starts again'); + assert.equal(f.players.length, 1, 'nothing is built by itself'); + assert.equal(f.view().state, 'idle'); // The same state again changes nothing. f.dispatch('gev:cockpit-mode-changed', { active: true }); - assert.equal(f.players.length, 2); - // playLive from the hidden section's view finds the Cockpit's screen too. + assert.equal(f.players.length, 1); + // Play in the Cockpit's page builds it in that page's screen. assert.equal(f.store.act('playLive'), true); - assert.equal(f.players.length, 2); + assert.equal(f.players[1].options.host, f.cockpitHost); f.dispatch('gev:cockpit-mode-changed', { active: false }); assert.equal(f.players[1].destroyed, 1); - assert.equal(f.players.length, 3); - assert.equal(f.players[2].options.host, f.host); + assert.equal(f.players.length, 2); +}); + +test('a view that is hidden removes the player only when it is in that view', () => { + const f = fixture(); + f.setKeys(['station:test']); + f.select(); + f.store.act('playLive'); + assert.equal(f.store.act('hideLive', 'cockpit'), false, 'not in the page'); + assert.equal(f.players[0].destroyed, 0); + assert.equal(f.store.act('hideLive', 'section'), true); + assert.equal(f.players[0].destroyed, 1); + assert.equal(f.view().state, 'idle'); + assert.equal(f.store.act('hideLive', 'section'), false, 'nothing left'); +}); + +test('selecting a station with streams builds no player until Play', () => { + const f = fixture(); + f.setKeys(['station:test']); + f.select(); + f.select({ origin: 'pick' }); + f.dispatch('gev:cockpit-mode-changed', { active: true }); + f.dispatch('gev:cockpit-mode-changed', { active: false }); + assert.equal(f.players.length, 0); + assert.equal(f.view().state, 'idle'); + f.store.act('playLive'); + assert.equal(f.players.length, 1); }); test('the Cockpit going on or off with nothing playing builds nothing', () => { diff --git a/src/ui/livePanel.test.mjs b/src/ui/livePanel.test.mjs index 3dac6e3389..7ea50af895 100644 --- a/src/ui/livePanel.test.mjs +++ b/src/ui/livePanel.test.mjs @@ -29,6 +29,7 @@ function fixture(t) { playLive: () => acted.push(['play']), stopLive: () => acted.push(['stop']), retryLive: () => acted.push(['retry']), + hideLive: (where) => acted.push(['hide', where]), }); const chrome = usePanelChromeStore(pinia); const token = chrome.connect({ toggle() {}, pin() {} }); @@ -66,7 +67,7 @@ function fixture(t) { ); await settle(); }; - return { $, publish, acted, setOpen }; + return { $, publish, acted, setOpen, chrome, token }; } test('without a view the section is hidden and shows OFF', (t) => { @@ -81,7 +82,7 @@ test('without a view the section is hidden and shows OFF', (t) => { assert.deepEqual(acted, [], 'nothing to start'); }); -test('a view shows the subject and the stream, and starts it at once, with the section collapsed', async (t) => { +test('a view shows the subject, the stream and Play under the IP notice, and loads nothing by itself', async (t) => { const { $, publish, acted } = fixture(t); await publish({}); const panel = $('live-panel'); @@ -96,17 +97,30 @@ test('a view shows the subject and the stream, and starts it at once, with the s 'https://www.youtube.com/watch?v=ROboUHfPUrU', ); assert.equal($('live-watch-link').getAttribute('rel'), 'noopener noreferrer'); - assert.deepEqual(acted, [['play']], 'the stream starts on selection'); - // Loading and playing change nothing further. + assert.deepEqual(acted, [], 'selecting the station loads no player'); + // The notice that YouTube sees the viewer's IP address comes before Play. + const notice = panel.querySelector('.live-privacy'); + const play = $('live-play-btn'); + assert.ok(notice && play); + assert.match(notice.textContent, /sees your IP address/); + assert.equal( + notice.compareDocumentPosition(play) & Node.DOCUMENT_POSITION_FOLLOWING, + Node.DOCUMENT_POSITION_FOLLOWING, + 'the notice is above Play', + ); + assert.equal($('live-status').textContent, 'Click to play'); + play.click(); + assert.deepEqual(acted, [['play']], 'Play is what loads the player'); + // Loading and playing hide Play and ask for nothing more. await publish({ state: 'loading' }); + assert.equal($('live-play-btn'), null); await publish({ state: 'playing' }); assert.deepEqual(acted, [['play']]); }); -test('a different stream chosen while idle starts too', async (t) => { - const { publish, acted } = fixture(t); +test('a different stream chosen while idle waits for Play too', async (t) => { + const { $, publish, acted } = fixture(t); await publish({}); - assert.deepEqual(acted, [['play']]); await publish({ current: { id: 'iss-crew', @@ -118,19 +132,26 @@ test('a different stream chosen while idle starts too', async (t) => { }, index: 1, }); - assert.deepEqual(acted, [['play'], ['play']]); + assert.deepEqual(acted, []); + assert.ok($('live-play-btn')); }); -test('collapsing or opening the section neither stops nor restarts the stream', async (t) => { - const { $, publish, acted, setOpen } = fixture(t); +test('collapsing the section, or Context, stops the player; opening it starts nothing', async (t) => { + const { $, publish, acted, setOpen, chrome, token } = fixture(t); await setOpen(true); await publish({ state: 'playing' }); assert.deepEqual(acted, [], 'already playing: nothing to start'); await setOpen(false); - assert.deepEqual(acted, [], 'the +/- only hides the body'); - assert.ok($('live-player-host'), 'the player keeps its element'); + assert.deepEqual(acted, [['hide', 'section']], 'nothing plays unseen'); + assert.ok($('live-player-host'), 'the screen keeps its element'); await setOpen(true); - assert.deepEqual(acted, []); + assert.deepEqual(acted, [['hide', 'section']], 'opening starts nothing'); + chrome.publish(token, 'global-context-panel', { collapsed: true }); + await settle(); + assert.deepEqual(acted, [ + ['hide', 'section'], + ['hide', 'section'], + ]); }); test('while playing the badge says ON AIR with the blinking dot, and there is no card', async (t) => { @@ -151,10 +172,10 @@ test('while playing the badge says ON AIR with the blinking dot, and there is no assert.equal($('live-status').textContent, 'Live'); }); -test('starting shows the waiting dot', async (t) => { +test('starting shows the waiting dot and says LOADING', async (t) => { const { $, publish } = fixture(t); await publish({ state: 'loading' }); - assert.equal($('live-badge-text').textContent, 'OFF'); + assert.equal($('live-badge-text').textContent, 'LOADING'); assert.equal( $('live-panel').querySelector('.live-dot').classList.contains('waiting'), true, diff --git a/src/ui/liveScreen.js b/src/ui/liveScreen.js index 0c31c891e2..3d941a817d 100644 --- a/src/ui/liveScreen.js +++ b/src/ui/liveScreen.js @@ -1,13 +1,14 @@ import { storeToRefs } from 'pinia'; -import { computed, nextTick, watch } from 'vue'; +import { computed } from 'vue'; import { t } from '../i18n/index.js'; import { useLiveStore } from './stores/live.js'; /** * What the LIVE section in Context and the Cockpit briefing's LIVE page - * share: the live store's view, its state read as words, and the rule that - * starts the stream. Each view calls this from its setup and renders the - * result; the controls call LiveControls through `act`. + * share: the live store's view and its state read as words. Each view calls + * this from its setup and renders the result; the controls call LiveControls + * through `act`. Nothing here starts the stream: the views show Play while + * it is `idle`, and the player is loaded only when the viewer presses it. */ export function useLiveScreen() { const store = useLiveStore(); @@ -17,7 +18,12 @@ export function useLiveScreen() { const loading = computed(() => view.value?.state === 'loading'); const offline = computed(() => view.value?.state === 'offline'); const unavailable = computed(() => view.value?.state === 'unavailable'); - const badgeText = computed(() => (playing.value ? t('ON AIR') : t('OFF'))); + const idle = computed( + () => Boolean(view.value) && view.value.state === 'idle', + ); + const badgeText = computed(() => + playing.value ? t('ON AIR') : loading.value ? t('LOADING') : t('OFF'), + ); const statusText = computed(() => { switch (view.value?.state) { case 'playing': @@ -26,28 +32,17 @@ export function useLiveScreen() { return t('Stream is offline'); case 'unavailable': return t('This stream cannot play here'); - default: + case 'loading': return t('Starting…'); + default: + return t('Click to play'); } }); - // Start the stream as soon as one is chosen and nothing plays, once the - // screen is in the page (the player is built into it). Which screen is - // LiveControls' choice, and asking from both views starts nothing twice. - // A stream that went offline or cannot play stays as it is until Try again. - watch( - [() => view.value?.current?.id ?? null, () => view.value?.state ?? null], - async ([streamId, state]) => { - if (!streamId || state !== 'idle') return; - await nextTick(); - act('playLive'); - }, - { immediate: true, flush: 'post' }, - ); - return { view, act, + idle, playing, loading, offline, diff --git a/src/ui/styles/live.css b/src/ui/styles/live.css index e2550afc0a..7986d63fa8 100644 --- a/src/ui/styles/live.css +++ b/src/ui/styles/live.css @@ -140,6 +140,36 @@ .live-screen:not(.active) .live-player-host { display: none; } +/* The poster's Play: the only way the player is loaded. */ +.live-play { + position: absolute; + inset: 0; + margin: auto; + width: max-content; + height: max-content; + display: inline-flex; + align-items: center; + gap: 6px; + min-width: 44px; + min-height: 44px; + padding: 8px 18px; + border: 1px solid rgba(255, 255, 255, 0.45); + border-radius: 4px; + background: rgba(0, 7, 12, 0.72); + color: #f4fbff; + font: inherit; + font-size: 12px; + letter-spacing: 0.1em; + cursor: pointer; +} +.live-play:hover, +.live-play:focus-visible { + border-color: #ff3b3b; + outline: none; +} +.live-play .material-symbols-outlined { + font-size: 20px; +} .live-card { position: absolute; inset: 0; diff --git a/src/ui/views/panels/CockpitBriefing.vue b/src/ui/views/panels/CockpitBriefing.vue index baecbc9bce..d0d16bfbe3 100644 --- a/src/ui/views/panels/CockpitBriefing.vue +++ b/src/ui/views/panels/CockpitBriefing.vue @@ -85,7 +85,7 @@ function leaveSignals() { {{ t('Weather data by Open-Meteo.com') }}
- +