summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMark Holmquist <mtraceur@member.fsf.org>2012-08-08 10:12:11 -0700
committerMark Holmquist <mtraceur@member.fsf.org>2012-08-08 10:12:11 -0700
commit3d4fb8179689c581e6f01c626d7d364a9e7d43b7 (patch)
tree549ef9e1b2d9278f3e0da0c8817082faa75f41ee /src
parentaa986ab9544f01d0ac1611b97ab8be73c32c5992 (diff)
downloadetherpad-lite-3d4fb8179689c581e6f01c626d7d364a9e7d43b7.zip
Add in an HTTP API call to send a custom message type.
You cannot currently send any data with your custom message, but this patch is just begging for a second one that will allow that.
Diffstat (limited to 'src')
-rw-r--r--src/node/db/API.js33
-rw-r--r--src/node/handler/APIHandler.js3
-rw-r--r--src/node/handler/PadMessageHandler.js22
3 files changed, 57 insertions, 1 deletions
diff --git a/src/node/db/API.js b/src/node/db/API.js
index 4a1371ba..64ddef68 100644
--- a/src/node/db/API.js
+++ b/src/node/db/API.js
@@ -512,6 +512,39 @@ exports.listAuthorsOfPad = function(padID, callback)
});
}
+/**
+sendClientsMessage(padID, msg) sends a message to all clients connected to the
+pad, possibly for the purpose of signalling a plugin.
+
+Note, this will only accept strings from the HTTP API, so sending bogus changes
+or chat messages will probably not be possible.
+
+The resulting message will be structured like so:
+
+{
+ type: 'COLLABROOM',
+ data: {
+ type: <msg>,
+ time: <time the message was sent>
+ }
+}
+
+Example returns:
+
+{code: 0, message:"ok"}
+{code: 1, message:"padID does not exist"}
+*/
+
+exports.sendClientsMessage = function (padID, msg, callback) {
+ getPadSafe(padID, true, function (err, pad) {
+ if (ERR(err, callback)) {
+ return;
+ } else {
+ padMessageHandler.handleCustomMessage(padID, msg, callback);
+ }
+ } );
+}
+
/******************************/
/** INTERNAL HELPER FUNCTIONS */
diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js
index 40c08441..4e16d56e 100644
--- a/src/node/handler/APIHandler.js
+++ b/src/node/handler/APIHandler.js
@@ -66,7 +66,8 @@ var functions = {
"setPassword" : ["padID", "password"],
"isPasswordProtected" : ["padID"],
"listAuthorsOfPad" : ["padID"],
- "padUsersCount" : ["padID"]
+ "padUsersCount" : ["padID"],
+ "sendClientsMessage" : ["padID", "msg"]
};
/**
diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js
index d02e6537..6a2dcaf2 100644
--- a/src/node/handler/PadMessageHandler.js
+++ b/src/node/handler/PadMessageHandler.js
@@ -273,6 +273,28 @@ function handleSaveRevisionMessage(client, message){
}
/**
+ * Handles a custom message (sent via HTTP API request)
+ *
+ * @param padID {Pad} the pad to which we're sending this message
+ * @param msg {String} the message we're sending
+ */
+exports.handleCustomMessage = function (padID, msg, cb) {
+ var time = new Date().getTime();
+ var msg = {
+ type: 'COLLABROOM',
+ data: {
+ type: msg,
+ time: time
+ }
+ };
+ for (var i in pad2sessions[padID]) {
+ socketio.sockets.sockets[pad2sessions[padID][i]].json.send(msg);
+ }
+
+ cb(null, {});
+}
+
+/**
* Handles a Chat Message
* @param client the client that send this message
* @param message the message from the client