From 50040df0a169495864665407a0616048a22042fd Mon Sep 17 00:00:00 2001 From: Balazs Kreith Date: Tue, 9 Apr 2024 14:53:15 +0300 Subject: [PATCH] add extension report and clientEventReport methods --- package.json | 2 +- src/ObservedCall.ts | 12 +++++++++++ src/ObservedClient.ts | 32 +++++++++++++++++++++++++++++- src/ObservedPeerConnection.ts | 18 ++++++++++++++++- src/ObservedSfu.ts | 11 ++++++++++ src/monitors/CallSummaryMonitor.ts | 1 + src/monitors/TurnUsageMonitor.ts | 1 + 7 files changed, 74 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index bf33a17..ccc1871 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@observertc/observer-js", - "version": "0.40.20", + "version": "0.40.22", "description": "Server Side NodeJS Library for processing ObserveRTC Samples", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/ObservedCall.ts b/src/ObservedCall.ts index 421f101..7e8e41b 100644 --- a/src/ObservedCall.ts +++ b/src/ObservedCall.ts @@ -3,6 +3,8 @@ import { ObservedClient, ObservedClientModel } from './ObservedClient'; import { ObservedOutboundTrack } from './ObservedOutboundTrack'; import { Observer } from './Observer'; import { createClientJoinedEventReport } from './common/callEventReports'; +import { PartialBy } from './common/utils'; +import { CallEventReport } from '@observertc/report-schemas-js'; export type ObservedCallModel = { serviceId: string; @@ -88,6 +90,16 @@ export class ObservedCall = Record, 'timestamp'>) { + this.reports.addCallEventReport({ + ...params, + serviceId: this.serviceId, + roomId: this.roomId, + callId: this.callId, + timestamp: params.timestamp ?? Date.now(), + }); + } + public createClient = Record>(config: ObservedClientModel & { appData: ClientAppData, generateClientJoinedReport?: boolean, joined?: number }) { if (this._closed) throw new Error(`Call ${this.callId} is closed`); diff --git a/src/ObservedClient.ts b/src/ObservedClient.ts index cdf73aa..32ae574 100644 --- a/src/ObservedClient.ts +++ b/src/ObservedClient.ts @@ -5,11 +5,12 @@ import { ObservedPeerConnection } from './ObservedPeerConnection'; import { createLogger } from './common/logger'; import { CallMetaType, createCallMetaReport } from './common/callMetaReports'; // eslint-disable-next-line camelcase -import { isValidUuid } from './common/utils'; +import { PartialBy, isValidUuid } from './common/utils'; import { createClientLeftEventReport } from './common/callEventReports'; import { CallEventType } from './common/CallEventType'; import { ObservedSfu } from './ObservedSfu'; import { ClientIssue } from './monitors/CallSummary'; +import { CallEventReport } from '@observertc/report-schemas-js'; const logger = createLogger('ObservedClient'); @@ -214,6 +215,35 @@ export class ObservedClient = Record, 'timestamp'>) { + this.reports.addCallEventReport({ + ...params, + serviceId: this.serviceId, + mediaUnitId: this.mediaUnitId, + roomId: this.roomId, + callId: this.callId, + clientId: this.clientId, + userId: this.userId, + timestamp: params.timestamp ?? Date.now(), + marker: this.marker, + }); + } + + public addExtensionStatsReport(extensionType: string, payload: Record) { + this.reports.addClientExtensionReport({ + serviceId: this.serviceId, + mediaUnitId: this.mediaUnitId, + roomId: this.roomId, + callId: this.callId, + clientId: this.clientId, + userId: this.userId, + timestamp: Date.now(), + extensionType, + payload: JSON.stringify(payload), + marker: this.marker, + }); + } + public addIssue(issue: ClientIssue) { try { this.reports.addCallEventReport({ diff --git a/src/ObservedPeerConnection.ts b/src/ObservedPeerConnection.ts index eb8e168..4e47290 100644 --- a/src/ObservedPeerConnection.ts +++ b/src/ObservedPeerConnection.ts @@ -3,9 +3,10 @@ import { PeerConnectionTransport } from '@observertc/sample-schemas-js'; import { ObservedClient } from './ObservedClient'; import { ObservedInboundTrack, ObservedInboundTrackModel } from './ObservedInboundTrack'; import { ObservedOutboundTrack, ObservedOutboundTrackModel } from './ObservedOutboundTrack'; -import { PeerConnectionTransportReport } from '@observertc/report-schemas-js'; +import { CallEventReport, PeerConnectionTransportReport } from '@observertc/report-schemas-js'; import { ObservedICE } from './ObservedICE'; import { ObservedDataChannel } from './ObservedDataChannel'; +import { PartialBy } from './common/utils'; export type ObservedPeerConnectionEvents = { update: [{ @@ -187,6 +188,21 @@ export class ObservedPeerConnection extends EventEmitter { this.ICE.marker = value; } + public addEventReport(params: PartialBy, 'timestamp'>) { + this.reports.addCallEventReport({ + ...params, + serviceId: this.serviceId, + mediaUnitId: this.mediaUnitId, + roomId: this.roomId, + callId: this.callId, + clientId: this.clientId, + userId: this.client.userId, + peerConnectionId: this.peerConnectionId, + marker: this.client.marker, + timestamp: params.timestamp ?? Date.now(), + }); + } + public get closed() { return this._closed; } diff --git a/src/ObservedSfu.ts b/src/ObservedSfu.ts index 929e703..7bbc3a3 100644 --- a/src/ObservedSfu.ts +++ b/src/ObservedSfu.ts @@ -3,6 +3,7 @@ import { Observer } from './Observer'; import { SfuSample } from '@observertc/sample-schemas-js'; import { ObservedSfuTransport, ObservedSfuTransportModel } from './ObservedSfuTransport'; import { SfuEventReport, SfuExtensionReport } from '@observertc/report-schemas-js'; +import { PartialBy } from './common/utils'; export type ObservedSfuModel= { serviceId: string; @@ -97,6 +98,16 @@ export class ObservedSfu = Record, 'timestamp'>) { + this.reports.addCallEventReport({ + ...params, + serviceId: this.serviceId, + mediaUnitId: this.mediaUnitId, + marker: this.marker, + timestamp: params.timestamp ?? Date.now(), + }); + } + public update(sample: SfuSample) { if (this._closed) throw new Error(`Sfu ${this.sfuId} is closed`); if (sample.sfuId !== this.sfuId) throw new Error(`Sfu ${this.sfuId} is not the same as sample.sfuId`); diff --git a/src/monitors/CallSummaryMonitor.ts b/src/monitors/CallSummaryMonitor.ts index 9d3a5af..5aae73d 100644 --- a/src/monitors/CallSummaryMonitor.ts +++ b/src/monitors/CallSummaryMonitor.ts @@ -30,6 +30,7 @@ export class CallSummaryMonitor extends EventEmitter { public readonly config: CallSummaryMonitorConfig = {}, ) { super(); + this.setMaxListeners(Infinity); } public addCall(call: ObservedCall) { diff --git a/src/monitors/TurnUsageMonitor.ts b/src/monitors/TurnUsageMonitor.ts index d5bd9c3..3791548 100644 --- a/src/monitors/TurnUsageMonitor.ts +++ b/src/monitors/TurnUsageMonitor.ts @@ -53,6 +53,7 @@ export class TurnUsageMonitor extends EventEmitter { private _closed = false; public constructor() { super(); + this.setMaxListeners(Infinity); } public getStats(): TurnStats[] {