Skip to content

Commit ab2f8c8

Browse files
committed
Restart signalr on tab visible
1 parent 1f14550 commit ab2f8c8

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

frontend/src/components/Contexts/SignalRContext.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { createContext, FC, useContext, useEffect, useCallback, useState,
33
import { AuthContext } from './AuthContext'
44
import { config } from 'config'
55
import { useMsal } from '@azure/msal-react'
6+
import { useOnPageVisible } from 'hooks/usePageVisibility'
67

78
/**
89
* SignalR provides asynchronous communication between backend and frontend. This
@@ -128,6 +129,12 @@ export const SignalRProvider: FC<Props> = ({ children }) => {
128129
}
129130
}, [accounts, inProgress])
130131

132+
useOnPageVisible(() => {
133+
if (!accounts[0] || inProgress !== 'none') return
134+
if (connectionRef.current?.state === signalR.HubConnectionState.Connected) return
135+
resetConnection()
136+
})
137+
131138
const registerEvent = (eventName: string, onMessageReceived: (username: string, message: string) => void) => {
132139
if (connectionRef.current)
133140
connectionRef.current.on(eventName, (username, message) => {

0 commit comments

Comments
 (0)