Hello Folks! I am new here so forgive me if I do not correctly follow your protocol. I have created a live chat on my website. The chat works very well. However, I am attempting to add an 'alarm' of sorts that will indicate when someone either responds to the chat, or enters the chat.
I am attempting to create a setTimeout script that repeats every three seconds. At the beginning of the script I generate the length of the chat log file, decide whether the file is larger than before, then play a sound file if the file is larger than before. The script just keeps repeating the sound file.
My code is as follows...
<script>
(function(){
<?php
$handle = fopen("log.html", "r");
$contents = fread($handle,filesize("log.html"));
fclose($handle);
$strnew = strlen ($contents);
if ($strnew > $strold) { ?>
var aSound = document.createElement('audio');
aSound.setAttribute('src', '/sounds/door_chime.mp3');
aSound.play();
<?php
}
$strold = $strnew;
?>
setTimeout(arguments.callee, 3000);
})
();
</script>