feat: add typescript (#3266)

* chore: update dependencies
* chore: add typescript config
* feat: add types
* chore: add build command
* chore: fix types
* fix: update linters
* chore: add display name to component
* chore: fix types
* chore: remove re-declare name variables
* docs: update changelog
This commit is contained in:
Krzysztof Moch
2023-10-06 18:39:14 +02:00
committed by GitHub
parent f4acaccd80
commit 92831afd5f
20 changed files with 1259 additions and 619 deletions

30
src/types/events.ts Normal file
View File

@@ -0,0 +1,30 @@
import type { OnBandwidthUpdateData, OnBufferData, OnLoadData, OnLoadStartData, OnProgressData, OnSeekData, OnPlaybackData, OnExternalPlaybackChangeData, OnPictureInPictureStatusChangedData, OnReceiveAdEventData, OnVideoErrorData, OnPlaybackStateChangedData, OnAudioFocusChangedData, OnTimedMetadataData, OnAudioTracksData, OnTextTracksData, OnVideoTracksData } from "../VideoNativeComponent";
export interface ReactVideoEvents {
onAudioBecomingNoisy?: () => void //Android, iOS
onAudioFocusChanged?: (e: OnAudioFocusChangedData) => void // Android
onIdle?: () => void // Android
onBandwidthUpdate?: (e: OnBandwidthUpdateData) => void //Android
onBuffer?: (e: OnBufferData) => void //Android, iOS
onEnd?: () => void //All
onError?: (e: OnVideoErrorData) => void //Android, iOS
onExternalPlaybackChange?: (e: OnExternalPlaybackChangeData) => void //iOS
onFullscreenPlayerWillPresent?: () => void //Android, iOS
onFullscreenPlayerDidPresent?: () => void //Android, iOS
onFullscreenPlayerWillDismiss?: () => void //Android, iOS
onFullscreenPlayerDidDismiss?: () => void //Android, iOS
onLoad?: (e: OnLoadData) => void //All
onLoadStart?: (e: OnLoadStartData) => void //All
onPictureInPictureStatusChanged?: (e: OnPictureInPictureStatusChangedData) => void //iOS
onPlaybackRateChange?: (e: OnPlaybackData) => void //All
onProgress?: (e: OnProgressData) => void //All
onReadyForDisplay?: () => void //Android, iOS, Web
onReceiveAdEvent?: (e: OnReceiveAdEventData) => void //Android, iOS
onRestoreUserInterfaceForPictureInPictureStop?: () => void //iOS
onSeek?: (e: OnSeekData) => void //Android, iOS, Windows UWP
onPlaybackStateChanged?: (e: OnPlaybackStateChangedData) => void // Android
onTimedMetadata?: (e: OnTimedMetadataData) => void //Android, iOS
onAudioTracks?: (e: OnAudioTracksData) => void // Android
onTextTracks?: (e: OnTextTracksData) => void //Android
onVideoTracks?: (e: OnVideoTracksData) => void //Android
}

184
src/types/language.ts Normal file
View File

@@ -0,0 +1,184 @@
export type ISO639_1 =
| 'aa'
| 'ab'
| 'ae'
| 'af'
| 'ak'
| 'am'
| 'an'
| 'ar'
| 'as'
| 'av'
| 'ay'
| 'az'
| 'ba'
| 'be'
| 'bg'
| 'bi'
| 'bm'
| 'bn'
| 'bo'
| 'br'
| 'bs'
| 'ca'
| 'ce'
| 'ch'
| 'co'
| 'cr'
| 'cs'
| 'cu'
| 'cv'
| 'cy'
| 'da'
| 'de'
| 'dv'
| 'dz'
| 'ee'
| 'el'
| 'en'
| 'eo'
| 'es'
| 'et'
| 'eu'
| 'fa'
| 'ff'
| 'fi'
| 'fj'
| 'fo'
| 'fr'
| 'fy'
| 'ga'
| 'gd'
| 'gl'
| 'gn'
| 'gu'
| 'gv'
| 'ha'
| 'he'
| 'hi'
| 'ho'
| 'hr'
| 'ht'
| 'hu'
| 'hy'
| 'hz'
| 'ia'
| 'id'
| 'ie'
| 'ig'
| 'ii'
| 'ik'
| 'io'
| 'is'
| 'it'
| 'iu'
| 'ja'
| 'jv'
| 'ka'
| 'kg'
| 'ki'
| 'kj'
| 'kk'
| 'kl'
| 'km'
| 'kn'
| 'ko'
| 'kr'
| 'ks'
| 'ku'
| 'kv'
| 'kw'
| 'ky'
| 'la'
| 'lb'
| 'lg'
| 'li'
| 'ln'
| 'lo'
| 'lt'
| 'lu'
| 'lv'
| 'mg'
| 'mh'
| 'mi'
| 'mk'
| 'ml'
| 'mn'
| 'mr'
| 'ms'
| 'mt'
| 'my'
| 'na'
| 'nb'
| 'nd'
| 'ne'
| 'ng'
| 'nl'
| 'nn'
| 'no'
| 'nr'
| 'nv'
| 'ny'
| 'oc'
| 'oj'
| 'om'
| 'or'
| 'os'
| 'pa'
| 'pi'
| 'pl'
| 'ps'
| 'pt'
| 'qu'
| 'rm'
| 'rn'
| 'ro'
| 'ru'
| 'rw'
| 'sa'
| 'sc'
| 'sd'
| 'se'
| 'sg'
| 'si'
| 'sk'
| 'sl'
| 'sm'
| 'sn'
| 'so'
| 'sq'
| 'sr'
| 'ss'
| 'st'
| 'su'
| 'sv'
| 'sw'
| 'ta'
| 'te'
| 'tg'
| 'th'
| 'ti'
| 'tk'
| 'tl'
| 'tn'
| 'to'
| 'tr'
| 'ts'
| 'tt'
| 'tw'
| 'ty'
| 'ug'
| 'uk'
| 'ur'
| 'uz'
| 've'
| 'vi'
| 'vo'
| 'wa'
| 'wo'
| 'xh'
| 'yi'
| 'yo'
| 'za'
| 'zh'
| 'zu';

135
src/types/video.ts Normal file
View File

@@ -0,0 +1,135 @@
import type { ISO639_1 } from './language';
import type { ReactVideoEvents } from './events';
import type { StyleProp, ViewStyle } from 'react-native'
type Filter = | 'None'
| 'CIColorInvert'
| 'CIColorMonochrome'
| 'CIColorPosterize'
| 'CIFalseColor'
| 'CIMaximumComponent'
| 'CIMinimumComponent'
| 'CIPhotoEffectChrome'
| 'CIPhotoEffectFade'
| 'CIPhotoEffectInstant'
| 'CIPhotoEffectMono'
| 'CIPhotoEffectNoir'
| 'CIPhotoEffectProcess'
| 'CIPhotoEffectTonal'
| 'CIPhotoEffectTransfer'
| 'CISepiaTone'
type Headers = Record<string, string>;
export type ReactVideoSource = Readonly<{
uri?: string;
isNetwork?: boolean;
isAsset?: boolean;
shouldCache?: boolean;
type?: string;
mainVer?: number;
patchVer?: number;
headers?: Headers;
startTime?: number;
endTime?: number;
}>;
export type ReactVideoDrm = Readonly<{
type?: 'widevine' | 'playready' | 'clearkey' | 'fairplay';
licenseServer?: string;
headers?: Headers;
contentId?: string; // ios
certificateUrl?: string; // ios
base64Certificate?: boolean; // ios default: false
getLicense?: (licenseUrl: string, contentId: string, spcBase64: string) => void; // ios
}>
type BufferConfig = {
minBufferMs?: number;
maxBufferMs?: number;
bufferForPlaybackMs?: number;
bufferForPlaybackAfterRebufferMs?: number;
maxHeapAllocationPercent?: number;
minBackBufferMemoryReservePercent?: number;
minBufferMemoryReservePercent?: number;
}
type SelectedTrack = {
type: 'system' | 'disabled' | 'title' | 'language' | 'index';
value?: string | number;
}
type SelectedVideoTrack = {
type: 'auto' | 'disabled' | 'resolution' | 'index'
value?: number;
}
type SubtitleStyle = {
fontSize?: number;
paddingTop?: number;
paddingBottom?: number;
paddingLeft?: number;
paddingRight?: number;
}
type TextTracks = {
title: string;
language: ISO639_1;
type: | 'application/x-subrip'
| 'application/ttml+xml'
| 'text/vtt';
uri: string;
}[]
export interface ReactVideoProps extends ReactVideoEvents {
source?: ReactVideoSource;
drm?: ReactVideoDrm;
style?: StyleProp<ViewStyle>;
adTagUrl?: string; // iOS
audioOnly?: boolean;
automaticallyWaitsToMinimizeStalling?: boolean; // iOS
backBufferDurationMs?: number; // Android
bufferConfig?: BufferConfig; // Android
contentStartTime?: number; // Android
controls?: boolean;
currentPlaybackTime?: number; // Android
disableFocus?: boolean;
disableDisconnectError?: boolean; // Android
filter?: Filter; // iOS
filterEnabled?: boolean; // iOS
focusable?: boolean; // Android
fullscreen?: boolean; // iOS
fullscreenAutorotate?: boolean; // iOS
fullscreenOrientation?: 'all' | 'landscape' | 'portrait'; // iOS
hideShutterView?: boolean; // Android
ignoreSilentSwitch?: 'inherit' | 'ignore' | 'obey' // iOS
minLoadRetryCount?: number; // Android
maxBitRate?: number;
mixWithOthers?: 'inherit' | 'mix' | 'duck'; // iOS
muted?: boolean;
paused?: boolean;
pictureInPicture?: boolean // iOS
playInBackground?: boolean;
playWhenInactive?: boolean // iOS
poster?: string;
posterResizeMode?: 'contain' | 'center' | 'cover' | 'none' | 'repeat' | 'stretch';
preferredForwardBufferDuration?: number// iOS
preventsDisplaySleepDuringVideoPlayback?: boolean;
progressUpdateInterval?: number;
rate?: number;
repeat?: boolean;
reportBandwidth?: boolean; //Android
resizeMode?: 'none' | 'contain' | 'cover' | 'stretch';
selectedAudioTrack?: SelectedTrack;
selectedTextTrack?: SelectedTrack;
selectedVideoTrack?: SelectedVideoTrack; // android
subtitleStyle?: SubtitleStyle // android
textTracks?: TextTracks;
trackId?: string; // Android
useTextureView?: boolean; // Android
useSecureView?: boolean; // Android
volume?: number;
localSourceEncryptionKeyScheme?: string;
}