fix: EventEmitter backpressure/drain events not being received by listeners
**Root Cause:** The BaileysEventStream class overrode the on()/off() methods to use a custom handler system (this.handlers Map), but emit() calls used the native EventEmitter. This caused control events (backpressure, drain, dropped, etc) to be emitted but never received by listeners. **Changes:** - Modified on() to use super.on() for control events (backpressure, drain, dropped, batch-processed, retry) - Modified off() to use super.off() for control events - Kept custom handler system for Baileys events (messages.upsert, connection.update, etc) - Now control events use native EventEmitter while Baileys events use custom system **Tests:** - ✅ Backpressure event tests now passing (was timing out before) - ✅ Drain event tests now passing (was timing out before) - Reduced test failures from 34 to 33 https://claude.ai/code/session_015R3U3kiprQiNTTNNt31Sg6
This commit is contained in:
@@ -334,7 +334,14 @@ export class BaileysEventStream extends EventEmitter {
|
||||
/**
|
||||
* Register handler for event type
|
||||
*/
|
||||
on<T = unknown>(event: BaileysEventType | '*', handler: EventHandler<T>): this {
|
||||
on<T = unknown>(event: BaileysEventType | '*' | 'backpressure' | 'drain' | 'dropped' | 'batch-processed' | 'retry', handler: EventHandler<T>): this {
|
||||
// For control events (backpressure, drain, etc), use native EventEmitter
|
||||
if (event === 'backpressure' || event === 'drain' || event === 'dropped' || event === 'batch-processed' || event === 'retry') {
|
||||
super.on(event, handler as any)
|
||||
return this
|
||||
}
|
||||
|
||||
// For Baileys events, use custom handler system
|
||||
if (!this.handlers.has(event)) {
|
||||
this.handlers.set(event, new Set())
|
||||
}
|
||||
@@ -345,7 +352,14 @@ export class BaileysEventStream extends EventEmitter {
|
||||
/**
|
||||
* Remove handler
|
||||
*/
|
||||
off(event: BaileysEventType | '*', handler: EventHandler): this {
|
||||
off(event: BaileysEventType | '*' | 'backpressure' | 'drain' | 'dropped' | 'batch-processed' | 'retry', handler: EventHandler): this {
|
||||
// For control events, use native EventEmitter
|
||||
if (event === 'backpressure' || event === 'drain' || event === 'dropped' || event === 'batch-processed' || event === 'retry') {
|
||||
super.off(event, handler as any)
|
||||
return this
|
||||
}
|
||||
|
||||
// For Baileys events, use custom handler system
|
||||
const handlers = this.handlers.get(event)
|
||||
if (handlers) {
|
||||
handlers.delete(handler)
|
||||
|
||||
Reference in New Issue
Block a user