Code coverage report for sockjs-client/lib/info-receiver.js

Statements: 94.74% (18 / 19)      Branches: 83.33% (5 / 6)      Functions: 100% (5 / 5)      Lines: 94.44% (17 / 18)      Ignored: none     

All files » sockjs-client/lib/ » info-receiver.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45                  1 1 1   1   1   1   1 15     1 15   15       15 2   13         1 13 13        
'use strict';
/*
 * ***** BEGIN LICENSE BLOCK *****
 * Copyright (c) 2011-2012 VMware, Inc.
 *
 * For the license see COPYING.
 * ***** END LICENSE BLOCK *****
 */
 
var EventEmitter = require('events').EventEmitter;
var inherits = require('util').inherits;
var request = require('request');
 
var jsonParse = require('./safe-json-parse.js');
 
module.exports = InfoReceiver;
 
inherits(InfoReceiver, EventEmitter);
 
function InfoReceiver(base_url) {
    process.nextTick(function () { this.doRequest(base_url); }.bind(this));
}
 
InfoReceiver.prototype.doRequest = function (base_url) {
    var t0 = Date.now();
 
    request({
        url: base_url + '/info',
        timeout: 8000, // copying the original SockJS client
    }, function (err, response, text) {
        if (err || response.statusCode !== 200) {
            this.emit('finish');
        } else {
            this.emit('finish', getInfo(text), Date.now() - t0);
        }
    }.bind(this));
};
 
function getInfo(text) {
    Eif (text) {
        return jsonParse(text);
    }
    return null;
}