mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
Long pulling method added
This commit is contained in:
@@ -23,6 +23,7 @@ export class ChatService {
|
||||
SERVER_URL = 'wss://www.tabularium.pt/websocket';
|
||||
public messages: Subject<any>;
|
||||
loggedUserChat:any;
|
||||
bindOnMessage: any;
|
||||
|
||||
constructor(
|
||||
private http:HttpClient,
|
||||
@@ -242,4 +243,40 @@ export class ChatService {
|
||||
return this.http.post(environment.apiChatUrl+'groups.kick', body, opts);
|
||||
}
|
||||
|
||||
async subscribe(roomId:any) {
|
||||
console.log('Subcrive')
|
||||
let params = new HttpParams();
|
||||
params = params.set("roomId", roomId);
|
||||
let opts = {
|
||||
headers: this.headers,
|
||||
params: params
|
||||
}
|
||||
|
||||
this.http.get(environment.apiChatUrl+'im.messages', opts).subscribe(async res => {
|
||||
console.log("Subcrive", res)
|
||||
|
||||
if (res == 502) {
|
||||
// Connection timeout
|
||||
// happens when the connection was pending for too long
|
||||
// let's reconnect
|
||||
await this.subscribe(roomId);
|
||||
} else if (res != 200) {
|
||||
// Show Error
|
||||
//showMessage(response.statusText);
|
||||
this.getRoomMessages(roomId)
|
||||
// Reconnect in one second
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
await this.subscribe(roomId);
|
||||
} else {
|
||||
// Got message
|
||||
//let message = await response.text();
|
||||
this.getRoomMessages(roomId)
|
||||
await this.subscribe(roomId);
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user