Skip to content

Commit

Permalink
fix(transcription): Sends transcription over xmpp in separate thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
damencho committed Oct 31, 2024
1 parent 5e06bcb commit 92b835a
Showing 1 changed file with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.Message;
import org.jitsi.jigasi.*;
import org.jitsi.jigasi.util.Util;
import org.jitsi.service.libjitsi.*;
import org.jitsi.service.neomedia.*;
import org.jitsi.service.neomedia.device.*;
import org.jitsi.service.neomedia.recording.*;
import org.jitsi.utils.logging.*;
import org.jitsi.utils.queue.*;

import java.io.*;
import java.nio.charset.*;
Expand Down Expand Up @@ -157,14 +159,29 @@ public abstract class AbstractTranscriptPublisher<T>
= Logger.getLogger(AbstractTranscriptPublisher.class);

/**
* Aspect for successful upload of transcript
* A queue used to offload xmpp message sending in a new thread to avoid blocking.
*/
private static final String DD_ASPECT_SUCCESS = "upload_success";
private static final PacketQueue<Runnable> xmppInvokeQueue = new PacketQueue<>(
Integer.MAX_VALUE,
false,
"xmpp-transcript-publisher",
r -> {
// do process and try
try
{
r.run();

/**
* Aspect for failed upload of transcript
*/
private static final String DD_ASPECT_FAIL = "upload_fail";
return true;
}
catch (Throwable e)
{
logger.error("Error processing xmpp queue item", e);

return false;
}
},
Util.createNewThreadPool("transcript-publisher-executor-pool")
);

/**
* Get a string which contains a time stamp and a random UUID, with an
Expand Down Expand Up @@ -194,13 +211,27 @@ protected static String generateHardToGuessTimeString(String prefix,
* @param message the message to send
*/
protected void sendMessage(ChatRoom chatRoom, T message)
{
xmppInvokeQueue.add(() -> sendMessageInternal(chatRoom, message));
}

private void sendMessageInternal(ChatRoom chatRoom, T message)
{
if (chatRoom == null)
{
logger.error("Cannot send message as chatRoom is null");
return;
}

if (!chatRoom.isJoined())
{
if (logger.isDebugEnabled())
{
logger.debug("Skip sending message to room which we left!");
}
return;
}

String messageString = message.toString();
Message chatRoomMessage = chatRoom.createMessage(messageString);
try
Expand All @@ -222,6 +253,11 @@ protected void sendMessage(ChatRoom chatRoom, T message)
* @param jsonMessage the json message to send
*/
protected void sendJsonMessage(ChatRoom chatRoom, T jsonMessage)
{
xmppInvokeQueue.add(() -> sendJsonMessageInternal(chatRoom, jsonMessage));
}

private void sendJsonMessageInternal(ChatRoom chatRoom, T jsonMessage)
{
if (chatRoom == null)
{
Expand Down

0 comments on commit 92b835a

Please sign in to comment.