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.

33 lines
894 B

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. ;
  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;