PeerJS growing CPU usage on connection to new peer

140 views
Skip to first unread message

Jeffrey Gordon

unread,
Jan 26, 2016, 11:13:33 PM1/26/16
to PeerJS
PeerJS is wonderful.  I'm working on a piece of Free, Open Source educational software, utilizing Firebase to share the peerID's.  Sending the data between peers will allow me to scale the software, and therefore serve many more users.  

I have a repeating timeout function that watches an array called activePeers and connects to each of them to send data.  PeerJS is behaving normally, but when a peerID is removed from the array, and replaced with a new one, CPU usage grows slightly.  Each time a new peer is acquired, CPU usage continues to grow.  

This pared down version of the function is still causing the problem, but I can't understand why:
var peer = new Peer({
          host: 'server-name-10056.herokuapp.com',
          port: 80,
          path: '/'
        });

        peer.on('open', function(id) {
          setData();
        });

        function setData() {
          setTimeout(setData, 5000);
          activePeers.forEach(function(peerID) {
            console.log(peerID)
            if (peerID != null) {
              var conn = peer.connect(peerID);
              conn.on('open', function() {
                console.log("open")
                conn.close();
              });

            }
          });
        }
Reply all
Reply to author
Forward
0 new messages