function init() {
    // Create and open the socket
    ws = new WebSocket("ws://localhost:6437/v6.json");

    // On successful connection
    ws.onopen = function(event) {
		
        var enableMessage = JSON.stringify({enableGestures: true});
        ws.send(enableMessage); // Enable gestures
        ws.send(JSON.stringify({focused: true})); // claim focus

        focusListener = window.addEventListener('focus', function(e) {
                               ws.send(JSON.stringify({focused: true})); // claim focus
                         });

        blurListener = window.addEventListener('blur', function(e) {
                               ws.send(JSON.stringify({focused: false})); // relinquish focus
                         });

        //document.getElementById("connection").innerHTML = "WebSocket connection open!";
    };

    // On message received
    ws.onmessage = function(event) {
        if (!paused) {
            var obj = JSON.parse(event.data);

			// Parse JSON Object
			parseFrame(obj);

            //var str = JSON.stringify(obj, undefined, 2);
            //document.getElementById("output").innerHTML = '<pre>' + str + '</pre>';
            if (pauseOnGesture && obj.gestures.length > 0) {
                togglePause();
            }
        }
    };

    // On socket close
    ws.onclose = function(event) {
        ws = null;
        window.removeListener("focus", focusListener);
        window.removeListener("blur", blurListener);
        document.getElementById("main").style.visibility = "hidden";
        //document.getElementById("connection").innerHTML = "WebSocket connection closed";
    }

    // On socket error
    ws.onerror = function(event) {
      alert("Received error");
    };


}
// Create the socket with event handlers
Create the socket with event handlers
Create the socket with event handlers
function init() {
    ws = new WebSocket("ws://localhost:6437/v6.json");
    ws.onopen = function(event) {
        var enableMessage = JSON.stringify({enableGestures: true});
        ws.send(enableMessage); 
        ws.send(JSON.stringify({focused: true})); 
        focusListener = window.addEventListener('focus', function(e) {
                               ws.send(JSON.stringify({focused: true})); 
                         });
        blurListener = window.addEventListener('blur', function(e) {
                               ws.send(JSON.stringify({focused: false})); 
                         });
    };
    ws.onmessage = function(event) {
        if (!paused) {
            var obj = JSON.parse(event.data);
			parseFrame(obj);
            if (pauseOnGesture && obj.gestures.length > 0) {
                togglePause();
            }
        }
    };
    ws.onclose = function(event) {
        ws = null;
        window.removeListener("focus", focusListener);
        window.removeListener("blur", blurListener);
        document.getElementById("main").style.visibility = "hidden";
    }
    ws.onerror = function(event) {
      alert("Received error");
    };
}
function init ( ) { ws = new WebSocket ( "ws://localhost:6437/v6.json" ) ; ws . onopen = function ( event ) { var enableMessage = JSON . stringify ( { enableGestures : true } ) ; ws . send ( enableMessage ) ; ws . send ( JSON . stringify ( { focused : true } ) ) ; focusListener = window . addEventListener ( 'focus' , function ( e ) { ws . send ( JSON . stringify ( { focused : true } ) ) ; } ) ; blurListener = window . addEventListener ( 'blur' , function ( e ) { ws . send ( JSON . stringify ( { focused : false } ) ) ; } ) ; } ; ws . onmessage = function ( event ) { if ( ! paused ) { var obj = JSON . parse ( event . data ) ; parseFrame ( obj ) ; if ( pauseOnGesture && obj . gestures . length > 0 ) { togglePause ( ) ; } } } ; ws . onclose = function ( event ) { ws = null ; window . removeListener ( "focus" , focusListener ) ; window . removeListener ( "blur" , blurListener ) ; document . getElementById ( "main" ) . style . visibility = "hidden" ; } ws . onerror = function ( event ) { alert ( "Received error" ) ; } ; }
Create the socket with event handlers
Create the socket with event handlers
// Create and open the socket // On successful connection // Enable gestures // claim focus // claim focus // relinquish focus //document.getElementById("connection").innerHTML = "WebSocket connection open!"; // On message received // Parse JSON Object //var str = JSON.stringify(obj, undefined, 2); //document.getElementById("output").innerHTML = '<pre>' + str + '</pre>'; // On socket close //document.getElementById("connection").innerHTML = "WebSocket connection closed"; // On socket error