diff options
author | metamuffin <metamuffin@disroot.org> | 2022-09-16 17:16:38 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-09-16 17:16:38 +0200 |
commit | 969444b32101a45d5917a3947b94bb09c3fc01a1 (patch) | |
tree | ac6d17ad6f3a1535c619aef9eba83179cd4c0878 /client-web/source/resource/mod.ts | |
parent | ff2329cac03703a10ce8b3793d707131403318b4 (diff) | |
download | keks-meet-969444b32101a45d5917a3947b94bb09c3fc01a1.tar keks-meet-969444b32101a45d5917a3947b94bb09c3fc01a1.tar.bz2 keks-meet-969444b32101a45d5917a3947b94bb09c3fc01a1.tar.zst |
optional channels (1)
Diffstat (limited to 'client-web/source/resource/mod.ts')
-rw-r--r-- | client-web/source/resource/mod.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/client-web/source/resource/mod.ts b/client-web/source/resource/mod.ts new file mode 100644 index 0000000..d437260 --- /dev/null +++ b/client-web/source/resource/mod.ts @@ -0,0 +1,48 @@ +import { ProvideInfo } from "../../../common/packets.d.ts" +import { ediv } from "../helper.ts" +import { log } from "../logger.ts" +import { User } from "../user/mod.ts" +import { RemoteUser } from "../user/remote.ts" +import { TrackResource } from "./track.ts" + +export type ChannelState = "running" | "disconnected" + +export abstract class Resource { + el: HTMLElement = ediv({ class: ["channel"] }) + constructor( + public user: User, + public info: ProvideInfo, + ) { + setTimeout(() => this.update_el(), 0) + } + + private _state: ChannelState = "disconnected" + get state() { return this._state } + set state(value: ChannelState) { + if (value != this._state) this.update_el() + this._state = value + } + + abstract create_element(): HTMLElement + abstract create_preview(): HTMLElement + + static create(user: User, info: ProvideInfo): Resource | undefined { + if (info.kind == "audio" || info.kind == "video") return new TrackResource(user, info) + if (info.kind == "file") throw new Error(""); + log({ scope: "media", warn: true }, "unknown resource kind") + } + + request() { + if (!(this.user instanceof RemoteUser)) return + this.user.send_to({ request: { id: this.info.id } }) + } + request_stop() { + if (!(this.user instanceof RemoteUser)) return + this.user.send_to({ request: { id: this.info.id } }) + } + + update_el() { + this.el.innerHTML = "" + this.el.append(this.create_element()) + } +} |