Advertisement
kator

Untitled

Mar 14th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var connNo = 0;
  3. var sum = 0;
  4. var ports = [];
  5. var portNo = 0;
  6. onconnect = function(e) {
  7.   connNo += 1;
  8.     var port = e.ports[0];
  9.     ports[portNo] = port;
  10.     portNo++;
  11.     for(i=0; i<portNo; i++)
  12.     ports[i].postMessage('Connection #' + connNo);
  13.   //port.postMessage('Connection #' + connNo);
  14.   port.onmessage = function(e) {
  15.         sum += parseInt(e.data);
  16.         for(i=0;i<portNo;i++){
  17.             ports[i].postMessage(sum);
  18.         }
  19.   }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement