Compare commits

...

7 Commits

3 changed files with 28 additions and 2 deletions

View File

@ -156,7 +156,6 @@ exports.handleMessage = function(client, message)
// handleMessage will be called, even if the client is not authorized
hooks.aCallAll("handleMessage", { client: client, message: message }, function ( err, messages ) {
if(ERR(err, callback)) return;
_.each(messages, function(newMessage){
if ( newMessage === null ) {
dropMessage = true;
@ -193,6 +192,7 @@ exports.handleMessage = function(client, message)
handleSuggestUserName(client, message);
} else {
messageLogger.warn("Dropped message, unknown COLLABROOM Data Type " + message.data.type);
console.warn(message);
}
} else {
messageLogger.warn("Dropped message, unknown Message Type " + message.type);
@ -254,6 +254,27 @@ function handleSaveRevisionMessage(client, message){
});
}
/**
* Handles a custom message, different to the function below as it handles objects not strings and you can direct the message to specific sessionID
*
* @param msg {Object} the message we're sending
* @param sessionID {string} the socketIO session to which we're sending this message
*/
exports.handleCustomObjectMessage = function (msg, sessionID, cb) {
if(msg.data.type === "CUSTOM"){
if(sessionID){ // If a sessionID is targeted then send directly to this sessionID
console.warn("Sent msg", msg);
console.warn("to sessionID", sessionID);
// socketio.clients[sessionID].send(msg);
socketio.sockets.socket(sessionID).emit(msg); // send a targeted message
}else{
socketio.sockets.in(msg.data.padId).json.send(msg); // broadcast to all clients on this pad
}
}
cb(null, {});
}
/**
* Handles a custom message (sent via HTTP API request)
*
@ -1478,3 +1499,5 @@ exports.padUsers = function (padID, callback) {
callback(null, {padUsers: result});
});
}
exports.sessioninfos = sessioninfos;

View File

@ -278,8 +278,9 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
if (!getSocket()) return;
if (!evt.data) return;
var wrapper = evt;
if (wrapper.type != "COLLABROOM") return;
if (wrapper.type != "COLLABROOM" && wrapper.type != "CUSTOM") return;
var msg = wrapper.data;
if (msg.type == "NEW_CHANGES")
{
var newRev = msg.newRev;
@ -390,6 +391,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
callbacks.onUserLeave(userInfo);
}
}
else if (msg.type == "DISCONNECT_REASON")
{
appLevelDisconnectReason = msg.reason;

View File

@ -441,6 +441,7 @@ var pad = {
//initialize the chat
chat.init(this);
padcookie.init();
pad.initTime = +(new Date());
pad.padOptions = clientVars.initialOptions;