Ver Fonte

feat: emit error on connections when receiving "EXPIRE"

Closes #924
Jonas Gloning há 2 anos atrás
pai
commit
b2016a5f6c
2 ficheiros alterados com 12 adições e 0 exclusões
  1. 1 0
      lib/enums.ts
  2. 11 0
      lib/peer.ts

+ 1 - 0
lib/enums.ts

@@ -61,6 +61,7 @@ export enum PeerErrorType {
 }
 
 export enum BaseConnectionErrorType {
+	PeerUnavailable = "peer-unavailable",
 	NegotiationFailed = "negotiation-failed",
 	ConnectionClosed = "connection-closed",
 }

+ 11 - 0
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, 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.