From a72d0a422546a9af746667b144d145968ecf7399 Mon Sep 17 00:00:00 2001 From: damencho Date: Thu, 31 Oct 2024 11:18:04 -0500 Subject: [PATCH] fix(whisper): Stopping reconnection when the meeting has ended. --- .../transcription/WhisperWebsocket.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jitsi/jigasi/transcription/WhisperWebsocket.java b/src/main/java/org/jitsi/jigasi/transcription/WhisperWebsocket.java index 4b8701b9..dbfc32ce 100644 --- a/src/main/java/org/jitsi/jigasi/transcription/WhisperWebsocket.java +++ b/src/main/java/org/jitsi/jigasi/transcription/WhisperWebsocket.java @@ -184,7 +184,8 @@ private void connectInternal() long waitTime = 1000L; boolean isConnected = false; wsSession = null; - while (attempt < maxRetryAttempts && !isConnected) + // avoid executing if meeting ended (we are not running) while we were reconnecting + while (attempt < maxRetryAttempts && !(reconnecting && !isRunning()) && !isConnected) { try { @@ -231,7 +232,7 @@ private void connectInternal() private synchronized void reconnect() { - if (reconnecting) + if (reconnecting && !isRunning()) { return; } @@ -250,7 +251,7 @@ private synchronized void reconnect() @OnWebSocketClose public void onClose(int statusCode, String reason) { - if (!this.participants.isEmpty()) + if (isRunning()) { // let's try to reconnect if (!wsSession.isOpen()) @@ -261,7 +262,7 @@ public void onClose(int statusCode, String reason) } } - if (participants != null && !participants.isEmpty()) + if (isRunning()) { logger.error("Websocket closed: " + statusCode + " reason:" + reason); } @@ -366,7 +367,7 @@ public void onMessage(String msg) @OnWebSocketError public void onError(Throwable cause) { - if (!ended() && participants != null && !participants.isEmpty()) + if (!ended() && isRunning()) { Statistics.incrementTotalTranscriberSendErrors(); logger.error("Error while streaming audio data to transcription service.", cause); @@ -414,7 +415,7 @@ public void disconnectParticipant(String participantId, Consumer callba private void disconnectParticipantInternal(String participantId, Consumer callback) { - if (ended() && (participants == null || participants.isEmpty())) + if (ended() && !isRunning()) { callback.accept(true); return; @@ -514,4 +515,15 @@ public boolean ended() { return wsSession == null; } + + /** + * We consider this websocket transcription running when there are participants. + * While reconnecting we still have participants. After disconnectParticipantInternal where we clean + * all participants and close the socket we are no longer running, and we should not try to reconnect. + * @return true if operational. + */ + private boolean isRunning() + { + return participants != null && !participants.isEmpty(); + } }