diff --git a/src/main/java/org/jitsi/jigasi/JvbConference.java b/src/main/java/org/jitsi/jigasi/JvbConference.java index a0e1896ab..b3af0ec6b 100644 --- a/src/main/java/org/jitsi/jigasi/JvbConference.java +++ b/src/main/java/org/jitsi/jigasi/JvbConference.java @@ -67,6 +67,7 @@ import java.io.*; import java.net.*; import java.util.*; +import java.util.concurrent.*; import static net.java.sip.communicator.service.protocol.event.LocalUserChatRoomPresenceChangeEvent.*; import static org.jivesoftware.smack.packet.StanzaError.Condition.*; @@ -185,11 +186,13 @@ public class JvbConference */ private String meetingId; + private static ExecutorService threadPool = Util.createNewThreadPool("xmpp-executor-pool"); + /** * A queue used to offload xmpp execution in a new thread to avoid blocking xmpp threads, * by executing the tasks in new thread */ - public static final PacketQueue xmppInvokeQueue = new PacketQueue<>( + public final PacketQueue xmppInvokeQueue = new PacketQueue<>( Integer.MAX_VALUE, false, "xmpp-invoke-queue", @@ -208,7 +211,32 @@ public class JvbConference return false; } }, - Util.createNewThreadPool("xmpp-executor-pool") + threadPool + ); + + /** + * A queue used for sending xmpp messages. + */ + public final PacketQueue xmppSendQueue = new PacketQueue<>( + Integer.MAX_VALUE, + false, + "xmpp-send-queue", + r -> { + // do process and try + try + { + r.run(); + + return true; + } + catch (Throwable e) + { + logger.error("Error processing xmpp queue item", e); + + return false; + } + }, + threadPool ); /** @@ -2299,6 +2327,80 @@ private void processVisitorsJson(String json) } } + /** + * Send a message to the muc room + * + * @param messageString the message to send + */ + public void sendMessageToRoom(String messageString) + { + xmppSendQueue.add(() -> sendMessageToRoomInternal(messageString)); + } + + public void sendMessageToRoomInternal(String messageString) + { + if (isInTheRoom()) + { + logger.error(this.callContext + " Cannot send message as chatRoom is null"); + return; + } + + try + { + this.mucRoom.sendMessage(this.mucRoom.createMessage(messageString)); + if (logger.isTraceEnabled()) + { + logger.trace(this.callContext + " Sending message: \"" + messageString + "\""); + } + } + catch (OperationFailedException e) + { + logger.warn(this.callContext + " Failed to send message " + messageString, e); + } + } + + /** + * Send a json-message to the muc room + * + * @param jsonMessage the json message to send + */ + public void sendJsonMessage(JSONObject jsonMessage) + { + xmppSendQueue.add(() -> sendJsonMessageInternal(jsonMessage)); + } + + private void sendJsonMessageInternal(JSONObject jsonMessage) + { + if (this.mucRoom == null) + { + logger.error(this.callContext + " Cannot send message as chatRoom is null"); + return; + } + + if (!isInTheRoom()) + { + if (logger.isDebugEnabled()) + { + logger.debug(this.callContext + " Skip sending message to room which we left!"); + } + return; + } + + String messageString = jsonMessage.toString(); + try + { + ((ChatRoomJabberImpl)this.mucRoom).sendJsonMessage(messageString); + if (logger.isTraceEnabled()) + { + logger.trace(this.callContext + " Sending json message: \"" + messageString + "\""); + } + } + catch (OperationFailedException e) + { + logger.warn(this.callContext + " Failed to send json message " + messageString, e); + } + } + /** * Threads handles the timeout for stopping the conference. * For waiting for conference call invite sent by the focus or for waiting diff --git a/src/main/java/org/jitsi/jigasi/TranscriptionGatewaySession.java b/src/main/java/org/jitsi/jigasi/TranscriptionGatewaySession.java index 857d0a174..03b7c134f 100644 --- a/src/main/java/org/jitsi/jigasi/TranscriptionGatewaySession.java +++ b/src/main/java/org/jitsi/jigasi/TranscriptionGatewaySession.java @@ -85,13 +85,6 @@ public class TranscriptionGatewaySession */ private TranscriptHandler handler; - /** - * The ChatRoom of the conference which is going to be transcribed. - * We will post messages to the ChatRoom to update users of progress - * of transcription - */ - private ChatRoom chatRoom = null; - /** * The transcriber managing transcriptions of audio */ @@ -213,14 +206,13 @@ Exception onConferenceCallStarted(Call jvbConferenceCall) // We can now safely set the Call connecting to the muc room // and the ChatRoom of the muc room this.jvbCall = jvbConferenceCall; - this.chatRoom = super.jvbConference.getJvbRoom(); // If the transcription service is not correctly configured, there is no // point in continuing this session, so end it immediately if (!service.isConfiguredProperly()) { logger.warn("TranscriptionService is not properly configured"); - sendMessageToRoom("Transcriber is not properly " + + super.jvbConference.sendMessageToRoom("Transcriber is not properly " + "configured. Contact the service administrators and let them " + "know! I will now leave."); jvbConference.stop(); @@ -260,7 +252,7 @@ Exception onConferenceCallStarted(Call jvbConferenceCall) if (welcomeMessage.length() > 0) { - sendMessageToRoom(welcomeMessage.toString()); + super.jvbConference.sendMessageToRoom(welcomeMessage.toString()); } try @@ -637,6 +629,13 @@ private List getCurrentConferenceMembers() */ private List getCurrentChatRoomMembers() { + if (super.jvbConference == null) + { + return null; + } + + ChatRoom chatRoom = super.jvbConference.getJvbRoom(); + return chatRoom == null ? null : chatRoom.getMembers(); } @@ -710,32 +709,6 @@ private String getParticipantIdentifier(ConferenceMember conferenceMember) return getConferenceMemberResourceID(conferenceMember); } - - /** - * Send a message to the muc room - * - * @param messageString the message to send - */ - private void sendMessageToRoom(String messageString) - { - if (chatRoom == null) - { - logger.error("Cannot send message as chatRoom is null"); - return; - } - - Message message = chatRoom.createMessage(messageString); - try - { - chatRoom.sendMessage(message); - logger.debug("Sending message: \"" + messageString + "\""); - } - catch (OperationFailedException e) - { - logger.warn("Failed to send message " + messageString, e); - } - } - /** * Send a {@link TranscriptionResult} to the {@link ChatRoom} * @@ -743,7 +716,7 @@ private void sendMessageToRoom(String messageString) */ private void sendTranscriptionResultToRoom(TranscriptionResult result) { - handler.publishTranscriptionResult(this.chatRoom, result); + handler.publishTranscriptionResult(super.jvbConference, result); } /** @@ -753,7 +726,7 @@ private void sendTranscriptionResultToRoom(TranscriptionResult result) */ private void sendTranslationResultToRoom(TranslationResult result) { - handler.publishTranslationResult(this.chatRoom, result); + handler.publishTranslationResult(super.jvbConference, result); } @Override diff --git a/src/main/java/org/jitsi/jigasi/lobby/Lobby.java b/src/main/java/org/jitsi/jigasi/lobby/Lobby.java index 977716c05..a8a1b0695 100644 --- a/src/main/java/org/jitsi/jigasi/lobby/Lobby.java +++ b/src/main/java/org/jitsi/jigasi/lobby/Lobby.java @@ -202,7 +202,7 @@ protected void leaveRoom() @Override public void invitationReceived(ChatRoomInvitationReceivedEvent evt) { - JvbConference.xmppInvokeQueue.add(() -> invitationReceivedInternal(evt)); + this.jvbConference.xmppInvokeQueue.add(() -> invitationReceivedInternal(evt)); } private void invitationReceivedInternal(ChatRoomInvitationReceivedEvent chatRoomInvitationReceivedEvent) @@ -255,7 +255,7 @@ private void notifyAccessGranted() @Override public void localUserPresenceChanged(LocalUserChatRoomPresenceChangeEvent evt) { - JvbConference.xmppInvokeQueue.add(() -> localUserPresenceChangedInternal(evt)); + this.jvbConference.xmppInvokeQueue.add(() -> localUserPresenceChangedInternal(evt)); } private void localUserPresenceChangedInternal(LocalUserChatRoomPresenceChangeEvent evt) diff --git a/src/main/java/org/jitsi/jigasi/transcription/AbstractTranscriptPublisher.java b/src/main/java/org/jitsi/jigasi/transcription/AbstractTranscriptPublisher.java index b3bcfad85..e220b1d76 100644 --- a/src/main/java/org/jitsi/jigasi/transcription/AbstractTranscriptPublisher.java +++ b/src/main/java/org/jitsi/jigasi/transcription/AbstractTranscriptPublisher.java @@ -17,9 +17,6 @@ */ package org.jitsi.jigasi.transcription; -import net.java.sip.communicator.impl.protocol.jabber.*; -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.Message; import org.jitsi.jigasi.*; import org.jitsi.service.libjitsi.*; import org.jitsi.service.neomedia.*; @@ -156,16 +153,6 @@ public abstract class AbstractTranscriptPublisher private static final Logger logger = Logger.getLogger(AbstractTranscriptPublisher.class); - /** - * Aspect for successful upload of transcript - */ - private static final String DD_ASPECT_SUCCESS = "upload_success"; - - /** - * Aspect for failed upload of transcript - */ - private static final String DD_ASPECT_FAIL = "upload_fail"; - /** * Get a string which contains a time stamp and a random UUID, with an * optional pre- and suffix attached. @@ -187,76 +174,6 @@ protected static String generateHardToGuessTimeString(String prefix, UUID.randomUUID(), suffix); } - /** - * Send a message to the muc room - * - * @param chatRoom the chatroom to send the message to - * @param message the message to send - */ - protected void sendMessage(ChatRoom chatRoom, T message) - { - if (chatRoom == null) - { - logger.error("Cannot send message as chatRoom is null"); - return; - } - - String messageString = message.toString(); - Message chatRoomMessage = chatRoom.createMessage(messageString); - try - { - chatRoom.sendMessage(chatRoomMessage); - if (logger.isTraceEnabled()) - logger.trace("Sending message: \"" + messageString + "\""); - } - catch (OperationFailedException e) - { - logger.warn("Failed to send message " + messageString, e); - } - } - - /** - * Send a json-message to the muc room - * - * @param chatRoom the chatroom to send the message to - * @param jsonMessage the json message to send - */ - protected void sendJsonMessage(ChatRoom chatRoom, T jsonMessage) - { - if (chatRoom == null) - { - logger.error("Cannot send message as chatRoom is null"); - return; - } - - if (!(chatRoom instanceof ChatRoomJabberImpl)) - { - logger.error("Cannot send message as chatRoom is not an" + - "instance of ChatRoomJabberImpl"); - return; - } - - if (!chatRoom.isJoined()) - { - if (logger.isDebugEnabled()) - { - logger.debug("Skip sending message to room which we left!"); - } - return; - } - - String messageString = jsonMessage.toString(); - try - { - ((ChatRoomJabberImpl)chatRoom).sendJsonMessage(messageString); - if (logger.isTraceEnabled()) - logger.trace("Sending json message: \"" + messageString + "\""); - } - catch (OperationFailedException e) - { - logger.warn("Failed to send json message " + messageString, e); - } - } /** * Save a transcript given as a String to subdirectory of getLogDirPath() * with the given directory name and the given file name diff --git a/src/main/java/org/jitsi/jigasi/transcription/LocalJsonTranscriptHandler.java b/src/main/java/org/jitsi/jigasi/transcription/LocalJsonTranscriptHandler.java index 9478f8caf..aae176887 100644 --- a/src/main/java/org/jitsi/jigasi/transcription/LocalJsonTranscriptHandler.java +++ b/src/main/java/org/jitsi/jigasi/transcription/LocalJsonTranscriptHandler.java @@ -18,6 +18,7 @@ package org.jitsi.jigasi.transcription; import net.java.sip.communicator.service.protocol.*; +import org.jitsi.jigasi.*; import org.json.simple.*; import java.time.*; @@ -225,19 +226,15 @@ public JSONFormatter getFormatter() } @Override - public void publish(ChatRoom room, TranscriptionResult result) + public void publish(JvbConference jvbConference, TranscriptionResult result) { - JSONObject eventObject = createTranscriptionJSONObject(result); - - super.sendJsonMessage(room, eventObject); + jvbConference.sendJsonMessage(createTranscriptionJSONObject(result)); } @Override - public void publish(ChatRoom room, TranslationResult result) + public void publish(JvbConference jvbConference, TranslationResult result) { - JSONObject eventObject = createTranslationJSONObject(result); - - super.sendJsonMessage(room, eventObject); + jvbConference.sendJsonMessage(createTranslationJSONObject(result)); } /** diff --git a/src/main/java/org/jitsi/jigasi/transcription/LocalTxtTranscriptHandler.java b/src/main/java/org/jitsi/jigasi/transcription/LocalTxtTranscriptHandler.java index 47e130c05..92271316a 100644 --- a/src/main/java/org/jitsi/jigasi/transcription/LocalTxtTranscriptHandler.java +++ b/src/main/java/org/jitsi/jigasi/transcription/LocalTxtTranscriptHandler.java @@ -17,7 +17,7 @@ */ package org.jitsi.jigasi.transcription; -import net.java.sip.communicator.service.protocol.*; +import org.jitsi.jigasi.*; import org.jitsi.utils.logging.*; import java.time.*; @@ -180,7 +180,7 @@ private static String getDelimiter() * {@inheritDoc} */ @Override - public void publish(ChatRoom chatRoom, TranscriptionResult result) + public void publish(JvbConference jvbConference, TranscriptionResult result) { if (result.isInterim()) { @@ -191,8 +191,7 @@ public void publish(ChatRoom chatRoom, TranscriptionResult result) String transcription = result.getAlternatives().iterator() .next().getTranscription(); - String toSend = name + ": " + transcription; - super.sendMessage(chatRoom, toSend); + jvbConference.sendMessageToRoom(name + ": " + transcription); } /** @@ -202,7 +201,7 @@ public void publish(ChatRoom chatRoom, TranscriptionResult result) * {@inheritDoc} */ @Override - public void publish(ChatRoom chatRoom, TranslationResult result) + public void publish(JvbConference jvbConference, TranslationResult result) { /* * We do not send the translated speech-to-text results to the Chatroom diff --git a/src/main/java/org/jitsi/jigasi/transcription/RemotePublisherTranscriptionHandler.java b/src/main/java/org/jitsi/jigasi/transcription/RemotePublisherTranscriptionHandler.java index 9ed66ecbf..915655135 100644 --- a/src/main/java/org/jitsi/jigasi/transcription/RemotePublisherTranscriptionHandler.java +++ b/src/main/java/org/jitsi/jigasi/transcription/RemotePublisherTranscriptionHandler.java @@ -17,7 +17,7 @@ */ package org.jitsi.jigasi.transcription; -import net.java.sip.communicator.service.protocol.*; +import org.jitsi.jigasi.*; import org.json.simple.*; import java.util.*; @@ -55,7 +55,7 @@ public RemotePublisherTranscriptionHandler(String urlsStr) } @Override - public void publish(ChatRoom room, TranscriptionResult result) + public void publish(JvbConference jvbConference, TranscriptionResult result) { if (result.isInterim()) return; diff --git a/src/main/java/org/jitsi/jigasi/transcription/TranscriptHandler.java b/src/main/java/org/jitsi/jigasi/transcription/TranscriptHandler.java index 35665a6a7..f0240e255 100644 --- a/src/main/java/org/jitsi/jigasi/transcription/TranscriptHandler.java +++ b/src/main/java/org/jitsi/jigasi/transcription/TranscriptHandler.java @@ -135,15 +135,15 @@ public TranscriptHandler() * Handle a {@link TranscriptionResult} with all given * {@link TranscriptionResultPublisher}'s * - * @param room the {@link ChatRoom} to send the result to + * @param jvbConference the {@link JvbConference} to send the result to * @param result the {@link TranscriptionResult} to handle */ - public void publishTranscriptionResult(ChatRoom room, + public void publishTranscriptionResult(JvbConference jvbConference, TranscriptionResult result) { for (TranscriptionResultPublisher p : resultPublishers) { - p.publish(room, result); + p.publish(jvbConference, result); } } @@ -151,15 +151,15 @@ public void publishTranscriptionResult(ChatRoom room, * Handle a {@link TranslationResult} with all given * {@link TranscriptionResultPublisher}'s * - * @param room the {@link ChatRoom} to send the result to + * @param jvbConference the {@link JvbConference} to send the result to * @param result the {@link TranslationResult} to handle */ - public void publishTranslationResult(ChatRoom room, + public void publishTranslationResult(JvbConference jvbConference, TranslationResult result) { for (TranscriptionResultPublisher p : resultPublishers) { - p.publish(room, result); + p.publish(jvbConference, result); } } diff --git a/src/main/java/org/jitsi/jigasi/transcription/TranscriptionResultPublisher.java b/src/main/java/org/jitsi/jigasi/transcription/TranscriptionResultPublisher.java index 1f8c1b10f..979745fc7 100644 --- a/src/main/java/org/jitsi/jigasi/transcription/TranscriptionResultPublisher.java +++ b/src/main/java/org/jitsi/jigasi/transcription/TranscriptionResultPublisher.java @@ -17,7 +17,7 @@ */ package org.jitsi.jigasi.transcription; -import net.java.sip.communicator.service.protocol.*; +import org.jitsi.jigasi.*; /** * This interface is used to send a message to the chatRoom of a jitsi-meet @@ -30,16 +30,16 @@ public interface TranscriptionResultPublisher /** * Publish the given TranscriptionResult to the given ChatRoom * - * @param chatRoom the chat room + * @param jvbConference the meeting room * @param result the result */ - void publish(ChatRoom chatRoom, TranscriptionResult result); + void publish(JvbConference jvbConference, TranscriptionResult result); /** * Publish the given TranslationResult to the given ChatRoom * - * @param chatRoom the chat room + * @param jvbConference the meeting room * @param result the result */ - void publish(ChatRoom chatRoom, TranslationResult result); + void publish(JvbConference jvbConference, TranslationResult result); }