PeerJS error while trying to broadcast

I am trying to make a broadcast function in PeerJS by specifying all peers and sending each message. My client code is below:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Test</title> <script src="http://cdn.peerjs.com/0.3/peer.js"></script> <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script> <script type="text/javascript"> const peer = new Peer({host: '127.0.0.1', port: 4982, path: '/', debug: 2}); peer.on('open', function(id) { document.getElementById('peerId').innerHTML = id; }); peer.on('connection', function(conn) { conn.on('data', function(data) { console.log(data); }); }); function bcast(message, id) { peer.listAllPeers(function(peers) { console.log(peers); // remove self from peer list peers.splice(peers.indexOf(id), 1); if (peers.length > 0) { peers.forEach(function(e, i) { let conn = peer.connect(e); conn.on('open', function() { conn.send(message); }); }); return true; } return false; }); } </script> </head> <body> Peer ID: <p id="peerId"></p> <button type="button" onclick="bcast('hello', id)">Broadcast Hello Message</button> </body> </html> 

My alarm server code is below:

 var PeerServer = require('peer').PeerServer; var server = PeerServer({port: 4982, path: '/', allow_discovery: true}); 

To test it, I started the server and opened two browser tabs, tab 1 and tab 2. Then I click the broadcast welcome button on tab 1. I expect that β€œhello” will be registered on tab 2, instead this error:

 PeerJS: WARNING Offer received for existing Connection ID: dc_eyxb5yz4k4eonyb4d0f3whfr undefined:1 Uncaught (in promise) DOMException: Error processing ICE candidate undefined:1 Uncaught (in promise) DOMException: Error processing ICE candidate undefined:1 Uncaught (in promise) DOMException: Error processing ICE candidate 

Oddly enough, without rebooting, nothing, if I press the broadcast button on tab 2 , it will launch it on tab 1 . I am new to WebRTC, so any help is greatly appreciated.

+5
source share

All Articles