Added connection state

Added some basic actions
This commit is contained in:
2023-11-03 15:55:55 -04:00
parent 03706849b3
commit 8228396309
6 changed files with 112 additions and 48 deletions

View File

@@ -1,3 +1,3 @@
# companion-module-[replace with module name]
# companion-module-voicemod
See [HELP.md](./companion/HELP.md) and [LICENSE](./LICENSE)

View File

@@ -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()
},
},
})

View File

@@ -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"]
}

56
main.js
View File

@@ -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() {

View File

@@ -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"

View File

@@ -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([])
}