summaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js53
1 files changed, 53 insertions, 0 deletions
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();
+ }
+};