Skip to content

Commit 76bbca7

Browse files
committed
fix(whisper): Stopping reconnection when the meeting has ended.
1 parent b754996 commit 76bbca7

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/main/java/org/jitsi/jigasi/transcription/WhisperWebsocket.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ private void connectInternal()
184184
long waitTime = 1000L;
185185
boolean isConnected = false;
186186
wsSession = null;
187-
while (attempt < maxRetryAttempts && !isConnected)
187+
// avoid executing if meeting ended (we are not running) while we were reconnecting
188+
while (attempt < maxRetryAttempts && !(reconnecting && !isRunning()) && !isConnected)
188189
{
189190
try
190191
{
@@ -231,7 +232,7 @@ private void connectInternal()
231232

232233
private synchronized void reconnect()
233234
{
234-
if (reconnecting)
235+
if (reconnecting && !isRunning())
235236
{
236237
return;
237238
}
@@ -250,7 +251,7 @@ private synchronized void reconnect()
250251
@OnWebSocketClose
251252
public void onClose(int statusCode, String reason)
252253
{
253-
if (!this.participants.isEmpty())
254+
if (isRunning())
254255
{
255256
// let's try to reconnect
256257
if (!wsSession.isOpen())
@@ -261,7 +262,7 @@ public void onClose(int statusCode, String reason)
261262
}
262263
}
263264

264-
if (participants != null && !participants.isEmpty())
265+
if (isRunning())
265266
{
266267
logger.error("Websocket closed: " + statusCode + " reason:" + reason);
267268
}
@@ -366,7 +367,7 @@ public void onMessage(String msg)
366367
@OnWebSocketError
367368
public void onError(Throwable cause)
368369
{
369-
if (!ended() && participants != null && !participants.isEmpty())
370+
if (!ended() && isRunning())
370371
{
371372
Statistics.incrementTotalTranscriberSendErrors();
372373
logger.error("Error while streaming audio data to transcription service.", cause);
@@ -414,7 +415,7 @@ public void disconnectParticipant(String participantId, Consumer<Boolean> callba
414415

415416
private void disconnectParticipantInternal(String participantId, Consumer<Boolean> callback)
416417
{
417-
if (ended() && (participants == null || participants.isEmpty()))
418+
if (ended() && !isRunning())
418419
{
419420
callback.accept(true);
420421
return;
@@ -514,4 +515,15 @@ public boolean ended()
514515
{
515516
return wsSession == null;
516517
}
518+
519+
/**
520+
* We consider this websocket transcription running when there are participants.
521+
* While reconnecting we still have participants. After disconnectParticipantInternal where we clean
522+
* all participants and close the socket we are no longer running, and we should not try to reconnect.
523+
* @return true if operational.
524+
*/
525+
private boolean isRunning()
526+
{
527+
return participants != null && !participants.isEmpty();
528+
}
517529
}

0 commit comments

Comments
 (0)