Fix private calls

This commit is contained in:
2026-05-17 15:14:52 +02:00
parent 0f6cb3ee77
commit e769a6ee4a
71 changed files with 5821 additions and 349 deletions

View File

@@ -18,6 +18,7 @@ export class RemoteScreenShareRequestController {
private remoteScreenShareRequestsEnabled = false;
private readonly desiredRemoteScreenSharePeers = new Set<string>();
private readonly activeRemoteScreenSharePeers = new Set<string>();
private readonly requestRetryTimers = new Map<string, ReturnType<typeof setTimeout>>();
constructor(
private readonly dependencies: RemoteScreenShareRequestControllerDependencies
@@ -31,6 +32,7 @@ export class RemoteScreenShareRequestController {
handlePeerDisconnected(peerId: string): void {
this.activeRemoteScreenSharePeers.delete(peerId);
this.clearRequestRetry(peerId);
this.dependencies.clearScreenShareRequest(peerId);
}
@@ -62,6 +64,7 @@ export class RemoteScreenShareRequestController {
if (!enabled) {
this.remoteScreenShareRequestsEnabled = false;
this.desiredRemoteScreenSharePeers.clear();
this.clearAllRequestRetries();
this.stopRemoteScreenShares([...this.activeRemoteScreenSharePeers]);
return;
}
@@ -83,18 +86,20 @@ export class RemoteScreenShareRequestController {
this.remoteScreenShareRequestsEnabled = false;
this.desiredRemoteScreenSharePeers.clear();
this.activeRemoteScreenSharePeers.clear();
this.clearAllRequestRetries();
}
private requestRemoteScreenShares(peerIds: string[]): void {
private requestRemoteScreenShares(peerIds: string[], retryAttempt = 0): void {
const connectedPeerIds = new Set(this.dependencies.getConnectedPeerIds());
for (const peerId of peerIds) {
if (!connectedPeerIds.has(peerId) || this.activeRemoteScreenSharePeers.has(peerId)) {
if (!connectedPeerIds.has(peerId)) {
continue;
}
this.dependencies.sendToPeer(peerId, { type: P2P_TYPE_SCREEN_SHARE_REQUEST });
this.activeRemoteScreenSharePeers.add(peerId);
this.scheduleRequestRetry(peerId, retryAttempt);
}
}
@@ -107,7 +112,48 @@ export class RemoteScreenShareRequestController {
}
this.activeRemoteScreenSharePeers.delete(peerId);
this.clearRequestRetry(peerId);
this.dependencies.clearRemoteScreenShareStream(peerId);
}
}
private scheduleRequestRetry(peerId: string, retryAttempt: number): void {
if (!this.remoteScreenShareRequestsEnabled || !this.desiredRemoteScreenSharePeers.has(peerId)) {
return;
}
const retryDelays = [
300,
1_000,
2_500
];
const delay = retryDelays[retryAttempt];
if (delay === undefined) {
return;
}
this.clearRequestRetry(peerId);
this.requestRetryTimers.set(peerId, setTimeout(() => {
this.requestRetryTimers.delete(peerId);
this.requestRemoteScreenShares([peerId], retryAttempt + 1);
}, delay));
}
private clearRequestRetry(peerId: string): void {
const timer = this.requestRetryTimers.get(peerId);
if (timer) {
clearTimeout(timer);
this.requestRetryTimers.delete(peerId);
}
}
private clearAllRequestRetries(): void {
for (const timer of this.requestRetryTimers.values()) {
clearTimeout(timer);
}
this.requestRetryTimers.clear();
}
}