Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix leak, fix IllegalMonitorStateException, move jwt to Authorization… #538

Merged
merged 2 commits into from
May 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions src/main/java/org/jitsi/jigasi/transcription/WhisperWebsocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public class WhisperWebsocket

private final static String jwtAudience;

private WebSocketClient ws;

static
{
jwtAudience = JigasiBundleActivator.getConfigurationService()
Expand Down Expand Up @@ -135,11 +137,11 @@ public class WhisperWebsocket
logger.info("Websocket transcription streaming endpoint: " + websocketUrlConfig);
}

private String getJWT() throws NoSuchAlgorithmException, InvalidKeySpecException
private String getJWT() throws NoSuchAlgorithmException, InvalidKeySpecException, IOException
{
if (privateKey.isEmpty() || privateKeyName.isEmpty())
{
return null;
throw new IOException("Failed generating JWT for Whisper. Missing private key or key name.");
}
long nowMillis = System.currentTimeMillis();
Date now = new Date(nowMillis);
Expand All @@ -164,15 +166,7 @@ private String getJWT() throws NoSuchAlgorithmException, InvalidKeySpecException
*/
private void generateWebsocketUrl()
{
try
{
websocketUrl = websocketUrlConfig + "/" + connectionId + "?auth_token=" + getJWT();
}
catch (Exception e)
{
Statistics.incrementTotalTranscriberConnectionErrors();
logger.error("Failed generating JWT for Whisper. " + e);
}
websocketUrl = websocketUrlConfig + "/" + connectionId;
if (logger.isDebugEnabled())
{
logger.debug("Whisper URL: " + websocketUrl);
Expand All @@ -197,10 +191,11 @@ void connect()
{
generateWebsocketUrl();
logger.info("Connecting to " + websocketUrl);
WebSocketClient ws = new WebSocketClient();
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
upgradeRequest.setHeader("Authorization", "Bearer " + getJWT());
ws = new WebSocketClient();
ws.start();
CompletableFuture<Session> connectFuture = ws.connect(this, new URI(websocketUrl));
wsSession = connectFuture.get();
wsSession = ws.connect(this, new URI(websocketUrl), upgradeRequest).get();
wsSession.setIdleTimeout(Duration.ofSeconds(300));
isConnected = true;
logger.info("Successfully connected to " + websocketUrl);
Expand All @@ -216,11 +211,14 @@ void connect()
logger.error(e.toString());
}
attempt++;
try
synchronized (this)
{
wait(waitTime);
try
{
wait(waitTime);
}
catch (InterruptedException ignored) {}
}
catch (InterruptedException ignored) {}
}

if (!isConnected)
Expand All @@ -236,6 +234,18 @@ public void onClose(int statusCode, String reason)
wsSession = null;
participants = null;
participantListeners = null;
try
{
if (ws != null)
{
ws.stop();
ws = null;
}
}
catch (Exception e)
{
logger.error("Error while stopping WebSocketClient", e);
}
}


Expand Down
Loading