TP-1|Kunal|added call status polling (#809)

* TP-1|Kunal|added call status polling

* TP-1|Kunal|added timeout unsub
This commit is contained in:
Kunal Sharma
2024-02-02 09:45:44 +05:30
committed by GitHub
parent 917ea9de81
commit ff5b02076a
4 changed files with 38 additions and 6 deletions

View File

@@ -2,7 +2,7 @@
import { AmeyoIcon } from '../../assets/icons/AmeyoIcon';
import styles from './AmeyoCollapsibleToolbar.module.scss';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { Button, Typography } from '@primitives';
import { Typography } from '@primitives';
import CloseIcon from '../../assets/icons/CloseIcon';
import { RssIcon } from '../../assets/icons/RssIcon';
import { useDispatch, useSelector } from 'react-redux';
@@ -42,19 +42,23 @@ import {
import { setAmeyoCallDetails } from '../../reducers/commonSlice';
import { toast } from '@primitives/Toast';
import { createQueryParams } from '../../utils/QueryParamsHelper';
import { navigateToCaseDetails } from '../../utils/commonUtils';
import { isFunction, navigateToCaseDetails } from '@cp/utils/commonUtils';
import APP_ROUTES from '../../layout/Routes';
import { useNavigate } from 'react-router-dom';
import GridRow from '@navi/web-ui/lib/layouts/Grid/GridRow/GridRow';
import GridColumn from '@navi/web-ui/lib/layouts/Grid/GridColumn/GridColumn';
import cx from 'classnames';
import { addAmeyoAvailabilityToggleClickstream } from '../../service/ameyo.service';
import { addClickstreamEvent } from '../../service/clickStreamEventService';
import { AMEYO_SESSION_EVENTS, CLICKSTREAM_EVENT_NAMES } from '../../service/clickStream.constant';
import MuteIcon from 'src/assets/icons/MuteIcon';
import UnMuteIcon from 'src/assets/icons/UnMuteIcon';
import { Tooltip, TooltipContent, TooltipTrigger } from '../TooltipV2/TooltipV2';
import { AmeyoConstants, AmeyoToggleNewStatus, AMEYO_MUTE_DISCLAIMER_INTERVAL } from './constants';
import {
AMEYO_CALL_STATUS_POLLING_INTERVAL,
AMEYO_MUTE_DISCLAIMER_INTERVAL,
AmeyoConstants,
AmeyoToggleNewStatus
} from './constants';
import MicOff from 'src/assets/icons/MicOff';
import HangUpCallIcon from 'src/assets/icons/HangUpCallIcon';
import MuteCircledIcon from 'src/assets/icons/MuteCircledIcon';
@@ -67,6 +71,9 @@ import { LITMUS_EXPERIMENT_NAMES } from '@cp/src/constants/litmusExperimentNames
import isLitmusExperimentEnabled from '@cp/src/utils/isLitmusExperimentEnabled';
import { LocalStorage } from '@cp/src/utils/StorageUtils';
import { LOCAL_STORAGE_KEYS } from '@cp/src/constants/StorageKeys';
import { poll } from '@cp/utils/polling';
import { noop } from '@utils/common';
const BUTTON_ENABLED_TIMEOUT = 10000;
export const BUBBLE_COLORS = {
TRANSPARENT: 'rgba(250,250,250,0)', // default/don't know
@@ -83,6 +90,7 @@ const handleTabClose = (event: any) => {
export const AmeyoCollapsibleToolbar = (props: {
isCallHappening: (isHappening: boolean) => void;
}) => {
const pollRef = useRef<() => void>();
const { authData, isAmeyoErronous, ameyoExtensionToggleOn } = useSelector((state: RootState) => {
return {
authData: state.common.userData,
@@ -799,6 +807,27 @@ export const AmeyoCollapsibleToolbar = (props: {
);
}
useEffect(() => {
if (isFunction(pollRef.current)) {
pollRef.current();
}
isLitmusExperimentEnabled(LITMUS_EXPERIMENT_NAMES.COLLECTION_AMEYO_TELE_POLLING, {
'x-customer-id': authData?.referenceId
}).then(res => {
if (res?.result) {
pollRef.current = poll(
() => {
setAmeyoCallData(ExtensionHandler.currentCallStatus());
ExtensionHandler.getCurrentCallStatus();
},
undefined,
AMEYO_CALL_STATUS_POLLING_INTERVAL,
noop
);
}
});
}, [authData?.referenceId]);
return (
<div className={styles.container} ref={currentRef}>
<div className={styles.sideToolbarAmeyoIconsWrapper}>

View File

@@ -21,3 +21,5 @@ export enum PING_PONG_CLICKSTREAM_EVENT_SOURCE {
LONGHORN = 'LONGHORN',
AMEYO = 'AMEYO'
}
export const AMEYO_CALL_STATUS_POLLING_INTERVAL = 2000;

View File

@@ -2,5 +2,6 @@ export enum LITMUS_EXPERIMENT_NAMES {
COLLECTION_FCM_FALLBACK = 'collections-fcm-fallback',
COLLECTION_AMEYO_FIX = 'collection-ameyo-fix',
COLLECTION_ENABLE_PAYMENT_SUCCESS_MODAL = 'collection-enable-payment-success-modal',
COLLECTION_LONGHORN_THEME_ENABLE = 'collection-enable-theme'
COLLECTION_LONGHORN_THEME_ENABLE = 'collection-enable-theme',
COLLECTION_AMEYO_TELE_POLLING = 'collection-ameyo-tele-polling'
}

View File

@@ -8,7 +8,7 @@ export enum PollStatus {
export function poll(
promiseFn: any,
dataFormatter: (data: any) => { data: any },
dataFormatter: undefined | ((data: any) => { data: any }),
pollingInterval: number,
callback: (status: PollStatus, data?: any) => void
) {