xdr-streaming.js 984 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. var inherits = require('inherits')
  3. , AjaxBasedTransport = require('./lib/ajax-based')
  4. , XhrReceiver = require('./receiver/xhr')
  5. , XDRObject = require('./sender/xdr')
  6. ;
  7. // According to:
  8. // http://stackoverflow.com/questions/1641507/detect-browser-support-for-cross-domain-xmlhttprequests
  9. // http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/
  10. function XdrStreamingTransport(transUrl) {
  11. if (!XDRObject.enabled) {
  12. throw new Error('Transport created when disabled');
  13. }
  14. AjaxBasedTransport.call(this, transUrl, '/xhr_streaming', XhrReceiver, XDRObject);
  15. }
  16. inherits(XdrStreamingTransport, AjaxBasedTransport);
  17. XdrStreamingTransport.enabled = function(info) {
  18. if (info.cookie_needed || info.nullOrigin) {
  19. return false;
  20. }
  21. return XDRObject.enabled && info.sameScheme;
  22. };
  23. XdrStreamingTransport.transportName = 'xdr-streaming';
  24. XdrStreamingTransport.roundTrips = 2; // preflight, ajax
  25. module.exports = XdrStreamingTransport;