Files
InfiniteAPI/src/Types/State.ts
T
João Lucas de Oliveira Lopes 812e53e4eb Refactor: Fix Event Buffer Deadlock with State Machine (#1633)
* feat: implement state machine for chat synchronization and buffer management

* test: Add Jest configuration and tests for connection deadlock handling

- Created a Jest configuration file to set up testing environment.
- Implemented utility functions for creating isolated authentication sessions and mocking WebSocket connections.
- Added a test case to ensure that the connection does not deadlock when history sync is disabled, verifying the correct handling of message events.

* feat: add GitHub Actions workflow for running tests

* chore: sort import lint

* fix: implement timeout handling for AwaitingInitialSync state in chat socket, maybe fix memory leak

* feat: enhance chat synchronization by refining AwaitingInitialSync handling and adding history sync checks
2025-08-07 01:15:41 +03:00

44 lines
1.3 KiB
TypeScript

import { Boom } from '@hapi/boom'
import type { Contact } from './Contact'
export enum SyncState {
/** The socket is connecting, but we haven't received pending notifications yet. */
Connecting,
/** Pending notifications received. Buffering events until we decide whether to sync or not. */
AwaitingInitialSync,
/** The initial app state sync (history, etc.) is in progress. Buffering continues. */
Syncing,
/** Initial sync is complete, or was skipped. The socket is fully operational and events are processed in real-time. */
Online
}
export type WAConnectionState = 'open' | 'connecting' | 'close'
export type ConnectionState = {
/** connection is now open, connecting or closed */
connection: WAConnectionState
/** the error that caused the connection to close */
lastDisconnect?: {
// TODO: refactor and gain independence from Boom
error: Boom | Error | undefined
date: Date
}
/** is this a new login */
isNewLogin?: boolean
/** the current QR code */
qr?: string
/** has the device received all pending notifications while it was offline */
receivedPendingNotifications?: boolean
/** legacy connection options */
legacy?: {
phoneConnected: boolean
user?: Contact
}
/**
* if the client is shown as an active, online client.
* If this is false, the primary phone and other devices will receive notifs
* */
isOnline?: boolean
}