22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5+ import * as i18n from '../../core/i18n/i18n.js' ;
56import * as Common from '../common/common.js' ;
67import * as Host from '../host/host.js' ;
78import type * as Platform from '../platform/platform.js' ;
@@ -10,6 +11,14 @@ import * as Root from '../root/root.js';
1011
1112import { RehydratingConnection } from './RehydratingConnection.js' ;
1213
14+ const UIStrings = {
15+ /**
16+ *@description Text on the remote debugging window to indicate the connection is lost
17+ */
18+ websocketDisconnected : 'WebSocket disconnected' ,
19+ } ;
20+ const str_ = i18n . i18n . registerUIStrings ( 'core/sdk/Connections.ts' , UIStrings ) ;
21+ const i18nString = i18n . i18n . getLocalizedString . bind ( undefined , str_ ) ;
1322export class MainConnection implements ProtocolClient . InspectorBackend . Connection {
1423 onMessage : ( ( arg0 : ( Object | string ) ) => void ) | null ;
1524 #onDisconnect: ( ( arg0 : string ) => void ) | null ;
@@ -80,10 +89,12 @@ export class WebSocketConnection implements ProtocolClient.InspectorBackend.Conn
8089 #socket: WebSocket | null ;
8190 onMessage : ( ( arg0 : ( Object | string ) ) => void ) | null ;
8291 #onDisconnect: ( ( arg0 : string ) => void ) | null ;
83- #onWebSocketDisconnect: ( ( ) => void ) | null ;
92+ #onWebSocketDisconnect: ( ( message : Platform . UIString . LocalizedString ) => void ) | null ;
8493 #connected: boolean ;
8594 #messages: string [ ] ;
86- constructor ( url : Platform . DevToolsPath . UrlString , onWebSocketDisconnect : ( ) => void ) {
95+ constructor (
96+ url : Platform . DevToolsPath . UrlString ,
97+ onWebSocketDisconnect : ( message : Platform . UIString . LocalizedString ) => void ) {
8798 this . #socket = new WebSocket ( url ) ;
8899 this . #socket. onerror = this . onError . bind ( this ) ;
89100 this . #socket. onopen = this . onOpen . bind ( this ) ;
@@ -111,7 +122,7 @@ export class WebSocketConnection implements ProtocolClient.InspectorBackend.Conn
111122
112123 private onError ( ) : void {
113124 if ( this . #onWebSocketDisconnect) {
114- this . #onWebSocketDisconnect. call ( null ) ;
125+ this . #onWebSocketDisconnect. call ( null , i18nString ( UIStrings . websocketDisconnected ) ) ;
115126 }
116127 if ( this . #onDisconnect) {
117128 // This is called if error occurred while connecting.
@@ -133,7 +144,7 @@ export class WebSocketConnection implements ProtocolClient.InspectorBackend.Conn
133144
134145 private onClose ( ) : void {
135146 if ( this . #onWebSocketDisconnect) {
136- this . #onWebSocketDisconnect. call ( null ) ;
147+ this . #onWebSocketDisconnect. call ( null , i18nString ( UIStrings . websocketDisconnected ) ) ;
137148 }
138149 if ( this . #onDisconnect) {
139150 this . #onDisconnect. call ( null , 'websocket closed' ) ;
@@ -266,21 +277,23 @@ export class ParallelConnection implements ParallelConnectionInterface {
266277}
267278
268279export async function initMainConnection (
269- createRootTarget : ( ) => Promise < void > , websocketConnectionLost : ( ) => void ) : Promise < void > {
270- ProtocolClient . InspectorBackend . Connection . setFactory ( createMainConnection . bind ( null , websocketConnectionLost ) ) ;
280+ createRootTarget : ( ) => Promise < void > ,
281+ onConnectionLost : ( message : Platform . UIString . LocalizedString ) => void ) : Promise < void > {
282+ ProtocolClient . InspectorBackend . Connection . setFactory ( createMainConnection . bind ( null , onConnectionLost ) ) ;
271283 await createRootTarget ( ) ;
272284 Host . InspectorFrontendHost . InspectorFrontendHostInstance . connectionReady ( ) ;
273285}
274286
275- function createMainConnection ( websocketConnectionLost : ( ) => void ) : ProtocolClient . InspectorBackend . Connection {
287+ function createMainConnection ( onConnectionLost : ( message : Platform . UIString . LocalizedString ) => void ) :
288+ ProtocolClient . InspectorBackend . Connection {
276289 if ( Root . Runtime . getPathName ( ) . includes ( 'rehydrated_devtools_app' ) ) {
277- return new RehydratingConnection ( ) ;
290+ return new RehydratingConnection ( onConnectionLost ) ;
278291 }
279292 const wsParam = Root . Runtime . Runtime . queryParam ( 'ws' ) ;
280293 const wssParam = Root . Runtime . Runtime . queryParam ( 'wss' ) ;
281294 if ( wsParam || wssParam ) {
282295 const ws = ( wsParam ? `ws://${ wsParam } ` : `wss://${ wssParam } ` ) as Platform . DevToolsPath . UrlString ;
283- return new WebSocketConnection ( ws , websocketConnectionLost ) ;
296+ return new WebSocketConnection ( ws , onConnectionLost ) ;
284297 }
285298 if ( Host . InspectorFrontendHost . InspectorFrontendHostInstance . isHostedMode ( ) ) {
286299 return new StubConnection ( ) ;
0 commit comments