@@ -111,22 +111,24 @@ class PlayerRestHandler(
111
111
val player = context.getPlayer(guildId)
112
112
113
113
playerUpdate.voice.ifPresent {
114
- val oldConn = context.koe.getConnection(guildId)
115
- if (oldConn == null ||
116
- oldConn.gatewayConnection?.isOpen == false ||
117
- oldConn.voiceServerInfo == null ||
118
- oldConn.voiceServerInfo?.endpoint != it.endpoint ||
119
- oldConn.voiceServerInfo?.token != it.token ||
120
- oldConn.voiceServerInfo?.sessionId != it.sessionId
121
- ) {
122
- // clear old connection
123
- context.koe.destroyConnection(guildId)
124
-
125
- val conn = context.getMediaConnection(player)
126
- conn.connect(VoiceServerInfo (it.sessionId, it.endpoint, it.token)).exceptionally {
127
- throw ResponseStatusException (HttpStatus .INTERNAL_SERVER_ERROR , " Failed to connect to voice server" )
128
- }.toCompletableFuture().join()
129
- player.provideTo(conn)
114
+ synchronized(player) {
115
+ val oldConn = context.koe.getConnection(guildId)
116
+ if (oldConn == null ||
117
+ oldConn.gatewayConnection?.isOpen == false ||
118
+ oldConn.voiceServerInfo == null ||
119
+ oldConn.voiceServerInfo?.endpoint != it.endpoint ||
120
+ oldConn.voiceServerInfo?.token != it.token ||
121
+ oldConn.voiceServerInfo?.sessionId != it.sessionId
122
+ ) {
123
+ // clear old connection
124
+ context.koe.destroyConnection(guildId)
125
+
126
+ val conn = context.getMediaConnection(player)
127
+ conn.connect(VoiceServerInfo (it.sessionId, it.endpoint, it.token)).exceptionally {
128
+ throw ResponseStatusException (HttpStatus .INTERNAL_SERVER_ERROR , " Failed to connect to voice server" )
129
+ }.toCompletableFuture().join()
130
+ player.provideTo(conn)
131
+ }
130
132
}
131
133
}
132
134
0 commit comments