Skip to content

Commit bd8ea01

Browse files
committed
Add forcemute unmute
1 parent cb27476 commit bd8ea01

File tree

4 files changed

+259
-3
lines changed

4 files changed

+259
-3
lines changed

src/main/java/org/jitsi/jigasi/JvbConference.java

Lines changed: 185 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.jitsi.jigasi;
1919

20+
import org.jitsi.jigasi.mute.*;
2021
import net.java.sip.communicator.impl.protocol.jabber.*;
2122
import net.java.sip.communicator.service.protocol.*;
2223
import net.java.sip.communicator.service.protocol.event.*;
@@ -37,12 +38,17 @@
3738
import org.jitsi.xmpp.extensions.rayo.*;
3839
import org.jivesoftware.smack.*;
3940
import org.jivesoftware.smack.bosh.*;
41+
import org.jivesoftware.smack.filter.StanzaTypeFilter;
4042
import org.jivesoftware.smack.iqrequest.*;
4143
import org.jivesoftware.smack.packet.*;
42-
import org.jivesoftware.smackx.disco.*;
43-
import org.jivesoftware.smackx.disco.packet.*;
44+
4445
import org.jivesoftware.smackx.nick.packet.*;
45-
import org.jivesoftware.smackx.xdata.packet.*;
46+
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
47+
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
48+
import org.jivesoftware.smackx.muc.packet.MUCUser;
49+
import org.jivesoftware.smackx.xdata.FormField;
50+
import org.jivesoftware.smackx.xdata.packet.DataForm;
51+
4652
import org.jxmpp.jid.*;
4753
import org.jxmpp.jid.impl.*;
4854
import org.jxmpp.jid.parts.*;
@@ -152,6 +158,12 @@ public class JvbConference
152158
public static final String LOCAL_REGION_PNAME
153159
= "org.jitsi.jigasi.LOCAL_REGION";
154160

161+
/**
162+
*
163+
*/
164+
private static final String VAR_ROOM_CONFIGURATION_SQUELCHED_JID
165+
= "muc#roomconfig_squelched";
166+
155167
/**
156168
* Adds the features supported by jigasi to a specific
157169
* <tt>OperationSetJitsiMeetTools</tt> instance.
@@ -318,6 +330,10 @@ private static void addSupportedFeatures(
318330
*/
319331
private MuteIqHandler muteIqHandler = null;
320332

333+
private RoomConfigurationListener roomConfigurationListener = null;
334+
335+
private ForceMute forceMute = null;
336+
321337
/**
322338
* Creates new instance of <tt>JvbConference</tt>
323339
* @param gatewaySession the <tt>AbstractGatewaySession</tt> that will be
@@ -328,6 +344,8 @@ public JvbConference(AbstractGatewaySession gatewaySession, CallContext ctx)
328344
{
329345
this.gatewaySession = gatewaySession;
330346
this.callContext = ctx;
347+
this.roomConfigurationListener = new RoomConfigurationListener(this);
348+
this.forceMute = new ForceMuteDisabled(this);
331349
}
332350

333351
private Localpart getResourceIdentifier()
@@ -810,6 +828,10 @@ public void joinConferenceRoom()
810828
// the room)
811829
inviteTimeout.scheduleTimeout();
812830

831+
this.getConnection()
832+
.addAsyncStanzaListener(this.roomConfigurationListener,
833+
new StanzaTypeFilter(org.jivesoftware.smack.packet.Message.class));
834+
813835
if (StringUtils.isNullOrEmpty(roomPassword))
814836
{
815837
mucRoom.joinAs(resourceIdentifier.toString());
@@ -836,6 +858,11 @@ public void joinConferenceRoom()
836858
}
837859

838860
gatewaySession.notifyJvbRoomJoined();
861+
862+
// ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.getConnection());
863+
//
864+
// DiscoverInfo discoverInfo = serviceDiscoveryManager.discoverInfo(JidCreate.entityBareFrom(this.mucRoom.getIdentifier()));
865+
839866
}
840867
catch (Exception e)
841868
{
@@ -1021,6 +1048,11 @@ private void onJvbCallEnded()
10211048

10221049
private void leaveConferenceRoom()
10231050
{
1051+
if (roomConfigurationListener != null)
1052+
{
1053+
this.getConnection().removeAsyncStanzaListener(this.roomConfigurationListener);
1054+
}
1055+
10241056
if (this.jitsiMeetTools != null)
10251057
{
10261058
this.jitsiMeetTools.removeRequestListener(this.gatewaySession);
@@ -1969,4 +2001,154 @@ private IQ handleMuteIq(MuteIq muteIq)
19692001
return IQ.createResultIQ(muteIq);
19702002
}
19712003
}
2004+
2005+
class RoomConfigurationListener implements StanzaListener
2006+
{
2007+
/**
2008+
* XEP-0045
2009+
* Status code for unknown room configuration changes.
2010+
*/
2011+
public final MUCUser.Status ROOM_CONFIGURATION_CHANGED_104 = MUCUser.Status.create(104);
2012+
2013+
/**
2014+
* Constructs a new room configuration listener that handles the notifications.
2015+
*/
2016+
private JvbConference jvbConference;
2017+
2018+
RoomConfigurationListener(JvbConference jvbConference)
2019+
{
2020+
this.jvbConference = jvbConference;
2021+
}
2022+
2023+
/**
2024+
* This handles the MUCUser extension status codes if the extension exists.
2025+
*
2026+
* @param packet
2027+
* @throws SmackException.NotConnectedException
2028+
* @throws InterruptedException
2029+
* @throws SmackException.NotLoggedInException
2030+
*/
2031+
@Override
2032+
public void processStanza(Stanza packet)
2033+
throws SmackException.NotConnectedException, InterruptedException, SmackException.NotLoggedInException
2034+
{
2035+
/**
2036+
* TODO check room configuration if force mute is enabled only.
2037+
*/
2038+
try
2039+
{
2040+
MUCUser mucUser = getMUCUserExtension(packet);
2041+
2042+
if (mucUser != null)
2043+
{
2044+
for (MUCUser.Status status: mucUser.getStatus()) {
2045+
if (status.getCode() == ROOM_CONFIGURATION_CHANGED_104.getCode())
2046+
{
2047+
// Room configuration changed
2048+
this.jvbConference.onRoomConfigurationChanged();
2049+
}
2050+
}
2051+
}
2052+
}
2053+
catch(Exception ex)
2054+
{
2055+
logger.error(ex.toString());
2056+
}
2057+
}
2058+
2059+
/**
2060+
* Returns the MUCUser packet extension included in the packet or <tt>null</tt> if none.
2061+
*
2062+
* @param packet the packet that may include the MUCUser extension.
2063+
* @return the MUCUser found in the packet.
2064+
*/
2065+
private MUCUser getMUCUserExtension(Stanza packet)
2066+
{
2067+
if (packet != null)
2068+
{
2069+
// Get the MUC User extension
2070+
return (MUCUser) packet.getExtension("x",
2071+
"http://jabber.org/protocol/muc#user");
2072+
}
2073+
return null;
2074+
}
2075+
}
2076+
2077+
/**
2078+
* Moderator has enabled force mute.
2079+
*/
2080+
private void onSessionForceMute()
2081+
{
2082+
this.forceMute = new ForceMuteEnabled(this);
2083+
}
2084+
2085+
/**
2086+
* Moderator has allowed the participant to unmute.
2087+
*/
2088+
private void onAllowedToUnmute()
2089+
{
2090+
this.forceMute = new ForceMuteDisabled(this);
2091+
}
2092+
2093+
/**
2094+
* Called when room configuration has changed.
2095+
*/
2096+
private void onRoomConfigurationChanged()
2097+
{
2098+
try
2099+
{
2100+
if (this.mucRoom != null)
2101+
{
2102+
ServiceDiscoveryManager serviceDiscoveryManager
2103+
= ServiceDiscoveryManager.getInstanceFor(this.getConnection());
2104+
2105+
DiscoverInfo discoverInfo
2106+
= serviceDiscoveryManager.discoverInfo(JidCreate.entityBareFrom(this.mucRoom.getIdentifier()));
2107+
2108+
DataForm formExtension = discoverInfo.getExtension("x", "jabber:x:data");
2109+
2110+
FormField formField = formExtension.getField(VAR_ROOM_CONFIGURATION_SQUELCHED_JID);
2111+
2112+
if (formField.getType() == FormField.Type.jid_multi)
2113+
{
2114+
List<String> squelchedList = formField.getValues();
2115+
2116+
// TODO Get local resource identifier
2117+
2118+
EntityBareJid roomJid = JidCreate.entityBareFrom(this.mucRoom.getIdentifier());
2119+
2120+
EntityFullJid localFullJid
2121+
= JidCreate.fullFrom(roomJid,
2122+
Resourcepart.from(this.getResourceIdentifier().toString()));
2123+
2124+
boolean allowedToSpeak = !squelchedList.contains(localFullJid.toString());
2125+
2126+
if (this.forceMute != null)
2127+
{
2128+
this.forceMute.setAllowedToSpeak(allowedToSpeak);
2129+
}
2130+
2131+
if (allowedToSpeak)
2132+
{
2133+
2134+
logger.error("ALLOWED TO SPEAK!!!");
2135+
}
2136+
else
2137+
{
2138+
2139+
logger.error("NOT ALLOWED TO SPEAK!!!");
2140+
}
2141+
2142+
}
2143+
}
2144+
else
2145+
{
2146+
logger.error("No MUC room when trying to retrieve room configuration!");
2147+
}
2148+
}
2149+
catch (Exception ex)
2150+
{
2151+
logger.error(ex.toString());
2152+
}
2153+
}
19722154
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.jitsi.jigasi.mute;
2+
3+
public interface ForceMute
4+
{
5+
void requestAudioMute(boolean muted);
6+
7+
void setAllowedToSpeak(boolean allowedToSpeak);
8+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.jitsi.jigasi.mute;
2+
3+
import org.jitsi.jigasi.JvbConference;
4+
5+
public class ForceMuteDisabled
6+
implements ForceMute
7+
{
8+
9+
private JvbConference conference;
10+
11+
public ForceMuteDisabled(JvbConference jvbConference)
12+
{
13+
this.conference = jvbConference;
14+
}
15+
16+
@Override
17+
public void requestAudioMute(boolean muted)
18+
{
19+
this.conference.requestAudioMute(muted);
20+
}
21+
22+
@Override
23+
public void setAllowedToSpeak(boolean allowedToSpeak)
24+
{
25+
26+
}
27+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.jitsi.jigasi.mute;
2+
3+
import org.jitsi.jigasi.JvbConference;
4+
5+
public class ForceMuteEnabled
6+
implements ForceMute
7+
{
8+
private JvbConference conference;
9+
10+
private boolean allowedToSpeak;
11+
12+
public ForceMuteEnabled(JvbConference jvbConference)
13+
{
14+
this.conference = jvbConference;
15+
this.allowedToSpeak = false;
16+
}
17+
18+
@Override
19+
public void requestAudioMute(boolean muted)
20+
{
21+
if (muted == false)
22+
{
23+
if (this.allowedToSpeak == false)
24+
{
25+
//
26+
27+
return;
28+
}
29+
}
30+
31+
this.conference.requestAudioMute(muted);
32+
}
33+
34+
@Override
35+
public void setAllowedToSpeak(boolean allowedToSpeak)
36+
{
37+
this.allowedToSpeak = allowedToSpeak;
38+
}
39+
}

0 commit comments

Comments
 (0)