From 303f6fbd45c4a39b5596941c8fe0baa634feaa9a Mon Sep 17 00:00:00 2001 From: root Date: Fri, 15 May 2026 14:57:51 -0400 Subject: [PATCH] =?UTF-8?q?chore:=20remove=20dead=20code=20=E2=80=94=20Inc?= =?UTF-8?q?omingCallNotification=20and=20useIncomingDmCall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are superseded by IncomingCallListener in CallEmbedProvider (merged from v4.12.1). IncomingCallNotification was already removed from Router.tsx in a previous commit. --- .../components/IncomingCallNotification.tsx | 310 ------------------ src/app/hooks/useIncomingDmCall.ts | 87 ----- 2 files changed, 397 deletions(-) delete mode 100644 src/app/components/IncomingCallNotification.tsx delete mode 100644 src/app/hooks/useIncomingDmCall.ts diff --git a/src/app/components/IncomingCallNotification.tsx b/src/app/components/IncomingCallNotification.tsx deleted file mode 100644 index 885afd6fe..000000000 --- a/src/app/components/IncomingCallNotification.tsx +++ /dev/null @@ -1,310 +0,0 @@ -import React, { useCallback, useEffect, useRef } from 'react'; -import { Avatar, Box, Button, Text } from 'folds'; -import { UserAvatar } from './user-avatar'; -import { useMatrixClient } from '../hooks/useMatrixClient'; -import { useCallStart } from '../hooks/useCallEmbed'; -import { useSetting } from '../state/hooks/settings'; -import { settingsAtom } from '../state/settings'; -import { useIncomingDmCall } from '../hooks/useIncomingDmCall'; -import { mxcUrlToHttp } from '../utils/matrix'; - -function useRingTone(active: boolean) { - const stopRef = useRef<(() => void) | null>(null); - - useEffect(() => { - if (!active) { - stopRef.current?.(); - stopRef.current = null; - return; - } - - let ctx: AudioContext; - try { - ctx = new AudioContext(); - } catch { - return; - } - - let cancelled = false; - - const pulse = (t: number, freq: number, dur: number) => { - const osc = ctx.createOscillator(); - const gain = ctx.createGain(); - osc.connect(gain); - gain.connect(ctx.destination); - osc.frequency.value = freq; - osc.type = 'sine'; - gain.gain.setValueAtTime(0, t); - gain.gain.linearRampToValueAtTime(0.22, t + 0.04); - gain.gain.setValueAtTime(0.22, t + dur - 0.04); - gain.gain.linearRampToValueAtTime(0, t + dur); - osc.start(t); - osc.stop(t + dur); - }; - - let ringTimer: ReturnType | null = null; - const ring = () => { - if (cancelled) return; - const now = ctx.currentTime; - pulse(now, 880, 0.18); - pulse(now + 0.28, 880, 0.18); - ringTimer = setTimeout(ring, 2200); - }; - - ring(); - - const stop = () => { - cancelled = true; - if (ringTimer !== null) clearTimeout(ringTimer); - ctx.close(); - }; - - stopRef.current = stop; - - return () => { - stop(); - stopRef.current = null; - }; - }, [active]); - - return stopRef; -} - -function IncomingCallCard() { - const mx = useMatrixClient(); - const startCall = useCallStart(true); - const [lotusTerminal] = useSetting(settingsAtom, 'lotusTerminal'); - const [incoming, dismiss] = useIncomingDmCall(); - const stopRingRef = useRingTone(!!incoming); - - const stopAndDismiss = useCallback(() => { - stopRingRef.current?.(); - dismiss(); - }, [dismiss, stopRingRef]); - - const handleAnswer = useCallback(() => { - if (!incoming) return; - stopRingRef.current?.(); - startCall(incoming.room); - dismiss(); - }, [incoming, startCall, dismiss, stopRingRef]); - - if (!incoming) return null; - - const callerUser = mx.getUser(incoming.callerId); - const callerName = callerUser?.displayName ?? incoming.callerId; - const avatarMxc = callerUser?.avatarUrl; - const avatarUrl = avatarMxc ? mxcUrlToHttp(mx, avatarMxc, undefined, 64, 64, 'crop') ?? undefined : undefined; - - if (lotusTerminal) { - return ( -
-
- - INCOMING CALL -
-
- - ( - - {callerName[0]?.toUpperCase() ?? '?'} - - )} - /> - -
-
{callerName}
-
- {incoming.callerId} -
-
-
-
- - -
- -
- ); - } - - return ( -
-
- - Incoming call -
-
- - ( - {callerName[0]?.toUpperCase() ?? '?'} - )} - /> - -
- {callerName} - {incoming.callerId} -
-
- - - - - -
- ); -} - -export function IncomingCallNotification() { - return ; -} diff --git a/src/app/hooks/useIncomingDmCall.ts b/src/app/hooks/useIncomingDmCall.ts deleted file mode 100644 index 7e5eac3b9..000000000 --- a/src/app/hooks/useIncomingDmCall.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { Room } from 'matrix-js-sdk'; -import { - MatrixRTCSession, - MatrixRTCSessionEvent, -} from 'matrix-js-sdk/lib/matrixrtc/MatrixRTCSession'; -import { MatrixRTCSessionManagerEvents } from 'matrix-js-sdk/lib/matrixrtc/MatrixRTCSessionManager'; -import { useEffect, useRef, useState } from 'react'; -import { useAtomValue } from 'jotai'; -import { useMatrixClient } from './useMatrixClient'; -import { callEmbedAtom } from '../state/callEmbed'; - -export type IncomingDmCall = { - room: Room; - callerId: string; -}; - -const isDmRoom = (room: Room): boolean => - room.hasEncryptionStateEvent() && room.getMembers().length <= 2; - -export const useIncomingDmCall = (): [IncomingDmCall | null, () => void] => { - const mx = useMatrixClient(); - const callEmbed = useAtomValue(callEmbedAtom); - const [incoming, setIncoming] = useState(null); - const sessionRef = useRef(null); - - useEffect(() => { - const myUserId = mx.getUserId(); - - const handleSessionStarted = (roomId: string, session: MatrixRTCSession) => { - if (callEmbed) return; - const room = mx.getRoom(roomId); - if (!room || !isDmRoom(room)) return; - const memberships = session.memberships ?? []; - if (memberships.length === 0) return; - const callerMembership = memberships.find((m) => m.sender !== myUserId); - if (!callerMembership) return; - if (memberships.find((m) => m.sender === myUserId)) return; - sessionRef.current = session; - setIncoming({ room, callerId: callerMembership.sender ?? callerMembership.deviceId }); - }; - - const handleSessionEnded = (roomId: string) => { - setIncoming((prev) => (prev?.room.roomId === roomId ? null : prev)); - }; - - mx.matrixRTC.on(MatrixRTCSessionManagerEvents.SessionStarted, handleSessionStarted); - mx.matrixRTC.on(MatrixRTCSessionManagerEvents.SessionEnded, handleSessionEnded); - return () => { - mx.matrixRTC.off(MatrixRTCSessionManagerEvents.SessionStarted, handleSessionStarted); - mx.matrixRTC.off(MatrixRTCSessionManagerEvents.SessionEnded, handleSessionEnded); - }; - }, [mx, callEmbed]); - - // Dismiss if caller leaves before answered - useEffect(() => { - const session = sessionRef.current; - if (!session || !incoming) return; - const myUserId = mx.getUserId(); - const check = () => { - const memberships = session.memberships ?? []; - if (!memberships.some((m) => m.sender !== myUserId)) setIncoming(null); - }; - session.on(MatrixRTCSessionEvent.MembershipsChanged, check); - return () => { - session.off(MatrixRTCSessionEvent.MembershipsChanged, check); - }; - }, [incoming, mx]); - - // Auto-dismiss after 30 seconds - useEffect(() => { - if (!incoming) return; - const t = setTimeout(() => setIncoming(null), 30_000); - return () => clearTimeout(t); - }, [incoming]); - - // Dismiss when user joins a call - useEffect(() => { - if (callEmbed) setIncoming(null); - }, [callEmbed]); - - const dismiss = () => { - sessionRef.current = null; - setIncoming(null); - }; - - return [incoming, dismiss]; -};