reject call after 1 minute showing the dialog

pull/2015/head
Audric Ackermann 3 years ago
parent 4700a0c832
commit 57449857f6
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -24,6 +24,7 @@ import {
useOurAvatarPath,
useOurConversationUsername,
} from '../../../hooks/useParamSelector';
import { useModuloWithTripleDots } from '../../../hooks/useModuloWithTripleDots';
const VideoContainer = styled.div`
height: 100%;
@ -258,20 +259,26 @@ const StyledCenteredLabel = styled.div`
const RingingLabel = () => {
const ongoingCallWithFocusedIsRinging = useSelector(getHasOngoingCallWithFocusedConvoIsOffering);
const modulatedStr = useModuloWithTripleDots(window.i18n('ringing'), 3, 1000);
if (!ongoingCallWithFocusedIsRinging) {
return null;
}
return <StyledCenteredLabel>{window.i18n('ringing')}</StyledCenteredLabel>;
return <StyledCenteredLabel>{modulatedStr}</StyledCenteredLabel>;
};
const ConnectingLabel = () => {
const ongoingCallWithFocusedIsConnecting = useSelector(
getHasOngoingCallWithFocusedConvosIsConnecting
);
const modulatedStr = useModuloWithTripleDots(window.i18n('establishingConnection'), 3, 1000);
if (!ongoingCallWithFocusedIsConnecting) {
return null;
}
return <StyledCenteredLabel>{window.i18n('establishingConnection')}</StyledCenteredLabel>;
return <StyledCenteredLabel>{modulatedStr}</StyledCenteredLabel>;
};
// tslint:disable-next-line: max-func-body-length

@ -1,9 +1,10 @@
import React from 'react';
import React, { useEffect } from 'react';
import { useSelector } from 'react-redux';
import styled from 'styled-components';
import _ from 'underscore';
import { useAvatarPath, useConversationUsername } from '../../../hooks/useParamSelector';
import { ed25519Str } from '../../../session/onions/onionPath';
import { CallManager } from '../../../session/utils';
import { getHasIncomingCall, getHasIncomingCallFrom } from '../../../state/selectors/conversations';
import { Avatar, AvatarSize } from '../../Avatar';
@ -27,10 +28,34 @@ const IncomingCallAvatatContainer = styled.div`
padding: 0 0 2rem 0;
`;
const timeoutMs = 60000;
export const IncomingCallDialog = () => {
const hasIncomingCall = useSelector(getHasIncomingCall);
const incomingCallFromPubkey = useSelector(getHasIncomingCallFrom);
useEffect(() => {
let timeout: NodeJS.Timeout;
if (incomingCallFromPubkey) {
timeout = global.setTimeout(async () => {
if (incomingCallFromPubkey) {
window.log.info(
`call missed with ${ed25519Str(
incomingCallFromPubkey
)} as dialog was not interacted with for ${timeoutMs} ms`
);
await CallManager.USER_rejectIncomingCallRequest(incomingCallFromPubkey);
}
}, timeoutMs);
}
return () => {
if (timeout) {
global.clearTimeout(timeout);
}
};
}, [incomingCallFromPubkey]);
//#region input handlers
const handleAcceptIncomingCall = async () => {
if (incomingCallFromPubkey) {

@ -0,0 +1,17 @@
import React from 'react';
// tslint:disable-next-line: no-submodule-imports
import useInterval from 'react-use/lib/useInterval';
export function useModulo(loopBackAt: number, delay: number) {
const [count, setCount] = React.useState(0);
useInterval(() => {
if (count >= loopBackAt) {
setCount(0);
} else {
setCount(count + 1);
}
}, delay);
console.warn('useModulo', count);
return { count };
}

@ -0,0 +1,14 @@
import { useModulo } from './useModulo';
export function useModuloWithTripleDots(
localizedString: string,
loopBackAt: number,
delay: number
) {
const modulo = useModulo(loopBackAt, delay);
if (localizedString.endsWith('...')) {
return localizedString.slice(0, localizedString.length - (loopBackAt - modulo.count));
}
return localizedString;
}

@ -698,7 +698,7 @@ export async function USER_hangup(fromSender: string) {
timestamp: Date.now(),
uuid: currentCallUUID,
});
await getMessageQueue().sendToPubKeyNonDurably(PubKey.cast(fromSender), endCallMessage);
void getMessageQueue().sendToPubKeyNonDurably(PubKey.cast(fromSender), endCallMessage);
}
window.inboxStore?.dispatch(endCall({ pubkey: fromSender }));
@ -825,7 +825,7 @@ export async function handleCallTypeOffer(
}
}
async function handleMissedCall(
export async function handleMissedCall(
sender: string,
incomingOfferTimestamp: number,
isBecauseOfCallPermission: boolean

Loading…
Cancel
Save