Comparing version 0.2.4 to 0.2.5
{ | ||
"name": "ss-utils", | ||
"title": "ServiceStack JavaScript Utils", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "ServiceStack's JavaScript library providing a number of convenience utilities in developing javascript web apps. Integrates with ServiceStack's Server features including Error Handling, Validation and Server Events", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/ServiceStack/ss-utils", |
@@ -706,26 +706,30 @@ ;(function (root, f) { | ||
if (opt.heartbeatUrl) { | ||
if (opt.heartbeat) { | ||
window.clearInterval(opt.heartbeat); | ||
} | ||
opt.heartbeat = window.setInterval(function () { | ||
if ($.ss.eventSource.readyState === 2) //CLOSED | ||
{ | ||
window.clearInterval(opt.heartbeat); | ||
var stopFn = $.ss.handlers["onStop"]; | ||
if (stopFn != null) | ||
stopFn.apply($.ss.eventSource); | ||
$.ss.reconnectServerEvents({ errorArgs: { error:'CLOSED' } }); | ||
return; | ||
$.ss.CONNECT_ID = $.ss.CONNECT_ID ? $.ss.CONNECT_ID + 1 : 1; | ||
(function(connectId) { | ||
function sendHeartbeat() { | ||
if (connectId !== $.ss.CONNECT_ID) // Only allow latest connections heartbeat callback through | ||
return; | ||
if ($.ss.eventSource.readyState === 2) //CLOSED | ||
{ | ||
var stopFn = $.ss.handlers["onStop"]; | ||
if (stopFn != null) | ||
stopFn.apply($.ss.eventSource); | ||
$.ss.reconnectServerEvents({ errorArgs: { error:'CLOSED' } }); | ||
return; | ||
} | ||
$.ajax({ | ||
type: "POST", | ||
url: opt.heartbeatUrl, | ||
data: null, | ||
dataType: "text", | ||
success: function (r) { | ||
setTimeout(sendHeartbeat, parseInt(opt.heartbeatIntervalMs) || 10000) | ||
}, | ||
error: function () { | ||
$.ss.reconnectServerEvents({ errorArgs: arguments }); | ||
} | ||
}); | ||
} | ||
$.ajax({ | ||
type: "POST", | ||
url: opt.heartbeatUrl, | ||
data: null, | ||
dataType: "text", | ||
success: function (r) { }, | ||
error: function () { | ||
$.ss.reconnectServerEvents({ errorArgs: arguments }); | ||
} | ||
}); | ||
}, parseInt(opt.heartbeatIntervalMs) || 10000); | ||
setTimeout(sendHeartbeat, parseInt(opt.heartbeatIntervalMs) || 10000); | ||
})($.ss.CONNECT_ID); | ||
} | ||
@@ -732,0 +736,0 @@ if (opt.unRegisterUrl) { |
39807
915