From 91259369b2b87eb647e9743c874d7e58894149c1 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 27 Jan 2024 19:59:39 +0100 Subject: handle room joins without page reload. --- client-web/source/chat.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'client-web/source/chat.ts') diff --git a/client-web/source/chat.ts b/client-web/source/chat.ts index 6025878..5d911c6 100644 --- a/client-web/source/chat.ts +++ b/client-web/source/chat.ts @@ -14,11 +14,10 @@ import { Room } from "./room.ts"; import { LocalUser } from "./user/local.ts"; import { User } from "./user/mod.ts"; -export let GLOBAL_CHAT: Chat; - interface ControlMessage { join?: User, leave?: User, + change_room?: string, } export class Chat { @@ -27,8 +26,9 @@ export class Chat { send_el: HTMLInputElement element: HTMLElement - constructor(public room: Room) { - GLOBAL_CHAT = this; + public room?: Room + + constructor() { const send = document.createElement("input") send.ariaLabel = "send message" send.type = "text" @@ -74,8 +74,10 @@ export class Chat { focus() { this.send_el.focus() } send(msg: ChatMessage) { - this.room.local_user.chat(msg) - this.add_message(this.room.local_user, msg) + if (this.room) { + this.room.local_user.chat(msg) + this.add_message(this.room.local_user, msg) + } } remove_oldest_message() { -- cgit v1.2.3-70-g09d2