After a homeserver stall Element Call showed "Connection lost" while the call bar still looked joined. Handle the fork's io.lotus.call_error: show "Call disconnected" with a Reconnect button (io.lotus.reconnect), and reconnect automatically once sync is back. Fixes #318 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
import { SyncState } from 'matrix-js-sdk';
|
|
import { CALL_ERROR_CHANGED, CallControl } from '../plugins/call/CallControl';
|
|
import { CallErrorState } from '../plugins/call/callError';
|
|
import { useMatrixClient } from './useMatrixClient';
|
|
import { useSyncState } from './useSyncState';
|
|
|
|
/** [Gitea #318] The fork's current call error (null while the call is fine). */
|
|
export function useCallError(control: CallControl): CallErrorState {
|
|
const [err, setErr] = useState(control.callError);
|
|
useEffect(() => {
|
|
const on = () => setErr(control.callError);
|
|
on();
|
|
control.on(CALL_ERROR_CHANGED, on);
|
|
return () => {
|
|
control.off(CALL_ERROR_CHANGED, on);
|
|
};
|
|
}, [control]);
|
|
return err;
|
|
}
|
|
|
|
/**
|
|
* [Gitea #318] After a homeserver stall the call drops with "Connection
|
|
* lost". Once sync is back, reconnect automatically (once per drop).
|
|
*/
|
|
export function useReconnectWhenSynced(control: CallControl): void {
|
|
const mx = useMatrixClient();
|
|
const err = useCallError(control);
|
|
const tried = useRef<CallErrorState>(null);
|
|
useSyncState(
|
|
mx,
|
|
useCallback(
|
|
(state: SyncState | null) => {
|
|
if (state !== SyncState.Syncing || !err?.recoverable || tried.current === err) return;
|
|
tried.current = err;
|
|
control.reconnect();
|
|
},
|
|
[err, control],
|
|
),
|
|
);
|
|
}
|