@arenahito/droid-webscr 0.0.0 → 0.1.0
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/android/droid-webscr-server-android.jar +0 -0
- package/dist/bin.js +81 -73
- package/dist/bin.js.map +1 -1
- package/dist/index.js +42 -48
- package/dist/index.js.map +1 -1
- package/dist/main.js +76 -72
- package/dist/main.js.map +1 -1
- package/package.json +5 -1
package/dist/main.js
CHANGED
|
@@ -4,33 +4,21 @@ var __export = (target, all) => {
|
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
// ../../packages/adb/
|
|
7
|
+
// ../../packages/adb/src/provider.ts
|
|
8
8
|
import { Readable } from "stream";
|
|
9
|
-
var AdbAuthorizationState;
|
|
10
|
-
(function(AdbAuthorizationState2) {
|
|
11
|
-
AdbAuthorizationState2["Authorized"] = "authorized";
|
|
12
|
-
AdbAuthorizationState2["Offline"] = "offline";
|
|
13
|
-
AdbAuthorizationState2["Unauthorized"] = "unauthorized";
|
|
14
|
-
})(AdbAuthorizationState || (AdbAuthorizationState = {}));
|
|
15
|
-
var AdbTransportKind;
|
|
16
|
-
(function(AdbTransportKind2) {
|
|
17
|
-
AdbTransportKind2["Emulator"] = "emulator";
|
|
18
|
-
AdbTransportKind2["Network"] = "network";
|
|
19
|
-
AdbTransportKind2["Usb"] = "usb";
|
|
20
|
-
})(AdbTransportKind || (AdbTransportKind = {}));
|
|
21
9
|
function isUsableDevice(device) {
|
|
22
|
-
return device.authorizationState ===
|
|
10
|
+
return device.authorizationState === "authorized" /* Authorized */ && device.serial.length > 0;
|
|
23
11
|
}
|
|
24
12
|
|
|
25
|
-
// ../../packages/adb/
|
|
13
|
+
// ../../packages/adb/src/system-adb-provider.ts
|
|
26
14
|
import { spawn } from "child_process";
|
|
27
15
|
import { createConnection, Server } from "net";
|
|
28
16
|
import { Readable as Readable2 } from "stream";
|
|
29
17
|
var SystemAdbProvider = class _SystemAdbProvider {
|
|
30
|
-
adbPath;
|
|
31
18
|
constructor(adbPath = "adb") {
|
|
32
19
|
this.adbPath = adbPath;
|
|
33
20
|
}
|
|
21
|
+
adbPath;
|
|
34
22
|
/* v8 ignore next 4 -- external adb process boundary; deterministic parsing is unit-tested */
|
|
35
23
|
async listDevices() {
|
|
36
24
|
const output = await runAndCollect(this.adbPath, ["devices", "-l"]);
|
|
@@ -69,16 +57,16 @@ var SystemAdbProvider = class _SystemAdbProvider {
|
|
|
69
57
|
}
|
|
70
58
|
};
|
|
71
59
|
var SystemAdbDeviceSession = class {
|
|
60
|
+
constructor(adbPath, serial) {
|
|
61
|
+
this.adbPath = adbPath;
|
|
62
|
+
this.serial = serial;
|
|
63
|
+
}
|
|
72
64
|
adbPath;
|
|
73
65
|
serial;
|
|
74
66
|
forwards = /* @__PURE__ */ new Set();
|
|
75
67
|
sockets = /* @__PURE__ */ new Set();
|
|
76
68
|
shellChildren = /* @__PURE__ */ new Set();
|
|
77
69
|
shellCloses = /* @__PURE__ */ new Map();
|
|
78
|
-
constructor(adbPath, serial) {
|
|
79
|
-
this.adbPath = adbPath;
|
|
80
|
-
this.serial = serial;
|
|
81
|
-
}
|
|
82
70
|
async push(localPath, remotePath) {
|
|
83
71
|
await runAndCollect(this.adbPath, ["-s", this.serial, "push", localPath, remotePath]);
|
|
84
72
|
}
|
|
@@ -124,10 +112,16 @@ var SystemAdbDeviceSession = class {
|
|
|
124
112
|
this.forwards.add(forward.local);
|
|
125
113
|
try {
|
|
126
114
|
const socket = await connectLocalPortWithRetry(localPort);
|
|
127
|
-
const forwardedSocket = new ForwardedAdbSocket(
|
|
128
|
-
this.
|
|
129
|
-
this.
|
|
130
|
-
|
|
115
|
+
const forwardedSocket = new ForwardedAdbSocket(
|
|
116
|
+
this.adbPath,
|
|
117
|
+
this.serial,
|
|
118
|
+
forward.local,
|
|
119
|
+
socket,
|
|
120
|
+
() => {
|
|
121
|
+
this.forwards.delete(forward.local);
|
|
122
|
+
this.sockets.delete(forwardedSocket);
|
|
123
|
+
}
|
|
124
|
+
);
|
|
131
125
|
this.sockets.add(forwardedSocket);
|
|
132
126
|
return forwardedSocket;
|
|
133
127
|
} catch (error51) {
|
|
@@ -143,7 +137,9 @@ var SystemAdbDeviceSession = class {
|
|
|
143
137
|
await Promise.allSettled([
|
|
144
138
|
...this.shellCloses.values(),
|
|
145
139
|
...[...this.sockets].map((socket) => socket.close()),
|
|
146
|
-
...[...this.forwards].map(
|
|
140
|
+
...[...this.forwards].map(
|
|
141
|
+
(forward) => runAndCollect(this.adbPath, ["-s", this.serial, "forward", "--remove", forward])
|
|
142
|
+
)
|
|
147
143
|
]);
|
|
148
144
|
this.forwards.clear();
|
|
149
145
|
}
|
|
@@ -172,24 +168,24 @@ function parseDeviceLine(line) {
|
|
|
172
168
|
}
|
|
173
169
|
function parseAuthorizationState(state) {
|
|
174
170
|
if (state === "device") {
|
|
175
|
-
return
|
|
171
|
+
return "authorized" /* Authorized */;
|
|
176
172
|
}
|
|
177
173
|
if (state === "unauthorized") {
|
|
178
|
-
return
|
|
174
|
+
return "unauthorized" /* Unauthorized */;
|
|
179
175
|
}
|
|
180
|
-
return
|
|
176
|
+
return "offline" /* Offline */;
|
|
181
177
|
}
|
|
182
178
|
function inferTransportKind(serial, fields) {
|
|
183
179
|
if (serial.startsWith("emulator-")) {
|
|
184
|
-
return
|
|
180
|
+
return "emulator" /* Emulator */;
|
|
185
181
|
}
|
|
186
182
|
if (serial.includes(":")) {
|
|
187
|
-
return
|
|
183
|
+
return "network" /* Network */;
|
|
188
184
|
}
|
|
189
185
|
if (fields.some((field) => field.startsWith("usb:"))) {
|
|
190
|
-
return
|
|
186
|
+
return "usb" /* Usb */;
|
|
191
187
|
}
|
|
192
|
-
return
|
|
188
|
+
return "usb" /* Usb */;
|
|
193
189
|
}
|
|
194
190
|
function parseField(fields, key) {
|
|
195
191
|
const prefix = `${key}:`;
|
|
@@ -212,7 +208,9 @@ async function runAndCollect(command, args) {
|
|
|
212
208
|
return stdout;
|
|
213
209
|
}
|
|
214
210
|
async function startLogcatTail(command, serial) {
|
|
215
|
-
const epoch = Number(
|
|
211
|
+
const epoch = Number(
|
|
212
|
+
(await runAndCollect(command, ["-s", serial, "shell", "date", "+%s"])).trim()
|
|
213
|
+
);
|
|
216
214
|
if (!Number.isFinite(epoch)) {
|
|
217
215
|
throw new Error("Failed to read device logcat start time.");
|
|
218
216
|
}
|
|
@@ -321,12 +319,6 @@ function delay(ms) {
|
|
|
321
319
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
322
320
|
}
|
|
323
321
|
var ForwardedAdbSocket = class {
|
|
324
|
-
adbPath;
|
|
325
|
-
serial;
|
|
326
|
-
localForward;
|
|
327
|
-
socket;
|
|
328
|
-
onClose;
|
|
329
|
-
chunks;
|
|
330
322
|
constructor(adbPath, serial, localForward, socket, onClose = () => {
|
|
331
323
|
}) {
|
|
332
324
|
this.adbPath = adbPath;
|
|
@@ -336,6 +328,12 @@ var ForwardedAdbSocket = class {
|
|
|
336
328
|
this.onClose = onClose;
|
|
337
329
|
this.chunks = socket;
|
|
338
330
|
}
|
|
331
|
+
adbPath;
|
|
332
|
+
serial;
|
|
333
|
+
localForward;
|
|
334
|
+
socket;
|
|
335
|
+
onClose;
|
|
336
|
+
chunks;
|
|
339
337
|
async write(chunk) {
|
|
340
338
|
await new Promise((resolve, reject) => {
|
|
341
339
|
this.socket.write(chunk, (error51) => {
|
|
@@ -363,7 +361,7 @@ var ForwardedAdbSocket = class {
|
|
|
363
361
|
}
|
|
364
362
|
};
|
|
365
363
|
|
|
366
|
-
// ../../packages/shared/
|
|
364
|
+
// ../../packages/shared/src/index.ts
|
|
367
365
|
var AppError = class extends Error {
|
|
368
366
|
code;
|
|
369
367
|
constructor(code, message) {
|
|
@@ -14893,7 +14891,7 @@ function date4(params) {
|
|
|
14893
14891
|
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/external.js
|
|
14894
14892
|
config(en_default());
|
|
14895
14893
|
|
|
14896
|
-
// ../../packages/config/
|
|
14894
|
+
// ../../packages/config/src/schema.ts
|
|
14897
14895
|
var defaultAgentConfig = {
|
|
14898
14896
|
authToken: void 0,
|
|
14899
14897
|
bindHost: "127.0.0.1",
|
|
@@ -14916,7 +14914,9 @@ function validateAgentConfig(input) {
|
|
|
14916
14914
|
return err(new ConfigError("CONFIG_INVALID", parsed.error.message));
|
|
14917
14915
|
}
|
|
14918
14916
|
if (!isLocalBind(parsed.data.bindHost) && !parsed.data.authToken) {
|
|
14919
|
-
return err(
|
|
14917
|
+
return err(
|
|
14918
|
+
new ConfigError("CONFIG_UNSAFE_BIND", "Non-local bind addresses require authToken.")
|
|
14919
|
+
);
|
|
14920
14920
|
}
|
|
14921
14921
|
return ok(parsed.data);
|
|
14922
14922
|
}
|
|
@@ -15148,33 +15148,26 @@ async function collectTextUntil(chunks, expected) {
|
|
|
15148
15148
|
// src/server/create-fastify-app.ts
|
|
15149
15149
|
import websocket from "@fastify/websocket";
|
|
15150
15150
|
|
|
15151
|
-
// ../../packages/protocol/
|
|
15152
|
-
var StreamId
|
|
15153
|
-
(function(StreamId2) {
|
|
15151
|
+
// ../../packages/protocol/src/streams.ts
|
|
15152
|
+
var StreamId = /* @__PURE__ */ ((StreamId2) => {
|
|
15154
15153
|
StreamId2[StreamId2["Session"] = 1] = "Session";
|
|
15155
15154
|
StreamId2[StreamId2["Device"] = 2] = "Device";
|
|
15156
15155
|
StreamId2[StreamId2["Video"] = 3] = "Video";
|
|
15157
15156
|
StreamId2[StreamId2["Control"] = 4] = "Control";
|
|
15158
15157
|
StreamId2[StreamId2["Log"] = 5] = "Log";
|
|
15159
|
-
|
|
15160
|
-
|
|
15158
|
+
return StreamId2;
|
|
15159
|
+
})(StreamId || {});
|
|
15160
|
+
var knownStreams = new Set(
|
|
15161
|
+
Object.values(StreamId).filter((value) => typeof value === "number")
|
|
15162
|
+
);
|
|
15161
15163
|
|
|
15162
|
-
// ../../packages/protocol/
|
|
15164
|
+
// ../../packages/protocol/src/frame.ts
|
|
15163
15165
|
var FRAME_MAGIC = 1146573635;
|
|
15164
15166
|
var FRAME_HEADER_LENGTH = 40;
|
|
15165
15167
|
var WIRE_VERSION = 1;
|
|
15166
15168
|
var DEFAULT_MAX_PAYLOAD_LENGTH = 16 * 1024 * 1024;
|
|
15167
15169
|
|
|
15168
|
-
// ../../packages/protocol/
|
|
15169
|
-
var ProtocolErrorCode;
|
|
15170
|
-
(function(ProtocolErrorCode2) {
|
|
15171
|
-
ProtocolErrorCode2["FrameTooShort"] = "FRAME_TOO_SHORT";
|
|
15172
|
-
ProtocolErrorCode2["InvalidMagic"] = "INVALID_MAGIC";
|
|
15173
|
-
ProtocolErrorCode2["UnsupportedVersion"] = "UNSUPPORTED_VERSION";
|
|
15174
|
-
ProtocolErrorCode2["UnsupportedHeaderLength"] = "UNSUPPORTED_HEADER_LENGTH";
|
|
15175
|
-
ProtocolErrorCode2["PayloadLengthMismatch"] = "PAYLOAD_LENGTH_MISMATCH";
|
|
15176
|
-
ProtocolErrorCode2["PayloadTooLarge"] = "PAYLOAD_TOO_LARGE";
|
|
15177
|
-
})(ProtocolErrorCode || (ProtocolErrorCode = {}));
|
|
15170
|
+
// ../../packages/protocol/src/errors.ts
|
|
15178
15171
|
var ProtocolError = class extends Error {
|
|
15179
15172
|
code;
|
|
15180
15173
|
constructor(code, message) {
|
|
@@ -15184,7 +15177,7 @@ var ProtocolError = class extends Error {
|
|
|
15184
15177
|
}
|
|
15185
15178
|
};
|
|
15186
15179
|
|
|
15187
|
-
// ../../packages/protocol/
|
|
15180
|
+
// ../../packages/protocol/src/codec.ts
|
|
15188
15181
|
function encodeFrame(frame) {
|
|
15189
15182
|
const payloadLength = frame.payload.byteLength;
|
|
15190
15183
|
const output = new Uint8Array(FRAME_HEADER_LENGTH + payloadLength);
|
|
@@ -15205,28 +15198,37 @@ function encodeFrame(frame) {
|
|
|
15205
15198
|
function decodeFrame(bytes, options = {}) {
|
|
15206
15199
|
const maxPayloadLength = options.maxPayloadLength ?? DEFAULT_MAX_PAYLOAD_LENGTH;
|
|
15207
15200
|
if (bytes.byteLength < FRAME_HEADER_LENGTH) {
|
|
15208
|
-
return failure(
|
|
15201
|
+
return failure("FRAME_TOO_SHORT" /* FrameTooShort */, "Frame is shorter than the protocol header.");
|
|
15209
15202
|
}
|
|
15210
15203
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
15211
15204
|
const magic = view.getUint32(0, false);
|
|
15212
15205
|
if (magic !== FRAME_MAGIC) {
|
|
15213
|
-
return failure(
|
|
15206
|
+
return failure("INVALID_MAGIC" /* InvalidMagic */, "Frame magic does not match DWSC.");
|
|
15214
15207
|
}
|
|
15215
15208
|
const version2 = view.getUint16(4, false);
|
|
15216
15209
|
if (version2 !== WIRE_VERSION) {
|
|
15217
|
-
return failure(
|
|
15210
|
+
return failure("UNSUPPORTED_VERSION" /* UnsupportedVersion */, `Unsupported wire version: ${version2}.`);
|
|
15218
15211
|
}
|
|
15219
15212
|
const headerLength = view.getUint16(6, false);
|
|
15220
15213
|
if (headerLength !== FRAME_HEADER_LENGTH) {
|
|
15221
|
-
return failure(
|
|
15214
|
+
return failure(
|
|
15215
|
+
"UNSUPPORTED_HEADER_LENGTH" /* UnsupportedHeaderLength */,
|
|
15216
|
+
`Unsupported header length: ${headerLength}.`
|
|
15217
|
+
);
|
|
15222
15218
|
}
|
|
15223
15219
|
const payloadLength = view.getUint32(16, false);
|
|
15224
15220
|
if (payloadLength > maxPayloadLength) {
|
|
15225
|
-
return failure(
|
|
15221
|
+
return failure(
|
|
15222
|
+
"PAYLOAD_TOO_LARGE" /* PayloadTooLarge */,
|
|
15223
|
+
`Payload length ${payloadLength} exceeds limit ${maxPayloadLength}.`
|
|
15224
|
+
);
|
|
15226
15225
|
}
|
|
15227
15226
|
const expectedLength = FRAME_HEADER_LENGTH + payloadLength;
|
|
15228
15227
|
if (bytes.byteLength !== expectedLength) {
|
|
15229
|
-
return failure(
|
|
15228
|
+
return failure(
|
|
15229
|
+
"PAYLOAD_LENGTH_MISMATCH" /* PayloadLengthMismatch */,
|
|
15230
|
+
`Frame length ${bytes.byteLength} does not match declared length ${expectedLength}.`
|
|
15231
|
+
);
|
|
15230
15232
|
}
|
|
15231
15233
|
return {
|
|
15232
15234
|
ok: true,
|
|
@@ -15254,9 +15256,8 @@ function failure(code, message) {
|
|
|
15254
15256
|
};
|
|
15255
15257
|
}
|
|
15256
15258
|
|
|
15257
|
-
// ../../packages/protocol/
|
|
15258
|
-
var MessageType
|
|
15259
|
-
(function(MessageType2) {
|
|
15259
|
+
// ../../packages/protocol/src/messages.ts
|
|
15260
|
+
var MessageType = /* @__PURE__ */ ((MessageType2) => {
|
|
15260
15261
|
MessageType2[MessageType2["SessionHello"] = 1] = "SessionHello";
|
|
15261
15262
|
MessageType2[MessageType2["SessionHelloAck"] = 2] = "SessionHelloAck";
|
|
15262
15263
|
MessageType2[MessageType2["SessionStart"] = 3] = "SessionStart";
|
|
@@ -15273,10 +15274,13 @@ var MessageType;
|
|
|
15273
15274
|
MessageType2[MessageType2["ControlSystem"] = 772] = "ControlSystem";
|
|
15274
15275
|
MessageType2[MessageType2["ControlClipboard"] = 773] = "ControlClipboard";
|
|
15275
15276
|
MessageType2[MessageType2["LogRecord"] = 1025] = "LogRecord";
|
|
15276
|
-
|
|
15277
|
-
|
|
15277
|
+
return MessageType2;
|
|
15278
|
+
})(MessageType || {});
|
|
15279
|
+
var knownMessageTypes = new Set(
|
|
15280
|
+
Object.values(MessageType).filter((value) => typeof value === "number")
|
|
15281
|
+
);
|
|
15278
15282
|
|
|
15279
|
-
// ../../packages/transport/
|
|
15283
|
+
// ../../packages/transport/src/stream.ts
|
|
15280
15284
|
var DEFAULT_MAX_BUFFERED_BYTES = 16 * 1024 * 1024;
|
|
15281
15285
|
var FrameAssembler = class {
|
|
15282
15286
|
buffer = new Uint8Array();
|
|
@@ -15345,7 +15349,7 @@ function readPayloadLength(bytes) {
|
|
|
15345
15349
|
return view.getUint32(16, false);
|
|
15346
15350
|
}
|
|
15347
15351
|
|
|
15348
|
-
// ../../packages/transport/
|
|
15352
|
+
// ../../packages/transport/src/backpressure.ts
|
|
15349
15353
|
var VIDEO_KEYFRAME_FLAG = 1 << 0;
|
|
15350
15354
|
|
|
15351
15355
|
// src/server/create-fastify-app.ts
|