Change everything to the new Socket.IO API
parent
fd5aafe17a
commit
80a478fd55
|
@ -66,8 +66,8 @@ exports.handleConnect = function(client)
|
||||||
throwExceptionIfClientOrIOisInvalid(client);
|
throwExceptionIfClientOrIOisInvalid(client);
|
||||||
|
|
||||||
//Initalize session2pad and sessioninfos for this new session
|
//Initalize session2pad and sessioninfos for this new session
|
||||||
session2pad[client.sessionId]=null;
|
session2pad[client.id]=null;
|
||||||
sessioninfos[client.sessionId]={};
|
sessioninfos[client.id]={};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,12 +80,12 @@ exports.handleDisconnect = function(client)
|
||||||
throwExceptionIfClientOrIOisInvalid(client);
|
throwExceptionIfClientOrIOisInvalid(client);
|
||||||
|
|
||||||
//save the padname of this session
|
//save the padname of this session
|
||||||
var sessionPad=session2pad[client.sessionId];
|
var sessionPad=session2pad[client.id];
|
||||||
|
|
||||||
//if this connection was already etablished with a handshake, send a disconnect message to the others
|
//if this connection was already etablished with a handshake, send a disconnect message to the others
|
||||||
if(sessioninfos[client.sessionId].author)
|
if(sessioninfos[client.id].author)
|
||||||
{
|
{
|
||||||
var author = sessioninfos[client.sessionId].author;
|
var author = sessioninfos[client.id].author;
|
||||||
|
|
||||||
//get the author color out of the db
|
//get the author color out of the db
|
||||||
authorManager.getAuthorColorId(author, function(err, color)
|
authorManager.getAuthorColorId(author, function(err, color)
|
||||||
|
@ -109,7 +109,7 @@ exports.handleDisconnect = function(client)
|
||||||
//Go trough all user that are still on the pad, and send them the USER_LEAVE message
|
//Go trough all user that are still on the pad, and send them the USER_LEAVE message
|
||||||
for(i in pad2sessions[sessionPad])
|
for(i in pad2sessions[sessionPad])
|
||||||
{
|
{
|
||||||
socketio.clients[pad2sessions[sessionPad][i]].send(messageToTheOtherUsers);
|
socketio.sockets.sockets[pad2sessions[sessionPad][i]].json.send(messageToTheOtherUsers);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ exports.handleDisconnect = function(client)
|
||||||
//Go trough all sessions of this pad, search and destroy the entry of this client
|
//Go trough all sessions of this pad, search and destroy the entry of this client
|
||||||
for(i in pad2sessions[sessionPad])
|
for(i in pad2sessions[sessionPad])
|
||||||
{
|
{
|
||||||
if(pad2sessions[sessionPad][i] == client.sessionId)
|
if(pad2sessions[sessionPad][i] == client.id)
|
||||||
{
|
{
|
||||||
delete pad2sessions[sessionPad][i];
|
delete pad2sessions[sessionPad][i];
|
||||||
break;
|
break;
|
||||||
|
@ -125,8 +125,8 @@ exports.handleDisconnect = function(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete the session2pad and sessioninfos entrys of this session
|
//Delete the session2pad and sessioninfos entrys of this session
|
||||||
delete session2pad[client.sessionId];
|
delete session2pad[client.id];
|
||||||
delete sessioninfos[client.sessionId];
|
delete sessioninfos[client.id];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -184,13 +184,13 @@ function handleUserInfoUpdate(client, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Find out the author name of this session
|
//Find out the author name of this session
|
||||||
var author = sessioninfos[client.sessionId].author;
|
var author = sessioninfos[client.id].author;
|
||||||
|
|
||||||
//Tell the authorManager about the new attributes
|
//Tell the authorManager about the new attributes
|
||||||
authorManager.setAuthorColorId(author, message.data.userInfo.colorId);
|
authorManager.setAuthorColorId(author, message.data.userInfo.colorId);
|
||||||
authorManager.setAuthorName(author, message.data.userInfo.name);
|
authorManager.setAuthorName(author, message.data.userInfo.name);
|
||||||
|
|
||||||
var padId = session2pad[client.sessionId];
|
var padId = session2pad[client.id];
|
||||||
|
|
||||||
//set a null name, when there is no name set. cause the client wants it null
|
//set a null name, when there is no name set. cause the client wants it null
|
||||||
if(message.data.userInfo.name == null)
|
if(message.data.userInfo.name == null)
|
||||||
|
@ -204,9 +204,9 @@ function handleUserInfoUpdate(client, message)
|
||||||
//Send the other clients on the pad the update message
|
//Send the other clients on the pad the update message
|
||||||
for(i in pad2sessions[padId])
|
for(i in pad2sessions[padId])
|
||||||
{
|
{
|
||||||
if(pad2sessions[padId][i] != client.sessionId)
|
if(pad2sessions[padId][i] != client.id)
|
||||||
{
|
{
|
||||||
socketio.clients[pad2sessions[padId][i]].send(message);
|
socketio.clients[pad2sessions[padId][i]].json.send(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -250,7 +250,7 @@ function handleUserChanges(client, message)
|
||||||
//get the pad
|
//get the pad
|
||||||
function(callback)
|
function(callback)
|
||||||
{
|
{
|
||||||
padManager.getPad(session2pad[client.sessionId], function(err, value)
|
padManager.getPad(session2pad[client.id], function(err, value)
|
||||||
{
|
{
|
||||||
pad = value;
|
pad = value;
|
||||||
callback(err);
|
callback(err);
|
||||||
|
@ -312,7 +312,7 @@ function handleUserChanges(client, message)
|
||||||
+ Changeset.oldLen(changeset) + " to document of length " + prevText.length;
|
+ Changeset.oldLen(changeset) + " to document of length " + prevText.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
var thisAuthor = sessioninfos[client.sessionId].author;
|
var thisAuthor = sessioninfos[client.id].author;
|
||||||
|
|
||||||
pad.appendRevision(changeset, thisAuthor);
|
pad.appendRevision(changeset, thisAuthor);
|
||||||
|
|
||||||
|
@ -370,7 +370,7 @@ function handleUserChanges(client, message)
|
||||||
|
|
||||||
if(author == sessioninfos[session].author)
|
if(author == sessioninfos[session].author)
|
||||||
{
|
{
|
||||||
socketio.clients[session].send({"type":"COLLABROOM","data":{type:"ACCEPT_COMMIT", newRev:r}});
|
socketio.sockets.sockets[session].json.send({"type":"COLLABROOM","data":{type:"ACCEPT_COMMIT", newRev:r}});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -380,7 +380,7 @@ function handleUserChanges(client, message)
|
||||||
apool: forWire.pool,
|
apool: forWire.pool,
|
||||||
author: author}};
|
author: author}};
|
||||||
|
|
||||||
socketio.clients[session].send(wireMsg);
|
socketio.clients[session].json.send(wireMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null);
|
callback(null);
|
||||||
|
@ -519,13 +519,13 @@ function handleClientReady(client, message)
|
||||||
{
|
{
|
||||||
if(sessioninfos[pad2sessions[message.padId][i]].author == author)
|
if(sessioninfos[pad2sessions[message.padId][i]].author == author)
|
||||||
{
|
{
|
||||||
socketio.clients[pad2sessions[message.padId][i]].send({disconnect:"doublelogin"});
|
socketio.clients[pad2sessions[message.padId][i]].json.send({disconnect:"doublelogin"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Save in session2pad that this session belonges to this pad
|
//Save in session2pad that this session belonges to this pad
|
||||||
var sessionId=String(client.sessionId);
|
var sessionId=String(client.id);
|
||||||
session2pad[sessionId] = message.padId;
|
session2pad[sessionId] = message.padId;
|
||||||
|
|
||||||
//check if there is already a pad2sessions entry, if not, create one
|
//check if there is already a pad2sessions entry, if not, create one
|
||||||
|
@ -603,11 +603,11 @@ function handleClientReady(client, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Send the clientVars to the Client
|
//Send the clientVars to the Client
|
||||||
client.send(clientVars);
|
client.json.send(clientVars);
|
||||||
|
|
||||||
//Save the revision and the author id in sessioninfos
|
//Save the revision and the author id in sessioninfos
|
||||||
sessioninfos[client.sessionId].rev = pad.getHeadRevisionNumber();
|
sessioninfos[client.id].rev = pad.getHeadRevisionNumber();
|
||||||
sessioninfos[client.sessionId].author = author;
|
sessioninfos[client.id].author = author;
|
||||||
|
|
||||||
//prepare the notification for the other users on the pad, that this user joined
|
//prepare the notification for the other users on the pad, that this user joined
|
||||||
var messageToTheOtherUsers = {
|
var messageToTheOtherUsers = {
|
||||||
|
@ -660,10 +660,10 @@ function handleClientReady(client, message)
|
||||||
function (callback)
|
function (callback)
|
||||||
{
|
{
|
||||||
//Jump over, if this session is the connection session
|
//Jump over, if this session is the connection session
|
||||||
if(sessionID != client.sessionId)
|
if(sessionID != client.id)
|
||||||
{
|
{
|
||||||
//Send this Session the Notification about the new user
|
//Send this Session the Notification about the new user
|
||||||
socketio.clients[sessionID].send(messageToTheOtherUsers);
|
socketio.clients[sessionID].json.send(messageToTheOtherUsers);
|
||||||
|
|
||||||
//Send the new User a Notification about this other user
|
//Send the new User a Notification about this other user
|
||||||
var messageToNotifyTheClientAboutTheOthers = {
|
var messageToNotifyTheClientAboutTheOthers = {
|
||||||
|
@ -679,7 +679,7 @@ function handleClientReady(client, message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
client.send(messageToNotifyTheClientAboutTheOthers);
|
client.json.send(messageToNotifyTheClientAboutTheOthers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
|
|
|
@ -48,7 +48,7 @@ exports.setSocketIO = function(_socket)
|
||||||
//save this socket internaly
|
//save this socket internaly
|
||||||
socket = _socket;
|
socket = _socket;
|
||||||
|
|
||||||
socket.on('connection', function(client)
|
socket.sockets.on('connection', function(client)
|
||||||
{
|
{
|
||||||
//tell all components about this connect
|
//tell all components about this connect
|
||||||
for(var i in components)
|
for(var i in components)
|
||||||
|
|
|
@ -86,7 +86,7 @@ function handleClientReady(client, message)
|
||||||
{
|
{
|
||||||
if(err) throw err;
|
if(err) throw err;
|
||||||
|
|
||||||
client.send({type: "CLIENT_VARS", data: clientVars});
|
client.json.send({type: "CLIENT_VARS", data: clientVars});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ function handleChangesetRequest(client, message)
|
||||||
var data = changesetInfo;
|
var data = changesetInfo;
|
||||||
data.requestID = message.data.requestID;
|
data.requestID = message.data.requestID;
|
||||||
|
|
||||||
client.send({type: "CHANGESET_REQ", data: data});
|
client.json.send({type: "CHANGESET_REQ", data: data});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue