microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.4.2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/cdp-proxy/CDPMessageHandlers/iOSDirectCDPMessageHandler.ts

66lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import { BaseCDPMessageHandler } from "./baseCDPMessageHandler";
5import { ProcessedCDPMessage } from "./ICDPMessageHandler";
6import { CDP_API_NAMES } from "./CDPAPINames";
7
8export class IOSDirectCDPMessageHandler extends BaseCDPMessageHandler {
9 private isBackcompatConfigured: boolean;
10
11 constructor() {
12 super();
13 this.isBackcompatConfigured = false;
14 }
15
16 public processDebuggerCDPMessage(event: any): ProcessedCDPMessage {
17 let sendBack = false;
18 if (!this.isBackcompatConfigured && event.method === CDP_API_NAMES.RUNTIME_ENABLE) {
19 this.configureTargetForIWDPCommunication();
20 }
21 return {
22 event,
23 sendBack,
24 };
25 }
26
27 public processApplicationCDPMessage(event: any): ProcessedCDPMessage {
28 if (event.method === CDP_API_NAMES.CONSOLE_MESSAGE_ADDED) {
29 event = this.processDeprecatedConsoleMessage(event);
30 }
31 if (event.result && event.result.properties) {
32 event.result = { result: event.result.properties };
33 }
34 return {
35 event,
36 sendBack: false,
37 };
38 }
39
40 private processDeprecatedConsoleMessage(event: any) {
41 return {
42 method: CDP_API_NAMES.RUNTIME_CONSOLE_API_CALLED,
43 params: {
44 type: event.params.message.type,
45 timestamp: event.params.message.timestamp,
46 args: event.params.message.parameters || [
47 { type: "string", value: event.params.message.text },
48 ],
49 stackTrace: {
50 callFrames: event.params.message.stack || event.params.message.stackTrace,
51 },
52 executionContextId: 1,
53 },
54 };
55 }
56
57 private configureTargetForIWDPCommunication(): void {
58 this.isBackcompatConfigured = true;
59 try {
60 this.applicationTarget?.api.Console.enable({});
61 this.applicationTarget?.api.Debugger.setBreakpointsActive({ active: true });
62 } catch (err) {
63 // Specifically ignore a fail here since it's only for backcompat
64 }
65 }
66}
67