File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
src/commonMain/kotlin/moe/nikky/vrcobs Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -93,11 +93,26 @@ object ViewersCommand : BaseCommand(
9393 try {
9494 val response = httpClient.get(" http://api.vrcdn.live/v1/viewers/$streamName " )
9595 .body<ViewersResponse >()
96+ // while(responseQueue.firstOrNull()?.second == response) {
97+ // responseQueue.removeFirst()
98+ // }
9699 responseQueue.addFirst(Clock .System .now() to response)
97- if (responseQueue.size > 100 ) {
100+ if (responseQueue.size > 100 ) {
98101 responseQueue.removeLast()
99102 }
100- animation.update(responseQueue.takeLast(10 ))
103+ val filtered = responseQueue
104+ .asSequence()
105+ .fold(
106+ initial = listOf<Pair <Instant , ViewersResponse >>()
107+ ) { acc, nextEntry ->
108+ val (timestamp, viewers) = nextEntry
109+ if (acc.lastOrNull()?.second?.hashCode() == viewers.hashCode()) {
110+ acc
111+ } else {
112+ acc + nextEntry
113+ }
114+ }
115+ animation.update(filtered.take(10 ).toList())
101116 } catch (e: Exception ) {
102117 logger.error(e) { " failed to get viewers" }
103118 }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ package moe.nikky.vrcobs.graph
33import kotlinx.serialization.Serializable
44
55@Serializable
6- class ViewersResponse (
6+ data class ViewersResponse (
77 val viewers : List <Region >
88) {
99 @Serializable
You can’t perform that action at this time.
0 commit comments