caelum0x d56639a594
Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

96 lines
3.5 KiB
JavaScript

/*
* Menivor cast receiver (Wave Q QM1.4, P-M16).
*
* Structure follows googlecast/CastReceiver js/receiver.js (Apache-2.0,
* commit ddfb06c7fb94db902d7706f610553d8dd4ba85e7): a LOAD message
* interceptor on the CAF PlayerManager. Our part: the sender passes
* customData {apiBase, titleId, session, deviceId}; the receiver checks apiBase
* against the build-time allowlist (config.js), fetches its own playback grant, refreshes it a minute before the 10-minute token ends,
* and rewrites manifest, segment and key requests to the newest token.
*/
import { markSpot, untilNextMove } from "./mark.js";
import { grantFetcher, readCast, TokenKeeper } from "./token.js";
const context = cast.framework.CastReceiverContext.getInstance();
const playerManager = context.getPlayerManager();
const playbackConfig = new cast.framework.PlaybackConfig();
let keeper = null;
let markTimer = null;
/** A visible message on the TV when a cast is refused (an empty string hides it). */
function showStatus(message) {
const el = document.getElementById("status");
if (!el) return;
el.textContent = message;
el.hidden = !message;
}
/** The moving viewer code over a paid title (QM1.5): faint, moves every 30 s; "" removes it. */
function showMark(mark) {
const el = document.getElementById("viewer-mark");
if (markTimer) clearTimeout(markTimer);
markTimer = null;
if (!el) return;
el.textContent = mark;
el.hidden = !mark;
if (!mark) return;
const move = () => {
const spot = markSpot(mark, Date.now());
el.style.left = `${spot.left}%`;
el.style.top = `${spot.top}%`;
markTimer = setTimeout(move, untilNextMove(Date.now()));
};
move();
}
function rewrite(requestInfo) {
if (keeper) requestInfo.url = keeper.rewrite(requestInfo.url);
}
playbackConfig.manifestRequestHandler = rewrite;
playbackConfig.segmentRequestHandler = rewrite;
playbackConfig.licenseRequestHandler = rewrite;
function loadError(reason) {
const error = new cast.framework.messages.ErrorData(cast.framework.messages.ErrorType.LOAD_FAILED);
error.reason = reason;
return error;
}
playerManager.setMessageInterceptor(cast.framework.messages.MessageType.LOAD, async (loadRequestData) => {
const parsed = readCast(loadRequestData && loadRequestData.customData);
if (!loadRequestData || !loadRequestData.media || !parsed.data) {
// Refused before any network request: the API address is off the allowlist or the request is incomplete.
showMark("");
showStatus(parsed.error || "This cast request is incomplete.");
return loadError(cast.framework.messages.ErrorReason.INVALID_REQUEST);
}
showStatus("");
if (keeper) keeper.stop();
keeper = new TokenKeeper(grantFetcher(parsed.data, (url, init) => fetch(url, init)));
try {
loadRequestData.media.contentUrl = await keeper.start();
} catch {
keeper.stop();
keeper = null;
showMark("");
showStatus("This video could not start on the TV.");
return loadError(cast.framework.messages.ErrorReason.NOT_AVAILABLE);
}
showMark(keeper.mark);
loadRequestData.media.contentType = "application/x-mpegURL";
// The packager writes fMP4 (CMAF) segments.
loadRequestData.media.hlsSegmentFormat = cast.framework.messages.HlsSegmentFormat.FMP4;
loadRequestData.media.hlsVideoSegmentFormat = cast.framework.messages.HlsVideoSegmentFormat.FMP4;
return loadRequestData;
});
playerManager.addEventListener(cast.framework.events.EventType.MEDIA_FINISHED, () => {
if (keeper) keeper.stop();
keeper = null;
showMark("");
});
context.start({ playbackConfig, disableIdleTimeout: false });