dont load sound data on cold load

v1.18.x
barisusakli 9 years ago
parent 90f575cae7
commit edf545cd2c

@ -5,31 +5,30 @@ define('sounds', ['buzz'], function(buzz) {
var Sounds = {}; var Sounds = {};
var loadedSounds = {}; var loadedSounds = {};
var eventSoundMapping = {}; var eventSoundMapping;
var files = {}; var files;
loadFiles();
loadMapping();
socket.on('event:sounds.reloadMapping', loadMapping); socket.on('event:sounds.reloadMapping', loadMapping);
function loadFiles() { function loadMapping(callback) {
socket.emit('modules.sounds.getSounds', function(err, sounds) { callback = callback || function() {};
socket.emit('modules.sounds.getMapping', function(err, mapping) {
if (err) { if (err) {
return app.alertError('[sounds] Could not initialise!'); return app.alertError('[sounds] Could not load sound mapping!');
} }
eventSoundMapping = mapping;
files = sounds; callback();
}); });
} }
function loadMapping() { function loadData(callback) {
socket.emit('modules.sounds.getMapping', function(err, mapping) { socket.emit('modules.sounds.getData', function(err, data) {
if (err) { if (err) {
return app.alertError('[sounds] Could not load sound mapping!'); 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 loadFile(fileName, callback) {
function createSound() {
if (files && files[fileName]) {
loadedSounds[fileName] = new buzz.sound(files[fileName]);
}
callback();
}
if (isSoundLoaded(fileName)) { if (isSoundLoaded(fileName)) {
return callback(); return callback();
} }
if (files && files[fileName]) { if (!files || !files[fileName]) {
loadedSounds[fileName] = new buzz.sound(files[fileName]); return loadData(createSound);
} }
callback(); createSound();
} }
Sounds.play = function(name) { Sounds.play = function(name) {
function play() {
Sounds.playFile(eventSoundMapping[name]);
}
if (!config.notificationSounds) { if (!config.notificationSounds) {
return; return;
} }
Sounds.playFile(eventSoundMapping[name]); if (!eventSoundMapping) {
return loadData(play);
}
play();
}; };
Sounds.playFile = function(fileName) { Sounds.playFile = function(fileName) {

@ -99,7 +99,7 @@ module.exports = function(Meta) {
return callback(null, defaults); return callback(null, defaults);
} }
callback.apply(null, arguments); callback(null, sounds);
}); });
}; };
}; };

@ -147,4 +147,11 @@ SocketModules.sounds.getMapping = function(socket, data, callback) {
meta.sounds.getMapping(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; module.exports = SocketModules;

Loading…
Cancel
Save