Skip to content

Commit 3550505

Browse files
feat: allow peer connections to be added manually
1 parent 5f38677 commit 3550505

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/WebRTCIssueDetector.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class WebRTCIssueDetector {
4242

4343
private readonly logger: Logger;
4444

45+
private readonly autoAddPeerConnections: boolean;
46+
4547
constructor(params: WebRTCIssueDetectorConstructorParams) {
4648
this.logger = params.logger ?? createLogger();
4749
this.eventEmitter = params.issueEmitter ?? new WebRTCIssueEmitter();
@@ -78,7 +80,10 @@ class WebRTCIssueDetector {
7880
});
7981

8082
(window as unknown as WIDWindow).wid = this;
81-
this.wrapRTCPeerConnection();
83+
this.autoAddPeerConnections = params.autoAddPeerConnections ?? true;
84+
if (this.autoAddPeerConnections) {
85+
this.wrapRTCPeerConnection();
86+
}
8287

8388
this.statsReporter.on(PeriodicWebRTCStatsReporter.STATS_REPORT_READY_EVENT, (report: StatsReportItem) => {
8489
this.detectIssues({
@@ -99,6 +104,10 @@ class WebRTCIssueDetector {
99104
}
100105

101106
public watchNewPeerConnections(): void {
107+
if (!this.autoAddPeerConnections) {
108+
throw new Error('Auto add peer connections was disabled in the constructor.');
109+
}
110+
102111
if (this.#running) {
103112
this.logger.warn('WebRTCIssueDetector is already started. Skip processing');
104113
return;
@@ -123,10 +132,16 @@ class WebRTCIssueDetector {
123132
}
124133

125134
public handleNewPeerConnection(pc: RTCPeerConnection): void {
126-
if (!this.#running) {
135+
if (!this.#running && this.autoAddPeerConnections) {
127136
this.logger.debug('Skip handling new peer connection. Detector is not running', pc);
128137
return;
129138
}
139+
140+
if (!this.#running && this.autoAddPeerConnections === false) {
141+
this.logger.info('Starting stats reporting for new peer connection');
142+
this.#running = true;
143+
this.statsReporter.startReporting();
144+
}
130145

131146
this.logger.debug('Handling new peer connection', pc);
132147

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export type WebRTCIssueDetectorConstructorParams = {
5757
onNetworkScoresUpdated?: (payload: NetworkScores) => void,
5858
ignoreSSRCList?: number[],
5959
getStatsInterval?: number,
60+
autoAddPeerConnections?: boolean,
6061
};
6162

6263
export enum IssueType {

0 commit comments

Comments
 (0)