Remove backward compatibility.

This commit is contained in:
John Livingston 2021-06-02 12:20:15 +02:00
parent a761d7067e
commit a1d5d83cc5
2 changed files with 5 additions and 34 deletions

View File

@ -3,7 +3,6 @@
flex-direction: column; flex-direction: column;
} }
/* For Peertube >= 3.2.0 */
#plugin-placeholder-player-next #peertube-plugin-livechat-container { #plugin-placeholder-player-next #peertube-plugin-livechat-container {
height: 100%; height: 100%;
} }

View File

@ -1,11 +1,9 @@
import { videoHasWebchat } from 'shared/lib/video' import { videoHasWebchat } from 'shared/lib/video'
interface VideoCache {[key: string]: Video}
interface VideoWatchLoadedHookOptions { interface VideoWatchLoadedHookOptions {
videojs: any videojs: any
video?: Video // comes with Peertube 3.2.0 video: Video
playlist?: any // comes with Peertube 3.2.0 playlist?: any
} }
function register ({ registerHook, peertubeHelpers }: RegisterOptions): void { function register ({ registerHook, peertubeHelpers }: RegisterOptions): void {
@ -16,10 +14,6 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void {
warn: (s: string) => console.warn('[peertube-plugin-livechat] ' + s) warn: (s: string) => console.warn('[peertube-plugin-livechat] ' + s)
} }
// This is for backward compatibility with Peertube < 3.2.0.
const videoCache: VideoCache = {}
let lastUUID: string | null = null
let settings: any = {} let settings: any = {}
function getBaseRoute (): string { function getBaseRoute (): string {
@ -178,10 +172,7 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void {
logger.error('No video provided') logger.error('No video provided')
return return
} }
// Peertube >= 3.2.0 provide #plugin-placeholder-player-next const placeholder = document.getElementById('plugin-placeholder-player-next')
const placeholder =
document.getElementById('plugin-placeholder-player-next') ??
document.getElementById('video-wrapper')
if (!placeholder) { if (!placeholder) {
logger.error('The required placeholder div is not present in the DOM.') logger.error('The required placeholder div is not present in the DOM.')
return return
@ -220,16 +211,6 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void {
}) })
} }
registerHook({
target: 'filter:api.video-watch.video.get.result',
handler: (video: Video) => {
// For Peertube < 3.2.0, hooks for action:video-watch... did not receive the video object
// So we store video objects in videoCache
videoCache[video.uuid] = video
lastUUID = video.uuid
return video
}
})
registerHook({ registerHook({
target: 'action:video-watch.video.loaded', target: 'action:video-watch.video.loaded',
handler: ({ handler: ({
@ -237,17 +218,8 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void {
playlist playlist
}: VideoWatchLoadedHookOptions) => { }: VideoWatchLoadedHookOptions) => {
if (!video) { if (!video) {
logger.info('It seems we are using Peertube < 3.2.0. Using a cache to get the video object') logger.error('No video argument in hook action:video-watch.video.loaded')
const uuid = lastUUID return
if (!uuid) {
logger.error('There is no lastUUID.')
return
}
video = videoCache[uuid]
if (!video) {
logger.error('Can\'t find the video ' + uuid + ' in the videoCache')
return
}
} }
if (playlist) { if (playlist) {
logger.info('We are in a playlist, we will not use the webchat') logger.info('We are in a playlist, we will not use the webchat')