Kaynağa Gözat

#1257: Prefer 'probably' over 'maybe' when evaluating Audio support.

Guus der Kinderen 6 yıl önce
ebeveyn
işleme
daa1654d35
2 değiştirilmiş dosya ile 17 ekleme ve 9 silme
  1. 2 0
      CHANGES.md
  2. 15 9
      src/converse-notification.js

+ 2 - 0
CHANGES.md

@@ -1,5 +1,7 @@
 # Changelog
 
+- #1257: Prefer 'probably' over 'maybe' when evaluating audio play support.
+
 ## 4.0.3 (2018-10-22)
 
 - New translations: Arabic, Basque, Czech, French, German, Hungarian, Japanese, Norwegian Bokmål, Polish, Romanian, Spanish

+ 15 - 9
src/converse-notification.js

@@ -109,16 +109,22 @@
                 // XXX Eventually this can be refactored to use Notification's sound
                 // feature, but no browser currently supports it.
                 // https://developer.mozilla.org/en-US/docs/Web/API/notification/sound
-                let audio;
+                let audioOgg, audioMp3, canPlayOgg, canPlayMp3;
                 if (_converse.play_sounds && !_.isUndefined(window.Audio)) {
-                    audio = new Audio(_converse.sounds_path+"msg_received.ogg");
-                    if (audio.canPlayType('audio/ogg')) {
-                        audio.play();
-                    } else {
-                        audio = new Audio(_converse.sounds_path+"msg_received.mp3");
-                        if (audio.canPlayType('audio/mp3')) {
-                            audio.play();
-                        }
+                    audioOgg = new Audio(_converse.sounds_path+"msg_received.ogg");
+                    canPlayOgg = audioOgg.canPlayType('audio/ogg');
+                    audioMp3 = new Audio(_converse.sounds_path+"msg_received.mp3");
+                    canPlayMp3 = audioMp3.canPlayType('audio/mp3');
+
+                    // Prefer 'probably' over 'maybe'.
+                    if ( canPlayOgg === 'probably') {
+                        audioOgg.play();
+                    } else if ( canPlayMp3 === 'probably' ) {
+                        audioMp3.play();
+                    } else if ( canPlayOgg === 'maybe' ) {
+                        audioOgg.play();
+                    } else if ( canPlayMp3 === 'maybe' ) {
+                        audioMp3.play();
                     }
                 }
             };