Files
nairobi/app/components/shared/embedded_video_component.rb
Javi Martín 442156b1cc Don't use cookies when embedding youtube videos
When embedding a video in our site YouTube stores cookies in the user's
computer that aren't necessary to watch the video, so we'd have to make
people accept those cookies before letting them watch the video.

Using a URL that doesn't use cookies, like mentioned in YouTube Help
[1], is easier, though, and respects people's privacy without affecting
the user experience.

That I've found some references saying that youtube does store cookies
once you hit the "play" button even when using the nocookie server [2].
Not sure whether that's an old behavior or I'm doing something wrong,
but I don't see this is the case; even after playing the video, cookies
aren't stored on my browser.

[1] https://support.google.com/youtube/answer/171780#zippy=%2Cturn-on-privacy-enhanced-mode
[2] https://www.cnet.com/news/privacy/youtubes-new-nocookie-feature-continues-to-serve-cookies/
2024-06-06 17:35:27 +02:00

60 lines
1.1 KiB
Ruby

class Shared::EmbeddedVideoComponent < ApplicationComponent
attr_reader :record
def initialize(record)
@record = record
end
def render?
record.video_url.present?
end
def embedded_video_code
if match && match[2]
"<iframe #{iframe_attributes}></iframe>"
end
end
private
def link
record.video_url
end
def title
t("proposals.show.embed_video_title", proposal: record.title)
end
def server
if link =~ /vimeo.*/
"Vimeo"
elsif link =~ /youtu*.*/
"YouTube"
end
end
def regex
if server == "Vimeo"
record.class::VIMEO_REGEX
elsif server == "YouTube"
record.class::YOUTUBE_REGEX
end
end
def src
if server == "Vimeo"
"https://player.vimeo.com/video/"
elsif server == "YouTube"
"https://www.youtube-nocookie.com/embed/"
end
end
def match
@match ||= link.match(regex) if regex
end
def iframe_attributes
tag.attributes(src: "#{src}#{match[2]}", style: "border:0;", allowfullscreen: true, title: title)
end
end