xhr-streaming.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. var inherits = require('inherits')
  3. , AjaxBasedTransport = require('./lib/ajax-based')
  4. , XhrReceiver = require('./receiver/xhr')
  5. , XHRCorsObject = require('./sender/xhr-cors')
  6. , XHRLocalObject = require('./sender/xhr-local')
  7. , browser = require('../utils/browser')
  8. ;
  9. function XhrStreamingTransport(transUrl) {
  10. if (!XHRLocalObject.enabled && !XHRCorsObject.enabled) {
  11. throw new Error('Transport created when disabled');
  12. }
  13. AjaxBasedTransport.call(this, transUrl, '/xhr_streaming', XhrReceiver, XHRCorsObject);
  14. }
  15. inherits(XhrStreamingTransport, AjaxBasedTransport);
  16. XhrStreamingTransport.enabled = function(info) {
  17. if (info.nullOrigin) {
  18. return false;
  19. }
  20. // Opera doesn't support xhr-streaming #60
  21. // But it might be able to #92
  22. if (browser.isOpera()) {
  23. return false;
  24. }
  25. return XHRCorsObject.enabled;
  26. };
  27. XhrStreamingTransport.transportName = 'xhr-streaming';
  28. XhrStreamingTransport.roundTrips = 2; // preflight, ajax
  29. // Safari gets confused when a streaming ajax request is started
  30. // before onload. This causes the load indicator to spin indefinetely.
  31. // Only require body when used in a browser
  32. XhrStreamingTransport.needBody = !!global.document;
  33. module.exports = XhrStreamingTransport;