casparcg-state
Version:
Node.js Javascript/Typescript library for keeping and resolving a given state of CasparCG into commands for casparcg-connection.
121 lines • 5.51 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveEmptyState = void 0;
const util_1 = require("../util");
const api_1 = require("../api");
const casparcg_connection_1 = require("casparcg-connection");
const _ = require("underscore");
function resolveEmptyState(oldState, newState, channel, layer) {
const oldChannel = (0, util_1.getChannel)(oldState, channel);
const oldLayer = (0, util_1.getLayer)(oldState, channel, layer);
const newLayer = (0, util_1.getLayer)(newState, channel, layer);
const diffCmds = {
cmds: [],
};
if (!newLayer.content &&
oldLayer.content !== api_1.LayerContentType.NOTHING &&
!newLayer.nextUp // if there is a nextup, we should do a stop, not a clear
) {
if (oldLayer.noClear) {
// hack: don't do the clear command:
}
else {
let noCommand = false;
let cmd = null;
if (oldLayer.content === api_1.LayerContentType.RECORD) {
cmd = (0, util_1.addContext)((0, util_1.literal)({
command: casparcg_connection_1.Commands.Remove,
params: {
channel: oldChannel.channelNo,
consumer: 'FILE',
},
}), `Old was recording`, oldLayer);
}
else if (typeof oldLayer.media === 'object' && oldLayer.media !== null) {
if (oldLayer.media.outTransition) {
cmd = (0, util_1.addContext)((0, util_1.literal)({
command: casparcg_connection_1.Commands.Play,
params: {
channel: oldChannel.channelNo,
layer: oldLayer.layerNo,
clip: 'empty',
...new api_1.Transition(oldLayer.media.outTransition).getOptions(oldChannel.fps),
},
}), `Old was media and has outTransition`, oldLayer);
}
}
if (!cmd) {
if (oldLayer.content === api_1.LayerContentType.TEMPLATE) {
const ol = oldLayer;
if (ol.cgStop) {
cmd = (0, util_1.addContext)((0, util_1.literal)({
command: casparcg_connection_1.Commands.CgStop,
params: {
channel: oldChannel.channelNo,
layer: oldLayer.layerNo,
cgLayer: 1,
},
}), `Old was template and had cgStop`, oldLayer);
}
}
}
if (oldLayer.content === api_1.LayerContentType.FUNCTION) {
// Functions only trigger action when they start, no action on end
// send nothing
noCommand = true;
}
else if (oldLayer.content === api_1.LayerContentType.MEDIA &&
oldLayer.media &&
oldLayer.media.valueOf() + '' === 'empty') {
// the old layer is an empty, thats essentially something that is cleared
// (or an out transition)
// send nothing then
noCommand = true;
}
if (!noCommand) {
if (!cmd) {
// ClearCommand:
cmd = (0, util_1.addContext)((0, util_1.literal)({
command: casparcg_connection_1.Commands.Clear,
params: {
channel: oldChannel.channelNo,
layer: oldLayer.layerNo,
},
}), `Clear old stuff`, oldLayer);
}
if (cmd) {
(0, util_1.addCommands)(diffCmds, cmd);
}
}
if (oldLayer.mixer && !_.isEmpty(oldLayer.mixer)) {
// reset the mixer because otherwise we lose info about the state it is in. (Should the lib user want to keep them, they should use an empty layer)
(0, util_1.addCommands)(diffCmds, (0, util_1.addContext)((0, util_1.literal)({
command: casparcg_connection_1.Commands.MixerClear,
params: {
channel: oldChannel.channelNo,
layer: oldLayer.layerNo,
},
}), `Clear mixer after clearing foreground`, oldLayer));
}
}
}
if (oldLayer.nextUp && !newLayer.nextUp && (0, util_1.compareAttrs)(oldLayer.nextUp, newLayer, ['media'])) {
const prevClearCommand = _.find(diffCmds.cmds, (cmd) => {
return cmd.command === casparcg_connection_1.Commands.Clear;
});
if (!prevClearCommand) {
// if ClearCommand is run, it clears bg too
(0, util_1.addCommands)(diffCmds, (0, util_1.addContext)((0, util_1.literal)({
command: casparcg_connection_1.Commands.Loadbg,
params: {
channel: oldChannel.channelNo,
layer: oldLayer.layerNo,
clip: 'EMPTY',
},
}), `Clear only old nextUp`, oldLayer));
}
}
return { commands: diffCmds };
}
exports.resolveEmptyState = resolveEmptyState;
//# sourceMappingURL=empty.js.map
;