Skip to content

Commit 524115f

Browse files
committed
fix(whisper): Keep sockets in the call object.
Having them in a pool risks leaking it and can cause not having transcription for a particular room.
1 parent 735351a commit 524115f

File tree

4 files changed

+36
-124
lines changed

4 files changed

+36
-124
lines changed

src/main/java/org/jitsi/jigasi/CallContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.jitsi.jigasi;
1919

20+
import net.java.sip.communicator.util.*;
2021
import org.apache.commons.lang3.StringUtils;
2122
import com.google.common.base.*;
2223

@@ -34,6 +35,7 @@
3435
* @author Damian Minkov
3536
*/
3637
public class CallContext
38+
extends DataObject
3739
{
3840
private final static Logger logger = Logger.getLogger(CallContext.class);
3941

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

Lines changed: 0 additions & 110 deletions
This file was deleted.

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

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,31 @@
1818
package org.jitsi.jigasi.transcription;
1919

2020
import org.jitsi.impl.neomedia.device.*;
21+
import org.jitsi.jigasi.*;
2122
import org.jitsi.jigasi.stats.*;
2223
import org.jitsi.utils.logging.*;
2324

2425
import java.nio.*;
2526
import java.util.function.*;
2627

27-
2828
/**
2929
* Implements a TranscriptionService which uses a custom built Whisper server
3030
* to perform live transcription.
3131
*
3232
* @author Razvan Purdel
3333
*/
3434
public class WhisperTranscriptionService
35-
extends AbstractTranscriptionService
35+
extends AbstractTranscriptionService
3636
{
37-
3837
/**
3938
* The logger for this class
4039
*/
41-
private final static Logger logger
42-
= Logger.getLogger(WhisperTranscriptionService.class);
40+
private final static Logger logger = Logger.getLogger(WhisperTranscriptionService.class);
41+
42+
/**
43+
* The Key to use to put a websocket connection in the call context so we can share it for the room.
44+
*/
45+
private final static String WHISPER_WS_CONNECTION_KEY = "whisper_ws_connection";
4346

4447
@Override
4548
public AudioMixerMediaDevice getMediaDevice(ReceiveStreamBufferListener listener)
@@ -118,7 +121,7 @@ public boolean supportsStreamRecognition()
118121
* the lifecycle of websocket
119122
*/
120123
public static class WhisperWebsocketStreamingSession
121-
implements StreamingRecognitionSession
124+
implements StreamingRecognitionSession
122125
{
123126

124127
private final Participant participant;
@@ -133,20 +136,38 @@ public static class WhisperWebsocketStreamingSession
133136

134137
private final String roomId;
135138

136-
private final WhisperConnectionPool connectionPool;
137-
138-
139139
WhisperWebsocketStreamingSession(Participant participant)
140140
{
141141
this.participant = participant;
142142
String[] debugName = this.participant.getDebugName().split("/");
143143
participantId = debugName[1];
144144
roomId = participant.getTranscriber().getRoomName();
145-
connectionPool = WhisperConnectionPool.getInstance();
146-
wsClient = connectionPool.getConnection(roomId);
145+
wsClient = getConnection();
147146
wsClient.setTranscriptionTag(transcriptionTag);
148147
}
149148

149+
/**
150+
* Gets a connection if it exists, creates one if it doesn't.
151+
* @return The websocket.
152+
*/
153+
public WhisperWebsocket getConnection()
154+
{
155+
CallContext ctx = this.participant.getCallContext();
156+
WhisperWebsocket socket = (WhisperWebsocket)ctx.getData(WHISPER_WS_CONNECTION_KEY);
157+
158+
if (socket == null)
159+
{
160+
logger.info(ctx + " Creating a new websocket connection.");
161+
socket = new WhisperWebsocket();
162+
163+
socket.connect();
164+
165+
ctx.setData(WHISPER_WS_CONNECTION_KEY, socket);
166+
}
167+
168+
return socket;
169+
}
170+
150171
public void sendRequest(TranscriptionRequest request)
151172
{
152173
if (this.wsClient.ended())
@@ -174,8 +195,7 @@ public void addTranscriptionListener(TranscriptionListener listener)
174195

175196
public void end()
176197
{
177-
logger.info("Disconnecting " + this.participantId + " from Whisper transcription service.");
178-
connectionPool.end(this.roomId, this.participantId);
198+
wsClient.disconnectParticipant(this.participantId, allDisconnected -> {});
179199
}
180200

181201
public boolean ended()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
/**
4040
* This holds the websocket that is used to send audio data to the Whisper.
41-
* This is one WhisperWebsocket per room (mapping is in <link>WhisperConnectionPool</link>).
41+
* This is one WhisperWebsocket per room.
4242
* The jetty WebSocketClient process messages in a single thread.
4343
*/
4444
@WebSocket

0 commit comments

Comments
 (0)