Skip to content

Commit

Permalink
cosmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
balazskreith committed Mar 9, 2024
1 parent a3e9dd6 commit 7501152
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@observertc/observer-js",
"version": "0.40.1-beta",
"version": "0.40.2-beta",
"description": "Server Side NodeJS Library for processing ObserveRTC Samples",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
14 changes: 12 additions & 2 deletions src/Observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { ReportsCollector } from './ReportsCollector';
import { EventEmitter } from 'events';
import { PartialBy } from './common/utils';
import { createCallEndedEventReport, createCallStartedEventReport } from './common/callEventReports';
import { ObserverSinkContext } from './common/types';

const logger = createLogger('Observer');

export type ObserverEvents = {
'newcall': [ObservedCall],
// 'newsfu': [ObservedSfu],
'reports': [ObserverSinkContext],
'close': [],
}

Expand Down Expand Up @@ -72,8 +74,10 @@ export class Observer extends EventEmitter {
) {
super();
this.setMaxListeners(Infinity);

logger.debug('Observer is created with config', this.config);

const onReports = (context: ObserverSinkContext) => this.emit('reports', context);
const onNewReport = (collectedReports: number) => {
if (!this.config.maxReports || this._closed) return;
if (this.config.maxReports < collectedReports) {
Expand All @@ -83,8 +87,12 @@ export class Observer extends EventEmitter {

this._emitReports();

this.once('close', () => this.reports.off('newreport', onNewReport));
this.once('close', () => {
this.reports.off('newreport', onNewReport);
this.reports.off('reports', onReports);
});
this.reports.on('newreport', onNewReport);
this.reports.on('reports', onReports);
}

public createObservedCall<T extends Record<string, unknown> = Record<string, unknown>>(
Expand Down Expand Up @@ -140,6 +148,8 @@ export class Observer extends EventEmitter {
return logger.debug('Attempted to close twice');
}
this._closed = true;

this._observedCalls.forEach((call) => call.close());

this.emit('close');
}
Expand Down

0 comments on commit 7501152

Please sign in to comment.