-
Notifications
You must be signed in to change notification settings - Fork 300
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
Changes from 1 commit
a649913
dac915a
38e93bb
f5db76d
f0fe2ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.*; | ||
|
@@ -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. | ||
*/ | ||
|
@@ -760,6 +766,24 @@ private void discoverComponentAddresses() | |
logger.info(String.format("%s Discovered %s for %oms.", | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason not to make the field |
||
{ | ||
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) | ||
{ | ||
|
@@ -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) | ||
{ | ||
|
@@ -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) | ||
{ | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: suggest to extract a |
||
|| isBackendTranscribingEnabled)) | ||
{ | ||
new Thread(() -> | ||
{ | ||
|
@@ -322,7 +340,8 @@ void notifyChatRoomMemberUpdated(ChatRoomMember chatMember, Presence presence) | |
logger.error(e); | ||
} | ||
|
||
if (!transcriber.isAnyParticipantRequestingTranscription()) | ||
if (!(transcriber.isAnyParticipantRequestingTranscription() | ||
|| isBackendTranscribingEnabled)) | ||
{ | ||
jvbConference.stop(); | ||
} | ||
|
@@ -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(); | ||
|
@@ -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(); | ||
} | ||
} |
There was a problem hiding this comment.
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 thediscoverInfo
callThere was a problem hiding this comment.
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.