mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
Merge main into denis/iss-live-telemetry
Conflicts: the locale catalogs and package boundaries are three-way merges (no message changed differently on both sides); zh-Hant is regenerated from zh-CN. bhoteKoshiEmbeddedMedia.js keeps main's card counter and the branch's shared YouTube loader (youtubeApi.js), so the media file builds one script element fewer. The Cockpit briefing's LIVE tab and the orbital NADIR/RESET button are main's UiButton.
This commit is contained in:
commit
edbf3a234d
244 files changed
+11747
-1273
No files matched your search
+174
-179
@@ -7,6 +7,8 @@ import {
|
||||
import { dot, sub } from '../geo/vector.js';
|
||||
import { loadYouTubeApi } from './youtubeApi.js';
|
||||
import { t, msg, onLocaleChange } from '../i18n/index.js';
|
||||
import { h, render as renderVue } from 'vue';
|
||||
import BhoteKoshiMediaCards from '../ui/bhoteKoshi/BhoteKoshiMediaCards.vue';
|
||||
|
||||
const YOUTUBE_HOSTS = new Set([
|
||||
'youtube.com',
|
||||
@@ -99,6 +101,8 @@ export function bhoteEventText(value) {
|
||||
let _xWidgetsPromise = null;
|
||||
let _facebookSdkPromise = null;
|
||||
let _facebookEmbedSequence = 0;
|
||||
let _cardSequence = 0;
|
||||
|
||||
/** A trimmed clip follows provider time, never time spent loading its iframe. */
|
||||
export function createTrimmedYouTubePlayback({
|
||||
iframe,
|
||||
@@ -629,32 +633,61 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
let record = null;
|
||||
let warmRecord = null;
|
||||
let generation = 0;
|
||||
// Text the cards show, kept as the calls that word it so a locale change
|
||||
// words it again. A node is forgotten once it has left the page.
|
||||
const worded = new Map();
|
||||
function forgetDetached() {
|
||||
for (const node of worded.keys())
|
||||
if (!node.isConnected) worded.delete(node);
|
||||
let destroyed = false;
|
||||
// The cards in the root, in the order they were shown: the current one and
|
||||
// any still leaving. Their text is kept as the calls that word it, so a
|
||||
// locale change words it again.
|
||||
const cards = [];
|
||||
|
||||
/** Render the cards and the YouTube preload into the root, synchronously. */
|
||||
function render() {
|
||||
if (destroyed) return;
|
||||
const warmFrame = warmRecord?.frame;
|
||||
renderVue(
|
||||
h(BhoteKoshiMediaCards, {
|
||||
warm: warmFrame
|
||||
? {
|
||||
key: warmRecord.key,
|
||||
src: warmFrame.src,
|
||||
title: warmFrame.title(),
|
||||
}
|
||||
: null,
|
||||
cards: cards.map((current) => ({
|
||||
id: current.id,
|
||||
provider: current.source.provider,
|
||||
portrait: current.portrait,
|
||||
entering: current.entering,
|
||||
leaving: current.leaving,
|
||||
unavailable: current.unavailable,
|
||||
label: current.label(),
|
||||
title: current.title(),
|
||||
status: current.status(),
|
||||
url: current.source.url,
|
||||
frame: current.frame && {
|
||||
src: current.frame.src,
|
||||
title: current.frame.title(),
|
||||
onLoad: current.frame.onLoad,
|
||||
},
|
||||
bind: current.bind,
|
||||
})),
|
||||
}),
|
||||
root,
|
||||
);
|
||||
}
|
||||
function word(node, property, text) {
|
||||
let properties = worded.get(node);
|
||||
if (!properties) worded.set(node, (properties = new Map()));
|
||||
properties.set(property, text);
|
||||
writeWord(node, property, text());
|
||||
}
|
||||
function writeWord(node, property, value) {
|
||||
if (property === 'textContent' || property === 'title')
|
||||
node[property] = value;
|
||||
else node.setAttribute(property, value);
|
||||
}
|
||||
const offLocale = onLocaleChange(() => {
|
||||
forgetDetached();
|
||||
for (const [node, properties] of worded)
|
||||
for (const [property, text] of properties)
|
||||
writeWord(node, property, text());
|
||||
});
|
||||
const offLocale = onLocaleChange(render);
|
||||
const leavingRecords = new Set();
|
||||
|
||||
/** Word a card's status and draw it. */
|
||||
function setStatus(current, text) {
|
||||
current.status = text;
|
||||
render();
|
||||
}
|
||||
/** Mark a card unavailable or not and draw it. */
|
||||
function setUnavailable(current, unavailable) {
|
||||
current.unavailable = unavailable;
|
||||
render();
|
||||
}
|
||||
|
||||
const prefersReducedMotion = () =>
|
||||
globalRef.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches ===
|
||||
true;
|
||||
@@ -795,9 +828,10 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
if (current.exitTimer != null) globalRef.clearTimeout?.(current.exitTimer);
|
||||
destroyFacebookSession(current.facebookSession);
|
||||
current.youtubeSession?.destroy();
|
||||
current.card?.remove?.();
|
||||
const at = cards.indexOf(current);
|
||||
if (at !== -1) cards.splice(at, 1);
|
||||
leavingRecords.delete(current);
|
||||
forgetDetached();
|
||||
render();
|
||||
}
|
||||
|
||||
const position = () => {
|
||||
@@ -813,7 +847,8 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
current.enterFrame = scheduleFrame(() => {
|
||||
current.enterFrame = null;
|
||||
if (token !== generation || record !== current) return;
|
||||
current.card.classList.add('is-entering');
|
||||
current.entering = true;
|
||||
render();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -835,9 +870,10 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
removeRecord(current);
|
||||
return;
|
||||
}
|
||||
current.card.classList.remove('is-entering');
|
||||
current.card.classList.add('is-leaving');
|
||||
current.entering = false;
|
||||
current.leaving = true;
|
||||
leavingRecords.add(current);
|
||||
render();
|
||||
current.exitTimer =
|
||||
globalRef.setTimeout?.(
|
||||
() => removeRecord(current),
|
||||
@@ -847,11 +883,10 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
|
||||
function clearWarm(key = null) {
|
||||
if (!warmRecord || (key && warmRecord.key !== key)) return;
|
||||
if (warmRecord.facebookSession)
|
||||
destroyFacebookSession(warmRecord.facebookSession);
|
||||
else warmRecord.iframe?.remove?.();
|
||||
const facebookSession = warmRecord.facebookSession;
|
||||
warmRecord = null;
|
||||
forgetDetached();
|
||||
if (facebookSession) destroyFacebookSession(facebookSession);
|
||||
else render();
|
||||
}
|
||||
|
||||
function takeWarmFacebook(key, host) {
|
||||
@@ -891,29 +926,26 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
warmRecord = { key, facebookSession };
|
||||
return true;
|
||||
}
|
||||
const iframe = documentRef.createElement('iframe');
|
||||
iframe.className = 'bhote-embedded-media-warmup';
|
||||
iframe.src = embeddedMediaFrameUrl(source, {
|
||||
autoplay: false,
|
||||
startAtSec,
|
||||
endAtSec,
|
||||
});
|
||||
word(iframe, 'title', () =>
|
||||
t('Preloading {provider} media', {
|
||||
provider: providerLabel(source.provider),
|
||||
}),
|
||||
);
|
||||
iframe.tabIndex = -1;
|
||||
iframe.setAttribute('aria-hidden', 'true');
|
||||
iframe.loading = 'eager';
|
||||
iframe.referrerPolicy = 'strict-origin-when-cross-origin';
|
||||
root.append(iframe);
|
||||
warmRecord = { key, iframe };
|
||||
warmRecord = {
|
||||
key,
|
||||
frame: {
|
||||
src: embeddedMediaFrameUrl(source, {
|
||||
autoplay: false,
|
||||
startAtSec,
|
||||
endAtSec,
|
||||
}),
|
||||
title: () =>
|
||||
t('Preloading {provider} media', {
|
||||
provider: providerLabel(source.provider),
|
||||
}),
|
||||
},
|
||||
};
|
||||
render();
|
||||
return true;
|
||||
}
|
||||
|
||||
async function mountX(current, token) {
|
||||
word(current.status, 'textContent', () => t('LOADING X POST…'));
|
||||
setStatus(current, () => t('LOADING X POST…'));
|
||||
try {
|
||||
const api = await xLoader(documentRef, globalRef);
|
||||
if (token !== generation || record !== current) return;
|
||||
@@ -933,14 +965,12 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
throw new Error(
|
||||
msg('The X post is unavailable or cannot be embedded.'),
|
||||
);
|
||||
word(current.status, 'textContent', () =>
|
||||
t('X POST · PROVIDER CONTROLS'),
|
||||
);
|
||||
setStatus(current, () => t('X POST · PROVIDER CONTROLS'));
|
||||
position();
|
||||
} catch (error) {
|
||||
if (token !== generation || record !== current) return;
|
||||
current.card.classList.add('is-unavailable');
|
||||
word(current.status, 'textContent', () =>
|
||||
current.unavailable = true;
|
||||
setStatus(current, () =>
|
||||
t('{reason} OPEN ORIGINAL.', {
|
||||
reason: t(String(error?.message || msg('X embed unavailable'))),
|
||||
}),
|
||||
@@ -957,16 +987,14 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
session.shouldPlay = autoplay === true;
|
||||
session.onReady = () => {
|
||||
if (token !== generation || record !== current) return;
|
||||
word(current.status, 'textContent', () =>
|
||||
t('FACEBOOK · PROVIDER CONTROLS'),
|
||||
);
|
||||
current.card.classList.remove('is-unavailable');
|
||||
current.status = () => t('FACEBOOK · PROVIDER CONTROLS');
|
||||
setUnavailable(current, false);
|
||||
position();
|
||||
};
|
||||
session.onError = (error) => {
|
||||
if (token !== generation || record !== current) return;
|
||||
current.card.classList.add('is-unavailable');
|
||||
word(current.status, 'textContent', () =>
|
||||
current.unavailable = true;
|
||||
setStatus(current, () =>
|
||||
t('{reason} OPEN ORIGINAL.', {
|
||||
reason: t(
|
||||
String(error?.message || msg('Facebook embed unavailable')),
|
||||
@@ -977,9 +1005,7 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
};
|
||||
session.onPlaybackBlocked = () => {
|
||||
if (token !== generation || record !== current) return;
|
||||
word(current.status, 'textContent', () =>
|
||||
t('AUTOPLAY BLOCKED · USE PROVIDER CONTROLS'),
|
||||
);
|
||||
setStatus(current, () => t('AUTOPLAY BLOCKED · USE PROVIDER CONTROLS'));
|
||||
};
|
||||
if (session.ready) session.onReady();
|
||||
else if (session.error) session.onError(session.error);
|
||||
@@ -1025,104 +1051,69 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
if (warmRecord && warmRecord.key !== warmKey) clearWarm();
|
||||
hide({ preserveWarm: true });
|
||||
const token = ++generation;
|
||||
const card = documentRef.createElement('section');
|
||||
const portraitClass = isPortraitMedia(media) ? ' is-portrait' : '';
|
||||
card.className = `bhote-embedded-callout is-${source.provider}${portraitClass}`;
|
||||
card.dataset.provider = source.provider;
|
||||
word(card, 'aria-label', () =>
|
||||
t('Embedded {provider} media for {source}', {
|
||||
provider: providerLabel(source.provider),
|
||||
source: observation?.title
|
||||
? bhoteEventText(observation.title)
|
||||
: t('witness source'),
|
||||
}),
|
||||
);
|
||||
const leader = documentRef.createElementNS(
|
||||
'http://www.w3.org/2000/svg',
|
||||
'svg',
|
||||
);
|
||||
leader.classList.add('bhote-embedded-callout-leader');
|
||||
leader.setAttribute('aria-hidden', 'true');
|
||||
leader.innerHTML =
|
||||
'<path pathLength="1" fill="none" stroke="rgba(147,213,228,.72)" stroke-width="1.5"/><circle r="4" fill="#6be8ff" stroke="#ffffff" stroke-width="1.5"/>';
|
||||
const player = documentRef.createElement('div');
|
||||
player.className = 'bhote-embedded-callout-player ui-scroll';
|
||||
const footer = documentRef.createElement('footer');
|
||||
const title = documentRef.createElement('strong');
|
||||
word(title, 'textContent', () =>
|
||||
bhoteEventText(
|
||||
observation?.shortTitle || observation?.title || t('Witness source'),
|
||||
).toUpperCase(),
|
||||
);
|
||||
const status = documentRef.createElement('small');
|
||||
status.setAttribute('role', 'status');
|
||||
word(status, 'textContent', () =>
|
||||
t('{provider} · EMBEDDED SOURCE', {
|
||||
provider: providerLabel(source.provider),
|
||||
}),
|
||||
);
|
||||
const link = documentRef.createElement('a');
|
||||
link.href = source.url;
|
||||
link.target = '_blank';
|
||||
link.rel = 'noopener noreferrer';
|
||||
word(link, 'textContent', () => t('OPEN ORIGINAL ↗'));
|
||||
footer.append(title, status, link);
|
||||
const body = documentRef.createElement('div');
|
||||
body.className = 'bhote-embedded-callout-body';
|
||||
// The card takes taps (its container and leader do not); Stories keeps that.
|
||||
body.setAttribute('data-overlay-input', '');
|
||||
body.append(player, footer);
|
||||
card.append(leader, body);
|
||||
root.append(card);
|
||||
record = {
|
||||
const providerName = () => providerLabel(source.provider);
|
||||
const sourceName = () =>
|
||||
observation?.title
|
||||
? bhoteEventText(observation.title)
|
||||
: t('witness source');
|
||||
const current = {
|
||||
id: ++_cardSequence,
|
||||
key,
|
||||
source,
|
||||
anchor,
|
||||
card,
|
||||
leader,
|
||||
player,
|
||||
status,
|
||||
portrait: isPortraitMedia(media),
|
||||
entering: false,
|
||||
leaving: false,
|
||||
unavailable: false,
|
||||
label: () =>
|
||||
t('Embedded {provider} media for {source}', {
|
||||
provider: providerName(),
|
||||
source: sourceName(),
|
||||
}),
|
||||
title: () =>
|
||||
bhoteEventText(
|
||||
observation?.shortTitle || observation?.title || t('Witness source'),
|
||||
).toUpperCase(),
|
||||
status: () =>
|
||||
t('{provider} · EMBEDDED SOURCE', { provider: providerName() }),
|
||||
frame: null,
|
||||
frameElement: null,
|
||||
card: null,
|
||||
leader: null,
|
||||
player: null,
|
||||
entered: false,
|
||||
};
|
||||
|
||||
if (source.provider === 'x') {
|
||||
void mountX(record, token);
|
||||
} else if (source.provider === 'facebook') {
|
||||
bindFacebook(record, token, warmKey, autoplay);
|
||||
} else {
|
||||
const iframe = documentRef.createElement('iframe');
|
||||
iframe.src = embeddedMediaFrameUrl(source, {
|
||||
autoplay,
|
||||
startAtSec,
|
||||
endAtSec,
|
||||
});
|
||||
const controlled =
|
||||
// The elements the card's view draws: placed after each frame, filled by
|
||||
// the provider.
|
||||
current.bind = (name, element) => {
|
||||
if (element) current[name] = element;
|
||||
};
|
||||
let controlled = false;
|
||||
if (source.provider === 'youtube') {
|
||||
const url = new URL(
|
||||
embeddedMediaFrameUrl(source, {
|
||||
autoplay,
|
||||
startAtSec,
|
||||
endAtSec,
|
||||
}),
|
||||
);
|
||||
controlled =
|
||||
autoplay &&
|
||||
Number.isFinite(Number(endAtSec)) &&
|
||||
Number(endAtSec) > startAtSec;
|
||||
if (controlled) {
|
||||
const url = new URL(iframe.src);
|
||||
url.searchParams.set('enablejsapi', '1');
|
||||
if (globalRef.location?.origin)
|
||||
url.searchParams.set('origin', globalRef.location.origin);
|
||||
iframe.src = url.href;
|
||||
}
|
||||
word(iframe, 'title', () =>
|
||||
t('{provider} media: {source}', {
|
||||
provider: providerLabel(source.provider),
|
||||
source: observation?.title
|
||||
? bhoteEventText(observation.title)
|
||||
: t('witness source'),
|
||||
}),
|
||||
);
|
||||
iframe.allow =
|
||||
'autoplay; encrypted-media; picture-in-picture; fullscreen';
|
||||
iframe.allowFullscreen = true;
|
||||
iframe.loading = 'eager';
|
||||
iframe.referrerPolicy = 'strict-origin-when-cross-origin';
|
||||
iframe.addEventListener?.(
|
||||
'load',
|
||||
() => {
|
||||
current.frame = {
|
||||
src: url.href,
|
||||
title: () =>
|
||||
t('{provider} media: {source}', {
|
||||
provider: providerName(),
|
||||
source: sourceName(),
|
||||
}),
|
||||
onLoad: () => {
|
||||
if (token !== generation || record?.key !== key) return;
|
||||
clearWarm(warmKey);
|
||||
if (
|
||||
@@ -1131,38 +1122,41 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
record.youtubeSession.getState().phase,
|
||||
)
|
||||
) {
|
||||
word(status, 'textContent', () =>
|
||||
t('{provider} · PROVIDER CONTROLS', {
|
||||
provider: providerLabel(source.provider),
|
||||
}),
|
||||
setStatus(current, () =>
|
||||
t('{provider} · PROVIDER CONTROLS', { provider: providerName() }),
|
||||
);
|
||||
}
|
||||
position();
|
||||
},
|
||||
{ once: true },
|
||||
);
|
||||
player.append(iframe);
|
||||
if (controlled) {
|
||||
const current = record;
|
||||
current.youtubeSession = createTrimmedYouTubePlayback({
|
||||
iframe,
|
||||
endAtSec: Number(endAtSec),
|
||||
startAtSec,
|
||||
globalRef,
|
||||
loadApi: () => youtubeLoader(documentRef, globalRef),
|
||||
isCurrent: () => token === generation && record === current,
|
||||
onStatus: (phase) => {
|
||||
if (phase !== 'completed')
|
||||
word(status, 'textContent', () =>
|
||||
t('YOUTUBE {state} · OPEN ORIGINAL', {
|
||||
state: YOUTUBE_PHASE_LABELS[phase]
|
||||
? t(YOUTUBE_PHASE_LABELS[phase])
|
||||
: phase.toUpperCase(),
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
record = current;
|
||||
cards.push(current);
|
||||
render();
|
||||
|
||||
if (source.provider === 'x') {
|
||||
void mountX(current, token);
|
||||
} else if (source.provider === 'facebook') {
|
||||
bindFacebook(current, token, warmKey, autoplay);
|
||||
} else if (controlled) {
|
||||
current.youtubeSession = createTrimmedYouTubePlayback({
|
||||
iframe: current.frameElement,
|
||||
endAtSec: Number(endAtSec),
|
||||
startAtSec,
|
||||
globalRef,
|
||||
loadApi: () => youtubeLoader(documentRef, globalRef),
|
||||
isCurrent: () => token === generation && record === current,
|
||||
onStatus: (phase) => {
|
||||
if (phase !== 'completed')
|
||||
setStatus(current, () =>
|
||||
t('YOUTUBE {state} · OPEN ORIGINAL', {
|
||||
state: YOUTUBE_PHASE_LABELS[phase]
|
||||
? t(YOUTUBE_PHASE_LABELS[phase])
|
||||
: phase.toUpperCase(),
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
position();
|
||||
return true;
|
||||
@@ -1170,11 +1164,12 @@ export function createBhoteKoshiEmbeddedMedia({
|
||||
|
||||
function destroy() {
|
||||
offLocale();
|
||||
worded.clear();
|
||||
hide({ immediate: true });
|
||||
for (const current of [...leavingRecords]) removeRecord(current);
|
||||
clearWarm();
|
||||
removePostRender?.();
|
||||
destroyed = true;
|
||||
renderVue(null, root);
|
||||
root.remove();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user