class Decidim::Meetings::MeetingIframeEmbedder
the structure of the URL.
in the live event. For some services it’s required to transforma a bit
This class handles the streaming url to be included in the iframe present
def embed_code(request_host)
def embed_code(request_host) return nil if parsed_online_meeting_uri.nil? <<~HTML <div class="disabled-iframe"> <!-- <iframe allow="camera; microphone; fullscreen; display-capture; autoplay" loading="lazy" src="#{embed_transformed_url(request_host)}" style="height: 100%; width: 100%; border: 0px;"></iframe> --> </div> HTML end
def embed_transformed_url(request_host)
def embed_transformed_url(request_host) return nil if parsed_online_meeting_uri.nil? case parsed_online_meeting_uri.host when "www.youtube.com" transform_youtube_url(parsed_online_meeting_uri) when "www.twitch.tv" transform_twitch_url(parsed_online_meeting_uri, request_host) else online_meeting_service_url end end
def embeddable?
def embeddable? return nil if parsed_online_meeting_uri.nil? embeddable_services.include?(parsed_online_meeting_uri.host) end
def embeddable_services
def embeddable_services @embeddable_services ||= Meetings.embeddable_services end
def initialize(online_meeting_service_url)
Public: Initializes the service.
def initialize(online_meeting_service_url) @online_meeting_service_url = online_meeting_service_url end
def parsed_online_meeting_uri
def parsed_online_meeting_uri @parsed_online_meeting_uri ||= URI.parse(online_meeting_service_url) if online_meeting_service_url.present? end
def transform_twitch_url(uri, request_host)
2. extract the request host
1. extract the video id from the third URL parameter
Twitch transformation consists on:
def transform_twitch_url(uri, request_host) _, param_name, video_id = *uri.path.split("/") return online_meeting_service_url if video_id.blank? || param_name != "videos" "https://player.twitch.tv/?video=#{video_id}&parent=#{request_host}" end
def transform_youtube_url(uri)
2. Create a new URL using the domain youtube-nocookie.com, converting it to an embed
1. extract the video id from the parameter v
Youtube transformation consists on:
def transform_youtube_url(uri) return online_meeting_service_url if uri.query.blank? parsed_query = CGI.parse(uri.query) video_id = parsed_query.has_key?("v") ? CGI.parse(uri.query).fetch("v")&.first : nil return online_meeting_service_url if video_id.blank? "https://www.youtube-nocookie.com/embed/#{video_id}" end