### Added

- new state variables
- voicemod connection retry logic

### Fixed
- Fix race-condition crash on init for undefined reference

### Changed
- Updated voicemod-api to a version that has `sharp` patched out
This commit is contained in:
2024-01-14 21:18:39 -05:00
parent cb429c3e72
commit 79ff3ce5a4
4 changed files with 89 additions and 66 deletions

View File

@@ -7,7 +7,7 @@ module.exports = function (self) {
id: 'voiceId', id: 'voiceId',
type: 'dropdown', type: 'dropdown',
label: 'Voice', label: 'Voice',
default: self.vm.voices[0].id, default: '',
choices: self.vm.voices.map((item) => ({ id: item.id, label: item.name })), choices: self.vm.voices.map((item) => ({ id: item.id, label: item.name })),
}, },
], ],

19
main.js
View File

@@ -9,6 +9,9 @@ class ModuleInstance extends InstanceBase {
constructor(internal) { constructor(internal) {
super(internal) super(internal)
this.loaded = false
this.failure = 0
this.config = {} this.config = {}
this.memes = [] this.memes = []
this.backgroundEffectsEnabled = false this.backgroundEffectsEnabled = false
@@ -18,10 +21,15 @@ class ModuleInstance extends InstanceBase {
this.muteMemesEnabled = false this.muteMemesEnabled = false
} }
sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
async init(config) { async init(config) {
this.config = config this.config = config
this.log('debug', 'init called') this.log('debug', 'init called')
do {
this.updateStatus(InstanceStatus.Connecting) this.updateStatus(InstanceStatus.Connecting)
this.vm = new VoiceMod(this.config.host, this.config.apiKey === '' ? 'anyClient' : this.config.apiKey) this.vm = new VoiceMod(this.config.host, this.config.apiKey === '' ? 'anyClient' : this.config.apiKey)
try { try {
@@ -75,17 +83,22 @@ class ModuleInstance extends InstanceBase {
this.updateStatus(InstanceStatus.Ok) this.updateStatus(InstanceStatus.Ok)
this.updateActionsFeedbacksVariables() this.updateActionsFeedbacksVariables()
this.loaded = true
this.log('debug', 'connected to VM and ready') this.log('debug', 'connected to VM and ready')
}, },
(reason) => { (reason) => {
this.log('debug', reason) this.log('debug', reason)
this.updateStatus(InstanceStatus.ConnectionFailure) this.updateStatus(InstanceStatus.ConnectionFailure)
++this.failure
} }
) )
} catch (e) { } catch (e) {
this.log('debug', e) this.log('debug', e)
this.updateStatus(InstanceStatus.UnknownError) this.updateStatus(InstanceStatus.UnknownError)
++this.failure
} }
if (this.loaded === false) await this.sleep(500)
} while (this.loaded === false && this.failure < 5)
} }
// When module gets deleted // When module gets deleted
async destroy() { async destroy() {
@@ -137,6 +150,12 @@ class ModuleInstance extends InstanceBase {
updateVariableDefinitions() { updateVariableDefinitions() {
UpdateVariableDefinitions(this) UpdateVariableDefinitions(this)
this.setVariableValues({
microphoneMuted: this.muteEnabled,
voiceChangerStatus: !this.voiceChangerEnabled,
voiceSelected: undefined,
})
} }
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "voicemod-api", "name": "voicemod-api",
"version": "0.1.0", "version": "0.2.0",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"format": "prettier -w ." "format": "prettier -w ."
@@ -12,7 +12,7 @@
}, },
"dependencies": { "dependencies": {
"@companion-module/base": "~1.5.1", "@companion-module/base": "~1.5.1",
"voicemod": "^0.1.6" "voicemod": "git+https://github.com/RavenX8/voicemod-api.git#companion-module-voicemod-api"
}, },
"devDependencies": { "devDependencies": {
"@companion-module/tools": "^1.4.1" "@companion-module/tools": "^1.4.1"

View File

@@ -1,3 +1,7 @@
module.exports = async function (self) { module.exports = async function (self) {
self.setVariableDefinitions([]) self.setVariableDefinitions([
{ variableId: 'microphoneMuted', name: 'Microphone Muted' },
{ variableId: 'voiceChangerStatus', name: 'Voice Changer Enabled' },
{ variableId: 'voiceSelected', name: 'Current Voice Selected' },
])
} }