diff options
Diffstat (limited to 'client-web/source')
-rw-r--r-- | client-web/source/chat.ts | 17 | ||||
-rw-r--r-- | client-web/source/helper.ts | 9 | ||||
-rw-r--r-- | client-web/source/preferences/decl.ts | 4 | ||||
-rw-r--r-- | client-web/source/user/remote.ts | 8 |
4 files changed, 27 insertions, 11 deletions
diff --git a/client-web/source/chat.ts b/client-web/source/chat.ts index e08437b..5776df4 100644 --- a/client-web/source/chat.ts +++ b/client-web/source/chat.ts @@ -1,6 +1,7 @@ import { ChatMessage } from "../../common/packets.d.ts"; -import { ediv, espan, image_view, OverlayUi } from "./helper.ts"; +import { ediv, espan, image_view, notify, OverlayUi } from "./helper.ts"; import { log } from "./logger.ts"; +import { PREFS } from "./preferences/mod.ts"; import { Room } from "./room.ts"; import { User } from "./user/mod.ts"; @@ -60,14 +61,10 @@ export class Chat extends OverlayUi { espan(sender.display_name, { class: "author" }), ": ", ...els )) this.shown = true - this.notify(sender, message) - } - notify(sender: User, message: ChatMessage) { - if (sender.local || document.hasFocus()) return - if (Notification.permission != "granted") return - let body = "(empty message)" - if (message.text) body = message.text - if (message.image) body = "(image)" - new Notification(`keks-meet: ${sender.display_name}`, { body }) + + let body_str = "(empty message)" + if (message.text) body_str = message.text + if (message.image) body_str = "(image)" + if (!sender.local && PREFS.notify_chat) notify(body_str, sender.display_name) } } diff --git a/client-web/source/helper.ts b/client-web/source/helper.ts index 35be473..4075a0f 100644 --- a/client-web/source/helper.ts +++ b/client-web/source/helper.ts @@ -64,3 +64,12 @@ export function image_view(url: string, opts?: Opts): HTMLElement { }) return img } + +export function notify(body: string, author?: string) { + if (document.hasFocus()) return + if (Notification.permission != "granted") return + if (author) + new Notification(`keks-meet: ${author}`, { body }) + else + new Notification(`keks-meet`, { body }) +} diff --git a/client-web/source/preferences/decl.ts b/client-web/source/preferences/decl.ts index 5718a44..82d9c09 100644 --- a/client-web/source/preferences/decl.ts +++ b/client-web/source/preferences/decl.ts @@ -23,4 +23,8 @@ export const PREF_DECLS = { camera_facing_mode: { type: string, possible_values: ["environment", "user"], description: "Prefer user-facing or env-facing camera" }, auto_gain_control: { type: bool, description: "Automatically adjust mic gain" }, echo_cancellation: { type: bool, description: "Cancel echo" }, + + notify_chat: { type: bool, default: true, description: "Send notifications for incoming chat messages" }, + notify_join: { type: bool, default: true, description: "Send notifications when users join" }, + notify_leave: { type: bool, default: true, description: "Send notifications when users leave" }, } diff --git a/client-web/source/user/remote.ts b/client-web/source/user/remote.ts index 2ddf2e6..5ac821c 100644 --- a/client-web/source/user/remote.ts +++ b/client-web/source/user/remote.ts @@ -1,8 +1,10 @@ /// <reference lib="dom" /> import { RelayMessage } from "../../../common/packets.d.ts"; +import { notify } from "../helper.ts"; import { ROOM_CONTAINER, RTC_CONFIG } from "../index.ts" import { log } from "../logger.ts" +import { PREFS } from "../preferences/mod.ts"; import { Room } from "../room.ts" import { TrackHandle } from "../track_handle.ts"; import { User } from "./mod.ts" @@ -40,6 +42,7 @@ export class RemoteUser extends User { this.room.remote_users.delete(this.id) super.leave() ROOM_CONTAINER.removeChild(this.el) + if (PREFS.notify_leave) notify(`${this.display_name} left`) } on_relay(message: RelayMessage) { @@ -47,7 +50,10 @@ export class RemoteUser extends User { if (message.ice_candidate) this.add_ice_candidate(message.ice_candidate) if (message.offer) this.on_offer(message.offer) if (message.answer) this.on_answer(message.answer) - if (message.identify) this.name = message.identify.username + if (message.identify) { + this.name = message.identify.username + if (PREFS.notify_join) notify(`${this.display_name} joined`) + } } async offer() { |