1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
/*
* ***** BEGIN LICENSE BLOCK *****
* Copyright (c) 2011-2012 VMware, Inc.
*
* For the license see COPYING.
* ***** END LICENSE BLOCK *****
*/
var AjaxBasedTransport = function() {};
AjaxBasedTransport.prototype = new BufferedSender();
AjaxBasedTransport.prototype.run = function(ri, trans_url,
url_suffix, Receiver, AjaxObject) {
var that = this;
that.ri = ri;
that.trans_url = trans_url;
that.send_constructor(createAjaxSender(AjaxObject));
that.poll = new Polling(ri, Receiver,
trans_url + url_suffix, AjaxObject);
};
AjaxBasedTransport.prototype.doCleanup = function() {
var that = this;
if (that.poll) {
that.poll.abort();
that.poll = null;
}
};
// xhr-streaming
var XhrStreamingTransport = SockJS['xhr-streaming'] = function(ri, trans_url) {
this.run(ri, trans_url, '/xhr_streaming', XhrReceiver, utils.XHRCorsObject);
};
XhrStreamingTransport.prototype = new AjaxBasedTransport();
XhrStreamingTransport.enabled = function() {
// Support for CORS Ajax aka Ajax2? Opera 12 claims CORS but
// doesn't do streaming.
return (_window.XMLHttpRequest &&
'withCredentials' in new XMLHttpRequest() &&
(!/opera/i.test(navigator.userAgent)));
};
XhrStreamingTransport.roundTrips = 2; // preflight, ajax
// Safari gets confused when a streaming ajax request is started
// before onload. This causes the load indicator to spin indefinetely.
XhrStreamingTransport.need_body = true;
// According to:
// http://stackoverflow.com/questions/1641507/detect-browser-support-for-cross-domain-xmlhttprequests
// http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/
// xdr-streaming
var XdrStreamingTransport = SockJS['xdr-streaming'] = function(ri, trans_url) {
this.run(ri, trans_url, '/xhr_streaming', XhrReceiver, utils.XDRObject);
};
XdrStreamingTransport.prototype = new AjaxBasedTransport();
XdrStreamingTransport.enabled = function() {
return !!_window.XDomainRequest;
};
XdrStreamingTransport.roundTrips = 2; // preflight, ajax
// xhr-polling
var XhrPollingTransport = SockJS['xhr-polling'] = function(ri, trans_url) {
this.run(ri, trans_url, '/xhr', XhrReceiver, utils.XHRCorsObject);
};
XhrPollingTransport.prototype = new AjaxBasedTransport();
XhrPollingTransport.enabled = XhrStreamingTransport.enabled;
XhrPollingTransport.roundTrips = 2; // preflight, ajax
// xdr-polling
var XdrPollingTransport = SockJS['xdr-polling'] = function(ri, trans_url) {
this.run(ri, trans_url, '/xhr', XhrReceiver, utils.XDRObject);
};
XdrPollingTransport.prototype = new AjaxBasedTransport();
XdrPollingTransport.enabled = XdrStreamingTransport.enabled;
XdrPollingTransport.roundTrips = 2; // preflight, ajax
|