Skip to content

Commit

Permalink
add extension report and clientEventReport methods
Browse files Browse the repository at this point in the history
  • Loading branch information
balazskreith committed Apr 9, 2024
1 parent 68542a6 commit 50040df
Show file tree
Hide file tree
Showing 7 changed files with 74 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.20",
"version": "0.40.22",
"description": "Server Side NodeJS Library for processing ObserveRTC Samples",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
12 changes: 12 additions & 0 deletions src/ObservedCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,6 +90,16 @@ export class ObservedCall<AppData extends Record<string, unknown> = Record<strin
this.emit('close');
}

public addEventReport(params: PartialBy<Omit<CallEventReport, 'serviceId' | 'roomId' | 'callId' >, 'timestamp'>) {
this.reports.addCallEventReport({
...params,
serviceId: this.serviceId,
roomId: this.roomId,
callId: this.callId,
timestamp: params.timestamp ?? Date.now(),
});
}

public createClient<ClientAppData extends Record<string, unknown> = Record<string, unknown>>(config: ObservedClientModel & { appData: ClientAppData, generateClientJoinedReport?: boolean, joined?: number }) {
if (this._closed) throw new Error(`Call ${this.callId} is closed`);

Expand Down
32 changes: 31 additions & 1 deletion src/ObservedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -214,6 +215,35 @@ export class ObservedClient<AppData extends Record<string, unknown> = Record<str
this.emit('close');
}

public addEventReport(params: PartialBy<Omit<CallEventReport, 'serviceId' | 'roomId' | 'callId' | 'clientId' | 'userId' | 'marker'>, '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<string, unknown>) {
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({
Expand Down
18 changes: 17 additions & 1 deletion src/ObservedPeerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{
Expand Down Expand Up @@ -187,6 +188,21 @@ export class ObservedPeerConnection extends EventEmitter {
this.ICE.marker = value;
}

public addEventReport(params: PartialBy<Omit<CallEventReport, 'serviceId' | 'roomId' | 'callId' | 'clientId' | 'userId' | 'peerConnectionId' | 'marker'>, '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;
}
Expand Down
11 changes: 11 additions & 0 deletions src/ObservedSfu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,6 +98,16 @@ export class ObservedSfu<AppData extends Record<string, unknown> = Record<string
this.emit('close');
}

public addEventReport(params: PartialBy<Omit<SfuEventReport, 'serviceId' | 'sfuId' | 'marker'>, '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`);
Expand Down
1 change: 1 addition & 0 deletions src/monitors/CallSummaryMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class CallSummaryMonitor extends EventEmitter {
public readonly config: CallSummaryMonitorConfig = {},
) {
super();
this.setMaxListeners(Infinity);
}

public addCall(call: ObservedCall) {
Expand Down
1 change: 1 addition & 0 deletions src/monitors/TurnUsageMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class TurnUsageMonitor extends EventEmitter {
private _closed = false;
public constructor() {
super();
this.setMaxListeners(Infinity);
}

public getStats(): TurnStats[] {
Expand Down

0 comments on commit 50040df

Please sign in to comment.