Skip to content
Snippets Groups Projects
Commit 7cb0bdfb authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

#187 - Add feedback for pad status

parent 3502e7b1
No related branches found
No related tags found
No related merge requests found
...@@ -2,30 +2,30 @@ const { combineRgb } = require('@companion-module/base') ...@@ -2,30 +2,30 @@ const { combineRgb } = require('@companion-module/base')
module.exports = async function (self) { module.exports = async function (self) {
self.setFeedbackDefinitions({ self.setFeedbackDefinitions({
ChannelState: { PadStatus: {
name: 'Example Feedback', name: 'Pad Status',
type: 'boolean', type: 'boolean',
label: 'Channel State', label: 'Pad Status',
defaultStyle: { defaultStyle: {
bgcolor: combineRgb(255, 0, 0), bgcolor: combineRgb(255, 0, 0),
color: combineRgb(0, 0, 0), color: combineRgb(0, 0, 0),
}, },
options: [ options: [
{ {
id: 'num', id: 'name',
type: 'number', type: 'textinput',
label: 'Test', label: 'Pad Name',
default: 5, default: '',
min: 0,
max: 10,
}, },
], ],
callback: (feedback) => { callback: (feedback, context) => {
console.log('Hello world!', feedback.options.num) self.log('debug', `Update feedback for pad name ${feedback.options.name}`);
if (feedback.options.num > 5) { const pad = self.currentProject.findPadByName(feedback.options.name);
return true if (pad != null) {
self.log('debug', `Update feedback for pad id ${pad.id} with status ${pad.status}`);
return pad.status === 'PLAY';
} else { } else {
return false return false;
} }
}, },
}, },
......
...@@ -7,6 +7,7 @@ const WebSocket = require('ws') ...@@ -7,6 +7,7 @@ const WebSocket = require('ws')
const ProjectUpdate = require("./receive/project_update"); const ProjectUpdate = require("./receive/project_update");
const Project = require("./project"); const Project = require("./project");
const PadNameUpdate = require("./receive/pad_name_update"); const PadNameUpdate = require("./receive/pad_name_update");
const PadStatusUpdate = require("./receive/pad_status_update");
const uuid = require('uuid'); const uuid = require('uuid');
class ModuleInstance extends InstanceBase { class ModuleInstance extends InstanceBase {
...@@ -16,7 +17,8 @@ class ModuleInstance extends InstanceBase { ...@@ -16,7 +17,8 @@ class ModuleInstance extends InstanceBase {
messageHandlers = { messageHandlers = {
'project-current': new ProjectUpdate(), 'project-current': new ProjectUpdate(),
'pad-name-changed': new PadNameUpdate() 'pad-name-changed': new PadNameUpdate(),
'pad-status-changed': new PadStatusUpdate()
}; };
currentProject = new Project({}); currentProject = new Project({});
......
module.exports = class Project { module.exports = class Project {
constructor(data) { constructor(data) {
this.data = data
this.padCache = {} this.padCache = {}
// Prefill with current project // Prefill with current project
...@@ -29,7 +28,38 @@ module.exports = class Project { ...@@ -29,7 +28,38 @@ module.exports = class Project {
delete this.padCache[oldName]; 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) { findPadByName(name) {
return this.padCache[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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment