disable (temporary) retrying websocket when failed

This commit is contained in:
Nicolas Constant 2018-11-01 23:49:00 -04:00
parent 24be608434
commit 6628bd5e6f
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 40 additions and 17 deletions

View File

@ -28,7 +28,7 @@ export class UserProfileComponent implements OnInit {
//set currentAccount(account: Account) {
set currentAccount(accountName: string) {
this.statuses.length = 0;
this.isLoading = true;
this.isLoading = true;
this.loadAccount(accountName)
.then((account: Account) => {
@ -36,9 +36,10 @@ export class UserProfileComponent implements OnInit {
return this.getStatuses(this.account);
})
.catch(err => {
this.error = 'Error when retieving account';
this.error = 'Error when retrieving account';
this.isLoading = false;
this.statusLoading = false;
console.warn(this.error);
});
// this.account = account;
@ -70,21 +71,17 @@ export class UserProfileComponent implements OnInit {
if (selectedAccounts.length === 0) {
this.error = 'no user selected';
return;
console.error(this.error);
return Promise.resolve(null);
}
this.isLoading = true;
return this.mastodonService.search(selectedAccounts[0], accountName, true)
.then((result: Results) => {
console.warn(result);
this.isLoading = false;
return result.accounts[0];
});
// .catch((err) => {
// this.error = 'Error when retieving account';
// })
// .then(()=>{
// this.isLoading = false;
// });
}
private getStatuses(account: Account): Promise<void> {

View File

@ -39,11 +39,12 @@ export class StreamingWrapper {
this.eventSource.onmessage = x => this.statusParsing(<WebSocketEvent>JSON.parse(x.data));
this.eventSource.onerror = x => this.webSocketGotError(x);
this.eventSource.onopen = x => console.log(x);
this.eventSource.onclose = x => this.webSocketClosed(route, x);
this.eventSource.onclose = x => this.webSocketClosed(route, x);
}
private errorClosing: boolean;
private webSocketGotError(x: Event) {
console.log(x);
this.errorClosing = true;
}
@ -52,7 +53,36 @@ export class StreamingWrapper {
console.log(x);
if (this.errorClosing) {
this.mastodonService.getTimeline(this.accountInfo, this.streamType, null, this.since_id)
this.pullNewStatuses(domain);
// this.mastodonService.getTimeline(this.accountInfo, this.streamType, null, this.since_id)
// .then((status: Status[]) => {
// // status = status.sort((n1, n2) => { return (<number>n1.id) < (<number>n2.id); });
// status = status.sort((a, b) => a.id.localeCompare(b.id));
// for (const s of status) {
// const update = new StatusUpdate();
// update.status = s;
// update.type = EventEnum.update;
// this.since_id = update.status.id;
// this.statusUpdateSubjet.next(update);
// }
// })
// .catch(err => {
// console.error(err);
// })
// .then(() => {
// setTimeout(() => { this.start(domain) }, 20 * 1000);
// });
this.errorClosing = false;
} else {
setTimeout(() => { this.start(domain) }, 5000);
}
}
private pullNewStatuses(domain){
this.mastodonService.getTimeline(this.accountInfo, this.streamType, null, this.since_id)
.then((status: Status[]) => {
// status = status.sort((n1, n2) => { return (<number>n1.id) < (<number>n2.id); });
status = status.sort((a, b) => a.id.localeCompare(b.id));
@ -68,13 +98,9 @@ export class StreamingWrapper {
console.error(err);
})
.then(() => {
setTimeout(() => { this.start(domain) }, 20 * 1000);
// setTimeout(() => { this.start(domain) }, 20 * 1000);
setTimeout(() => { this.pullNewStatuses(domain) }, 15 * 1000);
});
this.errorClosing = false;
} else {
setTimeout(() => { this.start(domain) }, 5000);
}
}
private statusParsing(event: WebSocketEvent) {