From b2016a5f6c0b54eeb1f24470d37f366693d5809e Mon Sep 17 00:00:00 2001 From: Jonas Gloning <34194370+jonasgloning@users.noreply.github.com> Date: Sat, 2 Sep 2023 17:34:38 +0200 Subject: [PATCH] feat: emit error on connections when receiving "EXPIRE" Closes #924 --- lib/enums.ts | 1 + lib/peer.ts | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/enums.ts b/lib/enums.ts index 0394f90aa..ee19d0cec 100644 --- a/lib/enums.ts +++ b/lib/enums.ts @@ -61,6 +61,7 @@ export enum PeerErrorType { } export enum BaseConnectionErrorType { + PeerUnavailable = "peer-unavailable", NegotiationFailed = "negotiation-failed", ConnectionClosed = "connection-closed", } diff --git a/lib/peer.ts b/lib/peer.ts index 6fa306cbc..4a77ba035 100644 --- a/lib/peer.ts +++ b/lib/peer.ts @@ -4,6 +4,7 @@ import { Socket } from "./socket"; import { MediaConnection } from "./mediaconnection"; import type { DataConnection } from "./dataconnection/DataConnection"; import { + BaseConnectionErrorType, ConnectionType, PeerErrorType, ServerMessageType, @@ -379,6 +380,16 @@ export class Peer extends EventEmitterWithError { 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.