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 // handleMessage will be called, even if the client is not authorized
hooks.aCallAll("handleMessage", { client: client, message: message }, function ( err, messages ) { hooks.aCallAll("handleMessage", { client: client, message: message }, function ( err, messages ) {
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
_.each(messages, function(newMessage){ _.each(messages, function(newMessage){
if ( newMessage === null ) { if ( newMessage === null ) {
dropMessage = true; dropMessage = true;
@ -193,6 +192,7 @@ exports.handleMessage = function(client, message)
handleSuggestUserName(client, message); handleSuggestUserName(client, message);
} else { } else {
messageLogger.warn("Dropped message, unknown COLLABROOM Data Type " + message.data.type); messageLogger.warn("Dropped message, unknown COLLABROOM Data Type " + message.data.type);
console.warn(message);
} }
} else { } else {
messageLogger.warn("Dropped message, unknown Message Type " + message.type); 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) * Handles a custom message (sent via HTTP API request)
* *
@ -1478,3 +1499,5 @@ exports.padUsers = function (padID, callback) {
callback(null, {padUsers: result}); callback(null, {padUsers: result});
}); });
} }
exports.sessioninfos = sessioninfos;

View File

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

View File

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