info-iframe-receiver.js 791 B

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