feat: harden isolated Tornado test workflow
This commit is contained in:
57
Web/playout-safety.js
Normal file
57
Web/playout-safety.js
Normal file
@@ -0,0 +1,57 @@
|
||||
(function (root, factory) {
|
||||
"use strict";
|
||||
|
||||
const api = Object.freeze(factory());
|
||||
if (typeof module === "object" && module.exports) module.exports = api;
|
||||
if (root) root.MbnPlayoutSafety = api;
|
||||
})(typeof globalThis === "object" ? globalThis : this, function () {
|
||||
"use strict";
|
||||
|
||||
const connectionStates = new Set([
|
||||
"disabled", "dry-run-ready", "disconnected", "connecting", "connected",
|
||||
"reconnecting", "disconnecting", "faulted", "outcome-unknown", "disposed"
|
||||
]);
|
||||
|
||||
function normalizeConnectionState(value) {
|
||||
const normalized = String(value || "unavailable")
|
||||
.trim()
|
||||
.toLocaleLowerCase("en-US")
|
||||
.replace(/[\s_]+/g, "-");
|
||||
return connectionStates.has(normalized) ? normalized : "unavailable";
|
||||
}
|
||||
|
||||
function responseTimeoutFromNative(value) {
|
||||
const operationTimeout = Number(value);
|
||||
if (!Number.isFinite(operationTimeout) || operationTimeout < 100 || operationTimeout > 300000) {
|
||||
return 15000;
|
||||
}
|
||||
return Math.min(305000, Math.max(5100, Math.trunc(operationTimeout) + 5000));
|
||||
}
|
||||
|
||||
function commandBlockReason(snapshot, command) {
|
||||
if (!snapshot || snapshot.pending) return "busy";
|
||||
if (snapshot.outcomeUnknown) return "outcome-unknown";
|
||||
if (!snapshot.commandAvailable) return "unavailable";
|
||||
|
||||
const onAir = snapshot.engineState === "PROGRAM" || Boolean(snapshot.onAirCode);
|
||||
const prepared = snapshot.engineState === "PREPARED" || Boolean(snapshot.preparedCode);
|
||||
if (command === "next" && !onAir) return "next-requires-on-air";
|
||||
if (command === "take-in" && !prepared) return "take-in-requires-prepare";
|
||||
if (command === "take-out" && !onAir && !prepared) return "nothing-to-take-out";
|
||||
return null;
|
||||
}
|
||||
|
||||
function matchesPendingCommand(pending, payload) {
|
||||
return Boolean(
|
||||
pending && payload &&
|
||||
payload.requestId === pending.requestId &&
|
||||
payload.command === pending.command);
|
||||
}
|
||||
|
||||
return {
|
||||
normalizeConnectionState,
|
||||
responseTimeoutFromNative,
|
||||
commandBlockReason,
|
||||
matchesPendingCommand
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user