(ws)
| 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) { |
no test coverage detected