Code coverage report for sockjs-client/lib/trans-websocket.js

Statements: 92% (23 / 25)      Branches: 50% (2 / 4)      Functions: 83.33% (5 / 6)      Lines: 92% (23 / 25)      Ignored: none     

All files » sockjs-client/lib/ » trans-websocket.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 46 47 48 49 50 51 52 53                  1   1   1   1 11 11     11   11 11   11   11 81     11         1 69     1 11 11 11 11 11       1 24    
'use strict';
/*
 * ***** BEGIN LICENSE BLOCK *****
 * Copyright (c) 2011-2012 VMware, Inc.
 *
 * For the license see COPYING.
 * ***** END LICENSE BLOCK *****
 */
 
var WebSocket = require('ws');
 
var helpers = require('./helpers.js');
 
module.exports = WebSocketTransport;
 
function WebSocketTransport(ri, trans_url) {
    var url = trans_url + '/websocket';
    Iif (url.slice(0, 5) === 'https') {
        url = 'wss' + url.slice(5);
    } else {
        url = 'ws' + url.slice(4);
    }
    this.ri = ri;
    this.url = url;
 
    this.ws = new WebSocket(this.url);
 
    this.ws.onmessage = function (e) {
        this.ri._didMessage(e.data);
    }.bind(this);
 
    this.ws.onclose = this.ws.onerror = function () {
        this.ri._didMessage(helpers.closeFrame(1006, 'WebSocket connection broken'));
    }.bind(this);
}
 
WebSocketTransport.prototype.doSend = function (data) {
    this.ws.send('[' + data + ']');
};
 
WebSocketTransport.prototype.doCleanup = function () {
    var ws = this.ws;
    Eif (ws) {
        ws.onmessage = ws.onclose = ws.onerror = null;
        ws.close();
        this.ri = this.ws = null;
    }
};
 
WebSocketTransport.enabled = function () {
    return true;
};