INNER CODE UNIT · JavaScript

writeValue

sebastiancarlos/beachpatrol · beachpatrol.js:167

  const writeValue = (value) => {
    // Write value to socket
    let output = typeof value === "string" ? value : JSON.stringify(value);
    if (!output.endsWith("\n")) output += "\n";
    socket.write(output);
  };
  const writeError = (message) => {
    // Log error to server console and to socket (with sentinel line)
    console.log(`Error: ${message}`);
    socket.write(`${ERROR_SENTINEL} ${message.replace(/\n/g, " ")}\n`);
    socket.end();
  };

  socket.on("data", async (data) => {
    const message = JSON.parse(data.toString());
    const [commandName, ...args] = message;

    // Sanitize commandName

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…