MDL-57772 chat: BEEP is back baby!
authorDamyon Wiese <damyon@moodle.com>
Mon, 6 Nov 2017 07:08:55 +0000 (15:08 +0800)
committerDamyon Wiese <damyon@moodle.com>
Tue, 7 Nov 2017 03:25:02 +0000 (11:25 +0800)
mod/chat/beep.mp3 [new file with mode: 0644]
mod/chat/beep.wav [deleted file]
mod/chat/chatd.php
mod/chat/gui_ajax/module.js
mod/chat/gui_header_js/jsupdate.php
mod/chat/gui_header_js/jsupdated.php

diff --git a/mod/chat/beep.mp3 b/mod/chat/beep.mp3
new file mode 100644 (file)
index 0000000..6cfa71d
Binary files /dev/null and b/mod/chat/beep.mp3 differ
diff --git a/mod/chat/beep.wav b/mod/chat/beep.wav
deleted file mode 100644 (file)
index fb48e2b..0000000
Binary files a/mod/chat/beep.wav and /dev/null differ
index 23fbeac..7213186 100644 (file)
@@ -104,7 +104,7 @@ class ChatDaemon {
         $this->_trace_level         = E_ALL ^ E_USER_NOTICE;
         $this->_pcntl_exists        = function_exists('pcntl_fork');
         $this->_time_rest_socket    = 20;
-        $this->_beepsoundsrc        = $GLOBALS['CFG']->wwwroot.'/mod/chat/beep.wav';
+        $this->_beepsoundsrc        = $GLOBALS['CFG']->wwwroot.'/mod/chat/beep.mp3';
         $this->_freq_update_records = 20;
         $this->_freq_poll_idle_chat = $GLOBALS['CFG']->chat_old_ping;
         $this->_stdout = fopen('php://stdout', 'w');
@@ -754,8 +754,11 @@ EOD;
                         $this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL]);
 
                     if ($output->beep) {
+                        $playscript = '(function() { var audioElement = document.createElement("audio");' . "\n";
+                        $playscript .= 'audioElement.setAttribute("src", "'.$this->_beepsoundsrc.'");' . "\n";
+                        $playscript .= 'audioElement.play(); })();' . "\n";
                         $this->write_data($this->conn_sets[$sessionid][CHAT_CONNECTION_CHANNEL],
-                                          '<embed src="'.$this->_beepsoundsrc.'" autostart="true" hidden="true" />');
+                                          '<script>' . $playscript . '</script>');
                     }
 
                     if ($info['quirks'] & QUIRK_CHUNK_UPDATE) {
index 7f4b07e..758df34 100644 (file)
@@ -133,7 +133,9 @@ M.mod_chat_ajax.init = function(Y, cfg) {
             item.addClass((message.mymessage) ? 'mdl-chat-my-entry' : 'mdl-chat-entry');
             Y.one('#messages-list').append(item);
             if (message.type && message.type == 'beep') {
-                Y.one('#chat-notify').setContent('<embed src="../beep.wav" autostart="true" hidden="true" name="beep" />');
+                var audioElement = document.createElement('audio');
+                audioElement.setAttribute('src', '../beep.mp3');
+                audioElement.play();
             }
         },
 
index a7e38f3..726a14b 100644 (file)
@@ -173,7 +173,11 @@ if ($refreshusers) {
     <body>
 <?php
 if ($beep) {
-    echo '<embed src="../beep.wav" autostart="true" hidden="true" name="beep" />';
+    echo '<script> (function() {';
+    echo 'var audioElement = document.createElement("audio");';
+    echo 'audioElement.setAttribute("src", "../beep.mp3");';
+    echo 'audioElement.play(); })();';
+    echo '</script>';
 }
 ?>
        <a href="<?php echo $refreshurlamp ?>" name="refreshLink">Refresh link</a>
index c30de52..3e564c6 100644 (file)
@@ -223,7 +223,11 @@ EOD;
     print "//]]>\n";
     print '</script>' . "\n\n";
     if ($beep) {
-        print '<embed src="../beep.wav" autostart="true" hidden="true" name="beep" />';
+        print '<script> (function() {';
+        print 'var audioElement = document.createElement("audio");';
+        print 'audioElement.setAttribute("src", "../beep.mp3");';
+        print 'audioElement.play(); })();';
+        print '</script>';
     }
     print $CHAT_DUMMY_DATA;
     sleep($CFG->chat_refresh_room);