games/dictator/waitroom/waitroom.js
function clientConnects(p) {
        var pList;
        var nPlayers;
        var waitTime;
        var widgetConfig;

        node.remoteSetup('page', p.id, {
            clearBody: true,
            title: { title: 'Welcome!', addToBody: true }
        });

        node.remoteSetup('widgets', p.id, {
            destroyAll: true,
            append: { 'WaitingRoom': {} }
        });

        if (waitRoom.isRoomOpen()) {
            console.log('Client connected to waiting room: ', p.id);

            // Mark code as used.
            channel.registry.markInvalid(p.id);

            pList = waitRoom.clients.player;
            nPlayers = pList.size();


            if (waitRoom.START_DATE) {
                waitTime = new Date(waitRoom.START_DATE).getTime() -
                    (new Date().getTime());
            }
            else if (waitRoom.MAX_WAIT_TIME) {
                waitTime = waitRoom.MAX_WAIT_TIME;
            }
            else {
                waitTime = null; // Widget won't start timer.
            }

            // Send the number of minutes to wait and all waitRoom settings.
            widgetConfig = waitRoom.makeWidgetConfig();
            widgetConfig.waitTime = waitTime;
            node.remoteSetup('waitroom', p.id, widgetConfig);

            console.log('NPL ', nPlayers);

            // Notify all players of new connection.
            node.say('PLAYERSCONNECTED', 'ROOM', nPlayers);

            // Start counting a timeout for max stay in waiting room.
            waitRoom.makeTimeOut(p.id, waitTime);

            // Wait for all players to connect.
            if (nPlayers < waitRoom.POOL_SIZE) return;

            if (waitRoom.EXECUTION_MODE === 'WAIT_FOR_N_PLAYERS') {
                waitRoom.dispatch({
                    action: 'AllPlayersConnected',
                    exit: 0
                });
            }
        }
        else {
            node.say('ROOM_CLOSED', p.id);
        }
    }
function clientConnects(p) {
        var pList;
        var nPlayers;
        var waitTime;
        var widgetConfig;

        node.remoteSetup('page', p.id, {
            clearBody: true,
            title: { title: 'Welcome!', addToBody: true }
        });

        node.remoteSetup('widgets', p.id, {
            destroyAll: true,
            append: { 'WaitingRoom': {} }
        });

        if (waitRoom.isRoomOpen()) {
            console.log('Client connected to waiting room: ', p.id);

            // Mark code as used.
            channel.registry.markInvalid(p.id);

            pList = waitRoom.clients.player;
            nPlayers = pList.size();


            if (waitRoom.START_DATE) {
                waitTime = new Date(waitRoom.START_DATE).getTime() -
                    (new Date().getTime());
            }
            else if (waitRoom.MAX_WAIT_TIME) {
                waitTime = waitRoom.MAX_WAIT_TIME;
            }
            else {
                waitTime = null; // Widget won't start timer.
            }

            // Send the number of minutes to wait and all waitRoom settings.
            widgetConfig = waitRoom.makeWidgetConfig();
            widgetConfig.waitTime = waitTime;
            node.remoteSetup('waitroom', p.id, widgetConfig);

            console.log('NPL ', nPlayers);

            // Notify all players of new connection.
            node.say('PLAYERSCONNECTED', 'ROOM', nPlayers);

            // Start counting a timeout for max stay in waiting room.
            waitRoom.makeTimeOut(p.id, waitTime);

            // Wait for all players to connect.
            if (nPlayers < waitRoom.POOL_SIZE) return;

            if (waitRoom.EXECUTION_MODE === 'WAIT_FOR_N_PLAYERS') {
                waitRoom.dispatch({
                    action: 'AllPlayersConnected',
                    exit: 0
                });
            }
        }
        else {
            node.say('ROOM_CLOSED', p.id);
        }
    }
function clientConnects ( p ) { var pList ; var nPlayers ; var waitTime ; var widgetConfig ; node . remoteSetup ( 'page' , p . id , { clearBody : true , title : { title : 'Welcome!' , addToBody : true } } ) ; node . remoteSetup ( 'widgets' , p . id , { destroyAll : true , append : { 'WaitingRoom' : { } } } ) ; if ( waitRoom . isRoomOpen ( ) ) { console . log ( 'Client connected to waiting room: ' , p . id ) ; // Mark code as used. channel . registry . markInvalid ( p . id ) ; pList = waitRoom . clients . player ; nPlayers = pList . size ( ) ; if ( waitRoom . START_DATE ) { waitTime = new Date ( waitRoom . START_DATE ) . getTime ( ) - ( new Date ( ) . getTime ( ) ) ; } else if ( waitRoom . MAX_WAIT_TIME ) { waitTime = waitRoom . MAX_WAIT_TIME ; } else { waitTime = null ; // Widget won't start timer. } // Send the number of minutes to wait and all waitRoom settings. widgetConfig = waitRoom . makeWidgetConfig ( ) ; widgetConfig . waitTime = waitTime ; node . remoteSetup ( 'waitroom' , p . id , widgetConfig ) ; console . log ( 'NPL ' , nPlayers ) ; // Notify all players of new connection. node . say ( 'PLAYERSCONNECTED' , 'ROOM' , nPlayers ) ; // Start counting a timeout for max stay in waiting room. waitRoom . makeTimeOut ( p . id , waitTime ) ; // Wait for all players to connect. if ( nPlayers < waitRoom . POOL_SIZE ) return ; if ( waitRoom . EXECUTION_MODE === 'WAIT_FOR_N_PLAYERS' ) { waitRoom . dispatch ( { action : 'AllPlayersConnected' , exit : 0 } ) ; } } else { node . say ( 'ROOM_CLOSED' , p . id ) ; } }
Using self-calling function to put `firstTime` into closure.
Using self - calling function to put firstTime into closure .