Skip to content

Commit

Permalink
Display currently watching viewer count on live streams (#4206)
Browse files Browse the repository at this point in the history
* Display currently watching viewer count on live streams

* Improve watching count styling

Co-authored-by: Jason <[email protected]>

---------

Co-authored-by: Jason <[email protected]>
  • Loading branch information
absidue and kommunarr authored Nov 21, 2023
1 parent a9fd502 commit d1a7b84
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
row-gap: 16px;
}

.watchingCount {
font-weight: normal;
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

0 comments on commit d1a7b84

Please sign in to comment.