From 822839630952f61ee6f3618d314255201f702796 Mon Sep 17 00:00:00 2001 From: RavenX8 <7156279+RavenX8@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:55:55 -0400 Subject: [PATCH] Added connection state Added some basic actions --- README.md | 2 +- actions.js | 70 +++++++++++++++++++++++++++++++++++------ companion/manifest.json | 18 +++++------ main.js | 56 ++++++++++++++++++++------------- package.json | 8 +++-- variables.js | 6 +--- 6 files changed, 112 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 6746243..ea18f3a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# companion-module-[replace with module name] +# companion-module-voicemod See [HELP.md](./companion/HELP.md) and [LICENSE](./LICENSE) diff --git a/actions.js b/actions.js index b9da0f7..a4ee250 100644 --- a/actions.js +++ b/actions.js @@ -1,19 +1,71 @@ module.exports = function (self) { self.setActionDefinitions({ - sample_action: { - name: 'My First Action', + set_voice_id: { + name: 'Set Voice', options: [ { - id: 'num', - type: 'number', - label: 'Test', - default: 5, - min: 0, - max: 100, + id: 'voiceId', + type: 'dropdown', + label: 'Voice', + default: 0, + choices: self.vm.voices.map((item) => ({ id: item.id, label: item.name })), }, ], callback: async (event) => { - console.log('Hello world!', event.options.num) + const voiceId = event.options.voiceId + self.vm.voices[voiceId].load() + }, + }, + set_beep_sound: { + name: 'Set Beep Sound', + options: [ + { + id: 'beepEnabled', + type: 'checkbox', + label: 'Enabled', + default: false, + }, + ], + callback: async (event) => { + self.vm.internal.setBeepSound(event.options.beepEnabled) + }, + }, + toggle_voice_changer: { + name: 'Toggle Voice Changer', + options: [], + callback: async (event) => { + self.vm.internal.toggleVoiceChanger() + }, + }, + play_meme: { + name: 'Play Meme', + options: [ + { + id: 'soundboardId', + type: 'dropdown', + label: 'Soundboard', + default: 0, + choices: self.vm.soundboards.map((item) => ({ id: item.id, label: item.name })), + }, + { + id: 'memeId', + type: 'dropdown', + label: 'Meme', + default: 0, + }, + ], + callback: async (event) => { + console.log('in callback!') + const soundboardId = event.options.soundboardId + const memeId = event.options.memeId + self.vm.soundboards[soundboardId][memeId].play() + }, + }, + stop_all_sounds: { + name: 'Stop all sounds', + options: [], + callback: async (event) => { + self.vm.stopAllSounds() }, }, }) diff --git a/companion/manifest.json b/companion/manifest.json index ad77bef..022656b 100644 --- a/companion/manifest.json +++ b/companion/manifest.json @@ -1,12 +1,12 @@ { - "id": "your-module-name", - "name": "your-module-name", - "shortname": "module-shortname", - "description": "A short one line description of your module", + "id": "companion-module-voicemod", + "name": "companion-module-voicemod", + "shortname": "Voicemod", + "description": "Voicemod control at your fingertips", "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", + "repository": "git+https://github.com/bitfocus/companion-module-voicemod.git", + "bugs": "https://github.com/bitfocus/companion-module-voicemod/issues", "maintainers": [ { "name": "Your name", @@ -20,7 +20,7 @@ "entrypoint": "../main.js" }, "legacyIds": [], - "manufacturer": "Your company", - "products": ["Your product"], - "keywords": [] + "manufacturer": "Voicemod", + "products": ["Voicemod"], + "keywords": ["Audio"] } diff --git a/main.js b/main.js index 42485cc..674f114 100644 --- a/main.js +++ b/main.js @@ -1,22 +1,41 @@ -const { InstanceBase, Regex, runEntrypoint, InstanceStatus } = require('@companion-module/base') +const { InstanceBase, runEntrypoint, InstanceStatus } = require('@companion-module/base') const UpgradeScripts = require('./upgrades') const UpdateActions = require('./actions') const UpdateFeedbacks = require('./feedbacks') const UpdateVariableDefinitions = require('./variables') +const { VoiceMod } = require('voicemod') class ModuleInstance extends InstanceBase { constructor(internal) { super(internal) + + this.config = {} + this.memes = [] } async init(config) { this.config = config + this.log('debug', 'init called') - this.updateStatus(InstanceStatus.Ok) + this.updateStatus(InstanceStatus.Connecting) + this.vm = new VoiceMod() + try { + this.vm.init().then( + async () => { + this.updateStatus(InstanceStatus.Ok) + this.updateActionsFeedbacksVariables() - this.updateActions() // export actions - this.updateFeedbacks() // export feedbacks - this.updateVariableDefinitions() // export variable definitions + this.log('debug', 'connected to VM and ready') + }, + (reason) => { + this.log('debug', reason) + this.updateStatus(InstanceStatus.ConnectionFailure) + } + ) + } catch (e) { + this.log('debug', e) + this.updateStatus(InstanceStatus.UnknownError) + } } // When module gets deleted async destroy() { @@ -25,26 +44,21 @@ class ModuleInstance extends InstanceBase { async configUpdated(config) { this.config = config + this.log('debug', 'config updated') } // 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, - }, - ] + return [] + } + + updateActionsFeedbacksVariables() { + // this.organizeChoices() + + this.updateActions() // export actions + // this.updateFeedbacks() // export feedbacks + // this.updateVariableDefinitions() // export variable definitions + // this.checkFeedbacks() } updateActions() { diff --git a/package.json b/package.json index 656f6cb..b25619a 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "your-module-name", + "name": "companion-module-voicemod", "version": "0.1.0", "main": "main.js", "scripts": { @@ -8,10 +8,12 @@ "license": "MIT", "repository": { "type": "git", - "url": "git+https://github.com/bitfocus/companion-module-your-module-name.git" + "url": "git+https://github.com/RavenX8/companion-module-voicemod.git" }, "dependencies": { - "@companion-module/base": "~1.5.1" + "@companion-module/base": "~1.5.1", + "voicemod": "^0.1.4", + "ws": "^8.14.2" }, "devDependencies": { "@companion-module/tools": "^1.4.1" diff --git a/variables.js b/variables.js index a4c9f8c..fa97146 100644 --- a/variables.js +++ b/variables.js @@ -1,7 +1,3 @@ module.exports = async function (self) { - self.setVariableDefinitions([ - { variableId: 'variable1', name: 'My first variable' }, - { variableId: 'variable2', name: 'My second variable' }, - { variableId: 'variable3', name: 'Another variable' }, - ]) + self.setVariableDefinitions([]) }