@unwanted/matrix-sdk-mini 34.12.0-1 → 34.12.0-2
Sign up to get free protection for your applications and to get access to all the features.
- package/git-revision.txt +1 -1
- package/lib/@types/event.d.ts +0 -19
- package/lib/@types/event.d.ts.map +1 -1
- package/lib/@types/event.js.map +1 -1
- package/lib/client.d.ts +2 -50
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +391 -501
- package/lib/client.js.map +1 -1
- package/lib/embedded.d.ts.map +1 -1
- package/lib/embedded.js +0 -1
- package/lib/embedded.js.map +1 -1
- package/lib/matrix.d.ts +0 -6
- package/lib/matrix.d.ts.map +1 -1
- package/lib/matrix.js +1 -5
- package/lib/matrix.js.map +1 -1
- package/package.json +1 -1
- package/src/@types/event.ts +2 -36
- package/src/client.ts +1 -150
- package/src/embedded.ts +0 -2
- package/src/matrix.ts +0 -13
- package/lib/matrixrtc/CallMembership.d.ts +0 -66
- package/lib/matrixrtc/CallMembership.d.ts.map +0 -1
- package/lib/matrixrtc/CallMembership.js +0 -197
- package/lib/matrixrtc/CallMembership.js.map +0 -1
- package/lib/matrixrtc/LivekitFocus.d.ts +0 -16
- package/lib/matrixrtc/LivekitFocus.d.ts.map +0 -1
- package/lib/matrixrtc/LivekitFocus.js +0 -20
- package/lib/matrixrtc/LivekitFocus.js.map +0 -1
- package/lib/matrixrtc/MatrixRTCSession.d.ts +0 -295
- package/lib/matrixrtc/MatrixRTCSession.d.ts.map +0 -1
- package/lib/matrixrtc/MatrixRTCSession.js +0 -1043
- package/lib/matrixrtc/MatrixRTCSession.js.map +0 -1
- package/lib/matrixrtc/MatrixRTCSessionManager.d.ts +0 -40
- package/lib/matrixrtc/MatrixRTCSessionManager.d.ts.map +0 -1
- package/lib/matrixrtc/MatrixRTCSessionManager.js +0 -146
- package/lib/matrixrtc/MatrixRTCSessionManager.js.map +0 -1
- package/lib/matrixrtc/focus.d.ts +0 -10
- package/lib/matrixrtc/focus.d.ts.map +0 -1
- package/lib/matrixrtc/focus.js +0 -1
- package/lib/matrixrtc/focus.js.map +0 -1
- package/lib/matrixrtc/index.d.ts +0 -7
- package/lib/matrixrtc/index.d.ts.map +0 -1
- package/lib/matrixrtc/index.js +0 -21
- package/lib/matrixrtc/index.js.map +0 -1
- package/lib/matrixrtc/types.d.ts +0 -19
- package/lib/matrixrtc/types.d.ts.map +0 -1
- package/lib/matrixrtc/types.js +0 -1
- package/lib/matrixrtc/types.js.map +0 -1
- package/lib/webrtc/audioContext.d.ts +0 -15
- package/lib/webrtc/audioContext.d.ts.map +0 -1
- package/lib/webrtc/audioContext.js +0 -46
- package/lib/webrtc/audioContext.js.map +0 -1
- package/lib/webrtc/call.d.ts +0 -560
- package/lib/webrtc/call.d.ts.map +0 -1
- package/lib/webrtc/call.js +0 -2541
- package/lib/webrtc/call.js.map +0 -1
- package/lib/webrtc/callEventHandler.d.ts +0 -37
- package/lib/webrtc/callEventHandler.d.ts.map +0 -1
- package/lib/webrtc/callEventHandler.js +0 -344
- package/lib/webrtc/callEventHandler.js.map +0 -1
- package/lib/webrtc/callEventTypes.d.ts +0 -73
- package/lib/webrtc/callEventTypes.d.ts.map +0 -1
- package/lib/webrtc/callEventTypes.js +0 -13
- package/lib/webrtc/callEventTypes.js.map +0 -1
- package/lib/webrtc/callFeed.d.ts +0 -128
- package/lib/webrtc/callFeed.d.ts.map +0 -1
- package/lib/webrtc/callFeed.js +0 -289
- package/lib/webrtc/callFeed.js.map +0 -1
- package/lib/webrtc/groupCall.d.ts +0 -323
- package/lib/webrtc/groupCall.d.ts.map +0 -1
- package/lib/webrtc/groupCall.js +0 -1337
- package/lib/webrtc/groupCall.js.map +0 -1
- package/lib/webrtc/groupCallEventHandler.d.ts +0 -31
- package/lib/webrtc/groupCallEventHandler.d.ts.map +0 -1
- package/lib/webrtc/groupCallEventHandler.js +0 -178
- package/lib/webrtc/groupCallEventHandler.js.map +0 -1
- package/lib/webrtc/mediaHandler.d.ts +0 -89
- package/lib/webrtc/mediaHandler.d.ts.map +0 -1
- package/lib/webrtc/mediaHandler.js +0 -437
- package/lib/webrtc/mediaHandler.js.map +0 -1
- package/lib/webrtc/stats/callFeedStatsReporter.d.ts +0 -8
- package/lib/webrtc/stats/callFeedStatsReporter.d.ts.map +0 -1
- package/lib/webrtc/stats/callFeedStatsReporter.js +0 -82
- package/lib/webrtc/stats/callFeedStatsReporter.js.map +0 -1
- package/lib/webrtc/stats/callStatsReportGatherer.d.ts +0 -25
- package/lib/webrtc/stats/callStatsReportGatherer.d.ts.map +0 -1
- package/lib/webrtc/stats/callStatsReportGatherer.js +0 -199
- package/lib/webrtc/stats/callStatsReportGatherer.js.map +0 -1
- package/lib/webrtc/stats/callStatsReportSummary.d.ts +0 -17
- package/lib/webrtc/stats/callStatsReportSummary.d.ts.map +0 -1
- package/lib/webrtc/stats/callStatsReportSummary.js +0 -1
- package/lib/webrtc/stats/callStatsReportSummary.js.map +0 -1
- package/lib/webrtc/stats/connectionStats.d.ts +0 -28
- package/lib/webrtc/stats/connectionStats.d.ts.map +0 -1
- package/lib/webrtc/stats/connectionStats.js +0 -26
- package/lib/webrtc/stats/connectionStats.js.map +0 -1
- package/lib/webrtc/stats/connectionStatsBuilder.d.ts +0 -5
- package/lib/webrtc/stats/connectionStatsBuilder.d.ts.map +0 -1
- package/lib/webrtc/stats/connectionStatsBuilder.js +0 -27
- package/lib/webrtc/stats/connectionStatsBuilder.js.map +0 -1
- package/lib/webrtc/stats/connectionStatsReportBuilder.d.ts +0 -7
- package/lib/webrtc/stats/connectionStatsReportBuilder.d.ts.map +0 -1
- package/lib/webrtc/stats/connectionStatsReportBuilder.js +0 -121
- package/lib/webrtc/stats/connectionStatsReportBuilder.js.map +0 -1
- package/lib/webrtc/stats/groupCallStats.d.ts +0 -22
- package/lib/webrtc/stats/groupCallStats.d.ts.map +0 -1
- package/lib/webrtc/stats/groupCallStats.js +0 -78
- package/lib/webrtc/stats/groupCallStats.js.map +0 -1
- package/lib/webrtc/stats/media/mediaSsrcHandler.d.ts +0 -10
- package/lib/webrtc/stats/media/mediaSsrcHandler.d.ts.map +0 -1
- package/lib/webrtc/stats/media/mediaSsrcHandler.js +0 -57
- package/lib/webrtc/stats/media/mediaSsrcHandler.js.map +0 -1
- package/lib/webrtc/stats/media/mediaTrackHandler.d.ts +0 -12
- package/lib/webrtc/stats/media/mediaTrackHandler.d.ts.map +0 -1
- package/lib/webrtc/stats/media/mediaTrackHandler.js +0 -62
- package/lib/webrtc/stats/media/mediaTrackHandler.js.map +0 -1
- package/lib/webrtc/stats/media/mediaTrackStats.d.ts +0 -86
- package/lib/webrtc/stats/media/mediaTrackStats.d.ts.map +0 -1
- package/lib/webrtc/stats/media/mediaTrackStats.js +0 -142
- package/lib/webrtc/stats/media/mediaTrackStats.js.map +0 -1
- package/lib/webrtc/stats/media/mediaTrackStatsHandler.d.ts +0 -22
- package/lib/webrtc/stats/media/mediaTrackStatsHandler.d.ts.map +0 -1
- package/lib/webrtc/stats/media/mediaTrackStatsHandler.js +0 -76
- package/lib/webrtc/stats/media/mediaTrackStatsHandler.js.map +0 -1
- package/lib/webrtc/stats/statsReport.d.ts +0 -99
- package/lib/webrtc/stats/statsReport.d.ts.map +0 -1
- package/lib/webrtc/stats/statsReport.js +0 -32
- package/lib/webrtc/stats/statsReport.js.map +0 -1
- package/lib/webrtc/stats/statsReportEmitter.d.ts +0 -15
- package/lib/webrtc/stats/statsReportEmitter.d.ts.map +0 -1
- package/lib/webrtc/stats/statsReportEmitter.js +0 -33
- package/lib/webrtc/stats/statsReportEmitter.js.map +0 -1
- package/lib/webrtc/stats/summaryStatsReportGatherer.d.ts +0 -16
- package/lib/webrtc/stats/summaryStatsReportGatherer.d.ts.map +0 -1
- package/lib/webrtc/stats/summaryStatsReportGatherer.js +0 -116
- package/lib/webrtc/stats/summaryStatsReportGatherer.js.map +0 -1
- package/lib/webrtc/stats/trackStatsBuilder.d.ts +0 -19
- package/lib/webrtc/stats/trackStatsBuilder.d.ts.map +0 -1
- package/lib/webrtc/stats/trackStatsBuilder.js +0 -168
- package/lib/webrtc/stats/trackStatsBuilder.js.map +0 -1
- package/lib/webrtc/stats/transportStats.d.ts +0 -11
- package/lib/webrtc/stats/transportStats.d.ts.map +0 -1
- package/lib/webrtc/stats/transportStats.js +0 -1
- package/lib/webrtc/stats/transportStats.js.map +0 -1
- package/lib/webrtc/stats/transportStatsBuilder.d.ts +0 -5
- package/lib/webrtc/stats/transportStatsBuilder.d.ts.map +0 -1
- package/lib/webrtc/stats/transportStatsBuilder.js +0 -34
- package/lib/webrtc/stats/transportStatsBuilder.js.map +0 -1
- package/lib/webrtc/stats/valueFormatter.d.ts +0 -4
- package/lib/webrtc/stats/valueFormatter.d.ts.map +0 -1
- package/lib/webrtc/stats/valueFormatter.js +0 -25
- package/lib/webrtc/stats/valueFormatter.js.map +0 -1
- package/src/matrixrtc/CallMembership.ts +0 -247
- package/src/matrixrtc/LivekitFocus.ts +0 -39
- package/src/matrixrtc/MatrixRTCSession.ts +0 -1319
- package/src/matrixrtc/MatrixRTCSessionManager.ts +0 -166
- package/src/matrixrtc/focus.ts +0 -25
- package/src/matrixrtc/index.ts +0 -22
- package/src/matrixrtc/types.ts +0 -36
- package/src/webrtc/audioContext.ts +0 -44
- package/src/webrtc/call.ts +0 -3074
- package/src/webrtc/callEventHandler.ts +0 -425
- package/src/webrtc/callEventTypes.ts +0 -93
- package/src/webrtc/callFeed.ts +0 -364
- package/src/webrtc/groupCall.ts +0 -1735
- package/src/webrtc/groupCallEventHandler.ts +0 -234
- package/src/webrtc/mediaHandler.ts +0 -484
- package/src/webrtc/stats/callFeedStatsReporter.ts +0 -94
- package/src/webrtc/stats/callStatsReportGatherer.ts +0 -219
- package/src/webrtc/stats/callStatsReportSummary.ts +0 -30
- package/src/webrtc/stats/connectionStats.ts +0 -47
- package/src/webrtc/stats/connectionStatsBuilder.ts +0 -28
- package/src/webrtc/stats/connectionStatsReportBuilder.ts +0 -140
- package/src/webrtc/stats/groupCallStats.ts +0 -93
- package/src/webrtc/stats/media/mediaSsrcHandler.ts +0 -57
- package/src/webrtc/stats/media/mediaTrackHandler.ts +0 -76
- package/src/webrtc/stats/media/mediaTrackStats.ts +0 -176
- package/src/webrtc/stats/media/mediaTrackStatsHandler.ts +0 -90
- package/src/webrtc/stats/statsReport.ts +0 -133
- package/src/webrtc/stats/statsReportEmitter.ts +0 -49
- package/src/webrtc/stats/summaryStatsReportGatherer.ts +0 -148
- package/src/webrtc/stats/trackStatsBuilder.ts +0 -207
- package/src/webrtc/stats/transportStats.ts +0 -26
- package/src/webrtc/stats/transportStatsBuilder.ts +0 -48
- package/src/webrtc/stats/valueFormatter.ts +0 -27
@@ -1,219 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
Copyright 2023 The Matrix.org Foundation C.I.C.
|
3
|
-
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
you may not use this file except in compliance with the License.
|
6
|
-
You may obtain a copy of the License at
|
7
|
-
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
See the License for the specific language governing permissions and
|
14
|
-
limitations under the License.
|
15
|
-
*/
|
16
|
-
|
17
|
-
import { ConnectionStats } from "./connectionStats.ts";
|
18
|
-
import { StatsReportEmitter } from "./statsReportEmitter.ts";
|
19
|
-
import { ByteSend, ByteSentStatsReport, TrackID } from "./statsReport.ts";
|
20
|
-
import { ConnectionStatsBuilder } from "./connectionStatsBuilder.ts";
|
21
|
-
import { TransportStatsBuilder } from "./transportStatsBuilder.ts";
|
22
|
-
import { MediaSsrcHandler } from "./media/mediaSsrcHandler.ts";
|
23
|
-
import { MediaTrackHandler } from "./media/mediaTrackHandler.ts";
|
24
|
-
import { MediaTrackStatsHandler } from "./media/mediaTrackStatsHandler.ts";
|
25
|
-
import { TrackStatsBuilder } from "./trackStatsBuilder.ts";
|
26
|
-
import { ConnectionStatsReportBuilder } from "./connectionStatsReportBuilder.ts";
|
27
|
-
import { ValueFormatter } from "./valueFormatter.ts";
|
28
|
-
import { CallStatsReportSummary } from "./callStatsReportSummary.ts";
|
29
|
-
import { logger } from "../../logger.ts";
|
30
|
-
import { CallFeedStatsReporter } from "./callFeedStatsReporter.ts";
|
31
|
-
|
32
|
-
export class CallStatsReportGatherer {
|
33
|
-
private isActive = true;
|
34
|
-
private previousStatsReport: RTCStatsReport | undefined;
|
35
|
-
private currentStatsReport: RTCStatsReport | undefined;
|
36
|
-
private readonly connectionStats = new ConnectionStats();
|
37
|
-
|
38
|
-
private readonly trackStats: MediaTrackStatsHandler;
|
39
|
-
|
40
|
-
public constructor(
|
41
|
-
public readonly callId: string,
|
42
|
-
private opponentMemberId: string,
|
43
|
-
private readonly pc: RTCPeerConnection,
|
44
|
-
private readonly emitter: StatsReportEmitter,
|
45
|
-
private readonly isFocus = true,
|
46
|
-
) {
|
47
|
-
pc.addEventListener("signalingstatechange", this.onSignalStateChange.bind(this));
|
48
|
-
this.trackStats = new MediaTrackStatsHandler(new MediaSsrcHandler(), new MediaTrackHandler(pc));
|
49
|
-
}
|
50
|
-
|
51
|
-
public async processStats(groupCallId: string, localUserId: string): Promise<CallStatsReportSummary> {
|
52
|
-
const summary = {
|
53
|
-
isFirstCollection: this.previousStatsReport === undefined,
|
54
|
-
receivedMedia: 0,
|
55
|
-
receivedAudioMedia: 0,
|
56
|
-
receivedVideoMedia: 0,
|
57
|
-
audioTrackSummary: { count: 0, muted: 0, maxPacketLoss: 0, maxJitter: 0, concealedAudio: 0, totalAudio: 0 },
|
58
|
-
videoTrackSummary: { count: 0, muted: 0, maxPacketLoss: 0, maxJitter: 0, concealedAudio: 0, totalAudio: 0 },
|
59
|
-
} as CallStatsReportSummary;
|
60
|
-
if (this.isActive) {
|
61
|
-
const statsPromise = this.pc.getStats();
|
62
|
-
if (typeof statsPromise?.then === "function") {
|
63
|
-
return statsPromise
|
64
|
-
.then((report) => {
|
65
|
-
// @ts-ignore
|
66
|
-
this.currentStatsReport = typeof report?.result === "function" ? report.result() : report;
|
67
|
-
|
68
|
-
try {
|
69
|
-
this.processStatsReport(groupCallId, localUserId);
|
70
|
-
} catch (error) {
|
71
|
-
this.handleError(error);
|
72
|
-
return summary;
|
73
|
-
}
|
74
|
-
|
75
|
-
this.previousStatsReport = this.currentStatsReport;
|
76
|
-
summary.receivedMedia = this.connectionStats.bitrate.download;
|
77
|
-
summary.receivedAudioMedia = this.connectionStats.bitrate.audio?.download || 0;
|
78
|
-
summary.receivedVideoMedia = this.connectionStats.bitrate.video?.download || 0;
|
79
|
-
const trackSummary = TrackStatsBuilder.buildTrackSummary(
|
80
|
-
Array.from(this.trackStats.getTrack2stats().values()),
|
81
|
-
);
|
82
|
-
return {
|
83
|
-
...summary,
|
84
|
-
audioTrackSummary: trackSummary.audioTrackSummary,
|
85
|
-
videoTrackSummary: trackSummary.videoTrackSummary,
|
86
|
-
};
|
87
|
-
})
|
88
|
-
.catch((error) => {
|
89
|
-
this.handleError(error);
|
90
|
-
return summary;
|
91
|
-
});
|
92
|
-
}
|
93
|
-
this.isActive = false;
|
94
|
-
}
|
95
|
-
return Promise.resolve(summary);
|
96
|
-
}
|
97
|
-
|
98
|
-
private processStatsReport(groupCallId: string, localUserId: string): void {
|
99
|
-
const byteSentStatsReport: ByteSentStatsReport = new Map<TrackID, ByteSend>() as ByteSentStatsReport;
|
100
|
-
byteSentStatsReport.callId = this.callId;
|
101
|
-
byteSentStatsReport.opponentMemberId = this.opponentMemberId;
|
102
|
-
|
103
|
-
this.currentStatsReport?.forEach((now) => {
|
104
|
-
const before = this.previousStatsReport ? this.previousStatsReport.get(now.id) : null;
|
105
|
-
// RTCIceCandidatePairStats - https://w3c.github.io/webrtc-stats/#candidatepair-dict*
|
106
|
-
if (now.type === "candidate-pair" && now.nominated && now.state === "succeeded") {
|
107
|
-
this.connectionStats.bandwidth = ConnectionStatsBuilder.buildBandwidthReport(now);
|
108
|
-
this.connectionStats.transport = TransportStatsBuilder.buildReport(
|
109
|
-
this.currentStatsReport,
|
110
|
-
now,
|
111
|
-
this.connectionStats.transport,
|
112
|
-
this.isFocus,
|
113
|
-
);
|
114
|
-
|
115
|
-
// RTCReceivedRtpStreamStats
|
116
|
-
// https://w3c.github.io/webrtc-stats/#receivedrtpstats-dict*
|
117
|
-
// RTCSentRtpStreamStats
|
118
|
-
// https://w3c.github.io/webrtc-stats/#sentrtpstats-dict*
|
119
|
-
} else if (now.type === "inbound-rtp" || now.type === "outbound-rtp") {
|
120
|
-
const trackStats = this.trackStats.findTrack2Stats(
|
121
|
-
now,
|
122
|
-
now.type === "inbound-rtp" ? "remote" : "local",
|
123
|
-
);
|
124
|
-
if (!trackStats) {
|
125
|
-
return;
|
126
|
-
}
|
127
|
-
|
128
|
-
if (before) {
|
129
|
-
TrackStatsBuilder.buildPacketsLost(trackStats, now, before);
|
130
|
-
}
|
131
|
-
|
132
|
-
// Get the resolution and framerate for only remote video sources here. For the local video sources,
|
133
|
-
// 'track' stats will be used since they have the updated resolution based on the simulcast streams
|
134
|
-
// currently being sent. Promise based getStats reports three 'outbound-rtp' streams and there will be
|
135
|
-
// more calculations needed to determine what is the highest resolution stream sent by the client if the
|
136
|
-
// 'outbound-rtp' stats are used.
|
137
|
-
if (now.type === "inbound-rtp") {
|
138
|
-
TrackStatsBuilder.buildFramerateResolution(trackStats, now);
|
139
|
-
if (before) {
|
140
|
-
TrackStatsBuilder.buildBitrateReceived(trackStats, now, before);
|
141
|
-
}
|
142
|
-
const ts = this.trackStats.findTransceiverByTrackId(trackStats.trackId);
|
143
|
-
TrackStatsBuilder.setTrackStatsState(trackStats, ts);
|
144
|
-
TrackStatsBuilder.buildJitter(trackStats, now);
|
145
|
-
TrackStatsBuilder.buildAudioConcealment(trackStats, now);
|
146
|
-
} else if (before) {
|
147
|
-
byteSentStatsReport.set(trackStats.trackId, ValueFormatter.getNonNegativeValue(now.bytesSent));
|
148
|
-
TrackStatsBuilder.buildBitrateSend(trackStats, now, before);
|
149
|
-
}
|
150
|
-
TrackStatsBuilder.buildCodec(this.currentStatsReport, trackStats, now);
|
151
|
-
} else if (now.type === "track" && now.kind === "video" && !now.remoteSource) {
|
152
|
-
const trackStats = this.trackStats.findLocalVideoTrackStats(now);
|
153
|
-
if (!trackStats) {
|
154
|
-
return;
|
155
|
-
}
|
156
|
-
TrackStatsBuilder.buildFramerateResolution(trackStats, now);
|
157
|
-
TrackStatsBuilder.calculateSimulcastFramerate(
|
158
|
-
trackStats,
|
159
|
-
now,
|
160
|
-
before,
|
161
|
-
this.trackStats.mediaTrackHandler.getActiveSimulcastStreams(),
|
162
|
-
);
|
163
|
-
}
|
164
|
-
});
|
165
|
-
|
166
|
-
this.emitter.emitByteSendReport(byteSentStatsReport);
|
167
|
-
this.emitter.emitCallFeedReport(
|
168
|
-
CallFeedStatsReporter.buildCallFeedReport(this.callId, this.opponentMemberId, this.pc),
|
169
|
-
);
|
170
|
-
this.processAndEmitConnectionStatsReport();
|
171
|
-
}
|
172
|
-
|
173
|
-
public setActive(isActive: boolean): void {
|
174
|
-
this.isActive = isActive;
|
175
|
-
}
|
176
|
-
|
177
|
-
public getActive(): boolean {
|
178
|
-
return this.isActive;
|
179
|
-
}
|
180
|
-
|
181
|
-
private handleError(error: any): void {
|
182
|
-
this.isActive = false;
|
183
|
-
logger.warn(`CallStatsReportGatherer ${this.callId} processStatsReport fails and set to inactive ${error}`);
|
184
|
-
}
|
185
|
-
|
186
|
-
private processAndEmitConnectionStatsReport(): void {
|
187
|
-
const report = ConnectionStatsReportBuilder.build(this.trackStats.getTrack2stats());
|
188
|
-
report.callId = this.callId;
|
189
|
-
report.opponentMemberId = this.opponentMemberId;
|
190
|
-
|
191
|
-
this.connectionStats.bandwidth = report.bandwidth;
|
192
|
-
this.connectionStats.bitrate = report.bitrate;
|
193
|
-
this.connectionStats.packetLoss = report.packetLoss;
|
194
|
-
|
195
|
-
this.emitter.emitConnectionStatsReport({
|
196
|
-
...report,
|
197
|
-
transport: this.connectionStats.transport,
|
198
|
-
});
|
199
|
-
|
200
|
-
this.connectionStats.transport = [];
|
201
|
-
}
|
202
|
-
|
203
|
-
public stopProcessingStats(): void {}
|
204
|
-
|
205
|
-
private onSignalStateChange(): void {
|
206
|
-
if (this.pc.signalingState === "stable") {
|
207
|
-
if (this.pc.currentRemoteDescription) {
|
208
|
-
this.trackStats.mediaSsrcHandler.parse(this.pc.currentRemoteDescription.sdp, "remote");
|
209
|
-
}
|
210
|
-
if (this.pc.currentLocalDescription) {
|
211
|
-
this.trackStats.mediaSsrcHandler.parse(this.pc.currentLocalDescription.sdp, "local");
|
212
|
-
}
|
213
|
-
}
|
214
|
-
}
|
215
|
-
|
216
|
-
public setOpponentMemberId(id: string): void {
|
217
|
-
this.opponentMemberId = id;
|
218
|
-
}
|
219
|
-
}
|
@@ -1,30 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
Copyright 2023 The Matrix.org Foundation C.I.C.
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
you may not use this file except in compliance with the License.
|
5
|
-
You may obtain a copy of the License at
|
6
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
7
|
-
Unless required by applicable law or agreed to in writing, software
|
8
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
9
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
10
|
-
See the License for the specific language governing permissions and
|
11
|
-
limitations under the License.
|
12
|
-
*/
|
13
|
-
export interface CallStatsReportSummary {
|
14
|
-
receivedMedia: number;
|
15
|
-
receivedAudioMedia: number;
|
16
|
-
receivedVideoMedia: number;
|
17
|
-
audioTrackSummary: TrackSummary;
|
18
|
-
videoTrackSummary: TrackSummary;
|
19
|
-
|
20
|
-
isFirstCollection: boolean;
|
21
|
-
}
|
22
|
-
|
23
|
-
export interface TrackSummary {
|
24
|
-
count: number;
|
25
|
-
muted: number;
|
26
|
-
maxJitter: number;
|
27
|
-
maxPacketLoss: number;
|
28
|
-
concealedAudio: number;
|
29
|
-
totalAudio: number;
|
30
|
-
}
|
@@ -1,47 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
Copyright 2023 The Matrix.org Foundation C.I.C.
|
3
|
-
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
you may not use this file except in compliance with the License.
|
6
|
-
You may obtain a copy of the License at
|
7
|
-
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
See the License for the specific language governing permissions and
|
14
|
-
limitations under the License.
|
15
|
-
*/
|
16
|
-
|
17
|
-
import { TransportStats } from "./transportStats.ts";
|
18
|
-
import { Bitrate } from "./media/mediaTrackStats.ts";
|
19
|
-
|
20
|
-
export interface ConnectionStatsBandwidth {
|
21
|
-
/**
|
22
|
-
* bytes per second
|
23
|
-
*/
|
24
|
-
download: number;
|
25
|
-
/**
|
26
|
-
* bytes per second
|
27
|
-
*/
|
28
|
-
upload: number;
|
29
|
-
}
|
30
|
-
|
31
|
-
export interface ConnectionStatsBitrate extends Bitrate {
|
32
|
-
audio?: Bitrate;
|
33
|
-
video?: Bitrate;
|
34
|
-
}
|
35
|
-
|
36
|
-
export interface PacketLoss {
|
37
|
-
total: number;
|
38
|
-
download: number;
|
39
|
-
upload: number;
|
40
|
-
}
|
41
|
-
|
42
|
-
export class ConnectionStats {
|
43
|
-
public bandwidth: ConnectionStatsBitrate = {} as ConnectionStatsBitrate;
|
44
|
-
public bitrate: ConnectionStatsBitrate = {} as ConnectionStatsBitrate;
|
45
|
-
public packetLoss: PacketLoss = {} as PacketLoss;
|
46
|
-
public transport: TransportStats[] = [];
|
47
|
-
}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
Copyright 2023 The Matrix.org Foundation C.I.C.
|
3
|
-
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
you may not use this file except in compliance with the License.
|
6
|
-
You may obtain a copy of the License at
|
7
|
-
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
See the License for the specific language governing permissions and
|
14
|
-
limitations under the License.
|
15
|
-
*/
|
16
|
-
import { Bitrate } from "./media/mediaTrackStats.ts";
|
17
|
-
|
18
|
-
export class ConnectionStatsBuilder {
|
19
|
-
public static buildBandwidthReport(now: RTCIceCandidatePairStats): Bitrate {
|
20
|
-
const availableIncomingBitrate = now.availableIncomingBitrate;
|
21
|
-
const availableOutgoingBitrate = now.availableOutgoingBitrate;
|
22
|
-
|
23
|
-
return {
|
24
|
-
download: availableIncomingBitrate ? Math.round(availableIncomingBitrate / 1000) : 0,
|
25
|
-
upload: availableOutgoingBitrate ? Math.round(availableOutgoingBitrate / 1000) : 0,
|
26
|
-
};
|
27
|
-
}
|
28
|
-
}
|
@@ -1,140 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
Copyright 2023 The Matrix.org Foundation C.I.C.
|
3
|
-
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
you may not use this file except in compliance with the License.
|
6
|
-
You may obtain a copy of the License at
|
7
|
-
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
See the License for the specific language governing permissions and
|
14
|
-
limitations under the License.
|
15
|
-
*/
|
16
|
-
import {
|
17
|
-
AudioConcealment,
|
18
|
-
CodecMap,
|
19
|
-
ConnectionStatsReport,
|
20
|
-
FramerateMap,
|
21
|
-
ResolutionMap,
|
22
|
-
TrackID,
|
23
|
-
} from "./statsReport.ts";
|
24
|
-
import { MediaTrackStats, Resolution } from "./media/mediaTrackStats.ts";
|
25
|
-
|
26
|
-
export class ConnectionStatsReportBuilder {
|
27
|
-
public static build(stats: Map<TrackID, MediaTrackStats>): ConnectionStatsReport {
|
28
|
-
const report = {} as ConnectionStatsReport;
|
29
|
-
|
30
|
-
// process stats
|
31
|
-
const totalPackets = {
|
32
|
-
download: 0,
|
33
|
-
upload: 0,
|
34
|
-
};
|
35
|
-
const lostPackets = {
|
36
|
-
download: 0,
|
37
|
-
upload: 0,
|
38
|
-
};
|
39
|
-
let bitrateDownload = 0;
|
40
|
-
let bitrateUpload = 0;
|
41
|
-
const resolutions: ResolutionMap = {
|
42
|
-
local: new Map<TrackID, Resolution>(),
|
43
|
-
remote: new Map<TrackID, Resolution>(),
|
44
|
-
};
|
45
|
-
const framerates: FramerateMap = { local: new Map<TrackID, number>(), remote: new Map<TrackID, number>() };
|
46
|
-
const codecs: CodecMap = { local: new Map<TrackID, string>(), remote: new Map<TrackID, string>() };
|
47
|
-
const jitter = new Map<TrackID, number>();
|
48
|
-
const audioConcealment = new Map<TrackID, AudioConcealment>();
|
49
|
-
|
50
|
-
let audioBitrateDownload = 0;
|
51
|
-
let audioBitrateUpload = 0;
|
52
|
-
let videoBitrateDownload = 0;
|
53
|
-
let videoBitrateUpload = 0;
|
54
|
-
|
55
|
-
let totalConcealedAudio = 0;
|
56
|
-
let totalAudioDuration = 0;
|
57
|
-
|
58
|
-
for (const [trackId, trackStats] of stats) {
|
59
|
-
// process packet loss stats
|
60
|
-
const loss = trackStats.getLoss();
|
61
|
-
const type = loss.isDownloadStream ? "download" : "upload";
|
62
|
-
|
63
|
-
totalPackets[type] += loss.packetsTotal;
|
64
|
-
lostPackets[type] += loss.packetsLost;
|
65
|
-
|
66
|
-
// process bitrate stats
|
67
|
-
bitrateDownload += trackStats.getBitrate().download;
|
68
|
-
bitrateUpload += trackStats.getBitrate().upload;
|
69
|
-
|
70
|
-
// collect resolutions and framerates
|
71
|
-
if (trackStats.kind === "audio") {
|
72
|
-
// process audio quality stats
|
73
|
-
const audioConcealmentForTrack = trackStats.getAudioConcealment();
|
74
|
-
totalConcealedAudio += audioConcealmentForTrack.concealedAudio;
|
75
|
-
totalAudioDuration += audioConcealmentForTrack.totalAudioDuration;
|
76
|
-
|
77
|
-
audioBitrateDownload += trackStats.getBitrate().download;
|
78
|
-
audioBitrateUpload += trackStats.getBitrate().upload;
|
79
|
-
} else {
|
80
|
-
videoBitrateDownload += trackStats.getBitrate().download;
|
81
|
-
videoBitrateUpload += trackStats.getBitrate().upload;
|
82
|
-
}
|
83
|
-
|
84
|
-
resolutions[trackStats.getType()].set(trackId, trackStats.getResolution());
|
85
|
-
framerates[trackStats.getType()].set(trackId, trackStats.getFramerate());
|
86
|
-
codecs[trackStats.getType()].set(trackId, trackStats.getCodec());
|
87
|
-
if (trackStats.getType() === "remote") {
|
88
|
-
jitter.set(trackId, trackStats.getJitter());
|
89
|
-
if (trackStats.kind === "audio") {
|
90
|
-
audioConcealment.set(trackId, trackStats.getAudioConcealment());
|
91
|
-
}
|
92
|
-
}
|
93
|
-
|
94
|
-
trackStats.resetBitrate();
|
95
|
-
}
|
96
|
-
|
97
|
-
report.bitrate = {
|
98
|
-
upload: bitrateUpload,
|
99
|
-
download: bitrateDownload,
|
100
|
-
};
|
101
|
-
|
102
|
-
report.bitrate.audio = {
|
103
|
-
upload: audioBitrateUpload,
|
104
|
-
download: audioBitrateDownload,
|
105
|
-
};
|
106
|
-
|
107
|
-
report.bitrate.video = {
|
108
|
-
upload: videoBitrateUpload,
|
109
|
-
download: videoBitrateDownload,
|
110
|
-
};
|
111
|
-
|
112
|
-
report.packetLoss = {
|
113
|
-
total: ConnectionStatsReportBuilder.calculatePacketLoss(
|
114
|
-
lostPackets.download + lostPackets.upload,
|
115
|
-
totalPackets.download + totalPackets.upload,
|
116
|
-
),
|
117
|
-
download: ConnectionStatsReportBuilder.calculatePacketLoss(lostPackets.download, totalPackets.download),
|
118
|
-
upload: ConnectionStatsReportBuilder.calculatePacketLoss(lostPackets.upload, totalPackets.upload),
|
119
|
-
};
|
120
|
-
report.audioConcealment = audioConcealment;
|
121
|
-
report.totalAudioConcealment = {
|
122
|
-
concealedAudio: totalConcealedAudio,
|
123
|
-
totalAudioDuration,
|
124
|
-
};
|
125
|
-
|
126
|
-
report.framerate = framerates;
|
127
|
-
report.resolution = resolutions;
|
128
|
-
report.codec = codecs;
|
129
|
-
report.jitter = jitter;
|
130
|
-
return report;
|
131
|
-
}
|
132
|
-
|
133
|
-
private static calculatePacketLoss(lostPackets: number, totalPackets: number): number {
|
134
|
-
if (!totalPackets || totalPackets <= 0 || !lostPackets || lostPackets <= 0) {
|
135
|
-
return 0;
|
136
|
-
}
|
137
|
-
|
138
|
-
return Math.round((lostPackets / totalPackets) * 100);
|
139
|
-
}
|
140
|
-
}
|
@@ -1,93 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
Copyright 2023 The Matrix.org Foundation C.I.C.
|
3
|
-
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
you may not use this file except in compliance with the License.
|
6
|
-
You may obtain a copy of the License at
|
7
|
-
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
See the License for the specific language governing permissions and
|
14
|
-
limitations under the License.
|
15
|
-
*/
|
16
|
-
import { CallStatsReportGatherer } from "./callStatsReportGatherer.ts";
|
17
|
-
import { StatsReportEmitter } from "./statsReportEmitter.ts";
|
18
|
-
import { CallStatsReportSummary } from "./callStatsReportSummary.ts";
|
19
|
-
import { SummaryStatsReportGatherer } from "./summaryStatsReportGatherer.ts";
|
20
|
-
import { logger } from "../../logger.ts";
|
21
|
-
|
22
|
-
export class GroupCallStats {
|
23
|
-
private timer: undefined | ReturnType<typeof setTimeout>;
|
24
|
-
private readonly gatherers: Map<string, CallStatsReportGatherer> = new Map<string, CallStatsReportGatherer>();
|
25
|
-
public readonly reports = new StatsReportEmitter();
|
26
|
-
private readonly summaryStatsReportGatherer = new SummaryStatsReportGatherer(this.reports);
|
27
|
-
|
28
|
-
public constructor(
|
29
|
-
private groupCallId: string,
|
30
|
-
private userId: string,
|
31
|
-
private interval: number = 10000,
|
32
|
-
) {}
|
33
|
-
|
34
|
-
public start(): void {
|
35
|
-
if (this.timer === undefined && this.interval > 0) {
|
36
|
-
this.timer = setInterval(() => {
|
37
|
-
this.processStats();
|
38
|
-
}, this.interval);
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
public stop(): void {
|
43
|
-
if (this.timer !== undefined) {
|
44
|
-
clearInterval(this.timer);
|
45
|
-
this.gatherers.forEach((c) => c.stopProcessingStats());
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
public hasStatsReportGatherer(callId: string): boolean {
|
50
|
-
return this.gatherers.has(callId);
|
51
|
-
}
|
52
|
-
|
53
|
-
public addStatsReportGatherer(
|
54
|
-
callId: string,
|
55
|
-
opponentMemberId: string,
|
56
|
-
peerConnection: RTCPeerConnection,
|
57
|
-
): boolean {
|
58
|
-
if (this.hasStatsReportGatherer(callId)) {
|
59
|
-
return false;
|
60
|
-
}
|
61
|
-
this.gatherers.set(callId, new CallStatsReportGatherer(callId, opponentMemberId, peerConnection, this.reports));
|
62
|
-
return true;
|
63
|
-
}
|
64
|
-
|
65
|
-
public removeStatsReportGatherer(callId: string): boolean {
|
66
|
-
return this.gatherers.delete(callId);
|
67
|
-
}
|
68
|
-
|
69
|
-
public getStatsReportGatherer(callId: string): CallStatsReportGatherer | undefined {
|
70
|
-
return this.hasStatsReportGatherer(callId) ? this.gatherers.get(callId) : undefined;
|
71
|
-
}
|
72
|
-
|
73
|
-
public updateOpponentMember(callId: string, opponentMember: string): void {
|
74
|
-
this.getStatsReportGatherer(callId)?.setOpponentMemberId(opponentMember);
|
75
|
-
}
|
76
|
-
|
77
|
-
private processStats(): void {
|
78
|
-
const summary: Promise<CallStatsReportSummary>[] = [];
|
79
|
-
this.gatherers.forEach((c) => {
|
80
|
-
summary.push(c.processStats(this.groupCallId, this.userId));
|
81
|
-
});
|
82
|
-
|
83
|
-
Promise.all(summary)
|
84
|
-
.then((s: Awaited<CallStatsReportSummary>[]) => this.summaryStatsReportGatherer.build(s))
|
85
|
-
.catch((err) => {
|
86
|
-
logger.error("Could not build summary stats report", err);
|
87
|
-
});
|
88
|
-
}
|
89
|
-
|
90
|
-
public setInterval(interval: number): void {
|
91
|
-
this.interval = interval;
|
92
|
-
}
|
93
|
-
}
|
@@ -1,57 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
Copyright 2023 The Matrix.org Foundation C.I.C.
|
3
|
-
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
you may not use this file except in compliance with the License.
|
6
|
-
You may obtain a copy of the License at
|
7
|
-
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
See the License for the specific language governing permissions and
|
14
|
-
limitations under the License.
|
15
|
-
*/
|
16
|
-
|
17
|
-
import { parse as parseSdp } from "sdp-transform";
|
18
|
-
|
19
|
-
export type Mid = string;
|
20
|
-
export type Ssrc = string;
|
21
|
-
export type MapType = "local" | "remote";
|
22
|
-
|
23
|
-
export class MediaSsrcHandler {
|
24
|
-
private readonly ssrcToMid = { local: new Map<Mid, Ssrc[]>(), remote: new Map<Mid, Ssrc[]>() };
|
25
|
-
|
26
|
-
public findMidBySsrc(ssrc: Ssrc, type: "local" | "remote"): Mid | undefined {
|
27
|
-
let mid: Mid | undefined;
|
28
|
-
this.ssrcToMid[type].forEach((ssrcs, m) => {
|
29
|
-
if (ssrcs.find((s) => s == ssrc)) {
|
30
|
-
mid = m;
|
31
|
-
return;
|
32
|
-
}
|
33
|
-
});
|
34
|
-
return mid;
|
35
|
-
}
|
36
|
-
|
37
|
-
public parse(description: string, type: MapType): void {
|
38
|
-
const sdp = parseSdp(description);
|
39
|
-
const ssrcToMid = new Map<Mid, Ssrc[]>();
|
40
|
-
sdp.media.forEach((m) => {
|
41
|
-
if ((!!m.mid && m.type === "video") || m.type === "audio") {
|
42
|
-
const ssrcs: Ssrc[] = [];
|
43
|
-
m.ssrcs?.forEach((ssrc) => {
|
44
|
-
if (ssrc.attribute === "cname") {
|
45
|
-
ssrcs.push(`${ssrc.id}`);
|
46
|
-
}
|
47
|
-
});
|
48
|
-
ssrcToMid.set(`${m.mid}`, ssrcs);
|
49
|
-
}
|
50
|
-
});
|
51
|
-
this.ssrcToMid[type] = ssrcToMid;
|
52
|
-
}
|
53
|
-
|
54
|
-
public getSsrcToMidMap(type: MapType): Map<Mid, Ssrc[]> {
|
55
|
-
return this.ssrcToMid[type];
|
56
|
-
}
|
57
|
-
}
|