From 3bb824484f4dd9fc60035e164f4ad8354f319304 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 3 Mar 2016 08:18:41 -0500 Subject: [PATCH 1/3] Added very basic audio notifications. This plays the same message.ogg/message.mp3 regardless of event type. It also does not check the user's event settings (LOUD/OFF/etc), instead playing a sound upon every single notification. Clearly, it still needs some work. Signed-off-by: Andrew Johnson --- src/Notifier.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Notifier.js b/src/Notifier.js index b64a001a5f..8e60aee24c 100644 --- a/src/Notifier.js +++ b/src/Notifier.js @@ -83,15 +83,24 @@ var Notifier = { }); global.focus(); }; - - /*var audioClip; - - if (audioNotification) { - audioClip = playAudio(audioNotification); - }*/ + + var playAudio = function() { + var e = document.getElementById("messageAudio"); + if (e) { + e.load(); + e.play(); + return e; + } + }; + + var audioClip; + audioClip = playAudio(); global.setTimeout(function() { notification.close(); + if (audioClip) { + audioClip.pause(); + } }, 5 * 1000); }, From 2a1e8ef39b0a285f70ba75bddc64bd6453c0400f Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 4 Mar 2016 15:29:33 +0000 Subject: [PATCH 2/3] Make audio notifs only play if the sound tweak is set --- src/Notifier.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Notifier.js b/src/Notifier.js index 8e60aee24c..3dbbf5cb82 100644 --- a/src/Notifier.js +++ b/src/Notifier.js @@ -35,7 +35,7 @@ var Notifier = { return TextForEvent.textForEvent(ev); }, - displayNotification: function(ev, room) { + displayNotification: function(ev, room, actions) { if (!global.Notification || global.Notification.permission != 'granted') { return; } @@ -94,7 +94,9 @@ var Notifier = { }; var audioClip; - audioClip = playAudio(); + if (actions.tweaks.sound) { + audioClip = playAudio(); + } global.setTimeout(function() { notification.close(); @@ -207,7 +209,7 @@ var Notifier = { var actions = MatrixClientPeg.get().getPushActionsForEvent(ev); if (actions && actions.notify) { - this.displayNotification(ev, room); + this.displayNotification(ev, room, actions); } } }; @@ -216,4 +218,4 @@ if (!global.mxNotifier) { global.mxNotifier = Notifier; } -module.exports = global.mxNotifier; \ No newline at end of file +module.exports = global.mxNotifier; From 69a8d654073386843111aaed50aac9e5a4a7f03c Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 4 Mar 2016 18:16:02 +0000 Subject: [PATCH 3/3] Don't pause the audio when we hide the notif: shouldn't be necessary and could cause sound to stop mid-way if a prior notif times out while the sound from a later one is playing. --- src/Notifier.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Notifier.js b/src/Notifier.js index 3dbbf5cb82..1c35bd7509 100644 --- a/src/Notifier.js +++ b/src/Notifier.js @@ -100,9 +100,6 @@ var Notifier = { global.setTimeout(function() { notification.close(); - if (audioClip) { - audioClip.pause(); - } }, 5 * 1000); },