1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-12 08:42:46 +03:00

Make webrtc stats collection optional (#3307)

* stats: disable stats collection if interval zero

* stats: add groupcall property for stats interval

* stats: disable collecting webrtc stats by default

* add setup methode for group call stats

* suppress lint errors in test
This commit is contained in:
Enrico Schwendig
2023-04-27 08:56:58 +02:00
committed by GitHub
parent 8f701f43fb
commit 261bc81554
4 changed files with 115 additions and 11 deletions

View File

@@ -236,7 +236,12 @@ export class GroupCall extends TypedEventEmitter<
private initWithVideoMuted = false;
private initCallFeedPromise?: Promise<void>;
private readonly stats: GroupCallStats;
private stats: GroupCallStats | undefined;
/**
* Configure default webrtc stats collection interval in ms
* Disable collecting webrtc stats by setting interval to 0
*/
private statsCollectIntervalTime = 0;
public constructor(
private client: MatrixClient,
@@ -261,12 +266,6 @@ export class GroupCall extends TypedEventEmitter<
this.on(GroupCallEvent.GroupCallStateChanged, this.onStateChanged);
this.on(GroupCallEvent.LocalScreenshareStateChanged, this.onLocalFeedsChanged);
this.allowCallWithoutVideoAndAudio = !!isCallWithoutVideoAndAudio;
const userID = this.client.getUserId() || "unknown";
this.stats = new GroupCallStats(this.groupCallId, userID);
this.stats.reports.on(StatsReport.CONNECTION_STATS, this.onConnectionStats);
this.stats.reports.on(StatsReport.BYTE_SENT_STATS, this.onByteSentStats);
this.stats.reports.on(StatsReport.SUMMARY_STATS, this.onSummaryStats);
}
private onConnectionStats = (report: ConnectionStatsReport): void => {
@@ -553,7 +552,7 @@ export class GroupCall extends TypedEventEmitter<
clearInterval(this.retryCallLoopInterval);
this.client.removeListener(CallEventHandlerEvent.Incoming, this.onIncomingCall);
this.stats.stop();
this.stats?.stop();
}
public leave(): void {
@@ -1087,7 +1086,7 @@ export class GroupCall extends TypedEventEmitter<
this.reEmitter.reEmit(call, Object.values(CallEvent));
call.initStats(this.stats);
call.initStats(this.getGroupCallStats());
onCallFeedsChanged();
}
@@ -1609,6 +1608,24 @@ export class GroupCall extends TypedEventEmitter<
};
public getGroupCallStats(): GroupCallStats {
if (this.stats === undefined) {
const userID = this.client.getUserId() || "unknown";
this.stats = new GroupCallStats(this.groupCallId, userID, this.statsCollectIntervalTime);
this.stats.reports.on(StatsReport.CONNECTION_STATS, this.onConnectionStats);
this.stats.reports.on(StatsReport.BYTE_SENT_STATS, this.onByteSentStats);
this.stats.reports.on(StatsReport.SUMMARY_STATS, this.onSummaryStats);
}
return this.stats;
}
public setGroupCallStatsInterval(interval: number): void {
this.statsCollectIntervalTime = interval;
if (this.stats !== undefined) {
this.stats.stop();
this.stats.setInterval(interval);
if (interval > 0) {
this.stats.start();
}
}
}
}

View File

@@ -27,7 +27,7 @@ export class GroupCallStats {
public constructor(private groupCallId: string, private userId: string, private interval: number = 10000) {}
public start(): void {
if (this.timer === undefined) {
if (this.timer === undefined && this.interval > 0) {
this.timer = setInterval(() => {
this.processStats();
}, this.interval);
@@ -69,4 +69,8 @@ export class GroupCallStats {
Promise.all(summary).then((s: Awaited<SummaryStats>[]) => this.summaryStatsReporter.build(s));
}
public setInterval(interval: number): void {
this.interval = interval;
}
}