@@ -155,6 +155,13 @@ public class WhisperWebsocket
155
155
156
156
private final JSONParser jsonParser = new JSONParser ();
157
157
158
+ private final CallContext ctx ;
159
+
160
+ public WhisperWebsocket (CallContext ctx )
161
+ {
162
+ this .ctx = ctx ;
163
+ }
164
+
158
165
/**
159
166
* Creates a connection url by concatenating the websocket
160
167
* url with the Connection Id;
@@ -164,7 +171,7 @@ private void generateWebsocketUrl()
164
171
websocketUrl = websocketUrlConfig + "/" + connectionId ;
165
172
if (logger .isDebugEnabled ())
166
173
{
167
- logger .debug (" Whisper URL: " + websocketUrl );
174
+ logger .debug (this . ctx + " Whisper URL: " + websocketUrl );
168
175
}
169
176
}
170
177
@@ -193,7 +200,7 @@ private void connectInternal()
193
200
try
194
201
{
195
202
generateWebsocketUrl ();
196
- logger .info (" Connecting to " + websocketUrl );
203
+ logger .info (ctx + " Connecting to " + websocketUrl );
197
204
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest ();
198
205
if (!privateKey .isEmpty () && !privateKeyName .isEmpty ())
199
206
{
@@ -206,17 +213,17 @@ private void connectInternal()
206
213
wsSession .setIdleTimeout (Duration .ofSeconds (300 ));
207
214
isConnected = true ;
208
215
reconnecting = false ;
209
- logger .info (" Successfully connected to " + websocketUrl );
216
+ logger .info (ctx + " Successfully connected to " + websocketUrl );
210
217
break ;
211
218
}
212
219
catch (Exception e )
213
220
{
214
221
Statistics .incrementTotalTranscriberConnectionErrors ();
215
222
int remaining = maxRetryAttempts - attempt ;
216
223
waitTime *= multiplier ;
217
- logger .error (" Failed connecting to " + websocketUrl + ". Retrying in "
224
+ logger .error (ctx + " Failed connecting to " + websocketUrl + ". Retrying in "
218
225
+ waitTime /1000 + "seconds for another " + remaining + " times." );
219
- logger .error (e . toString () );
226
+ logger .error (ctx + " " + e );
220
227
}
221
228
attempt ++;
222
229
synchronized (this )
@@ -232,7 +239,7 @@ private void connectInternal()
232
239
if (!isConnected )
233
240
{
234
241
Statistics .incrementTotalTranscriberConnectionErrors ();
235
- logger .error (" Failed connecting to " + websocketUrl + ". Nothing to do." );
242
+ logger .error (ctx + " Failed connecting to " + websocketUrl + ". Nothing to do." );
236
243
}
237
244
}
238
245
@@ -270,7 +277,7 @@ public void onClose(int statusCode, String reason)
270
277
271
278
if (isRunning ())
272
279
{
273
- logger .error (" Websocket closed: " + statusCode + " reason:" + reason );
280
+ logger .error (ctx + " Websocket closed: " + statusCode + " reason:" + reason );
274
281
}
275
282
276
283
wsSession = null ;
@@ -299,7 +306,7 @@ private void stopWebSocketClient()
299
306
}
300
307
catch (Exception e )
301
308
{
302
- logger .error (" Error while stopping WebSocketClient" , e );
309
+ logger .error (ctx + " Error while stopping WebSocketClient" , e );
303
310
}
304
311
}
305
312
@@ -313,7 +320,7 @@ public void onMessage(String msg)
313
320
}
314
321
catch (ParseException e )
315
322
{
316
- logger .error (" Error parsing message: " + msg , e );
323
+ logger .error (ctx + " Error parsing message: " + msg , e );
317
324
}
318
325
}
319
326
@@ -336,7 +343,7 @@ private void onMessageInternal(String msg)
336
343
double stability = (double )obj .get ("variance" );
337
344
if (logger .isDebugEnabled ())
338
345
{
339
- logger .debug (" Received result: " + result );
346
+ logger .debug (ctx + " Received result: " + result );
340
347
}
341
348
342
349
Instant startTranscription = participantTranscriptionStarts .getOrDefault (participantId , null );
@@ -361,8 +368,8 @@ private void onMessageInternal(String msg)
361
368
i ++;
362
369
if (logger .isDebugEnabled ())
363
370
{
364
- logger .debug (" ParticipantId: " + i + ", " + participantId );
365
- logger .debug (" TranscriptionListener: " + l .toString ());
371
+ logger .debug (ctx + " ParticipantId: " + i + ", " + participantId );
372
+ logger .debug (ctx + " TranscriptionListener: " + l .toString ());
366
373
}
367
374
TranscriptionResult tsResult = new TranscriptionResult (
368
375
participant ,
@@ -390,7 +397,7 @@ public void onError(Throwable cause)
390
397
if (!ended () && isRunning ())
391
398
{
392
399
Statistics .incrementTotalTranscriberSendErrors ();
393
- logger .error (" Error while streaming audio data to transcription service." , cause );
400
+ logger .error (ctx + " Error while streaming audio data to transcription service." , cause );
394
401
}
395
402
}
396
403
@@ -399,15 +406,15 @@ private String getLanguage(Participant participant)
399
406
String lang = participant .getTranslationLanguage ();
400
407
if (logger .isDebugEnabled ())
401
408
{
402
- logger .debug (" Translation language is " + lang );
409
+ logger .debug (ctx + " Translation language is " + lang );
403
410
}
404
411
if (lang == null )
405
412
{
406
413
lang = participant .getSourceLanguage ();
407
414
}
408
415
if (logger .isDebugEnabled ())
409
416
{
410
- logger .debug (" Returned language is " + lang );
417
+ logger .debug (ctx + " Returned language is " + lang );
411
418
}
412
419
return lang ;
413
420
}
@@ -447,20 +454,21 @@ private void disconnectParticipantInternal(String participantId, Consumer<Boolea
447
454
{
448
455
participants .remove (participantId );
449
456
participantListeners .remove (participantId );
450
- logger .info (" Disconnected " + participantId );
457
+ logger .info (ctx + " Disconnected " + participantId );
451
458
}
452
459
453
460
if (participants .isEmpty ())
454
461
{
455
- logger .info (" All participants have left, disconnecting from Whisper transcription server." );
462
+ logger .info (ctx + " All participants have left, disconnecting from Whisper transcription server." );
456
463
457
464
try
458
465
{
459
466
wsSession .getRemote ().sendBytes (EOF_MESSAGE );
460
467
}
461
468
catch (IOException e )
462
469
{
463
- logger .error ("Error while finalizing websocket connection for participant " + participantId , e );
470
+ logger .error (ctx + " Error while finalizing websocket connection for participant "
471
+ + participantId , e );
464
472
}
465
473
466
474
wsSession .disconnect ();
@@ -475,21 +483,21 @@ public void sendAudio(String participantId, Participant participant, ByteBuffer
475
483
{
476
484
if (logger .isDebugEnabled ())
477
485
{
478
- logger .debug (" Sending audio for " + participantId );
486
+ logger .debug (ctx + " Sending audio for " + participantId );
479
487
}
480
488
addParticipantIfNotExists (participantId , participant );
481
489
RemoteEndpoint remoteEndpoint = wsSession .getRemote ();
482
490
if (remoteEndpoint == null )
483
491
{
484
492
Statistics .incrementTotalTranscriberSendErrors ();
485
- logger .error (" Failed sending audio for " + participantId + ". Attempting to reconnect." );
493
+ logger .error (ctx + " Failed sending audio for " + participantId + ". Attempting to reconnect." );
486
494
if (!wsSession .isOpen ())
487
495
{
488
496
reconnect ();
489
497
}
490
498
else
491
499
{
492
- logger .warn (" Failed sending audio for " + participantId
500
+ logger .warn (ctx + " Failed sending audio for " + participantId
493
501
+ ". RemoteEndpoint is null but sessions is open." );
494
502
}
495
503
}
@@ -502,7 +510,7 @@ public void sendAudio(String participantId, Participant participant, ByteBuffer
502
510
catch (IOException e )
503
511
{
504
512
Statistics .incrementTotalTranscriberSendErrors ();
505
- logger .error (" Failed sending audio for " + participantId + ". " + e );
513
+ logger .error (ctx + " Failed sending audio for " + participantId + ". " + e );
506
514
}
507
515
}
508
516
}
0 commit comments