Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect video downloaded #40647 #41054

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/VideoPlayer/BaseVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Hoverable from '@components/Hoverable';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import {useFullScreenContext} from '@components/VideoPlayerContexts/FullScreenContext';
import {usePlaybackContext} from '@components/VideoPlayerContexts/PlaybackContext';
import {useVideoPopoverMenuContext} from '@components/VideoPlayerContexts/VideoPopoverMenuContext';
import {useVolumeContext} from '@components/VideoPlayerContexts/VolumeContext';
import VideoPopoverMenu from '@components/VideoPopoverMenu';
import useNetwork from '@hooks/useNetwork';
Expand Down Expand Up @@ -79,6 +80,7 @@ function BaseVideoPlayer({
const isUploading = CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => url.startsWith(prefix));
const videoStateRef = useRef<AVPlaybackStatus | null>(null);
const {updateVolume} = useVolumeContext();
const {videoPopoverMenuPlayerRef} = useVideoPopoverMenuContext();

const togglePlayCurrentVideo = useCallback(() => {
videoResumeTryNumber.current = 0;
Expand All @@ -93,6 +95,7 @@ function BaseVideoPlayer({

const showPopoverMenu = (event?: GestureResponderEvent | KeyboardEvent) => {
setIsPopoverVisible(true);
videoPopoverMenuPlayerRef.current = videoPlayerRef.current;
if (!event || !('nativeEvent' in event)) {
return;
}
Expand Down
16 changes: 11 additions & 5 deletions src/components/VideoPlayerContexts/VideoPopoverMenuContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useCallback, useContext, useMemo, useState} from 'react';
import React, {useCallback, useContext, useMemo, useRef, useState} from 'react';
import * as Expensicons from '@components/Icon/Expensicons';
import type {PopoverMenuItem} from '@components/PopoverMenu';
import type {VideoWithOnFullScreenUpdate} from '@components/VideoPlayer/types';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
Expand All @@ -18,6 +19,7 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
const [currentPlaybackSpeed, setCurrentPlaybackSpeed] = useState<PlaybackSpeed>(CONST.VIDEO_PLAYER.PLAYBACK_SPEEDS[2]);
const {isOffline} = useNetwork();
const isLocalFile = currentlyPlayingURL && CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => currentlyPlayingURL.startsWith(prefix));
const videoPopoverMenuPlayerRef = useRef<VideoWithOnFullScreenUpdate | null>(null);

const updatePlaybackSpeed = useCallback(
(speed: PlaybackSpeed) => {
Expand All @@ -28,12 +30,16 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
);

const downloadAttachment = useCallback(() => {
if (currentlyPlayingURL === null) {
if (videoPopoverMenuPlayerRef.current === null) {
return;
}
const sourceURI = addEncryptedAuthTokenToURL(currentlyPlayingURL);
const {source} = videoPopoverMenuPlayerRef.current?.props ?? {};
if (typeof source === 'number' || !source) {
return;
}
const sourceURI = addEncryptedAuthTokenToURL(source.uri);
fileDownload(sourceURI);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source.uri already has encryptedAuthToken appended. We are adding it again here,And because of this double encryptedAuthToken in the URL causes this issue: #43117 in Safari on mWeb.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jayeshmangwani Does this mean we have to fix this issue again? Or did your follow up solution make sure to not cause a regression?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have fixed the issue in a PR, comment was just to notify that we could have avoided this issue

}, [currentlyPlayingURL]);
}, [videoPopoverMenuPlayerRef]);

const menuItems = useMemo(() => {
const items: PopoverMenuItem[] = [];
Expand Down Expand Up @@ -63,7 +69,7 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
return items;
}, [currentPlaybackSpeed, downloadAttachment, translate, updatePlaybackSpeed, isOffline, isLocalFile]);

const contextValue = useMemo(() => ({menuItems, updatePlaybackSpeed}), [menuItems, updatePlaybackSpeed]);
const contextValue = useMemo(() => ({menuItems, videoPopoverMenuPlayerRef, updatePlaybackSpeed}), [menuItems, videoPopoverMenuPlayerRef, updatePlaybackSpeed]);
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
}

Expand Down
1 change: 1 addition & 0 deletions src/components/VideoPlayerContexts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type VolumeContext = {

type VideoPopoverMenuContext = {
menuItems: PopoverMenuItem[];
videoPopoverMenuPlayerRef: MutableRefObject<VideoWithOnFullScreenUpdate | null>;
updatePlaybackSpeed: (speed: PlaybackSpeed) => void;
};

Expand Down
Loading