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):
print("BROADCAT!",message)
count = 0
for ws in self.subscriptions.get(channel_uid,[]):
subscriptions = set(self.subscriptions.get(channel_uid,[]))
for ws in subscriptions:
try:
await ws.send_json(message)
except Exception as ex:

View File

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

View File

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