Long pulling method added

This commit is contained in:
Eudes Inácio
2021-07-26 10:52:14 +01:00
parent 1c25190787
commit 21c0bd8956
2 changed files with 66 additions and 2 deletions
+29 -2
View File
@@ -59,6 +59,7 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges {
this.load();
/* }, 9000); */
console.log(this.roomId);
}
@@ -113,14 +114,19 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges {
}
loadMessages(){
this.showLoader = true;
//this.showLoader = true;
this.chatService.getRoomMessages(this.roomId).subscribe(res => {
/* console.log(res); */
this.messages = res['messages'].reverse();
console.log(this.messages);
this.showLoader = false;
this.serverLongPull(res)
/* this.chatService.subscribe(this.roomId).then(res => {
console.log("Real fake msg", res)
}); */
//this.showLoader = false;
})
}
getChatMembers(){
console.log(this.roomId);
@@ -282,6 +288,27 @@ export class MessagesPage implements OnInit, AfterViewChecked, OnChanges {
return await modal.present();
}
async serverLongPull(res){
if (res == 502) {
// Connection timeout
// happens when the connection was pending for too long
// let's reconnect
await this.serverLongPull(res);
} else if (res != 200) {
// Show Error
//showMessage(response.statusText);
this.load()
// Reconnect in one second
await new Promise(resolve => setTimeout(resolve, 1000));
await this.serverLongPull(res);
} else {
// Got message
//let message = await response.text();
this.load()
await this.serverLongPull(res);
}
}
}