Skip to content

Commit 4646ede

Browse files
feat: on stats parsed callback (#28)
* feat: on stats parsed callback * chore(release): 1.13.0-tt-212-on-parsed-stats.1 [skip ci] * fix: change handleNewPeerConnection args * chore(release): 1.13.0-tt-212-on-parsed-stats.2 [skip ci] --------- Co-authored-by: vlprojects-bot <info@vlprojects.pro>
1 parent 1bcc718 commit 4646ede

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webrtc-issue-detector",
3-
"version": "1.12.0",
3+
"version": "1.13.0-tt-212-on-parsed-stats.2",
44
"description": "WebRTC diagnostic tool that detects issues with network or user devices",
55
"repository": "git@github.com:VLprojects/webrtc-issue-detector.git",
66
"author": "Roman Kuzakov <roman.kuzakov@gmail.com>",

src/WebRTCIssueDetector.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,19 @@ class WebRTCIssueDetector {
9595
this.calculateNetworkScores(report.stats);
9696
});
9797

98-
this.statsReporter.on(PeriodicWebRTCStatsReporter.STATS_REPORTS_PARSED, (data: { timeTaken: number }) => {
98+
this.statsReporter.on(PeriodicWebRTCStatsReporter.STATS_REPORTS_PARSED, (data: {
99+
timeTaken: number,
100+
reportItems: StatsReportItem[],
101+
}) => {
99102
const payload = {
100103
timeTaken: data.timeTaken,
101104
ts: Date.now(),
102105
};
103106

107+
if (params.onStats) {
108+
params.onStats(data.reportItems);
109+
}
110+
104111
this.eventEmitter.emit(EventType.StatsParsingFinished, payload);
105112
});
106113
}
@@ -133,7 +140,7 @@ class WebRTCIssueDetector {
133140
this.statsReporter.stopReporting();
134141
}
135142

136-
public handleNewPeerConnection(pc: RTCPeerConnection): void {
143+
public handleNewPeerConnection(pc: RTCPeerConnection, id?: string): void {
137144
if (!this.#running && this.autoAddPeerConnections) {
138145
this.logger.debug('Skip handling new peer connection. Detector is not running', pc);
139146
return;
@@ -147,7 +154,7 @@ class WebRTCIssueDetector {
147154

148155
this.logger.debug('Handling new peer connection', pc);
149156

150-
this.compositeStatsParser.addPeerConnection({ pc });
157+
this.compositeStatsParser.addPeerConnection({ pc, id });
151158
}
152159

153160
private emitIssues(issues: IssuePayload[]): void {

src/parser/PeriodicWebRTCStatsReporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class PeriodicWebRTCStatsReporter extends EventEmitter {
6464
const reportItems = await this.compositeStatsParser.parse();
6565
const timeTaken = Date.now() - startTime;
6666

67-
this.emit(PeriodicWebRTCStatsReporter.STATS_REPORTS_PARSED, { timeTaken });
67+
this.emit(PeriodicWebRTCStatsReporter.STATS_REPORTS_PARSED, { timeTaken, reportItems });
6868

6969
reportItems.forEach((item: StatsReportItem) => {
7070
this.emit(PeriodicWebRTCStatsReporter.STATS_REPORT_READY_EVENT, item);

src/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { WebRTCIssueEmitter } from './WebRTCIssueEmitter';
44

55
export interface WIDWindow {
66
wid: {
7-
handleNewPeerConnection(pc: RTCPeerConnection): void;
7+
handleNewPeerConnection(pc: RTCPeerConnection, id?: string): void;
88
},
99
}
1010

@@ -55,6 +55,7 @@ export type WebRTCIssueDetectorConstructorParams = {
5555
logger?: Logger,
5656
onIssues?: (payload: IssueDetectorResult) => void,
5757
onNetworkScoresUpdated?: (payload: NetworkScores) => void,
58+
onStats?: (payload: StatsReportItem[]) => void,
5859
ignoreSSRCList?: number[],
5960
getStatsInterval?: number,
6061
autoAddPeerConnections?: boolean,
@@ -177,6 +178,7 @@ export type ParsedInboundAudioStreamStats = {
177178
},
178179
trackId: string,
179180
transportId: string,
181+
trackIdentifier: string,
180182
};
181183

182184
export type ParsedOutboundAudioStreamStats = {
@@ -268,6 +270,7 @@ export type ParsedInboundVideoStreamStats = {
268270
}
269271
trackId: string,
270272
transportId: string,
273+
trackIdentifier: string,
271274
};
272275

273276
export type ParsedOutboundVideoStreamStats = {

test/parser/PeriodicWebRTCStatsReporter.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('wid/lib/PeriodicWebRTCStatsReporter', () => {
102102
reporter.startReporting();
103103
await clock.tickAsync(getStatsInterval);
104104

105-
expect(emitSpy).to.be.calledWith(PeriodicWebRTCStatsReporter.STATS_REPORTS_PARSED, { timeTaken: 0 });
105+
expect(emitSpy).to.be.calledWith(PeriodicWebRTCStatsReporter.STATS_REPORTS_PARSED, { timeTaken: 0, reportItems: undefined });
106106
});
107107

108108
it('should emit stats report ready event for each stats report item', async () => {

0 commit comments

Comments
 (0)