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

Infinite loading on video preview before sending video #39755

Merged
merged 1 commit into from
May 6, 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
6 changes: 5 additions & 1 deletion src/components/VideoPlayer/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as Browser from '@libs/Browser';

/**
* Converts milliseconds to '[hours:]minutes:seconds' format
*/
Expand All @@ -14,7 +16,9 @@ function convertMillisecondsToTime(milliseconds: number) {
* Adds a #t=seconds tag to the end of the URL to skip first seconds of the video
*/
function addSkipTimeTagToURL(url: string, seconds: number) {
if (url.includes('#t=')) {
// On iOS: mWeb (WebKit-based browser engines), we don't add the time fragment
// because it's not supported and will throw (WebKitBlobResource error 1).
if (Browser.isMobileWebKit() || url.includes('#t=')) {
return url;
}
return `${url}#t=${seconds}`;
Expand Down
6 changes: 4 additions & 2 deletions src/libs/Browser/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {GetBrowser, IsMobile, IsMobileChrome, IsMobileSafari, IsSafari, OpenRouteInDesktopApp} from './types';
import type {GetBrowser, IsMobile, IsMobileChrome, IsMobileSafari, IsMobileWebKit, IsSafari, OpenRouteInDesktopApp} from './types';

const getBrowser: GetBrowser = () => '';

Expand All @@ -8,8 +8,10 @@ const isMobileSafari: IsMobileSafari = () => false;

const isMobileChrome: IsMobileChrome = () => false;

const isMobileWebKit: IsMobileWebKit = () => false;

const isSafari: IsSafari = () => false;

const openRouteInDesktopApp: OpenRouteInDesktopApp = () => {};

export {getBrowser, isMobile, isMobileSafari, isSafari, isMobileChrome, openRouteInDesktopApp};
export {getBrowser, isMobile, isMobileSafari, isMobileWebKit, isSafari, isMobileChrome, openRouteInDesktopApp};
12 changes: 10 additions & 2 deletions src/libs/Browser/index.website.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CONFIG from '@src/CONFIG';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {GetBrowser, IsMobile, IsMobileChrome, IsMobileSafari, IsSafari, OpenRouteInDesktopApp} from './types';
import type {GetBrowser, IsMobile, IsMobileChrome, IsMobileSafari, IsMobileWebKit, IsSafari, OpenRouteInDesktopApp} from './types';

/**
* Fetch browser name from UA string
Expand Down Expand Up @@ -58,6 +58,14 @@ const isMobileChrome: IsMobileChrome = () => {
return /Android/i.test(userAgent) && /chrome|chromium|crios/i.test(userAgent);
};

/**
* Checks if the requesting user agent is a WebKit-based browser on an iOS mobile device.
*/
const isMobileWebKit: IsMobileWebKit = () => {
const userAgent = navigator.userAgent;
return /iP(ad|od|hone)/i.test(userAgent) && /WebKit/i.test(userAgent);
};

const isSafari: IsSafari = () => getBrowser() === 'safari' || isMobileSafari();

/**
Expand Down Expand Up @@ -101,4 +109,4 @@ const openRouteInDesktopApp: OpenRouteInDesktopApp = (shortLivedAuthToken = '',
}
};

export {getBrowser, isMobile, isMobileSafari, isSafari, isMobileChrome, openRouteInDesktopApp};
export {getBrowser, isMobile, isMobileSafari, isMobileWebKit, isSafari, isMobileChrome, openRouteInDesktopApp};
Copy link
Contributor Author

@ikevin127 ikevin127 May 4, 2024

Choose a reason for hiding this comment

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

Context:

Reviewer asked whether we can use existing isMobileSafari.

Nope, we need to cover all iOS: mWeb WebKit-based browser engines, this includes iOS: Chrome, Firefox and ay other browsers which are forced by Apple to use the WebKit engine.

Therefore we need to cover for all of them, otherwise the infinite loading would appear on Chrome / Firefox / other browsers one can install on their iPhone.

4 changes: 3 additions & 1 deletion src/libs/Browser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ type IsMobileSafari = () => boolean;

type IsMobileChrome = () => boolean;

type IsMobileWebKit = () => boolean;

type IsSafari = () => boolean;

type OpenRouteInDesktopApp = (shortLivedAuthToken?: string, email?: string) => void;

export type {GetBrowser, IsMobile, IsMobileSafari, IsMobileChrome, IsSafari, OpenRouteInDesktopApp};
export type {GetBrowser, IsMobile, IsMobileSafari, IsMobileChrome, IsMobileWebKit, IsSafari, OpenRouteInDesktopApp};
Loading