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
723 B

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