Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-cli-osc-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cuecue/cli': patch
---

`cuecue osc-output` works again: it imported an `OscOutput` that `@cuecue/osc` doesn't export, and never opened its OSC client. It now sends the message, prints it, and exits with an error code when sending fails.
19 changes: 19 additions & 0 deletions .changeset/fix-show-stoppers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@cuecue/app': patch
'@cuecue/http': patch
'@cuecue/osc': patch
'@cuecue/pubnub': patch
'@cuecue/socketio': patch
'@cuecue/store-mysql': patch
---

Fixes that keep a show running:

- `@cuecue/app`: an output that fails no longer stops the app, nor the other outputs: the failure is logged with the new `logger` option (`console` by default). A command from an input that fails is logged too.
- `@cuecue/app`: `reset` and `resetInteractions` after `end` are ignored instead of stopping the app.
- `@cuecue/app`: a cue's `duration` stops when another cue starts: it no longer uncues the next cue. The duration is a timer instead of a check every 10 ms, and `after_duration: 'next'` goes to the next cue of the session, defined cues included.
- `@cuecue/osc`, `@cuecue/pubnub`, `@cuecue/http`, `@cuecue/socketio`: outputs return the promise of `cue()`, `interact()` and the like, so that the app can catch their failures. PubNub's failed publishes reject with an `Error`.
- `@cuecue/pubnub`, `@cuecue/socketio`: inputs emit the command that `transformCommand` returns, not the original one.
- `@cuecue/socketio`: `ServerOutput` sends to the namespace that `transformCommand` returns.
- `@cuecue/osc`: inputs and outputs can be destroyed before they are initialized.
- `@cuecue/store-mysql`: the store uses a pool of one connection, which replaces a lost connection, and a connection error no longer stops the process. `destroy()` works, and `autoConnect` connects after `init()`.
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

132 changes: 65 additions & 67 deletions packages/app/src/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Application extends EventEmitter {
this.options = {
store: new MemoryStore(),
debugFunction: createDebug('cuecue:app'),
// Where failed outputs and commands are logged, with logger.error()
logger: console,
getHandle: (id) => `${id}_${dayjs().format('YYYY_MM_DD')}_${Date.now().toString(36)}`,
validateCommand: (command) =>
[
Expand Down Expand Up @@ -150,6 +152,10 @@ class Application extends EventEmitter {
}

async reset() {
if (this.session === null) {
this.debug('reset ignored: no session');
return;
}
await this.resetSessionInteractions();
await this.resetSession();
await this.uncue();
Expand Down Expand Up @@ -219,9 +225,13 @@ class Application extends EventEmitter {
}

async resetInteractions(...args) {
if (this.session === null) {
this.debug('resetInteractions ignored: no session');
return;
}
const ids = args || [];

this.resetInteractidonsByIds(ids);
await this.resetInteractionsByIds(ids);

await this.sendUninteractionsToOutputs(ids);
}
Expand All @@ -232,7 +242,7 @@ class Application extends EventEmitter {
});
}

async resetInteractidonsByIds(ids) {
async resetInteractionsByIds(ids) {
return Promise.all(
ids.map((id) =>
this.store.deleteItems('interactions', {
Expand Down Expand Up @@ -400,7 +410,10 @@ class Application extends EventEmitter {
return process.nextTick(() => {
this.emit('idle');

// Recover
// Recover, unless the session ended meanwhile
if (this.session === null) {
return;
}
const { cue = null, ended = false, data = null } = this.session;
if (ended) {
this.end();
Expand Down Expand Up @@ -432,6 +445,9 @@ class Application extends EventEmitter {
return false;
}

// The previous cue's duration doesn't apply to this one.
this.stopCueDurationInterval();

const { id = null, stateful = false } = cue;
if (stateful) {
this.debug('Stateful cue: %s', id);
Expand Down Expand Up @@ -468,19 +484,19 @@ class Application extends EventEmitter {
async onCueDurationEnd(cue) {
this.debug('Cue %s duration is ended', cue.id);
const { after_duration: afterDuration = null } = cue;
const { cues = [] } = this.definition;
const cues = (await this.getCues()) || [];
switch (afterDuration) {
case 'next': {
const cueIndex = cues.findIndex((it) => it.id === cue.id);
const nextCue =
cueIndex !== -1 && cueIndex < cues.length - 1 ? cues[cueIndex + 1] : null;
if (nextCue !== null) {
this.cue(nextCue.id);
await this.cue(nextCue.id);
}
break;
}
default:
this.uncue();
await this.uncue();
break;
}
}
Expand Down Expand Up @@ -542,10 +558,10 @@ class Application extends EventEmitter {

this.emit('input:command', finalCommand, finalArgs);

this[finalCommand](...finalArgs);
this.debug(this[finalCommand], finalArgs);
await this[finalCommand](...finalArgs);
} catch (e) {
this.debug(`Error with command "${command}": ${e.message}`);
const { logger } = this.options;
logger.error(`[cuecue] The command "${command}" failed: ${e.message}`);
}
}

Expand Down Expand Up @@ -578,24 +594,22 @@ class Application extends EventEmitter {
}

startCueDurationInterval(cue) {
const { duration = null } = cue;
const startTime = new Date().getTime();
this.debug('Starting interval for %i for cue %s...', duration, cue.id);
this.cueDurationInterval = setInterval(() => {
const currentTime = new Date().getTime();
const currentDuration = Math.floor((currentTime - startTime) / 1000);
if (currentDuration >= duration) {
clearInterval(this.cueDurationInterval);
this.cueDurationInterval = null;
this.onCueDurationEnd(cue);
}
}, 10);
const { id, duration = null } = cue;
this.stopCueDurationInterval();
this.debug('Cue %s ends in %s s', id, duration);
this.cueDurationInterval = setTimeout(() => {
this.cueDurationInterval = null;
this.onCueDurationEnd(cue).catch((error) => {
const { logger } = this.options;
logger.error(`[cuecue] Ending the cue "${id}" failed: ${error.message}`);
});
}, duration * 1000);
}

stopCueDurationInterval() {
if (this.cueDurationInterval !== null) {
this.debug('Stopping interval for cue...');
clearInterval(this.cueDurationInterval);
this.debug('Stopping the duration of the cue...');
clearTimeout(this.cueDurationInterval);
this.cueDurationInterval = null;
}
}
Expand Down Expand Up @@ -728,77 +742,61 @@ class Application extends EventEmitter {
);
}

sendCueToOutputs(cue, sessionData = null) {
this.debug('Send cue to outputs: %O %O', cue, sessionData);
/**
* Calls a method of every output that has it. An output that fails is logged and never stops
* the others, nor the show.
*/
sendToOutputs(method, ...args) {
const { logger } = this.options;
const name = method === 'command' ? args[0] : method;
return Promise.all(
this.outputs.map((it) =>
typeof it.cue !== 'undefined' ? it.cue(cue, sessionData) : Promise.resolve(),
this.outputs.map((output) =>
typeof output[method] !== 'undefined'
? Promise.resolve()
.then(() => output[method](...args))
.catch((error) => {
logger.error(
`[cuecue] An output failed on "${name}": ${error.message}`,
);
})
: Promise.resolve(),
),
);
}

sendCueToOutputs(cue, sessionData = null) {
this.debug('Send cue to outputs: %O %O', cue, sessionData);
return this.sendToOutputs('cue', cue, sessionData);
}

sendCuesToOutputs(cues) {
this.debug('Send cues to outputs: %O', cues);
return Promise.all(
this.outputs.map((it) =>
typeof it.cues !== 'undefined' ? it.cues(cues) : Promise.resolve(),
),
);
return this.sendToOutputs('cues', cues);
}

sendInteractToOutputs(data, interactionId) {
this.debug('Send interact to outputs: %O %s', data, interactionId);
return Promise.all(
this.outputs.map((it) =>
typeof it.interact !== 'undefined'
? it.interact(data, interactionId)
: Promise.resolve(),
),
);
return this.sendToOutputs('interact', data, interactionId);
}

sendInteractionToOutputs(interaction) {
this.debug('Send interaction to outputs: %O', interaction);
return Promise.all(
this.outputs.map((it) =>
typeof it.interaction !== 'undefined'
? it.interaction(interaction)
: Promise.resolve(),
),
);
return this.sendToOutputs('interaction', interaction);
}

sendUninteractionToOutputs(interactionId) {
this.debug('Send interact to outputs: %O %s', interactionId);
return Promise.all(
this.outputs.map((it) =>
typeof it.uninteraction !== 'undefined'
? it.uninteraction(interactionId)
: Promise.resolve(),
),
);
return this.sendToOutputs('uninteraction', interactionId);
}

sendUninteractionsToOutputs(interactionIds) {
this.debug('Send uninteractions to outputs: %O', interactionIds);
return Promise.all(
this.outputs.map((it) =>
typeof it.uninteractions !== 'undefined'
? it.uninteractions(interactionIds)
: Promise.resolve(),
),
);
return this.sendToOutputs('uninteractions', interactionIds);
}

sendCommandToOutputs(command, ...args) {
this.debug(`Send command to outputs: %s %o`, command, args);
return Promise.all(
this.outputs.map((it) =>
typeof it.command !== 'undefined'
? it.command(command, ...args)
: Promise.resolve(),
),
);
return this.sendToOutputs('command', command, ...args);
}

stopInputs() {
Expand Down
Loading