Skip to content

Commit ce04f99

Browse files
committed
Display currently watching viewer count on live streams
1 parent c1d3707 commit ce04f99

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/renderer/components/watch-video-live-chat/watch-video-live-chat.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
row-gap: 16px;
2323
}
2424

25+
.watchingCount {
26+
font-weight: normal;
27+
}
28+
2529
.message {
2630
font-size: 18px;
2731
color: var(--tertiary-text-color);

src/renderer/components/watch-video-live-chat/watch-video-live-chat.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import FtButton from '../ft-button/ft-button.vue'
66
import autolinker from 'autolinker'
77
import { getRandomColorClass } from '../../helpers/colors'
88
import { getLocalVideoInfo, parseLocalTextRuns } from '../../helpers/api/local'
9+
import { formatNumber } from '../../helpers/utils'
910

1011
export default defineComponent({
1112
name: 'WatchVideoLiveChat',
@@ -30,6 +31,7 @@ export default defineComponent({
3031
},
3132
data: function () {
3233
return {
34+
/** @type {import('youtubei.js').YT.LiveChat|null} */
3335
liveChatInstance: null,
3436
isLoading: true,
3537
hasError: false,
@@ -52,7 +54,9 @@ export default defineComponent({
5254
amount: '',
5355
colorClass: ''
5456
}
55-
}
57+
},
58+
/** @type {number|null} */
59+
watchingCount: null,
5660
}
5761
},
5862
computed: {
@@ -74,6 +78,14 @@ export default defineComponent({
7478

7579
scrollingBehaviour: function () {
7680
return this.$store.getters.getDisableSmoothScrolling ? 'auto' : 'smooth'
81+
},
82+
83+
hideVideoViews: function () {
84+
return this.$store.getters.getHideVideoViews
85+
},
86+
87+
formattedWatchingCount: function () {
88+
return this.watchingCount !== null ? formatNumber(this.watchingCount) : '0'
7789
}
7890
},
7991
beforeDestroy: function () {
@@ -181,6 +193,12 @@ export default defineComponent({
181193
}
182194
})
183195

196+
this.liveChatInstance.on('metadata-update', metadata => {
197+
if (!this.hideVideoViews && metadata.views && !isNaN(metadata.views.original_view_count)) {
198+
this.watchingCount = metadata.views.original_view_count
199+
}
200+
})
201+
184202
this.liveChatInstance.once('end', () => {
185203
this.hasEnded = true
186204
this.liveChatInstance = null

src/renderer/components/watch-video-live-chat/watch-video-live-chat.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@
4242
v-else
4343
class="relative"
4444
>
45-
<h4>{{ $t("Video.Live Chat") }}</h4>
45+
<h4>
46+
{{ $t("Video.Live Chat") }}
47+
<span
48+
v-if="!hideVideoViews && watchingCount !== null"
49+
class="watchingCount"
50+
>
51+
{{ $tc('Global.Counts.Watching Count', watchingCount, { count: formattedWatchingCount }) }}
52+
</span>
53+
</h4>
4654
<div
4755
v-if="superChatComments.length > 0"
4856
class="superChatComments"

0 commit comments

Comments
 (0)