peerjs: 'RTCPeerConnection': Cannot create so many PeerConnections

Hello everyone I’m trying to create a multiplayer game in phaser. Once the game has been created i have two player. When i move my player (green) I can see the movement in a new page of my browser (not green). schermata del 2018-07-24 12-44-53 Everything works for the best. But considering that the number of movements is high, after some time you get this error: VM2455:300 Uncaught DOMException: Failed to construct 'RTCPeerConnection': Cannot create so many PeerConnections at new WrappedRTCPeerConnection (<anonymous>:300:28) at Object.m._startPeerConnection (http://localhost/SP2P/lib/peer.js:1:33131) at Object.m._getPeerConnection (http://localhost/SP2P/lib/peer.js:1:32849) at Object.m.startConnection (http://localhost/SP2P/lib/peer.js:1:32216) at new d (http://localhost/SP2P/lib/peer.js:1:2579) at p.connect (http://localhost/SP2P/lib/peer.js:1:25072) at PeerClient.conn (http://localhost/SP2P/P2P/PeerClient.js:100:27) at Object.P2PMaze.send (http://localhost/SP2P/js/GameMultiplayer.js:42:29) at P2PMaze.GameMultiplayer.update (http://localhost/SP2P/js/GameMultiplayer.js:236:21) at Phaser.StateManager.update (http://localhost/SP2P/lib/phaser.js:31183:39)

Peerjs Version: 0.3.9 Chrome version: 67.0.3396.62

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

I confirm that with the second solution I avoid the error. For this, now I have only two connection:

  • the first: from A to B
  • the second: from B to A The other exchange of data is execute with the same connection. Thank @kidandcat for your support. šŸ‘

The second solution would be much recommended. The first one will give you a lot of troubles because you are creating a lot of connections, one per message, and that will not only lead you to the first error you got from PeerJS, but it will also beat your resources (cpu, ram, network)

ok thanks for the patience, as soon as I implement the code I will post the result šŸ‘