mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-09 01:49:37 -06:00
fix(baileys): resolve incoming message events not working after reconnection
- Add cleanup logic in mount() to prevent memory leaks from multiple subscriptions - Recreate messageSubject if it was completed during logout - Remount messageProcessor in connectToWhatsapp() to ensure subscription is active after reconnection This fixes the issue where incoming message events stop working after logout and reconnect, while outgoing message events continue to work normally. The root cause was that onDestroy() calls complete() on the RxJS Subject, making it permanently closed. When reconnecting, the Subject would silently ignore all new messages. The fix ensures that: 1. Old subscriptions are properly cleaned up before creating new ones 2. If the Subject is closed, a new one is created automatically 3. The messageProcessor is remounted on every connection to ensure active subscription
This commit is contained in:
parent
3454bec79f
commit
92626fa559
@ -19,6 +19,22 @@ export class BaileysMessageProcessor {
|
|||||||
}>();
|
}>();
|
||||||
|
|
||||||
mount({ onMessageReceive }: MountProps) {
|
mount({ onMessageReceive }: MountProps) {
|
||||||
|
// Se já existe subscription, fazer cleanup primeiro
|
||||||
|
if (this.subscription && !this.subscription.closed) {
|
||||||
|
this.subscription.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Se o Subject foi completado, recriar
|
||||||
|
if (this.messageSubject.closed) {
|
||||||
|
this.processorLogs.warn('MessageSubject was closed, recreating...');
|
||||||
|
this.messageSubject = new Subject<{
|
||||||
|
messages: WAMessage[];
|
||||||
|
type: MessageUpsertType;
|
||||||
|
requestId?: string;
|
||||||
|
settings: any;
|
||||||
|
}>();
|
||||||
|
}
|
||||||
|
|
||||||
this.subscription = this.messageSubject
|
this.subscription = this.messageSubject
|
||||||
.pipe(
|
.pipe(
|
||||||
tap(({ messages }) => {
|
tap(({ messages }) => {
|
||||||
|
|||||||
@ -710,6 +710,11 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
this.loadWebhook();
|
this.loadWebhook();
|
||||||
this.loadProxy();
|
this.loadProxy();
|
||||||
|
|
||||||
|
// Remontar o messageProcessor para garantir que está funcionando após reconexão
|
||||||
|
this.messageProcessor.mount({
|
||||||
|
onMessageReceive: this.messageHandle['messages.upsert'].bind(this),
|
||||||
|
});
|
||||||
|
|
||||||
return await this.createClient(number);
|
return await this.createClient(number);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error);
|
this.logger.error(error);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user