18
18
package org .jitsi .jigasi .transcription ;
19
19
20
20
import org .jitsi .impl .neomedia .device .*;
21
+ import org .jitsi .jigasi .*;
21
22
import org .jitsi .jigasi .stats .*;
22
23
import org .jitsi .utils .logging .*;
23
24
24
25
import java .nio .*;
25
26
import java .util .function .*;
26
27
27
-
28
28
/**
29
29
* Implements a TranscriptionService which uses a custom built Whisper server
30
30
* to perform live transcription.
31
31
*
32
32
* @author Razvan Purdel
33
33
*/
34
34
public class WhisperTranscriptionService
35
- extends AbstractTranscriptionService
35
+ extends AbstractTranscriptionService
36
36
{
37
-
38
37
/**
39
38
* The logger for this class
40
39
*/
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" ;
43
46
44
47
@ Override
45
48
public AudioMixerMediaDevice getMediaDevice (ReceiveStreamBufferListener listener )
@@ -118,7 +121,7 @@ public boolean supportsStreamRecognition()
118
121
* the lifecycle of websocket
119
122
*/
120
123
public static class WhisperWebsocketStreamingSession
121
- implements StreamingRecognitionSession
124
+ implements StreamingRecognitionSession
122
125
{
123
126
124
127
private final Participant participant ;
@@ -133,20 +136,38 @@ public static class WhisperWebsocketStreamingSession
133
136
134
137
private final String roomId ;
135
138
136
- private final WhisperConnectionPool connectionPool ;
137
-
138
-
139
139
WhisperWebsocketStreamingSession (Participant participant )
140
140
{
141
141
this .participant = participant ;
142
142
String [] debugName = this .participant .getDebugName ().split ("/" );
143
143
participantId = debugName [1 ];
144
144
roomId = participant .getTranscriber ().getRoomName ();
145
- connectionPool = WhisperConnectionPool .getInstance ();
146
- wsClient = connectionPool .getConnection (roomId );
145
+ wsClient = getConnection ();
147
146
wsClient .setTranscriptionTag (transcriptionTag );
148
147
}
149
148
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
+
150
171
public void sendRequest (TranscriptionRequest request )
151
172
{
152
173
if (this .wsClient .ended ())
@@ -174,8 +195,7 @@ public void addTranscriptionListener(TranscriptionListener listener)
174
195
175
196
public void end ()
176
197
{
177
- logger .info ("Disconnecting " + this .participantId + " from Whisper transcription service." );
178
- connectionPool .end (this .roomId , this .participantId );
198
+ wsClient .disconnectParticipant (this .participantId , allDisconnected -> {});
179
199
}
180
200
181
201
public boolean ended ()
0 commit comments