Skip to content

Commit

Permalink
see #60
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaffle committed Jul 23, 2015
1 parent af29ee5 commit 3e14803
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@
var XHR = global.XMLHttpRequest;
var XDR = global.XDomainRequest;
var isCORSSupported = XHR != undefined && (new XHR()).withCredentials != undefined;
var isXHR = isCORSSupported;
var Transport = isCORSSupported ? XHR : (XDR != undefined ? XDR : undefined);
var isXHR = isCORSSupported || (XHR != undefined && XDR == undefined);
var Transport = isXHR ? XHR : XDR;

var WAITING = -1;
var CONNECTING = 0;
var OPEN = 1;
Expand Down Expand Up @@ -488,13 +489,16 @@

EventSource.prototype = new F();
F.call(EventSource);
if (isCORSSupported) {
EventSource.prototype.withCredentials = undefined;
}

var isEventSourceSupported = function () {
// Opera 12 fails this test, but this is fine.
return global.EventSource != undefined && ("withCredentials" in global.EventSource.prototype);
};

if (Transport != undefined && !isEventSourceSupported()) {
if (Transport != undefined && (global.EventSource == undefined || (isCORSSupported && !isEventSourceSupported()))) {
// Why replace a native EventSource ?
// https://bugzilla.mozilla.org/show_bug.cgi?id=444328
// https://bugzilla.mozilla.org/show_bug.cgi?id=831392
Expand Down
10 changes: 7 additions & 3 deletions tests/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@
var XHR = global.XMLHttpRequest;
var XDR = global.XDomainRequest;
var isCORSSupported = XHR != undefined && (new XHR()).withCredentials != undefined;
var isXHR = isCORSSupported;
var Transport = isCORSSupported ? XHR : (XDR != undefined ? XDR : undefined);
var isXHR = isCORSSupported || (XHR != undefined && XDR == undefined);
var Transport = isXHR ? XHR : XDR;

var WAITING = -1;
var CONNECTING = 0;
var OPEN = 1;
Expand Down Expand Up @@ -488,13 +489,16 @@

EventSource.prototype = new F();
F.call(EventSource);
if (isCORSSupported) {
EventSource.prototype.withCredentials = undefined;
}

var isEventSourceSupported = function () {
// Opera 12 fails this test, but this is fine.
return global.EventSource != undefined && ("withCredentials" in global.EventSource.prototype);
};

if (Transport != undefined && !isEventSourceSupported()) {
if (Transport != undefined && (global.EventSource == undefined || (isCORSSupported && !isEventSourceSupported()))) {
// Why replace a native EventSource ?
// https://bugzilla.mozilla.org/show_bug.cgi?id=444328
// https://bugzilla.mozilla.org/show_bug.cgi?id=831392
Expand Down

0 comments on commit 3e14803

Please sign in to comment.