amazing offline mode

This commit is contained in:
Jean-Tiare Le Bigot 2012-03-03 21:38:00 +01:00
parent 0a68f06610
commit 8921c1976b
3 changed files with 43 additions and 9 deletions

View file

@ -533,7 +533,7 @@ table#otheruserstable { display: none; }
margin-bottom: 10px; margin-bottom: 10px;
} }
#connectionboxinner .disconnected p { #connectionboxinner .disconnected p {
margin: 10px 10px; margin: 10px 0;
font-size: 1.2em; font-size: 1.2em;
line-height: 1.1; line-height: 1.1;
color: #333; color: #333;

View file

@ -277,9 +277,38 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
setChannelState("CONNECTED"); setChannelState("CONNECTED");
} }
} }
var disconnectedMessages = [];
function processDisconnectedMessages()
{
//assume that it is connected
var len = disconnectedMessages.length;
while(disconnectedMessages.length)
{
var msg = disconnectedMessages.shift();//remove from the array
_sendMessage(msg);//process.
}
}
function sendMessage(msg) function sendMessage(msg)
{ {
if(channelState != "CONNECTED")
{
console.log("Channel is not connected WAITING");
disconnectedMessages.push(msg);
return;
}
_sendMessage(msg);
}
function _sendMessage(msg)
{
console.log("sending msg =>");
console.log(msg);
getSocket().json.send( getSocket().json.send(
{ {
type: "COLLABROOM", type: "COLLABROOM",
@ -287,7 +316,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
data: msg data: msg
}); });
} }
function wrapRecordingErrors(catcher, func) function wrapRecordingErrors(catcher, func)
{ {
return function() return function()
@ -671,7 +700,8 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
getMissedChanges: getMissedChanges, getMissedChanges: getMissedChanges,
callWhenNotCommitting: callWhenNotCommitting, callWhenNotCommitting: callWhenNotCommitting,
addHistoricalAuthors: tellAceAboutHistoricalAuthors, addHistoricalAuthors: tellAceAboutHistoricalAuthors,
setChannelState: setChannelState setChannelState: setChannelState,
processDisconnectedMessages: processDisconnectedMessages
}; };
$(document).ready(setUpSocket); $(document).ready(setUpSocket);

View file

@ -203,8 +203,13 @@ function handshake()
msg.client_rev=pad.collabClient.getCurrentRevisionNumber(); msg.client_rev=pad.collabClient.getCurrentRevisionNumber();
msg.reconnect=true; msg.reconnect=true;
} }
console.log("sending CLIENT_READY =>");
console.log(msg);
socket.json.send(msg); socket.json.send(msg);
if(isReconnect == true)
{
pad.collabClient.processDisconnectedMessages();
}
}; };
var disconnectTimeout; var disconnectTimeout;
@ -219,9 +224,8 @@ function handshake()
{ {
clearTimeout(disconnectTimeout); clearTimeout(disconnectTimeout);
} }
pad.collabClient.setChannelState("CONNECTED");
sendClientReady(true); sendClientReady(true);
pad.collabClient.setChannelState("CONNECTED");
}); });
socket.on('disconnect', function (reason) { socket.on('disconnect', function (reason) {
@ -703,10 +707,10 @@ var pad = {
{ {
padconnectionstatus.reconnecting(); padconnectionstatus.reconnecting();
padeditor.disable(); /*padeditor.disable();
padeditbar.disable(); padeditbar.disable();
paddocbar.disable(); paddocbar.disable();
padimpexp.disable(); padimpexp.disable();*/
} }
else if (newState == "DISCONNECTED") else if (newState == "DISCONNECTED")
{ {