diff --git a/app-template/config-template.xml b/app-template/config-template.xml index ed4b192ba..239f78d6c 100644 --- a/app-template/config-template.xml +++ b/app-template/config-template.xml @@ -72,7 +72,9 @@ - + + + diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index fc92a2287..51c193d4a 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, $stateParams, $window, $state, $log, profileService, bitcore, bitcoreCash, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, bwcError, txConfirmNotification, externalLinkService, firebaseEventsService) { +angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, $stateParams, $window, $state, $log, profileService, bitcore, bitcoreCash, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, bwcError, txConfirmNotification, externalLinkService, firebaseEventsService, soundService) { var countDown = null; var FEE_TOO_HIGH_LIMIT_PER = 15; @@ -624,10 +624,7 @@ angular.module('copayApp.controllers').controller('confirmController', function( (processName == 'sendingTx' && !$scope.wallet.canSign() && !$scope.wallet.isPrivKeyExternal()) ) && !isOn) { $scope.sendStatus = 'success'; - if (config.soundsEnabled && $scope.wallet.coin == 'bch') { - var audio = new Audio('misc/bch_sent.mp3'); - audio.play(); - } + soundService.play('misc/payment_sent.mp3'); firebaseEventsService.logEvent('sent_bitcoin', { coin: $scope.wallet.coin }); $timeout(function() { $scope.$digest(); diff --git a/src/js/controllers/tab-receive.js b/src/js/controllers/tab-receive.js index 32cd5281a..44db9b0bc 100644 --- a/src/js/controllers/tab-receive.js +++ b/src/js/controllers/tab-receive.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('tabReceiveController', function($rootScope, $scope, $timeout, $log, $ionicModal, $state, $ionicHistory, $ionicPopover, storageService, platformInfo, walletService, profileService, configService, lodash, gettextCatalog, popupService, bwcError, bitcoinCashJsService, $ionicNavBarDelegate, txFormatService) { +angular.module('copayApp.controllers').controller('tabReceiveController', function($rootScope, $scope, $timeout, $log, $ionicModal, $state, $ionicHistory, $ionicPopover, storageService, platformInfo, walletService, profileService, configService, lodash, gettextCatalog, popupService, bwcError, bitcoinCashJsService, $ionicNavBarDelegate, txFormatService, soundService) { var listeners = []; $scope.bchAddressType = { type: 'cashaddr' }; @@ -15,22 +15,6 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi var config; - var soundLoaded = false; - var nativeAudioAvailable = (window.plugins && window.plugins.NativeAudio); - - if (nativeAudioAvailable) { - window.plugins.NativeAudio.preloadSimple('received', 'misc/coin_received.mp3', function (msg) { - $log.debug('Receive sound loaded.'); - soundLoaded = true; - }, function (error) { - $log.debug('Error loading receive sound.'); - $log.debug(error); - }); - } else { - $log.debug('isNW: Using HTML5-Audio instead of native audio'); - soundLoaded = true; - } - $scope.displayBalanceAsFiat = true; $scope.requestSpecificAmount = function() { @@ -147,17 +131,7 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi } $scope.paymentReceivedCoin = $scope.wallet.coin; $scope.$apply(function () { - - if (config.soundsEnabled && soundLoaded) { - $log.debug('Play sound.'); - if (nativeAudioAvailable) { - window.plugins.NativeAudio.play('received'); - } else { - new Audio('misc/coin_received.ogg').play(); // NW.js has no mp3 support - } - } else { - $log.debug('Sound is disabled.'); - } + soundService.play('misc/payment_received.mp3'); $scope.showingPaymentReceived = true; }); } diff --git a/src/js/services/soundService.js b/src/js/services/soundService.js new file mode 100644 index 000000000..20318883f --- /dev/null +++ b/src/js/services/soundService.js @@ -0,0 +1,39 @@ +'use strict'; + +angular.module('copayApp.services').service('soundService', function($log, $timeout, platformInfo, configService) { + + var root = {}; + + /** + * Play a sound (when enabled in the configuration) using the Cordova Media-plugin (on Mobile) or html5-audio (on Desktop) relative to the www-root + * Make sure there is a .ogg file as well for NW.js (desktop) implementation + * @param soundFile + */ + root.play = function(soundFile) { + configService.whenAvailable(function(config) { + if (config.soundsEnabled) { + if (platformInfo.isCordova) { + var p = window.location.pathname; + var device_path = p.substring(0, p.lastIndexOf('/')); + var audio = new Media(device_path + '/' + soundFile, + function () { + $log.debug("playAudio(bch_sent):Audio Success"); + }, + function (err) { + $log.debug("playAudio():Audio Error: " + err); + } + ); + audio.play({playAudioWhenScreenIsLocked: false}); // XX SP: "Locked" is also the mute switch in iOS + } else { + if (platformInfo.isNW) { + soundFile = soundFile.substring(0, soundFile.lastIndexOf('.')) + ".ogg"; + $log.debug("Playing .ogg file ("+soundFile+"), as NW.js has no mp3 support"); + } + new Audio(soundFile).play(); + } + } + }); + }; + + return root; +}); \ No newline at end of file diff --git a/www/misc/coin_received.mp3 b/www/misc/payment_received.mp3 similarity index 100% rename from www/misc/coin_received.mp3 rename to www/misc/payment_received.mp3 diff --git a/www/misc/coin_received.ogg b/www/misc/payment_received.ogg similarity index 100% rename from www/misc/coin_received.ogg rename to www/misc/payment_received.ogg diff --git a/www/misc/bch_sent.mp3 b/www/misc/payment_sent.mp3 similarity index 100% rename from www/misc/bch_sent.mp3 rename to www/misc/payment_sent.mp3 diff --git a/www/misc/payment_sent.ogg b/www/misc/payment_sent.ogg new file mode 100644 index 000000000..8527a893c Binary files /dev/null and b/www/misc/payment_sent.ogg differ