Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
balazskreith committed Jan 14, 2025
1 parent b3d974d commit 35f4992
Show file tree
Hide file tree
Showing 49 changed files with 817 additions and 4,184 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Table of Contents:
- [Quick Start](#quick-start)
- [Integrations](#integrations)
- [Mediasoup](#mediasoup)
- [Configuration](#configurations)
- [Developer Manual](#developer-manual)
- [API Manual](#api-manual)
<!--
- [Collected Metrics](#collected-metrics)
- [Calculated updates](#calculated-updates)
- [PeerConnection Entry](#peerconnection-entry)
Expand All @@ -20,16 +24,14 @@ Table of Contents:
- [Video Freeze Detector](#video-freeze-detector)
- [Stucked Inbound Track Detector](#stucked-inbound-track-detector)
- [Issues](#issues)
- [Configurations](#configurations)
- [Events](#events)
- [CLIENT_JOINED Event](#client_joined-event)
- [CLIENT_LEFT Event](#client_left-event)
- [Custom Call Event](#custom-call-event)
- [Extension Stats Event](#extension-stats-event)
- [Sampling](#sampling)
- [Sampling](#sampling) -->
- [NPM package](#npm-package)
- [API docs](#api-docs)
- [Schemas](#schemas)
- [Getting Involved](#getting-involved)
- [License](#license)

Expand All @@ -52,7 +54,7 @@ Add `@observertc/client-monitor-js` to your WebRTC app.
```javascript
import { createClientMonitor } from "@observertc/client-monitor-js";
const monitor = createClientMonitor();
const collector = monitor.collectors.addRTCPeerConnection(peerConnection);
const collector = monitor.sources.addRTCPeerConnection(peerConnection);

monitor.on("stats-collected", () => {
console.log(`Sending audio bitrate: ${monitor.sendingAudioBitrate}`);
Expand Down
26 changes: 25 additions & 1 deletion src/ClientMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { AcceptedClientEvent, AcceptedClientIssue, AcceptedClientMetaData, Clien
import { PeerConnectionMonitor } from './monitors/PeerConnectionMonitor';
import { ClientEventType } from './utils/enums';
import { ClientMonitorConfig } from './ClientMonitorConfig';
import { StatsAdapters } from './collectors/StatsAdapters';
import { StatsAdapters } from './adapters/StatsAdapters';
import { Sources } from './sources/Sources';
import { PartialBy } from './utils/common';
import { Detectors } from './detectors/Detectors';
import { CpuPerformanceDetector } from './detectors/CpuPerformanceDetector';
import { OutboundTrackMonitor } from './monitors/OutboundTrackMonitor';
import { InboundTrackMonitor } from './monitors/InboundTrackMonitor';

const logger = createLogger('ClientMonitor');

Expand All @@ -25,6 +27,8 @@ export class ClientMonitor extends EventEmitter {
public readonly sources: Sources;
public readonly statsAdapters = new StatsAdapters();
public readonly mappedPeerConnections = new Map<string, PeerConnectionMonitor>();
public readonly mappedOutboundTracks = new Map<string, OutboundTrackMonitor>();
public readonly mappedInboundTracks = new Map<string, InboundTrackMonitor>();
public readonly detectors:Detectors;

public clientId?: string;
Expand Down Expand Up @@ -302,6 +306,26 @@ export class ClientMonitor extends EventEmitter {
return [ ...this.peerConnections.flatMap(peerConnection => peerConnection.certificates) ];
}

public get tracks() {
return [
...this.mappedInboundTracks.values(),
...this.mappedOutboundTracks.values(),
]
}

public getTrackMonitor(trackId: string) {
return this.mappedInboundTracks.get(trackId) ??
this.mappedOutboundTracks.get(trackId);
}

public getInboundTrackMonitor(trackId: string) {
return this.mappedInboundTracks.get(trackId);
}

public getOutboundTrackMonitor(trackId: string) {
return this.mappedOutboundTracks.get(trackId);
}


private _setupTimer(): void {
this._timer && clearInterval(this._timer);
Expand Down
16 changes: 16 additions & 0 deletions src/ClientMonitorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ export type ClientMonitorConfig = {

audioDesyncDetector: {
disabled?: boolean,
/**
* The fractional threshold used to determine if the audio desynchronization
* correction is considered significant or not.
* It represents the minimum required ratio of corrected samples to total samples.
* For example, a value of 0.1 means that if the corrected samples ratio
* exceeds 0.1, it will be considered a significant audio desynchronization issue.
*/
fractionalCorrectionAlertOnThreshold: number;
/**
* The fractional threshold used to determine if the audio desynchronization
* correction is considered negligible and the alert should be turned off.
* It represents the maximum allowed ratio of corrected samples to total samples.
* For example, a value of 0.05 means that if the corrected samples ratio
* falls below 0.05, the audio desynchronization alert will be turned off.
*/
fractionalCorrectionAlertOffThreshold: number;
}

congestionDetector: {
Expand Down
7 changes: 4 additions & 3 deletions src/ClientMonitorEvents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { InboundRtpMonitor } from "./monitors/InboundRtpMonitor";
import { InboundTrackMonitor } from "./monitors/InboundTrackMonitor";
import { PeerConnectionMonitor } from "./monitors/PeerConnectionMonitor";
import { ClientSample } from "./schema/ClientSample"
import { RtcStats } from "./schema/W3cStatsIdentifiers";
Expand Down Expand Up @@ -43,16 +44,16 @@ export type ClientMonitorEvents = {
}],
'cpulimitation': [],
'audio-desync': [{
trackId: string,
inboundRtp: InboundRtpMonitor,
}],
'freezed-video': [{
inboundRtp: InboundRtpMonitor,
}],
'stucked-inbound-track': [{
inboundRtp: InboundRtpMonitor,
inboundTrack: InboundTrackMonitor,
}],
'too-long-pc-connection-establishment': [{
peerConnection: PeerConnectionMonitor,
peerConnection: PeerConnectionMonitor,
}]

}
Loading

0 comments on commit 35f4992

Please sign in to comment.