react-video-player-hook
Version:
React Hook for capacitor-video-player plugin
30 lines (26 loc) • 758 B
text/typescript
import { Capacitor } from '@capacitor/core';
import { FeatureNotAvailableError } from './models';
const allTrue = {
web: true,
ios: true,
android: true,
electron: true
}
const featureMap = {
CapacitorVideoPlayer: {
useVideoPlayer: allTrue
}
}
export function isFeatureAvailable<
T extends typeof featureMap,
PluginKeys extends keyof NonNullable<T>,
FeatureKeys extends keyof NonNullable<NonNullable<T>[PluginKeys]>>
(plugin: PluginKeys, method: FeatureKeys): boolean {
if(Capacitor.isPluginAvailable(plugin as string) && !!(featureMap as any)[plugin][method][Capacitor.getPlatform()]) {
return true;
}
return false;
}
export function featureNotAvailableError(): any {
throw new FeatureNotAvailableError()
}