title: How to stop a function sending data to websocket and switch to another alternately with button click
body: <p>I feed data to websocket and send it to a server with the method below:</p>
  
  <pre><code>function sendData(source, images) {
      var data = {
              data_source: this.source,
              img: this.images
          };
      var Data = JSON.stringify({ type:'image', data: data });
      socket.send(Data);
  }
  
  function source1() {
      var source = camera1;
      var images = feed1;
      sendData(this.source, this.images);
  }
  
  function source2() {
      var source = camera2;
      var images = feed2;
      sendData(this.source, this.images);
  }
  
  button1.addEventListener('click', source1, false);
  button2.addEventListener('click', source2, false);
  </code></pre>
  
  <p>How do I stop source1 feeding when I click on a button 2 and switch click alternately.</p>
  
  <p>In my current practice when I click on a button 2 function source1 is still running. It causes the image rendered on the other end flipping (maybe not the right word, my English is not good) between two image sources. And worst, when I switching clicks between two buttons for a few times it crashed completely.</p>
  
  <p>How do I solve this problem?</p>
  
  <p>Thank you,</p>