diff --git a/netlify/functions/serverless/cleanse-query-parameters.js b/netlify/functions/serverless/cleanse-query-parameters.js index ac48931..4808472 100644 --- a/netlify/functions/serverless/cleanse-query-parameters.js +++ b/netlify/functions/serverless/cleanse-query-parameters.js @@ -5,8 +5,8 @@ const defaults = require('../../../src/_data/defaults'); */ const VALID_PARAMETERS = { DEMO: { - validate: isBoolean, - transform: toBoolean, + validate: (value) => isBoolean(value) || value === 'static', + transform: (value) => (isBoolean(value) ? toBoolean(value) : value), }, clearMessageAfter: { validate: isPositiveInteger, diff --git a/src/docs/configuration.html b/src/docs/configuration.html index 6d3b7ff..b174f85 100644 --- a/src/docs/configuration.html +++ b/src/docs/configuration.html @@ -28,11 +28,21 @@ DEMO - true or false + true, false, or static {{defaults.DEMO}} - Displays plausible but randomly generated messages instead of a live - feed +

+ Displays plausible but randomly generated messages instead of a live + feed. +

+ diff --git a/src/scripts/demo.mjs b/src/scripts/demo.mjs index 62f2e9d..8a1d4ae 100644 --- a/src/scripts/demo.mjs +++ b/src/scripts/demo.mjs @@ -143,7 +143,15 @@ const MOCK_COMFY = (function () { if (channelNames.length) { broadcaster.user = channelNames[0]; } - setTimeout(_generateNextMessage, 500); + + // send all messages at once if the demo page is static + if (window.CONFIG.DEMO === 'static') { + for (let i = 0; i < window.CONFIG.showLatestMessages; i++) { + _generateNextMessage(); + } + } else { + setTimeout(_generateNextMessage, 500); + } }, }; @@ -258,11 +266,15 @@ const MOCK_COMFY = (function () { messages.push(message); comfy.onChat(...message); - // Ready up the next message - const duration = Math.floor(Math.random() * 4) + 3; - const nextGeneratedMessage = - Math.random() < 0.25 ? _generateChatCommand : _generateNextMessage; - setTimeout(nextGeneratedMessage, duration * 1000); + // do not send more messages if the demo page is static + if (window.CONFIG.DEMO !== 'static') { + // Ready up the next message + const nextGeneratedMessage = + Math.random() < 0.25 ? _generateChatCommand : _generateNextMessage; + + const duration = Math.floor(Math.random() * 4) + 3; + setTimeout(nextGeneratedMessage, duration * 1000); + } } /**