From 6926e39c5679e75c9ca6ef1a123abdce3d7ff992 Mon Sep 17 00:00:00 2001 From: Federico Rapetti Date: Sat, 4 Mar 2023 22:38:36 +0100 Subject: [PATCH] Temporary workaround for VoiceConnection stuck in signalling state (#907) --- CHANGELOG.md | 2 ++ src/services/player.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e82628..0386d30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Add temporary workaround to avoid VoiceConnection being stuck in signalling state ## [2.2.0] - 2023-02-26 ### Added diff --git a/src/services/player.ts b/src/services/player.ts index 78f72b2..0b57ad7 100644 --- a/src/services/player.ts +++ b/src/services/player.ts @@ -84,6 +84,22 @@ export default class { guildId: channel.guild.id, adapterCreator: channel.guild.voiceAdapterCreator as DiscordGatewayAdapterCreator, }); + + // Workaround to disable keepAlive + this.voiceConnection.on('stateChange', (oldState, newState) => { + /* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call */ + const oldNetworking = Reflect.get(oldState, 'networking'); + const newNetworking = Reflect.get(newState, 'networking'); + + const networkStateChangeHandler = (_: any, newNetworkState: any) => { + const newUdp = Reflect.get(newNetworkState, 'udp'); + clearInterval(newUdp?.keepAliveInterval); + }; + + oldNetworking?.off('stateChange', networkStateChangeHandler); + newNetworking?.on('stateChange', networkStateChangeHandler); + /* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call */ + }); } disconnect(): void {