Adding a Shared folder:

* init some shared functions (videoHasWebchat, parseConfigUUIDs)
* api/room: checking that video has live enabled
* fix promise handling in initChat function
* removing some 'use strict' that are no more necessary in typescript
This commit is contained in:
John Livingston
2021-05-01 18:30:21 +02:00
parent 0cc57dfc12
commit ef05583fba
9 changed files with 145 additions and 24 deletions

View File

@ -1,6 +1,4 @@
'use strict'
function register ({ registerHook }: RegisterOptions): void {
registerHook({
target: 'action:router.navigation-end',

View File

@ -13,8 +13,13 @@
"strictBindCallApply": true, // should already be true because of strict:true
"noUnusedLocals": true,
"outDir": "../dist/client",
"paths": {}
"paths": {
"shared/*": ["../shared/*"]
}
},
"include": ["./**/*"],
"include": [
"./**/*",
"../shared/**/*"
],
"exclude": []
}

View File

@ -1,4 +1,4 @@
'use strict'
import { parseConfigUUIDs } from 'shared/lib/config'
interface VideoCache {[key: string]: Video}
@ -14,19 +14,6 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void {
let lastUUID: string | null = null
let settings: any = {}
function parseUUIDs (s: string): string[] {
if (!s) {
return []
}
let a = s.split('\n')
a = a.map(line => {
return line.replace(/#.*$/, '')
.replace(/^\s+/, '')
.replace(/\s+$/, '')
})
return a.filter(line => line !== '')
}
function getBaseRoute (): string {
// FIXME: should be provided by PeertubeHelpers (does not exists for now)
// We are guessing the route with the correct plugin version with this trick:
@ -195,12 +182,11 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void {
container.setAttribute('peertube-plugin-livechat-state', 'initializing')
videoWrapper.append(container)
// eslint-disable-next-line @typescript-eslint/no-floating-promises
peertubeHelpers.getSettings().then((s: any) => {
settings = s
const liveOn = !!settings['chat-all-lives']
const nonLiveOn = !!settings['chat-all-non-lives']
const uuids = parseUUIDs(settings['chat-videos-list'])
const uuids = parseConfigUUIDs(settings['chat-videos-list'])
if (!uuids.length && !liveOn && !nonLiveOn) {
logger.log('Feature not activated.')
return
@ -241,6 +227,8 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void {
container.setAttribute('peertube-plugin-livechat-state', 'closed')
}
})
}, () => {
logger.error('Cant get settings')
})
}