Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reconnection logic for JSONP transport. Also, process advice from inc…

…oming messages before doing anything else.
  • Loading branch information...
commit 8e56bf63784398d3ddecac2aaaa4f5d5848d4690 1 parent dbbbf33
@jcoglan jcoglan authored
View
2  examples/node/app.js
@@ -5,7 +5,7 @@ var fs = require('fs'),
faye = require('./faye-node');
var PUBLIC_DIR = path.dirname(__filename) + '/../shared/public',
- comet = new faye.NodeAdapter({mount: '/comet', timeout: 45}),
+ comet = new faye.NodeAdapter({mount: '/comet', timeout: 5}),
port = process.ARGV[2] || '8000';
View
2  examples/rack/config.ru
@@ -3,6 +3,6 @@ dir = File.dirname(__FILE__)
require dir + '/../../lib/faye'
require dir + '/app'
-use Faye::RackAdapter, :mount => '/comet', :timeout => 25
+use Faye::RackAdapter, :mount => '/comet', :timeout => 5
run Sinatra::Application
View
2  examples/shared/public/index.html
@@ -44,7 +44,7 @@
if (window.console) console.log(msg);
};
- Comet = new Faye.Client('/comet');
+ Comet = new Faye.Client('http://127.0.0.1:8000/comet');
Soapbox.init(Comet);
</script>
View
11 javascript/network/browser.js
@@ -81,8 +81,9 @@ Faye.Transport.register('long-polling', Faye.XHRTransport);
Faye.JSONPTransport = Faye.extend(Faye.Class(Faye.Transport, {
- request: function(message) {
- var params = {message: Faye.toJSON(message)},
+ request: function(message, timeout) {
+ var timeout = timeout || this._client.getTimeout() * 2,
+ params = {message: Faye.toJSON(message)},
head = document.getElementsByTagName('head')[0],
script = document.createElement('script'),
callbackName = Faye.JSONPTransport.getCallbackName(),
@@ -97,6 +98,12 @@ Faye.JSONPTransport = Faye.extend(Faye.Class(Faye.Transport, {
self.receive(data);
};
+ setTimeout(function() {
+ if (!Faye.ENV[callbackName]) return;
+ self.abort(script);
+ self.request(message, 2 * timeout);
+ }, 1000 * timeout);
+
location.params.jsonp = callbackName;
script.type = 'text/javascript';
script.src = location.toURL();
View
6 javascript/network/transport.js
@@ -37,15 +37,15 @@ Faye.Transport = Faye.extend(Faye.Class({
var handleResponse = function(response) {
this._client.pipeThroughExtensions('incoming', response, function(response) {
if (response) {
+ if (response.advice)
+ this._client.handleAdvice(response.advice);
+
if (callback = this._callbacks[response.id]) {
delete this._callbacks[response.id];
if (callback[0].call(callback[1], response) === false)
deliverable = false;
}
- if (response.advice)
- this._client.handleAdvice(response.advice);
-
if (response.data && response.channel)
messages.push(response);
}
Please sign in to comment.
Something went wrong with that request. Please try again.