-
Notifications
You must be signed in to change notification settings - Fork 9
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
Veue 486 audience view show VOD badges when broadcast finishes #311
Changes from all commits
9d292f6
d6a4453
1f0e694
2e1b58d
8af4e6a
fbec65e
70514c2
372d3e3
75f566b
f6772f2
42025a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,12 +34,13 @@ function hideLoginElements(): void { | |
}); | ||
} | ||
|
||
function visibilityOfDataElement( | ||
export function visibilityOfDataElement( | ||
dataElementName: HTMLElement, | ||
hidden: boolean | ||
hidden: boolean, | ||
visibility: string = "block" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 if you do |
||
): void { | ||
dataElementName.setAttribute( | ||
"style", | ||
hidden ? "display: none;" : "display: block;" | ||
hidden ? "display: none;" : `display: ${visibility};` | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
import { | ||
visibilityOfDataElement, | ||
currentUserId, | ||
} from "./authentication_helpers"; | ||
|
||
export function getVideoId(): string { | ||
return document | ||
.querySelector("*[data-video-id]") | ||
|
@@ -30,3 +35,38 @@ export function getVideoVisibility(): Visibility { | |
function getVideoVisibilityElement(): HTMLElement { | ||
return document.querySelector("*[data-video-visibility]"); | ||
} | ||
|
||
export function showHideWhenLive() { | ||
showStreamElements(); | ||
hideStreamElements(); | ||
} | ||
|
||
export function currentStreamType(): string | undefined { | ||
const element = document.querySelector("*[data-audience-view-stream-type]"); | ||
return element?.getAttribute("data-audience-view-stream-type"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I always forget we use TS and can use optional chaining!! |
||
} | ||
|
||
function showStreamElements() { | ||
let vodStream = currentStreamType() !== "vod"; | ||
document | ||
.querySelectorAll("*[data-show-when-live]") | ||
.forEach((element: HTMLElement) => { | ||
const showOnAudience = element.dataset.hasOwnProperty("showOnAudience"); | ||
vodStream = showOnAudience ? vodStream : vodStream && !!currentUserId(); | ||
|
||
visibilityOfDataElement(element, !vodStream, "flex"); | ||
}); | ||
} | ||
|
||
function hideStreamElements() { | ||
let vodStream = currentStreamType() === "vod"; | ||
|
||
document | ||
.querySelectorAll("*[data-show-when-vod]") | ||
.forEach((element: HTMLElement) => { | ||
const showOnAudience = element.dataset.hasOwnProperty("showOnAudience"); | ||
vodStream = showOnAudience ? vodStream : vodStream && !!currentUserId(); | ||
|
||
visibilityOfDataElement(element, !vodStream, "flex"); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type VideoState = { | ||
state: string; | ||
type: string; | ||
timecodeMs: number; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,33 +7,51 @@ | |
"target": "audience--header-bar.addressInput" | ||
} | ||
} | ||
- if current_video.live? | ||
.widget | ||
.icon | ||
= svg_tag "view" | ||
#active-viewers{ | ||
"data": { | ||
"controller": "live-viewer-count", | ||
"target": "live-viewer-count.counter" | ||
} | ||
}= current_video.active_viewers_count | ||
.widget.live | ||
.widget-live__desktop | ||
LIVE | ||
.widget-live__mobile | ||
= svg_tag "live" | ||
- if current_video.finished? | ||
- video_views = current_video.video_views.count | ||
.widget{"data-views": video_views} | ||
.icon | ||
= svg_tag "view" | ||
#active-viewers | ||
= video_views | ||
.replay-badge | ||
.replay-badge__text | ||
REPLAY | ||
= svg_tag "no-stream", class: "replay-badge__image" | ||
.badge-message | ||
.badge-message__body | ||
This stream happened on | ||
= current_video.created_at.strftime("%B %d, %Y") | ||
.widget{ | ||
data: { | ||
"show-when-live": true, | ||
"show-on-audience": true, | ||
} | ||
} | ||
Comment on lines
+10
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ hmmm...these repeated data-* attributes dont feel great. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ParamagicDev yeah, but required for show/hide. I think otherwise we need to fetch Markup from backend. 🤔 |
||
.icon | ||
= svg_tag "view" | ||
#active-viewers{ | ||
"data": { | ||
"controller": "live-viewer-count", | ||
"target": "live-viewer-count.counter" | ||
} | ||
}= current_video.active_viewers_count | ||
.widget.live{ | ||
data: { | ||
"show-when-live": true, | ||
"show-on-audience": true | ||
} | ||
} | ||
.widget-live__desktop | ||
LIVE | ||
.widget-live__mobile | ||
= svg_tag "live" | ||
.widget{ | ||
data: { | ||
views: video_views, | ||
"show-when-vod": true, | ||
"show-on-audience": "true" | ||
} | ||
} | ||
.icon | ||
= svg_tag "view" | ||
#active-viewers | ||
= video_views | ||
.replay-badge{ | ||
data: { | ||
"show-when-vod": true, | ||
"show-on-audience": true | ||
} | ||
} | ||
.replay-badge__text | ||
REPLAY | ||
= svg_tag "no-stream", class: "replay-badge__image" | ||
.badge-message | ||
.badge-message__body | ||
This stream happened on | ||
= current_video.created_at.strftime("%B %d, %Y") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny note, we use a
counter_cache
on video views, instead of count we should be usingsize
since itll read from the counter_cache first, and then if it cant find it will query from the database to get the count.#count
will always query the database for a count.https://blog.appsignal.com/2018/06/19/activerecords-counter-cache.html