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 peers#924
  • Loading branch information
jonasgloning committed Sep 3, 2023
1 parent 59cea73 commit b2016a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export enum PeerErrorType {
}

export enum BaseConnectionErrorType {
PeerUnavailable = "peer-unavailable",
NegotiationFailed = "negotiation-failed",
ConnectionClosed = "connection-closed",
}
Expand Down
11 changes: 11 additions & 0 deletions lib/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Socket } from "./socket";
import { MediaConnection } from "./mediaconnection";
import type { DataConnection } from "./dataconnection/DataConnection";
import {
BaseConnectionErrorType,
ConnectionType,
PeerErrorType,
ServerMessageType,
Expand Down Expand Up @@ -379,6 +380,16 @@ export class Peer extends EventEmitterWithError<PeerErrorType, PeerEvents> {
PeerErrorType.PeerUnavailable,
`Could not connect to peer ${peerId}`,
);
// Emit an error on all connections with this peer.
const connections = (this._connections.get(peerId) ?? []).filter(
(c) => c.peer === peerId,
);
for (const conn of connections) {
conn.emitError(
BaseConnectionErrorType.PeerUnavailable,
`${peerId} is unavailable`,
);
}
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 b2016a5

Please sign in to comment.