Skip to content

Commit

Permalink
Merge pull request #2029 from OneCommunityGlobal/xiaow_add_failure_li…
Browse files Browse the repository at this point in the history
…mits_to_heartbeat_in_timer

XiaoW_Allow up to 3 failed connection attempts for the heartbeat in Timer
  • Loading branch information
one-community authored Mar 6, 2024
2 parents 1e3eefd + f0da5ce commit 3e2f7f1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/components/Timer/Timer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default function Timer() {
const [timeIsOverModalOpen, setTimeIsOverModalIsOpen] = useState(false);
const [remaining, setRemaining] = useState(time);
const [logTimer, setLogTimer] = useState({ hours: 0, minutes: 0 });
const isWSOpenRef = useRef(true);
const isWSOpenRef = useRef(0);
const timeIsOverAudioRef = useRef(null);
const forcedPausedAudioRef = useRef(null);

Expand Down Expand Up @@ -212,7 +212,7 @@ export default function Timer() {
useEffect(() => {
// Exclude heartbeat message
if (lastJsonMessage && lastJsonMessage.heartbeat === 'pong') {
isWSOpenRef.current = true;
isWSOpenRef.current = 0;
return;
}
/**
Expand All @@ -235,11 +235,11 @@ export default function Timer() {
useEffect(() => {
// This useEffect is to make sure that the WS is open and send a heartbeat every 60 seconds
const interval = setInterval(() => {
if (running && isWSOpenRef.current) {
isWSOpenRef.current = false;
if (running) {
isWSOpenRef.current += 1;
sendHeartbeat();
setTimeout(() => {
if (!isWSOpenRef.current) {
if (isWSOpenRef.current > 3) {
setRunning(false);
setInacModal(true);
getWebSocket().close();
Expand Down

0 comments on commit 3e2f7f1

Please sign in to comment.