start of coredump (#2050)
* start of coredump Signed-off-by: Jess Frazelle <github@jessfraz.com> * add local Signed-off-by: Jess Frazelle <github@jessfraz.com> * more coredummp Signed-off-by: Jess Frazelle <github@jessfraz.com> * add arch Signed-off-by: Jess Frazelle <github@jessfraz.com> * os info Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix app version Signed-off-by: Jess Frazelle <github@jessfraz.com> * more webrtc stats Signed-off-by: Jess Frazelle <github@jessfraz.com> * webrtc data Signed-off-by: Jess Frazelle <github@jessfraz.com> * webrtc stats Signed-off-by: Jess Frazelle <github@jessfraz.com> * add wasm function Signed-off-by: Jess Frazelle <github@jessfraz.com> * add coredump things Signed-off-by: Jess Frazelle <github@jessfraz.com> * add hotkey Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * cleanup Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * clippy Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
114
src/lib/coredump.ts
Normal file
114
src/lib/coredump.ts
Normal file
@ -0,0 +1,114 @@
|
||||
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<string> {
|
||||
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<string> {
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user