import { EngineCommandManager } from 'lang/std/engineConnection' import { WebrtcStats } from 'wasm-lib/kcl/bindings/WebrtcStats' import { OsInfo } from 'wasm-lib/kcl/bindings/OsInfo' import { isTauri } from 'lib/isTauri' import { platform as tauriPlatform, arch as tauriArch, version as tauriKernelVersion, } from '@tauri-apps/plugin-os' import { APP_VERSION } from 'routes/Settings' import { UAParser } from 'ua-parser-js' // This is a class for getting all the values from the JS world to pass to the Rust world // for a core dump. export class CoreDumpManager { engineCommandManager: EngineCommandManager constructor(engineCommandManager: EngineCommandManager) { this.engineCommandManager = engineCommandManager } // Get the version of the app from the package.json. version(): string { return APP_VERSION } // Get the os information. getOsInfo(): Promise { if (this.isTauri()) { return tauriArch() .catch((error: any) => { throw new Error(`Error getting arch: ${error}`) }) .then((arch: string) => { return tauriPlatform() .catch((error: any) => { throw new Error(`Error getting platform: ${error}`) }) .then((platform: string) => { return tauriKernelVersion() .catch((error: any) => { throw new Error(`Error getting kernel version: ${error}`) }) .then((kernelVersion: string) => { const osinfo: OsInfo = { platform, arch, version: kernelVersion, } return JSON.stringify(osinfo) }) }) }) } const userAgent = window.navigator.userAgent || 'unknown browser' if (userAgent === 'unknown browser') { const osinfo: OsInfo = { platform: userAgent, arch: userAgent, version: userAgent, } return new Promise((resolve) => resolve(JSON.stringify(osinfo))) } const parser = new UAParser(userAgent) const parserResults = parser.getResult() const osinfo: OsInfo = { platform: parserResults.os.name, arch: parserResults.cpu.architecture, version: parserResults.os.version, browser: userAgent, } return new Promise((resolve) => resolve(JSON.stringify(osinfo))) } isTauri(): boolean { return isTauri() } getWebrtcStats(): Promise { if (!this.engineCommandManager.engineConnection) { throw new Error('Engine connection not initialized') } if (!this.engineCommandManager.engineConnection.webrtcStatsCollector) { throw new Error('Engine webrtcStatsCollector not initialized') } return this.engineCommandManager.engineConnection .webrtcStatsCollector() .catch((error: any) => { throw new Error(`Error getting webrtc stats: ${error}`) }) .then((stats: any) => { const webrtcStats: WebrtcStats = { packets_lost: stats.rtc_packets_lost, frames_received: stats.rtc_frames_received, frame_width: stats.rtc_frame_width, frame_height: stats.rtc_frame_height, frame_rate: stats.rtc_frames_per_second, key_frames_decoded: stats.rtc_keyframes_decoded, frames_dropped: stats.rtc_frames_dropped, pause_count: stats.rtc_pause_count, total_pauses_duration: stats.rtc_total_pauses_duration_sec, freeze_count: stats.rtc_freeze_count, total_freezes_duration: stats.rtc_total_freezes_duration_sec, pli_count: stats.rtc_pli_count, jitter: stats.rtc_jitter_sec, } return JSON.stringify(webrtcStats) }) } }