MCPcopy Create free account
hub / github.com/gnmyt/Nexterm / createMessageHandler

Method createMessageHandler

server/lib/ScriptLayer.js:127–146  ·  view source on GitHub ↗
(ws)

Source from the content-addressed store, hash-verified

125 }
126
127 createMessageHandler(ws) {
128 const handler = (msg) => {
129 const str = msg.toString();
130 if (!str.startsWith(SCRIPT_MAGIC)) return;
131 try {
132 const data = JSON.parse(str.slice(1));
133 if (data.type === MSG.INPUT_RESPONSE && this.pending) {
134 this.stream.write((data.value || this.pending.default || "") + "\n");
135 this.pending = null;
136 } else if (data.type === MSG.INPUT_CANCELLED) {
137 this.stream.write("\x03");
138 this.pending = null;
139 }
140 } catch (e) {}
141 };
142 ws.on("message", handler);
143 this.handlers.add({ ws, handler });
144 this.replayEvents(ws);
145 return handler;
146 }
147
148 removeMessageHandler(ws) {
149 for (const entry of this.handlers) {

Callers 1

handleSessionFunction · 0.80

Calls 1

replayEventsMethod · 0.95

Tested by

no test coverage detected