info-iframe-receiver.js 761 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. var inherits = require('inherits')
  3. , EventEmitter = require('events').EventEmitter
  4. , XHRLocalObject = require('./transport/sender/xhr-local')
  5. , InfoAjax = require('./info-ajax')
  6. ;
  7. function InfoReceiverIframe(transUrl) {
  8. var self = this;
  9. EventEmitter.call(this);
  10. this.ir = new InfoAjax(transUrl, XHRLocalObject);
  11. this.ir.once('finish', function(info, rtt) {
  12. self.ir = null;
  13. self.emit('message', JSON.stringify([info, rtt]));
  14. });
  15. }
  16. inherits(InfoReceiverIframe, EventEmitter);
  17. InfoReceiverIframe.transportName = 'iframe-info-receiver';
  18. InfoReceiverIframe.prototype.close = function() {
  19. if (this.ir) {
  20. this.ir.close();
  21. this.ir = null;
  22. }
  23. this.removeAllListeners();
  24. };
  25. module.exports = InfoReceiverIframe;