Added notification sound.

This commit is contained in:
retoor 2025-01-28 17:37:10 +01:00
parent 5aee606d5d
commit 14c59ba5c0
3 changed files with 20 additions and 9 deletions

View File

@ -22,7 +22,8 @@ class SocketService(BaseService):
async def broadcast(self, channel_uid, message): async def broadcast(self, channel_uid, message):
print("BROADCAT!",message) print("BROADCAT!",message)
count = 0 count = 0
for ws in self.subscriptions.get(channel_uid,[]): subscriptions = set(self.subscriptions.get(channel_uid,[]))
for ws in subscriptions:
try: try:
await ws.send_json(message) await ws.send_json(message)
except Exception as ex: except Exception as ex:

View File

@ -8,6 +8,7 @@ class ChatInputElement extends HTMLElement {
this.shadowRoot.appendChild(this.component); this.shadowRoot.appendChild(this.component);
} }
connectedCallback() { connectedCallback() {
const me = this
const link = document.createElement("link") const link = document.createElement("link")
link.rel = 'stylesheet' link.rel = 'stylesheet'
link.href = '/base.css' link.href = '/base.css'
@ -18,22 +19,31 @@ class ChatInputElement extends HTMLElement {
<textarea placeholder="Type a message..." rows="2"></textarea> <textarea placeholder="Type a message..." rows="2"></textarea>
<button>Send</button> <button>Send</button>
`; `;
this.container.querySelector('textarea').addEventListener('input', (e) => { this.textBox = this.container.querySelector('textarea')
this.textBox.addEventListener('input', (e) => {
this.dispatchEvent(new CustomEvent("input", { detail: e.target.value, bubbles: true })) this.dispatchEvent(new CustomEvent("input", { detail: e.target.value, bubbles: true }))
const message = e.target.value; const message = e.target.value;
const button = this.container.querySelector('button'); const button = this.container.querySelector('button');
button.disabled = !message; button.disabled = !message;
}) })
this.container.querySelector('textarea').addEventListener('change',(e)=>{ this.textBox.addEventListener('change', (e) => {
this.dispatchEvent(new CustomEvent("change", { detail: e.target.value, bubbles: true })) this.dispatchEvent(new CustomEvent("change", { detail: e.target.value, bubbles: true }))
console.error(e.target.value) console.error(e.target.value)
}) })
this.container.querySelector('textarea').addEventListener('keyup', (e) => { this.textBox.addEventListener('keyup', (e) => {
if (e.key == 'Enter' && !e.shiftKey) { if (e.key == 'Enter' && !e.shiftKey) {
this.dispatchEvent(new CustomEvent("submit", { detail: e.target.value, bubbles: true })) this.dispatchEvent(new CustomEvent("submit", { detail: e.target.value, bubbles: true }))
e.target.value = '' e.target.value = ''
} }
}) })
this.container.querySelector('button').addEventListener('click', (e) => {
this.dispatchEvent(new CustomEvent("submit", { detail: me.textBox.value, bubbles: true }))
setTimeout(()=>{
me.textBox.value = ''
me.textBox.focus()
},200)
})
this.component.appendChild(this.container) this.component.appendChild(this.container)
} }
} }

View File

@ -36,7 +36,7 @@ class ChatWindowElement extends HTMLElement {
this.container.appendChild(channelElement) this.container.appendChild(channelElement)
const chatInput = document.createElement('chat-input') const chatInput = document.createElement('chat-input')
chatInput.classList.add("chat-input")
chatInput.addEventListener("submit",(e)=>{ chatInput.addEventListener("submit",(e)=>{
app.rpc.sendMessage(channel.uid,e.detail) app.rpc.sendMessage(channel.uid,e.detail)
}) })