-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactored collectors and sampler * `clientMontior.os` is moved to `clientMonitor.meta.operationSystem` * `clientMontior.engine` is moved to `clientMonitor.meta.engine` * `clientMontior.browser` is moved to `clientMonitor.meta.browser` * `clientMontior.audioInputs` is moved to `clientMonitor.meta.audioInputs` * `clientMontior.audioOutputs` is moved to `clientMonitor.meta.audioOutputs` * `clientMontior.videoInputs` is moved to `clientMonitor.meta.videoInputs` * `clientMonitor.alerts` is removed, `clientMonitor.audioDesyncDetector`, `clientMonitor.cpuPerformanceDetector`, and `clientMonitor.congestionDetector` * all `updates` fields in storage entries are moved to the entries of the `storage` * `metrics` field is removed `elapsedSinceLastCollectInMs` and `elapsedSinceLastSampleInMs` is added to the `stats-collected`, and `sample-created` events * refactored mediasoup-collector * add events are collected automatically * simplified configuration, and detectors configurations are moved to create detectors
- Loading branch information
1 parent
95fb3ba
commit 7da32a3
Showing
72 changed files
with
6,510 additions
and
9,673 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import * as Bowser from "bowser"; | ||
import { createLogger } from "./utils/logger"; | ||
|
||
import { OperationSystem, Browser, Platform, Engine, MediaDevice } from './schema/Samples'; | ||
import { IndexedMap } from "./utils/IndexedMap"; | ||
import { Sampler } from "./Sampler"; | ||
|
||
// import * as proto from "./ProtobufSamples" | ||
const logger = createLogger("ClientDevices"); | ||
|
||
const UNKNOWN_OS: OperationSystem = { | ||
name: "Unkown", | ||
version: undefined, | ||
versionName: undefined, | ||
}; | ||
|
||
const UNKNOWN_BROWSER: Browser = { | ||
name: "Unknown", | ||
version: undefined, | ||
}; | ||
|
||
const UNKNOWN_PLATFORM: Platform = { | ||
type: "Unknown", | ||
vendor: undefined, | ||
model: undefined, | ||
}; | ||
|
||
const UNKNOWN_ENGINE: Engine = { | ||
name: "Unknown", | ||
version: undefined, | ||
}; | ||
|
||
const MEDIA_DEVICE_KIND = 'mediaDeviceKind'; | ||
|
||
export type StoredMediaDevice = MediaDevice & { | ||
sampled: boolean, | ||
} | ||
|
||
export class ClientMetaData { | ||
public readonly operationSystem: OperationSystem; | ||
public readonly browser: Browser; | ||
public readonly platform: Platform; | ||
public readonly engine: Engine; | ||
private readonly _mediaDevices: IndexedMap<string, StoredMediaDevice, MediaDeviceKind>; | ||
|
||
public constructor( | ||
|
||
) { | ||
try { | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
let outerNavigator: any = undefined; | ||
if (navigator !== undefined) outerNavigator = navigator; | ||
else if (window !== undefined && window.navigator !== undefined) outerNavigator = window.navigator; | ||
else throw new Error(`navigator is not available`); | ||
const parsedResult = Bowser.parse(outerNavigator.userAgent); | ||
this.browser = parsedResult.browser; | ||
this.engine = parsedResult.engine; | ||
this.operationSystem = parsedResult.os; | ||
this.platform = parsedResult.platform; | ||
} catch (err) { | ||
logger.warn(`Cannot collect media devices and navigator data, because an error occurred`, err); | ||
this.operationSystem = UNKNOWN_OS; | ||
this.browser = UNKNOWN_BROWSER; | ||
this.platform = UNKNOWN_PLATFORM; | ||
this.engine = UNKNOWN_ENGINE; | ||
} | ||
|
||
this._mediaDevices = new IndexedMap<string, StoredMediaDevice, MediaDeviceKind>() | ||
.addIndex(MEDIA_DEVICE_KIND, (device) => device.kind) | ||
; | ||
|
||
} | ||
|
||
public set mediaDevices(values: MediaDevice[]) { | ||
const visited = new Set<string>(); | ||
for (const mediaDevice of values) { | ||
if (!mediaDevice.id) continue; | ||
visited.add(mediaDevice.id); | ||
if (this._mediaDevices.has(mediaDevice.id)) continue; | ||
this._mediaDevices.set(mediaDevice.id, { | ||
...mediaDevice, | ||
sampled: false, | ||
}); | ||
} | ||
for (const [id] of this._mediaDevices.entries()) { | ||
if (visited.has(id)) continue; | ||
this._mediaDevices.delete(id); | ||
} | ||
} | ||
|
||
public get mediaDevices(): MediaDevice[] { | ||
return Array.from(this._mediaDevices.values()); | ||
} | ||
|
||
/** | ||
* Iterable iterator for the audio input devices obtained by the observer. | ||
*/ | ||
public audioInputs(): IterableIterator<StoredMediaDevice> { | ||
return this._mediaDevices.values(MEDIA_DEVICE_KIND, "audioinput"); | ||
} | ||
|
||
/** | ||
* Iterable iterator for the audio output devices obtained by the observer. | ||
*/ | ||
public audioOutputs(): IterableIterator<StoredMediaDevice> { | ||
return this._mediaDevices.values(MEDIA_DEVICE_KIND, "audiooutput"); | ||
} | ||
|
||
/** | ||
* Iterable iterator for the video input devices obtained by the observer. | ||
*/ | ||
public videoInputs(): IterableIterator<StoredMediaDevice> { | ||
return this._mediaDevices.values(MEDIA_DEVICE_KIND, "videoinput"); | ||
} | ||
} |
Oops, something went wrong.