@@ -97,6 +97,8 @@ export default class InspectorProxy implements InspectorProxyQueries {
9797
9898 #eventLoopPerfTracker: EventLoopPerfTracker ;
9999
100+ #onDevicesListChangedCallbacks: Set < ( devices : Map < string , Device > ) => void > ;
101+
100102 constructor (
101103 serverBaseUrl : string ,
102104 eventReporter : ?EventReporter ,
@@ -111,6 +113,7 @@ export default class InspectorProxy implements InspectorProxyQueries {
111113 this . #experiments = experiments ;
112114 this . #logger = logger ;
113115 this . #customMessageHandler = customMessageHandler ;
116+ this . #onDevicesListChangedCallbacks = new Set ( ) ;
114117 if ( trackEventLoopPerf ) {
115118 this . #eventLoopPerfTracker = new EventLoopPerfTracker ( {
116119 perfMeasurementDuration : EVENT_LOOP_PERF_MEASUREMENT_MS ,
@@ -142,6 +145,19 @@ export default class InspectorProxy implements InspectorProxyQueries {
142145 }
143146 }
144147
148+ getConnectedDevices ( ) : Array < Device > {
149+ return Array . from ( this . #devices. values ( ) ) ;
150+ }
151+
152+ onDevicesListChanged (
153+ callback : ( devices : Map < string , Device> ) => void ,
154+ ) : ( ) => void {
155+ this . #onDevicesListChangedCallbacks. add ( callback ) ;
156+ return ( ) => {
157+ this . #onDevicesListChangedCallbacks. delete ( callback ) ;
158+ } ;
159+ }
160+
145161 getPageDescriptions ( {
146162 requestorRelativeBaseUrl,
147163 logNoPagesForConnectedDevice = false ,
@@ -365,6 +381,7 @@ export default class InspectorProxy implements InspectorProxyQueries {
365381 }
366382
367383 this . #devices. set ( deviceId , newDevice ) ;
384+ this . #onDevicesListChangedCallbacks. forEach ( cb => cb ( this . #devices) ) ;
368385
369386 debug (
370387 "Got new device connection: name='%s', app=%s, device=%s, via=%s" ,
@@ -457,6 +474,9 @@ export default class InspectorProxy implements InspectorProxyQueries {
457474
458475 if ( this . #devices. get ( deviceId ) ?. dangerouslyGetSocket ( ) === socket ) {
459476 this . #devices. delete ( deviceId ) ;
477+ this . #onDevicesListChangedCallbacks. forEach ( cb =>
478+ cb ( this . #devices) ,
479+ ) ;
460480 }
461481 } ) ;
462482 } catch ( error ) {
0 commit comments