Skip to content

Commit

Permalink
feat: 添加变量控制是否使用 title 覆盖 document.title
Browse files Browse the repository at this point in the history
  • Loading branch information
kssaerbeisi123 committed Dec 29, 2021
1 parent 838c322 commit ed597dd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
53 changes: 27 additions & 26 deletions packages/griffith/README-zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,33 @@ render(<Player {...props} />)

### `props`

| 字段 | 类型 | 默认值 | 说明 |
| ------------------------- | ------------------------------------------------- | --------- | ------------------------------------------ |
| `id` | `string` | | 播放器实例唯一标识 |
| `title` | `string` | | 视频标题 |
| `cover` | `string` | | 视频封面图片 URL |
| `duration` | `number` | | 初始视频时长。在视频元数据载入后使用实际值 |
| `sources` | `sources` | | 视频播放数据。具体见下, |
| `defaultQuality` | `ld \| sd \| hd \| fhd` | | 视频默认播放清晰度 |
| `useAutoQuality` | `boolean` | `false` | 是否启用自动清晰度功能 |
| `standalone` | `boolean` | `false` | 是否启用 standalone 模式 |
| `onBeforePlay` | `function` | `void` | 视频播放之前回调函数 |
| `onEvent` | `(type: string) => void` | `void` | 公共事件的回调函数 |
| `shouldObserveResize` | `boolean` | `false` | 是否监听窗口 resize |
| `initialObjectFit` | `fill \| \contain \| cover \| none \| scale-down` | `contain` | object-fit 参数 |
| `useMSE` | `boolean` | `false` | 是否启用 MSE |
| `locale` | `en \| ja \| zh-Hans \| zh-Hant` | `en` | 界面语言 |
| `autoplay` | `boolean` | `false` | 自动播放 |
| `muted` | `boolean` | `false` | 静音 |
| `disablePictureInPicture` | `boolean` | `false` | 禁用画中画功能 |
| `hiddenPlayButton` | `boolean` | `false` | 隐藏播放按钮 |
| `hiddenTimeline` | `boolean` | `false` | 隐藏进度条 |
| `hiddenTime` | `boolean` | `false` | 隐藏播放时间 |
| `hiddenQualityMenu` | `boolean` | `false` | 隐藏质量选择菜单(如果展示的话) |
| `hiddenVolume` | `boolean` | `false` | 隐藏音量调节 |
| `hiddenFullScreenButton` | `boolean` | `false` | 隐藏全屏按钮 |
| `progressDots` | `ProgressDotItem[]` | `[]` | 进度条节点信息 |
| 字段 | 类型 | 默认值 | 说明 |
| ------------------------- | ------------------------------------------------- | --------- | --------------------------------------------------- |
| `id` | `string` | | 播放器实例唯一标识 |
| `title` | `string` | | 视频标题 |
| `cover` | `string` | | 视频封面图片 URL |
| `duration` | `number` | | 初始视频时长。在视频元数据载入后使用实际值 |
| `sources` | `sources` | | 视频播放数据。具体见下, |
| `defaultQuality` | `ld \| sd \| hd \| fhd` | | 视频默认播放清晰度 |
| `useAutoQuality` | `boolean` | `false` | 是否启用自动清晰度功能 |
| `standalone` | `boolean` | `false` | 是否启用 standalone 模式 |
| `onBeforePlay` | `function` | `void` | 视频播放之前回调函数 |
| `onEvent` | `(type: string) => void` | `void` | 公共事件的回调函数 |
| `shouldObserveResize` | `boolean` | `false` | 是否监听窗口 resize |
| `initialObjectFit` | `fill \| \contain \| cover \| none \| scale-down` | `contain` | object-fit 参数 |
| `useMSE` | `boolean` | `false` | 是否启用 MSE |
| `locale` | `en \| ja \| zh-Hans \| zh-Hant` | `en` | 界面语言 |
| `autoplay` | `boolean` | `false` | 自动播放 |
| `muted` | `boolean` | `false` | 静音 |
| `disablePictureInPicture` | `boolean` | `false` | 禁用画中画功能 |
| `hiddenPlayButton` | `boolean` | `false` | 隐藏播放按钮 |
| `hiddenTimeline` | `boolean` | `false` | 隐藏进度条 |
| `hiddenTime` | `boolean` | `false` | 隐藏播放时间 |
| `hiddenQualityMenu` | `boolean` | `false` | 隐藏质量选择菜单(如果展示的话) |
| `hiddenVolume` | `boolean` | `false` | 隐藏音量调节 |
| `hiddenFullScreenButton` | `boolean` | `false` | 隐藏全屏按钮 |
| `progressDots` | `ProgressDotItem[]` | `[]` | 进度条节点信息 |
| `noWriteDocTitle` | `boolean` | `false` | standalone 模式,是否使用 title 覆盖 document.title |

`sources` 字段:

Expand Down
12 changes: 9 additions & 3 deletions packages/griffith/src/components/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type InnerPlayerProps = ProviderOnlyProps & {
shouldShowPageFullScreenButton?: boolean
hideMobileControls?: boolean
hideCover?: boolean
noWriteDocTitle?: boolean
}

// 仅供 Provider 使用的属性
Expand Down Expand Up @@ -131,6 +132,7 @@ class InnerPlayer extends Component<InnerPlayerProps, State> {
progressDots: [],
hideMobileControls: false,
hideCover: false,
noWriteDocTitle: false,
}

state = {
Expand Down Expand Up @@ -251,9 +253,13 @@ class InnerPlayer extends Component<InnerPlayerProps, State> {
}

setDocumentTitle = () => {
const {title, standalone} = this.props

if (standalone && typeof title === 'string' && title !== document.title) {
const {title, standalone, noWriteDocTitle} = this.props
if (
standalone &&
typeof title === 'string' &&
title !== document.title &&
!noWriteDocTitle
) {
document.title = title
}
}
Expand Down

0 comments on commit ed597dd

Please sign in to comment.