fix: initialize voice encryption libs before first connection

- await sodium.ready + nacl preload (same as original jukebox)
- Add generateDependencyReport() for debugging
- Add type declarations for libsodium-wrappers and tweetnacl

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Daniel 2026-03-06 01:13:46 +01:00
parent 1d4a48cf74
commit 9ac1034e5e
2 changed files with 11 additions and 0 deletions

View file

@ -9,8 +9,11 @@ import {
joinVoiceChannel, createAudioPlayer, createAudioResource,
AudioPlayerStatus, NoSubscriberBehavior, getVoiceConnection,
VoiceConnectionStatus, StreamType, entersState,
generateDependencyReport,
type VoiceConnection, type AudioResource,
} from '@discordjs/voice';
import sodium from 'libsodium-wrappers';
import nacl from 'tweetnacl';
import { ChannelType, Events, type VoiceState, type Message } from 'discord.js';
import type { Plugin, PluginContext } from '../../core/plugin.js';
import { sseBroadcast } from '../../core/sse.js';
@ -481,6 +484,12 @@ const soundboardPlugin: Plugin = {
fs.mkdirSync(SOUNDS_DIR, { recursive: true });
fs.mkdirSync(NORM_CACHE_DIR, { recursive: true });
persistedState = readPersistedState();
// Voice encryption libs must be initialized before first voice connection
await sodium.ready;
void nacl.randomBytes(1);
console.log(generateDependencyReport());
console.log(`[Soundboard] ${listAllSounds().length} sounds, ${persistedState.totalPlays ?? 0} total plays`);
},

2
server/src/types/modules.d.ts vendored Normal file
View file

@ -0,0 +1,2 @@
declare module "libsodium-wrappers";
declare module "tweetnacl";