mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-21 15:33:11 +01:00
bugfix / Update video preview functionality (#3433)
* Add video preview functionality and update dependencies * Refactor video preview component to use Buffer for base64 decoding and update muted prop syntax --------- Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
parent
412a0ed078
commit
77d3fa7e1e
@ -66,6 +66,7 @@
|
|||||||
"react-i18next": "^15.0.1",
|
"react-i18next": "^15.0.1",
|
||||||
"react-inspector": "^6.0.2",
|
"react-inspector": "^6.0.2",
|
||||||
"react-pdf": "9.1.1",
|
"react-pdf": "9.1.1",
|
||||||
|
"react-player": "^2.16.0",
|
||||||
"react-redux": "^7.2.6",
|
"react-redux": "^7.2.6",
|
||||||
"react-tooltip": "^5.5.2",
|
"react-tooltip": "^5.5.2",
|
||||||
"sass": "^1.46.0",
|
"sass": "^1.46.0",
|
||||||
|
@ -1,14 +1,41 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
import CodeEditor from 'components/CodeEditor/index';
|
import CodeEditor from 'components/CodeEditor/index';
|
||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
import { useDispatch, useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
import { sendRequest } from 'providers/ReduxStore/slices/collections/actions';
|
import { sendRequest } from 'providers/ReduxStore/slices/collections/actions';
|
||||||
import { Document, Page } from 'react-pdf';
|
import { Document, Page } from 'react-pdf';
|
||||||
import { useState } from 'react';
|
|
||||||
import 'pdfjs-dist/build/pdf.worker';
|
import 'pdfjs-dist/build/pdf.worker';
|
||||||
import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
|
import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
|
||||||
import 'react-pdf/dist/esm/Page/TextLayer.css';
|
import 'react-pdf/dist/esm/Page/TextLayer.css';
|
||||||
import { GlobalWorkerOptions } from 'pdfjs-dist/build/pdf';
|
import { GlobalWorkerOptions } from 'pdfjs-dist/build/pdf';
|
||||||
GlobalWorkerOptions.workerSrc = 'pdfjs-dist/legacy/build/pdf.worker.min.mjs';
|
GlobalWorkerOptions.workerSrc = 'pdfjs-dist/legacy/build/pdf.worker.min.mjs';
|
||||||
|
import ReactPlayer from 'react-player';
|
||||||
|
|
||||||
|
const VideoPreview = memo(({ contentType, dataBuffer }) => {
|
||||||
|
const [videoUrl, setVideoUrl] = useState(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const videoType = contentType.split(';')[0];
|
||||||
|
const byteArray = Buffer.from(dataBuffer, 'base64');
|
||||||
|
const blob = new Blob([byteArray], { type: videoType });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
setVideoUrl(url);
|
||||||
|
return () => URL.revokeObjectURL(url);
|
||||||
|
}, [contentType, dataBuffer]);
|
||||||
|
|
||||||
|
if (!videoUrl) return <div>Loading video...</div>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ReactPlayer
|
||||||
|
url={videoUrl}
|
||||||
|
controls
|
||||||
|
muted={true}
|
||||||
|
width="100%"
|
||||||
|
height="100%"
|
||||||
|
onError={(e) => console.error('Error loading video:', e)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
const QueryResultPreview = ({
|
const QueryResultPreview = ({
|
||||||
previewTab,
|
previewTab,
|
||||||
@ -73,9 +100,7 @@ const QueryResultPreview = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
case 'preview-video': {
|
case 'preview-video': {
|
||||||
return (
|
return <VideoPreview contentType={contentType} dataBuffer={dataBuffer} />;
|
||||||
<video controls src={`data:${contentType.replace(/\;(.*)/, '')};base64,${dataBuffer}`} className="mx-auto" />
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
case 'raw': {
|
case 'raw': {
|
||||||
|
Loading…
Reference in New Issue
Block a user