From 67541f17a92d9fbd1633a60b5d38aeaf296be229 Mon Sep 17 00:00:00 2001 From: QQ Date: Tue, 17 Nov 2026 08:37:31 +0800 Subject: [PATCH] Import apps/server/src/gateway.ts --- apps/server/src/gateway.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/server/src/gateway.ts b/apps/server/src/gateway.ts index 5639757..b236db6 100644 --- a/apps/server/src/gateway.ts +++ b/apps/server/src/gateway.ts @@ -287,15 +287,20 @@ export class Gateway { } /** - * Authorize a REST `/api/v1/turn/credentials` request. Only the two devices - * of an active logical connection may obtain credentials, and only while - * that connection is still being established. + * Authorize a REST `/api/v1/turn/credentials` request. Only the two live + * devices of an active logical connection may obtain credentials: either + * while the connection is being established (`accepted`/`handshake`) or + * during an authenticated in-band transport upgrade (`ready`) when the link + * negotiated at least one WebRTC transport (`lan`/`p2p`/`turn`). */ authorizeIce(deviceId: string, connectionId: string): boolean { const link = this.links.get(connectionId) if (link === undefined) return false if (link.host !== deviceId && link.client !== deviceId) return false - if (link.stage !== 'accepted' && link.stage !== 'handshake') return false + if (link.stage === 'pending') return false + if (link.stage === 'ready' && !link.preferredTransports.some(transport => transport !== 'relay')) { + return false + } return this.peers.has(link.host) && this.peers.has(link.client) } private supportedCapabilities(): string[] {