Refractor videojs player
[oweals/peertube.git] / client / src / assets / player / peertube-videojs-typings.ts
1 // FIXME: something weird with our path definition in tsconfig and typings
2 // @ts-ignore
3 import * as videojs from 'video.js'
4
5 import { VideoFile } from '../../../../shared/models/videos/video.model'
6 import { PeerTubePlugin } from './peertube-plugin'
7 import { WebTorrentPlugin } from './webtorrent-plugin'
8
9 declare namespace videojs {
10   interface Player {
11     peertube (): PeerTubePlugin
12     webtorrent (): WebTorrentPlugin
13   }
14 }
15
16 interface VideoJSComponentInterface {
17   _player: videojs.Player
18
19   new (player: videojs.Player, options?: any): any
20
21   registerComponent (name: string, obj: any): any
22 }
23
24 type VideoJSCaption = {
25   label: string
26   language: string
27   src: string
28 }
29
30 type UserWatching = {
31   url: string,
32   authorizationHeader: string
33 }
34
35 type PeerTubePluginOptions = {
36   autoplay: boolean
37   videoViewUrl: string
38   videoDuration: number
39   startTime: number | string
40
41   userWatching?: UserWatching
42   subtitle?: string
43
44   videoCaptions: VideoJSCaption[]
45 }
46
47 type WebtorrentPluginOptions = {
48   playerElement: HTMLVideoElement
49
50   autoplay: boolean
51   videoDuration: number
52
53   videoFiles: VideoFile[]
54 }
55
56 type P2PMediaLoaderPluginOptions = {
57   type: string
58   src: string
59 }
60
61 type VideoJSPluginOptions = {
62   peertube: PeerTubePluginOptions
63
64   webtorrent?: WebtorrentPluginOptions
65
66   p2pMediaLoader?: P2PMediaLoaderPluginOptions
67 }
68
69 // videojs typings don't have some method we need
70 const videojsUntyped = videojs as any
71
72 type LoadedQualityData = {
73   qualitySwitchCallback: Function,
74   qualityData: {
75     video: {
76       id: number
77       label: string
78       selected: boolean
79     }[]
80   }
81 }
82
83 type ResolutionUpdateData = {
84   auto: boolean,
85   resolutionId: number
86 }
87
88 type AutoResolutionUpdateData = {
89   possible: boolean
90 }
91
92 export {
93   ResolutionUpdateData,
94   AutoResolutionUpdateData,
95   VideoJSComponentInterface,
96   videojsUntyped,
97   VideoJSCaption,
98   UserWatching,
99   PeerTubePluginOptions,
100   WebtorrentPluginOptions,
101   P2PMediaLoaderPluginOptions,
102   VideoJSPluginOptions,
103   LoadedQualityData
104 }