changeset 31:a0820965ba04

notify sound
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 09 Nov 2024 21:35:46 -0700
parents f4708943f29e
children 0f40501b0b56
files src/chat.js src/images/notify.mp3
diffstat 2 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/chat.js	Sat Nov 09 19:17:21 2024 -0700
+++ b/src/chat.js	Sat Nov 09 21:35:46 2024 -0700
@@ -4,6 +4,7 @@
 let currentChatId = null;
 let eventSource;
 let lastUpdate;
+let hasUnseen = false;
 
 function evalEvent(event) {
 	// console.log(event);
@@ -140,8 +141,6 @@
 	input.insertAdjacentHTML('beforebegin',html);
 	fixPosts();
 	input.scrollIntoView({block: 'end'});
-	if( !document.hasFocus() )
-		document.title = title + ' *';
 }
 
 function getChats(chatId,updated) {
@@ -152,6 +151,11 @@
 	}
 	if( updated )
 		lastUpdate = updated;
+	if( !document.hasFocus() && !hasUnseen ) {
+		document.title = title + ' *';
+		notify();
+		hasUnseen = true;
+	}
 }
 
 function gotChats(html) {
@@ -170,6 +174,7 @@
 
 window.onfocus = function() {
 	document.title = title;
+	hasUnseen = false;
 };
 
 let urlRegex = /(^|\s)(https?:\/\/\S+)/g;
@@ -211,3 +216,9 @@
 	document.querySelector('div[posts]').innerHTML = '';
 	ajax('get_chats.js');
 }
+
+let sound = new Audio('/images/notify.mp3');
+function notify() {
+	sound.play();
+}
+
Binary file src/images/notify.mp3 has changed