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:
Wanjohi
2024-12-08 14:54:56 +03:00
committed by GitHub
parent 5eb21eeadb
commit 379db1c87b
137 changed files with 12737 additions and 5234 deletions

View File

@@ -1,7 +1,7 @@
export class Deferred<T> {
promise: Promise<T>
resolve!: (value: T | PromiseLike<T>) => void
reject!: (reason: any) => void
reject!: (reason: unknown) => void
pending = true
constructor() {
@@ -35,16 +35,19 @@ export class Watch<T> {
update(v: T | ((v: T) => T)) {
if (!this.#next.pending) {
throw new Error("already closed")
throw new Error("closed")
}
// If we're given a function, call it with the current value
let value: T
if (v instanceof Function) {
v = v(this.#current[0])
value = v(this.#current[0])
} else {
value = v
}
const next = new Deferred<WatchNext<T>>()
this.#current = [v, next.promise]
this.#current = [value, next.promise]
this.#next.resolve(this.#current)
this.#next = next
}
@@ -53,6 +56,10 @@ export class Watch<T> {
this.#current[1] = undefined
this.#next.resolve(this.#current)
}
closed() {
return !this.#next.pending
}
}
// Wakes up a multiple consumers.
@@ -88,6 +95,7 @@ export class Queue<T> {
}
async push(v: T) {
if (this.#closed) throw new Error("closed")
const w = this.#stream.writable.getWriter()
await w.write(v)
w.releaseLock()