diff --git a/app/src/about.tsx b/app/src/about.tsx index 3212eb78..db1632de 100644 --- a/app/src/about.tsx +++ b/app/src/about.tsx @@ -8,17 +8,6 @@ import { Canvas } from "./room/canvas"; import { FakeRoom } from "./room/fake"; export function About(): JSX.Element { - const canvas = ; - - const room = new FakeRoom(new Canvas(canvas as HTMLCanvasElement)); - onCleanup(() => room.close()); - - const audioEnabled = solid(room.sound.enabled); - const enableAudio = () => { - room.sound.enabled.set(true); - room.sound.tts.enabled.set(true); - }; - const services = ["Meet", "Zoom", "Teams", "Discord", "Skype", "WebEx", "FaceTime", "WhatsApp"]; const [currentService, setCurrentService] = createSignal(0); @@ -30,6 +19,68 @@ export function About(): JSX.Element { onCleanup(() => clearInterval(interval)); }); + return ( + +
+
+

+ I built hang.live because the internet forgot how to hang out. We forgot how to + be weird. +

+

+ So here's a fun (and free) place to hang out with friends. Spend your free time with{" "} + real people, not doomscrolling feeds of AI slop. Unless you're into that. +

+
+
+
+
+
+ + + Start a hang + +
+
+ + +
+
+ +
+ +
+ +

+ Powered by new and open source web tech:{" "} + MoQ. There's more to live than another {services[currentService()]}{" "} + clone. Crazy, I know. +

+
+
+ ); +} + +function Demo(): JSX.Element { + const canvas = document.createElement("canvas"); + canvas.className = "border-3 border-link-hue rounded-lg w-full h-full"; + canvas.id = "demo"; + const renderer = new Canvas(canvas); + onCleanup(() => renderer.close()); + if (!renderer.supported) return

Interactive demo needs WebGL2.

; + + const room = new FakeRoom(renderer); + onCleanup(() => { + room.close(); + room.sound.close(); + }); + + const audioEnabled = solid(room.sound.enabled); + const enableAudio = () => { + room.sound.enabled.set(true); + room.sound.tts.enabled.set(true); + }; + const random = () => (Math.random() > 0.5 ? -0.5 : 0.5) * (Math.random() * Math.random()); const randomLocation = () => ({ x: random(), y: random() }); const randomLeft = () => ({ x: -0.5 * Math.random() * Math.random(), y: random() }); @@ -231,45 +282,10 @@ export function About(): JSX.Element { }); return ( - -
-
-

- I built hang.live because the internet forgot how to hang out. We forgot how to - be weird. -

-

- So here's a fun (and free) place to hang out with friends. Spend your free time with{" "} - real people, not doomscrolling feeds of AI slop. Unless you're into that. -

-
-
-
-
-
- - - Start a hang - -
-
- - -
-
- -
- - - {canvas} -
- -

- Powered by new and open source web tech:{" "} - MoQ. There's more to live than another {services[currentService()]}{" "} - clone. Crazy, I know. -

-
-
+ <> + + + {canvas} + ); } diff --git a/app/src/components/profile.tsx b/app/src/components/profile.tsx index 29ac8005..13fa94e3 100644 --- a/app/src/components/profile.tsx +++ b/app/src/components/profile.tsx @@ -59,9 +59,11 @@ export default function Profile(props: { local: Local }): JSX.Element { {/* Avatar/Video Preview */} -
-
{canvas}
-
+ Camera preview needs WebGL2.

}> +
+
{canvas}
+
+
{/* Media Controls */}
@@ -117,25 +119,27 @@ export default function Profile(props: { local: Local }): JSX.Element { */ class LocalPreview { canvas: Canvas; - sound: Sound; - space: Space; + sound?: Sound; + space?: Space; signals = new Effect(); constructor(element: HTMLCanvasElement, camera: HangLocalSource) { // Create a minimal canvas without the background effects this.canvas = new Canvas(element); + if (!this.canvas.supported) return; // Create a minimal sound context (muted for preview) this.sound = new Sound(); - this.space = new Space(this.canvas, this.sound, { + const space = new Space(this.canvas, this.sound, { // Not elegant, but disable some of the functionality for this profile preview. profile: true, }); + this.space = space; - const broadcast = this.space.add("local", camera); - this.signals.cleanup(() => this.space.remove("local")); + const broadcast = space.add("local", camera); + this.signals.cleanup(() => space.remove("local")); this.signals.run((effect: Effect) => { const position = effect.get(broadcast.position); @@ -155,8 +159,8 @@ class LocalPreview { close() { this.signals.close(); - this.space.close(); + this.space?.close(); this.canvas.close(); - this.sound.close(); + this.sound?.close(); } } diff --git a/app/src/room/canvas.ts b/app/src/room/canvas.ts index 7a2b1396..64709825 100644 --- a/app/src/room/canvas.ts +++ b/app/src/room/canvas.ts @@ -7,9 +7,12 @@ import { GLContext } from "./gl/context"; export class Canvas { #canvas: HTMLCanvasElement; - #glContext: GLContext; - #camera: Camera; - #backgroundRenderer: BackgroundRenderer; + #glContext?: GLContext; + #camera?: Camera; + #backgroundRenderer?: BackgroundRenderer; + + /** Whether this canvas can render with WebGL2. */ + readonly supported: boolean; // Use a callback to render after the background. onRender?: (now: DOMHighResTimeStamp) => void; @@ -24,14 +27,17 @@ export class Canvas { } get gl(): WebGL2RenderingContext { + if (!this.#glContext) throw new Error("WebGL2 not supported"); return this.#glContext.gl; } get glContext(): GLContext { + if (!this.#glContext) throw new Error("WebGL2 not supported"); return this.#glContext; } - get camera() { + get camera(): Camera { + if (!this.#camera) throw new Error("WebGL2 not supported"); return this.#camera; } @@ -41,10 +47,14 @@ export class Canvas { this.visible = new Signal(false); this.viewport = new Signal(Vector.create(0, 0)); - // Initialize WebGL2 context - this.#glContext = new GLContext(this.#canvas, this.viewport); - this.#camera = new Camera(); - this.#backgroundRenderer = new BackgroundRenderer(this.#glContext); + const glContext = GLContext.create(this.#canvas, this.viewport); + this.#glContext = glContext; + this.supported = glContext !== undefined; + if (!glContext) return; + + const camera = new Camera(); + this.#camera = camera; + this.#backgroundRenderer = new BackgroundRenderer(glContext); const resize = (entries: ResizeObserverEntry[]) => { for (const entry of entries) { @@ -68,14 +78,14 @@ export class Canvas { this.#canvas.height = newHeight; // Update WebGL viewport - this.#glContext.resize(newWidth, newHeight); + glContext.resize(newWidth, newHeight); // The internal logic ignores devicePixelRatio because we automatically scale when rendering. const viewport = Vector.create(newWidth / dpr, newHeight / dpr); this.viewport.set(viewport); // Update camera projection - this.#camera.updateOrtho(viewport); + camera.updateOrtho(viewport); // Render immediately to avoid black flicker during resize if (this.visible.peek()) { @@ -130,6 +140,8 @@ export class Canvas { } #render(now: DOMHighResTimeStamp) { + if (!this.#glContext || !this.#backgroundRenderer) return; + // Clear the screen this.#glContext.clear(); @@ -169,6 +181,6 @@ export class Canvas { close() { this.#signals.close(); - this.#backgroundRenderer.cleanup(); + this.#backgroundRenderer?.cleanup(); } } diff --git a/app/src/room/gl/context.ts b/app/src/room/gl/context.ts index c95c798f..04fd5743 100644 --- a/app/src/room/gl/context.ts +++ b/app/src/room/gl/context.ts @@ -6,7 +6,8 @@ export class GLContext { canvas: HTMLCanvasElement; viewport: Signal; - constructor(canvas: HTMLCanvasElement, viewport: Signal) { + /** Create a context when the browser supports WebGL2. */ + static create(canvas: HTMLCanvasElement, viewport: Signal): GLContext | undefined { const gl = canvas.getContext("webgl2", { alpha: false, antialias: true, @@ -14,10 +15,11 @@ export class GLContext { premultipliedAlpha: false, }); - if (!gl) { - throw new Error("WebGL2 not supported"); - } + if (!gl) return; + return new GLContext(canvas, viewport, gl); + } + private constructor(canvas: HTMLCanvasElement, viewport: Signal, gl: WebGL2RenderingContext) { this.gl = gl; this.canvas = canvas; this.viewport = viewport; diff --git a/app/src/sup.tsx b/app/src/sup.tsx index 74cdacbc..8c2962b3 100644 --- a/app/src/sup.tsx +++ b/app/src/sup.tsx @@ -21,6 +21,8 @@ import { Sound } from "./room/sound"; import Settings from "./settings"; export function Sup(props: { canvas: Canvas; room: string }): JSX.Element { + if (!props.canvas.supported) return ; + const connection = new Moq.Connection.Reload({ enabled: true }); onCleanup(() => connection.close()); @@ -66,6 +68,16 @@ export function Sup(props: { canvas: Canvas; room: string }): JSX.Element { ); } +function WebGLUnsupported(): JSX.Element { + return ( + +

WebGL2 is required

+

This room needs WebGL2 to render video, but it is unavailable in your browser.

+

Use a browser with WebGL2 enabled and reload the page.

+
+ ); +} + function App(props: { connection: Moq.Connection.Reload; canvas: Canvas;