Skip to content

Commit 5dcb520

Browse files
authored
add video to embed (#5145)
1 parent fcf27f0 commit 5dcb520

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed
Lines changed: 1 addition & 0 deletions
Loading

bskyembed/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "eslint --cache --ext .js,.jsx,.ts,.tsx src"
1010
},
1111
"dependencies": {
12-
"@atproto/api": "0.13.1",
12+
"@atproto/api": "0.13.6",
1313
"@preact/preset-vite": "^2.8.2",
1414
"@vitejs/plugin-legacy": "^5.3.2",
1515
"preact": "^10.4.8",

bskyembed/src/components/embed.tsx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
AppBskyEmbedImages,
44
AppBskyEmbedRecord,
55
AppBskyEmbedRecordWithMedia,
6+
AppBskyEmbedVideo,
67
AppBskyFeedDefs,
78
AppBskyFeedPost,
89
AppBskyGraphDefs,
@@ -14,6 +15,7 @@ import {ComponentChildren, h} from 'preact'
1415
import {useMemo} from 'preact/hooks'
1516

1617
import infoIcon from '../../assets/circleInfo_stroke2_corner0_rounded.svg'
18+
import playIcon from '../../assets/play_filled_corner2_rounded.svg'
1719
import starterPackIcon from '../../assets/starterPack.svg'
1820
import {CONTENT_LABELS, labelsToInfo} from '../labels'
1921
import {getRkey} from '../utils'
@@ -160,7 +162,12 @@ export function Embed({
160162
return null
161163
}
162164

163-
// Case 4: Record with media
165+
// Case 4: Video
166+
if (AppBskyEmbedVideo.isView(content)) {
167+
return <VideoEmbed content={content} />
168+
}
169+
170+
// Case 5: Record with media
164171
if (
165172
AppBskyEmbedRecordWithMedia.isView(content) &&
166173
AppBskyEmbedRecord.isViewRecord(content.record.record)
@@ -354,6 +361,31 @@ function GenericWithImageEmbed({
354361
)
355362
}
356363

364+
// just the thumbnail and a play button
365+
function VideoEmbed({content}: {content: AppBskyEmbedVideo.View}) {
366+
let aspectRatio = 1
367+
368+
if (content.aspectRatio) {
369+
const {width, height} = content.aspectRatio
370+
aspectRatio = clamp(width / height, 1 / 1, 3 / 1)
371+
}
372+
373+
return (
374+
<div
375+
className="w-full overflow-hidden rounded-lg aspect-square"
376+
style={{aspectRatio: `${aspectRatio} / 1`}}>
377+
<img
378+
src={content.thumbnail}
379+
alt={content.alt}
380+
className="object-cover size-full"
381+
/>
382+
<div className="size-24 absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full bg-black/50 flex items-center justify-center">
383+
<img src={playIcon} className="object-cover size-3/5" />
384+
</div>
385+
</div>
386+
)
387+
}
388+
357389
function StarterPackEmbed({
358390
content,
359391
}: {
@@ -410,3 +442,7 @@ function getStarterPackHref(
410442
const handleOrDid = starterPack.creator.handle || starterPack.creator.did
411443
return `/starter-pack/${handleOrDid}/${rkey}`
412444
}
445+
446+
function clamp(num: number, min: number, max: number) {
447+
return Math.max(min, Math.min(num, max))
448+
}

bskyembed/yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
"@jridgewell/gen-mapping" "^0.3.5"
2121
"@jridgewell/trace-mapping" "^0.3.24"
2222

23-
"@atproto/[email protected].1":
24-
version "0.13.1"
25-
resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.13.1.tgz#fbf4306e4465d5467aaf031308c1b47dcc8039d0"
26-
integrity sha512-DL3iBfavn8Nnl48FmnAreQB0k0cIkW531DJ5JAHUCQZo10Nq0ZLk2/WFxcs0KuBG5wuLnGUdo+Y6/GQPVq8dYw==
23+
"@atproto/[email protected].6":
24+
version "0.13.6"
25+
resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.13.6.tgz#2500e9d7143e6718089632300c42ce50149f8cd5"
26+
integrity sha512-58emFFZhqY8nVWD3xFWK0yYqAmJ2un+NaTtZxBbRo00mGq1rz9VXTpVmfoHFcuXL1hoDQN3WyJfsub8r6xGOgg==
2727
dependencies:
2828
"@atproto/common-web" "^0.3.0"
2929
"@atproto/lexicon" "^0.4.1"
3030
"@atproto/syntax" "^0.3.0"
31-
"@atproto/xrpc" "^0.6.0"
31+
"@atproto/xrpc" "^0.6.1"
3232
await-lock "^2.2.2"
3333
multiformats "^9.9.0"
3434
tlds "^1.234.0"
@@ -59,10 +59,10 @@
5959
resolved "https://registry.yarnpkg.com/@atproto/syntax/-/syntax-0.3.0.tgz#fafa2dbea9add37253005cb663e7373e05e618b3"
6060
integrity sha512-Weq0ZBxffGHDXHl9U7BQc2BFJi/e23AL+k+i5+D9hUq/bzT4yjGsrCejkjq0xt82xXDjmhhvQSZ0LqxyZ5woxA==
6161

62-
"@atproto/xrpc@^0.6.0":
63-
version "0.6.0"
64-
resolved "https://registry.yarnpkg.com/@atproto/xrpc/-/xrpc-0.6.0.tgz#668c3262e67e2afa65951ea79a03bfe3720ddf5c"
65-
integrity sha512-5BbhBTv5j6MC3iIQ4+vYxQE7nLy2dDGQ+LYJrH8PptOCUdq0Pwg6aRccQ3y52kUZlhE/mzOTZ8Ngiy9pSAyfVQ==
62+
"@atproto/xrpc@^0.6.1":
63+
version "0.6.1"
64+
resolved "https://registry.yarnpkg.com/@atproto/xrpc/-/xrpc-0.6.1.tgz#dcd1315c8c60eef5af2db7fa4e35a38ebc6d79d5"
65+
integrity sha512-Zy5ydXEdk6sY7FDUZcEVfCL1jvbL4tXu5CcdPqbEaW6LQtk9GLds/DK1bCX9kswTGaBC88EMuqQMfkxOhp2t4A==
6666
dependencies:
6767
"@atproto/lexicon" "^0.4.1"
6868
zod "^3.23.8"

0 commit comments

Comments
 (0)