improve chat token timer

This commit is contained in:
Peter Maquiran
2022-09-30 14:20:29 +01:00
parent 47dee7180a
commit cc9be61de4
+25 -12
View File
@@ -354,7 +354,7 @@ export class ChatService {
headers: this.headers,
};
this.resetTimer()
this.resetTimer();
}
}
} catch (error) {
@@ -370,18 +370,26 @@ export class ChatService {
headers: this.headers
};
let res = await this.http.get(environment.apiURL + 'UserAuthentication/RegenereChatToken', options).toPromise();
let data = {
status: res['status'],
data: {
userId: res['data'].userId,
authToken: res['data'].authToken
try {
let res = await this.http.get(environment.apiURL + 'UserAuthentication/RegenereChatToken', options).toPromise();
let data = {
status: res['status'],
data: {
userId: res['data'].userId,
authToken: res['data'].authToken
}
}
SessionStore.user.ChatData = data
SessionStore.save()
this.setheader()
this.timerEventTriggerDateLastUpdate = new Date();
} catch (error) {
this.resetTimer();
}
SessionStore.user.ChatData = data
SessionStore.save()
this.setheader()
} else {
this.setheader()
@@ -391,10 +399,15 @@ export class ChatService {
functionTimer = null;
timerEventTriggerDate = null
timerEventTriggerDateLastUpdate = null
resetTimer() {
clearTimeout(this.functionTimer);
this.functionTimer = setTimeout(()=>{
this.timerEventTriggerDate = new Date(+new Date() + 60000*15);
this.functionTimer = setTimeout(() => {
this.timerEventTriggerDateLastUpdate = new Date();
this.refreshtoken();
}, 60000 * 5); // time is in milliseconds
}