Commit 30e04551 authored by JC Brand's avatar JC Brand Committed by GitHub

Merge pull request #1258 from guusdk/1257_notifications-prefer-probably-over-maybe

#1257: Prefer 'probably' over 'maybe' when evaluating Audio support.
parents 6904f9a8 ce30b64b
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
- Use [Lerna](https://lernajs.io/) to create the @converse/headless package - Use [Lerna](https://lernajs.io/) to create the @converse/headless package
- Use ES2015 modules instead of UMD. - Use ES2015 modules instead of UMD.
- #1257: Prefer 'probably' over 'maybe' when evaluating audio play support.
## 4.0.3 (2018-10-22) ## 4.0.3 (2018-10-22)
......
...@@ -102,22 +102,27 @@ converse.plugins.add('converse-notification', { ...@@ -102,22 +102,27 @@ converse.plugins.add('converse-notification', {
_converse.isMessageToHiddenChat(message); _converse.isMessageToHiddenChat(message);
}; };
_converse.playSoundNotification = function () { _converse.playSoundNotification = function () {
/* Plays a sound to notify that a new message was recieved. /* Plays a sound to notify that a new message was recieved.
*/ */
// XXX Eventually this can be refactored to use Notification's sound // XXX Eventually this can be refactored to use Notification's sound
// feature, but no browser currently supports it. // feature, but no browser currently supports it.
// https://developer.mozilla.org/en-US/docs/Web/API/notification/sound // https://developer.mozilla.org/en-US/docs/Web/API/notification/sound
let audio;
if (_converse.play_sounds && !_.isUndefined(window.Audio)) { if (_converse.play_sounds && !_.isUndefined(window.Audio)) {
audio = new Audio(_converse.sounds_path+"msg_received.ogg"); const audioOgg = new Audio(_converse.sounds_path+"msg_received.ogg");
if (audio.canPlayType('audio/ogg')) { const canPlayOgg = audioOgg.canPlayType('audio/ogg');
audio.play(); if (canPlayOgg === 'probably') {
} else { return audioOgg.play();
audio = new Audio(_converse.sounds_path+"msg_received.mp3"); }
if (audio.canPlayType('audio/mp3')) { const audioMp3 = new Audio(_converse.sounds_path+"msg_received.mp3");
audio.play(); const canPlayMp3 = audioMp3.canPlayType('audio/mp3');
} if (canPlayMp3 === 'probably') {
audioMp3.play();
} else if (canPlayOgg === 'maybe') {
audioOgg.play();
} else if (canPlayMp3 === 'maybe') {
audioMp3.play();
} }
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment