Skip to content

Commit

Permalink
Merge pull request #32 from hahow/feature/screenshot-add-config-filename
Browse files Browse the repository at this point in the history
feat(@hahow/jwplayer-plugin-screenshot): 新增 config.name 自訂截圖檔名
  • Loading branch information
amowu authored Sep 16, 2022
2 parents 75f3844 + 1a82e85 commit acbcba4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-carpets-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hahow/jwplayer-plugin-screenshot": patch
---

新增 `config.name` 自訂截圖檔名
16 changes: 10 additions & 6 deletions apps/docs/stories/Screenshot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ IIFE 格式,JW Player 預設使用 plugin 的方式:
"playlist": "{your_playlist_url}",
"plugins": {
"//unpkg.com/@hahow/jwplayer-plugin-screenshot@latest/dist/iife/screenshot.js": {
enabled: true
enabled: true,
name: "screenshot"
}
}
});
Expand All @@ -60,7 +61,8 @@ const App = () => (
config={{
plugins: {
"//unpkg.com/@hahow/jwplayer-plugin-screenshot@latest/dist/iife/screenshot.js": {
enabled: true
enabled: true,
name: "screenshot"
}
},
}}
Expand Down Expand Up @@ -91,7 +93,8 @@ const App = () => (
config={{
plugins: {
"/screenshot.js": {
enabled: true
enabled: true,
name: "screenshot"
}
},
}}
Expand All @@ -105,6 +108,7 @@ const App = () => (

## Configuration

| config | type | default | description |
| --------- | --------- | ------- | ---------------- |
| `enabled` | `boolean` | `true` | 是否開啟截圖功能 |
| config | type | default | description |
| --------- | --------- | ------------ | ---------------- |
| `enabled` | `boolean` | `true` | 是否開啟截圖功能 |
| `name` | `string` | `screenshot` | 截圖檔名 |
1 change: 1 addition & 0 deletions apps/docs/stories/Screenshot.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const Screenshot = createPluginStory({
"//unpkg.com/@hahow/jwplayer-plugin-screenshot@latest/dist/iife/screenshot.js",
pluginConfig: {
enabled: true,
name: "screenshot",
},
storyArgs: {
config: {
Expand Down
10 changes: 7 additions & 3 deletions packages/jwplayer-plugin-screenshot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import { download, getBlobUrl } from "./utils";
interface ScreenshotPluginConfig {
/** 是否開啟截圖功能,預設 true */
enabled?: boolean;
/** 截圖檔名,預設 "screenshot" */
name?: string;
}

export function initPlugin(
playerInstance: jwplayer.JWPlayer,
pluginConfig: ScreenshotPluginConfig = { enabled: true }
pluginConfig: ScreenshotPluginConfig
) {
if (pluginConfig.enabled === false) return;
const { enabled = true, name = "screenshot" } = pluginConfig;

if (enabled === false) return;

playerInstance.on("ready", () => {
const video = document.querySelector<HTMLVideoElement>(".jw-video");
Expand All @@ -21,7 +25,7 @@ export function initPlugin(
const handleClick = async () => {
if (video) {
const dataUri = await getBlobUrl(video);
download(dataUri, "screenshot");
download(dataUri, name);
}
};

Expand Down

0 comments on commit acbcba4

Please sign in to comment.