Skip to content

Commit

Permalink
Adding debug logging to help debug donation sound issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zoton2 committed Dec 9, 2023
1 parent 4275311 commit 2e50b1d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/extension/omnibar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,29 +216,42 @@ nodecg().listenFor('omnibarShowNext', (data, ack) => {
});

// Listens for messages from the graphic to play the "donation" SFX via OBS source.
nodecg().listenFor('omnibarPlaySound', async (data: { amount?: number }, ack) => {
nodecg().listenFor('omnibarPlaySound', async (data: { amount?: number } | undefined, ack) => {
if (config.obs.enabled && obs.connected) {
try {
nodecg().log.debug('omnibarPlaySound called with amount %s', data?.amount || 'none');
const alert = orderBy(donationAlerts.value, (v) => v.threshold, 'desc')
.find((v) => v.threshold <= (data.amount ?? 0));
.find((v) => v.threshold <= (data?.amount ?? 0));
const asset = assetsDonationAlertAssets.value.find((a) => alert && a.name === alert?.sound);
nodecg().log.debug(
'[Omnibar] omnibarPlaySound called, alert %s, asset %s',
alert?.sound || 'not found',
asset?.name || 'not found',
);
if (alert && asset) {
const source = await obs.conn.send('GetSourceSettings', {
sourceName: config.obs.names.sources.donationSound,
});
nodecg().log.debug('[Omnibar] omnibarPlaySound OBS source found');
const location = join(cwd(), `assets/${asset.namespace}/${asset.category}/${asset.base}`);
nodecg().log.debug('[Omnibar] omnibarPlaySound location of sound:', location);
// Set volume of source.
await obs.conn.send('SetVolume', {
source: config.obs.names.sources.donationSound,
volume: Math.min(alert.volume, 0),
useDecibel: true,
});
nodecg().log.debug(
'[Omnibar] omnibarPlaySound volume set to %s',
Math.min(alert.volume, 0),
);
// File is the same as before, just restart it.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((source.sourceSettings as any).local_file === location) {
await obs.conn.send('RestartMedia', {
sourceName: config.obs.names.sources.donationSound,
});
nodecg().log.debug('[Omnibar] omnibarPlaySound media restarted');
// If different, explicitily set it. This also starts the playback.
} else {
await obs.conn.send('SetSourceSettings', {
Expand All @@ -250,9 +263,12 @@ nodecg().listenFor('omnibarPlaySound', async (data: { amount?: number }, ack) =>
restart_on_active: false,
},
});
nodecg().log.debug('[Omnibar] omnibarPlaySound source settings set');
}
}
} catch (err) { /* catch */ }
} catch (err) {
nodecg().log.error('[Omnibar] omnibarPlaySound error:', err);
}
}
if (ack && !ack?.handled) ack();
});
Expand Down

0 comments on commit 2e50b1d

Please sign in to comment.