From af399e3b72c772ed97e943e7d71dc6384ab8ccc0 Mon Sep 17 00:00:00 2001 From: retoor Date: Wed, 29 Jan 2025 17:08:40 +0100 Subject: [PATCH] Added docks. --- src/snek/static/app.js | 30 ++++++++++++++++++++++++------ src/snek/static/message-list.js | 2 +- src/snek/static/schedule.js | 7 ++++--- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/snek/static/app.js b/src/snek/static/app.js index a125c4e..44853f1 100644 --- a/src/snek/static/app.js +++ b/src/snek/static/app.js @@ -345,13 +345,18 @@ class Socket extends EventHandler { } -class App extends EventHandler { - rooms = [] - rest = rest - ws = null - rpc = null +class NotificationAudio { + constructor(timeout){ + if(!timeout) + timeout = 500 + this.schedule = new Schedule(timeout) + } sounds = ["/audio/soundfx.d_beep3.mp3"] - playSound(soundIndex) { + play(soundIndex) { + this.schedule.delay(() => { + + + if (!soundIndex) soundIndex = 0 @@ -364,17 +369,30 @@ class App extends EventHandler { .catch((error) => { console.error("Notification failed:", error); }); + }) } +} + +class App extends EventHandler { + rooms = [] + rest = rest + ws = null + rpc = null + audio = null constructor() { super() this.rooms.push(new Room("General")) this.ws = new Socket() this.rpc = this.ws.client const me = this + this.audio = new NotificationAudio(500) this.ws.addEventListener("channel-message", (data) => { me.emit(data.channel_uid, data) }) } + playSound(index){ + this.audio.play(index) + } async benchMark(times, message) { if (!times) times = 100 diff --git a/src/snek/static/message-list.js b/src/snek/static/message-list.js index 01fe8fb..c4b67cb 100644 --- a/src/snek/static/message-list.js +++ b/src/snek/static/message-list.js @@ -55,7 +55,7 @@ class MessageListElement extends HTMLElement { const text = document.createElement("div") text.classList.add("text") if(message.html) - text.innerHTML = this.linkifyText(message.html) + text.innerHTML = message.html const time = document.createElement("div") time.classList.add("time") time.textContent = message.created_at diff --git a/src/snek/static/schedule.js b/src/snek/static/schedule.js index 0eb41d1..3ed8069 100644 --- a/src/snek/static/schedule.js +++ b/src/snek/static/schedule.js @@ -17,8 +17,8 @@ class Schedule { this.interval = null } cancelDelay() { - clearTimeout(this.interval) - this.interval = null + clearTimeout(this.timeOut) + this.timeOut = null } repeat(func){ if(this.interval){ @@ -35,9 +35,10 @@ class Schedule { } const me = this this.timeOut = setTimeout(()=>{ + func(me.timeOutCount) clearTimeout(me.timeOut) me.timeOut = null - func(me.timeOutCount) + me.cancelDelay() me.timeOutCount = 0 }, this.msDelay)