Sha256: 87c9191add3db6368d17424f53c78426005ab020b63d5f9653a8c44a7ec67c06

Contents?: true

Size: 1.48 KB

Versions: 34

Compression:

Stored size: 1.48 KB

Contents

'use strict';

var EventEmitter = require('events').EventEmitter
  , inherits = require('inherits')
  , JSON3 = require('json3')
  , utils = require('./utils/event')
  , IframeTransport = require('./transport/iframe')
  , InfoReceiverIframe = require('./info-iframe-receiver')
  ;

var debug = function() {};
if (process.env.NODE_ENV !== 'production') {
  debug = require('debug')('sockjs-client:info-iframe');
}

function InfoIframe(baseUrl, url) {
  var self = this;
  EventEmitter.call(this);

  var go = function() {
    var ifr = self.ifr = new IframeTransport(InfoReceiverIframe.transportName, url, baseUrl);

    ifr.once('message', function(msg) {
      if (msg) {
        var d;
        try {
          d = JSON3.parse(msg);
        } catch (e) {
          debug('bad json', msg);
          self.emit('finish');
          self.close();
          return;
        }

        var info = d[0], rtt = d[1];
        self.emit('finish', info, rtt);
      }
      self.close();
    });

    ifr.once('close', function() {
      self.emit('finish');
      self.close();
    });
  };

  // TODO this seems the same as the 'needBody' from transports
  if (!global.document.body) {
    utils.attachEvent('load', go);
  } else {
    go();
  }
}

inherits(InfoIframe, EventEmitter);

InfoIframe.enabled = function() {
  return IframeTransport.enabled();
};

InfoIframe.prototype.close = function() {
  if (this.ifr) {
    this.ifr.close();
  }
  this.removeAllListeners();
  this.ifr = null;
};

module.exports = InfoIframe;

Version data entries

34 entries across 33 versions & 12 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/sockjs-client/lib/info-iframe.js
disco_app-0.18.0 test/dummy/node_modules/sockjs-client/lib/info-iframe.js
disco_app-0.18.2 test/dummy/node_modules/sockjs-client/lib/info-iframe.js
disco_app-0.16.1 test/dummy/node_modules/sockjs-client/lib/info-iframe.js
disco_app-0.15.2 test/dummy/node_modules/sockjs-client/lib/info-iframe.js
disco_app-0.18.4 test/dummy/node_modules/sockjs-client/lib/info-iframe.js
disco_app-0.18.1 test/dummy/node_modules/sockjs-client/lib/info-iframe.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/sockjs-client/lib/info-iframe.js
disco_app-0.14.0 test/dummy/node_modules/sockjs-client/lib/info-iframe.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/sockjs-client/lib/info-iframe.js
tang-0.2.1 spec/tang_app/node_modules/sockjs-client/lib/info-iframe.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/sockjs-client/lib/info-iframe.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/sockjs-client/lib/info-iframe.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/sockjs-client/lib/info-iframe.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/sockjs-client/lib/info-iframe.js
tang-0.2.0 spec/tang_app/node_modules/sockjs-client/lib/info-iframe.js
tang-0.1.0 spec/tang_app/node_modules/sockjs-client/lib/info-iframe.js
tang-0.0.9 spec/tang_app/node_modules/sockjs-client/lib/info-iframe.js
enju_library-0.3.8 spec/dummy/node_modules/sockjs-client/lib/info-iframe.js
ilog-0.4.1 node_modules/sockjs-client/lib/info-iframe.js