<html>
    <head>
    </head>
    <body>
        Server Port <input id="port" type="text" value="8989"></input> <button onclick="connect()">Connect</button><br>
        <div id="socketState"></div>
        <div id="mouseInfo"></div>
        <div id="keyInfo"></div>
        <br>
        <div id="frame" style="border: 2px solid; height:300"></div>
        <script>
            let portInput = document.getElementById("port")
            let mouseInfo = document.getElementById("mouseInfo")
            let ketInfo = document.getElementById("keyInfo")
            let frame = document.getElementById("frame")
            let socketState = document.getElementById("socketState")
            let socket

            frame.addEventListener('mousemove', onMouseMove)
            document.addEventListener('keydown', onKeyDown)
            document.addEventListener('keyup', onKeyUp)

            function connect() {
                socket = new WebSocket(`ws://localhost:${portInput.value}`);
                socket.onopen = _ => {
                    socketState.innerText = 'OPEN'
                }
                socket.onclose = _ => {
                    socketState.innerText = 'CLOSED'
                }
                socket.onerror = (error) => {
                    socketState.innerText = 'ERROR'
                    console.log(`ERROR: ${error}`)
                }
            }

            function send(message) {
                if (socket && socket.readyState == WebSocket.OPEN) {
                    socket.send(JSON.stringify(message))
                }
            }
            function onMouseMove(event) {
                //console.log(event.clientX, event.clientY)
                mouseInfo.innerText = `MOUSE: x=${event.clientX}, y=${event.clientY}`
                send({ type:'mousemove', x: event.clientX, y: event.clientY })
            }

            function onKeyDown(event) {
                //console.log(event)
                keyInfo.innerText = `KEYDOWN: ${event.key}`
                send({ type:'keydown', key: event.key })
            }

            function onKeyUp(event) {
                //console.log(event)
                keyInfo.innerText = `KEYUP: ${event.key}`
                send({ type:'keyup', key: event.key })
            }
        </script>
    </body>
</html>
