in src/devtoolsPanel.ts [53:126]
private constructor(
panel: vscode.WebviewPanel,
context: vscode.ExtensionContext,
telemetryReporter: Readonly<TelemetryReporter>,
targetUrl: string,
config: IRuntimeConfig) {
this.panel = panel;
this.context = context;
this.telemetryReporter = telemetryReporter;
this.extensionPath = this.context.extensionPath;
this.targetUrl = targetUrl;
this.config = config;
this.timeStart = null;
this.devtoolsBaseUri = this.config.devtoolsBaseUri || null;
this.isHeadless = false;
// Hook up the socket events
if (this.config.isJsDebugProxiedCDPConnection) {
this.panelSocket = new JsDebugProxyPanelSocket(this.targetUrl, (e, msg) => this.postToDevTools(e, msg));
} else {
this.panelSocket = new PanelSocket(this.targetUrl, (e, msg) => this.postToDevTools(e, msg));
}
this.panelSocket.on('ready', () => this.onSocketReady());
this.panelSocket.on('websocket', msg => this.onSocketMessage(msg));
this.panelSocket.on('telemetry', msg => this.onSocketTelemetry(msg));
this.panelSocket.on('getState', msg => this.onSocketGetState(msg));
this.panelSocket.on('getVscodeSettings', msg => this.onSocketGetVscodeSettings(msg));
this.panelSocket.on('setState', msg => this.onSocketSetState(msg));
this.panelSocket.on('getUrl', msg => this.onSocketGetUrl(msg) as unknown as void);
this.panelSocket.on('openUrl', msg => this.onSocketOpenUrl(msg) as unknown as void);
this.panelSocket.on('openInEditor', msg => this.onSocketOpenInEditor(msg) as unknown as void);
this.panelSocket.on('toggleScreencast', () => this.toggleScreencast() as unknown as void);
this.panelSocket.on('cssMirrorContent', msg => this.onSocketCssMirrorContent(msg) as unknown as void);
this.panelSocket.on('close', () => this.onSocketClose());
this.panelSocket.on('copyText', msg => this.onSocketCopyText(msg));
this.panelSocket.on('focusEditor', msg => this.onSocketFocusEditor(msg));
this.panelSocket.on('focusEditorGroup', msg => this.onSocketFocusEditorGroup(msg));
// This Websocket is only used on initial connection to determine the browser version.
// The browser version is used to select the correct hashed version of the devtools
this.versionDetectionSocket = new BrowserVersionDetectionSocket(this.targetUrl);
this.versionDetectionSocket.on('setCdnParameters', msg => this.setCdnParameters(msg));
// Handle closing
this.panel.onDidDispose(() => {
this.dispose();
}, this, this.disposables);
// Handle view change
this.panel.onDidChangeViewState(_e => {
if (this.panel.visible) {
if (this.panelSocket.isConnectedToTarget) {
// Connection type determined already
this.update();
} else {
// Use version socket to determine which Webview/Tools to use
this.versionDetectionSocket.detectVersion();
}
}
}, this, this.disposables);
// Handle messages from the webview
this.panel.webview.onDidReceiveMessage(message => {
this.panelSocket.onMessageFromWebview(message);
}, this, this.disposables);
// Update DevTools theme if user changes global theme
vscode.workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('workbench.colorTheme') &&
this.panel.visible) {
this.update();
}
});
}