eventsource.js 766 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. var inherits = require('inherits')
  3. , AjaxBasedTransport = require('./lib/ajax-based')
  4. , EventSourceReceiver = require('./receiver/eventsource')
  5. , XHRCorsObject = require('./sender/xhr-cors')
  6. , EventSourceDriver = require('eventsource')
  7. ;
  8. function EventSourceTransport(transUrl) {
  9. if (!EventSourceTransport.enabled()) {
  10. throw new Error('Transport created when disabled');
  11. }
  12. AjaxBasedTransport.call(this, transUrl, '/eventsource', EventSourceReceiver, XHRCorsObject);
  13. }
  14. inherits(EventSourceTransport, AjaxBasedTransport);
  15. EventSourceTransport.enabled = function() {
  16. return !!EventSourceDriver;
  17. };
  18. EventSourceTransport.transportName = 'eventsource';
  19. EventSourceTransport.roundTrips = 2;
  20. module.exports = EventSourceTransport;