ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / mcp / terminal / socketConnection.js
Blame History Raw 81 lines
1
"use strict";
2
var __defProp = Object.defineProperty;
3
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
var __getOwnPropNames = Object.getOwnPropertyNames;
5
var __hasOwnProp = Object.prototype.hasOwnProperty;
6
var __export = (target, all) => {
7
for (var name in all)
8
__defProp(target, name, { get: all[name], enumerable: true });
9
};
10
var __copyProps = (to, from, except, desc) => {
11
if (from && typeof from === "object" || typeof from === "function") {
12
for (let key of __getOwnPropNames(from))
13
if (!__hasOwnProp.call(to, key) && key !== except)
14
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
}
16
return to;
17
};
18
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
var socketConnection_exports = {};
20
__export(socketConnection_exports, {
21
SocketConnection: () => SocketConnection
22
});
23
module.exports = __toCommonJS(socketConnection_exports);
24
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
25
const daemonDebug = (0, import_utilsBundle.debug)("pw:daemon");
26
class SocketConnection {
27
constructor(socket) {
28
this._pendingBuffers = [];
29
this._socket = socket;
30
socket.on("data", (buffer) => this._onData(buffer));
31
socket.on("close", () => {
32
this.onclose?.();
33
});
34
socket.on("error", (e) => daemonDebug(`error: ${e.message}`));
35
}
36
async send(message) {
37
await new Promise((resolve, reject) => {
38
this._socket.write(`${JSON.stringify(message)}
39
`, (error) => {
40
if (error)
41
reject(error);
42
else
43
resolve(void 0);
44
});
45
});
46
}
47
close() {
48
this._socket.destroy();
49
}
50
_onData(buffer) {
51
let end = buffer.indexOf("\n");
52
if (end === -1) {
53
this._pendingBuffers.push(buffer);
54
return;
55
}
56
this._pendingBuffers.push(buffer.slice(0, end));
57
const message = Buffer.concat(this._pendingBuffers).toString();
58
this._dispatchMessage(message);
59
let start = end + 1;
60
end = buffer.indexOf("\n", start);
61
while (end !== -1) {
62
const message2 = buffer.toString(void 0, start, end);
63
this._dispatchMessage(message2);
64
start = end + 1;
65
end = buffer.indexOf("\n", start);
66
}
67
this._pendingBuffers = [buffer.slice(start)];
68
}
69
_dispatchMessage(message) {
70
try {
71
this.onmessage?.(JSON.parse(message));
72
} catch (e) {
73
daemonDebug("failed to dispatch message", e);
74
}
75
}
76
}
77
// Annotate the CommonJS export names for ESM import in node:
78
0 && (module.exports = {
79
SocketConnection
80
});
81

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button