@portlens/cli 1.0.10 → 1.0.12
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/dist/index.js +82 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -73215,6 +73215,8 @@ var Agent = class extends EventEmitter4 {
|
|
|
73215
73215
|
screenshotDone = false;
|
|
73216
73216
|
/** Timestamp of the last agent-initiated ping; null when no ping is in-flight. */
|
|
73217
73217
|
pingTimestamp = null;
|
|
73218
|
+
/** Local WebSocket connections opened on behalf of proxied browser connections. */
|
|
73219
|
+
wsConnections = /* @__PURE__ */ new Map();
|
|
73218
73220
|
reconnectionManager = new ReconnectionManager();
|
|
73219
73221
|
token;
|
|
73220
73222
|
connect() {
|
|
@@ -73225,6 +73227,13 @@ var Agent = class extends EventEmitter4 {
|
|
|
73225
73227
|
close() {
|
|
73226
73228
|
this.closing = true;
|
|
73227
73229
|
this._stopPing();
|
|
73230
|
+
for (const ws of this.wsConnections.values()) {
|
|
73231
|
+
try {
|
|
73232
|
+
ws.close(1001, "Tunnel closing");
|
|
73233
|
+
} catch {
|
|
73234
|
+
}
|
|
73235
|
+
}
|
|
73236
|
+
this.wsConnections.clear();
|
|
73228
73237
|
if (this.ws) {
|
|
73229
73238
|
this.ws.removeAllListeners();
|
|
73230
73239
|
this.ws.close();
|
|
@@ -73315,6 +73324,29 @@ var Agent = class extends EventEmitter4 {
|
|
|
73315
73324
|
this._forwardRequest(msg);
|
|
73316
73325
|
return;
|
|
73317
73326
|
}
|
|
73327
|
+
if (msg.type === "ws-connect") {
|
|
73328
|
+
this._openLocalWs(msg.wsId, msg.path);
|
|
73329
|
+
return;
|
|
73330
|
+
}
|
|
73331
|
+
if (msg.type === "ws-message") {
|
|
73332
|
+
const localWs = this.wsConnections.get(msg.wsId);
|
|
73333
|
+
if (localWs?.readyState === import_ws2.default.OPEN) {
|
|
73334
|
+
const payload = msg.binary ? Buffer.from(msg.data, "base64") : msg.data;
|
|
73335
|
+
localWs.send(payload);
|
|
73336
|
+
}
|
|
73337
|
+
return;
|
|
73338
|
+
}
|
|
73339
|
+
if (msg.type === "ws-close") {
|
|
73340
|
+
const localWs = this.wsConnections.get(msg.wsId);
|
|
73341
|
+
if (localWs) {
|
|
73342
|
+
try {
|
|
73343
|
+
localWs.close(msg.code ?? 1e3, msg.reason ?? "");
|
|
73344
|
+
} catch {
|
|
73345
|
+
}
|
|
73346
|
+
this.wsConnections.delete(msg.wsId);
|
|
73347
|
+
}
|
|
73348
|
+
return;
|
|
73349
|
+
}
|
|
73318
73350
|
if (msg.type === "error") {
|
|
73319
73351
|
console.error(import_chalk2.default.red(`
|
|
73320
73352
|
Relay error [${msg.code}]: ${msg.message}`));
|
|
@@ -73374,6 +73406,55 @@ var Agent = class extends EventEmitter4 {
|
|
|
73374
73406
|
req.write(reqBody);
|
|
73375
73407
|
req.end();
|
|
73376
73408
|
}
|
|
73409
|
+
// ── Local WebSocket proxy ─────────────────────────────────────────────────
|
|
73410
|
+
_openLocalWs(wsId, path15) {
|
|
73411
|
+
const url = `ws://localhost:${this.port}${path15}`;
|
|
73412
|
+
let localWs;
|
|
73413
|
+
try {
|
|
73414
|
+
localWs = new import_ws2.default(url);
|
|
73415
|
+
} catch (err) {
|
|
73416
|
+
this.ws?.send(JSON.stringify({
|
|
73417
|
+
type: "ws-error",
|
|
73418
|
+
wsId,
|
|
73419
|
+
message: err instanceof Error ? err.message : String(err)
|
|
73420
|
+
}));
|
|
73421
|
+
return;
|
|
73422
|
+
}
|
|
73423
|
+
localWs.on("open", () => {
|
|
73424
|
+
this.wsConnections.set(wsId, localWs);
|
|
73425
|
+
});
|
|
73426
|
+
localWs.on("message", (data, isBinary) => {
|
|
73427
|
+
if (this.ws?.readyState !== import_ws2.default.OPEN)
|
|
73428
|
+
return;
|
|
73429
|
+
this.ws.send(JSON.stringify({
|
|
73430
|
+
type: "ws-message",
|
|
73431
|
+
wsId,
|
|
73432
|
+
data: isBinary ? Buffer.from(data).toString("base64") : data.toString(),
|
|
73433
|
+
binary: isBinary
|
|
73434
|
+
}));
|
|
73435
|
+
});
|
|
73436
|
+
localWs.on("close", (code, reason) => {
|
|
73437
|
+
this.wsConnections.delete(wsId);
|
|
73438
|
+
if (this.ws?.readyState === import_ws2.default.OPEN) {
|
|
73439
|
+
this.ws.send(JSON.stringify({
|
|
73440
|
+
type: "ws-close",
|
|
73441
|
+
wsId,
|
|
73442
|
+
code,
|
|
73443
|
+
reason: reason.toString()
|
|
73444
|
+
}));
|
|
73445
|
+
}
|
|
73446
|
+
});
|
|
73447
|
+
localWs.on("error", (err) => {
|
|
73448
|
+
this.wsConnections.delete(wsId);
|
|
73449
|
+
if (this.ws?.readyState === import_ws2.default.OPEN) {
|
|
73450
|
+
this.ws.send(JSON.stringify({
|
|
73451
|
+
type: "ws-error",
|
|
73452
|
+
wsId,
|
|
73453
|
+
message: err.message
|
|
73454
|
+
}));
|
|
73455
|
+
}
|
|
73456
|
+
});
|
|
73457
|
+
}
|
|
73377
73458
|
// ── Screenshot capture ────────────────────────────────────────────────────
|
|
73378
73459
|
/** Convert the relay WebSocket URL to its HTTP equivalent. */
|
|
73379
73460
|
_relayHttp() {
|
|
@@ -73842,7 +73923,7 @@ program.argument("<port>", "Local port to tunnel", (v2) => {
|
|
|
73842
73923
|
let reconnectInfo;
|
|
73843
73924
|
let boxVisible = false;
|
|
73844
73925
|
let refreshTimer = null;
|
|
73845
|
-
let shareUrl = `${VIEWER_BASE}/${agent.token}`;
|
|
73926
|
+
let shareUrl = `${VIEWER_BASE}/v/${agent.token}`;
|
|
73846
73927
|
function boxOpts() {
|
|
73847
73928
|
return { shareUrl, localPort: port, expiresAt, status: currentStatus, rtt: currentRtt, reconnectInfo };
|
|
73848
73929
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portlens/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "Share your local server with anyone, instantly.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"prepublishOnly": "npm run build"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@portlens/shared": "^1.0.1",
|
|
21
22
|
"chalk": "^4.1.2",
|
|
22
23
|
"commander": "^8.3.0",
|
|
23
24
|
"dotenv": "^10.0.0",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@types/qrcode-terminal": "^0.12.2",
|
|
32
33
|
"@types/ws": "^8.18.1",
|
|
33
|
-
"esbuild": "^0.
|
|
34
|
+
"esbuild": "^0.25.12",
|
|
34
35
|
"ts-node": "^10.9.2",
|
|
35
36
|
"typescript": "*"
|
|
36
37
|
}
|