function createSocket() {
    connection = new WebSocket("wss://ws.blockchain.info/inv");
    connection.onopen = function(e) {
        updateSubs();
    }
    connection.onmessage = function(e) {
        var p = JSON.parse(e.data);
        var tmp;
        switch (p.op) {
            case "status":
                tmp = statusMessage(e, p); break;
            case "utx":
                tmp = dispatchTransaction(e, p); break;
            case "block":
                tmp = blocksMessage(e, p); 
                $("#but_lastblock").attr("title","View last block (#"+p.x.height+")");
                break;
            default:
                return;
        }

        if (!tmp)
            return;

        var text = tmp[0];
        var cls = tmp[1];
        if(tmp[0] != prevMsg){
            addMessage(timeStamp(), cls, text);
        }else{
            console.log("Blocked double msg");
        }
        prevMsg=tmp[0];
    };
    connection.onclose = function(e) {
        setTimeout(createSocket, 300);
    }
    connection.onerror = function(e) {
        addMessage(timeStamp(), "failure", e.msg);
    }
}
// Create the connnection object and set up the handlers
Create the connnection object and set up the handlers
Create the connnection object and set up the handlers
function createSocket() {
    connection = new WebSocket("wss://ws.blockchain.info/inv");
    connection.onopen = function(e) {
        updateSubs();
    }
    connection.onmessage = function(e) {
        var p = JSON.parse(e.data);
        var tmp;
        switch (p.op) {
            case "status":
                tmp = statusMessage(e, p); break;
            case "utx":
                tmp = dispatchTransaction(e, p); break;
            case "block":
                tmp = blocksMessage(e, p); 
                $("#but_lastblock").attr("title","View last block (#"+p.x.height+")");
                break;
            default:
                return;
        }
        if (!tmp)
            return;
        var text = tmp[0];
        var cls = tmp[1];
        if(tmp[0] != prevMsg){
            addMessage(timeStamp(), cls, text);
        }else{
            console.log("Blocked double msg");
        }
        prevMsg=tmp[0];
    };
    connection.onclose = function(e) {
        setTimeout(createSocket, 300);
    }
    connection.onerror = function(e) {
        addMessage(timeStamp(), "failure", e.msg);
    }
}
function createSocket ( ) { connection = new WebSocket ( "wss://ws.blockchain.info/inv" ) ; connection . onopen = function ( e ) { updateSubs ( ) ; } connection . onmessage = function ( e ) { var p = JSON . parse ( e . data ) ; var tmp ; switch ( p . op ) { case "status" : tmp = statusMessage ( e , p ) ; break ; case "utx" : tmp = dispatchTransaction ( e , p ) ; break ; case "block" : tmp = blocksMessage ( e , p ) ; $ ( "#but_lastblock" ) . attr ( "title" , "View last block (#" + p . x . height + ")" ) ; break ; default : return ; } if ( ! tmp ) return ; var text = tmp [ 0 ] ; var cls = tmp [ 1 ] ; if ( tmp [ 0 ] != prevMsg ) { addMessage ( timeStamp ( ) , cls , text ) ; } else { console . log ( "Blocked double msg" ) ; } prevMsg = tmp [ 0 ] ; } ; connection . onclose = function ( e ) { setTimeout ( createSocket , 300 ) ; } connection . onerror = function ( e ) { addMessage ( timeStamp ( ) , "failure" , e . msg ) ; } }
Create the connnection object and set up the handlers
Create the connnection object and set up the handlers