Skip to content

Commit

Permalink
Add forcemute unmute
Browse files Browse the repository at this point in the history
  • Loading branch information
cristifg committed Sep 21, 2020
1 parent 6df3db2 commit 3f1f246
Show file tree
Hide file tree
Showing 4 changed files with 261 additions and 0 deletions.
187 changes: 187 additions & 0 deletions src/main/java/org/jitsi/jigasi/JvbConference.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
*/
package org.jitsi.jigasi;

import org.jitsi.jigasi.mute.*;
import net.java.sip.communicator.impl.protocol.jabber.*;
import net.java.sip.communicator.service.gui.ConfigurationForm;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.service.protocol.jabber.*;
Expand All @@ -36,9 +38,18 @@
import org.jitsi.xmpp.extensions.rayo.*;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.bosh.*;
import org.jivesoftware.smack.filter.StanzaTypeFilter;
import org.jivesoftware.smack.iqrequest.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.smackx.muc.packet.MUCUser;
import org.jivesoftware.smackx.nick.packet.*;
import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.jxmpp.jid.*;
import org.jxmpp.jid.impl.*;
import org.jxmpp.jid.parts.*;
Expand Down Expand Up @@ -148,6 +159,12 @@ public class JvbConference
public static final String LOCAL_REGION_PNAME
= "org.jitsi.jigasi.LOCAL_REGION";

/**
*
*/
private static final String VAR_ROOM_CONFIGURATION_SQUELCHED_JID
= "muc#roomconfig_squelched";

/**
* Adds the features supported by jigasi to a specific
* <tt>OperationSetJitsiMeetTools</tt> instance.
Expand Down Expand Up @@ -314,6 +331,10 @@ private static void addSupportedFeatures(
*/
private MuteIqHandler muteIqHandler = null;

private RoomConfigurationListener roomConfigurationListener = null;

private ForceMute forceMute = null;

/**
* Creates new instance of <tt>JvbConference</tt>
* @param gatewaySession the <tt>AbstractGatewaySession</tt> that will be
Expand All @@ -324,6 +345,8 @@ public JvbConference(AbstractGatewaySession gatewaySession, CallContext ctx)
{
this.gatewaySession = gatewaySession;
this.callContext = ctx;
this.roomConfigurationListener = new RoomConfigurationListener(this);
this.forceMute = new ForceMuteDisabled(this);
}

private Localpart getResourceIdentifier()
Expand Down Expand Up @@ -800,6 +823,10 @@ private void joinConferenceRoom()
// the room)
inviteTimeout.scheduleTimeout();

this.getConnection()
.addAsyncStanzaListener(this.roomConfigurationListener,
new StanzaTypeFilter(org.jivesoftware.smack.packet.Message.class));

if (StringUtils.isNullOrEmpty(roomPassword))
{
mucRoom.joinAs(resourceIdentifier.toString());
Expand All @@ -826,6 +853,11 @@ private void joinConferenceRoom()
}

gatewaySession.notifyJvbRoomJoined();

// ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.getConnection());
//
// DiscoverInfo discoverInfo = serviceDiscoveryManager.discoverInfo(JidCreate.entityBareFrom(this.mucRoom.getIdentifier()));

}
catch (Exception e)
{
Expand Down Expand Up @@ -913,6 +945,11 @@ private void onJvbCallEnded()

private void leaveConferenceRoom()
{
if (roomConfigurationListener != null)
{
this.getConnection().removeAsyncStanzaListener(this.roomConfigurationListener);
}

if (this.jitsiMeetTools != null)
{
this.jitsiMeetTools.removeRequestListener(this.gatewaySession);
Expand Down Expand Up @@ -1772,4 +1809,154 @@ private IQ handleMuteIq(MuteIq muteIq)
return IQ.createResultIQ(muteIq);
}
}

class RoomConfigurationListener implements StanzaListener
{
/**
* XEP-0045
* Status code for unknown room configuration changes.
*/
public final MUCUser.Status ROOM_CONFIGURATION_CHANGED_104 = MUCUser.Status.create(104);

/**
* Constructs a new room configuration listener that handles the notifications.
*/
private JvbConference jvbConference;

RoomConfigurationListener(JvbConference jvbConference)
{
this.jvbConference = jvbConference;
}

/**
* This handles the MUCUser extension status codes if the extension exists.
*
* @param packet
* @throws SmackException.NotConnectedException
* @throws InterruptedException
* @throws SmackException.NotLoggedInException
*/
@Override
public void processStanza(Stanza packet)
throws SmackException.NotConnectedException, InterruptedException, SmackException.NotLoggedInException
{
/**
* TODO check room configuration if force mute is enabled only.
*/
try
{
MUCUser mucUser = getMUCUserExtension(packet);

if (mucUser != null)
{
for (MUCUser.Status status: mucUser.getStatus()) {
if (status.getCode() == ROOM_CONFIGURATION_CHANGED_104.getCode())
{
// Room configuration changed
this.jvbConference.onRoomConfigurationChanged();
}
}
}
}
catch(Exception ex)
{
logger.error(ex.toString());
}
}

/**
* Returns the MUCUser packet extension included in the packet or <tt>null</tt> if none.
*
* @param packet the packet that may include the MUCUser extension.
* @return the MUCUser found in the packet.
*/
private MUCUser getMUCUserExtension(Stanza packet)
{
if (packet != null)
{
// Get the MUC User extension
return (MUCUser) packet.getExtension("x",
"http://jabber.org/protocol/muc#user");
}
return null;
}
}

/**
* Moderator has enabled force mute.
*/
private void onSessionForceMute()
{
this.forceMute = new ForceMuteEnabled(this);
}

/**
* Moderator has allowed the participant to unmute.
*/
private void onAllowedToUnmute()
{
this.forceMute = new ForceMuteDisabled(this);
}

/**
* Called when room configuration has changed.
*/
private void onRoomConfigurationChanged()
{
try
{
if (this.mucRoom != null)
{
ServiceDiscoveryManager serviceDiscoveryManager
= ServiceDiscoveryManager.getInstanceFor(this.getConnection());

DiscoverInfo discoverInfo
= serviceDiscoveryManager.discoverInfo(JidCreate.entityBareFrom(this.mucRoom.getIdentifier()));

DataForm formExtension = discoverInfo.getExtension("x", "jabber:x:data");

FormField formField = formExtension.getField(VAR_ROOM_CONFIGURATION_SQUELCHED_JID);

if (formField.getType() == FormField.Type.jid_multi)
{
List<String> squelchedList = formField.getValues();

// TODO Get local resource identifier

EntityBareJid roomJid = JidCreate.entityBareFrom(this.mucRoom.getIdentifier());

EntityFullJid localFullJid
= JidCreate.fullFrom(roomJid,
Resourcepart.from(this.getResourceIdentifier().toString()));

boolean allowedToSpeak = !squelchedList.contains(localFullJid.toString());

if (this.forceMute != null)
{
this.forceMute.setAllowedToSpeak(allowedToSpeak);
}

if (allowedToSpeak)
{

logger.error("ALLOWED TO SPEAK!!!");
}
else
{

logger.error("NOT ALLOWED TO SPEAK!!!");
}

}
}
else
{
logger.error("No MUC room when trying to retrieve room configuration!");
}
}
catch (Exception ex)
{
logger.error(ex.toString());
}
}
}
8 changes: 8 additions & 0 deletions src/main/java/org/jitsi/jigasi/mute/ForceMute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jitsi.jigasi.mute;

public interface ForceMute
{
void requestAudioMute(boolean muted);

void setAllowedToSpeak(boolean allowedToSpeak);
}
27 changes: 27 additions & 0 deletions src/main/java/org/jitsi/jigasi/mute/ForceMuteDisabled.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jitsi.jigasi.mute;

import org.jitsi.jigasi.JvbConference;

public class ForceMuteDisabled
implements ForceMute
{

private JvbConference conference;

public ForceMuteDisabled(JvbConference jvbConference)
{
this.conference = jvbConference;
}

@Override
public void requestAudioMute(boolean muted)
{
this.conference.requestAudioMute(muted);
}

@Override
public void setAllowedToSpeak(boolean allowedToSpeak)
{

}
}
39 changes: 39 additions & 0 deletions src/main/java/org/jitsi/jigasi/mute/ForceMuteEnabled.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jitsi.jigasi.mute;

import org.jitsi.jigasi.JvbConference;

public class ForceMuteEnabled
implements ForceMute
{
private JvbConference conference;

private boolean allowedToSpeak;

public ForceMuteEnabled(JvbConference jvbConference)
{
this.conference = jvbConference;
this.allowedToSpeak = false;
}

@Override
public void requestAudioMute(boolean muted)
{
if (muted == false)
{
if (this.allowedToSpeak == false)
{
//

return;
}
}

this.conference.requestAudioMute(muted);
}

@Override
public void setAllowedToSpeak(boolean allowedToSpeak)
{
this.allowedToSpeak = allowedToSpeak;
}
}

0 comments on commit 3f1f246

Please sign in to comment.