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

[Proposal] Forbid usage of the HTMLMediaElement and MSE TS types #1397

Merged
merged 12 commits into from
Jul 31, 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
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ module.exports = {
Symbol: {
message: "Avoid using the `Symbol` type. Did you mean `symbol`?",
},
HTMLMediaElement: {
message:
"Avoid relying on `HTMLMediaElement` directly unless it is API-facing. Prefer our more restricted `IMediaElement` type",
},
MediaSource: {
message:
"Avoid relying on `MediaSource` directly unless it is API-facing. Prefer our more restricted `IMediaSource` type",
},
SourceBuffer: {
message:
"Avoid relying on `SourceBuffer` directly unless it is API-facing. Prefer our more restricted `ISourceBuffer` type",
},
SourceBufferList: {
message:
"Avoid relying on `SourceBufferList` directly unless it is API-facing. Prefer our more restricted `ISourceBufferList` type",
},
},
},
],
Expand Down
7 changes: 4 additions & 3 deletions src/compat/__tests__/add_text_track.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, beforeEach, it, expect, vi } from "vitest";
import type { IMediaElement } from "../../compat/browser_compatibility_types";

// Needed for calling require (which itself is needed to mock properly) because
// it is not type-checked:
Expand All @@ -23,7 +24,7 @@ describe("compat - addTextTrack", () => {
const fakeMediaElement = {
textTracks: [fakeTextTrack],
addTextTrack: mockAddTextTrack,
} as unknown as HTMLMediaElement;
} as unknown as IMediaElement;

vi.doMock("../browser_detection", () => ({
isIEOrEdge: true,
Expand Down Expand Up @@ -51,7 +52,7 @@ describe("compat - addTextTrack", () => {
const fakeMediaElement = {
textTracks: fakeTextTracks,
addTextTrack: mockAddTextTrack,
} as unknown as HTMLMediaElement;
} as unknown as IMediaElement;

vi.doMock("../browser_detection", () => ({
isIEOrEdge: true,
Expand Down Expand Up @@ -95,7 +96,7 @@ describe("compat - addTextTrack", () => {
textTracks: fakeTextTracks,
appendChild: mockAppendChild,
childNodes: fakeChildNodes,
} as unknown as HTMLMediaElement;
} as unknown as IMediaElement;

const spyOnCreateElement = vi
.spyOn(document, "createElement")
Expand Down
7 changes: 4 additions & 3 deletions src/compat/__tests__/change_source_buffer_type.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { describe, it, expect, vi } from "vitest";
import log from "../../log";
import type { ISourceBuffer } from "../browser_compatibility_types";
import tryToChangeSourceBufferType from "../change_source_buffer_type";

describe("Compat - tryToChangeSourceBufferType", () => {
it("should just return false if the SourceBuffer provided does not have a changeType method", () => {
const spy = vi.spyOn(log, "warn");
const fakeSourceBuffer: SourceBuffer = {} as unknown as SourceBuffer;
const fakeSourceBuffer: ISourceBuffer = {} as unknown as ISourceBuffer;
expect(tryToChangeSourceBufferType(fakeSourceBuffer, "toto")).toBe(false);
expect(spy).not.toHaveBeenCalled();
});
Expand All @@ -15,7 +16,7 @@ describe("Compat - tryToChangeSourceBufferType", () => {
const changeTypeFn = vi.fn();
const fakeSourceBuffer = {
changeType: changeTypeFn,
} as unknown as SourceBuffer;
} as unknown as ISourceBuffer;
expect(tryToChangeSourceBufferType(fakeSourceBuffer, "toto")).toBe(true);
expect(spy).not.toHaveBeenCalled();
});
Expand All @@ -28,7 +29,7 @@ describe("Compat - tryToChangeSourceBufferType", () => {
});
const fakeSourceBuffer = {
changeType: changeTypeFn,
} as unknown as SourceBuffer;
} as unknown as ISourceBuffer;
expect(tryToChangeSourceBufferType(fakeSourceBuffer, "toto")).toBe(false);
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(
Expand Down
4 changes: 2 additions & 2 deletions src/compat/add_text_track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import type { ICompatTextTrack } from "./browser_compatibility_types";
import type { ICompatTextTrack, IMediaElement } from "./browser_compatibility_types";
import { isIEOrEdge } from "./browser_detection";

/**
Expand All @@ -28,7 +28,7 @@ import { isIEOrEdge } from "./browser_detection";
* @param {HTMLMediaElement} mediaElement
* @returns {Object}
*/
export default function addTextTrack(mediaElement: HTMLMediaElement): {
export default function addTextTrack(mediaElement: IMediaElement): {
track: ICompatTextTrack;
trackElement: HTMLTrackElement | undefined;
} {
Expand Down
Loading
Loading