]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/peertube-videojs-typings.ts
Fix webtorrent resolution issue
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / peertube-videojs-typings.ts
index 634c7fdc9df0e38484c31cebe5ed2b0b1b721c49..e4572266130c8bd03c3686f563ad15b6cc9c5344 100644 (file)
@@ -1,22 +1,50 @@
-// FIXME: something weird with our path definition in tsconfig and typings
-// @ts-ignore
-import * as videojs from 'video.js'
+import videojs from 'video.js'
+import { PeerTubePlugin } from './peertube-plugin'
+import { WebTorrentPlugin } from './webtorrent/webtorrent-plugin'
+import { P2pMediaLoaderPlugin } from './p2p-media-loader/p2p-media-loader-plugin'
+import { PlayerMode } from './peertube-player-manager'
+import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager'
+import { VideoFile } from '@shared/models'
 
-import { VideoFile } from '../../../../shared/models/videos/video.model'
-import { PeerTubePlugin } from './peertube-videojs-plugin'
+declare module 'video.js' {
+  export interface VideoJsPlayer {
+    theaterEnabled: boolean
+
+    // FIXME: add it to upstream typings
+    posterImage: {
+      show (): void
+      hide (): void
+    }
+
+    handleTechSeeked_ (): void
+
+    // Plugins
 
-declare namespace videojs {
-  interface Player {
     peertube (): PeerTubePlugin
-  }
-}
+    webtorrent (): WebTorrentPlugin
+    p2pMediaLoader (): P2pMediaLoaderPlugin
+
+    contextmenuUI (options: any): any
 
-interface VideoJSComponentInterface {
-  _player: videojs.Player
+    bezels (): void
 
-  new (player: videojs.Player, options?: any): any
+    qualityLevels (): { height: number, id: number }[] & {
+      selectedIndex: number
+      selectedIndex_: number
 
-  registerComponent (name: string, obj: any): any
+      addQualityLevel (representation: {
+        id: number
+        label: string
+        height: number
+        _enabled: boolean
+      }): void
+    }
+
+    textTracks (): TextTrackList & {
+      on: Function
+      tracks_: { kind: string, mode: string, language: string }[]
+    }
+  }
 }
 
 type VideoJSCaption = {
@@ -30,26 +58,95 @@ type UserWatching = {
   authorizationHeader: string
 }
 
-type PeertubePluginOptions = {
-  videoFiles: VideoFile[]
-  playerElement: HTMLVideoElement
+type PeerTubePluginOptions = {
+  mode: PlayerMode
+
+  autoplay: boolean
   videoViewUrl: string
   videoDuration: number
-  startTime: number | string
-  autoplay: boolean,
-  videoCaptions: VideoJSCaption[]
 
-  subtitle?: string
   userWatching?: UserWatching
+  subtitle?: string
+
+  videoCaptions: VideoJSCaption[]
+
+  stopTime: number | string
 }
 
-// videojs typings don't have some method we need
-const videojsUntyped = videojs as any
+type WebtorrentPluginOptions = {
+  playerElement: HTMLVideoElement
+
+  autoplay: boolean
+  videoDuration: number
+
+  videoFiles: VideoFile[]
+
+  startTime: number | string
+}
+
+type P2PMediaLoaderPluginOptions = {
+  redundancyUrlManager: RedundancyUrlManager
+  type: string
+  src: string
+
+  startTime: number | string
+}
+
+type VideoJSPluginOptions = {
+  peertube: PeerTubePluginOptions
+
+  webtorrent?: WebtorrentPluginOptions
+
+  p2pMediaLoader?: P2PMediaLoaderPluginOptions
+}
+
+type LoadedQualityData = {
+  qualitySwitchCallback: Function,
+  qualityData: {
+    video: {
+      id: number
+      label: string
+      selected: boolean
+    }[]
+  }
+}
+
+type ResolutionUpdateData = {
+  auto: boolean,
+  resolutionId: number
+  id?: number
+}
+
+type AutoResolutionUpdateData = {
+  possible: boolean
+}
+
+type PlayerNetworkInfo = {
+  http: {
+    downloadSpeed: number
+    uploadSpeed: number
+    downloaded: number
+    uploaded: number
+  }
+
+  p2p: {
+    downloadSpeed: number
+    uploadSpeed: number
+    downloaded: number
+    uploaded: number
+    numPeers: number
+  }
+}
 
 export {
-  VideoJSComponentInterface,
-  PeertubePluginOptions,
-  videojsUntyped,
+  PlayerNetworkInfo,
+  ResolutionUpdateData,
+  AutoResolutionUpdateData,
   VideoJSCaption,
-  UserWatching
+  UserWatching,
+  PeerTubePluginOptions,
+  WebtorrentPluginOptions,
+  P2PMediaLoaderPluginOptions,
+  VideoJSPluginOptions,
+  LoadedQualityData
 }