Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transcribing backend flag #519

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 98 additions & 6 deletions src/main/java/org/jitsi/jigasi/JvbConference.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.jivesoftware.smackx.xdata.packet.*;
import org.jivesoftware.smackx.xdata.*;
import org.json.simple.*;
import org.json.simple.parser.*;
import org.jxmpp.jid.*;
import org.jxmpp.jid.impl.*;
import org.jxmpp.jid.parts.*;
Expand Down Expand Up @@ -366,6 +367,11 @@ private static ExtensionElement addSupportedFeatures(
*/
private RoomConfigurationChangeListener roomConfigurationListener = null;

/**
* Listens for messages from room metadata component for changes in room metadata.
*/
private RoomMetadataListener roomMetadataListener = null;

/**
* Up-to-date list of participants in the room that are jigasi.
*/
Expand Down Expand Up @@ -760,6 +766,24 @@ private void discoverComponentAddresses()
logger.info(String.format("%s Discovered %s for %oms.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really care about this message only for avModarationAddress? I suggest either remove it or move it out of the "if" to be printed right after the discoverInfo call

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove that and move the print after, I just kept it when moving the stuff.

this.callContext, avModerationAddress, System.currentTimeMillis() - startQuery));
}

DiscoverInfo.Identity roomMetadataIdentity = info.getIdentities().stream().
filter(di -> di.getCategory().equals("component") && di.getType().equals("room_metadata"))
.findFirst().orElse(null);

// we process room metadata messages only when we are transcribing
if (roomMetadataIdentity != null && this.gatewaySession instanceof TranscriptionGatewaySession)
{
if (roomMetadataListener != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to make the field final and always initialize it? You can remove these 5 lines of code and not worry about this executing after a re-connect for example

{
logger.error(this.callContext + " RoomMetadata listener is not supposed to be initialized");
}
roomMetadataListener = new RoomMetadataListener();
getConnection().addAsyncStanzaListener(roomMetadataListener,
new AndFilter(
MessageTypeFilter.NORMAL,
FromMatchesFilter.create(JidCreate.domainBareFrom(roomMetadataIdentity.getName()))));
}
}
catch(Exception e)
{
Expand Down Expand Up @@ -924,12 +948,6 @@ public void joinConferenceRoom()

gatewaySession.notifyJvbRoomJoined();

if (lobbyEnabled)
{
// let's check room config
updateFromRoomConfiguration();
}

// let's listen for any future changes in room configuration, whether lobby will be enabled/disabled
if (roomConfigurationListener == null && mucRoom instanceof ChatRoomJabberImpl)
{
Expand All @@ -939,6 +957,11 @@ public void joinConferenceRoom()
FromMatchesFilter.create(((ChatRoomJabberImpl)this.mucRoom).getIdentifierAsJid()),
MessageTypeFilter.GROUPCHAT));
}

// let's check room config
updateFromRoomConfiguration();

logger.info(this.callContext + " Joined room: " + roomName + " meetingId:" + this.getMeetingId());
}
catch (Exception e)
{
Expand Down Expand Up @@ -1124,6 +1147,17 @@ private void leaveConferenceRoom()
this.roomConfigurationListener = null;
}

if (this.roomMetadataListener != null)
{
XMPPConnection connection = getConnection();
if (connection != null)
{
connection.removeAsyncStanzaListener(roomMetadataListener);
}

this.roomMetadataListener = null;
}

// remove listener needs to be after leave,
// to catch all member left events
// and when focus is leaving we will call again leaveConferenceRoom making mucRoom, so we need another check
Expand Down Expand Up @@ -1991,13 +2025,51 @@ private void updateFromRoomConfiguration()
boolean singleModeratorEnabled = df.getField(Lobby.DATA_FORM_SINGLE_MODERATOR_FIELD) != null;
setLobbyEnabled(lobbyEnabled);
this.singleModeratorEnabled = singleModeratorEnabled;

List<String> roomMetadataValues
= df.getField(TranscriptionGatewaySession.DATA_FORM_ROOM_METADATA_FIELD).getValuesAsString();
if (roomMetadataValues != null && !roomMetadataValues.isEmpty())
{
// it is supposed to have a single value
processRoomMetadataJson(roomMetadataValues.get(0));
}
}
catch(Exception e)
{
logger.error(this.callContext + " Error checking room configuration", e);
}
}

private void processRoomMetadataJson(String json)
{
if (!(this.gatewaySession instanceof TranscriptionGatewaySession))
{
return;
}

try
{
Object o = new JSONParser().parse(json);

if (o instanceof JSONObject)
{
JSONObject data = (JSONObject) o;

if (data.get("type").equals("room_metadata"))
{
JSONObject metadataObj = (JSONObject)data.getOrDefault("metadata", new JSONObject());
JSONObject recordingObj = (JSONObject)metadataObj.getOrDefault("recording", new JSONObject());
((TranscriptionGatewaySession)this.gatewaySession).setBackendTranscribingEnabled(
(boolean)recordingObj.getOrDefault("isTranscribingEnabled", false));
}
}
}
catch(Exception e)
{
logger.error(callContext + " Error parsing", e);
}
}

/**
* Threads handles the timeout for stopping the conference.
* For waiting for conference call invite sent by the focus or for waiting
Expand Down Expand Up @@ -2174,6 +2246,26 @@ public void processStanza(Stanza stanza)
}
}

/**
* When a room metadata change is received.
*/
private class RoomMetadataListener
implements StanzaListener
{
@Override
public void processStanza(Stanza stanza)
{
JsonMessageExtension jsonMsg = stanza.getExtension(JsonMessageExtension.class);

if (jsonMsg == null)
{
return;
}

processRoomMetadataJson(jsonMsg.getJson());
}
}

/**
* Used to check the jvb side of the call for any activity.
*/
Expand Down
46 changes: 36 additions & 10 deletions src/main/java/org/jitsi/jigasi/TranscriptionGatewaySession.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public class TranscriptionGatewaySession
private final static Logger logger
= Logger.getLogger(TranscriptionGatewaySession.class);

/**
* The data form field added when transcription is enabled.
*/
public static final String DATA_FORM_ROOM_METADATA_FIELD = "muc#roominfo_jitsimetadata";

/**
* The display name which should be displayed when Jigasi joins the
* room
Expand Down Expand Up @@ -101,6 +106,13 @@ public class TranscriptionGatewaySession
private List<TranscriptPublisher.Promise> finalTranscriptPromises
= new LinkedList<>();

/**
* When a backend transcribing is enabled, overrides participants request for transcriptions and keep the
* transcriber in the room and working even though no participant is requesting it.
* This is used to make transcriptions available for post-processing.
*/
private boolean isBackendTranscribingEnabled = false;

/**
* Create a TranscriptionGatewaySession which can handle the transcription
* of a JVB conference
Expand Down Expand Up @@ -308,8 +320,14 @@ void notifyChatRoomMemberUpdated(ChatRoomMember chatMember, Presence presence)
String identifier = getParticipantIdentifier(chatMember);
this.transcriber.updateParticipant(identifier, chatMember);

if (transcriber.isTranscribing() &&
!transcriber.isAnyParticipantRequestingTranscription())
this.maybeStopTranscription();
}

private void maybeStopTranscription()
{
if (transcriber.isTranscribing()
&& !(transcriber.isAnyParticipantRequestingTranscription()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: suggest to extract a isTranscriptionRequested() method

|| isBackendTranscribingEnabled))
{
new Thread(() ->
{
Expand All @@ -322,7 +340,8 @@ void notifyChatRoomMemberUpdated(ChatRoomMember chatMember, Presence presence)
logger.error(e);
}

if (!transcriber.isAnyParticipantRequestingTranscription())
if (!(transcriber.isAnyParticipantRequestingTranscription()
|| isBackendTranscribingEnabled))
{
jvbConference.stop();
}
Expand Down Expand Up @@ -666,13 +685,10 @@ public void notify(Transcriber transcriber, TranscriptEvent event)
{
// in will_end we will be still transcribing but we need
// to explicitly send off
TranscriptionStatusExtension.Status status
= event.getEvent() ==
Transcript.TranscriptEventType.WILL_END ?
TranscriptionStatusExtension.Status.OFF
: transcriber.isTranscribing() ?
TranscriptionStatusExtension.Status.ON
: TranscriptionStatusExtension.Status.OFF;
TranscriptionStatusExtension.Status status = event.getEvent() == Transcript.TranscriptEventType.WILL_END
? TranscriptionStatusExtension.Status.OFF
: transcriber.isTranscribing()
? TranscriptionStatusExtension.Status.ON : TranscriptionStatusExtension.Status.OFF;

TranscriptionStatusExtension extension
= new TranscriptionStatusExtension();
Expand All @@ -689,4 +705,14 @@ public boolean hasCallResumeSupport()
{
return false;
}

/**
* Sets whether backend transcriptions are enabled or not.
*/
public void setBackendTranscribingEnabled(boolean backendTranscribingEnabled)
{
this.isBackendTranscribingEnabled = backendTranscribingEnabled;

this.maybeStopTranscription();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,7 @@ private Participant getParticipant(String identifier)
*/
public boolean isAnyParticipantRequestingTranscription()
{

return getParticipants()
.stream()
.anyMatch(Participant::isRequestingTranscription);
return getParticipants().stream().anyMatch(Participant::isRequestingTranscription);
}

/**
Expand Down
Loading