Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions jquery.eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,15 @@

if ( stream.cache[ label ] ) {

var headers = {};
if (stream.cache[ label ].lastEventId)
headers['Last-Event-ID'] = stream.cache[ label ].lastEventId;

source = jQuery.ajax({
type: "GET",
url: options.url,
data: options.data,
headers: headers,
beforeSend: function() {
if ( stream.cache[ label ] ) {
this.label = label;
Expand Down Expand Up @@ -174,27 +179,40 @@

this.label = label;

stream.cache[ label ].lastEventId++;
stream.cache[ label ].history[ stream.cache[ label ].lastEventId ] = parsedData;
if (parsedData[0]) {
stream.cache[ label ].lastEventId = parsedData[0].id;
stream.cache[ label ].history[ stream.cache[ label ].lastEventId ] = parsedData;
}

stream.cache[ label ].options.message.call(this, parsedData[0] ? parsedData[0] : null, {
data: parsedData,
lastEventId: stream.cache[ label ].lastEventId
});

setTimeout(
function() {
pluginFns._private.openPollingSource.call( this, options );
},
// Use server sent retry time if exists or default retry time if not
( stream.cache[ label ] && stream.cache[ label ].retry ) || 500
);
pluginFns._private.pollAgain(options);
}
},
error: function() {
pluginFns._private.pollAgain(options);
},
cache: false,
timeout: 50000
});
}
return source;
},
pollAgain: function (options) {
var label = options.label;
if (stream.cache[ label ].timer)
clearInterval(stream.cache[ label ].timer);

stream.cache[ label ].timer = setTimeout(
function() {
pluginFns._private.openPollingSource( options );
},
// Use server sent retry time if exists or default retry time if not
( stream.cache[ label ] && stream.cache[ label ].retry ) || 500
);
}
}
},
Expand Down