}
pollingServer = true;
- thisRequestIsPolling = true;
data.version = VERSION;
- }
- if (!thisRequestIsPolling) {
- blockMove++;
- }
+ if (window.EventSource) {
+ eventSource = new EventSource('/:trivabble/sse/' + JSON.stringify(data));
- if (thisRequestIsPolling && window.EventSource) {
- eventSource = new EventSource('/:trivabble/sse/' + JSON.stringify(data));
+ eventSource.onopen = connectionReady;
- eventSource.onopen = connectionReady;
+ eventSource.onmessage = function (e) {
+ connectionReady();
+ parseAndHandleReceivedData(e.data);
+ };
- eventSource.onmessage = function (e) {
- connectionReady();
- parseAndHandleReceivedData(e.data);
- };
+ eventSource.onerror = function () {
+ pollingReady = false;
+ if (needsRestart) {
+ eventSource.close();
+ } else if (!blockEventSourceAutoRetry) {
+ retryPolling();
+ }
+ };
- eventSource.onerror = function () {
- pollingReady = false;
- if (needsRestart) {
- eventSource.close();
- } else if (!blockEventSourceAutoRetry) {
- retryPolling();
- }
- };
+ return;
+ }
- return;
+ thisRequestIsPolling = true;
+ } else {
+ blockMove++;
}
var xhr = new XMLHttpRequest();
xhr.send(JSON.stringify(data));
xhr.onreadystatechange = function () {
- // TODO error handling
-
if (xhr.readyState === 2 && thisRequestIsPolling) {
connectionReady();
} else if (xhr.readyState === 3 && thisRequestIsPolling) {