Skip to content

Commit b9afe79

Browse files
committed
fix youtube embeds
1 parent 6e44a2d commit b9afe79

4 files changed

Lines changed: 62 additions & 4 deletions

File tree

eslint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export default defineConfig(
3030
'.husky/**',
3131
'patches/**',
3232
'*.html',
33+
// Eurosky fork: static iframe player scripts (browser globals like YT /
34+
// onYouTubeIframeAPIReady, not app code). Mirrors the bskyweb/** ignore.
35+
'web/iframe/**',
3336
'bskyweb/**',
3437
'bskyembed/**',
3538
'bskyogcard/**',

src/lib/strings/embed-player.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import {IS_WEB} from '#/env'
55
const {height: SCREEN_HEIGHT} = Dimensions.get('window')
66

77
const IFRAME_HOST = IS_WEB
8-
? // @ts-ignore only for web
9-
window.location.host === 'localhost:8100'
10-
? 'http://localhost:8100'
11-
: 'https://bsky.app'
8+
? // @ts-ignore only for web -- Eurosky fork: serve the YouTube iframe player
9+
// from our own origin instead of bsky.app. bsky.app/iframe/* sends
10+
// X-Frame-Options: SAMEORIGIN, so it refuses to be framed cross-origin. The
11+
// player files live in web/iframe/* and are copied to the web build root.
12+
window.location.origin
1213
: __DEV__ && !process.env.JEST_WORKER_ID
1314
? 'http://localhost:8100'
1415
: 'https://bsky.app'

web/iframe/youtube.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html><meta name="viewport" content="width=device-width, initial-scale=1" />
2+
<style>
3+
body {
4+
margin: 0;
5+
}
6+
.container {
7+
position: relative;
8+
overflow: hidden;
9+
width: 100vw;
10+
height: 100vh;
11+
}
12+
.video {
13+
position: absolute;
14+
width: 100vw;
15+
height: 100vh;
16+
}
17+
</style>
18+
<div class="container"><div class="video" id="player"></div></div>
19+
<script src="youtube.js"></script>

web/iframe/youtube.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const url = new URL(window.location)
2+
const viewport = document.querySelector('meta[name=viewport]')
3+
4+
const tag = document.createElement('script')
5+
tag.src = 'https://www.youtube.com/iframe_api'
6+
const firstScriptTag = document.getElementsByTagName('script')[0]
7+
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag)
8+
9+
let player
10+
function onYouTubeIframeAPIReady() {
11+
let videoId = url.searchParams.get('videoId')
12+
videoId = decodeURIComponent(videoId)
13+
videoId = videoId.replace(/[^a-zA-Z0-9_-]/g, '')
14+
if (videoId.length !== 11) throw new Error('Invalid video ID')
15+
16+
let start = url.searchParams.get('start')
17+
start = start.replace(/[^0-9]/g, '')
18+
19+
player = new YT.Player('player', {
20+
width: '1000',
21+
height: '1000',
22+
videoId,
23+
playerVars: {
24+
autoplay: 1,
25+
start,
26+
rel: 0,
27+
loop: 0,
28+
playsinline: 1,
29+
origin: url.origin,
30+
},
31+
})
32+
}
33+
function onPlayerReady(event) {
34+
event.target.playVideo()
35+
}

0 commit comments

Comments
 (0)