Skip to content

Commit

Permalink
fix(whisper): Stopping reconnection when the meeting has ended.
Browse files Browse the repository at this point in the history
  • Loading branch information
damencho committed Oct 31, 2024
1 parent b754996 commit 76bbca7
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/main/java/org/jitsi/jigasi/transcription/WhisperWebsocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -231,7 +232,7 @@ private void connectInternal()

private synchronized void reconnect()
{
if (reconnecting)
if (reconnecting && !isRunning())
{
return;
}
Expand All @@ -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())
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -414,7 +415,7 @@ public void disconnectParticipant(String participantId, Consumer<Boolean> callba

private void disconnectParticipantInternal(String participantId, Consumer<Boolean> callback)
{
if (ended() && (participants == null || participants.isEmpty()))
if (ended() && !isRunning())
{
callback.accept(true);
return;
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 76bbca7

Please sign in to comment.