Merge branch 'master' into develop
[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/webtorrent-plugin'
8 import { P2pMediaLoaderPlugin } from './p2p-media-loader/p2p-media-loader-plugin'
9 import { PlayerMode } from './peertube-player-manager'
10
11 declare namespace videojs {
12   interface Player {
13     peertube (): PeerTubePlugin
14     webtorrent (): WebTorrentPlugin
15     p2pMediaLoader (): P2pMediaLoaderPlugin
16   }
17 }
18
19 interface VideoJSComponentInterface {
20   _player: videojs.Player
21
22   new (player: videojs.Player, options?: any): any
23
24   registerComponent (name: string, obj: any): any
25 }
26
27 type VideoJSCaption = {
28   label: string
29   language: string
30   src: string
31 }
32
33 type UserWatching = {
34   url: string,
35   authorizationHeader: string
36 }
37
38 type PeerTubePluginOptions = {
39   mode: PlayerMode
40
41   autoplay: boolean
42   videoViewUrl: string
43   videoDuration: number
44
45   userWatching?: UserWatching
46   subtitle?: string
47
48   videoCaptions: VideoJSCaption[]
49
50   stopTime: number | string
51 }
52
53 type WebtorrentPluginOptions = {
54   playerElement: HTMLVideoElement
55
56   autoplay: boolean
57   videoDuration: number
58
59   videoFiles: VideoFile[]
60
61   startTime: number | string
62 }
63
64 type P2PMediaLoaderPluginOptions = {
65   redundancyBaseUrls: string[]
66   type: string
67   src: string
68
69   startTime: number | string
70 }
71
72 type VideoJSPluginOptions = {
73   peertube: PeerTubePluginOptions
74
75   webtorrent?: WebtorrentPluginOptions
76
77   p2pMediaLoader?: P2PMediaLoaderPluginOptions
78 }
79
80 // videojs typings don't have some method we need
81 const videojsUntyped = videojs as any
82
83 type LoadedQualityData = {
84   qualitySwitchCallback: Function,
85   qualityData: {
86     video: {
87       id: number
88       label: string
89       selected: boolean
90     }[]
91   }
92 }
93
94 type ResolutionUpdateData = {
95   auto: boolean,
96   resolutionId: number
97   id?: number
98 }
99
100 type AutoResolutionUpdateData = {
101   possible: boolean
102 }
103
104 type PlayerNetworkInfo = {
105   http: {
106     downloadSpeed: number
107     uploadSpeed: number
108     downloaded: number
109     uploaded: number
110   }
111
112   p2p: {
113     downloadSpeed: number
114     uploadSpeed: number
115     downloaded: number
116     uploaded: number
117     numPeers: number
118   }
119 }
120
121 export {
122   PlayerNetworkInfo,
123   ResolutionUpdateData,
124   AutoResolutionUpdateData,
125   VideoJSComponentInterface,
126   videojsUntyped,
127   VideoJSCaption,
128   UserWatching,
129   PeerTubePluginOptions,
130   WebtorrentPluginOptions,
131   P2PMediaLoaderPluginOptions,
132   VideoJSPluginOptions,
133   LoadedQualityData
134 }