feat(routing): rescue blocked relay admission (#68)

This commit is contained in:
AAA authored and GitHub committed 2026-08-20 15:12:11 +08:00 Unverified
1 parent 6351b4463c
commit 31bee238bc
14 files changed
+372 -39

No files matched your search

+12 -16
View File
@@ -75,8 +75,8 @@ import type {
} from "../types";
import { HostPeer } from "../webrtc/host-peer";
import {
limitMediaAssignment,
MAX_HOST_MEDIA_CHILDREN,
reconcileBoundedMediaChildren,
} from "../webrtc/media-assignment";
import { sourceSwitchNotice } from "./host-page-notices";
@@ -757,23 +757,19 @@ export function HostPage({ onAuthorizationRequired }: HostPageProps = {}) {
childPeerIds: string[],
generation: number,
): void {
const assignment = limitMediaAssignment(
{ parentPeerId: null, childPeerIds },
reconcileBoundedMediaChildren(
peersRef.current.keys(),
childPeerIds,
MAX_HOST_MEDIA_CHILDREN,
removePeer,
(peerId) => {
void startPeer(peerId, generation).catch((error: unknown) => {
if (isCurrentGeneration(generation)) {
setNotice(readableError(error));
}
});
},
);
const assignedChildren = new Set(assignment.childPeerIds);
for (const peerId of peersRef.current.keys()) {
if (!assignedChildren.has(peerId)) {
removePeer(peerId);
}
}
for (const peerId of assignedChildren) {
void startPeer(peerId, generation).catch((error: unknown) => {
if (isCurrentGeneration(generation)) {
setNotice(readableError(error));
}
});
}
}
function handleSignalMessage(
+23
View File
@@ -17,6 +17,29 @@ export function limitMediaAssignment(
};
}
export function reconcileBoundedMediaChildren(
currentPeerIds: Iterable<string>,
nextChildPeerIds: readonly string[],
maxChildren: number,
removeChild: (peerId: string) => void,
startChild: (peerId: string) => void,
): void {
const nextPeerIds = new Set(
limitMediaAssignment(
{ parentPeerId: null, childPeerIds: [...nextChildPeerIds] },
maxChildren,
).childPeerIds,
);
for (const peerId of currentPeerIds) {
if (!nextPeerIds.has(peerId)) {
removeChild(peerId);
}
}
for (const peerId of nextPeerIds) {
startChild(peerId);
}
}
export function viewerSignalMessage(
peerAssisted: boolean,
targetPeerId: string,