diff --git a/static/js/controllers/appcontroller.js b/static/js/controllers/appcontroller.js index 950a9bb0..e97b9ef6 100644 --- a/static/js/controllers/appcontroller.js +++ b/static/js/controllers/appcontroller.js @@ -56,7 +56,11 @@ define(["jquery", "angular", "underscore"], function($, angular, _) { videoLeakyBucket: true, videoNoiseReduction: false }, - playSoundEffects: true + sound: { + incomingMessages: true, + incomingCall: true, + roomJoinLeave: false + } } }; $scope.master = angular.copy($scope.defaults); @@ -67,6 +71,7 @@ define(["jquery", "angular", "underscore"], function($, angular, _) { $scope.updateStatus(); } $scope.refreshWebrtcSettings(); + $scope.refreshSoundSettings(); }; $scope.reset = function() { diff --git a/static/js/controllers/uicontroller.js b/static/js/controllers/uicontroller.js index f17cc3ee..4f98ebe5 100644 --- a/static/js/controllers/uicontroller.js +++ b/static/js/controllers/uicontroller.js @@ -88,7 +88,8 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web "end": "end1", "dial": "ringtone1", "connect": "connect1", - "prompt": "question1" + "prompt": "question1", + "chatmessage": "message1" }); var displayName = safeDisplayName; @@ -164,6 +165,16 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web }; $scope.refreshWebrtcSettings(); // Call once for bootstrap. + $scope.refreshSoundSettings = function() { + var s = $scope.master.settings.sound; + playSound.disable("chatmessage", !s.incomingMessages); + playSound.disable("ring", !s.incomingCall); + var roomJoinLeave = $scope.peer ? false : s.roomJoinLeave; // Do not play these sounds when in call. + playSound.disable("joined", !roomJoinLeave); + playSound.disable("left", !roomJoinLeave); + }; + $scope.refreshSoundSettings(); // Call once on bootstrap; + var pickupTimeout = null; var autoAcceptTimeout = null; $scope.updateAutoAccept = function(id, from) { @@ -235,12 +246,10 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web // Watch for peer and disable some sounds while there is a peer. if (c && !o) { // New call. - playSound.disable("joined"); - playSound.disable("left"); + $scope.refreshSoundSettings(); } else if (!c && o) { // No longer in call. - playSound.disable("joined", false); - playSound.disable("left", false); + $scope.refreshSoundSettings(); } }); diff --git a/static/js/directives/chat.js b/static/js/directives/chat.js index 2c9bf7b4..d764b09e 100644 --- a/static/js/directives/chat.js +++ b/static/js/directives/chat.js @@ -383,7 +383,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro // Make sure we are not in group chat or the message is from ourselves // before we beep and shout. if (!subscope.isgroupchat && from !== sessionid) { - playSound.play("message1"); + playSound.play("chatmessage"); desktopNotify.notify(translation._("Message from ") + displayName(from), message); appData.e.triggerHandler("uiNotification", ["chatmessage", {from: from, message: message, first: subscope.firstmessage}]); } diff --git a/static/js/services/playsound.js b/static/js/services/playsound.js index e2a021b6..f0fe1eb6 100644 --- a/static/js/services/playsound.js +++ b/static/js/services/playsound.js @@ -28,7 +28,7 @@ define(['underscore', 'Howler', 'require'], function(_, Howler, require) { window.PLAYSOUND = registry; // make available for debug. // playSound - return ["appData", function(appData) { + return [function() { var SoundInterval = function(sound, id, time) { this.sound = sound; @@ -112,17 +112,14 @@ define(['underscore', 'Howler', 'require'], function(_, Howler, require) { }; - Sound.prototype.play = function(id, interval, autostart) { + Sound.prototype.play = function(name, interval, autostart) { if (!this.sound) { - console.log("Play sound but not initialized.", id); - return null; - } - if (!this.shouldPlaySound(id)) { + console.log("Play sound but not initialized.", name); return null; } - id = this.getId(id); + var id = this.getId(name); if (interval) { @@ -137,6 +134,10 @@ define(['underscore', 'Howler', 'require'], function(_, Howler, require) { } else { + if (!this.shouldPlaySound(name) || !this.shouldPlaySound(id)) { + return; + } + var player = this.players[id]; var sound = this.sound; if (!player) { @@ -162,11 +163,10 @@ define(['underscore', 'Howler', 'require'], function(_, Howler, require) { }; Sound.prototype.shouldPlaySound = function(id) { - if (disabled.hasOwnProperty(id) && disabled[id] >= 1) { + if (disabled.all || disabled.hasOwnProperty(id)) { return false; } - var data = appData.get(); - return data && data.master.settings.playSoundEffects; + return true; }; return { @@ -204,19 +204,9 @@ define(['underscore', 'Howler', 'require'], function(_, Howler, require) { return s.play(id, time); }, disable: function(id, status) { - // Disable play back of a certain sound id. Pass status as false to re-enable. - if (!disabled.hasOwnProperty(id)) { - disabled[id] = 0; - } if (status !== false) { - // Increment for disable. - disabled[id]++; + disabled[id] = true; } else { - // Decrement for eenable. - disabled[id]--; - } - if (disabled[id] === 0) { - // Cleanup when 0. delete disabled[id]; } } diff --git a/static/partials/settings.html b/static/partials/settings.html index b4fd34bb..0b997574 100644 --- a/static/partials/settings.html +++ b/static/partials/settings.html @@ -110,16 +110,7 @@ {{_('Set alternative room to join at start.')}} -