Skip to content

Commit

Permalink
Merge branch 'v5' into ui-extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
ebiggz authored Nov 27, 2024
2 parents f35cc50 + f593c15 commit 6f3d5e5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firebotv5",
"version": "5.63.2",
"version": "5.64.0",
"description": "Powerful all-in-one bot for Twitch streamers.",
"main": "build/main.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/backend/effects/builtin-effect-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ exports.loadEffects = () => {
'reset-timer',
'run-command',
'run-program',
'send-custom-websocket-event',
'sequential-effect',
'set-user-metadata',
'shoutout',
Expand Down
62 changes: 62 additions & 0 deletions src/backend/effects/builtin/send-custom-websocket-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { EffectType } from "../../../types/effects";
import { EffectCategory } from "../../../shared/effect-constants";
import logger from "../../logwrapper";
import WebSocketServerManager from "../../../server/websocket-server-manager";

const model: EffectType<{
eventName: string;
eventData: string;
}> = {
definition: {
id: "firebot:send-custom-websocket-event",
name: "Send Custom WebSocket Event",
description: "Sends a custom event and any relevant data to all connected WebSocket clients",
icon: "fad fa-plug",
categories: [EffectCategory.ADVANCED, EffectCategory.SCRIPTING],
dependencies: []
},
optionsTemplate: `
<eos-container header="Event Name">
<p class="muted">Enter the name of the event you'd like to send. It will be sent as:<br/><code>custom-event:eventname</code></p>
<firebot-input
model="effect.eventName"
placeholder-text="Enter event name"
menu-position="under"
/>
</eos-container>
<eos-container header="Event Data" pad-top="true">
<p class="muted">Enter any event data that you'd like to include with the event.</p>
<firebot-input
model="effect.eventData"
placeholder-text="Enter event data"
use-text-area="true"
rows="4"
cols="40"
menu-position="under"
/>
</eos-container>
`,
optionsController: () => { },
optionsValidator: (effect) => {
const errors = [];
if (!(effect.eventName?.length > 0)) {
errors.push("Please input an event name.");
}
return errors;
},
onTriggerEvent: async ({ effect }) => {
try {
let data: unknown = effect.eventData ?? {};

try {
data = JSON.parse(effect.eventData);
} catch { }
WebSocketServerManager.triggerEvent(`custom-event:${effect.eventName}`, data as object);
} catch (error) {
logger.error(`Error sending custom WebSocket event ${effect.eventName}`, error);
}
}
};

module.exports = model;

0 comments on commit 6f3d5e5

Please sign in to comment.