mirror of https://github.com/openclaw/openclaw.git
fix(whatsapp): use globalThis singleton for active-listener registry
The WhatsApp active-listener Map is duplicated across multiple Rollup chunks, causing proactive sends to fail with "No active WhatsApp Web listener" — setActiveWebListener() and requireActiveWebListener() resolve to different Map instances in different chunks. Use resolveGlobalMap() (from src/shared/global-singleton.ts) to ensure all chunks share a single listener Map via globalThis, matching the pattern applied to Telegram, Slack, Feishu and other extensions in PR #43683. Also removes dead _currentListener variable (written but never read). Fixes #47313 Relates to #14406, #47389 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
392ddb56e2
commit
5c6769fa33
|
|
@ -1,6 +1,7 @@
|
|||
import { formatCliCommand } from "../../../src/cli/command-format.js";
|
||||
import type { PollInput } from "../../../src/polls.js";
|
||||
import { DEFAULT_ACCOUNT_ID } from "../../../src/routing/session-key.js";
|
||||
import { resolveGlobalMap } from "../../../src/shared/global-singleton.js";
|
||||
|
||||
export type ActiveWebSendOptions = {
|
||||
gifPlayback?: boolean;
|
||||
|
|
@ -28,9 +29,8 @@ export type ActiveWebListener = {
|
|||
close?: () => Promise<void>;
|
||||
};
|
||||
|
||||
let _currentListener: ActiveWebListener | null = null;
|
||||
|
||||
const listeners = new Map<string, ActiveWebListener>();
|
||||
const WA_LISTENERS_KEY = Symbol.for("openclaw.whatsappActiveListeners");
|
||||
const listeners = resolveGlobalMap<string, ActiveWebListener>(WA_LISTENERS_KEY);
|
||||
|
||||
export function resolveWebAccountId(accountId?: string | null): string {
|
||||
return (accountId ?? "").trim() || DEFAULT_ACCOUNT_ID;
|
||||
|
|
@ -73,9 +73,6 @@ export function setActiveWebListener(
|
|||
} else {
|
||||
listeners.set(id, listener);
|
||||
}
|
||||
if (id === DEFAULT_ACCOUNT_ID) {
|
||||
_currentListener = listener;
|
||||
}
|
||||
}
|
||||
|
||||
export function getActiveWebListener(accountId?: string | null): ActiveWebListener | null {
|
||||
|
|
|
|||
Loading…
Reference in New Issue