From bf365bedfdec21683e3fcce3e9f41108cc4dd27f Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 2 Sep 2013 17:00:33 -0400 Subject: [PATCH 1/3] pushing fix to issue where htmlfile transport for socket.io was causing NodeBB to not work at all --- src/websockets.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/websockets.js b/src/websockets.js index 3027bfbdf9..2c72da7ae9 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -1,5 +1,8 @@ -var SocketIO = require('socket.io').listen(global.server, { log:false }), +var SocketIO = require('socket.io').listen(global.server, { + log: false, + transports: ['websocket', 'xhr-polling', 'jsonp-polling', 'flashsocket'] + }), cookie = require('cookie'), express = require('express'), user = require('./user.js'), From d1a17b39ea4d889027172c048e56031f3af8ba4f Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 2 Sep 2013 17:14:56 -0400 Subject: [PATCH 2/3] allowing npm update of socket.io to newer version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 41d1b7a637..17223e898b 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "main": "app.js", "dependencies": { - "socket.io": "0.9.14", + "socket.io": "~0.9.14", "redis": "0.8.3", "express": "3.2.0", "express-namespace": "0.1.1", From c1a41c66051236923b247ac99095300159a0be50 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 2 Sep 2013 21:53:15 -0400 Subject: [PATCH 3/3] added hook priority to plugin hook registration --- src/plugins.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/plugins.js b/src/plugins.js index a7e66421d9..64b2933337 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -19,7 +19,7 @@ var fs = require('fs'), }, function(plugins, next) { if (plugins && Array.isArray(plugins) && plugins.length > 0) { - async.each(plugins, function(plugin) { + async.each(plugins, function(plugin, next) { // TODO: Update this check to also check node_modules var pluginPath = path.join(__dirname, '../plugins/', plugin), modulePath = path.join(__dirname, '../node_modules/', plugin); @@ -31,6 +31,17 @@ var fs = require('fs'), } }, next); } else next(); + }, + function(next) { + winston.info('[plugins] Sorting hooks to fire in priority sequence'); + Object.keys(_self.loadedHooks).forEach(function(hook) { + var hooks = _self.loadedHooks[hook]; + hooks = hooks.sort(function(a, b) { + return a[3] - b[3]; + }); + }); + + next(); } ], function(err) { if (err) { @@ -66,30 +77,33 @@ var fs = require('fs'), `data.hook`*, the name of the NodeBB hook `data.method`*, the method called in that plugin `data.callbacked`, whether or not the hook expects a callback (true), or a return (false). Only used for filters. (Default: false) - (Not implemented) `data.priority`, the relative priority of the method when it is eventually called (default: 10) + `data.priority`, the relative priority of the method when it is eventually called (default: 10) */ var _self = this; if (data.hook && data.method) { + // Assign default priority of 10 if none is passed-in + if (!data.priority) data.priority = 10; + _self.loadedHooks[data.hook] = _self.loadedHooks[data.hook] || []; - _self.loadedHooks[data.hook].push([id, data.method, !!data.callbacked]); + _self.loadedHooks[data.hook].push([id, data.method, !!data.callbacked, data.priority]); + if (global.env === 'development') winston.info('[plugins] Hook registered: ' + data.hook + ' will call ' + id); } else return; }, fireHook: function(hook, args, callback) { - // TODO: Implement priority hook firing var _self = this hookList = this.loadedHooks[hook]; if (hookList && Array.isArray(hookList)) { - //if (global.env === 'development') winston.info('[plugins] Firing hook: \'' + hook + '\''); + if (global.env === 'development') winston.info('[plugins] Firing hook: \'' + hook + '\''); var hookType = hook.split(':')[0]; switch(hookType) { case 'filter': // Filters only take one argument, so only args[0] will be passed in var returnVal = (Array.isArray(args) ? args[0] : args); - async.each(hookList, function(hookObj, next) { + async.eachSeries(hookList, function(hookObj, next) { if (hookObj[2]) { _self.libraries[hookObj[0]][hookObj[1]](returnVal, function(err, afterVal) { returnVal = afterVal;