From edf545cd2c272604872707e5916c7724e30a37e6 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 20 Oct 2015 18:47:34 -0400 Subject: [PATCH] dont load sound data on cold load --- public/src/modules/sounds.js | 50 +++++++++++++++++++++++------------- src/meta/sounds.js | 2 +- src/socket.io/modules.js | 7 +++++ 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/public/src/modules/sounds.js b/public/src/modules/sounds.js index 3314500ce5..4a6bb80f51 100644 --- a/public/src/modules/sounds.js +++ b/public/src/modules/sounds.js @@ -5,31 +5,30 @@ define('sounds', ['buzz'], function(buzz) { var Sounds = {}; var loadedSounds = {}; - var eventSoundMapping = {}; - var files = {}; - - loadFiles(); - - loadMapping(); + var eventSoundMapping; + var files; socket.on('event:sounds.reloadMapping', loadMapping); - function loadFiles() { - socket.emit('modules.sounds.getSounds', function(err, sounds) { + function loadMapping(callback) { + callback = callback || function() {}; + socket.emit('modules.sounds.getMapping', function(err, mapping) { if (err) { - return app.alertError('[sounds] Could not initialise!'); + return app.alertError('[sounds] Could not load sound mapping!'); } - - files = sounds; + eventSoundMapping = mapping; + callback(); }); } - function loadMapping() { - socket.emit('modules.sounds.getMapping', function(err, mapping) { + function loadData(callback) { + socket.emit('modules.sounds.getData', function(err, data) { if (err) { return app.alertError('[sounds] Could not load sound mapping!'); } - eventSoundMapping = mapping; + eventSoundMapping = data.mapping; + files = data.files; + callback(); }); } @@ -38,22 +37,37 @@ define('sounds', ['buzz'], function(buzz) { } function loadFile(fileName, callback) { + function createSound() { + if (files && files[fileName]) { + loadedSounds[fileName] = new buzz.sound(files[fileName]); + } + callback(); + } + if (isSoundLoaded(fileName)) { return callback(); } - if (files && files[fileName]) { - loadedSounds[fileName] = new buzz.sound(files[fileName]); + if (!files || !files[fileName]) { + return loadData(createSound); } - callback(); + createSound(); } Sounds.play = function(name) { + function play() { + Sounds.playFile(eventSoundMapping[name]); + } + if (!config.notificationSounds) { return; } - Sounds.playFile(eventSoundMapping[name]); + if (!eventSoundMapping) { + return loadData(play); + } + + play(); }; Sounds.playFile = function(fileName) { diff --git a/src/meta/sounds.js b/src/meta/sounds.js index 1449ae21f5..30f1f9e165 100644 --- a/src/meta/sounds.js +++ b/src/meta/sounds.js @@ -99,7 +99,7 @@ module.exports = function(Meta) { return callback(null, defaults); } - callback.apply(null, arguments); + callback(null, sounds); }); }; }; \ No newline at end of file diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js index b0dde46c5c..d7b2c7c03b 100644 --- a/src/socket.io/modules.js +++ b/src/socket.io/modules.js @@ -147,4 +147,11 @@ SocketModules.sounds.getMapping = function(socket, data, callback) { meta.sounds.getMapping(callback); }; +SocketModules.sounds.getData = function(socket, data, callback) { + async.parallel({ + mapping: async.apply(meta.sounds.getMapping), + files: async.apply(meta.sounds.getFiles) + }, callback); +}; + module.exports = SocketModules;