Node.js based forum software built for the modern web
allowing plugins to define new sounds -- woot.
Julian Lamdf8728c78518
diff --git a/package.json b/package.jsonindex 5df4aaa5f5..e8202d8648 100644--- a/package.json+++ b/package.json@@ -43,6 +43,7 @@"nodebb-widget-essentials": "~0.0.21","nodebb-theme-vanilla": "~0.0.19","nodebb-theme-lavender": "~0.0.25",+ "nodebb-plugin-soundpack-default": "~0.1.0","less": "~1.6.3","daemon": "~1.1.0","underscore": "~1.6.0",diff --git a/public/sounds/notification.wav b/public/sounds/notification.wavdeleted file mode 100644index c6ba307524..0000000000Binary files a/public/sounds/notification.wav and /dev/null differdiff --git a/public/sounds/waterdrop-high.wav b/public/sounds/waterdrop-high.wavdeleted file mode 100644index 581addfc89..0000000000Binary files a/public/sounds/waterdrop-high.wav and /dev/null differdiff --git a/public/sounds/waterdrop-low.wav b/public/sounds/waterdrop-low.wavdeleted file mode 100644index cb50a587a6..0000000000Binary files a/public/sounds/waterdrop-low.wav and /dev/null differdiff --git a/src/controllers/admin.js b/src/controllers/admin.jsindex a326029f97..a4954c4946 100644--- a/src/controllers/admin.js+++ b/src/controllers/admin.js@@ -156,7 +156,7 @@ adminController.groups.get = function(req, res, next) {};adminController.sounds.get = function(req, res, next) {- meta.sounds.getLocal(function(err, sounds) {+ meta.sounds.getFiles(function(err, sounds) {sounds = Object.keys(sounds).map(function(name) {return {name: namediff --git a/src/meta.js b/src/meta.jsindex 4f2a25f7e9..835bbc5f60 100644--- a/src/meta.js+++ b/src/meta.js@@ -8,6 +8,8 @@ var fs = require('fs'),_ = require('underscore'),less = require('less'),fork = require('child_process').fork,+ rimraf = require('rimraf'),+ mkdirp = require('mkdirp'),utils = require('./../public/src/utils'),translator = require('./../public/src/translator'),@@ -366,7 +368,42 @@ var fs = require('fs'),/* Sounds */Meta.sounds = {};- Meta.sounds.getLocal = function(callback) {+ Meta.sounds.init = function() {+ var soundsPath = path.join(__dirname, '../public/sounds');++ plugins.fireHook('filter:sounds.get', [], function(err, filePaths) {+ if (err) {+ winston.error('Could not initialise sound files:' + err.message);+ }++ // Clear the sounds directory+ async.series([+ function(next) {+ rimraf(soundsPath, next);+ },+ function(next) {+ mkdirp(soundsPath, next);+ }+ ], function(err) {+ if (err) {+ winston.error('Could not initialise sound files:' + err.message);+ }++ // Link paths+ async.each(filePaths, function(filePath, next) {+ fs.symlink(filePath, path.join(soundsPath, path.basename(filePath)), 'file', next);+ }, function(err) {+ if (!err) {+ winston.info('[sounds] Sounds OK');+ } else {+ winston.error('[sounds] Could not initialise sounds: ' + err.message);+ }+ });+ });+ });+ };++ 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 = {};diff --git a/src/routes/debug.js b/src/routes/debug.jsindex 0e9dc0920f..5198dbd3dc 100644--- a/src/routes/debug.js+++ b/src/routes/debug.js@@ -54,14 +54,8 @@ module.exports = function(app, middleware, controllers) {});app.get('/test', function(req, res) {- var groups = require('../groups');-- groups.list({- showAllGroups: true- }, function(err, groups) {- res.json(200, groups);- });- // res.send(200);+ require('../meta').sounds.init();+ res.send(200);});});};\ No newline at end of filediff --git a/src/socket.io/modules.js b/src/socket.io/modules.jsindex 7dea871b32..e8952ff9a1 100644--- a/src/socket.io/modules.js+++ b/src/socket.io/modules.js@@ -224,7 +224,7 @@ SocketModules.notifications.mark_all_read = function(socket, data, callback) {/* Sounds */SocketModules.sounds.getSounds = function(socket, data, callback) {// Read sounds from local directory- meta.sounds.getLocal(callback);+ meta.sounds.getFiles(callback);};SocketModules.sounds.getMapping = function(socket, data, callback) {diff --git a/src/webserver.js b/src/webserver.jsindex 6dacf88c22..13c3b7a128 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -42,6 +42,13 @@ if(nconf.get('ssl')) {notifications.init();user.startJobs();+ // Preparation dependent on plugins+ plugins.ready(function() {+ meta.js.minify(app.enabled('minification'));+ meta.css.minify();+ meta.sounds.init();+ });+async.series({themesData: meta.themes.get,currentThemeData: function(next) {@@ -89,12 +96,6 @@ if(nconf.get('ssl')) {winston.info('Using ports 80 and 443 is not recommend; use a proxy instead. See README.md');}- // Front-end assets- plugins.ready(function() {- meta.js.minify(app.enabled('minification'));- meta.css.minify();- });-module.exports.server = server;module.exports.init = function () {server.on("error", function(err){