facade.js 693 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. var iframeUtils = require('./utils/iframe')
  3. ;
  4. function FacadeJS(transport) {
  5. this._transport = transport;
  6. transport.on('message', this._transportMessage.bind(this));
  7. transport.on('close', this._transportClose.bind(this));
  8. }
  9. FacadeJS.prototype._transportClose = function(code, reason) {
  10. iframeUtils.postMessage('c', JSON.stringify([code, reason]));
  11. };
  12. FacadeJS.prototype._transportMessage = function(frame) {
  13. iframeUtils.postMessage('t', frame);
  14. };
  15. FacadeJS.prototype._send = function(data) {
  16. this._transport.send(data);
  17. };
  18. FacadeJS.prototype._close = function() {
  19. this._transport.close();
  20. this._transport.removeAllListeners();
  21. };
  22. module.exports = FacadeJS;