peers / peerjs

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

Error expected on DataConnection when not establishing a connection #924

Open arthuro555 opened 2 years ago

arthuro555 commented 2 years ago

When a DataConnection fails to establish, for example, due to connecting to an invalid ID or to one's own ID, I would expect the dataConnection.on('error', () => {...}) callback to be executed. Instead, only peer.on('error', () => {}) catches such kinds of errors. This is especially annoying when you want to for example connect to multiple peers at once since we cannot know which one has failed to connect, making it hard to tell the user which peer(s) has issues.

szcuipeng commented 1 year ago

i need too. and now i use setTimeout instead.

WofWca commented 1 year ago

This also applies to the 'unavailable-id' error (the reconnect case). That is, you have no context as to which peer the error relates to.

Responsible source code: https://github.com/peers/peerjs/blob/633cd84929f398899a06e8281706e3040410d706/lib/peer.ts#L390-L395

I think Promise-based API would make it easier to resolve this .