summaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
authorAlexander Sulfrian <alex@spline.inf.fu-berlin.de>2016-01-11 03:06:20 +0100
committerAlexander Sulfrian <alex@spline.inf.fu-berlin.de>2016-01-11 03:06:20 +0100
commit783c4546d4b6910addd4aee01a77a6894d502968 (patch)
tree799a282011af5ea7a1184531d394dcbfeed6cd45 /index.js
parent1f237f390a4c997c133661e01a7019ac116b1585 (diff)
downloadep_global_view-783c4546d4b6910addd4aee01a77a6894d502968.tar.gz
ep_global_view-783c4546d4b6910addd4aee01a77a6894d502968.tar.bz2
ep_global_view-783c4546d4b6910addd4aee01a77a6894d502968.zip
First per-pad state for global view
The global view settings are send to the server with a GLOBAL_VIEW message in a COLLABROOM message. Only the changed values have to submitted to the server. On every change the server broadcasts the new state to all clients. The global view state is also contained in the clientVars to transmit the initial values for new clients.
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();
+ }
+};