var ws = new WebSocket("ws://{hostname}",['echo-protocol']);

// Define methods to handle response
var methods = {};

methods.request = function (ctx) {
    delete ctx.command;
    console.log(ctx);
}

methods.auth = function(ctx) {
    console.log(ctx.message);
}

ws.onmessage = function (evt) 
{ 
    var cmd = evt.data;
    cmd = JSON.parse(cmd);
    methods[cmd.command](cmd);
};
ws.onopen = function()
{
    // Define keys here
    var ctx = {"private":"","token":""}
    ws.send(JSON.stringify(ctx));
};