mirror of
https://github.com/NicolasConstant/sengi
synced 2025-02-06 13:23:42 +01:00
added buffer logic when scrolling the stream
This commit is contained in:
parent
a3e63366a7
commit
0795a39502
@ -18,6 +18,7 @@ export class StreamComponent implements OnInit {
|
||||
private websocketStreaming: StreamingWrapper;
|
||||
|
||||
statuses: Status[] = [];
|
||||
private bufferStream: Status[] = [];
|
||||
|
||||
@Input()
|
||||
set streamElement(streamElement: StreamElement) {
|
||||
@ -70,9 +71,19 @@ export class StreamComponent implements OnInit {
|
||||
console.log('Bottom reached!!');
|
||||
this.streamPositionnedAtBottom = true;
|
||||
} else if (atTop) {
|
||||
this.scrolledToTop()
|
||||
}
|
||||
}
|
||||
|
||||
private scrolledToTop() {
|
||||
console.log('Top reached!!');
|
||||
this.streamPositionnedAtTop = true;
|
||||
|
||||
for (const status of this.bufferStream) {
|
||||
this.statuses.unshift(status); //TODO check order of status
|
||||
}
|
||||
|
||||
this.bufferStream.length = 0;
|
||||
}
|
||||
|
||||
private getRegisteredAccounts(): AccountInfo[] {
|
||||
@ -89,13 +100,19 @@ export class StreamComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
private launchWebsocket(): void {
|
||||
this.websocketStreaming = this.streamingService.getStreaming(this.account, this._streamElement.type);
|
||||
this.websocketStreaming.statusUpdateSubjet.subscribe((update: StatusUpdate) => {
|
||||
if (update) {
|
||||
if (update.type === EventEnum.update) {
|
||||
if (!this.statuses.find(x => x.id == update.status.id)) {
|
||||
if (this.streamPositionnedAtTop) {
|
||||
this.statuses.unshift(update.status);
|
||||
} else {
|
||||
this.bufferStream.unshift(update.status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,9 +123,11 @@ export class StreamComponent implements OnInit {
|
||||
|
||||
private checkAndCleanUpStream(): void {
|
||||
if (this.streamPositionnedAtTop && this.statuses.length > 60) {
|
||||
console.log(`clean up start! ${this.statuses.length}`);
|
||||
this.statuses.length = 40;
|
||||
console.log(`clean up ends! ${this.statuses.length}`);
|
||||
}
|
||||
|
||||
if (this.bufferStream.length > 60) {
|
||||
this.bufferStream.length = 40;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user