@lynx-js/devtool-connector 0.1.1 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/LICENSE +1 -1
- package/README.md +152 -0
- package/dist/187.js +272 -0
- package/dist/390.js +102 -0
- package/dist/43.js +20 -0
- package/dist/556.js +253 -0
- package/dist/63.js +93 -0
- package/dist/677.js +19 -0
- package/dist/712.js +180 -0
- package/dist/872.js +771 -0
- package/dist/962.js +12150 -0
- package/dist/client-id.d.ts +7 -0
- package/dist/daemon/device-connection.d.ts +36 -0
- package/dist/daemon/entry.d.ts +1 -0
- package/dist/daemon/entry.js +46 -0
- package/dist/daemon/index.d.ts +1 -0
- package/dist/daemon/index.js +1 -0
- package/dist/daemon/manager.d.ts +14 -0
- package/dist/daemon/protocol.d.ts +73 -0
- package/dist/daemon/server.d.ts +14 -0
- package/dist/daemon/static-server.d.ts +5 -0
- package/dist/daemon/tarball-cache.d.ts +16 -0
- package/dist/daemon/version.d.ts +1 -0
- package/dist/index.d.ts +47 -19
- package/dist/index.js +188 -349
- package/dist/rslib-runtime.js +0 -20
- package/dist/streams/cdp.d.ts +2 -4
- package/dist/streams/customized.d.ts +5 -4
- package/dist/streams/index.d.ts +3 -0
- package/dist/streams/index.js +1 -0
- package/dist/streams/utils.d.ts +11 -0
- package/dist/transport/android.d.ts +4 -3
- package/dist/transport/base.d.ts +9 -0
- package/dist/transport/daemon.d.ts +20 -0
- package/dist/transport/desktop.d.ts +4 -3
- package/dist/transport/index.d.ts +5 -0
- package/dist/transport/index.js +3 -11253
- package/dist/transport/ios.d.ts +3 -4
- package/dist/transport/transport.d.ts +7 -5
- package/dist/transport/usbmux.d.ts +49 -0
- package/dist/transport/ws-stream.d.ts +28 -0
- package/dist/types.d.ts +73 -19
- package/package.json +33 -15
- package/public/inspector-wrapper.html +539 -0
- package/dist/844.js +0 -632
- /package/dist/{streams → transport}/peertalk.d.ts +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Transport, TransportConnectOptions } from '../transport/transport.ts';
|
|
2
|
+
import { type AppInfo } from '../types.ts';
|
|
3
|
+
export interface DeviceConnectionSubscriber {
|
|
4
|
+
readonly id: number;
|
|
5
|
+
send(message: unknown): void;
|
|
6
|
+
close(): void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Maintains a persistent connection to a single device:port through a real
|
|
10
|
+
* transport.
|
|
11
|
+
*
|
|
12
|
+
* On first connect it performs the Initialize/Register handshake and caches
|
|
13
|
+
* the {@link AppInfo}. After that, messages from the device are broadcast to
|
|
14
|
+
* all subscribers, and messages from clients are forwarded to the device.
|
|
15
|
+
*/
|
|
16
|
+
export declare class DeviceConnection {
|
|
17
|
+
#private;
|
|
18
|
+
readonly key: string;
|
|
19
|
+
readonly deviceId: string;
|
|
20
|
+
readonly port: number;
|
|
21
|
+
/** Populated after a successful Initialize/Register handshake. */
|
|
22
|
+
appInfo: AppInfo | null;
|
|
23
|
+
constructor(transport: Transport, options: TransportConnectOptions);
|
|
24
|
+
/**
|
|
25
|
+
* Opens the underlying transport connection. The caller should wrap this
|
|
26
|
+
* in a try/catch — a failure means the device:port is unreachable.
|
|
27
|
+
*/
|
|
28
|
+
connect(): Promise<void>;
|
|
29
|
+
addSubscriber(subscriber: DeviceConnectionSubscriber): void;
|
|
30
|
+
removeSubscriber(id: number): void;
|
|
31
|
+
get subscriberCount(): number;
|
|
32
|
+
get isDisposed(): boolean;
|
|
33
|
+
get isPersistent(): boolean;
|
|
34
|
+
send(message: unknown): Promise<void>;
|
|
35
|
+
dispose(): Promise<void>;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { AndroidTransport, DesktopTransport, iOSTransport } from "../962.js";
|
|
3
|
+
import "../390.js";
|
|
4
|
+
import { DevtoolDaemon } from "../872.js";
|
|
5
|
+
function getAndroidTransportSpec(env) {
|
|
6
|
+
const port = Number.parseInt(env['ADB_SERVER_PORT'] ?? '5037', 10);
|
|
7
|
+
return {
|
|
8
|
+
host: env['ADB_SERVER_HOST'] ?? '127.0.0.1',
|
|
9
|
+
port: Number.isInteger(port) && port > 0 ? port : 5037
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
const { values: values } = parseArgs({
|
|
13
|
+
options: {
|
|
14
|
+
port: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
default: String(21783)
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
strict: true
|
|
20
|
+
});
|
|
21
|
+
const entry_port = Number.parseInt(values.port ?? String(21783), 10);
|
|
22
|
+
const daemon = new DevtoolDaemon([
|
|
23
|
+
new AndroidTransport(getAndroidTransportSpec(process.env)),
|
|
24
|
+
new iOSTransport(),
|
|
25
|
+
new DesktopTransport()
|
|
26
|
+
], {
|
|
27
|
+
onIdle: ()=>{
|
|
28
|
+
daemon.close().then(()=>{
|
|
29
|
+
process.exit(0);
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
onShutdown: ()=>{
|
|
33
|
+
process.exit(0);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
await daemon.start(entry_port);
|
|
37
|
+
process.on('SIGTERM', ()=>{
|
|
38
|
+
daemon.close().then(()=>{
|
|
39
|
+
process.exit(0);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
process.on('SIGINT', ()=>{
|
|
43
|
+
daemon.close().then(()=>{
|
|
44
|
+
process.exit(0);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DevtoolDaemon } from './server.ts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DevtoolDaemon } from "../872.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { DEFAULT_DAEMON_PORT } from './protocol.ts';
|
|
2
|
+
export declare function resolveDaemonEntryPath(moduleUrl?: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* Manages the daemon process lifecycle.
|
|
5
|
+
*
|
|
6
|
+
* - `ensureRunning()`: checks if the daemon is alive, spawns it if not
|
|
7
|
+
* - `spawn()`: forks a detached daemon process
|
|
8
|
+
* - `kill()`: sends SIGTERM to the daemon
|
|
9
|
+
*/
|
|
10
|
+
export declare class DaemonManager {
|
|
11
|
+
#private;
|
|
12
|
+
static ensureRunning(port?: number): Promise<string>;
|
|
13
|
+
static kill(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { AppInfo } from '../types.ts';
|
|
2
|
+
export interface InitializeEvent {
|
|
3
|
+
event: 'Initialize';
|
|
4
|
+
data: number;
|
|
5
|
+
}
|
|
6
|
+
export interface RegisterEvent {
|
|
7
|
+
event: 'Register';
|
|
8
|
+
data: {
|
|
9
|
+
id: number;
|
|
10
|
+
type: 'Driver';
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface ClientListEvent {
|
|
14
|
+
event: 'ClientList';
|
|
15
|
+
data: ClientListEntry[];
|
|
16
|
+
}
|
|
17
|
+
export interface ClientListEntry {
|
|
18
|
+
id: string;
|
|
19
|
+
info: AppInfo;
|
|
20
|
+
type: 'runtime';
|
|
21
|
+
}
|
|
22
|
+
export interface ListClientsRequest {
|
|
23
|
+
event: 'ListClients';
|
|
24
|
+
}
|
|
25
|
+
export interface PingEvent {
|
|
26
|
+
event: 'Ping';
|
|
27
|
+
}
|
|
28
|
+
export interface PongEvent {
|
|
29
|
+
event: 'Pong';
|
|
30
|
+
}
|
|
31
|
+
export interface ControlRequest {
|
|
32
|
+
event: 'Control';
|
|
33
|
+
data: {
|
|
34
|
+
id: number;
|
|
35
|
+
method: 'listClients' | 'listDevices' | 'listAvailableApps' | 'openApp' | 'subscribe';
|
|
36
|
+
params?: Record<string, unknown>;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export interface ControlResponse {
|
|
40
|
+
event: 'ControlResponse';
|
|
41
|
+
data: {
|
|
42
|
+
id: number;
|
|
43
|
+
result?: unknown;
|
|
44
|
+
error?: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export type DaemonIncomingMessage = RegisterEvent | ListClientsRequest | PingEvent | ControlRequest | CustomizedMessage;
|
|
48
|
+
export type DaemonOutgoingMessage = InitializeEvent | ClientListEvent | PongEvent | ControlResponse | CustomizedMessage;
|
|
49
|
+
export interface CustomizedMessage {
|
|
50
|
+
event: 'Customized';
|
|
51
|
+
data: {
|
|
52
|
+
type: string;
|
|
53
|
+
data: {
|
|
54
|
+
client_id?: number;
|
|
55
|
+
session_id?: number;
|
|
56
|
+
message?: unknown;
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
};
|
|
59
|
+
sender?: number;
|
|
60
|
+
[key: string]: unknown;
|
|
61
|
+
};
|
|
62
|
+
to?: number;
|
|
63
|
+
}
|
|
64
|
+
export declare function isCustomizedMessage(msg: unknown): msg is CustomizedMessage;
|
|
65
|
+
export declare function isControlRequest(msg: unknown): msg is ControlRequest;
|
|
66
|
+
export declare function isListClientsRequest(msg: unknown): msg is ListClientsRequest;
|
|
67
|
+
export declare function isPingEvent(msg: unknown): msg is PingEvent;
|
|
68
|
+
export declare function isRegisterEvent(msg: unknown): msg is RegisterEvent;
|
|
69
|
+
export declare const DEFAULT_DAEMON_PORT = 21783;
|
|
70
|
+
export declare const DAEMON_WS_PATH = "/devtool/connector";
|
|
71
|
+
export declare const DAEMON_VERSION_PATH: string;
|
|
72
|
+
export declare const DAEMON_SHUTDOWN_PATH: string;
|
|
73
|
+
export declare const DAEMON_INSPECTOR_PATH: string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Transport } from '../transport/transport.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The daemon process. Holds real transports, manages persistent device
|
|
4
|
+
* connections, and exposes a WebSocket server for DaemonTransport clients.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DevtoolDaemon {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(transports: Transport[], options?: {
|
|
9
|
+
onIdle?: () => void;
|
|
10
|
+
onShutdown?: () => void;
|
|
11
|
+
});
|
|
12
|
+
start(port: number): Promise<number>;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface TarballEntry {
|
|
2
|
+
gzipped: Buffer;
|
|
3
|
+
rawSize: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Streaming tarball loader. Downloads, gunzips, and parses tar entries on
|
|
7
|
+
* the fly. Only retains files matching the filter prefix, stored gzip-compressed.
|
|
8
|
+
* Files become available for serving as soon as each entry is fully read.
|
|
9
|
+
*/
|
|
10
|
+
export declare class TarballCache {
|
|
11
|
+
#private;
|
|
12
|
+
get(filePath: string): TarballEntry | undefined;
|
|
13
|
+
get isDone(): boolean;
|
|
14
|
+
waitFor(filePath: string): Promise<TarballEntry | null>;
|
|
15
|
+
start(url: string): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CONNECTOR_VERSION: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,37 +1,65 @@
|
|
|
1
|
-
import { ReadableStream } from 'node:stream/web';
|
|
2
|
-
|
|
1
|
+
import { ReadableStream, type TransformStream } from 'node:stream/web';
|
|
2
|
+
export { CDPOutputTransformStream, CDPRequestTransformStream, CDPResponseTransformStream, } from './streams/cdp.ts';
|
|
3
|
+
import { ClientId } from './client-id.ts';
|
|
3
4
|
import type { App, Client, Device, OpenAppOptions, Transport } from './transport/transport.ts';
|
|
4
|
-
import type
|
|
5
|
-
export { MessageToPeertalkTransformStream, PeertalkToMessageTransformStream };
|
|
5
|
+
import { type CDPRequestMessage, type GlobalKeys, type HeadlessPrepareState, type Session } from './types.ts';
|
|
6
6
|
interface OutputStream<O> extends AsyncDisposable, ReadableStream<O> {
|
|
7
|
+
inputClosed: Promise<void>;
|
|
7
8
|
}
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} | null;
|
|
14
|
-
}
|
|
9
|
+
export { ClientId };
|
|
10
|
+
type Pipeline = {
|
|
11
|
+
input: TransformStream[];
|
|
12
|
+
output: TransformStream[];
|
|
13
|
+
};
|
|
15
14
|
export declare class Connector {
|
|
16
15
|
#private;
|
|
17
16
|
constructor(transports: Transport[]);
|
|
18
17
|
listClients(): Promise<Client[]>;
|
|
19
18
|
listDevices(): Promise<Device[]>;
|
|
20
|
-
close(): Promise<void>;
|
|
21
19
|
listAvailableApps(deviceId: string): Promise<App[]>;
|
|
22
20
|
openApp(deviceId: string, packageName: string, options?: OpenAppOptions): Promise<void>;
|
|
23
|
-
sendMessage<T, R>(clientId: string, message: T): Promise<R>;
|
|
21
|
+
sendMessage<T, R>(clientId: string, message: T, pipeline?: Pipeline): Promise<R>;
|
|
22
|
+
/**
|
|
23
|
+
* Send a message to the device without waiting for a response.
|
|
24
|
+
*
|
|
25
|
+
* Unlike {@link sendMessage}, this method does not wait for the output
|
|
26
|
+
* stream to produce a value. It connects, writes the message, and then
|
|
27
|
+
* disposes of the connection. This is useful for fire-and-forget messages
|
|
28
|
+
* such as `xdb_proxy_config` where the device does not send a reply.
|
|
29
|
+
*/
|
|
30
|
+
sendMessageNoReply<T>(clientId: string, message: T): Promise<void>;
|
|
24
31
|
sendAppMessage<Output, Params = never>(clientId: string, method: string, params?: Params): Promise<Output>;
|
|
25
|
-
sendCDPMessage<Output, Params = never>(clientId: string, sessionId: number, method: string, params?: Params): Promise<Output>;
|
|
32
|
+
sendCDPMessage<Output, Params = never>(clientId: string, sessionId: number, method: string, params?: Params, isMainThread?: boolean): Promise<Output>;
|
|
26
33
|
sendListSessionMessage(clientId: string): Promise<Session[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Probe the headless runtime's readiness. Returns immediately with the
|
|
36
|
+
* current state and, when not ready, kicks off the binary download in the
|
|
37
|
+
* background. Callers (e.g. the `open` command) poll this until `ready` so
|
|
38
|
+
* the download is driven by a caller-controlled timeout rather than a single
|
|
39
|
+
* request that could be cut off mid-download.
|
|
40
|
+
*/
|
|
41
|
+
prepareHeadless(clientId: string): Promise<HeadlessPrepareState>;
|
|
42
|
+
/**
|
|
43
|
+
* Block until the headless runtime is ready, polling {@link prepareHeadless}
|
|
44
|
+
* so the (potentially long) first-use binary download is not cut off by a
|
|
45
|
+
* single request timeout. A transient `error` is tolerated until the overall
|
|
46
|
+
* deadline because the transport retries the download on the next poll.
|
|
47
|
+
*
|
|
48
|
+
* Intended to be called from the CLI/tool layer before opening a page on the
|
|
49
|
+
* headless client; the core request path is intentionally left untouched.
|
|
50
|
+
*/
|
|
51
|
+
waitForHeadlessReady(clientId: string, options?: {
|
|
52
|
+
timeoutMs?: number;
|
|
53
|
+
pollIntervalMs?: number;
|
|
54
|
+
}): Promise<void>;
|
|
27
55
|
getGlobalSwitch(clientId: string, key: GlobalKeys): Promise<boolean>;
|
|
28
56
|
setGlobalSwitch(clientId: string, key: GlobalKeys, value: boolean): Promise<void>;
|
|
29
|
-
sendStream<I, O>(clientId: string, inputStream: ReadableStream<I>, { signal }
|
|
30
|
-
signal?: AbortSignal;
|
|
57
|
+
sendStream<I, O>(clientId: string, inputStream: ReadableStream<I>, { signal, pipeline, }?: {
|
|
58
|
+
signal?: AbortSignal | undefined;
|
|
59
|
+
pipeline?: Pipeline | undefined;
|
|
31
60
|
}): Promise<OutputStream<O>>;
|
|
32
|
-
sendCDPStream(clientId: string, inputStream: ReadableStream<CDPRequestMessage
|
|
33
|
-
sessionId: number;
|
|
34
|
-
}>, { signal }?: {
|
|
61
|
+
sendCDPStream(clientId: string, sessionId: number, inputStream: ReadableStream<CDPRequestMessage>, { signal }?: {
|
|
35
62
|
signal?: AbortSignal;
|
|
36
63
|
}): Promise<OutputStream<CDPRequestMessage>>;
|
|
37
64
|
}
|
|
65
|
+
export * from './types.ts';
|