From eb1e95379740eb571cc6e6067d1cec03fe02dc77 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Sat, 27 Jun 2026 22:18:27 -0500 Subject: [PATCH] dont ring on call end --- .../features/call/callSignalingFallback.test.ts | 15 +++++++++++++++ src/app/features/call/callSignalingFallback.ts | 3 ++- src/app/hooks/useCallSignaling.ts | 16 ++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/app/features/call/callSignalingFallback.test.ts b/src/app/features/call/callSignalingFallback.test.ts index 984626938..9a5afcbff 100644 --- a/src/app/features/call/callSignalingFallback.test.ts +++ b/src/app/features/call/callSignalingFallback.test.ts @@ -66,6 +66,7 @@ describe('evaluateOutgoingRingbackFallback', () => { activeCallRoomId: '!room:example.org', outgoingRingbackAllowed: true, declinedRoomId: null, + hasCallBeenActive: false, getRoom: () => ({ roomId: '!room:example.org' }) as never, getSessionDescription: () => EMPTY_SESSION, }; @@ -115,4 +116,18 @@ describe('evaluateOutgoingRingbackFallback', () => { ); expect(action.kind).toBe('stop'); }); + + it('stops ringback if call has been active previously', () => { + const action = evaluateOutgoingRingbackFallback( + { ringRoomId: null, ringStartedAt: null }, + NOW, + { + ...baseContext, + hasCallBeenActive: true, + isOutgoingPending: () => true, + isCallActive: () => false, + } + ); + expect(action.kind).toBe('stop'); + }); }); diff --git a/src/app/features/call/callSignalingFallback.ts b/src/app/features/call/callSignalingFallback.ts index 1bcedd6e4..de65cf924 100644 --- a/src/app/features/call/callSignalingFallback.ts +++ b/src/app/features/call/callSignalingFallback.ts @@ -58,6 +58,7 @@ export type OutgoingRingbackContext = { activeCallRoomId: string | undefined; outgoingRingbackAllowed: boolean; declinedRoomId: string | null; + hasCallBeenActive: boolean; getRoom: (roomId: string) => Room | null | undefined; getSessionDescription: (room: Room) => SessionDescription; isOutgoingPending?: typeof isOutgoingCallPending; @@ -97,7 +98,7 @@ export const evaluateOutgoingRingbackFallback = ( const pendingOutgoing = isOutgoingPending(context.myUserId, outgoingRoom, sessionDescription); const activeCall = isActive(context.myUserId, outgoingRoom, sessionDescription); - if (!pendingOutgoing || activeCall) { + if (!pendingOutgoing || activeCall || context.hasCallBeenActive) { return stop(); } diff --git a/src/app/hooks/useCallSignaling.ts b/src/app/hooks/useCallSignaling.ts index 1a40381b2..40ce2eca3 100644 --- a/src/app/hooks/useCallSignaling.ts +++ b/src/app/hooks/useCallSignaling.ts @@ -37,7 +37,7 @@ import { callRingtoneVolumeToGain, canPlayCallAudio } from '$features/call/callR import { dismissSystemCallNotifications } from '$features/call/callNotificationBridge'; import { resolveCallToneSources } from '$features/call/callToneSources'; import { isIncomingCallSuppressed } from '$features/call/callIncomingIngress'; -import { getRemoteRtcMemberUserIds } from '$features/call/callMembershipState'; +import { getRemoteRtcMemberUserIds, isCallActive } from '$features/call/callMembershipState'; import { useMatrixClient } from './useMatrixClient'; import { createDebugLogger } from '../utils/debugLogger'; @@ -85,6 +85,7 @@ export function useIncomingCallSignaling() { const outgoingStartRef = useRef(null); const activeOutgoingNotificationIdRef = useRef(null); const seenDeclineEventIdsRef = useRef>(new Set()); + const hasCallBeenActiveRef = useRef(false); type SignalingHandlerRefs = { callEmbed: typeof callEmbed; @@ -113,6 +114,7 @@ export function useIncomingCallSignaling() { outgoingDeclinesRef.current.clear(); activeOutgoingNotificationIdRef.current = null; seenDeclineEventIdsRef.current.clear(); + hasCallBeenActiveRef.current = false; }, [callEmbed]); useEffect(() => { @@ -559,6 +561,15 @@ export function useIncomingCallSignaling() { }; const evaluateOutgoingFallback = () => { + const activeCallRoomId = handlers().callEmbed?.roomId; + const outgoingRoom = activeCallRoomId ? mx.getRoom(activeCallRoomId) : null; + if (outgoingRoom) { + const session = mx.matrixRTC.getRoomSession(outgoingRoom).sessionDescription; + if (isCallActive(myUserId, outgoingRoom, session)) { + hasCallBeenActiveRef.current = true; + } + } + const ringAction = evaluateOutgoingRingbackFallback( { ringRoomId: outgoingRingRoomIdRef.current, @@ -567,9 +578,10 @@ export function useIncomingCallSignaling() { Date.now(), { ...fallbackContext, - activeCallRoomId: handlers().callEmbed?.roomId, + activeCallRoomId, outgoingRingbackAllowed: handlers().outgoingRingbackAllowed, declinedRoomId: declinedOutgoingRoomIdRef.current, + hasCallBeenActive: hasCallBeenActiveRef.current, } );