From 03706849b3672bfd28a30bf9936a374a4607cec9 Mon Sep 17 00:00:00 2001 From: Christopher Torres <7156279+RavenX8@users.noreply.github.com> Date: Mon, 30 Oct 2023 20:36:51 -0400 Subject: [PATCH] Initial commit --- .gitignore | 4 +++ .prettierignore | 2 ++ LICENSE | 21 ++++++++++++++ README.md | 3 ++ actions.js | 20 +++++++++++++ companion/HELP.md | 3 ++ companion/manifest.json | 26 +++++++++++++++++ feedbacks.js | 33 +++++++++++++++++++++ main.js | 63 +++++++++++++++++++++++++++++++++++++++++ package.json | 20 +++++++++++++ upgrades.js | 13 +++++++++ variables.js | 7 +++++ 12 files changed, 215 insertions(+) create mode 100644 .gitignore create mode 100644 .prettierignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 actions.js create mode 100644 companion/HELP.md create mode 100644 companion/manifest.json create mode 100644 feedbacks.js create mode 100644 main.js create mode 100644 package.json create mode 100644 upgrades.js create mode 100644 variables.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..27cb7b2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +package-lock.json +/pkg +/pkg.tgz \ No newline at end of file diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..f54ff83 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +package.json +/LICENSE.md \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0f6be20 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Bitfocus AS - Open Source + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6746243 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# companion-module-[replace with module name] + +See [HELP.md](./companion/HELP.md) and [LICENSE](./LICENSE) diff --git a/actions.js b/actions.js new file mode 100644 index 0000000..b9da0f7 --- /dev/null +++ b/actions.js @@ -0,0 +1,20 @@ +module.exports = function (self) { + self.setActionDefinitions({ + sample_action: { + name: 'My First Action', + options: [ + { + id: 'num', + type: 'number', + label: 'Test', + default: 5, + min: 0, + max: 100, + }, + ], + callback: async (event) => { + console.log('Hello world!', event.options.num) + }, + }, + }) +} diff --git a/companion/HELP.md b/companion/HELP.md new file mode 100644 index 0000000..e77197b --- /dev/null +++ b/companion/HELP.md @@ -0,0 +1,3 @@ +## Your module + +Write some help for your users here! diff --git a/companion/manifest.json b/companion/manifest.json new file mode 100644 index 0000000..ad77bef --- /dev/null +++ b/companion/manifest.json @@ -0,0 +1,26 @@ +{ + "id": "your-module-name", + "name": "your-module-name", + "shortname": "module-shortname", + "description": "A short one line description of your module", + "version": "0.0.0", + "license": "MIT", + "repository": "git+https://github.com/bitfocus/companion-module-your-module-name.git", + "bugs": "https://github.com/bitfocus/companion-module-your-module-name/issues", + "maintainers": [ + { + "name": "Your name", + "email": "Your email" + } + ], + "runtime": { + "type": "node18", + "api": "nodejs-ipc", + "apiVersion": "0.0.0", + "entrypoint": "../main.js" + }, + "legacyIds": [], + "manufacturer": "Your company", + "products": ["Your product"], + "keywords": [] +} diff --git a/feedbacks.js b/feedbacks.js new file mode 100644 index 0000000..1f331c7 --- /dev/null +++ b/feedbacks.js @@ -0,0 +1,33 @@ +const { combineRgb } = require('@companion-module/base') + +module.exports = async function (self) { + self.setFeedbackDefinitions({ + ChannelState: { + name: 'Example Feedback', + type: 'boolean', + label: 'Channel State', + defaultStyle: { + bgcolor: combineRgb(255, 0, 0), + color: combineRgb(0, 0, 0), + }, + options: [ + { + id: 'num', + type: 'number', + label: 'Test', + default: 5, + min: 0, + max: 10, + }, + ], + callback: (feedback) => { + console.log('Hello world!', feedback.options.num) + if (feedback.options.num > 5) { + return true + } else { + return false + } + }, + }, + }) +} diff --git a/main.js b/main.js new file mode 100644 index 0000000..42485cc --- /dev/null +++ b/main.js @@ -0,0 +1,63 @@ +const { InstanceBase, Regex, runEntrypoint, InstanceStatus } = require('@companion-module/base') +const UpgradeScripts = require('./upgrades') +const UpdateActions = require('./actions') +const UpdateFeedbacks = require('./feedbacks') +const UpdateVariableDefinitions = require('./variables') + +class ModuleInstance extends InstanceBase { + constructor(internal) { + super(internal) + } + + async init(config) { + this.config = config + + this.updateStatus(InstanceStatus.Ok) + + this.updateActions() // export actions + this.updateFeedbacks() // export feedbacks + this.updateVariableDefinitions() // export variable definitions + } + // When module gets deleted + async destroy() { + this.log('debug', 'destroy') + } + + async configUpdated(config) { + this.config = config + } + + // Return config fields for web config + getConfigFields() { + return [ + { + type: 'textinput', + id: 'host', + label: 'Target IP', + width: 8, + regex: Regex.IP, + }, + { + type: 'textinput', + id: 'port', + label: 'Target Port', + width: 4, + regex: Regex.PORT, + }, + ] + } + + updateActions() { + UpdateActions(this) + } + + updateFeedbacks() { + UpdateFeedbacks(this) + } + + updateVariableDefinitions() { + UpdateVariableDefinitions(this) + } +} + +runEntrypoint(ModuleInstance, UpgradeScripts) diff --git a/package.json b/package.json new file mode 100644 index 0000000..656f6cb --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "your-module-name", + "version": "0.1.0", + "main": "main.js", + "scripts": { + "format": "prettier -w ." + }, + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/bitfocus/companion-module-your-module-name.git" + }, + "dependencies": { + "@companion-module/base": "~1.5.1" + }, + "devDependencies": { + "@companion-module/tools": "^1.4.1" + }, + "prettier": "@companion-module/tools/.prettierrc.json" +} diff --git a/upgrades.js b/upgrades.js new file mode 100644 index 0000000..d9d6472 --- /dev/null +++ b/upgrades.js @@ -0,0 +1,13 @@ +module.exports = [ + /* + * Place your upgrade scripts here + * Remember that once it has been added it cannot be removed! + */ + // function (context, props) { + // return { + // updatedConfig: null, + // updatedActions: [], + // updatedFeedbacks: [], + // } + // }, +] diff --git a/variables.js b/variables.js new file mode 100644 index 0000000..a4c9f8c --- /dev/null +++ b/variables.js @@ -0,0 +1,7 @@ +module.exports = async function (self) { + self.setVariableDefinitions([ + { variableId: 'variable1', name: 'My first variable' }, + { variableId: 'variable2', name: 'My second variable' }, + { variableId: 'variable3', name: 'Another variable' }, + ]) +}