Skip to content

Commit 28afc02

Browse files
authored
feat: emit error on connections when receiving "EXPIRE"
Closes #924
1 parent 633cd84 commit 28afc02

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/peer.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,22 @@ export class Peer extends EventEmitter<PeerEvents> {
392392
PeerErrorType.PeerUnavailable,
393393
`Could not connect to peer ${peerId}`,
394394
);
395+
396+
// This is so that an error is emited on a connection that has just been created,
397+
// but could not be established because the server responded with
398+
// `ServerMessageType.Expire` (but yes, we emit the error on all connections).
399+
// See https://github.com/peers/peerjs/issues/924
400+
//
401+
// TODO how about `this._cleanupPeer(peerId);` instead?
402+
// Or how about make the server send back `connectionId`, and only emit the error
403+
// on that connection?
404+
const connections = this._connections.get(peerId);
405+
if (connections) {
406+
for (const c of connections) {
407+
c.emit("error", new Error(`Server says ${peerId} is unavailable`);
408+
}
409+
}
410+
395411
break;
396412
case ServerMessageType.Offer: {
397413
// we should consider switching this to CALL/CONNECT, but this is the least breaking option.

0 commit comments

Comments
 (0)