facade.js 723 B

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