@observertc/observer-js 0.40.0-beta → 0.40.2-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Observer.ts CHANGED
@@ -4,12 +4,14 @@ import { ReportsCollector } from './ReportsCollector';
4
4
  import { EventEmitter } from 'events';
5
5
  import { PartialBy } from './common/utils';
6
6
  import { createCallEndedEventReport, createCallStartedEventReport } from './common/callEventReports';
7
+ import { ObserverSinkContext } from './common/types';
7
8
 
8
9
  const logger = createLogger('Observer');
9
10
 
10
11
  export type ObserverEvents = {
11
12
  'newcall': [ObservedCall],
12
13
  // 'newsfu': [ObservedSfu],
14
+ 'reports': [ObserverSinkContext],
13
15
  'close': [],
14
16
  }
15
17
 
@@ -71,7 +73,11 @@ export class Observer extends EventEmitter {
71
73
  public readonly config: ObserverConfig,
72
74
  ) {
73
75
  super();
76
+ this.setMaxListeners(Infinity);
77
+
74
78
  logger.debug('Observer is created with config', this.config);
79
+
80
+ const onReports = (context: ObserverSinkContext) => this.emit('reports', context);
75
81
  const onNewReport = (collectedReports: number) => {
76
82
  if (!this.config.maxReports || this._closed) return;
77
83
  if (this.config.maxReports < collectedReports) {
@@ -81,8 +87,12 @@ export class Observer extends EventEmitter {
81
87
 
82
88
  this._emitReports();
83
89
 
84
- this.once('close', () => this.reports.off('newreport', onNewReport));
90
+ this.once('close', () => {
91
+ this.reports.off('newreport', onNewReport);
92
+ this.reports.off('reports', onReports);
93
+ });
85
94
  this.reports.on('newreport', onNewReport);
95
+ this.reports.on('reports', onReports);
86
96
  }
87
97
 
88
98
  public createObservedCall<T extends Record<string, unknown> = Record<string, unknown>>(
@@ -138,6 +148,8 @@ export class Observer extends EventEmitter {
138
148
  return logger.debug('Attempted to close twice');
139
149
  }
140
150
  this._closed = true;
151
+
152
+ this._observedCalls.forEach((call) => call.close());
141
153
 
142
154
  this.emit('close');
143
155
  }