Incoming WebSocket data

This WebSocket API recognizes clicks. Send some "click" messages to the server.

You can also send a message that our API doesn't recognize.

Here's how it handles incoming requests.


// server.js
websocket.addEventListener("message", ({ data }) => {
  if (data === "CLICK") {
    return websocket.send(JSON.stringify({ 
      data, 
      count: count + 1, 
      tz: new Date() 
    }))
  }

  websocket.send(JSON.stringify({ 
    data, 
    error: "Unknown message received", 
    tz: new Date() 
  }))
})

When you're done clicking, you can close the connection below. Further clicks won't work until you reconnect.