Merge pull request #929 from MarkTraceur/hook/http/send-clients-message
Add in an HTTP API call to send a custom message type.pull/928/merge
commit
ba6acd822e
|
@ -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 */
|
/** INTERNAL HELPER FUNCTIONS */
|
||||||
|
|
|
@ -66,7 +66,8 @@ var functions = {
|
||||||
"setPassword" : ["padID", "password"],
|
"setPassword" : ["padID", "password"],
|
||||||
"isPasswordProtected" : ["padID"],
|
"isPasswordProtected" : ["padID"],
|
||||||
"listAuthorsOfPad" : ["padID"],
|
"listAuthorsOfPad" : ["padID"],
|
||||||
"padUsersCount" : ["padID"]
|
"padUsersCount" : ["padID"],
|
||||||
|
"sendClientsMessage" : ["padID", "msg"]
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -272,6 +272,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
|
* Handles a Chat Message
|
||||||
* @param client the client that send this message
|
* @param client the client that send this message
|
||||||
|
|
Loading…
Reference in New Issue