-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
+
+ constructor (player: videojs.Player, options: PeertubePluginOptions) {
+ super(player, options)
+
+ this.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
+ this.player.src = function () {
+ return true
+ }
+
+ this.playerElement = options.playerElement
+
+ this.player.ready(() => {
+ this.initializePlayer(options)
+ this.runTorrentInfoScheduler()
+ })
+ }
+
+ dispose () {
+ // Don't need to destroy renderer, video player will be destroyed
+ this.flushVideoFile(this.currentVideoFile, false)