Skip to content
This repository has been archived by the owner on Feb 12, 2018. It is now read-only.

Commit

Permalink
Fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfrancisco committed Jul 16, 2011
1 parent a17d677 commit 1629657
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions public/js/script.js
Expand Up @@ -525,25 +525,41 @@ var escrito = function () {
if (window.location.hostname !== "localhost") { // FIXME
port = "80";
}
var connection = new sharejs.Connection(window.location.hostname, port);

connection.open(docName, function (doc, error) {
if (error) {
console.error(error);
return;
}
doc.attach_ace(editor);
editor.setReadOnly(false);
var connected = false;
var connection;

function openConnection() {
connection = new sharejs.Connection(window.location.hostname, port);
connection.open(docName, function (doc, error) {
if (error) {
console.error(error);
return;
}
connected = true;
doc.attach_ace(editor);
editor.setReadOnly(false);

window.doc = doc;
window.doc = doc;

render(doc.snapshot);
$preview.focus();
$preview.activity(false);
doc.on('change', function () {
render(doc.snapshot);
$preview.focus();
$preview.activity(false);
doc.on('change', function () {
render(doc.snapshot);
});
});
});
}

openConnection();
setTimeout(function () { responseTimeout(); }, 8000);
function responseTimeout() {
// If it's taking too long, try again (this happens a lot because heroku doesn't support websockets)
if (!connected) {
console.log("Trying to connect one more time");
openConnection();
setTimeout(function () { responseTimeout(); }, 8000);
}
}
}

return { init : init, addImportInstructions: addImportInstructions };
Expand Down

0 comments on commit 1629657

Please sign in to comment.