~kylep/pipes

e0f71e1aa2f0f46a5f9daf2009b80582391b641b — Kyle Perik 2 months ago 0c0f01c
Add send button
2 files changed, 17 insertions(+), 12 deletions(-)

M src/device.js
M src/index.html
M src/device.js => src/device.js +16 -11
@@ 39,23 39,28 @@ function initDevices () {
  }
  requestAnimationFrame(frame)
  const input = document.getElementById('input')
  const sendButton = document.getElementById('send-button')
  input.focus()
  const output = document.getElementById('output')
  function sendInput () {
    try {
      value = JSON.parse(input.value)
    } catch {
      value = input.value
    }
    logOutput(`> ${JSON.stringify(value)}`)
    processEvent([
      'input',
      value
    ])
    input.value = ''
  }
  input.addEventListener('keypress', e => {
    if (e.key === 'Enter') {
      try {
        value = JSON.parse(input.value)
      } catch {
        value = input.value
      }
      logOutput(`> ${JSON.stringify(value)}`)
      processEvent([
        'input',
        value
      ])
      input.value = ''
      sendInput()
    }
  })
  sendButton.addEventListener('click', sendInput)
  ctx = canvas.getContext("2d")
  processEvent(['init', null])
}

M src/index.html => src/index.html +1 -1
@@ 13,7 13,7 @@
            <canvas id="canvas" width="500" height="500">
            </canvas>
        </div>
        <input id="input" />
        <input id="input" /><input value="send" type="button" id="send-button" />
        <div style="white-space: pre;" id="output"></div>
    </body>
</html>