peers / peerjs

Simple peer-to-peer with WebRTC.
https://peerjs.com
MIT License
12.48k stars 1.43k forks source link

Big lag issues #917

Closed skymen closed 2 years ago

skymen commented 2 years ago

Hey,

I am making a game using peerjs where players send info about their positioning every frame to the host, and the host redistributes the data.

However, sometimes, even when playing with myself, the events have a massive delay that piles up over time, and the distant pllayer is multiple seconds behind his client counterpart. All the movements and events are executed in the correct order, they're just very slow.

This does not happen all the time. Sometimes it works just fine.

Can this be due to me using the public server? Would this be fixed by using a self hosted one?

Or is this due to sending too many updates per second and the library cannot keep up?

yeemachine commented 2 years ago

I also have this issue. Sending json over too quickly causes a delay, that later bunches the sent data together once I close the connection.

I've been just manually limiting the rate I'm sending and smoothing the position on the other end, but def not ideal.

skymen commented 2 years ago

Can you show/explain how you implemented your rate limiting?

afrokick commented 2 years ago

Sorry, it is no peerjs issue. Close the issue.

skymen commented 2 years ago

How is it not a peerjs issue?

afrokick commented 2 years ago

Because in PeerJS library there is no any logic about rate limiting or bandwidth limits.

You should customise you network settings via sdp ( https://github.com/peers/peerjs/issues/901#issuecomment-1046230997 ) + using your own STUN/TURN servers to minimise RTT and packet loss.