Permalink
Browse files

Handle connection errors in long polling.

  • Loading branch information...
1 parent 2cd67dd commit c2f2c2f79d2668da3122d22757e62433e8898756 @scottgonzalez committed Apr 27, 2010
Showing with 14 additions and 6 deletions.
  1. +1 −0 demo/web/js/client.js
  2. +13 −6 demo/web/js/nodechat.js
@@ -8,6 +8,7 @@ var title = document.title,
message;
// TODO: Turn off auto scrolling if user has scrolled up from the bottom
+// TODO: handle connectionerror
$(function() {
log = $("#chat-log");
@@ -26,7 +26,6 @@ $.extend(Channel.prototype, {
},
poll: function() {
- // TODO: get error handling to work
if (this.pollingErrors > 2) {
$(this).triggerHandler("connectionerror");
return;
@@ -37,11 +36,14 @@ $.extend(Channel.prototype, {
since: this.lastMessageTime,
id: this.id
},
- success: this.handlePoll,
- error: function() {
- channel.pollingErrors++;
- setTimeout(channel.poll, 10*1000);
- }
+ success: function(data) {
+ if (data) {
+ channel.handlePoll(data);
+ } else {
+ channel.handlePollError();
+ }
+ },
+ error: this.handlePollError
});
},
@@ -55,6 +57,11 @@ $.extend(Channel.prototype, {
});
}
this.poll();
+ },
+
+ handlePollError: function() {
+ this.pollingErrors++;
+ setTimeout(this.poll, 10*1000);
}
});

0 comments on commit c2f2c2f

Please sign in to comment.