fix: recurriing network issue
All checks were successful
Queue Release Build / prepare (push) Successful in 18s
Deploy Web Apps / deploy (push) Successful in 6m32s
Queue Release Build / build-windows (push) Successful in 26m8s
Queue Release Build / build-linux (push) Successful in 40m18s
Queue Release Build / finalize (push) Successful in 42s

This commit is contained in:
2026-04-30 04:04:34 +02:00
parent b1fe286be8
commit a49e18b9f0
16 changed files with 522 additions and 17 deletions

View File

@@ -4,6 +4,7 @@ import { Store } from '@ngrx/store';
import {
Subject,
filter,
merge,
type Observable
} from 'rxjs';
import { RealtimeSessionFacade } from '../../../../core/realtime';
@@ -17,7 +18,10 @@ export class PeerDeliveryService {
private readonly users = this.store.selectSignal(selectAllUsers);
private readonly networkRestoredSubject = new Subject<void>();
readonly directMessageEvents$: Observable<ChatEvent> = this.webrtc.onMessageReceived.pipe(
readonly directMessageEvents$: Observable<ChatEvent> = merge(
this.webrtc.onMessageReceived,
this.webrtc.onSignalingMessage as Observable<ChatEvent>
).pipe(
filter((event) => event.type === 'direct-message' || event.type === 'direct-message-status' || event.type === 'direct-message-mutation')
);
@@ -35,12 +39,14 @@ export class PeerDeliveryService {
const peerId = this.resolvePeerId(recipientId);
if (!peerId) {
return false;
let sent = false;
if (peerId) {
this.webrtc.sendToPeer(peerId, event);
sent = true;
}
this.webrtc.sendToPeer(peerId, event);
return true;
return this.sendViaSignaling(recipientId, event) || sent;
}
handleAck(recipientId: string, event: ChatEvent): boolean {
@@ -77,6 +83,48 @@ export class PeerDeliveryService {
return candidates.find((candidate) => connectedPeerIds.has(candidate)) ?? null;
}
private sendViaSignaling(recipientId: string, event: ChatEvent): boolean {
if (event.type !== 'direct-message' && event.type !== 'direct-message-status' && event.type !== 'direct-message-mutation') {
return false;
}
const targetPeerId = this.resolveSignalingPeerId(recipientId);
if (!targetPeerId) {
return false;
}
try {
this.webrtc.sendRawMessage({
...event,
targetUserId: targetPeerId
});
return true;
} catch {
return false;
}
}
private resolveSignalingPeerId(recipientId: string): string | null {
return this.resolveCandidateIds(recipientId).find((candidate) => this.webrtc.hasSignalingRouteForPeer(candidate)) ?? null;
}
private resolveCandidateIds(recipientId: string): string[] {
const user = this.users().find((candidate: User) =>
candidate.id === recipientId || candidate.oderId === recipientId || candidate.peerId === recipientId
);
return [
recipientId,
user?.oderId,
user?.peerId,
user?.id
].filter((candidate, index, candidates): candidate is string =>
!!candidate && candidates.indexOf(candidate) === index
);
}
private isOfflineOverrideEnabled(): boolean {
return typeof window !== 'undefined'
&& !!(window as Window & { metoyouDmNetworkOffline?: boolean }).metoyouDmNetworkOffline;