Skip to content

Commit

Permalink
fix(transcription): Stop websocket in new thread as recommended.
Browse files Browse the repository at this point in the history
  • Loading branch information
damencho committed Oct 31, 2024
1 parent a0e043b commit 27d6f8f
Showing 1 changed file with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.jetty.websocket.api.*;
import org.eclipse.jetty.websocket.api.annotations.*;
import org.eclipse.jetty.websocket.client.*;
import org.jitsi.jigasi.util.*;
import org.jitsi.utils.logging.*;

import java.io.*;
Expand Down Expand Up @@ -58,6 +59,11 @@ public class OracleRealtimeClient
private final static Logger logger
= Logger.getLogger(OracleRealtimeClient.class);

/**
* The thread pool to serve all connect, disconnect ore reconnect operations.
*/
private static final ExecutorService threadPool = Util.createNewThreadPool("jigasi-oracle-ws");

/**
* Constructor.
*
Expand All @@ -83,20 +89,23 @@ public OracleRealtimeClient(
@OnWebSocketClose
public void onClose(int statusCode, String reason)
{
String closedBy = isClosureClientInitiated ? "client" : "server";
logger.info("Session closed by " + closedBy + ", reason = " + reason + ", status code = " + statusCode);
isConnected = false;
this.session = null;
try
{
this.client.stop();
}
catch (Exception e)
threadPool.submit(() ->
{
logger.error("Error while stopping the OCI transcription client: ", e);
}
//The listener can implement their own closing logic
this.listener.onClose(statusCode, reason);
String closedBy = isClosureClientInitiated ? "client" : "server";
logger.info("Session closed by " + closedBy + ", reason = " + reason + ", status code = " + statusCode);
isConnected = false;
this.session = null;
try
{
this.client.stop();
}
catch (Exception e)
{
logger.error("Error while stopping the OCI transcription client: ", e);
}
//The listener can implement their own closing logic
this.listener.onClose(statusCode, reason);
});
}

/**
Expand Down

0 comments on commit 27d6f8f

Please sign in to comment.