mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-16 18:55:37 +02:00
✨ feat: Add streaming support (#125)
This adds: - [x] Keyboard and mouse handling on the frontend - [x] Video and audio streaming from the backend to the frontend - [x] Input server that works with Websockets Update - 17/11 - [ ] Master docker container to run this - [ ] Steam runtime - [ ] Entrypoint.sh --------- Co-authored-by: Kristian Ollikainen <14197772+DatCaptainHorse@users.noreply.github.com> Co-authored-by: Kristian Ollikainen <DatCaptainHorse@users.noreply.github.com>
This commit is contained in:
54
packages/input/src/latency.ts
Normal file
54
packages/input/src/latency.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
type TimestampEntry = {
|
||||
stage: string;
|
||||
time: Date;
|
||||
};
|
||||
|
||||
export class LatencyTracker {
|
||||
sequence_id: string;
|
||||
timestamps: TimestampEntry[];
|
||||
metadata?: Record<string, any>;
|
||||
|
||||
constructor(sequence_id: string, timestamps: TimestampEntry[] = [], metadata: Record<string, any> = {}) {
|
||||
this.sequence_id = sequence_id;
|
||||
this.timestamps = timestamps;
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
addTimestamp(stage: string): void {
|
||||
const timestamp: TimestampEntry = {
|
||||
stage,
|
||||
time: new Date(),
|
||||
};
|
||||
this.timestamps.push(timestamp);
|
||||
}
|
||||
|
||||
// Calculates the total time between the first and last recorded timestamps.
|
||||
getTotalLatency(): number {
|
||||
if (this.timestamps.length < 2) return 0;
|
||||
|
||||
const times = this.timestamps.map((entry) => entry.time.getTime());
|
||||
const minTime = Math.min(...times);
|
||||
const maxTime = Math.max(...times);
|
||||
return maxTime - minTime;
|
||||
}
|
||||
|
||||
toJSON(): Record<string, any> {
|
||||
return {
|
||||
sequence_id: this.sequence_id,
|
||||
timestamps: this.timestamps.map((entry) => ({
|
||||
stage: entry.stage,
|
||||
// Fill nanoseconds with zeros to match the expected format
|
||||
time: entry.time.toISOString().replace(/\.(\d+)Z$/, ".$1000000Z"),
|
||||
})),
|
||||
metadata: this.metadata,
|
||||
};
|
||||
}
|
||||
|
||||
static fromJSON(json: any): LatencyTracker {
|
||||
const timestamps: TimestampEntry[] = json.timestamps.map((ts: any) => ({
|
||||
stage: ts.stage,
|
||||
time: new Date(ts.time),
|
||||
}));
|
||||
return new LatencyTracker(json.sequence_id, timestamps, json.metadata);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user