Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display currently watching viewer count on live streams #4206

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
row-gap: 16px;
}

.watchingCount {
font-weight: normal;
absidue marked this conversation as resolved.
Show resolved Hide resolved
margin-inline-start: 5px;
font-size: 15px;
color: var(--tertiary-text-color);
}

.message {
font-size: 18px;
color: var(--tertiary-text-color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import FtButton from '../ft-button/ft-button.vue'
import autolinker from 'autolinker'
import { getRandomColorClass } from '../../helpers/colors'
import { getLocalVideoInfo, parseLocalTextRuns } from '../../helpers/api/local'
import { formatNumber } from '../../helpers/utils'

export default defineComponent({
name: 'WatchVideoLiveChat',
Expand All @@ -30,6 +31,7 @@ export default defineComponent({
},
data: function () {
return {
/** @type {import('youtubei.js').YT.LiveChat|null} */
liveChatInstance: null,
isLoading: true,
hasError: false,
Expand All @@ -52,7 +54,9 @@ export default defineComponent({
amount: '',
colorClass: ''
}
}
},
/** @type {number|null} */
watchingCount: null,
}
},
computed: {
Expand All @@ -74,6 +78,14 @@ export default defineComponent({

scrollingBehaviour: function () {
return this.$store.getters.getDisableSmoothScrolling ? 'auto' : 'smooth'
},

hideVideoViews: function () {
return this.$store.getters.getHideVideoViews
},

formattedWatchingCount: function () {
return this.watchingCount !== null ? formatNumber(this.watchingCount) : '0'
}
},
beforeDestroy: function () {
Expand Down Expand Up @@ -181,6 +193,12 @@ export default defineComponent({
}
})

this.liveChatInstance.on('metadata-update', metadata => {
if (!this.hideVideoViews && metadata.views && !isNaN(metadata.views.original_view_count)) {
this.watchingCount = metadata.views.original_view_count
}
})

this.liveChatInstance.once('end', () => {
this.hasEnded = true
this.liveChatInstance = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@
v-else
class="relative"
>
<h4>{{ $t("Video.Live Chat") }}</h4>
<h4>
{{ $t("Video.Live Chat") }}
<span
v-if="!hideVideoViews && watchingCount !== null"
class="watchingCount"
>
{{ $tc('Global.Counts.Watching Count', watchingCount, { count: formattedWatchingCount }) }}
</span>
</h4>
<div
v-if="superChatComments.length > 0"
class="superChatComments"
Expand Down