index.js 646 B

12345678910111213141516171819
  1. let socket = io()
  2. let ourId;
  3. socket.on('gamers', gamers => {
  4. gamersUL.innerHTML = '';
  5. for (let [id,gamer] of Object.entries(gamers)){
  6. let el = document.createElement('li')
  7. el.innerHTML = gamer.ready && id != ourId ? `<button>${gamer.nick}</button>` : gamer.nick;
  8. el.children[0] && (el.children[0].onclick = () => socket.emit('start', {with: id}))
  9. gamersUL.appendChild(el)
  10. }
  11. })
  12. socket.on('id', i => ourId = i)
  13. socket.on('hand', handData => console.log(handData))
  14. const sendUpdate = ()=> socket.emit('hi', {nick: nick.value, ready: ready.checked})
  15. hi.onclick = sendUpdate
  16. ready.onchange = sendUpdate