Skip to content

Commit

Permalink
make transcriber leave a conference based on participants presence (j…
Browse files Browse the repository at this point in the history
…itsi#129)

* make transcriber leave a conference based on participants presence

* remove TranscriptionStatus from Jigasi

* change leave logic of Transcriber to use TranscriptionRequestExtension

* update jitsi-desk
  • Loading branch information
nikvaessen authored and bgrozev committed Aug 24, 2018
1 parent 41dced8 commit 91881f3
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 112 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<properties>
<assembly.skipAssembly>true</assembly.skipAssembly>
<smack.version>4.2.1</smack.version>
<jitsi-desktop.version>2.13.812e3ed</jitsi-desktop.version>
<jitsi-desktop.version>2.13.5160aa9</jitsi-desktop.version>
</properties>

<dependencies>
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/org/jitsi/jigasi/TranscriptionGatewaySession.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.service.protocol.media.*;
import org.jitsi.jigasi.transcription.*;
import org.jitsi.jigasi.xmpp.*;
import org.jitsi.service.neomedia.*;
import org.jitsi.service.neomedia.device.*;
import org.jitsi.util.*;
Expand Down Expand Up @@ -58,6 +57,12 @@ public class TranscriptionGatewaySession
*/
public final static String DISPLAY_NAME = "Transcriber";

/**
* How long the transcriber should wait until really leaving the conference
* when no participant is requesting transcription anymore.
*/
public final static int PRESENCE_UPDATE_WAIT_UNTIL_LEAVE_DURATION = 2500;

/**
* The TranscriptionService used by this session
*/
Expand Down Expand Up @@ -296,6 +301,27 @@ void notifyChatRoomMemberUpdated(ChatRoomMember chatMember, Presence presence)
{
this.transcriber.updateParticipantTargetLanguage(identifier, null);
}

if(transcriber.isTranscribing() &&
!transcriber.isAnyParticipantRequestingTranscription())
{
new Thread(() ->
{
try
{
Thread.sleep(PRESENCE_UPDATE_WAIT_UNTIL_LEAVE_DURATION);
}
catch (InterruptedException e)
{
e.printStackTrace();
}

if(!transcriber.isAnyParticipantRequestingTranscription())
{
jvbConference.stop();
}
}).start();
}
}

@Override
Expand Down
53 changes: 51 additions & 2 deletions src/main/java/org/jitsi/jigasi/transcription/Participant.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ private AvatarIdPacketExtension getAvatarIdExtensionOrNull(Presence p)
AvatarIdPacketExtension.NAME_SPACE);
}

private TranscriptionRequestExtension
getTranscriptionRequestExtensionOrNull(Presence p)
{
return p.getExtension(TranscriptionRequestExtension.ELEMENT_NAME,
TranscriptionRequestExtension.NAMESPACE);
}

/**
* Get the ssrc of the audio of this participant
*
Expand All @@ -364,7 +371,9 @@ public long getSSRC()
*/
public String getSourceLanguage()
{
return sourceLanguageLocale.getLanguage();
return sourceLanguageLocale == null ?
null :
sourceLanguageLocale.getLanguage();
}

/**
Expand All @@ -384,7 +393,14 @@ public String getTranslationLanguage()
*/
public void setSourceLanguage(String language)
{
sourceLanguageLocale = Locale.forLanguageTag(language);
if (language == null)
{
sourceLanguageLocale = null;
}
else
{
sourceLanguageLocale = Locale.forLanguageTag(language);
}
}

/**
Expand Down Expand Up @@ -617,4 +633,37 @@ private static long getConferenceMemberAudioSSRC(
// bitwise AND to fix signed int casted to long
return confMember.getAudioSsrc() & 0xffffffffL;
}

/**
* Check whether this Participant is requesting a source language
*
* @return true when the source language is set and non-empty, false
* otherwise.
*/
public boolean hasValidSourceLanguage()
{
String lang = this.getSourceLanguage();

return lang != null && !lang.isEmpty();
}

/**
* Get whether this {@link Participant} is requesting transcription by
* checking the {@link TranscriptionRequestExtension} in the
* {@link Presence}
*
* @return true when the {@link Participant} is requesting transcription,
* false otherwise
*/
public boolean isRequestingTranscription()
{
ChatRoomMemberJabberImpl memberJabber
= ((ChatRoomMemberJabberImpl) this.chatMember);

TranscriptionRequestExtension ext
= getTranscriptionRequestExtensionOrNull(
memberJabber.getLastPresence());

return ext != null && Boolean.valueOf(ext.getText());
}
}
27 changes: 25 additions & 2 deletions src/main/java/org/jitsi/jigasi/transcription/Transcriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,14 @@ public void bufferReceived(ReceiveStream receiveStream, Buffer buffer)
long ssrc = receiveStream.getSSRC() & 0xffffffffL;

Participant p = findParticipant(ssrc);

if (p != null)
{
logger.trace("Gave audio to buffer");
p.giveBuffer(buffer);
if (p.hasValidSourceLanguage())
{
logger.trace("Gave audio to buffer");
p.giveBuffer(buffer);
}
}
else
{
Expand Down Expand Up @@ -660,6 +664,25 @@ private Participant getParticipant(String identifier)
}
}

/**
* Check whether any {@link Participant} are requesting transcription
*
* @return true when at least one {@link Participant} is requesting
* transcription, false otherwise
*/
public boolean isAnyParticipantRequestingTranscription()
{
List<Participant> participantsCopy;
synchronized (this.participants)
{
participantsCopy = new ArrayList<>(this.participants.values());
}

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

/**
* Get the MediaDevice this transcriber is listening to for audio
*
Expand Down
106 changes: 0 additions & 106 deletions src/main/java/org/jitsi/jigasi/xmpp/TranscriptionStatusExtension.java

This file was deleted.

0 comments on commit 91881f3

Please sign in to comment.