var socket = io(); socket.on('connect', function () { console.log(socket.id); }); function getNickname() { var nickname = document.getElementById('nickname').value; console.log(nickname); socket.emit('nickname', nickname); } document.addEventListener("DOMContentLoaded", function () { var mouse = { click: false, move: false, pos: { x: 0, y: 0 }, }; var canvas = document.getElementById('tracking'); var width = window.innerWidth; var height = window.innerHeight; console.log("gg", height, width); //Canvas Size canvas.width = width; canvas.height = height; canvas.onmousemove = function (e) { mouse.pos.x = e.clientX / width; mouse.pos.y = e.clientY / height; }; function mainLoop() { socket.emit('cursor_pos', { pos: mouse.pos, id: socket.id }); setTimeout(mainLoop, 25); } socket.on('cursor_draw', function (data) { var mouse_el = CursorElement(data.id); mouse_el.style.left = (data.pos.x * width); mouse_el.style.top = (data.pos.y * height); }); socket.on('nickname_set', function (data) { console.log(data.name, data.id); var elementId = 'cursor-' + data.id; var el_nick = document.getElementById(elementId); el_nick.innerHTML = "