@@ -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
0 commit comments