Skip to content

Commit

Permalink
refactor(webview): webview plugin api to get textTracks
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenlx committed Mar 20, 2024
1 parent 9f65cc0 commit 2b5003c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@radix-ui/react-dropdown-menu": "^2.0.5",
"@radix-ui/react-slider": "^1.1.2",
"@radix-ui/react-tooltip": "^1.0.6",
"@vidstack/react": "npm:@aidenlx/vidstack-react@1.10.3-mod.4",
"@vidstack/react": "npm:@aidenlx/vidstack-react@1.10.9-mod.1",
"ahooks": "^3.7.8",
"arktype": "1.0.29-alpha",
"assert-never": "^1.2.1",
Expand Down
2 changes: 2 additions & 0 deletions apps/app/src/lib/remote-player/hook/handler-register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export function registerHandlers(this: MediaPlugin) {
value: serializeMediaStatePropValue(player[prop]),
}));
});
port.handle("getTracks", async () => ({ value: await this.getTracks() }));
port.handle("getTrack", async (id) => ({ value: await this.getTrack(id) }));
port.handle("pictureInPictureEnabled", () => {
return { value: document.pictureInPictureElement === player };
});
Expand Down
8 changes: 8 additions & 0 deletions apps/app/src/lib/remote-player/lib/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { TextTrackInit, VTTContent } from "@vidstack/react";
import { LifeCycle } from "@/lib/lifecycle";
import { TimeoutError } from "@/lib/message";
import { registerEvents } from "../hook/event-register";
Expand All @@ -21,6 +22,13 @@ export default class MediaPlugin extends LifeCycle {
this.register(() => controller.unload());
}

async getTracks(): Promise<(TextTrackInit & { id: string })[]> {
return [];
}
async getTrack(_id: string): Promise<VTTContent | null> {
return null;
}

getStyle(): string | null {
return css;
}
Expand Down
10 changes: 9 additions & 1 deletion apps/app/src/lib/remote-player/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { MediaErrorCode } from "@vidstack/react";
import type {
MediaErrorCode,
TextTrackInit,
VTTContent,
} from "@vidstack/react";
import type { BilibiliPlayerManifest } from "@/web/bili-api/base";
import type { MessageController, Nil } from "../message";
// import { enumerate } from "../must-include";
Expand Down Expand Up @@ -199,6 +203,8 @@ export type MsgCtrlRemote = MessageController<
bili_getManifest(): {
value: BilibiliPlayerManifest;
};
getTracks(): { value: (TextTrackInit & { id: string })[] };
getTrack(id: string): { value: VTTContent | null };
},
Nil,
{
Expand Down Expand Up @@ -237,6 +243,8 @@ export type MsgCtrlLocal = MessageController<
requestPictureInPicture(): void;
exitPictureInPicture(): void;
bili_getManifest(): Promise<BilibiliPlayerManifest>;
getTracks(): Promise<(TextTrackInit & { id: string })[]>;
getTrack(id: string): Promise<VTTContent | null>;
},
Record<CustomEvent, void> & MediaEventPayloadMap & CustomEventWithPayload,
{
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b5003c

Please sign in to comment.