Skip to content

Commit 00660c3

Browse files
authored
feat: Add rtcstats_enabled field to JibriIq (#138)
1 parent 0872ef4 commit 00660c3

3 files changed

Lines changed: 83 additions & 0 deletions

File tree

src/main/java/org/jitsi/xmpp/extensions/jibri/JibriIq.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ public class JibriIq
110110
*/
111111
static final String APP_DATA_ATTR_NAME = "app_data";
112112

113+
/**
114+
* The name of the XML attribute which stores whether rtcstats is enabled.
115+
*/
116+
static final String RTCSTATS_ENABLED_ATTR_NAME = "rtcstats_enabled";
117+
113118
/**
114119
* The name of XML attribute which stores the recording mode which can be
115120
* either 'stream' or 'file'. If the attribute is not present, but
@@ -203,6 +208,11 @@ public class JibriIq
203208
*/
204209
private EntityBareJid room = null;
205210

211+
/**
212+
* Whether rtcstats is enabled for this conference. Null means not specified.
213+
*/
214+
private Boolean rtcStatsEnabled = null;
215+
206216
public JibriIq()
207217
{
208218
super(ELEMENT, NAMESPACE);
@@ -343,6 +353,16 @@ public void setRoom(EntityBareJid room)
343353
this.room = room;
344354
}
345355

356+
public Boolean getRtcStatsEnabled()
357+
{
358+
return rtcStatsEnabled;
359+
}
360+
361+
public void setRtcStatsEnabled(Boolean rtcStatsEnabled)
362+
{
363+
this.rtcStatsEnabled = rtcStatsEnabled;
364+
}
365+
346366
/**
347367
* Whether or not this IQ represents a failure from Jibri
348368
* @return true if it represents failure, false otherwise
@@ -385,6 +405,10 @@ protected IQ.IQChildElementXmlStringBuilder getIQChildElementBuilder(IQ.IQChildE
385405
xml.attribute(SHOULD_RETRY_ATTR_NAME, shouldRetry);
386406
}
387407
xml.optAttribute(APP_DATA_ATTR_NAME, appData);
408+
if (rtcStatsEnabled != null)
409+
{
410+
xml.attribute(RTCSTATS_ENABLED_ATTR_NAME, rtcStatsEnabled);
411+
}
388412

389413
xml.setEmptyElement();
390414

src/main/java/org/jitsi/xmpp/extensions/jibri/JibriIqProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ protected JibriIq doParse(XmlPullParser parser, int initialDepth, IqData data, X
121121
= parser.getAttributeValue("", JibriIq.SIP_ADDRESS_ATTR_NAME);
122122
if (StringUtils.isNotEmpty(sipAddress))
123123
iq.setSipAddress(sipAddress);
124+
125+
String rtcStatsEnabledStr
126+
= parser.getAttributeValue("", JibriIq.RTCSTATS_ENABLED_ATTR_NAME);
127+
if (StringUtils.isNotEmpty(rtcStatsEnabledStr))
128+
{
129+
iq.setRtcStatsEnabled(Boolean.valueOf(rtcStatsEnabledStr));
130+
}
124131
}
125132
else
126133
{

src/test/java/org/jitsi/xmpp/extensions/jibri/JibriIqProviderTest.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.junit.jupiter.api.Assertions.*;
1919

2020
import org.jitsi.xmpp.extensions.*;
21+
import org.jivesoftware.smack.packet.*;
2122
import org.junit.jupiter.api.*;
2223

2324
/**
@@ -55,4 +56,55 @@ public void testParseIQ()
5556

5657
assertNull(jibriIq.getError());
5758
}
59+
60+
@Test
61+
public void testParseRtcStatsEnabled()
62+
throws Exception
63+
{
64+
JibriIqProvider provider = new JibriIqProvider();
65+
66+
String iqWithTrue =
67+
"<iq to='t' from='f' type='set'>" +
68+
"<jibri xmlns='http://jitsi.org/protocol/jibri'" +
69+
" action='start' rtcstats_enabled='true'" +
70+
"/>" +
71+
"</iq>";
72+
JibriIq iqTrue = IQUtils.parse(iqWithTrue, provider);
73+
assertEquals(Boolean.TRUE, iqTrue.getRtcStatsEnabled());
74+
75+
String iqWithFalse =
76+
"<iq to='t' from='f' type='set'>" +
77+
"<jibri xmlns='http://jitsi.org/protocol/jibri'" +
78+
" action='start' rtcstats_enabled='false'" +
79+
"/>" +
80+
"</iq>";
81+
JibriIq iqFalse = IQUtils.parse(iqWithFalse, provider);
82+
assertEquals(Boolean.FALSE, iqFalse.getRtcStatsEnabled());
83+
84+
String iqWithoutFlag =
85+
"<iq to='t' from='f' type='set'>" +
86+
"<jibri xmlns='http://jitsi.org/protocol/jibri'" +
87+
" action='start'" +
88+
"/>" +
89+
"</iq>";
90+
JibriIq iqAbsent = IQUtils.parse(iqWithoutFlag, provider);
91+
assertNull(iqAbsent.getRtcStatsEnabled());
92+
}
93+
94+
@Test
95+
public void testSerializeRtcStatsEnabled()
96+
{
97+
JibriIq iq = new JibriIq();
98+
iq.setType(IQ.Type.set);
99+
iq.setAction(JibriIq.Action.START);
100+
101+
iq.setRtcStatsEnabled(true);
102+
assertTrue(iq.toXML().toString().contains("rtcstats_enabled='true'"));
103+
104+
iq.setRtcStatsEnabled(false);
105+
assertTrue(iq.toXML().toString().contains("rtcstats_enabled='false'"));
106+
107+
iq.setRtcStatsEnabled(null);
108+
assertFalse(iq.toXML().toString().contains("rtcstats_enabled"));
109+
}
58110
}

0 commit comments

Comments
 (0)