diff options
| author | かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com> | 2024-11-09 10:57:04 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-09 10:57:04 +0900 |
| commit | 3a421837bfc8ea816c3109394a916cb0cac0e8d8 (patch) | |
| tree | bc652cc03f6d2198b0ceca208af8a801483066f7 /packages/frontend/src/scripts/fullscreen.ts | |
| parent | enhance(backend) : リモートユーザーの照会をオリジナルにリ... (diff) | |
| download | sharkey-3a421837bfc8ea816c3109394a916cb0cac0e8d8.tar.gz sharkey-3a421837bfc8ea816c3109394a916cb0cac0e8d8.tar.bz2 sharkey-3a421837bfc8ea816c3109394a916cb0cac0e8d8.zip | |
refactor(frontend): 動画UIのフルスクリーン周りの調整 (#14877)
* refactor(frontend): フルスクリーン周りの調整
(cherry picked from commit 783032caec5853d78d5af3391e29cf364f2282e8)
* refactor(frontend): deviceKindの循環参照を除去
(cherry picked from commit 1ca471f57e968a1a6e2259bde4a7c6da1fe0c54e)
* fix
---------
Co-authored-by: taiyme <53635909+taiyme@users.noreply.github.com>
Diffstat (limited to 'packages/frontend/src/scripts/fullscreen.ts')
| -rw-r--r-- | packages/frontend/src/scripts/fullscreen.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/packages/frontend/src/scripts/fullscreen.ts b/packages/frontend/src/scripts/fullscreen.ts new file mode 100644 index 0000000000..7a0a018ef3 --- /dev/null +++ b/packages/frontend/src/scripts/fullscreen.ts @@ -0,0 +1,46 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +type PartiallyPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; + +type VideoEl = PartiallyPartial<HTMLVideoElement, 'requestFullscreen'> & { + webkitEnterFullscreen?(): void; + webkitExitFullscreen?(): void; +}; + +type PlayerEl = PartiallyPartial<HTMLElement, 'requestFullscreen'>; + +type RequestFullscreenProps = { + readonly videoEl: VideoEl; + readonly playerEl: PlayerEl; + readonly options?: FullscreenOptions | null; +}; + +type ExitFullscreenProps = { + readonly videoEl: VideoEl; +}; + +export const requestFullscreen = ({ videoEl, playerEl, options }: RequestFullscreenProps) => { + if (playerEl.requestFullscreen != null) { + playerEl.requestFullscreen(options ?? undefined); + return; + } + if (videoEl.webkitEnterFullscreen != null) { + videoEl.webkitEnterFullscreen(); + return; + } +}; + +export const exitFullscreen = ({ videoEl }: ExitFullscreenProps) => { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + if (document.exitFullscreen != null) { + document.exitFullscreen(); + return; + } + if (videoEl.webkitExitFullscreen != null) { + videoEl.webkitExitFullscreen(); + return; + } +}; |