oc-phone-link 2.4.2 → 2.4.3
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 +2 -0
- package/beacon.mjs +20 -5
- package/index.js +7 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,8 @@ are attributed to the app repository's own changelog
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
## [2.4.3] - 2026-11-30
|
|
13
|
+
|
|
12
14
|
Ships with the 2.4.0 app. The app and beacon must be upgraded together.
|
|
13
15
|
|
|
14
16
|
- Upgrading a state written by 2.2.0/2.3.x: a v5 PIN record with no recorded
|
package/beacon.mjs
CHANGED
|
@@ -922,7 +922,11 @@ function proxy(req, res) {
|
|
|
922
922
|
req.pipe(upstream);
|
|
923
923
|
}
|
|
924
924
|
|
|
925
|
-
function upgradeProxy(req, clientSocket, head) {
|
|
925
|
+
function upgradeProxy(req, clientSocket, head, sockets) {
|
|
926
|
+
if (sockets) {
|
|
927
|
+
sockets.add(clientSocket);
|
|
928
|
+
clientSocket.once("close", () => sockets.delete(clientSocket));
|
|
929
|
+
}
|
|
926
930
|
let why = "pin";
|
|
927
931
|
try { why = gate(req); } catch (e) { why = "pin"; }
|
|
928
932
|
if (why) {
|
|
@@ -943,6 +947,10 @@ function upgradeProxy(req, clientSocket, head) {
|
|
|
943
947
|
return k + ": " + v + "\r\n";
|
|
944
948
|
}).join("");
|
|
945
949
|
const upstream = connect({ host: "127.0.0.1", port: port() });
|
|
950
|
+
if (sockets) {
|
|
951
|
+
sockets.add(upstream);
|
|
952
|
+
upstream.once("close", () => sockets.delete(upstream));
|
|
953
|
+
}
|
|
946
954
|
let replied = false;
|
|
947
955
|
upstream.on("connect", () => {
|
|
948
956
|
try {
|
|
@@ -1370,10 +1378,11 @@ export function startBeacon(opts) {
|
|
|
1370
1378
|
const proxyServer = createHttpsServer({ key: tls.key, cert: tls.cert }, (req, res) => proxy(req, res));
|
|
1371
1379
|
proxyServer.requestTimeout = 0;
|
|
1372
1380
|
proxyServer.headersTimeout = 60000;
|
|
1373
|
-
proxyServer.on("upgrade", (req, socket, head) => upgradeProxy(req, socket, head));
|
|
1381
|
+
proxyServer.on("upgrade", (req, socket, head) => upgradeProxy(req, socket, head, upgradeSockets));
|
|
1374
1382
|
const loopback = createHttpServer((req, res) => { handleLoopback(req, res); });
|
|
1375
1383
|
|
|
1376
1384
|
const servers = [];
|
|
1385
|
+
const upgradeSockets = new Set();
|
|
1377
1386
|
const retryTimers = new Set();
|
|
1378
1387
|
let stopping = false;
|
|
1379
1388
|
const listen = (srv, portNum, host, tag) => {
|
|
@@ -1381,7 +1390,7 @@ export function startBeacon(opts) {
|
|
|
1381
1390
|
let retry = null;
|
|
1382
1391
|
let tracked = false;
|
|
1383
1392
|
srv.on("listening", () => {
|
|
1384
|
-
if (stopping) { try { srv.close(); } catch {} return; }
|
|
1393
|
+
if (stopping) { try { srv.closeAllConnections(); } catch {} try { srv.close(); } catch {} return; }
|
|
1385
1394
|
wait = 2000;
|
|
1386
1395
|
if (!tracked) { tracked = true; servers.push(srv); }
|
|
1387
1396
|
log(tag + " listening", portNum);
|
|
@@ -1417,7 +1426,7 @@ export function startBeacon(opts) {
|
|
|
1417
1426
|
const exposed = createHttpServer((req, res) => { handleAgent(req, res, { exposed: true }); });
|
|
1418
1427
|
let exposedTracked = false;
|
|
1419
1428
|
exposed.on("listening", () => {
|
|
1420
|
-
if (stopping) { try { exposed.close(); } catch {} return; }
|
|
1429
|
+
if (stopping) { try { exposed.closeAllConnections(); } catch {} try { exposed.close(); } catch {} return; }
|
|
1421
1430
|
if (!exposedTracked) { exposedTracked = true; servers.push(exposed); }
|
|
1422
1431
|
});
|
|
1423
1432
|
exposed.on("error", (e) => log("exposed listener unavailable", e.code || e.message));
|
|
@@ -1446,7 +1455,13 @@ export function startBeacon(opts) {
|
|
|
1446
1455
|
clearInterval(announce);
|
|
1447
1456
|
clearInterval(aliveTimer);
|
|
1448
1457
|
try { if (udp) udp.close(); } catch {}
|
|
1449
|
-
for (const
|
|
1458
|
+
for (const sock of upgradeSockets) { try { sock.destroy(); } catch {} }
|
|
1459
|
+
upgradeSockets.clear();
|
|
1460
|
+
try { agent.destroy(); } catch {}
|
|
1461
|
+
for (const srv of servers) {
|
|
1462
|
+
try { srv.closeAllConnections(); } catch {}
|
|
1463
|
+
try { srv.close(); } catch {}
|
|
1464
|
+
}
|
|
1450
1465
|
if (globalThis[Symbol.for("oc-phone-link.beacon")] === stop) globalThis[Symbol.for("oc-phone-link.beacon")] = null;
|
|
1451
1466
|
log("beacon stopped");
|
|
1452
1467
|
};
|
package/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Plugin } from "@opencode/plugin";
|
|
2
2
|
import { startBeacon } from "./beacon.mjs";
|
|
3
3
|
|
|
4
|
-
let stop = null;
|
|
5
|
-
|
|
6
4
|
function portFrom(ctx) {
|
|
7
5
|
const raw = ctx && (ctx.port ?? ctx.server?.port ?? ctx.server?.url);
|
|
8
6
|
if (typeof raw === "number" && Number.isFinite(raw) && raw > 0) return raw;
|
|
@@ -21,14 +19,13 @@ function portFrom(ctx) {
|
|
|
21
19
|
export default Plugin.define({
|
|
22
20
|
id: "oc-phone-link",
|
|
23
21
|
setup(ctx) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
22
|
+
let stop = null;
|
|
23
|
+
try {
|
|
24
|
+
const port = portFrom(ctx);
|
|
25
|
+
stop = startBeacon(port ? { port } : {}) || null;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.error("oc-phone-link: beacon failed to start:", e?.message || e);
|
|
28
|
+
stop = null;
|
|
32
29
|
}
|
|
33
30
|
return () => {
|
|
34
31
|
if (stop) { stop(); stop = null; }
|
package/package.json
CHANGED