mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
tweak(calls): Abstract initialize call action & own number handling
This commit is contained in:
1 parent
af6e291368
commit
be4323f337
6 files changed
+40
-53
No files matched your search
@@ -6,6 +6,9 @@ import { fetchNui } from '../../../utils/fetchNui';
|
||||
import { useCallback } from 'react';
|
||||
import { useMyPhoneNumber } from '../../simcard/hooks/useMyPhoneNumber';
|
||||
import { useDialingSound } from './useDialingSound';
|
||||
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ServerPromiseResp } from '../../../../../typings/common';
|
||||
|
||||
interface CallHook {
|
||||
call: ActiveCall;
|
||||
@@ -13,13 +16,35 @@ interface CallHook {
|
||||
acceptCall(): void;
|
||||
rejectCall(): void;
|
||||
endCall(): void;
|
||||
initializeCall(number: string): void;
|
||||
}
|
||||
|
||||
export const useCall = (): CallHook => {
|
||||
const [call, setCall] = useRecoilState(callerState.currentCall);
|
||||
const myPhoneNumber = useMyPhoneNumber();
|
||||
const { t } = useTranslation();
|
||||
const { addAlert } = useSnackbar();
|
||||
const { endDialTone, startDialTone } = useDialingSound();
|
||||
|
||||
const initializeCall = useCallback(
|
||||
(number) => {
|
||||
// We allow calling of ourselves in development
|
||||
if (process.env.NODE_ENV !== 'development' && myPhoneNumber === number) {
|
||||
return addAlert({ message: t('CALLS.FEEDBACK.ERROR_MYSELF'), type: 'error' });
|
||||
}
|
||||
|
||||
fetchNui<ServerPromiseResp>(CallEvents.INITIALIZE_CALL, {
|
||||
receiverNumber: number,
|
||||
}).then((resp) => {
|
||||
if (resp.status === 'error') {
|
||||
addAlert({ message: t('CALLS.FEEDBACK.ERROR'), type: 'error' });
|
||||
console.error(resp.errorMsg);
|
||||
}
|
||||
});
|
||||
},
|
||||
[addAlert, myPhoneNumber, t],
|
||||
);
|
||||
|
||||
const acceptCall = useCallback(() => {
|
||||
fetchNui(CallEvents.ACCEPT_CALL, {
|
||||
transmitterNumber: call.transmitter,
|
||||
@@ -39,5 +64,5 @@ export const useCall = (): CallHook => {
|
||||
});
|
||||
}, [call, myPhoneNumber]);
|
||||
|
||||
return { call, setCall, acceptCall, rejectCall, endCall };
|
||||
return { call, setCall, acceptCall, rejectCall, endCall, initializeCall };
|
||||
};
|
||||
Reference in new issue
Block a user