diff --git a/src/app/services/chat.service.ts b/src/app/services/chat.service.ts index 7bf3c146f..51a5d0be3 100644 --- a/src/app/services/chat.service.ts +++ b/src/app/services/chat.service.ts @@ -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 }