application timeout

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
randyh
Profound User
Posts: 21
Joined: Mon Dec 15, 2014 5:21 pm
First Name: Randy
Last Name: Heinz
Company Name: Southwestern Motor Transport
Phone: 210.662.3272
Address 1: 4600 Goldfield
City: San Antonio
State / Province: Texas
Zip / Postal Code: 78218
Country: United States
Contact:

application timeout

Post by randyh »

I would like to start a new session when a user has no activity on the web page for 60 seconds.

So I launch an anonymous program which works fine for the initial signon. It executes a program which has menu options that a user can chose from. Each of the display files from the menu program, I've coded this on the onload of a record format.

var count = 60; // 300 seconds or 5 minutes

setInterval(function() {
count = count - 1;
if (count < 0) {
pui.start();
// to do - quit program or end session here
}
}, 1000); // call this every second (1000 milliseconds)

pui.onuseractivity = function() {
// reset counter
counter = 60;
}

After cycling for 60 seconds, the program will end and my first anonymous program appears again, but it continually cycling through not allowing me to enter in a userid and password.
User avatar
Alex
Profound Logic Staff Member
Posts: 233
Joined: Fri Jan 04, 2008 12:10 pm
First Name: Alex
Last Name: Roytman
Company Name: Profound Logic Software
Contact:

Re: application timeout

Post by Alex »

I am not sure if you realize this, but setInterval() will continue firing even after navigating to a different screen because Profound UI does not reload the page as you move through the applications -- the screens are fetched through AJAX. Therefore, putting this code into multiple screen's onload events may not be best practice. Or, at the very least, you should consider setting up clearInterval() when the screen submits?

Also, Profound UI has some built-in user/session inactivity timeout features. The timeout value for this can be modified. If these features do not do what you want, and you are looking to implement this type of stuff on your own, we ship a JavaScript class called pui.Timer() that can help with this. pui.Timer has methods built-in methods to start and stop the timer.

To be complete, you should also have something that keeps the server alive by pinging it once in a while. Because technically the user could be active (moving mouse around or typing) on the screen, but in the meanwhile the server side could time out.

Here is some example code that does something similar to what you're trying to accomplish:

Code: Select all

// Turn off Profound UI's built-in client-side timeout monitoring
pui["client side timeout"] = false;

var timeoutMonitor = {};

timeoutMonitor.timer = new pui["Timer"]();
timeoutMonitor.timer.action = function() {
  if (getObj("timeout") != null) pui.click("timeout");
  timeoutMonitor.timer.stop();
  timeoutMonitor.keepalive.stop();
}

timeoutMonitor.keepalive = new pui["Timer"]();
timeoutMonitor.keepalive.action = function() {
  pui["keepAlive"]();
}

timeoutMonitor.start = function() {  // this is called when a screen is rendered
  timeoutMonitor.timer.stop();
  timeoutMonitor.keepalive.stop();
  if (getObj("timeout") == null) return;
  var timeout = getObj("timeout").pui.properties["user defined data"];
  if (timeout == null) return;
  timeout = Number(timeout);
  if (isNaN(timeout) || timeout <= 0) return;
  var keepAliveValue = 600;  // keep Profound UI session alive every 10 minutes
  timeoutMonitor.timer.timeout = timeout;
  //timeoutMonitor.timer.showDebugInfo = true;
  timeoutMonitor.keepalive.timeout = keepAliveValue;
  //timeoutMonitor.keepalive.showDebugInfo = true;
  timeoutMonitor.timer.start();
  timeoutMonitor.keepalive.start();
}

timeoutMonitor.end = function() {  // this is called when a screen is submitted
  timeoutMonitor.timer.stop();
  timeoutMonitor.keepalive.stop();
}

pui.onuseractivity = function() {
  timeoutMonitor.timer.reset();
}
The code looks for a hidden button on your screens with an id of "timeout". This can be bound to a response indicator to let the RPG program know that the screen has timed out. This element should also have the timeout value specified in seconds in the "user defined data" property. When there is no activity, the hidden button is "pressed" by the code. The code also keeps the sever alive.

To implement this, I would put the code into an external JS file. It could go into your /www/profoundui/htdocs/profoundui/userdata/custom/js directory. Then on the screens' onload event, use timeoutMonitor.start(). And on the screens' onsubmit event, use timeoutMonitor.end().
randyh
Profound User
Posts: 21
Joined: Mon Dec 15, 2014 5:21 pm
First Name: Randy
Last Name: Heinz
Company Name: Southwestern Motor Transport
Phone: 210.662.3272
Address 1: 4600 Goldfield
City: San Antonio
State / Province: Texas
Zip / Postal Code: 78218
Country: United States
Contact:

Re: application timeout

Post by randyh »

Alex

I new to java coding so bear with me.

Where do I control the length of time for the timeout monitoring. I'd like to use 1 minute.

I have saved the js script included to our IFS and I added the onload and onsubmit calls as directed but it still not working for me. In the java script the is "user defined data" do I need to put something there?

In my programs I doing a return to exit the program but how do I make it call the inital program which will bring up my anonymous window signon program.
User avatar
Alex
Profound Logic Staff Member
Posts: 233
Joined: Fri Jan 04, 2008 12:10 pm
First Name: Alex
Last Name: Roytman
Company Name: Profound Logic Software
Contact:

Re: application timeout

Post by Alex »

"user defined data" is an element property in the Visual Designer.

For this to work, you will need to add an element in the designer with the following properties:
id: timeout
field type: button
value: hidden timeout button
response: [bind to an RPG indicator]
user defined data: 60
visibility: hidden
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests