You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

4 years ago
  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;