diff --git a/feedbacks.js b/feedbacks.js index 1f331c7a769b1b15642f3ca93b690deb71032004..7fb6e3258dfe9827e74234adcc9506838ec0c8db 100644 --- a/feedbacks.js +++ b/feedbacks.js @@ -2,31 +2,31 @@ const { combineRgb } = require('@companion-module/base') module.exports = async function (self) { self.setFeedbackDefinitions({ - ChannelState: { - name: 'Example Feedback', + PadStatus: { + name: 'Pad Status', type: 'boolean', - label: 'Channel State', + label: 'Pad Status', defaultStyle: { bgcolor: combineRgb(255, 0, 0), color: combineRgb(0, 0, 0), }, options: [ { - id: 'num', - type: 'number', - label: 'Test', - default: 5, - min: 0, - max: 10, + id: 'name', + type: 'textinput', + label: 'Pad Name', + default: '', }, ], - callback: (feedback) => { - console.log('Hello world!', feedback.options.num) - if (feedback.options.num > 5) { - return true - } else { - return false - } + callback: (feedback, context) => { + self.log('debug', `Update feedback for pad name ${feedback.options.name}`); + const pad = self.currentProject.findPadByName(feedback.options.name); + if (pad != null) { + self.log('debug', `Update feedback for pad id ${pad.id} with status ${pad.status}`); + return pad.status === 'PLAY'; + } else { + return false; + } }, }, }) diff --git a/main.js b/main.js index ee804df3b70ef151a8bf28fd83ab20f6bb134ddf..5b12f73fedd64a8fed6119accc7b901a66b46daa 100644 --- a/main.js +++ b/main.js @@ -7,6 +7,7 @@ const WebSocket = require('ws') const ProjectUpdate = require("./receive/project_update"); const Project = require("./project"); const PadNameUpdate = require("./receive/pad_name_update"); +const PadStatusUpdate = require("./receive/pad_status_update"); const uuid = require('uuid'); class ModuleInstance extends InstanceBase { @@ -16,7 +17,8 @@ class ModuleInstance extends InstanceBase { messageHandlers = { 'project-current': new ProjectUpdate(), - 'pad-name-changed': new PadNameUpdate() + 'pad-name-changed': new PadNameUpdate(), + 'pad-status-changed': new PadStatusUpdate() }; currentProject = new Project({}); diff --git a/project.js b/project.js index 7ce958babb34e9e31928a4238c68728ca208c137..57530b344368a9ccde4bacf3fd1a46e022a484e0 100644 --- a/project.js +++ b/project.js @@ -1,6 +1,5 @@ module.exports = class Project { constructor(data) { - this.data = data this.padCache = {} // Prefill with current project @@ -29,7 +28,38 @@ module.exports = class Project { delete this.padCache[oldName]; } + /** + * + * @param {string} padId + * @param {string} newStatus + */ + updatePadStatus(padId, newStatus) { + const pad = this.findPadById(padId); + if (pad != null) { + pad.status = newStatus; + } + } + + /** + * + * @param {string} name + * @returns {*} + */ findPadByName(name) { return this.padCache[name]; } + + /** + * + * @param {string} padId + */ + findPadById(padId) { + for (const id in this.padCache) { + const pad = this.padCache[id]; + if (pad.id === padId) { + return pad + } + } + return null + } } \ No newline at end of file diff --git a/receive/pad_status_update.js b/receive/pad_status_update.js new file mode 100644 index 0000000000000000000000000000000000000000..6a5b03c48d5604efaa233ae0316a32c72bc5ac16 --- /dev/null +++ b/receive/pad_status_update.js @@ -0,0 +1,11 @@ +const MessageExecutable = require("./message_executable"); + +module.exports = class PadStatusUpdate extends MessageExecutable { + + handleMessage(plugin, message) { + plugin.currentProject.updatePadStatus(message.pad, message.status); + plugin.checkFeedbacks(); + } +} + +// {"pad":"8b7ef494-d735-45f9-ab84-c95e299298a6","status":"PLAY","updateType":"pad-status-changed"} \ No newline at end of file