model/consoleState.js
function(socket) {

        var username = null;
        var permissions = null;
        if (socket.handshake.headers.authorization) {
            username = socket.handshake.headers.authorization.match(/username="([^"]+)"/)[1];
            permissions = $$config.permissions ? $$config.permissions[username] : null;
        }

        // Responds to requests for appState updates, but throttle it to _updateConsoleRate.
        var updateConsole = _.bind(this._updateConsole, this);
        socket.on('appStateRequest', _.bind(function() {
            clearTimeout(this._updateConsoleTimeout);
            this._updateConsoleTimeout = setTimeout(updateConsole, this._updateConsoleRate);
        }, this));

        socket.on('start', _.bind(function() {
            if (permissions && !permissions.app) {
                return;
            }

            logger.info('Startup requested from console.');
            $$serverState.saveState('runApp', true);
            $$persistence.startApp(true);
        }, this));

        socket.on('restart-app', _.bind(function() {
            if (permissions && !permissions.app) {
                return;
            }

            logger.info('Restart requested from console.');
            $$serverState.saveState('runApp', true);
            $$persistence.restartApp(true);
        }, this));

        socket.on('shutdown-app', _.bind(function() {
            if (permissions && !permissions.app) {
                return;
            }

            logger.info('Shutdown requested from console.');
            $$serverState.saveState('runApp', false);
            $$persistence.shutdownApp();
        }, this));

        socket.on('restart-pc', _.bind(function() {
            if (permissions && !permissions.computer) {
                return;
            }

            logger.info('Reboot requested from console.');
            $$persistence.restartMachine();
        }, this));

        socket.on('shutdown-pc', _.bind(function() {
            if (permissions && !permissions.computer) {
                return;
            }

            logger.info('Shutdown requested from console.');
            $$persistence.shutdownMachine();
        }, this));

        socket.on('switchConfig', _.bind(function(config) {
            $$serverState.saveState('configFile', config, $$persistence.restartServer);
        }, this));

        $$network.transports.socketToConsole.sockets.emit('config', this.fullConfig(username), this.get('configs'));
    }
function(socket) {

        var username = null;
        var permissions = null;
        if (socket.handshake.headers.authorization) {
            username = socket.handshake.headers.authorization.match(/username="([^"]+)"/)[1];
            permissions = $$config.permissions ? $$config.permissions[username] : null;
        }

        // Responds to requests for appState updates, but throttle it to _updateConsoleRate.
        var updateConsole = _.bind(this._updateConsole, this);
        socket.on('appStateRequest', _.bind(function() {
            clearTimeout(this._updateConsoleTimeout);
            this._updateConsoleTimeout = setTimeout(updateConsole, this._updateConsoleRate);
        }, this));

        socket.on('start', _.bind(function() {
            if (permissions && !permissions.app) {
                return;
            }

            logger.info('Startup requested from console.');
            $$serverState.saveState('runApp', true);
            $$persistence.startApp(true);
        }, this));

        socket.on('restart-app', _.bind(function() {
            if (permissions && !permissions.app) {
                return;
            }

            logger.info('Restart requested from console.');
            $$serverState.saveState('runApp', true);
            $$persistence.restartApp(true);
        }, this));

        socket.on('shutdown-app', _.bind(function() {
            if (permissions && !permissions.app) {
                return;
            }

            logger.info('Shutdown requested from console.');
            $$serverState.saveState('runApp', false);
            $$persistence.shutdownApp();
        }, this));

        socket.on('restart-pc', _.bind(function() {
            if (permissions && !permissions.computer) {
                return;
            }

            logger.info('Reboot requested from console.');
            $$persistence.restartMachine();
        }, this));

        socket.on('shutdown-pc', _.bind(function() {
            if (permissions && !permissions.computer) {
                return;
            }

            logger.info('Shutdown requested from console.');
            $$persistence.shutdownMachine();
        }, this));

        socket.on('switchConfig', _.bind(function(config) {
            $$serverState.saveState('configFile', config, $$persistence.restartServer);
        }, this));

        $$network.transports.socketToConsole.sockets.emit('config', this.fullConfig(username), this.get('configs'));
    }
function ( socket ) { var username = null ; var permissions = null ; if ( socket . handshake . headers . authorization ) { username = socket . handshake . headers . authorization . match ( / username="([^"]+)" / ) [ 1 ] ; permissions = $$config . permissions ? $$config . permissions [ username ] : null ; } // Responds to requests for appState updates, but throttle it to _updateConsoleRate. var updateConsole = _ . bind ( this . _updateConsole , this ) ; socket . on ( 'appStateRequest' , _ . bind ( function ( ) { clearTimeout ( this . _updateConsoleTimeout ) ; this . _updateConsoleTimeout = setTimeout ( updateConsole , this . _updateConsoleRate ) ; } , this ) ) ; socket . on ( 'start' , _ . bind ( function ( ) { if ( permissions && ! permissions . app ) { return ; } logger . info ( 'Startup requested from console.' ) ; $$serverState . saveState ( 'runApp' , true ) ; $$persistence . startApp ( true ) ; } , this ) ) ; socket . on ( 'restart-app' , _ . bind ( function ( ) { if ( permissions && ! permissions . app ) { return ; } logger . info ( 'Restart requested from console.' ) ; $$serverState . saveState ( 'runApp' , true ) ; $$persistence . restartApp ( true ) ; } , this ) ) ; socket . on ( 'shutdown-app' , _ . bind ( function ( ) { if ( permissions && ! permissions . app ) { return ; } logger . info ( 'Shutdown requested from console.' ) ; $$serverState . saveState ( 'runApp' , false ) ; $$persistence . shutdownApp ( ) ; } , this ) ) ; socket . on ( 'restart-pc' , _ . bind ( function ( ) { if ( permissions && ! permissions . computer ) { return ; } logger . info ( 'Reboot requested from console.' ) ; $$persistence . restartMachine ( ) ; } , this ) ) ; socket . on ( 'shutdown-pc' , _ . bind ( function ( ) { if ( permissions && ! permissions . computer ) { return ; } logger . info ( 'Shutdown requested from console.' ) ; $$persistence . shutdownMachine ( ) ; } , this ) ) ; socket . on ( 'switchConfig' , _ . bind ( function ( config ) { $$serverState . saveState ( 'configFile' , config , $$persistence . restartServer ) ; } , this ) ) ; $$network . transports . socketToConsole . sockets . emit ( 'config' , this . fullConfig ( username ) , this . get ( 'configs' ) ) ; }
On initial socket connection with the console, listen for commands and send out the config.
On initial socket connection with the console listen for commands and send out the config .