peers / peerjs

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

New feature: add 'allow_override_connect' startup option #1203

Closed RJiazhen closed 3 months ago

RJiazhen commented 3 months ago

Currently, when the peer server receives a connection request with the same connection ID as an existing one, it immediately returns an "ID-TAKEN" error and disconnects the connection.

However, I would like to add an "allow_override_connect" startup option (defaulting to false). When set to true, it should accept the connection request from the new client and send an "OVERRIDE_CONNECTION" error to the old client, then disconnect the old connection. Like this:

I have forked the peer-server and implemented the related functionality. However, due to the limitations in PeerJS regarding error types, the client cannot respond to this error directly. As a temporary solution, I am overriding the _handleMessage method to handle this response.

So, can we consider adding relevant startup options in peer-server and implementing corresponding response functionality in PeerJS?

I would also be happy to participate in the development of this feature.