|
|
|
@ -17,9 +17,72 @@ module.exports = function(Meta) {
|
|
|
|
|
|
|
|
|
|
Meta.sounds.init = function(callback) {
|
|
|
|
|
if (nconf.get('isPrimary') === 'true') {
|
|
|
|
|
setupSounds(callback);
|
|
|
|
|
} else {
|
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Meta.sounds.getFiles = function(callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
|
fs.readdir(path.join(__dirname, '../../public/sounds'), next);
|
|
|
|
|
},
|
|
|
|
|
function(sounds, next) {
|
|
|
|
|
fs.readdir(path.join(__dirname, '../../public/uploads/sounds'), function(err, uploaded) {
|
|
|
|
|
next(err, sounds.concat(uploaded));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
], function(err, files) {
|
|
|
|
|
var localList = {};
|
|
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.error('Could not get local sound files:' + err.message);
|
|
|
|
|
console.log(err.stack);
|
|
|
|
|
return callback(null, []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return proper paths
|
|
|
|
|
files.forEach(function(filename) {
|
|
|
|
|
localList[filename] = nconf.get('relative_path') + '/sounds/' + filename;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback(null, localList);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Meta.sounds.getMapping = function(callback) {
|
|
|
|
|
db.getObject('settings:sounds', function(err, sounds) {
|
|
|
|
|
if (err || !sounds) {
|
|
|
|
|
// Send default sounds
|
|
|
|
|
var defaults = {
|
|
|
|
|
'notification': 'notification.mp3',
|
|
|
|
|
'chat-incoming': 'waterdrop-high.mp3',
|
|
|
|
|
'chat-outgoing': undefined
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return callback(null, defaults);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, sounds);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function setupSounds(callback) {
|
|
|
|
|
var soundsPath = path.join(__dirname, '../../public/sounds');
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:sounds.get', [], function(err, filePaths) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
|
fs.readdir(path.join(__dirname, '../../public/uploads/sounds'), next);
|
|
|
|
|
},
|
|
|
|
|
function(uploaded, next) {
|
|
|
|
|
uploaded = uploaded.map(function(filename) {
|
|
|
|
|
return path.join(__dirname, '../../public/uploads/sounds', filename);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:sounds.get', uploaded, function(err, filePaths) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.error('Could not initialise sound files:' + err.message);
|
|
|
|
|
return;
|
|
|
|
@ -59,47 +122,7 @@ module.exports = function(Meta) {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Meta.sounds.getFiles = function(callback) {
|
|
|
|
|
// todo: Possibly move these into a bundled module?
|
|
|
|
|
fs.readdir(path.join(__dirname, '../../public/sounds'), function(err, files) {
|
|
|
|
|
var localList = {};
|
|
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.error('Could not get local sound files:' + err.message);
|
|
|
|
|
console.log(err.stack);
|
|
|
|
|
return callback(null, []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return proper paths
|
|
|
|
|
files.forEach(function(filename) {
|
|
|
|
|
localList[filename] = nconf.get('relative_path') + '/sounds/' + filename;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback(null, localList);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Meta.sounds.getMapping = function(callback) {
|
|
|
|
|
db.getObject('settings:sounds', function(err, sounds) {
|
|
|
|
|
if (err || !sounds) {
|
|
|
|
|
// Send default sounds
|
|
|
|
|
var defaults = {
|
|
|
|
|
'notification': 'notification.mp3',
|
|
|
|
|
'chat-incoming': 'waterdrop-high.mp3',
|
|
|
|
|
'chat-outgoing': undefined
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return callback(null, defaults);
|
|
|
|
|
], callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, sounds);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
};
|