Skip to content

Commit 8864668

Browse files
committed
fix(transcription): Sends transcription over xmpp in separate thread.
1 parent 76bbca7 commit 8864668

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

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

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
import net.java.sip.communicator.service.protocol.*;
2222
import net.java.sip.communicator.service.protocol.Message;
2323
import org.jitsi.jigasi.*;
24+
import org.jitsi.jigasi.util.Util;
2425
import org.jitsi.service.libjitsi.*;
2526
import org.jitsi.service.neomedia.*;
2627
import org.jitsi.service.neomedia.device.*;
2728
import org.jitsi.service.neomedia.recording.*;
2829
import org.jitsi.utils.logging.*;
30+
import org.jitsi.utils.queue.*;
2931

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

159161
/**
160-
* Aspect for successful upload of transcript
162+
* A queue used to offload xmpp message sending in a new thread to avoid blocking.
161163
*/
162-
private static final String DD_ASPECT_SUCCESS = "upload_success";
164+
private static final PacketQueue<Runnable> xmppInvokeQueue = new PacketQueue<>(
165+
Integer.MAX_VALUE,
166+
false,
167+
"xmpp-transcript-publisher",
168+
r -> {
169+
// do process and try
170+
try
171+
{
172+
r.run();
163173

164-
/**
165-
* Aspect for failed upload of transcript
166-
*/
167-
private static final String DD_ASPECT_FAIL = "upload_fail";
174+
return true;
175+
}
176+
catch (Throwable e)
177+
{
178+
logger.error("Error processing xmpp queue item", e);
179+
180+
return false;
181+
}
182+
},
183+
Util.createNewThreadPool("transcript-publisher-executor-pool")
184+
);
168185

169186
/**
170187
* Get a string which contains a time stamp and a random UUID, with an
@@ -194,13 +211,27 @@ protected static String generateHardToGuessTimeString(String prefix,
194211
* @param message the message to send
195212
*/
196213
protected void sendMessage(ChatRoom chatRoom, T message)
214+
{
215+
xmppInvokeQueue.add(() -> sendMessageInternal(chatRoom, message));
216+
}
217+
218+
private void sendMessageInternal(ChatRoom chatRoom, T message)
197219
{
198220
if (chatRoom == null)
199221
{
200222
logger.error("Cannot send message as chatRoom is null");
201223
return;
202224
}
203225

226+
if (!chatRoom.isJoined())
227+
{
228+
if (logger.isDebugEnabled())
229+
{
230+
logger.debug("Skip sending message to room which we left!");
231+
}
232+
return;
233+
}
234+
204235
String messageString = message.toString();
205236
Message chatRoomMessage = chatRoom.createMessage(messageString);
206237
try
@@ -222,6 +253,11 @@ protected void sendMessage(ChatRoom chatRoom, T message)
222253
* @param jsonMessage the json message to send
223254
*/
224255
protected void sendJsonMessage(ChatRoom chatRoom, T jsonMessage)
256+
{
257+
xmppInvokeQueue.add(() -> sendJsonMessageInternal(chatRoom, jsonMessage));
258+
}
259+
260+
private void sendJsonMessageInternal(ChatRoom chatRoom, T jsonMessage)
225261
{
226262
if (chatRoom == null)
227263
{

0 commit comments

Comments
 (0)