react-native-get-pixel_edit/node_modules/@react-native/dev-middleware/dist/inspector-proxy/Device.js.flow
2025-07-09 11:41:52 +09:00

98 lines
2.6 KiB
Plaintext

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
import type {
DebuggerRequest,
GetScriptSourceRequest,
MessageFromDevice,
MessageToDevice,
Page,
SetBreakpointByUrlRequest,
} from "./types";
import DeviceEventReporter from "./DeviceEventReporter";
import WS from "ws";
import type { EventReporter } from "../types/EventReporter";
type DebuggerInfo = {
// Debugger web socket connection
socket: WS,
// If we replaced address (like '10.0.2.2') to localhost we need to store original
// address because Chrome uses URL or urlRegex params (instead of scriptId) to set breakpoints.
originalSourceURLAddress?: string,
prependedFilePrefix: boolean,
pageId: string,
userAgent: string | null,
};
/**
* Device class represents single device connection to Inspector Proxy. Each device
* can have multiple inspectable pages.
*/
declare export default class Device {
_id: string;
_name: string;
_app: string;
_deviceSocket: WS;
_pages: Array<Page>;
_debuggerConnection: ?DebuggerInfo;
_lastConnectedReactNativePage: ?Page;
_isReloading: boolean;
_lastGetPagesMessage: string;
_scriptIdToSourcePathMapping: Map<string, string>;
_projectRoot: string;
_deviceEventReporter: ?DeviceEventReporter;
constructor(
id: string,
name: string,
app: string,
socket: WS,
projectRoot: string,
eventReporter: ?EventReporter
): void;
getName(): string;
getApp(): string;
getPagesList(): Array<Page>;
handleDebuggerConnection(
socket: WS,
pageId: string,
metadata: $ReadOnly<{
userAgent: string | null,
}>
): void;
handleDuplicateDeviceConnection(newDevice: Device): void;
_handleMessageFromDevice(message: MessageFromDevice): void;
_sendMessageToDevice(message: MessageToDevice): void;
_setPagesPolling(): void;
_newReactNativePage(page: Page): void;
_processMessageFromDevice(
payload: { method: string, params: { sourceMapURL: string, url: string } },
debuggerInfo: DebuggerInfo
): void;
_interceptMessageFromDebugger(
req: DebuggerRequest,
debuggerInfo: DebuggerInfo,
socket: WS
): boolean;
_processDebuggerSetBreakpointByUrl(
req: SetBreakpointByUrlRequest,
debuggerInfo: DebuggerInfo
): void;
_processDebuggerGetScriptSource(
req: GetScriptSourceRequest,
socket: WS
): void;
_mapToDevicePageId(pageId: string): string;
_tryParseHTTPURL(url: string): ?URL;
_fetchText(url: URL): Promise<string>;
_sendErrorToDebugger(message: string): void;
}