Exported Types
The RxPlayer being written in TypeScript, it has type definitions attached to its source code that can be helpful if you develop an application in TypeScript yourself.
“Using” types
Because we follow the usual way of adding definition files (as d.ts
file
alongside our sources), those typings should be auto-exported when importing our
library in your favorite editor (as long as it is linked to a TSServer of some
sort).
Importing specific types
As some APIs can have pretty complicated arguments, you might also want to import some of our internal type definitions into your code.
To simplify this process, we export some type definitions which can be imported through the following line in your file:
import { SOME_TYPE } from "rx-player/types"
The exported types are:
-
IConstructorOptions
: Argument to give tonew RxPlayer(args)
. Example:import RxPlayer from "rx-player"; import { IConstructorOptions } from "rx-player/types"; function generateConstructorOptions() : IConstructorOptions { const videoElement = document.querySelector("video"); return { stopAtEnd: false, videoElement, }; } const options = generateConstructorOptions(); const player = new RxPlayer(options); export default player;
-
ILoadVideoOptions
: Argument to give to aloadVideo
call. Example:import { ILoadVideoOptions } from "rx-player/types"; import player from "./player"; // define an RxPlayer instance import config from "./config"; // define a global config function generateLoadVideoOptions(url : string) : ILoadVideoOptions { return { url, transport: "dash", autoPlay: true, }; } const loadVideoOpts = generateLoadVideoOptions(config.DEFAULT_URL); player.loadVideo(loadVideoOpts);
Speaking of loadVideo
, some subparts of ILoadVideoOptions
are also
exported:
-
ITransportOptions
: type for thetransportOptions
property optionally given toloadVideo
. -
IKeySystemOption
: type for an element of thekeySystems
array, which is an optional property given toloadVideo
.To clarify, the
keySystems
property in aloadVideo
call is an optional array of one or multipleIKeySystemOption
. -
ISupplementaryTextTrackOption
: type for an element of thesupplementaryTextTracks
array, which is an optional property given toloadVideo
. -
ISupplementaryImageTrackOption
: type for an element of thesupplementaryImageTracks
array, which is an optional property given toloadVideo
. -
IDefaultAudioTrackOption
: type for thedefaultAudioTrack
property optionally given toloadVideo
. -
IDefaultTextTrackOption
: type for thedefaultAudioTrack
property optionally given toloadVideo
. -
INetworkConfigOption
: type for thenetworkConfig
property optionally given toloadVideo
. -
IStartAtOption
: type for thestartAt
property optionally given toloadVideo
.
Two constructor options have also their type definition exported, those are:
-
IAudioTrackPreference
: which is the type of a single element in thepreferredAudioTracks
array. -
ITextTrackPreference
: which is the type of a single element in thepreferredTextTracks
array.