Package arez.dom

Class IdleStatus

java.lang.Object
arez.dom.IdleStatus

@ArezComponent(requireId=DISABLE) public abstract class IdleStatus extends Object
An Arez browser component that tracks when the user is idle. A user is considered idle if they have not interacted with the browser for a specified amount of time. The component declares state that tracks when the user is "idle". A user is considered idle if they have not interacted with the browser for a specified amount of time.

Application code can observe the idle state via accessing isIdle(). Typically this is done in a tracking transaction such as those defined by autorun.

The "amount of time" is defined by the Observable value "timeout" accessible via getTimeout() and mutable via setTimeout(long).

The "not interacted with the browser" is detected by listening for interaction events on the browser. The list of events that the model listens for is controlled via getEvents() and setEvents(Set). It should be noted that if there is no observer observing the idle state then the model will remove listeners so as not to have any significant performance impact.

A very simple example


 import com.google.gwt.core.client.EntryPoint;
 import akasha.Console;
 import arez.Arez;
 import arez.dom.IdleStatus;

 public class IdleStatusExample
   implements EntryPoint
 {
   public void onModuleLoad()
   {
     final IdleStatus idleStatus = IdleStatus.create();
     Arez.context().autorun( () -> {
       final String message = "Interaction Status: " + ( idleStatus.isIdle() ? "Idle" : "Active" );
       Console.log( message );
     } );
   }
 }
 
  • Method Details

    • create

      @Nonnull public static IdleStatus create()
      Create an instance of this model.
      Returns:
      an instance of IdleStatus.
    • create

      @Nonnull public static IdleStatus create(long timeout)
      Create an instance of this model.
      Parameters:
      timeout - the duration to after activity before becoming idle.
      Returns:
      an instance of IdleStatus.
    • isIdle

      @Memoize public boolean isIdle()
      Return true if the user is idle.
      Returns:
      true if the user is idle, false otherwise.
    • getTimeout

      @Observable(initializer=ENABLE) public abstract long getTimeout()
      Return the duration for which no events should be received for the idle condition to be triggered.
      Returns:
      the timeout.
    • setTimeout

      public abstract void setTimeout(long timeout)
      Set the timeout.
      Parameters:
      timeout - the timeout.
    • getEvents

      @Nonnull @Observable public Set<String> getEvents()
      Return the set of events to listen to.
      Returns:
      the set of events.
    • setEvents

      public void setEvents(@Nonnull Set<String> events)
      Specify the set of events to listen to. If the model is already active, the listeners will be updated to reflect the new events.
      Parameters:
      events - the set of events.
    • getLastActivityAt

      @Observable public abstract long getLastActivityAt()
      Return the time at which the last monitored event was received.
      Returns:
      the time at which the last event was received.