jsonp-polling.js 1016 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. // The simplest and most robust transport, using the well-know cross
  3. // domain hack - JSONP. This transport is quite inefficient - one
  4. // message could use up to one http request. But at least it works almost
  5. // everywhere.
  6. // Known limitations:
  7. // o you will get a spinning cursor
  8. // o for Konqueror a dumb timer is needed to detect errors
  9. var inherits = require('inherits')
  10. , SenderReceiver = require('./lib/sender-receiver')
  11. , JsonpReceiver = require('./receiver/jsonp')
  12. , jsonpSender = require('./sender/jsonp')
  13. ;
  14. function JsonPTransport(transUrl) {
  15. if (!JsonPTransport.enabled()) {
  16. throw new Error('Transport created when disabled');
  17. }
  18. SenderReceiver.call(this, transUrl, '/jsonp', jsonpSender, JsonpReceiver);
  19. }
  20. inherits(JsonPTransport, SenderReceiver);
  21. JsonPTransport.enabled = function() {
  22. return !!global.document;
  23. };
  24. JsonPTransport.transportName = 'jsonp-polling';
  25. JsonPTransport.roundTrips = 1;
  26. JsonPTransport.needBody = true;
  27. module.exports = JsonPTransport;