-
Notifications
You must be signed in to change notification settings - Fork 1
Revise native oembed_controller.js to handle Kaltura embeds #88
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
Merged
Merged
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
1a45f42
Revise native oembed_controller.js to handle Kaltura embeds
rshiggin 264bd12
Refactored .js for video embed with better guards and fallbacks
rshiggin 1a282c1
External link icon for Kaltura URL, border and spacing between sections
rshiggin 47d92ed
Remove .al-show-sub-heading, it's too broad a target
rshiggin 768593b
move ead2002 directory to root of project
gkostin1966 01ef8ad
keep empty data directory in project root
gkostin1966 ec0716c
changes to compose
gkostin1966 908b7ea
changes to read me
gkostin1966 a6511e7
use Rails development environment
gkostin1966 f80e469
changes
gkostin1966 4e0b24c
change to production environment
gkostin1966 3c4f0f5
Brief refactoring in response to Copilot/Claude code review
rshiggin a8f5de9
Add class and improved output for nil repo ID/slug error
rshiggin 0c39bb8
Make /opt/app-data directory and specify permissions; mount source co…
ssciolla f0e4603
Remove source code mappings to fix assets pipeline
ssciolla 248c8dd
Convert search in banner from two layers to one
rshiggin 5c84f45
Select item button in leaf display toolbar, alongside Request and Cle…
rshiggin c559787
Remove unintended visible label from checkboxes, minor style changes
rshiggin ed0912e
Restrictions preview in component (leaf) display to match prod
rshiggin 5533797
Resolve conflicts
rshiggin 64bcdfd
Still resolving conflict with _contents.scss
rshiggin 922221f
Use locale file rather than catalog controller to translate parent re…
rshiggin 0f3531d
rubocop manual fixes
rshiggin 30c9145
Corrections responding to code review: moved solr query out of compon…
rshiggin 632e282
Clean up conflict markup
rshiggin da8061e
Ensure restrictions preview only appears on single items with restric…
rshiggin df20a16
Tighten up conmment
rshiggin b5fd900
rubocop correction
rshiggin 2c37303
Resolve additional conflicts
rshiggin 57a6fc1
Resolve conflicts
rshiggin e2737a0
Remove .al-show-sub-heading, it's too broad a target
rshiggin 7893ab8
Merge branch 'main' into arc-173-oembed-video
rshiggin 00c4cb5
Minor refactor of oembed js
rshiggin 044c543
Refactoring pass
rshiggin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import { Controller } from '@hotwired/stimulus' | ||
|
|
||
| const PARTNER_ID = '1758271' | ||
| const UICONF_ID = '56928822' | ||
| const PLAYER_HOST = 'https://cdnapisec.kaltura.com' | ||
| const ENTRY_ID_PATTERN = /^\d_[a-z0-9]{8}$/i | ||
|
|
||
| // Kaltura-backed hosts (kaltura.com and MediaSpace instances) | ||
| const KALTURA_HOST_SUFFIXES = ['.kaltura.com', '.mivideo.it.umich.edu'] | ||
|
|
||
| export default class OembedController extends Controller { | ||
| static values = { | ||
| url: String | ||
| } | ||
|
|
||
| connect() { | ||
| if (this.element.getAttribute('loaded') === 'loaded') return | ||
|
|
||
| const entryId = this.findKalturaEntryId() | ||
| if (entryId) { | ||
| this.loadKalturaEmbed(entryId) | ||
| return | ||
| } | ||
|
|
||
| this.loadOEmbed() | ||
| } | ||
|
|
||
| findKalturaEntryId() { | ||
| let url | ||
|
|
||
| try { | ||
| url = new URL(this.urlValue, window.location.href) | ||
| } catch (error) { | ||
| console.warn(`Invalid oEmbed URL: ${this.urlValue}`, error) | ||
| return null | ||
| } | ||
|
|
||
| const isKalturaHost = url.hostname === 'kaltura.com' | ||
|
rshiggin marked this conversation as resolved.
Outdated
|
||
| || KALTURA_HOST_SUFFIXES.some((suffix) => url.hostname.endsWith(suffix)) | ||
| if (!isKalturaHost) return null | ||
|
|
||
| const queryEntryId = url.searchParams.get('entry_id') | ||
| if (queryEntryId && ENTRY_ID_PATTERN.test(queryEntryId)) { | ||
| return queryEntryId | ||
| } | ||
|
|
||
| return url.pathname | ||
| .match(/(?:^|\/)(\d_[a-z0-9]{8})(?:\/|$)/i)?.[1] || null | ||
|
rshiggin marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| loadKalturaEmbed(entryId) { | ||
| const linkContainer = this.element.querySelector('.al-digital-object') | ||
| if (!linkContainer) { | ||
| console.warn('Could not find .al-digital-object for Kaltura embed') | ||
| return | ||
| } | ||
|
|
||
| const params = new URLSearchParams({ | ||
| iframeembed: 'true', | ||
| entry_id: entryId | ||
| }) | ||
|
|
||
| const iframe = document.createElement('iframe') | ||
| iframe.src = `${PLAYER_HOST}/p/${PARTNER_ID}/embedPlaykitJs/uiconf_id/${UICONF_ID}?${params}` | ||
| iframe.setAttribute('allowfullscreen', '') | ||
| iframe.setAttribute('allow', 'autoplay; fullscreen; encrypted-media') | ||
| iframe.setAttribute( | ||
| 'title', | ||
| this.element.querySelector('a')?.textContent?.trim() || 'Media player' | ||
| ) | ||
| iframe.style.cssText = 'width: 100%; aspect-ratio: 16 / 9; height: auto; border: 0;' | ||
|
|
||
| // Keep the original link as a fallback. | ||
| linkContainer.insertAdjacentElement('beforebegin', iframe) | ||
| this.element.setAttribute('loaded', 'loaded') | ||
| } | ||
|
|
||
| loadOEmbed() { | ||
| fetch(this.urlValue) | ||
| .then((response) => { | ||
| if (response.ok) return response.text() | ||
| throw new Error(`HTTP error, status = ${response.status}`) | ||
| }) | ||
| .then((body) => { | ||
| const endpoint = this.findOEmbedEndpoint(body) | ||
| if (!endpoint) { | ||
| console.warn(`No oEmbed endpoint found in <head> at ${this.urlValue}`) | ||
| return null | ||
| } | ||
|
|
||
| return fetch(endpoint) | ||
| }) | ||
| .then((response) => { | ||
| if (!response) return null | ||
| if (response.ok) return response.json() | ||
| throw new Error(`HTTP error, status = ${response.status}`) | ||
| }) | ||
| .then((json) => { | ||
| if (!json?.html) return | ||
|
|
||
| this.element.innerHTML = json.html | ||
| this.element.setAttribute('loaded', 'loaded') | ||
| }) | ||
| .catch((error) => { | ||
| console.error(error) | ||
| }) | ||
| } | ||
|
|
||
| findOEmbedEndpoint(body) { | ||
| const doc = new DOMParser().parseFromString(body, 'text/html') | ||
| const endpoint = doc | ||
| .querySelector('link[rel="alternate"][type="application/json+oembed"]') | ||
| ?.getAttribute('href') | ||
|
|
||
| if (!endpoint) return null | ||
|
|
||
| return new URL(endpoint, this.urlValue).toString() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.