xhr-polling.js 894 B

123456789101112131415161718192021222324252627282930313233
  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. ;
  8. function XhrPollingTransport(transUrl) {
  9. if (!XHRLocalObject.enabled && !XHRCorsObject.enabled) {
  10. throw new Error('Transport created when disabled');
  11. }
  12. AjaxBasedTransport.call(this, transUrl, '/xhr', XhrReceiver, XHRCorsObject);
  13. }
  14. inherits(XhrPollingTransport, AjaxBasedTransport);
  15. XhrPollingTransport.enabled = function(info) {
  16. if (info.nullOrigin) {
  17. return false;
  18. }
  19. if (XHRLocalObject.enabled && info.sameOrigin) {
  20. return true;
  21. }
  22. return XHRCorsObject.enabled;
  23. };
  24. XhrPollingTransport.transportName = 'xhr-polling';
  25. XhrPollingTransport.roundTrips = 2; // preflight, ajax
  26. module.exports = XhrPollingTransport;