Here's a quick summary: How can I trigger a function inside a view-model from outside of it using Aurelia?
I want to automatically log out a user if they remain inactive for a certain amount of time without performing any actions. After reading through this GitHub issue, I created an inactivity-logout view and view-model, integrated them into my app.html file, and used the attached() function to start a timer that logs the user out when the time limit is reached.
While everything is functioning as expected, I encountered an issue that has left me feeling lost. How do I call the resetInactivityTimer() function from another class outside of the view-model? Is there a way to make a function publicly accessible within a class? For example, when a request is made to the server, I would like to invoke the resetInactivityTimer() function from my service class.
inactivity-logout.ts
import {Aurelia} from 'aurelia-framework';
import {Router} from 'aurelia-router';
import {inject} from 'aurelia-dependency-injection';
@inject(Aurelia, Router)
export class InactivityLogout {
inactivityWarningDuration: number;
initialInactivityWarningDuration: number;
inactivityDuration: number;
inactivityIntervalHandle: any;
constructor(aurelia, router) {
// Constructor code here
}
attached() {
this.queueInactivityTimer();
}
resetInactivityTimer(){
// Function code here
}
queueInactivityTimer(){
// Function code here
}
displayWarning(){
// Function code here
}
logout(){
// Function code here
}
}
app.html
<require from='./inactivity-logout.js'></require>
<inactivity-logout></inactivity-logout>
search-service.ts
performSearch(searchText: String) {
/*
* Code here to reset the inactivity timer
*/
return this.httpClient.put("/api/Search", searchText)
.then(response => {
return response;
});
}