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) See [HELP.md](./companion/HELP.md) and [LICENSE](./LICENSE)

View File

@@ -1,19 +1,71 @@
module.exports = function (self) { module.exports = function (self) {
self.setActionDefinitions({ self.setActionDefinitions({
sample_action: { set_voice_id: {
name: 'My First Action', name: 'Set Voice',
options: [ options: [
{ {
id: 'num', id: 'voiceId',
type: 'number', type: 'dropdown',
label: 'Test', label: 'Voice',
default: 5, default: 0,
min: 0, choices: self.vm.voices.map((item) => ({ id: item.id, label: item.name })),
max: 100,
}, },
], ],
callback: async (event) => { 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", "id": "companion-module-voicemod",
"name": "your-module-name", "name": "companion-module-voicemod",
"shortname": "module-shortname", "shortname": "Voicemod",
"description": "A short one line description of your module", "description": "Voicemod control at your fingertips",
"version": "0.0.0", "version": "0.0.0",
"license": "MIT", "license": "MIT",
"repository": "git+https://github.com/bitfocus/companion-module-your-module-name.git", "repository": "git+https://github.com/bitfocus/companion-module-voicemod.git",
"bugs": "https://github.com/bitfocus/companion-module-your-module-name/issues", "bugs": "https://github.com/bitfocus/companion-module-voicemod/issues",
"maintainers": [ "maintainers": [
{ {
"name": "Your name", "name": "Your name",
@@ -20,7 +20,7 @@
"entrypoint": "../main.js" "entrypoint": "../main.js"
}, },
"legacyIds": [], "legacyIds": [],
"manufacturer": "Your company", "manufacturer": "Voicemod",
"products": ["Your product"], "products": ["Voicemod"],
"keywords": [] "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 UpgradeScripts = require('./upgrades')
const UpdateActions = require('./actions') const UpdateActions = require('./actions')
const UpdateFeedbacks = require('./feedbacks') const UpdateFeedbacks = require('./feedbacks')
const UpdateVariableDefinitions = require('./variables') const UpdateVariableDefinitions = require('./variables')
const { VoiceMod } = require('voicemod')
class ModuleInstance extends InstanceBase { class ModuleInstance extends InstanceBase {
constructor(internal) { constructor(internal) {
super(internal) super(internal)
this.config = {}
this.memes = []
} }
async init(config) { async init(config) {
this.config = 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.log('debug', 'connected to VM and ready')
this.updateFeedbacks() // export feedbacks },
this.updateVariableDefinitions() // export variable definitions (reason) => {
this.log('debug', reason)
this.updateStatus(InstanceStatus.ConnectionFailure)
}
)
} catch (e) {
this.log('debug', e)
this.updateStatus(InstanceStatus.UnknownError)
}
} }
// When module gets deleted // When module gets deleted
async destroy() { async destroy() {
@@ -25,26 +44,21 @@ class ModuleInstance extends InstanceBase {
async configUpdated(config) { async configUpdated(config) {
this.config = config this.config = config
this.log('debug', 'config updated')
} }
// Return config fields for web config // Return config fields for web config
getConfigFields() { getConfigFields() {
return [ return []
{ }
type: 'textinput',
id: 'host', updateActionsFeedbacksVariables() {
label: 'Target IP', // this.organizeChoices()
width: 8,
regex: Regex.IP, this.updateActions() // export actions
}, // this.updateFeedbacks() // export feedbacks
{ // this.updateVariableDefinitions() // export variable definitions
type: 'textinput', // this.checkFeedbacks()
id: 'port',
label: 'Target Port',
width: 4,
regex: Regex.PORT,
},
]
} }
updateActions() { updateActions() {

View File

@@ -1,5 +1,5 @@
{ {
"name": "your-module-name", "name": "companion-module-voicemod",
"version": "0.1.0", "version": "0.1.0",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
@@ -8,10 +8,12 @@
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "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": { "dependencies": {
"@companion-module/base": "~1.5.1" "@companion-module/base": "~1.5.1",
"voicemod": "^0.1.4",
"ws": "^8.14.2"
}, },
"devDependencies": { "devDependencies": {
"@companion-module/tools": "^1.4.1" "@companion-module/tools": "^1.4.1"

View File

@@ -1,7 +1,3 @@
module.exports = async function (self) { module.exports = async function (self) {
self.setVariableDefinitions([ self.setVariableDefinitions([])
{ variableId: 'variable1', name: 'My first variable' },
{ variableId: 'variable2', name: 'My second variable' },
{ variableId: 'variable3', name: 'Another variable' },
])
} }