Skip to content

Commit

Permalink
feat: emit error on connections when receiving "EXPIRE"
Browse files Browse the repository at this point in the history
Closes #924
  • Loading branch information
WofWca committed Aug 26, 2023
1 parent 633cd84 commit 986e0ca
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,22 @@ export class Peer extends EventEmitter<PeerEvents> {
PeerErrorType.PeerUnavailable,
`Could not connect to peer ${peerId}`,
);

// This is so that an error is emited on a connection that has just been created,
// but could not be established because the server responded with
// `ServerMessageType.Expire` (but yes, we emit the error on all connections).
// See https://github.com/peers/peerjs/issues/924
//
// TODO how about `this._cleanupPeer(peerId);` instead?
// Or how about make the server send back `connectionId`, and only emit the error
// on that connection?
const connections = this._connections.get(peerId);
if (connections) {
for (const c of connections) {
c.emit("error", new Error(`Server says ${peerId} is unavailable`));

Check failure on line 407 in lib/peer.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

This expression is not callable.

Check failure on line 407 in lib/peer.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

This expression is not callable.
}
}

break;
case ServerMessageType.Offer: {
// we should consider switching this to CALL/CONNECT, but this is the least breaking option.
Expand Down

0 comments on commit 986e0ca

Please sign in to comment.