Skip to content
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
49 changes: 6 additions & 43 deletions src/compat/__tests__/should_wait_for_data_before_loaded.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("compat - shouldWaitForDataBeforeLoaded", () => {
const shouldWaitForDataBeforeLoaded = jest.requireActual(
"../should_wait_for_data_before_loaded",
);
expect(shouldWaitForDataBeforeLoaded.default(false, true)).toBe(true);
expect(shouldWaitForDataBeforeLoaded.default(false)).toBe(true);
});

it("should return true if we are not on Safari browser but in directfile mode", () => {
Expand All @@ -49,7 +49,7 @@ describe("compat - shouldWaitForDataBeforeLoaded", () => {
const shouldWaitForDataBeforeLoaded = jest.requireActual(
"../should_wait_for_data_before_loaded",
);
expect(shouldWaitForDataBeforeLoaded.default(true, false)).toBe(true);
expect(shouldWaitForDataBeforeLoaded.default(true)).toBe(true);
});

it("should return true if we are on the Safari browser but not in directfile mode", () => {
Expand All @@ -62,10 +62,11 @@ describe("compat - shouldWaitForDataBeforeLoaded", () => {
const shouldWaitForDataBeforeLoaded = jest.requireActual(
"../should_wait_for_data_before_loaded",
);
expect(shouldWaitForDataBeforeLoaded.default(false, false)).toBe(true);
expect(shouldWaitForDataBeforeLoaded.default(false)).toBe(true);
});

it("should return false if we are on the Safari browser with no play inline and in directfile mode", () => {
// eslint-disable-next-line max-len
it("should return false if we are on the Safari browser and in directfile mode", () => {
jest.mock("../browser_detection", () => {
return {
__esModule: true as const,
Expand All @@ -75,47 +76,9 @@ describe("compat - shouldWaitForDataBeforeLoaded", () => {
const shouldWaitForDataBeforeLoaded = jest.requireActual(
"../should_wait_for_data_before_loaded",
);
expect(shouldWaitForDataBeforeLoaded.default(true, false)).toBe(false);
expect(shouldWaitForDataBeforeLoaded.default(true)).toBe(false);
});

it("should return true if we are on the Safari browser, we should play inline and in directfile mode", () => {
jest.mock("../browser_detection", () => {
return {
__esModule: true as const,
isSafariMobile: true,
};
});
const shouldWaitForDataBeforeLoaded = jest.requireActual(
"../should_wait_for_data_before_loaded",
);
expect(shouldWaitForDataBeforeLoaded.default(true, true)).toBe(true);
});

it("should return true if we are on the Safari browser, play inline but no directfile mode", () => {
jest.mock("../browser_detection", () => {
return {
__esModule: true as const,
isSafariMobile: true,
};
});
const shouldWaitForDataBeforeLoaded = jest.requireActual(
"../should_wait_for_data_before_loaded",
);
expect(shouldWaitForDataBeforeLoaded.default(false, true)).toBe(true);
});

it("should return true if we are not on the Safari browser, should not play inline and in directfile mode", () => {
jest.mock("../browser_detection", () => {
return {
__esModule: true as const,
isSafariMobile: false,
};
});
const shouldWaitForDataBeforeLoaded = jest.requireActual(
"../should_wait_for_data_before_loaded",
);
expect(shouldWaitForDataBeforeLoaded.default(true, false)).toBe(true);
});
beforeEach(() => {
jest.resetModules();
});
Expand Down
10 changes: 4 additions & 6 deletions src/compat/should_wait_for_data_before_loaded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ import { isSafariMobile } from "./browser_detection";
* @param {Boolean} isDirectfile
* @returns {Boolean}
*/
export default function shouldWaitForDataBeforeLoaded(
isDirectfile: boolean,
mustPlayInline: boolean,
): boolean {
export default function shouldWaitForDataBeforeLoaded(isDirectfile: boolean): boolean {
if (isDirectfile && isSafariMobile) {
return mustPlayInline;
return false;
} else {
return true;
}
return true;
}
7 changes: 1 addition & 6 deletions src/main_thread/init/utils/get_loaded_reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ export default function getLoadedReference(
return;
}

if (
!shouldWaitForDataBeforeLoaded(
isDirectfile,
mediaElement.hasAttribute("playsinline"),
)
) {
if (!shouldWaitForDataBeforeLoaded(isDirectfile)) {
// The duration is NaN if no media data is available,
// which means media is not loaded yet.
if (isNaN(mediaElement.duration)) {
Expand Down