Project

General

Profile

Setup

It is required to go to the Servoy Admin page, and the Server Plugins area and set the com.servoyguy.plugins.robot.accesspassword

Example Usage to disconnect clients idle for 1 hour

function disconnectIdleClients(){
    try{
        var validPassword = plugins.servoyguy_robot.checkAccessPassword('yourPassHere')
        if(!validPassword)
            return

        var clients = plugins.servoyguy_robot.getClients()

        for(var i=0; i<clients.length; i++)
        {
            try{
                var ts = clients[i].getIdleTimestamp()
                var lastActive = new Date(ts)
                var now = new Date()
                var diff = now.getTime() - lastActive.getTime()
                var diffSeconds = Math.abs(diff / 1000);

                var OneHourInSeconds = 3600

                if(clients[i].getApplicationType() != APPLICATION_TYPES.HEADLESS_CLIENT && diffSeconds > OneHourInSeconds)
                    clients[i].shutdown()

            }
            catch(e){
                application.output(e)
            }
        }
    }
    catch(e){
        application.output(e)
    }
}

Then create a new solution, and onSolutionOpen on that new solution, include this code. That will run it every 15 minutes to check and see if there are idle users to disconnect.

plugins.scheduler.addCronJob('disconnectIdleClients','0 0/15 * * * ?', globals.disconnectIdleClients)

Note: Remember to make sure your disconnectIdleClients function is in the solution, or a module of the solution so it can run