Sha256: 326bde72930f95aaffb18c57d15953de5f62f623f831257b69d6aae8d019d362

Contents?: true

Size: 1.01 KB

Versions: 34

Compression:

Stored size: 1.01 KB

Contents

'use strict';

var EventEmitter = require('events').EventEmitter
  , inherits = require('inherits')
  , JSON3 = require('json3')
  , objectUtils = require('./utils/object')
  ;

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

function InfoAjax(url, AjaxObject) {
  EventEmitter.call(this);

  var self = this;
  var t0 = +new Date();
  this.xo = new AjaxObject('GET', url);

  this.xo.once('finish', function(status, text) {
    var info, rtt;
    if (status === 200) {
      rtt = (+new Date()) - t0;
      if (text) {
        try {
          info = JSON3.parse(text);
        } catch (e) {
          debug('bad json', text);
        }
      }

      if (!objectUtils.isObject(info)) {
        info = {};
      }
    }
    self.emit('finish', info, rtt);
    self.removeAllListeners();
  });
}

inherits(InfoAjax, EventEmitter);

InfoAjax.prototype.close = function() {
  this.removeAllListeners();
  this.xo.close();
};

module.exports = InfoAjax;

Version data entries

34 entries across 33 versions & 12 rubygems

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