-const peertubePlugin = function (options: PeertubePluginOptions) {
- const player = this
- let currentVideoFile: VideoFile = undefined
- const playerElement = options.playerElement
- player.videoFiles = options.videoFiles
-
- // Hack to "simulate" src link in video.js >= 6
- // Without this, we can't play the video after pausing it
- // https://github.com/videojs/video.js/blob/master/src/js/player.js#L1633
- player.src = function () {
- return true
+Button.registerComponent('WebTorrentButton', WebTorrentButton)
+
+const Plugin: VideoJSComponentInterface = videojsUntyped.getPlugin('plugin')
+class PeerTubePlugin extends Plugin {
+ private player: any
+ private currentVideoFile: VideoFile
+ private playerElement: HTMLVideoElement
+ private videoFiles: VideoFile[]
+ private torrent: WebTorrent.Torrent
+ private autoplay = false
+ private videoViewUrl: string
+ private videoDuration: number
+ private videoViewInterval
+ private torrentInfoInterval
+ private savePlayerSrcFunction: Function
+
+ constructor (player: videojs.Player, options: PeertubePluginOptions) {
+ super(player, options)
+
+ // Fix canplay event on google chrome by disabling default videojs autoplay
+ this.autoplay = this.player.options_.autoplay
+ this.player.options_.autoplay = false
+
+ this.videoFiles = options.videoFiles
+ this.videoViewUrl = options.videoViewUrl
+ this.videoDuration = options.videoDuration
+
+ this.savePlayerSrcFunction = this.player.src
+ // Hack to "simulate" src link in video.js >= 6
+ // Without this, we can't play the video after pausing it
+ // https://github.com/videojs/video.js/blob/master/src/js/player.js#L1633
+ this.player.src = () => true
+
+ this.playerElement = options.playerElement
+
+ this.player.ready(() => {
+ this.initializePlayer(options)
+ this.runTorrentInfoScheduler()
+ this.runViewAdd()
+ })