github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/themes/wind/static/libs/sockjs-client-1.1.0/lib/facade.js (about)

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