-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'RTCPeerConnection': Cannot create so many PeerConnections #431
Comments
It seems like you are creating a lot of new connections. Could you show your code? Also it looks like you are using an old peerjs version, latest npm version is 0.3.16: |
Of course. My code is this:
I try to create a single connection. I create a global variable
and
But in this way my multiplayer doesn't work. For this I thought that the correct approch is
|
If I'm not wrong, here:
You are opening a new connection every time you want to send a message. You should save your created connection somewhere, and use it for all messages, for example, something like this:
Use the And listen for the Maybe I didn't understood your code. I think conn is peerjs, and sendData is send from connection Object? if not, please post the code of those functions too. |
|
I have tried with this solution that you suggest me but it doesn't work. |
Here you are creating a new listener, and when the event 'open' come, you send the data. You should just send the data:
The Open event is to check if the connection has been established. You can check for it, or you can just send the data and let it fail if the connection is not still open. The 'open' event is send once after you open a connection, that's why it is working to you only with multiple conections. Because the second time you want to send data, you will wait indefinitely for the 'open' event, that as I said, it is emitted only one time when the connection is established. So apply that change I proposed, and create the connection only once. |
ooooh very good. Thanks. I did not understand. When i try my code i post the result. thanks thanks thanks. |
Ok it works, but now i don't receive the data:
I see from console that the connection and the sharing of data is ok, but this method doesn't work. Can you explain me why ? |
Is Something like this? Also I don't see where are you calling enableReceptionData, keep in mind that if you are testing in your local computer, the connection may be so fast that the 'connection' event is being launched inmediately after you call
If you do any other thing between the connection creation and the listeners (enableReceptionData), you may be missing the 'connection' event. |
If I undestrand the
} ` I retrieve this message:
|
When you open the connection in:
You should inmediatly start listening the events, so:
Also I'm sorry I miss explained before, the 'open' event is emmited when you connect to the PeerServer, so you must listen for that event before trying to connect to other peers, and it will be thrown after you do new Peer(id):
so listen for the 'open' event in your constructor after Note that for the 'open' event it is as I explained before, you must listen to it inmediately after new Peer() or you may miss the event if you wait too long to listen for it. |
ok thanks for the patience, as soon as I implement the code I will post the result 👍 |
No this continues to not work. |
I solved with the old solution.
this can be considered a good comromise? In this way, i can't create new listener but i use the same connection. One solution more refined is: use this function only one time and then send the data with
But i want tested before. Do you think is a good solution ? |
I'm afraid we will need to continue tomorrow. Would you like to upload your code to https://gist.github.com/ ? My email: kidandcat@gmail.com |
thank you so much for the opportunity. At the moment my code is an open construction site. As soon as I have arranged it I will make it available. In the meantime, when you have time, could you tell me if the last solution I indicated could be a good approach to the problem? |
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) |
I confirm that with the second solution I avoid the error. For this, now I have only two connection:
|
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).
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
The text was updated successfully, but these errors were encountered: