fix(unified-session): address code review feedback

Fixes 3 issues identified in code review:

1. ENV VAR PRECEDENCE: Changed DEFAULT_CONNECTION_CONFIG to use
   undefined for enableUnifiedSession, allowing env var
   BAILEYS_UNIFIED_SESSION_ENABLED to take precedence.
   Priority is now: explicit config > env var > default (true)

2. SINGLE INITIALIZATION: UnifiedSessionManager is now created
   only once, after sendNode is defined. This avoids:
   - Duplicate circuit breaker instances
   - State reinitialization
   - Unnecessary overhead and logs

3. CONTINUOUS TIME SYNC: serverTimeOffset is now updated on
   every received frame that contains a 't' attribute, not just
   on CB:success. This keeps the offset accurate even during
   long-running connections.
This commit is contained in:
Claude
2026-01-24 19:14:02 +00:00
parent 9f17567951
commit 22eda03eb2
2 changed files with 23 additions and 17 deletions
+3 -1
View File
@@ -108,7 +108,9 @@ export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {
// + 10 buffer slots for high-load scenarios = 50 total
maxSocketClientListeners: 50,
// Unified session telemetry (reduces detection of unofficial clients)
enableUnifiedSession: true
// NOTE: undefined means "check env var first, then default to true"
// This allows BAILEYS_UNIFIED_SESSION_ENABLED env var to have precedence
enableUnifiedSession: undefined
}
export const MEDIA_PATH_MAP: { [T in MediaType]?: string } = {