mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +00:00
LIVE loads YouTube only after Play, and stops when its view is hidden
Selecting a station no longer builds the player: the LIVE section and the Cockpit's LIVE page show a poster with Play under the line that YouTube sees the viewer's IP address, as SECURITY.md asks of third-party media. The player goes when the section collapses, Context collapses or closes, the Cockpit leaves its LIVE page, or the Cockpit is entered or left, so nothing plays unseen. A selection that moves straight on to another entry of the same station (the Cockpit stepping between views) keeps the player instead of rebuilding it. SECURITY.md also lists the ISS telemetry relay.
This commit is contained in:
1 parent
71d57481b7
commit
1e2332eeb6
14 files changed
+314
-108
No files matched your search
@@ -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<string, string|number>}
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
+67
-22
@@ -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();
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
+36
-15
@@ -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,
|
||||
|
||||
+15
-20
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -85,7 +85,7 @@ function leaveSignals() {
|
||||
<a class="cockpit-weather-credit" href="https://open-meteo.com/" target="_blank" rel="noopener">{{ t('Weather data by Open-Meteo.com') }}</a>
|
||||
</section>
|
||||
<section data-cockpit-brief-page="live" :aria-label="t('Live video')" :hidden="b.pageId !== 'live'">
|
||||
<CockpitLivePage v-if="live" />
|
||||
<CockpitLivePage v-if="live" :shown="b.pageId === 'live'" />
|
||||
</section>
|
||||
</div>
|
||||
<footer class="cockpit-signal-footer">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup>
|
||||
import { onBeforeUnmount, watch } from 'vue';
|
||||
import { t } from '../../../i18n/index.js';
|
||||
import { useLiveScreen } from '../../liveScreen.js';
|
||||
|
||||
@@ -6,11 +7,18 @@ import { useLiveScreen } from '../../liveScreen.js';
|
||||
// card's measure, for the ridden subject's streams. The briefing renders it
|
||||
// only while a stream is on offer. LiveControls builds the player into
|
||||
// `#cockpit-live-player-host` while the Cockpit is on (the right rail, and
|
||||
// the section's screen with it, is hidden there), and the page's controls
|
||||
// call LiveControls through the live store, as the section's do.
|
||||
// the section's screen with it, is hidden there), only when the viewer
|
||||
// presses Play, under the notice that YouTube sees their IP address. The
|
||||
// page's controls call LiveControls through the live store, as the section's
|
||||
// do. Leaving the page, or the page going, stops the player.
|
||||
const props = defineProps({
|
||||
/** Whether the briefing shows this page now. */
|
||||
shown: { type: Boolean, default: true },
|
||||
});
|
||||
const {
|
||||
view,
|
||||
act,
|
||||
idle,
|
||||
playing,
|
||||
loading,
|
||||
offline,
|
||||
@@ -18,6 +26,13 @@ const {
|
||||
badgeText,
|
||||
statusText,
|
||||
} = useLiveScreen();
|
||||
watch(
|
||||
() => props.shown,
|
||||
(now) => {
|
||||
if (!now) act('hideLive', 'cockpit');
|
||||
},
|
||||
);
|
||||
onBeforeUnmount(() => act('hideLive', 'cockpit'));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -31,9 +46,11 @@ const {
|
||||
<span id="cockpit-live-stream-title" class="live-stream-title" aria-live="polite">{{ t(view.current.title) }}<small v-if="view.count > 1"> · {{ view.index + 1 }}/{{ view.count }}</small></span>
|
||||
<button v-if="view.count > 1" id="cockpit-live-next" type="button" class="live-step" @click="act('cycleLive', 1)" :aria-label="t('Next stream')" :title="t('Next stream')"><span class="material-symbols-outlined" aria-hidden="true">chevron_right</span></button>
|
||||
</div>
|
||||
<p class="live-privacy cockpit-live-privacy">{{ t('Video plays from YouTube, which sees your IP address.') }}</p>
|
||||
<!-- The player's element stays put across re-renders: LiveControls mounts the player in it. -->
|
||||
<div class="live-screen" :class="{ active: playing || loading }">
|
||||
<div id="cockpit-live-player-host" class="live-player-host"></div>
|
||||
<button v-if="idle" id="cockpit-live-play" type="button" class="live-play" @click="act('playLive')"><span class="material-symbols-outlined" aria-hidden="true">play_arrow</span>{{ t('Play') }}</button>
|
||||
<div v-if="offline || unavailable" class="live-card" :class="{ offline, unavailable }">
|
||||
<span class="live-card-dot" aria-hidden="true"></span>
|
||||
<strong>{{ offline ? t('Stream is offline') : t('This stream cannot play here') }}</strong>
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed, onBeforeUnmount, watch } from 'vue';
|
||||
import { t } from '../../../i18n/index.js';
|
||||
import RailPanel from '../../rail/RailPanel.vue';
|
||||
import { vClassToggle } from '../../rail/classToggle.js';
|
||||
import { useLiveScreen } from '../../liveScreen.js';
|
||||
import { usePanelChromeStore } from '../../stores/panelChrome.js';
|
||||
|
||||
// The LIVE section inside Context: the live streams attached to the selected
|
||||
// object (LiveControls publishes them), one at a time in the platform's own
|
||||
// player. It is there only while the selection has a stream, and the stream
|
||||
// starts as soon as one is chosen (useLiveScreen). The section starts
|
||||
// collapsed; its +/- hides and shows the body, and the player plays on,
|
||||
// muted, underneath. Its controls call LiveControls through the store.
|
||||
// player. It is there only while the selection has a stream. The player is
|
||||
// loaded only when the viewer presses Play, under the notice that YouTube
|
||||
// sees their IP address; collapsing the section, collapsing Context, or the
|
||||
// section leaving the page stops it. Its controls call LiveControls through
|
||||
// the store.
|
||||
const PANEL_ID = 'live-panel';
|
||||
const {
|
||||
view,
|
||||
act,
|
||||
idle,
|
||||
playing,
|
||||
loading,
|
||||
offline,
|
||||
@@ -22,6 +26,17 @@ const {
|
||||
badgeText,
|
||||
statusText,
|
||||
} = useLiveScreen();
|
||||
// Nothing plays unseen: a hidden section gives up its player.
|
||||
const { panels } = storeToRefs(usePanelChromeStore());
|
||||
const hidden = computed(
|
||||
() =>
|
||||
(panels.value[PANEL_ID]?.collapsed ?? true) ||
|
||||
panels.value['global-context-panel']?.collapsed === true,
|
||||
);
|
||||
watch(hidden, (now) => {
|
||||
if (now) act('hideLive', 'section');
|
||||
});
|
||||
onBeforeUnmount(() => act('hideLive', 'section'));
|
||||
const liveWords = computed(() => ({
|
||||
expandLabel: t('Expand Live section'),
|
||||
collapseLabel: t('Collapse Live section'),
|
||||
@@ -40,9 +55,11 @@ const liveWords = computed(() => ({
|
||||
<span id="live-stream-title" class="live-stream-title" aria-live="polite">{{ t(view.current.title) }}<small v-if="view.count > 1"> · {{ view.index + 1 }}/{{ view.count }}</small></span>
|
||||
<button v-if="view.count > 1" id="live-next-btn" type="button" class="live-step" @click="act('cycleLive', 1)" :aria-label="t('Next stream')" :title="t('Next stream')"><span class="material-symbols-outlined" aria-hidden="true">chevron_right</span></button>
|
||||
</div>
|
||||
<p class="live-privacy">{{ t('Video plays from YouTube, which sees your IP address.') }}</p>
|
||||
<!-- The player's element stays put across re-renders: LiveControls mounts the player in it. -->
|
||||
<div class="live-screen" :class="{ active: playing || loading }">
|
||||
<div id="live-player-host" class="live-player-host"></div>
|
||||
<button v-if="idle" id="live-play-btn" type="button" class="live-play" @click="act('playLive')"><span class="material-symbols-outlined" aria-hidden="true">play_arrow</span>{{ t('Play') }}</button>
|
||||
<div v-if="offline || unavailable" class="live-card" :class="{ offline, unavailable }">
|
||||
<span class="live-card-dot" aria-hidden="true"></span>
|
||||
<strong>{{ offline ? t('Stream is offline') : t('This stream cannot play here') }}</strong>
|
||||
@@ -51,7 +68,6 @@ const liveWords = computed(() => ({
|
||||
</div>
|
||||
<p id="live-status" class="live-status" role="status" aria-live="polite">{{ statusText }}</p>
|
||||
<p class="live-credit"><a :href="view.current.ownerUrl" target="_blank" rel="noopener noreferrer">{{ view.current.owner }}</a> · <a id="live-watch-link" :href="view.current.watchUrl" target="_blank" rel="noopener noreferrer">{{ t('Open on YouTube') }}</a></p>
|
||||
<p class="live-privacy">{{ t('Video plays from YouTube, which sees your IP address.') }}</p>
|
||||
</template>
|
||||
</RailPanel>
|
||||
</template>
|
||||
Reference in new issue
Block a user