diff options
-rw-r--r-- | ep.json | 13 | ||||
-rw-r--r-- | index.js | 53 | ||||
-rw-r--r-- | package.json | 18 |
3 files changed, 84 insertions, 0 deletions
@@ -0,0 +1,13 @@ +{ + "parts": [ + { + "name": "main", + "client_hooks": { + }, + "hooks": { + "clientVars": "ep_global_view/index", + "handleMessage": "ep_global_view/index" + } + } + ] +} diff --git a/index.js b/index.js new file mode 100644 index 0000000..6e7e0cd --- /dev/null +++ b/index.js @@ -0,0 +1,53 @@ +var ERR = require("async-stacktrace"); +var padMessage = require("ep_etherpad-lite/node/handler/PadMessageHandler.js"); +var padManager = require("ep_etherpad-lite/node/db/PadManager.js"); + +exports.clientVars = function(hook, context, callback) +{ + var globalViewInfo = {}; + + if (context.hasOwnProperty("pad")) { + var pad = context.pad; + if (pad.hasOwnProperty("globalViewInfo")) { + globalViewInfo = pad.globalViewInfo; + } + } + + return callback({ "globalViewInfo": globalViewInfo }); +}; + +exports.handleMessage = function(hook_name, context, cb) { + if ( context.message.type == "COLLABROOM" && context.message.data.type == "GLOBAL_VIEW") { + var client = context.client; + var session = padMessage.sessioninfos[client.id]; + + padManager.getPad(session.padId, function(err, pad) { + if (ERR(err)) return cb(); + + var globalViewInfo = {}; + if (pad.hasOwnProperty("globalViewInfo")) { + globalViewInfo = pad.globalViewInfo; + } + + for (key in context.message.data.data) { + globalViewInfo[key] = context.message.data.data[key]; + } + pad.globalViewInfo = globalViewInfo; + pad.saveToDatabase(); + + var message = { + "type": "COLLABROOM", + "data": { + type: "GLOABL_VIEW", + globalViewInfo: globalViewInfo + } + }; + + client.broadcast.to(session.padId).json.send(message); + return cb([null]); + }); + } + else { + return cb(); + } +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..843e850 --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "description": "Add some pad-global view settings.", + "name": "ep_global_view", + "version": "0.0.1", + "author": "Alexander Sulfrian <alexander@sulfrian.net>", + "dependencies": { + "async-stacktrace": "0.0.2" + }, + "engines": { + "node": "*" + }, + "homepage": "https://github.com/AlexanderS/ep_global_view", + "devDependencies": {}, + "repository": { + "type": "git", + "url": "https://github.com/AlexanderS/ep_global_view.git" + } +} |