1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2025-01-20 02:21:25 +01:00
smov/src/utils/detectFeatures.ts

53 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-01-10 19:53:55 +01:00
import fscreen from "fscreen";
export const isSafari = /^((?!chrome|android).)*safari/i.test(
navigator.userAgent
);
let cachedVolumeResult: boolean | null = null;
export async function canChangeVolume(): Promise<boolean> {
if (cachedVolumeResult === null) {
const timeoutPromise = new Promise<false>((resolve) => {
setTimeout(() => resolve(false), 1e3);
});
const promise = new Promise<true>((resolve) => {
const video = document.createElement("video");
const handler = () => {
video.removeEventListener("volumechange", handler);
resolve(true);
};
video.addEventListener("volumechange", handler);
video.volume = 0.5;
});
cachedVolumeResult = await Promise.race([promise, timeoutPromise]);
}
return cachedVolumeResult;
}
export function canFullscreenAnyElement(): boolean {
return fscreen.fullscreenEnabled;
}
export function canWebkitFullscreen(): boolean {
return canFullscreenAnyElement() || isSafari;
}
export function canFullscreen(): boolean {
return canFullscreenAnyElement() || canWebkitFullscreen();
}
2023-02-27 07:58:36 +01:00
export function canPictureInPicture(): boolean {
return "pictureInPictureEnabled" in document;
}
2023-02-27 10:43:14 +01:00
export function canWebkitPictureInPicture(): boolean {
return "webkitSupportsPresentationMode" in document.createElement("video");
}
2023-11-29 17:27:17 +01:00
export function canPlayHlsNatively(video: HTMLVideoElement): boolean {
return !!video.canPlayType("application/vnd.apple.mpegurl");
}