fix: increase radio connect timeout from 5s to 30s, wait for voice+player before loading track
This commit is contained in:
parent
41bc1358fb
commit
37d50ab240
1 changed files with 21 additions and 29 deletions
|
|
@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class RadioManager {
|
public class RadioManager {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(RadioManager.class);
|
private static final Logger logger = LoggerFactory.getLogger(RadioManager.class);
|
||||||
private static final long VOICE_TIMEOUT_MS = 5000;
|
private static final long CONNECT_TIMEOUT_MS = 30000;
|
||||||
|
|
||||||
private final Map<Long, GuildRadioState> radioStates = new ConcurrentHashMap<>();
|
private final Map<Long, GuildRadioState> radioStates = new ConcurrentHashMap<>();
|
||||||
private final QueueRepository queueRepository;
|
private final QueueRepository queueRepository;
|
||||||
|
|
@ -72,16 +72,6 @@ public class RadioManager {
|
||||||
logger.warn("Radio: guild {} not found in radio bot cache", guildId);
|
logger.warn("Radio: guild {} not found in radio bot cache", guildId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var client = lavalinkManager.getClient();
|
|
||||||
if (client != null
|
|
||||||
&& !VoiceHelper.waitForCondition(
|
|
||||||
() -> client.getNodes().stream().anyMatch(n -> n.getSessionId() != null),
|
|
||||||
VOICE_TIMEOUT_MS,
|
|
||||||
TimeUnit.MILLISECONDS)) {
|
|
||||||
LoggerDecorator.warn(
|
|
||||||
logger, "Radio: Lavalink node not ready for guild " + guildId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var vc = guild.getVoiceChannelById(channelId);
|
var vc = guild.getVoiceChannelById(channelId);
|
||||||
if (vc == null) {
|
if (vc == null) {
|
||||||
logger.warn("Radio: voice channel {} not found in guild {}", channelId, guildId);
|
logger.warn("Radio: voice channel {} not found in guild {}", channelId, guildId);
|
||||||
|
|
@ -100,27 +90,29 @@ public class RadioManager {
|
||||||
if (!guild.getAudioManager().isConnected()) {
|
if (!guild.getAudioManager().isConnected()) {
|
||||||
guild.getAudioManager().openAudioConnection(vc);
|
guild.getAudioManager().openAudioConnection(vc);
|
||||||
}
|
}
|
||||||
// Ждём голосовой статус (не прерываемся если не дождались — дальше создаём плеер)
|
|
||||||
var inChannel = VoiceHelper.waitForCondition(
|
|
||||||
() -> self.getVoiceState().inAudioChannel(), VOICE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
|
||||||
if (!inChannel) {
|
|
||||||
logger.warn(
|
|
||||||
"Radio: voice connection timeout for guild {} (channel: {}), continuing...",
|
|
||||||
guildId,
|
|
||||||
self.getVoiceState().getChannel() != null
|
|
||||||
? self.getVoiceState().getChannel().getId()
|
|
||||||
: "null");
|
|
||||||
}
|
|
||||||
var link = lavalinkManager.getOrCreateLink(guildId);
|
var link = lavalinkManager.getOrCreateLink(guildId);
|
||||||
var playerReady = VoiceHelper.waitForCondition(
|
|
||||||
() -> link.getCachedPlayer() != null, VOICE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
VoiceHelper.waitForCondition(
|
||||||
if (!playerReady) {
|
() -> self.getVoiceState().inAudioChannel(), CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||||
LoggerDecorator.warn(logger, "Radio: Lavalink player timeout for guild " + guildId);
|
if (self.getVoiceState().inAudioChannel()) {
|
||||||
|
logger.info("Radio: voice connected for guild {}", guildId);
|
||||||
|
} else {
|
||||||
|
logger.warn("Radio: voice not connected after {}ms for guild {}", CONNECT_TIMEOUT_MS, guildId);
|
||||||
}
|
}
|
||||||
if (!inChannel || !playerReady) {
|
|
||||||
LoggerDecorator.warn(
|
VoiceHelper.waitForCondition(
|
||||||
logger, "Radio: problems connecting, but trying to load stream for guild " + guildId);
|
() -> link.getCachedPlayer() != null, CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||||
|
if (link.getCachedPlayer() != null) {
|
||||||
|
logger.info("Radio: player created for guild {}", guildId);
|
||||||
|
} else {
|
||||||
|
logger.warn("Radio: no player after {}ms for guild {}", CONNECT_TIMEOUT_MS, guildId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!self.getVoiceState().inAudioChannel() || link.getCachedPlayer() == null) {
|
||||||
|
LoggerDecorator.warn(logger, "Radio: skipping — no voice or player for guild " + guildId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var mm = new GuildMusicManager(guildId, lavalinkManager, queueRepository);
|
var mm = new GuildMusicManager(guildId, lavalinkManager, queueRepository);
|
||||||
int vol = finalState.volume;
|
int vol = finalState.volume;
|
||||||
var url = finalState.streamUrl;
|
var url = finalState.streamUrl;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue