Spaces:
Runtime error
Runtime error
Nyk commited on
Commit ·
9264288
1
Parent(s): 3fd1706
fix(websocket): declare ping support ref for type safety
Browse files- src/lib/websocket.ts +3 -0
src/lib/websocket.ts
CHANGED
|
@@ -59,6 +59,8 @@ export function useWebSocket() {
|
|
| 59 |
const pingCounterRef = useRef<number>(0)
|
| 60 |
const pingSentTimestamps = useRef<Map<string, number>>(new Map())
|
| 61 |
const missedPongsRef = useRef<number>(0)
|
|
|
|
|
|
|
| 62 |
|
| 63 |
const {
|
| 64 |
connection,
|
|
@@ -116,6 +118,7 @@ export function useWebSocket() {
|
|
| 116 |
|
| 117 |
pingIntervalRef.current = setInterval(() => {
|
| 118 |
if (!wsRef.current || wsRef.current.readyState !== WebSocket.OPEN || !handshakeCompleteRef.current) return
|
|
|
|
| 119 |
|
| 120 |
// Check missed pongs
|
| 121 |
if (missedPongsRef.current >= MAX_MISSED_PONGS) {
|
|
|
|
| 59 |
const pingCounterRef = useRef<number>(0)
|
| 60 |
const pingSentTimestamps = useRef<Map<string, number>>(new Map())
|
| 61 |
const missedPongsRef = useRef<number>(0)
|
| 62 |
+
// Compat flag for gateway versions that may not implement ping RPC.
|
| 63 |
+
const gatewaySupportsPingRef = useRef<boolean>(true)
|
| 64 |
|
| 65 |
const {
|
| 66 |
connection,
|
|
|
|
| 118 |
|
| 119 |
pingIntervalRef.current = setInterval(() => {
|
| 120 |
if (!wsRef.current || wsRef.current.readyState !== WebSocket.OPEN || !handshakeCompleteRef.current) return
|
| 121 |
+
if (!gatewaySupportsPingRef.current) return
|
| 122 |
|
| 123 |
// Check missed pongs
|
| 124 |
if (missedPongsRef.current >= MAX_MISSED_PONGS) {
|