ScuttleBot

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

Keyboard Shortcuts

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