chat interceptor added

This commit is contained in:
Eudes Inácio
2024-03-06 15:20:35 +01:00
parent d4c20457a2
commit af5d428134
4 changed files with 152 additions and 182 deletions
-55
View File
@@ -392,61 +392,6 @@ export class ChatService {
async refreshtoken() {
if(this.headers && SessionStore.user.ChatData) {
this.headers = this.headers.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
let options = {
headers: this.headers
};
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) {
if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Offline) {
this.RochetChatConnectorService.registerCallback({
requestId: 'refreshtoken',
type: 'reConnect',
funx: async () => {
this.resetTimer();
await this.refreshtoken();
return true
}
})
} else {
if(SessionStore.user.Authorization != '') {
setTimeout(async () => {
this.resetTimer();
await this.refreshtoken();
}, 60000)
}
}
}
} else if(!SessionStore.user.ChatData) {
// do nothing
} else if (!this.headers) {
this.setheader()
this.refreshtoken()
}
}