1717 */
1818package org .jitsi .jigasi ;
1919
20+ import org .jitsi .jigasi .mute .*;
2021import net .java .sip .communicator .impl .protocol .jabber .*;
2122import net .java .sip .communicator .service .protocol .*;
2223import net .java .sip .communicator .service .protocol .event .*;
3738import org .jitsi .xmpp .extensions .rayo .*;
3839import org .jivesoftware .smack .*;
3940import org .jivesoftware .smack .bosh .*;
41+ import org .jivesoftware .smack .filter .StanzaTypeFilter ;
4042import org .jivesoftware .smack .iqrequest .*;
4143import org .jivesoftware .smack .packet .*;
42- import org .jivesoftware .smackx .disco .*;
43- import org .jivesoftware .smackx .disco .packet .*;
44+
4445import 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+
4652import org .jxmpp .jid .*;
4753import org .jxmpp .jid .impl .*;
4854import 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}
0 commit comments