mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
Long pulling method added
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user