123456789101112131415161718 |
- let socket = io()
- let ourId;
- socket.on('gamers', gamers => {
- gamersUL.innerHTML = '';
- for (let [id,gamer] of Object.entries(gamers)){
- let el = document.createElement('li')
- el.innerHTML = gamer.ready && id != ourId ? `<button>${gamer.nick}</button>` : gamer.nick;
- el.children[0] && (el.children[0].onclick = () => socket.emit('start', {with: id}))
- gamersUL.appendChild(el)
- }
- })
- socket.on('id', i => ourId = i)
- const sendUpdate = ()=> socket.emit('hi', {nick: nick.value, ready: ready.checked})
- hi.onclick = sendUpdate
- ready.onchange = sendUpdate
|