-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add thumbnail support to the caspar plugin
Signed-off-by: Axel Boberg <[email protected]>
- Loading branch information
1 parent
dd07f2b
commit 175b0aa
Showing
9 changed files
with
159 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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 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 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,14 @@ | ||
import React from 'react' | ||
import './style.css' | ||
|
||
export const ThumbnailImage = ({ src, alt = 'Thumbnail image' }) => { | ||
return ( | ||
<div className='ThumbnailImage'> | ||
{ | ||
src | ||
? <img className='ThumbnailImage-img' alt={alt} src={src} /> | ||
: <div className='Thumbnail-text'>Thumbnail not available</div> | ||
} | ||
</div> | ||
) | ||
} |
This file contains 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,17 @@ | ||
.ThumbnailImage { | ||
display: flex; | ||
position: relative; | ||
|
||
width: 100%; | ||
height: 100%; | ||
|
||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.ThumbnailImage-img { | ||
width: 100%; | ||
height: 100%; | ||
|
||
object-fit: contain; | ||
} |
This file contains 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,55 @@ | ||
import React from 'react' | ||
import bridge from 'bridge' | ||
|
||
import { SharedContext } from '../sharedContext' | ||
import { ThumbnailImage } from '../components/ThumbnailImage' | ||
|
||
export const Thumbnail = () => { | ||
const [state] = React.useContext(SharedContext) | ||
const [item, setItem] = React.useState({}) | ||
const [image, setImage] = React.useState() | ||
const [selection, setSelection] = React.useState([]) | ||
|
||
React.useEffect(() => { | ||
const selection = state?._connections?.[bridge.client.getIdentity()]?.selection | ||
setSelection(selection) | ||
}, [state]) | ||
|
||
React.useEffect(() => { | ||
async function getItem () { | ||
if (!selection || selection.length < 1) { | ||
setImage(undefined) | ||
setItem(undefined) | ||
return | ||
} | ||
const item = await bridge.items.getItem(selection[0]) | ||
|
||
if (item?.type !== 'bridge.caspar.media') { | ||
setImage(undefined) | ||
setItem(undefined) | ||
return | ||
} | ||
|
||
if (!item?.data?.caspar?.server || !item?.data?.caspar?.target) { | ||
setImage(undefined) | ||
setItem(undefined) | ||
return | ||
} | ||
|
||
try { | ||
const res = await bridge.commands.executeCommand('caspar.sendCommand', item?.data?.caspar?.server, 'thumbnailRetrieve', item?.data?.caspar?.target) | ||
const src = (res?.data || []).join('') | ||
setImage(`data:image/png;base64,${src}`) | ||
setItem(item) | ||
} catch (_) { | ||
setImage(undefined) | ||
setItem(undefined) | ||
} | ||
} | ||
getItem() | ||
}, [selection]) | ||
|
||
return ( | ||
<ThumbnailImage src={image} alt={item?.name} /> | ||
) | ||
} |
This file contains 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 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 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 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