@@ -7,6 +7,7 @@ import type * as ProtocolProxyApi from '../../generated/protocol-proxy-api.js';
77import type * as Protocol from '../../generated/protocol.js' ;
88import type * as Platform from '../platform/platform.js' ;
99
10+ import { ConnectionTransport } from './ConnectionTransport.js' ;
1011import { NodeURL } from './NodeURL.js' ;
1112
1213export const DevToolsStubErrorCode = - 32015 ;
@@ -160,35 +161,6 @@ export class InspectorBackend {
160161 }
161162}
162163
163- let connectionFactory : ( ) => Connection ;
164-
165- export class Connection {
166- declare onMessage : ( ( arg0 : Object ) => void ) | null ;
167-
168- // on message from browser
169- setOnMessage ( _onMessage : ( arg0 : Object | string ) => void ) : void {
170- }
171-
172- setOnDisconnect ( _onDisconnect : ( arg0 : string ) => void ) : void {
173- }
174-
175- // send raw CDP message to browser
176- sendRawMessage ( _message : string ) : void {
177- }
178-
179- disconnect ( ) : Promise < void > {
180- throw new Error ( 'not implemented' ) ;
181- }
182-
183- static setFactory ( factory : ( ) => Connection ) : void {
184- connectionFactory = factory ;
185- }
186-
187- static getFactory ( ) : ( ) => Connection {
188- return connectionFactory ;
189- }
190- }
191-
192164type SendRawMessageCallback = ( ...args : unknown [ ] ) => void ;
193165
194166export const test = {
@@ -232,18 +204,18 @@ export const test = {
232204const LongPollingMethods = new Set < string > ( [ 'CSS.takeComputedStyleUpdates' ] ) ;
233205
234206export class SessionRouter {
235- readonly #connection: Connection ;
207+ readonly #connection: ConnectionTransport ;
236208 #lastMessageId = 1 ;
237209 #pendingResponsesCount = 0 ;
238210 readonly #pendingLongPollingMessageIds = new Set < number > ( ) ;
239211 readonly #sessions = new Map < string , {
240212 target : TargetBase ,
241213 callbacks : Map < number , CallbackWithDebugInfo > ,
242- proxyConnection : Connection | undefined | null ,
214+ proxyConnection : ConnectionTransport | undefined | null ,
243215 } > ( ) ;
244216 #pendingScripts: Array < ( ) => void > = [ ] ;
245217
246- constructor ( connection : Connection ) {
218+ constructor ( connection : ConnectionTransport ) {
247219 this . #connection = connection ;
248220
249221 test . deprecatedRunAfterPendingDispatches = this . deprecatedRunAfterPendingDispatches . bind ( this ) ;
@@ -259,7 +231,7 @@ export class SessionRouter {
259231 } ) ;
260232 }
261233
262- registerSession ( target : TargetBase , sessionId : string , proxyConnection ?: Connection | null ) : void {
234+ registerSession ( target : TargetBase , sessionId : string , proxyConnection ?: ConnectionTransport | null ) : void {
263235 // Only the Audits panel uses proxy connections. If it is ever possible to have multiple active at the
264236 // same time, it should be tested thoroughly.
265237 if ( proxyConnection ) {
@@ -297,7 +269,7 @@ export class SessionRouter {
297269 return this . #lastMessageId++ ;
298270 }
299271
300- connection ( ) : Connection {
272+ connection ( ) : ConnectionTransport {
301273 return this . #connection;
302274 }
303275
@@ -497,7 +469,8 @@ export class TargetBase {
497469 #dispatchers: DispatcherMap = new Map ( ) ;
498470
499471 constructor (
500- needsNodeJSPatching : boolean , parentTarget : TargetBase | null , sessionId : string , connection : Connection | null ) {
472+ needsNodeJSPatching : boolean , parentTarget : TargetBase | null , sessionId : string ,
473+ connection : ConnectionTransport | null ) {
501474 this . needsNodeJSPatching = needsNodeJSPatching ;
502475 this . sessionId = sessionId ;
503476
@@ -511,7 +484,7 @@ export class TargetBase {
511484 } else if ( connection ) {
512485 router = new SessionRouter ( connection ) ;
513486 } else {
514- router = new SessionRouter ( connectionFactory ( ) ) ;
487+ router = new SessionRouter ( ConnectionTransport . getFactory ( ) ( ) ) ;
515488 }
516489
517490 this . #router = router ;
0 commit comments