Skip to content

Commit

Permalink
feat: Add an enable-rtcstats field to ColibriConferenceIQ. (#1758)
Browse files Browse the repository at this point in the history
* feat: Add an enable-rtcstats field to ColibriConferenceIQ.

* feat: Handles ColibriConferenceIQ callstats-enabled field.
  • Loading branch information
gpolitis authored Nov 23, 2021
1 parent 7fb44c1 commit 1e2879e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
23 changes: 22 additions & 1 deletion jvb/src/main/java/org/jitsi/videobridge/Conference.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public class Conference
*/
private final ConcurrentHashMap<String, AbstractEndpoint> endpointsById = new ConcurrentHashMap<>();

/**
* A boolean that indicates whether or not to include RTCStats for this call.
*/
private final boolean isRtcStatsEnabled;

/**
* A boolean that indicates whether or not to report to CallStats for this call.
*/
private final boolean isCallStatsEnabled;

/**
* A read-only cache of the endpoints in this conference. Note that it
* contains only the {@link Endpoint} instances (local endpoints, not Octo endpoints).
Expand Down Expand Up @@ -188,14 +198,18 @@ public Conference(Videobridge videobridge,
String id,
EntityBareJid conferenceName,
long gid,
@Nullable String meetingId)
@Nullable String meetingId,
boolean isRtcStatsEnabled,
boolean isCallStatsEnabled)
{
if (gid != GID_NOT_SET && (gid < 0 || gid > 0xffff_ffffL))
{
throw new IllegalArgumentException("Invalid GID:" + gid);
}
this.meetingId = meetingId;
this.videobridge = Objects.requireNonNull(videobridge, "videobridge");
this.isRtcStatsEnabled = isRtcStatsEnabled;
this.isCallStatsEnabled = isCallStatsEnabled;
Map<String, String> context = JMap.ofEntries(
entry("confId", id),
entry("gid", String.valueOf(gid))
Expand Down Expand Up @@ -789,6 +803,11 @@ public final String getID()
return id;
}

public final boolean isCallStatsEnabled()
{
return isCallStatsEnabled;
}

/**
* Gets an <tt>Endpoint</tt> participating in this <tt>Conference</tt> which
* has a specific identifier/ID.
Expand Down Expand Up @@ -1174,6 +1193,8 @@ public JSONObject getDebugState(boolean full, String endpointId)
{
JSONObject debugState = new JSONObject();
debugState.put("id", id);
debugState.put("rtcstatsEnabled", isRtcStatsEnabled);

if (conferenceName != null)
{
debugState.put("name", conferenceName.toString());
Expand Down
18 changes: 12 additions & 6 deletions jvb/src/main/java/org/jitsi/videobridge/Videobridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ public Videobridge(
* Generate conference IDs until one is found that isn't in use and create a new {@link Conference}
* object using that ID
*/
private @NotNull Conference doCreateConference(EntityBareJid name, long gid, String meetingId)
private @NotNull Conference doCreateConference(
EntityBareJid name, long gid, String meetingId,
boolean isRtcStatsEnabled, boolean isCallStatsEnabled)
{
Conference conference = null;
do
Expand All @@ -207,7 +209,7 @@ public Videobridge(
{
if (!conferencesById.containsKey(id))
{
conference = new Conference(this, id, name, gid, meetingId);
conference = new Conference(this, id, name, gid, meetingId, isRtcStatsEnabled, isCallStatsEnabled);
conferencesById.put(id, conference);
}
}
Expand All @@ -228,7 +230,8 @@ public Videobridge(
*/
public @NotNull Conference createConference(EntityBareJid name)
{
return createConference(name, Conference.GID_NOT_SET, null);
// we default to rtcstatsEnabled=false and callstatsEnabled=false because this is only used for testing
return createConference(name, Conference.GID_NOT_SET, null, false, false);
}

/**
Expand All @@ -243,9 +246,10 @@ public Videobridge(
* @return a new <tt>Conference</tt> instance with an ID unique to the
* <tt>Conference</tt> instances listed by this <tt>Videobridge</tt>
*/
public @NotNull Conference createConference(EntityBareJid name, long gid, String meetingId)
public @NotNull Conference createConference(
EntityBareJid name, long gid, String meetingId, boolean isRtcStatsEnabled, boolean isCallStatsEnabled)
{
final Conference conference = doCreateConference(name, gid, meetingId);
final Conference conference = doCreateConference(name, gid, meetingId, isRtcStatsEnabled, isCallStatsEnabled);

logger.info(() -> "create_conf, id=" + conference.getID() + " gid=" + conference.getGid());

Expand Down Expand Up @@ -427,7 +431,9 @@ private void handleColibriRequest(XmppConnection.ColibriRequest request)
return createConference(
conferenceIq.getName(),
ColibriUtil.parseGid(conferenceIq.getGID()),
conferenceIq.getMeetingId());
conferenceIq.getMeetingId(),
conferenceIq.isRtcStatsEnabled(),
conferenceIq.isCallStatsEnabled());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void stop()
@Override
public void conferenceCreated(@NotNull Conference conference)
{
if (conference.getName() != null)
if (conference.getName() != null && conference.isCallStatsEnabled())
{
// Create a new PeriodicRunnable and start it.
ConferencePeriodicRunnable cpr = new ConferencePeriodicRunnable(
Expand All @@ -125,6 +125,11 @@ public void conferenceCreated(@NotNull Conference conference)
@Override
public void conferenceExpired(@NotNull Conference conference)
{
if (!conference.isCallStatsEnabled())
{
return;
}

ConferencePeriodicRunnable cpr = statisticsProcessors.remove(conference);

if (cpr == null)
Expand Down
6 changes: 3 additions & 3 deletions jvb/src/test/kotlin/org/jitsi/videobridge/ConferenceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ class ConferenceTest : ConfigTest() {
}

context("Adding local endpoints should work") {
with(Conference(videobridge, "id", name, Conference.GID_NOT_SET, null)) {
with(Conference(videobridge, "id", name, Conference.GID_NOT_SET, null, false, false)) {
endpointCount shouldBe 0
createLocalEndpoint("abcdabcd", true)
endpointCount shouldBe 1
debugState.shouldBeValidJson()
}
}
context("Enabling octo should fail when the GID is not set") {
with(Conference(videobridge, "id", name, Conference.GID_NOT_SET, null)) {
with(Conference(videobridge, "id", name, Conference.GID_NOT_SET, null, false, false)) {
isOctoEnabled shouldBe false
shouldThrow<IllegalStateException> {
tentacle
Expand All @@ -58,7 +58,7 @@ class ConferenceTest : ConfigTest() {
}
}
context("Enabling octo should work") {
with(Conference(videobridge, "id", name, 1234, null)) {
with(Conference(videobridge, "id", name, 1234, null, false, false)) {
isOctoEnabled shouldBe false
tentacle
isOctoEnabled shouldBe true
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jitsi-xmpp-extensions</artifactId>
<version>1.0-35-g090af0a</version>
<version>1.0-36-gc8f4179</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down

0 comments on commit 1e2879e

Please sign in to comment.