Skip to content

Commit

Permalink
fix(client): added a check to prevent Safari from crashing when tryin…
Browse files Browse the repository at this point in the history
…g to read .ogg video files
  • Loading branch information
Will Moss committed Jul 18, 2024
1 parent b39b278 commit d253e5b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const App = () => {
};
const _isVideo = (file) =>
["mp4", "ogg", "webm"].includes(file.name.toLowerCase().split(".").at(-1));
const _isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);

const _toAuthenticatedUrl = (url) => `${url}?hash=${secureHash}`;
const _veryFirsPageTitle = document.title;
const _updatePageTitle = (video) => {
Expand Down Expand Up @@ -146,7 +148,7 @@ const App = () => {
_retrieveVideosRecursively().then((files) => {
if (!files) setLoading(false);

const _videoFiles = files
let _videoFiles = files
.filter((f) => _isVideo(f))
.map((v) => ({
url: _toAuthenticatedUrl(`${window.PUBLIC_URL}/media/${v.url}`),
Expand All @@ -156,9 +158,13 @@ const App = () => {
.split(".")
.slice(0, -1)
.join(""),
extension: v.url.split(".").at(-1).toLowerCase(),
}))
.sort((a, b) => 0.5 - Math.random());

// Fix for Safari : .ogg files are not supported
if (_isSafari) _videoFiles = _videoFiles.filter((f) => f.extension !== "ogg");

setVideos(_videoFiles);

// Load the first two videos
Expand Down
1 change: 1 addition & 0 deletions src/components/VideoCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const VideoCard = ({ index, url, title, isLoaded, isMuted, refForwarder }) => {
onClick={togglePause}
muted={isMuted}
loop
playsInline
/>
<div className="bottom-controls">
<div className="footer-left">
Expand Down

0 comments on commit d253e5b

Please sign in to comment.