Skip to content

Commit

Permalink
Added types for single players
Browse files Browse the repository at this point in the history
Manual merge of #1098
Fixes #953
  • Loading branch information
JuanM04 authored and cookpete committed Jan 20, 2021
1 parent 7e69418 commit e411975
Show file tree
Hide file tree
Showing 17 changed files with 9,326 additions and 8,595 deletions.
133 changes: 0 additions & 133 deletions index.d.ts

This file was deleted.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"start": "webpack-dev-server --config webpack/config.babel.js",
"lint": "standard --verbose | snazzy",
"lint:fix": "standard --fix",
"lint:ts": "ts-standard --verbose types/*.d.ts | snazzy",
"lint:ts:fix": "ts-standard --fix types/*.d.ts",
"test": "cross-env NODE_ENV=test ava",
"test:coverage": "cross-env NODE_ENV=test nyc ava",
"test:codecov": "nyc report --reporter=json && codecov -f coverage/coverage-final.json",
Expand All @@ -19,7 +21,7 @@
"build:standalone": "cross-env NODE_ENV=production webpack --config webpack/standalone.babel.js",
"preversion": "npm run lint && npm run test",
"version": "auto-changelog -p && npm run build:dist && npm run build:standalone && git add CHANGELOG.md dist",
"prepublishOnly": "npm run build:lib && npm run build:lazy && npm run build:dist && node scripts/pre-publish.js && cp index.d.ts lazy",
"prepublishOnly": "npm run build:lib && npm run build:lazy && npm run build:dist && node scripts/pre-publish.js && cp types/*.d.ts . && cp types/index.d.ts lazy",
"postpublish": "node scripts/post-publish.js && npm run clean"
},
"repository": {
Expand Down Expand Up @@ -63,6 +65,8 @@
"@babel/preset-react": "^7.9.4",
"@babel/register": "^7.9.0",
"@hot-loader/react-dom": "^16.13.0",
"@types/node": "^14.0.24",
"@types/react": "^17.0.0",
"auto-changelog": "^2.0.0",
"autoprefixer": "^9.7.6",
"ava": "^3.6.0",
Expand Down Expand Up @@ -92,6 +96,8 @@
"snazzy": "^8.0.0",
"standard": "^14.3.3",
"style-loader": "^1.0.0",
"ts-standard": "^9.0.0",
"typescript": "^4.1.2",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"include": ["types/*.d.ts"]
}
59 changes: 59 additions & 0 deletions types/base.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Component, ReactElement, CSSProperties } from 'react'
import ReactPlayer from './index'

interface SourceProps {
src: string
type: string
}

export interface BaseReactPlayerProps {
url?: string | string[] | SourceProps[] | MediaStream
playing?: boolean
loop?: boolean
controls?: boolean
volume?: number
muted?: boolean
playbackRate?: number
width?: string | number
height?: string | number
style?: CSSProperties
progressInterval?: number
playsinline?: boolean
playIcon?: ReactElement
pip?: boolean
stopOnUnmount?: boolean
light?: boolean | string
wrapper?: any
onReady?: (player: ReactPlayer) => void
onStart?: () => void
onPlay?: () => void
onPause?: () => void
onBuffer?: () => void
onBufferEnd?: () => void
onEnded?: () => void
onEnablePIP?: () => void
onDisablePIP?: () => void
onError?: ( error: any, data?: any, hlsInstance?: any, hlsGlobal?: any) => void
onDuration?: (duration: number) => void
onSeek?: (seconds: number) => void
onProgress?: (state: {
played: number
playedSeconds: number
loaded: number
loadedSeconds: number
}) => void
[otherProps: string]: any
}

export default class BaseReactPlayer<T extends BaseReactPlayerProps> extends Component<T, any> {
static canPlay (url: string): boolean;
static canEnablePIP (url: string): boolean;
static addCustomPlayer (player: ReactPlayer): void;
static removeCustomPlayers (): void;
seekTo (amount: number, type?: 'seconds' | 'fraction'): void;
getCurrentTime (): number;
getSecondsLoaded (): number;
getDuration (): number;
getInternalPlayer (key?: string): Record<string, any>;
showPreview (): void;
}
11 changes: 11 additions & 0 deletions types/dailymotion.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import BaseReactPlayer, { BaseReactPlayerProps } from './base'

export interface DailyMotionConfig {
params?: Record<string, any>
}

export interface DailyMotionPlayerProps extends BaseReactPlayerProps {
config?: DailyMotionConfig
}

export default class DailyMotionPlayer extends BaseReactPlayer<DailyMotionPlayerProps> {}
13 changes: 13 additions & 0 deletions types/facebook.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import BaseReactPlayer, { BaseReactPlayerProps } from './base'

export interface FacebookConfig {
appId: string
version: string
playerId: string
}

export interface FacebookPlayerProps extends BaseReactPlayerProps {
config?: FacebookConfig
}

export default class FacebookPlayer extends BaseReactPlayer<FacebookPlayerProps> {}
29 changes: 29 additions & 0 deletions types/file.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import BaseReactPlayer, { BaseReactPlayerProps } from './base'

export interface TrackProps {
kind: string
src: string
srcLang: string
label: string
default?: boolean
}

export interface FileConfig {
attributes?: Record<string, any>
tracks?: TrackProps[]
forceVideo?: boolean
forceAudio?: boolean
forceHLS?: boolean
forceDASH?: boolean
forceFLV?: boolean
hlsOptions?: Record<string, any>
hlsVersion?: string
dashVersion?: string
flvVersion?: string
}

export interface FilePlayerProps extends BaseReactPlayerProps {
config?: FileConfig
}

export default class FilePlayer extends BaseReactPlayer<FilePlayerProps> {}
31 changes: 31 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import BaseReactPlayer, { BaseReactPlayerProps } from './base'

import { DailyMotionConfig } from './dailymotion'
import { FacebookConfig } from './facebook'
import { FileConfig } from './file'
import { MixcloudConfig } from './mixcloud'
import { SoundCloudConfig } from './soundcloud'
import { TwitchConfig } from './twitch'
import { VidyardConfig } from './vidyard'
import { VimeoConfig } from './vimeo'
import { WistiaConfig } from './wistia'
import { YouTubeConfig } from './youtube'

export interface Config {
soundcloud?: SoundCloudConfig
youtube?: YouTubeConfig
facebook?: FacebookConfig
dailymotion?: DailyMotionConfig
vimeo?: VimeoConfig
file?: FileConfig
wistia?: WistiaConfig
mixcloud?: MixcloudConfig
vidyard?: VidyardConfig
twitch?: TwitchConfig
}

export interface ReactPlayerProps extends BaseReactPlayerProps {
config?: Config
}

export default class ReactPlayer extends BaseReactPlayer<ReactPlayerProps> {}
11 changes: 11 additions & 0 deletions types/mixcloud.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import BaseReactPlayer, { BaseReactPlayerProps } from './base'

export interface MixcloudConfig {
options?: Record<string, any>
}

export interface MixcloudPlayerProps extends BaseReactPlayerProps {
config?: MixcloudConfig
}

export default class MixcloudPlayer extends BaseReactPlayer<MixcloudPlayerProps> {}
11 changes: 11 additions & 0 deletions types/soundcloud.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import BaseReactPlayer, { BaseReactPlayerProps } from './base'

export interface SoundCloudConfig {
options?: Record<string, any>
}

export interface SoundCloudPlayerProps extends BaseReactPlayerProps {
config?: SoundCloudConfig
}

export default class SoundCloudPlayer extends BaseReactPlayer<SoundCloudPlayerProps> {}
5 changes: 5 additions & 0 deletions types/streamable.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import BaseReactPlayer, { BaseReactPlayerProps } from './base'

export interface StreamablePlayerProps extends BaseReactPlayerProps {}

export default class StreamablePlayer extends BaseReactPlayer<StreamablePlayerProps> {}
12 changes: 12 additions & 0 deletions types/twitch.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import BaseReactPlayer, { BaseReactPlayerProps } from './base'

export interface TwitchConfig {
options?: Record<string, any>
playerId?: string
}

export interface TwitchPlayerProps extends BaseReactPlayerProps {
config?: TwitchConfig
}

export default class TwitchPlayer extends BaseReactPlayer<TwitchPlayerProps> {}
11 changes: 11 additions & 0 deletions types/vidyard.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import BaseReactPlayer, { BaseReactPlayerProps } from './base'

export interface VidyardConfig {
options?: Record<string, object>
}

export interface VidyardPlayerProps extends BaseReactPlayerProps {
config?: VidyardConfig
}

export default class VidyardPlayer extends BaseReactPlayer<VidyardPlayerProps> {}
11 changes: 11 additions & 0 deletions types/vimeo.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import BaseReactPlayer, { BaseReactPlayerProps } from './base'

export interface VimeoConfig {
playerOptions?: Record<string, any>
}

export interface VimeoPlayerProps extends BaseReactPlayerProps {
config?: VimeoConfig
}

export default class VimeoPlayer extends BaseReactPlayer<VimeoPlayerProps> {}
Loading

0 comments on commit e411975

Please sign in to comment.