🚑 Fix voice connection being stuck in signaling

This commit is contained in:
Manuel 2023-03-02 20:40:46 +01:00
parent 09a67b087a
commit 54c62f240a
3 changed files with 32 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import {
joinVoiceChannel,
NoSubscriberBehavior,
VoiceConnection,
VoiceConnectionStatus,
} from '@discordjs/voice';
import { Injectable } from '@nestjs/common';
@ -216,6 +217,33 @@ export class DiscordVoiceService {
}
private attachEventListenersToAudioPlayer() {
this.voiceConnection.on('debug', (message) => {
if (process.env.DEBUG?.toLowerCase() !== 'true') {
return;
}
this.logger.debug(message);
});
this.voiceConnection.on('error', (err) => {
this.logger.error(`Voice connection error: ${err}`);
});
// Tempoary keep alive fix for servers, see https://github.com/discordjs/discord.js/issues/9185
this.voiceConnection.on('stateChange', (oldState, newState) => {
const oldNetworking = Reflect.get(oldState, 'networking');
const newNetworking = Reflect.get(newState, 'networking');
const networkStateChangeHandler = (
oldNetworkState: any,
newNetworkState: any,
) => {
const newUdp = Reflect.get(newNetworkState, 'udp');
clearInterval(newUdp?.keepAliveInterval);
};
oldNetworking?.off('stateChange', networkStateChangeHandler);
newNetworking?.on('stateChange', networkStateChangeHandler);
});
this.audioPlayer.on('debug', (message) => {
this.logger.debug(message);
});

View File

@ -90,7 +90,7 @@ export class GenericPlaylist {
* @returns if there is a track next in the playlist
*/
hasNextTrackInPlaylist() {
return this.activeTrackIndex < this.tracks.length;
return this.activeTrackIndex + 1 < this.tracks.length;
}
/**

View File

@ -33,11 +33,11 @@ export const Constants = {
InvisibleSpace: '\u1CBC',
Icons: {
JellyfinLogo:
'https://github.com/manuel-rw/jellyfin-discord-music-bot/blob/nestjs-migration/images/icons/jellyfin-icon-squared.png?raw=true',
'https://raw.githubusercontent.com/manuel-rw/jellyfin-discord-music-bot/master/images/icons/jellyfin-icon-squared.png',
SuccessIcon:
'https://github.com/manuel-rw/jellyfin-discord-music-bot/blob/nestjs-migration/images/icons/circle-check.png?raw=true',
'https://raw.githubusercontent.com/manuel-rw/jellyfin-discord-music-bot/master/images/icons/circle-check.png',
ErrorIcon:
'https://github.com/manuel-rw/jellyfin-discord-music-bot/blob/nestjs-migration/images/icons/alert-circle.png?raw=true',
'https://raw.githubusercontent.com/manuel-rw/jellyfin-discord-music-bot/master/images/icons/alert-circle.png',
},
},
};