fix: correct voice adapter debug wrapper method direction
Previous wrapper intercepted wrong methods (library→adapter vs adapter→library). Now correctly wraps: - sendPayload (adapter→gateway): logs op code and return value - onVoiceServerUpdate/onVoiceStateUpdate (gateway→library): logs incoming events Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
cc5e21fe1c
commit
a13765d5b6
1 changed files with 22 additions and 17 deletions
|
|
@ -294,27 +294,32 @@ function attachVoiceLifecycle(state: GuildAudioState, guild: any) {
|
|||
}
|
||||
|
||||
// ── Debug adapter wrapper ──
|
||||
// voiceAdapterCreator(libraryMethods) → { sendPayload, destroy }
|
||||
// libraryMethods = { onVoiceServerUpdate, onVoiceStateUpdate, destroy }
|
||||
// returned adapter = { sendPayload(payload) → boolean, destroy() }
|
||||
function debugAdapterCreator(guild: any): any {
|
||||
const original = guild.voiceAdapterCreator;
|
||||
return (methods: any) => {
|
||||
const wrappedMethods = {
|
||||
...methods,
|
||||
sendPayload(payload: any) {
|
||||
const result = methods.sendPayload(payload);
|
||||
console.log(`${SB} adapter.sendPayload op=${payload?.op ?? '?'} d.channel_id=${payload?.d?.channel_id ?? '?'} → ${result}`);
|
||||
return result;
|
||||
return (libraryMethods: any) => {
|
||||
// Wrap library methods to log when Discord gateway events arrive
|
||||
const wrappedLibraryMethods = {
|
||||
...libraryMethods,
|
||||
onVoiceServerUpdate(data: any) {
|
||||
console.log(`${SB} ← onVoiceServerUpdate: token=${data?.token ? 'yes' : 'no'} endpoint=${data?.endpoint ?? 'none'}`);
|
||||
return libraryMethods.onVoiceServerUpdate(data);
|
||||
},
|
||||
onVoiceStateUpdate(data: any) {
|
||||
console.log(`${SB} ← onVoiceStateUpdate: session_id=${data?.session_id ? 'yes' : 'no'} channel_id=${data?.channel_id ?? 'none'}`);
|
||||
return libraryMethods.onVoiceStateUpdate(data);
|
||||
},
|
||||
};
|
||||
const adapter = original(wrappedMethods);
|
||||
const origVSU = adapter.onVoiceServerUpdate;
|
||||
const origVStU = adapter.onVoiceStateUpdate;
|
||||
adapter.onVoiceServerUpdate = (data: any) => {
|
||||
console.log(`${SB} adapter.onVoiceServerUpdate: token=${data?.token ? 'yes' : 'no'} endpoint=${data?.endpoint ?? 'none'}`);
|
||||
return origVSU(data);
|
||||
};
|
||||
adapter.onVoiceStateUpdate = (data: any) => {
|
||||
console.log(`${SB} adapter.onVoiceStateUpdate: session_id=${data?.session_id ? 'yes' : 'no'} channel_id=${data?.channel_id ?? 'none'}`);
|
||||
return origVStU(data);
|
||||
// Call original adapter creator with our wrapped library methods
|
||||
const adapter = original(wrappedLibraryMethods);
|
||||
// Wrap the adapter's sendPayload to log outgoing gateway commands
|
||||
const origSend = adapter.sendPayload.bind(adapter);
|
||||
adapter.sendPayload = (payload: any) => {
|
||||
const result = origSend(payload);
|
||||
console.log(`${SB} → sendPayload op=${payload?.op ?? '?'} guild=${payload?.d?.guild_id ?? '?'} channel=${payload?.d?.channel_id ?? '?'} → ${result}`);
|
||||
return result;
|
||||
};
|
||||
return adapter;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue