From a3cc9f8fb1bf45741b08ce6d383c4d7cc8ea8b1f Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 16 Sep 2022 20:46:58 +0200 Subject: optional streams (2, basic functionality) --- client-web/source/resource/mod.ts | 4 ++++ client-web/source/resource/track.ts | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'client-web/source/resource') diff --git a/client-web/source/resource/mod.ts b/client-web/source/resource/mod.ts index d437260..3091a45 100644 --- a/client-web/source/resource/mod.ts +++ b/client-web/source/resource/mod.ts @@ -9,6 +9,8 @@ export type ChannelState = "running" | "disconnected" export abstract class Resource { el: HTMLElement = ediv({ class: ["channel"] }) + on_destroy = () => { } + constructor( public user: User, public info: ProvideInfo, @@ -23,6 +25,8 @@ export abstract class Resource { this._state = value } + destroy() { this.on_destroy() } + abstract create_element(): HTMLElement abstract create_preview(): HTMLElement diff --git a/client-web/source/resource/track.ts b/client-web/source/resource/track.ts index ee87917..f58e020 100644 --- a/client-web/source/resource/track.ts +++ b/client-web/source/resource/track.ts @@ -1,12 +1,27 @@ import { ProvideInfo } from "../../../common/packets.d.ts"; import { ebutton } from "../helper.ts"; import { TrackHandle } from "../track_handle.ts"; +import { LocalUser } from "../user/local.ts"; import { User } from "../user/mod.ts"; import { Resource } from "./mod.ts"; export class TrackResource extends Resource { - constructor(user: User, info: ProvideInfo, public track?: TrackHandle) { + private _track?: TrackHandle + constructor(user: User, info: ProvideInfo, track?: TrackHandle) { super(user, info) + this.track = track + } + + get track() { return this._track } + set track(value: TrackHandle | undefined) { + const handle_end = () => { + this.track = undefined + if (this.user instanceof LocalUser) this.destroy() + } + this._track?.removeEventListener("ended", handle_end) + this._track = value + this._track?.addEventListener("ended", handle_end) + this.update_el() } create_preview(): HTMLElement { -- cgit v1.2.3-70-g09d2