window.addEventListener('load', () => {
  let pushedbox = document.getElementById('pushedteam');
  let ws = new WebSocket('ws://' + window.location.host + '/websocket');

  ws.onopen = () => console.log('connection opened');
  ws.onclose = () => console.log('connection closed');
  ws.onmessage = m => {
    if (m.data=="Delete!") {
      while (pushedbox.firstChild) pushedbox.removeChild(pushedbox.firstChild);
    } else {
      let li = document.createElement('li');
      li.textContent = m.data;
      pushedbox.append(li);
      document.getElementById("hayaoshi").pause();
      document.getElementById("hayaoshi").play();
      playFlag = false;
      audioObj.pause();
      pButton.innerHTML = 'PLAY';
    };
  };

  var resetButton = document.getElementById('reset');

  resetButton.addEventListener('click', function(){
    while (pushedbox.firstChild) pushedbox.removeChild(pushedbox.firstChild);
    ws.send("Delete!");
  });

});
