chromeflow 0.1.47 → 0.1.49
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/ws-bridge.js +16 -14
- package/package.json +1 -1
package/dist/ws-bridge.js
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
|
-
import { execSync } from "child_process";
|
|
2
1
|
import { WebSocketServer, WebSocket } from "ws";
|
|
3
|
-
const
|
|
2
|
+
const WS_PORT_BASE = 7878;
|
|
3
|
+
const WS_PORT_MAX = 7888;
|
|
4
4
|
const REQUEST_TIMEOUT_MS = 3e4;
|
|
5
5
|
class WsBridge {
|
|
6
6
|
wss;
|
|
7
7
|
client = null;
|
|
8
8
|
pending = /* @__PURE__ */ new Map();
|
|
9
|
+
port = WS_PORT_BASE;
|
|
9
10
|
constructor() {
|
|
10
|
-
this.bind();
|
|
11
|
+
this.bind(WS_PORT_BASE);
|
|
11
12
|
}
|
|
12
|
-
bind() {
|
|
13
|
-
|
|
13
|
+
bind(tryPort) {
|
|
14
|
+
if (tryPort > WS_PORT_MAX) {
|
|
15
|
+
console.error(
|
|
16
|
+
`[chromeflow] All ports ${WS_PORT_BASE}-${WS_PORT_MAX} are in use. Cannot start MCP server.`
|
|
17
|
+
);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const wss = new WebSocketServer({ port: tryPort });
|
|
14
21
|
wss.on("error", (err) => {
|
|
15
22
|
if (err.code === "EADDRINUSE") {
|
|
16
|
-
console.error(
|
|
17
|
-
|
|
18
|
-
);
|
|
19
|
-
try {
|
|
20
|
-
execSync(`lsof -ti:${WS_PORT} | xargs kill -9`, { stdio: "ignore" });
|
|
21
|
-
} catch {
|
|
22
|
-
}
|
|
23
|
-
setTimeout(() => this.bind(), 800);
|
|
23
|
+
console.error(`[chromeflow] Port ${tryPort} in use, trying ${tryPort + 1}...`);
|
|
24
|
+
this.bind(tryPort + 1);
|
|
24
25
|
} else {
|
|
25
26
|
console.error("[chromeflow] WS server error:", err);
|
|
26
27
|
}
|
|
27
28
|
});
|
|
28
29
|
wss.on("listening", () => {
|
|
29
30
|
this.wss = wss;
|
|
30
|
-
|
|
31
|
+
this.port = tryPort;
|
|
32
|
+
console.error(`[chromeflow] WS bridge listening on ws://localhost:${tryPort}`);
|
|
31
33
|
});
|
|
32
34
|
wss.on("connection", (ws) => {
|
|
33
35
|
if (this.client) {
|
package/package.json
CHANGED