diff --git a/node/src/Consumer.ts b/node/src/Consumer.ts index 0a9d60d832..7964ec92ea 100644 --- a/node/src/Consumer.ts +++ b/node/src/Consumer.ts @@ -173,6 +173,7 @@ export type ConsumerEvents = layerschange: [ConsumerLayers?]; trace: [ConsumerTraceEventData]; rtp: [Buffer]; + listenererror: [string, Error]; // Private events. '@close': []; '@producerclose': []; diff --git a/node/src/DataConsumer.ts b/node/src/DataConsumer.ts index 17a41dd41d..5df47431ff 100644 --- a/node/src/DataConsumer.ts +++ b/node/src/DataConsumer.ts @@ -85,6 +85,7 @@ export type DataConsumerEvents = message: [Buffer, number]; sctpsendbufferfull: []; bufferedamountlow: [number]; + listenererror: [string, Error]; // Private events. '@close': []; '@dataproducerclose': []; diff --git a/node/src/DataProducer.ts b/node/src/DataProducer.ts index 26fc8efd81..66003db76d 100644 --- a/node/src/DataProducer.ts +++ b/node/src/DataProducer.ts @@ -61,6 +61,7 @@ export type DataProducerType = 'sctp' | 'direct'; export type DataProducerEvents = { transportclose: []; + listenererror: [string, Error]; // Private events. '@close': []; }; diff --git a/node/src/EnhancedEventEmitter.ts b/node/src/EnhancedEventEmitter.ts index f2e3a057d5..3460f034ab 100644 --- a/node/src/EnhancedEventEmitter.ts +++ b/node/src/EnhancedEventEmitter.ts @@ -23,8 +23,6 @@ export class EnhancedEventEmitter extends EventEmitte */ safeEmit(eventName: K, ...args: E[K]): boolean { - const numListeners = super.listenerCount(eventName); - try { return super.emit(eventName, ...args); @@ -33,9 +31,19 @@ export class EnhancedEventEmitter extends EventEmitte { logger.error( 'safeEmit() | event listener threw an error [eventName:%s]:%o', - eventName, error); - - return Boolean(numListeners); + eventName, error + ); + + try + { + super.emit('listenererror', eventName, error); + } + catch (error2) + { + // Ignore it. + } + + return Boolean(super.listenerCount(eventName)); } } diff --git a/node/src/Producer.ts b/node/src/Producer.ts index 8f799244bc..149ba0811a 100644 --- a/node/src/Producer.ts +++ b/node/src/Producer.ts @@ -134,6 +134,7 @@ export type ProducerEvents = score: [ProducerScore[]]; videoorientationchange: [ProducerVideoOrientation]; trace: [ProducerTraceEventData]; + listenererror: [string, Error]; // Private events. '@close': []; }; diff --git a/node/src/Router.ts b/node/src/Router.ts index edecf0ce4b..9b836f67ad 100644 --- a/node/src/Router.ts +++ b/node/src/Router.ts @@ -172,6 +172,7 @@ type PipeTransportPair = export type RouterEvents = { workerclose: []; + listenererror: [string, Error]; // Private events. '@close': []; }; diff --git a/node/src/RtpObserver.ts b/node/src/RtpObserver.ts index 4c3d64051c..42ee9f099c 100644 --- a/node/src/RtpObserver.ts +++ b/node/src/RtpObserver.ts @@ -11,6 +11,7 @@ import * as FbsRtpObserver from './fbs/rtp-observer'; export type RtpObserverEvents = { routerclose: []; + listenererror: [string, Error]; // Private events. '@close': []; }; diff --git a/node/src/Transport.ts b/node/src/Transport.ts index 7486cf8065..a0e3449a62 100644 --- a/node/src/Transport.ts +++ b/node/src/Transport.ts @@ -154,6 +154,7 @@ export type TransportEvents = routerclose: []; listenserverclose: []; trace: [TransportTraceEventData]; + listenererror: [string, Error]; // Private events. '@close': []; '@newproducer': [Producer]; diff --git a/node/src/WebRtcServer.ts b/node/src/WebRtcServer.ts index ad45f9e179..abfd064c0f 100644 --- a/node/src/WebRtcServer.ts +++ b/node/src/WebRtcServer.ts @@ -31,6 +31,7 @@ export type WebRtcServerListenInfo = TransportListenInfo; export type WebRtcServerEvents = { workerclose: []; + listenererror: [string, Error]; // Private events. '@close': []; }; diff --git a/node/src/Worker.ts b/node/src/Worker.ts index d4e930970c..a7af360bfb 100644 --- a/node/src/Worker.ts +++ b/node/src/Worker.ts @@ -197,6 +197,7 @@ export type WorkerDump = export type WorkerEvents = { died: [Error]; + listenererror: [string, Error]; // Private events. '@success': []; '@failure': [Error]; diff --git a/node/src/tests/test-DirectTransport.ts b/node/src/tests/test-DirectTransport.ts index 2a8431ddc3..1a92dba8d4 100644 --- a/node/src/tests/test-DirectTransport.ts +++ b/node/src/tests/test-DirectTransport.ts @@ -130,6 +130,24 @@ test('dataProducer.send() succeeds', async () => let lastSentMessageId = 0; let lastRecvMessageId = 0; + console.log('TODO: REMOVE'); + transport2.on('listenererror', (eventName, error) => + { + throw new Error(`------ transport2 listener error [eventName:${eventName}]: ${error}`); + }); + + console.log('TODO: REMOVE'); + dataProducer.on('listenererror', (eventName, error) => + { + throw new Error(`------ dataProducer listener error [eventName:${eventName}]: ${error}`); + }); + + console.log('TODO: REMOVE'); + dataConsumer.on('listenererror', (eventName, error) => + { + throw new Error(`------ dataConsumer listener error [eventName:${eventName}]: ${error}`); + }); + // eslint-disable-next-line no-async-promise-executor await new Promise(async (resolve) => {