Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nko/nodelay
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomEtc committed Aug 29, 2010
2 parents 3c44e5e + c6ffb9b commit bcb770e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
21 changes: 18 additions & 3 deletions nodelay.js
Expand Up @@ -30,12 +30,26 @@ window.onload = function() {
}

// Start polling for JS when WebSocket and Flash aren't available
function receivePoll(json) {
processEdit(json);
}

var polling = false;
function startPolling() {
polling = true;
var pollurl = "http://"+document.location.host+'/poll' + (Math.random() * 10000);
//console.log('startPolling', pollurl);
var self = this;
setTimeout(function() {
// check timeout, and start polling again
if (polling) {
self.startPolling();
}
},60000)

utils.loadJSLib(pollurl, function() {
setTimeout(function() {
polling = false;
//console.log('loaded', pollurl);
self.startPolling();
},1)
Expand Down Expand Up @@ -87,11 +101,12 @@ function processEdit(data) {

// Update user count
usercountel = document.getElementById('updates');
var usercounttext = commaSeparated(edit.usercount) + ' user' + (edit.usercount == 1 ? '' : 's') + ' from ' + commaSeparated(edit.uniqueips) + ' unique address' + (edit.uniqueips == 1 ? '' : 'es');
var usercounttext = commaSeparated(edit.usercount) + ' user' + (edit.usercount == 1 ? '' : 's')
var uniqueiptext = ' from ' + commaSeparated(edit.uniqueips) + ' unique address' + (edit.uniqueips == 1 ? '' : 'es');
var editcounttext = commaSeparated(edit.editcount) + ' edit' + (edit.editcount == 1 ? '' : 's');
var userstring = 'Nodelay has ' + usercounttext + ' and has served ' + editcounttext + '!';
var userstring = 'Nodelay has served ' + editcounttext + ' to ' + usercounttext + uniqueiptext + '!';
usercountel.innerHTML = userstring;
top.document.title = userstring;
top.document.title = usercounttext + ' online now';

var queryurl = document.location.search;
// Update languages table
Expand Down
6 changes: 3 additions & 3 deletions server.js
Expand Up @@ -220,7 +220,7 @@ var lookInGoogle = function(returnobj, callback) {
var clientip = uniqueips[Math.floor(Math.random() * uniqueips.length)]
//console.log('found clientip', clientip, uniqueips);
var url = "/ajax/services/search/web?v=1.0&key=ABQIAAAANJy59z-JG5ojQlRVP3myHBQazc0JSD0GCdkBcD0H4asbApndtBRNVqQ4MvCnn6oQF6lHyWk4Q9S5AA&userip=" + clientip + "&q='" + querystring.escape(title) + "'";
console.log('google request', url);
//console.log('google request', url);

var request = googleclient.request('GET', url, {'host': 'ajax.googleapis.com','referer': 'http://code.google.com/apis'})
request.end()
Expand All @@ -236,7 +236,7 @@ var lookInGoogle = function(returnobj, callback) {

// process when the response ends
response.on('end', function () {
console.log('parsing: ' + url + ' for chunk ' + responsedata)
//console.log('parsing: ' + url + ' for chunk ' + responsedata)
try {
var data = JSON.parse(responsedata)
if (data.responseData && data.responseData.results) {
Expand Down Expand Up @@ -320,7 +320,7 @@ var loadMetadata = function(returnobj) {
while (waitingclients.length) {
var client = waitingclients.shift()
// TODO: don't use a direct callback
client("processEdit('" + out.replace(/'/g,"\\'").replace(/"/g,'\\"') + "')")
client("receivePoll('" + out.replace(/'/g,"\\'").replace(/"/g,'\\"') + "')")
}
waitingclients = [];
}
Expand Down

0 comments on commit bcb770e

Please sign in to comment.