diff --git a/app/public/config/config.example.js b/app/public/config/config.example.js index 71e2645c..33ddfaa8 100644 --- a/app/public/config/config.example.js +++ b/app/public/config/config.example.js @@ -153,6 +153,26 @@ var config = drawerOverlayed : true, // Position of notifications notificationPosition : 'right', + /** + * Set the notificationSounds. Valid keys are: + * 'parkedPeer', 'parkedPeers', 'raisedHand', 'chatMessage', + * 'sendFile', 'newPeer' and 'default'. + * + * Not defining a key is equivalent to using the default notification sound. + * Setting 'play' to null disables the sound notification. + */ + notificationSounds : { + chatMessage : { + play : '/sounds/notify-chat.mp3', + }, + raisedHand : { + play : '/sounds/notify-hand.mp3', + }, + default : { + delay : 5000, // minimum delay between alert sounds [ms] + play : '/sounds/notify.mp3', + }, + }, // Timeout for autohiding topbar and button control bar hideTimeout : 3000, // max number of participant that will be visible in diff --git a/app/public/sounds/notify-chat.mp3 b/app/public/sounds/notify-chat.mp3 new file mode 100644 index 00000000..8de9039f Binary files /dev/null and b/app/public/sounds/notify-chat.mp3 differ diff --git a/app/public/sounds/notify-hand.mp3 b/app/public/sounds/notify-hand.mp3 new file mode 100644 index 00000000..1fc9438d Binary files /dev/null and b/app/public/sounds/notify-hand.mp3 differ diff --git a/app/src/RoomClient.js b/app/src/RoomClient.js index ddb1487b..2cf26c2c 100644 --- a/app/src/RoomClient.js +++ b/app/src/RoomClient.js @@ -185,8 +185,19 @@ export default class RoomClient // Access code this._accessCode = accessCode; - // Alert sound - this._soundAlert = new Audio('/sounds/notify.mp3'); + // Alert sounds + this._soundAlerts = { 'default': { audio: new Audio('/sounds/notify.mp3') } }; + if ('notificationSounds' in window.config) + { + for (const [ k, v ] of Object.entries(window.config.notificationSounds)) + { + if (v != null && v.play !== undefined) + this._soundAlerts[k] = { + audio : new Audio(v.play), + delay : v.delay ? v.delay: 0 + }; + } + } // Socket.io peer connection this._signalingSocket = null; @@ -597,13 +608,24 @@ export default class RoomClient })); } - _soundNotification() + _soundNotification(type = 'default') { const { notificationSounds } = store.getState().settings; if (notificationSounds) { - const alertPromise = this._soundAlert.play(); + const soundAlert = this._soundAlerts[type] === undefined + ? this._soundAlerts['default'] : this._soundAlerts[type]; + + const now = Date.now(); + + if (soundAlert.last !== undefined && (now - soundAlert.last) < soundAlert.delay) + { + return; + } + soundAlert.last = now; + + const alertPromise = soundAlert.audio.play(); if (alertPromise !== undefined) { @@ -2631,7 +2653,7 @@ export default class RoomClient store.dispatch( roomActions.setToolbarsVisible(true)); - this._soundNotification(); + this._soundNotification(notification.method); store.dispatch(requestActions.notify( { @@ -2673,7 +2695,7 @@ export default class RoomClient store.dispatch( roomActions.setToolbarsVisible(true)); - this._soundNotification(); + this._soundNotification(notification.method); store.dispatch(requestActions.notify( { @@ -2892,7 +2914,7 @@ export default class RoomClient })); } - this._soundNotification(); + this._soundNotification(notification.method); break; } @@ -2912,7 +2934,7 @@ export default class RoomClient { store.dispatch( roomActions.setToolbarsVisible(true)); - this._soundNotification(); + this._soundNotification(notification.method); } break; @@ -2955,7 +2977,7 @@ export default class RoomClient { store.dispatch( roomActions.setToolbarsVisible(true)); - this._soundNotification(); + this._soundNotification(notification.method); } break; @@ -2995,7 +3017,7 @@ export default class RoomClient this._spotlights.newPeer(id); - this._soundNotification(); + this._soundNotification(notification.method); store.dispatch(requestActions.notify( {