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.

27 lines
766 B

4 years ago
  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;