Correctly implement p2p-media-loader
[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   id?: number
87 }
88
89 type AutoResolutionUpdateData = {
90   possible: boolean
91 }
92
93 type PlayerNetworkInfo = {
94   p2p: {
95     downloadSpeed: number
96     uploadSpeed: number
97     downloaded: number
98     uploaded: number
99     numPeers: number
100   }
101 }
102
103 export {
104   PlayerNetworkInfo,
105   ResolutionUpdateData,
106   AutoResolutionUpdateData,
107   VideoJSComponentInterface,
108   videojsUntyped,
109   VideoJSCaption,
110   UserWatching,
111   PeerTubePluginOptions,
112   WebtorrentPluginOptions,
113   P2PMediaLoaderPluginOptions,
114   VideoJSPluginOptions,
115   LoadedQualityData
116 }