Skip to content

Commit

Permalink
fix: update types (#3288)
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofMoch authored Oct 11, 2023
1 parent 7fd7b3f commit 5c3baca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
34 changes: 19 additions & 15 deletions src/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
fullscreen,
drm,
textTracks,
selectedVideoTrack,
selectedAudioTrack,
selectedTextTrack,
onLoadStart,
Expand Down Expand Up @@ -153,8 +154,9 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
if (!drm) {
return;
}

return {
drmType: drm.type,
type: drm.type,
licenseServer: drm.licenseServer,
headers: drm.headers,
contentId: drm.contentId,
Expand All @@ -168,14 +170,9 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
if (!selectedTextTrack) {
return;
}
if (typeof selectedTextTrack?.value === 'number') {
return {
selectedTextType: selectedTextTrack?.type,
index: selectedTextTrack?.value,
};
}

return {
selectedTextType: selectedTextTrack?.type,
type: selectedTextTrack?.type,
value: selectedTextTrack?.value,
};
}, [selectedTextTrack]);
Expand All @@ -184,18 +181,24 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
if (!selectedAudioTrack) {
return;
}
if (typeof selectedAudioTrack?.value === 'number') {
return {
selectedAudioType: selectedAudioTrack?.type,
index: selectedAudioTrack?.value,
};
}

return {
selectedAudioType: selectedAudioTrack?.type,
type: selectedAudioTrack?.type,
value: selectedAudioTrack?.value,
};
}, [selectedAudioTrack]);

const _selectedVideoTrack = useMemo(() => {
if (!selectedVideoTrack) {
return;
}

return {
type: selectedVideoTrack?.type,
value: selectedVideoTrack?.value,
};
}, [selectedVideoTrack]);

const seek = useCallback(async (time: number, tolerance?: number) => {
if (isNaN(time)) {
throw new Error('Specified time is not a number');
Expand Down Expand Up @@ -470,6 +473,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
textTracks={textTracks}
selectedTextTrack={_selectedTextTrack}
selectedAudioTrack={_selectedAudioTrack}
selectedVideoTrack={_selectedVideoTrack}
onGetLicense={onGetLicense}
onVideoLoad={onVideoLoad}
onVideoLoadStart={onVideoLoadStart}
Expand Down
13 changes: 5 additions & 8 deletions src/VideoNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type DebugConfig = Readonly<{
}>;

type Drm = Readonly<{
drmType?: DrmType;
type?: DrmType;
licenseServer?: string;
headers?: Headers;
contentId?: string; // ios
Expand All @@ -74,17 +74,15 @@ type TextTracks = ReadonlyArray<
type TextTrackType = 'system' | 'disabled' | 'title' | 'language' | 'index';

type SelectedTextTrack = Readonly<{
selectedTextType: TextTrackType;
value?: string;
index?: number;
type: TextTrackType;
value?: string | number;
}>;

type AudioTrackType = 'system' | 'disabled' | 'title' | 'language' | 'index';

type SelectedAudioTrack = Readonly<{
selectedAudioType: AudioTrackType;
value?: string;
index?: number;
type: AudioTrackType;
value?: string | number;
}>;

export type Seek = Readonly<{
Expand Down Expand Up @@ -146,7 +144,6 @@ export type OnBandwidthUpdateData = Readonly<{
export type OnSeekData = Readonly<{
currentTime: number;
seekTime: number;
finished: boolean;
}>;

export type OnPlaybackStateChangedData = Readonly<{
Expand Down

0 comments on commit 5c3baca

Please sign in to comment.