mirror of
https://github.com/RavenX8/companion-module-voicemod.git
synced 2026-04-03 12:58:52 -04:00
### 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:
@@ -7,7 +7,7 @@ module.exports = function (self) {
|
||||
id: 'voiceId',
|
||||
type: 'dropdown',
|
||||
label: 'Voice',
|
||||
default: self.vm.voices[0].id,
|
||||
default: '',
|
||||
choices: self.vm.voices.map((item) => ({ id: item.id, label: item.name })),
|
||||
},
|
||||
],
|
||||
|
||||
143
main.js
143
main.js
@@ -9,6 +9,9 @@ class ModuleInstance extends InstanceBase {
|
||||
constructor(internal) {
|
||||
super(internal)
|
||||
|
||||
this.loaded = false
|
||||
this.failure = 0
|
||||
|
||||
this.config = {}
|
||||
this.memes = []
|
||||
this.backgroundEffectsEnabled = false
|
||||
@@ -18,74 +21,84 @@ class ModuleInstance extends InstanceBase {
|
||||
this.muteMemesEnabled = false
|
||||
}
|
||||
|
||||
sleep(ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
async init(config) {
|
||||
this.config = config
|
||||
this.log('debug', 'init called')
|
||||
|
||||
this.updateStatus(InstanceStatus.Connecting)
|
||||
this.vm = new VoiceMod(this.config.host, this.config.apiKey === '' ? 'anyClient' : this.config.apiKey)
|
||||
try {
|
||||
this.vm.init().then(
|
||||
async () => {
|
||||
this.vm.internal.on('backgroundEffectsEnabledEvent', (background) => {
|
||||
this.backgroundEffectsEnabled = true
|
||||
this.checkFeedbacks('BackgroundEffectState')
|
||||
})
|
||||
this.vm.internal.on('backgroundEffectsDisabledEvent', (background) => {
|
||||
this.backgroundEffectsEnabled = false
|
||||
this.checkFeedbacks('BackgroundEffectState')
|
||||
})
|
||||
this.vm.internal.on('voiceChangerEnabledEvent', (data) => {
|
||||
this.voiceChangerEnabled = true
|
||||
this.checkFeedbacks('VoiceChangerState')
|
||||
})
|
||||
this.vm.internal.on('voiceChangerDisabledEvent', (data) => {
|
||||
this.voiceChangerEnabled = false
|
||||
this.checkFeedbacks('VoiceChangerState')
|
||||
})
|
||||
this.vm.internal.on('hearMySelfEnabledEvent', (data) => {
|
||||
this.hearMyVoiceEnabled = true
|
||||
this.checkFeedbacks('HearMyVoiceState')
|
||||
})
|
||||
this.vm.internal.on('hearMySelfDisabledEvent', (data) => {
|
||||
this.hearMyVoiceEnabled = false
|
||||
this.checkFeedbacks('HearMyVoiceState')
|
||||
})
|
||||
this.vm.internal.on('muteMicrophoneEnabledEvent', (data) => {
|
||||
this.muteEnabled = true
|
||||
this.checkFeedbacks('MicMutedState')
|
||||
})
|
||||
this.vm.internal.on('muteMicrophoneDisabledEvent', (data) => {
|
||||
this.muteEnabled = false
|
||||
this.checkFeedbacks('MicMutedState')
|
||||
})
|
||||
this.vm.internal.on('muteMemeForMeEnabledEvent', (data) => {
|
||||
this.muteMemesEnabled = true
|
||||
this.checkFeedbacks('MemesMutedForMeState')
|
||||
})
|
||||
this.vm.internal.on('muteMemeForMeDisabledEvent', (data) => {
|
||||
this.muteMemesEnabled = false
|
||||
this.checkFeedbacks('MemesMutedForMeState')
|
||||
})
|
||||
this.vm.internal.getVoiceChangerStatus()
|
||||
this.vm.internal.getBackgroundEffectStatus()
|
||||
this.vm.internal.getMuteMicStatus()
|
||||
this.vm.internal.getMuteMemeForMeStatus()
|
||||
do {
|
||||
this.updateStatus(InstanceStatus.Connecting)
|
||||
this.vm = new VoiceMod(this.config.host, this.config.apiKey === '' ? 'anyClient' : this.config.apiKey)
|
||||
try {
|
||||
this.vm.init().then(
|
||||
async () => {
|
||||
this.vm.internal.on('backgroundEffectsEnabledEvent', (background) => {
|
||||
this.backgroundEffectsEnabled = true
|
||||
this.checkFeedbacks('BackgroundEffectState')
|
||||
})
|
||||
this.vm.internal.on('backgroundEffectsDisabledEvent', (background) => {
|
||||
this.backgroundEffectsEnabled = false
|
||||
this.checkFeedbacks('BackgroundEffectState')
|
||||
})
|
||||
this.vm.internal.on('voiceChangerEnabledEvent', (data) => {
|
||||
this.voiceChangerEnabled = true
|
||||
this.checkFeedbacks('VoiceChangerState')
|
||||
})
|
||||
this.vm.internal.on('voiceChangerDisabledEvent', (data) => {
|
||||
this.voiceChangerEnabled = false
|
||||
this.checkFeedbacks('VoiceChangerState')
|
||||
})
|
||||
this.vm.internal.on('hearMySelfEnabledEvent', (data) => {
|
||||
this.hearMyVoiceEnabled = true
|
||||
this.checkFeedbacks('HearMyVoiceState')
|
||||
})
|
||||
this.vm.internal.on('hearMySelfDisabledEvent', (data) => {
|
||||
this.hearMyVoiceEnabled = false
|
||||
this.checkFeedbacks('HearMyVoiceState')
|
||||
})
|
||||
this.vm.internal.on('muteMicrophoneEnabledEvent', (data) => {
|
||||
this.muteEnabled = true
|
||||
this.checkFeedbacks('MicMutedState')
|
||||
})
|
||||
this.vm.internal.on('muteMicrophoneDisabledEvent', (data) => {
|
||||
this.muteEnabled = false
|
||||
this.checkFeedbacks('MicMutedState')
|
||||
})
|
||||
this.vm.internal.on('muteMemeForMeEnabledEvent', (data) => {
|
||||
this.muteMemesEnabled = true
|
||||
this.checkFeedbacks('MemesMutedForMeState')
|
||||
})
|
||||
this.vm.internal.on('muteMemeForMeDisabledEvent', (data) => {
|
||||
this.muteMemesEnabled = false
|
||||
this.checkFeedbacks('MemesMutedForMeState')
|
||||
})
|
||||
this.vm.internal.getVoiceChangerStatus()
|
||||
this.vm.internal.getBackgroundEffectStatus()
|
||||
this.vm.internal.getMuteMicStatus()
|
||||
this.vm.internal.getMuteMemeForMeStatus()
|
||||
|
||||
this.updateStatus(InstanceStatus.Ok)
|
||||
this.updateActionsFeedbacksVariables()
|
||||
this.updateStatus(InstanceStatus.Ok)
|
||||
this.updateActionsFeedbacksVariables()
|
||||
|
||||
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)
|
||||
}
|
||||
this.loaded = true
|
||||
this.log('debug', 'connected to VM and ready')
|
||||
},
|
||||
(reason) => {
|
||||
this.log('debug', reason)
|
||||
this.updateStatus(InstanceStatus.ConnectionFailure)
|
||||
++this.failure
|
||||
}
|
||||
)
|
||||
} catch (e) {
|
||||
this.log('debug', e)
|
||||
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
|
||||
async destroy() {
|
||||
@@ -137,6 +150,12 @@ class ModuleInstance extends InstanceBase {
|
||||
|
||||
updateVariableDefinitions() {
|
||||
UpdateVariableDefinitions(this)
|
||||
|
||||
this.setVariableValues({
|
||||
microphoneMuted: this.muteEnabled,
|
||||
voiceChangerStatus: !this.voiceChangerEnabled,
|
||||
voiceSelected: undefined,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "voicemod-api",
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.0",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"format": "prettier -w ."
|
||||
@@ -12,7 +12,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@companion-module/base": "~1.5.1",
|
||||
"voicemod": "^0.1.6"
|
||||
"voicemod": "git+https://github.com/RavenX8/voicemod-api.git#companion-module-voicemod-api"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@companion-module/tools": "^1.4.1"
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
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' },
|
||||
])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user