Skip to content

Commit 3f1f246

Browse files
committed
Add forcemute unmute
1 parent 6df3db2 commit 3f1f246

File tree

4 files changed

+261
-0
lines changed

4 files changed

+261
-0
lines changed

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

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

20+
import org.jitsi.jigasi.mute.*;
2021
import net.java.sip.communicator.impl.protocol.jabber.*;
22+
import net.java.sip.communicator.service.gui.ConfigurationForm;
2123
import net.java.sip.communicator.service.protocol.*;
2224
import net.java.sip.communicator.service.protocol.event.*;
2325
import net.java.sip.communicator.service.protocol.jabber.*;
@@ -36,9 +38,18 @@
3638
import org.jitsi.xmpp.extensions.rayo.*;
3739
import org.jivesoftware.smack.*;
3840
import org.jivesoftware.smack.bosh.*;
41+
import org.jivesoftware.smack.filter.StanzaTypeFilter;
3942
import org.jivesoftware.smack.iqrequest.*;
4043
import org.jivesoftware.smack.packet.*;
44+
import org.jivesoftware.smack.packet.Message;
45+
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
46+
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
47+
import org.jivesoftware.smackx.muc.MultiUserChat;
48+
import org.jivesoftware.smackx.muc.packet.MUCUser;
4149
import org.jivesoftware.smackx.nick.packet.*;
50+
import org.jivesoftware.smackx.xdata.Form;
51+
import org.jivesoftware.smackx.xdata.FormField;
52+
import org.jivesoftware.smackx.xdata.packet.DataForm;
4253
import org.jxmpp.jid.*;
4354
import org.jxmpp.jid.impl.*;
4455
import org.jxmpp.jid.parts.*;
@@ -148,6 +159,12 @@ public class JvbConference
148159
public static final String LOCAL_REGION_PNAME
149160
= "org.jitsi.jigasi.LOCAL_REGION";
150161

162+
/**
163+
*
164+
*/
165+
private static final String VAR_ROOM_CONFIGURATION_SQUELCHED_JID
166+
= "muc#roomconfig_squelched";
167+
151168
/**
152169
* Adds the features supported by jigasi to a specific
153170
* <tt>OperationSetJitsiMeetTools</tt> instance.
@@ -314,6 +331,10 @@ private static void addSupportedFeatures(
314331
*/
315332
private MuteIqHandler muteIqHandler = null;
316333

334+
private RoomConfigurationListener roomConfigurationListener = null;
335+
336+
private ForceMute forceMute = null;
337+
317338
/**
318339
* Creates new instance of <tt>JvbConference</tt>
319340
* @param gatewaySession the <tt>AbstractGatewaySession</tt> that will be
@@ -324,6 +345,8 @@ public JvbConference(AbstractGatewaySession gatewaySession, CallContext ctx)
324345
{
325346
this.gatewaySession = gatewaySession;
326347
this.callContext = ctx;
348+
this.roomConfigurationListener = new RoomConfigurationListener(this);
349+
this.forceMute = new ForceMuteDisabled(this);
327350
}
328351

329352
private Localpart getResourceIdentifier()
@@ -800,6 +823,10 @@ private void joinConferenceRoom()
800823
// the room)
801824
inviteTimeout.scheduleTimeout();
802825

826+
this.getConnection()
827+
.addAsyncStanzaListener(this.roomConfigurationListener,
828+
new StanzaTypeFilter(org.jivesoftware.smack.packet.Message.class));
829+
803830
if (StringUtils.isNullOrEmpty(roomPassword))
804831
{
805832
mucRoom.joinAs(resourceIdentifier.toString());
@@ -826,6 +853,11 @@ private void joinConferenceRoom()
826853
}
827854

828855
gatewaySession.notifyJvbRoomJoined();
856+
857+
// ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.getConnection());
858+
//
859+
// DiscoverInfo discoverInfo = serviceDiscoveryManager.discoverInfo(JidCreate.entityBareFrom(this.mucRoom.getIdentifier()));
860+
829861
}
830862
catch (Exception e)
831863
{
@@ -913,6 +945,11 @@ private void onJvbCallEnded()
913945

914946
private void leaveConferenceRoom()
915947
{
948+
if (roomConfigurationListener != null)
949+
{
950+
this.getConnection().removeAsyncStanzaListener(this.roomConfigurationListener);
951+
}
952+
916953
if (this.jitsiMeetTools != null)
917954
{
918955
this.jitsiMeetTools.removeRequestListener(this.gatewaySession);
@@ -1772,4 +1809,154 @@ private IQ handleMuteIq(MuteIq muteIq)
17721809
return IQ.createResultIQ(muteIq);
17731810
}
17741811
}
1812+
1813+
class RoomConfigurationListener implements StanzaListener
1814+
{
1815+
/**
1816+
* XEP-0045
1817+
* Status code for unknown room configuration changes.
1818+
*/
1819+
public final MUCUser.Status ROOM_CONFIGURATION_CHANGED_104 = MUCUser.Status.create(104);
1820+
1821+
/**
1822+
* Constructs a new room configuration listener that handles the notifications.
1823+
*/
1824+
private JvbConference jvbConference;
1825+
1826+
RoomConfigurationListener(JvbConference jvbConference)
1827+
{
1828+
this.jvbConference = jvbConference;
1829+
}
1830+
1831+
/**
1832+
* This handles the MUCUser extension status codes if the extension exists.
1833+
*
1834+
* @param packet
1835+
* @throws SmackException.NotConnectedException
1836+
* @throws InterruptedException
1837+
* @throws SmackException.NotLoggedInException
1838+
*/
1839+
@Override
1840+
public void processStanza(Stanza packet)
1841+
throws SmackException.NotConnectedException, InterruptedException, SmackException.NotLoggedInException
1842+
{
1843+
/**
1844+
* TODO check room configuration if force mute is enabled only.
1845+
*/
1846+
try
1847+
{
1848+
MUCUser mucUser = getMUCUserExtension(packet);
1849+
1850+
if (mucUser != null)
1851+
{
1852+
for (MUCUser.Status status: mucUser.getStatus()) {
1853+
if (status.getCode() == ROOM_CONFIGURATION_CHANGED_104.getCode())
1854+
{
1855+
// Room configuration changed
1856+
this.jvbConference.onRoomConfigurationChanged();
1857+
}
1858+
}
1859+
}
1860+
}
1861+
catch(Exception ex)
1862+
{
1863+
logger.error(ex.toString());
1864+
}
1865+
}
1866+
1867+
/**
1868+
* Returns the MUCUser packet extension included in the packet or <tt>null</tt> if none.
1869+
*
1870+
* @param packet the packet that may include the MUCUser extension.
1871+
* @return the MUCUser found in the packet.
1872+
*/
1873+
private MUCUser getMUCUserExtension(Stanza packet)
1874+
{
1875+
if (packet != null)
1876+
{
1877+
// Get the MUC User extension
1878+
return (MUCUser) packet.getExtension("x",
1879+
"http://jabber.org/protocol/muc#user");
1880+
}
1881+
return null;
1882+
}
1883+
}
1884+
1885+
/**
1886+
* Moderator has enabled force mute.
1887+
*/
1888+
private void onSessionForceMute()
1889+
{
1890+
this.forceMute = new ForceMuteEnabled(this);
1891+
}
1892+
1893+
/**
1894+
* Moderator has allowed the participant to unmute.
1895+
*/
1896+
private void onAllowedToUnmute()
1897+
{
1898+
this.forceMute = new ForceMuteDisabled(this);
1899+
}
1900+
1901+
/**
1902+
* Called when room configuration has changed.
1903+
*/
1904+
private void onRoomConfigurationChanged()
1905+
{
1906+
try
1907+
{
1908+
if (this.mucRoom != null)
1909+
{
1910+
ServiceDiscoveryManager serviceDiscoveryManager
1911+
= ServiceDiscoveryManager.getInstanceFor(this.getConnection());
1912+
1913+
DiscoverInfo discoverInfo
1914+
= serviceDiscoveryManager.discoverInfo(JidCreate.entityBareFrom(this.mucRoom.getIdentifier()));
1915+
1916+
DataForm formExtension = discoverInfo.getExtension("x", "jabber:x:data");
1917+
1918+
FormField formField = formExtension.getField(VAR_ROOM_CONFIGURATION_SQUELCHED_JID);
1919+
1920+
if (formField.getType() == FormField.Type.jid_multi)
1921+
{
1922+
List<String> squelchedList = formField.getValues();
1923+
1924+
// TODO Get local resource identifier
1925+
1926+
EntityBareJid roomJid = JidCreate.entityBareFrom(this.mucRoom.getIdentifier());
1927+
1928+
EntityFullJid localFullJid
1929+
= JidCreate.fullFrom(roomJid,
1930+
Resourcepart.from(this.getResourceIdentifier().toString()));
1931+
1932+
boolean allowedToSpeak = !squelchedList.contains(localFullJid.toString());
1933+
1934+
if (this.forceMute != null)
1935+
{
1936+
this.forceMute.setAllowedToSpeak(allowedToSpeak);
1937+
}
1938+
1939+
if (allowedToSpeak)
1940+
{
1941+
1942+
logger.error("ALLOWED TO SPEAK!!!");
1943+
}
1944+
else
1945+
{
1946+
1947+
logger.error("NOT ALLOWED TO SPEAK!!!");
1948+
}
1949+
1950+
}
1951+
}
1952+
else
1953+
{
1954+
logger.error("No MUC room when trying to retrieve room configuration!");
1955+
}
1956+
}
1957+
catch (Exception ex)
1958+
{
1959+
logger.error(ex.toString());
1960+
}
1961+
}
17751962
}
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)