Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add static demo option #194

Merged
merged 2 commits into from
Oct 3, 2022
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
4 changes: 2 additions & 2 deletions netlify/functions/serverless/cleanse-query-parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 13 additions & 3 deletions src/docs/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,21 @@
<th scope="row">
<code><a href="#demo">DEMO</a></code>
</th>
<td><code>true</code> or <code>false</code></td>
<td><code>true</code>, <code>false</code>, or <code>static</code></td>
<td><code>{{defaults.DEMO}}</code></td>
<td>
BenDMyers marked this conversation as resolved.
Show resolved Hide resolved
Displays plausible but randomly generated messages instead of a live
feed
<p>
Displays plausible but randomly generated messages instead of a live
feed.
</p>
<ul>
<li>
When <code>true</code>, new messages are added periodically.
</li>
<li>
When <code>static</code>, all messages are shown immediately and no messages are added.
</li>
</ul>
</td>
</tr>
<tr id="clear-message-after">
Expand Down
24 changes: 18 additions & 6 deletions src/scripts/demo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
};

Expand Down Expand Up @@ -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);
}
}

/**
Expand Down