ibm-mobilefirstworklight-serverworklight-runtime

Session Timeout Notification in worklight


I am creating an app in IBM Worklight 6.2 for my Organization. I have set session timetout property in worklight.properties to 5 mins.

#######################################
    Idle session timeout in minutes
#######################################
serverSessionTimeout=5

Its working perfectly fine and user is getting logged out from app, however, its not notifying that session timeout is occurred. Is there any way through which I can notify user that his session is going to expire in a minute or so?


Solution

  • There is no way to get notified by Worklight that the session is about to expire.

    My suggestion is to create a local timer in the application in order to get an approximation of when the timeout will occur and notify the user accordingly.

    This can be achieved for example by implementing setInterval in the onSuccess callback of WL.Client.connect (assuming this is how you are connecting to Worklight Server).

    Could be something like this:

    function wlCommonInit() {
        WL.Client.connect({onSuccess: connectSuccess, onFailure: connectFailure});
    }
    
    function connectSuccess() {
        setInterval (timesUp, 240000);
        // other things ...
    }
    
    function connectFailure() {
        // ...
    }
    
    function timesUp() {
        alert ("Session will expire in 1 minute.");
        clearInterval();
        // Maybe show a WL.SimpleDialog instead with buttons 
        // to reset the timeout by performing some action against the server or some such.
    }