Skip to content

Commit

Permalink
fix: improve types, add consts for well-defined values, export const …
Browse files Browse the repository at this point in the history
…objects from react media store.
  • Loading branch information
cjpillsbury committed Apr 5, 2024
1 parent 4e18759 commit 874ed4e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,21 @@ export const StreamTypes = {
UNKNOWN: 'unknown',
};

/**
* @type {{
* HIGH: 'high';
* MEDIUM: 'medium';
* LOW: 'low';
* OFF: 'off';
* }}
*/
export const VolumeLevels = {
HIGH: 'high',
MEDIUM: 'medium',
LOW: 'low',
OFF: 'off',
};

/**
* @type {{
* INLINE: 'inline';
Expand Down
6 changes: 3 additions & 3 deletions src/js/media-store/request-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { getSubtitleTracks, toggleSubtitleTracks } from './util.js';
* } & {
* mediaPreviewTime: number;
* mediaPreviewImage: string;
* mediaPreviewCoords: [string,string,string,string]
* mediaPreviewCoords: [number,number,number,number]
* }} MediaState
*/

Expand Down Expand Up @@ -101,8 +101,8 @@ export const requestMap = {
: undefined;
const url = new URL(cue.text, base);
const previewCoordsStr = new URLSearchParams(url.hash).get('#xywh');
mediaPreviewCoords = /** @type {[string, string, string, string]} */ (
previewCoordsStr.split(',')
mediaPreviewCoords = /** @type {[number, number, number, number]} */ (
previewCoordsStr.split(',').map(numStr => +numStr)
);
mediaPreviewImage = url.href;
}
Expand Down
4 changes: 2 additions & 2 deletions src/js/media-store/state-mediator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import {
import { getTextTracksList } from '../utils/captions.js';

/**
* @typedef {'on-demand'|'live'|'unknown'} StreamTypeValue
* @typedef {StreamTypes[keyof StreamTypes]} StreamTypeValue
*/

/**
* @typedef {'unavailable'|'unsupported'} AvailabilityTypeValue
* @typedef {AvailabilityStates[keyof AvailabilityStates]} AvailabilityTypeValue
*/

/**
Expand Down
17 changes: 14 additions & 3 deletions src/js/react/media-store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import type {
MediaStateOwner,
MediaStore,
} from '../media-store/media-store';
import { MediaUIEvents, MediaUIProps } from '../constants';
import {
MediaUIEvents,
MediaUIProps,
AvailabilityStates,
StreamTypes,
VolumeLevels,
} from '../constants';

/**
* @description A lookup object for all well-defined action types that can be dispatched
Expand Down Expand Up @@ -39,9 +45,14 @@ import { MediaUIEvents, MediaUIProps } from '../constants';

export { MediaState };

export { AvailabilityStates, StreamTypes, VolumeLevels };

const {
REGISTER_MEDIA_STATE_RECEIVER,
UNREGISTER_MEDIA_STATE_RECEIVER,
// NOTE: These generic state change requests are not currently supported (CJP)
MEDIA_SHOW_TEXT_TRACKS_REQUEST,
MEDIA_HIDE_TEXT_TRACKS_REQUEST,
...StateChangeRequests
} = MediaUIEvents;

Expand Down Expand Up @@ -212,9 +223,9 @@ export const useMediaRef = () => {
/**
* @description This is the primary way to associate a component with the `MediaStore` provided
* by {@link MediaProvider|`<MediaProvider/>`} to be used as the target for entering fullscreen.
* To associate the media component, use `useMediaRef` just
* To associate the media component, use `useMediaFullscreenRef` just
* like you would {@link https://react.dev/reference/react/useRef#manipulating-the-dom-with-a-ref|useRef}.
* Unlike `useRef`, however, "under the hood" `useMediaRef` is actually a
* Unlike `useRef`, however, "under the hood" `useMediaFullscreenRef` is actually a
* {@link https://react.dev/reference/react-dom/components/common#ref-callback|ref callback} function.
*
* @example
Expand Down

0 comments on commit 874ed4e

Please sign in to comment.