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

41
shared/.eslintrc.json Normal file
View File

@ -0,0 +1,41 @@
{
"root": true,
"env": {
"browser": true,
"es6": true
},
"extends": [
"standard-with-typescript"
],
"globals": {},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"project": [
"./server/tsconfig.json",
"./client/tsconfig.json"
]
},
"plugins": [
"@typescript-eslint"
],
"ignorePatterns": [],
"rules": {
"@typescript-eslint/no-unused-vars": [2, {"argsIgnorePattern": "^_"}],
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/return-await": [2, "in-try-catch"], // FIXME: correct?
"@typescript-eslint/no-invalid-void-type": "off",
"@typescript-eslint/triple-slash-reference": "off",
"max-len": [
"error",
{
"code": 120,
"comments": 120
}
],
"no-unused-vars": "off"
}
}

16
shared/lib/config.ts Normal file
View File

@ -0,0 +1,16 @@
function parseConfigUUIDs (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 !== '')
}
export {
parseConfigUUIDs
}

52
shared/lib/video.ts Normal file
View File

@ -0,0 +1,52 @@
import { parseConfigUUIDs } from './config'
interface SharedSettings {
'chat-only-locals': boolean
'chat-all-lives': boolean
'chat-all-non-lives': boolean
'chat-videos-list': string
}
interface SharedVideoBase {
uuid: string
isLive: boolean
}
interface SharedVideoFrontend extends SharedVideoBase {
isLocal: boolean
}
interface SharedVideoBackend extends SharedVideoBase {
remote: boolean
}
type SharedVideo = SharedVideoBackend | SharedVideoFrontend
function videoHasWebchat (settings: SharedSettings, video: SharedVideo): boolean {
if (settings['chat-only-locals']) {
if ('isLocal' in video) {
if (!video.isLocal) return false
} else {
if (video.remote) return false
}
}
if (settings['chat-all-lives']) {
if (video.isLive) return true
}
if (settings['chat-all-non-lives']) {
if (!video.isLive) return true
}
const uuids = parseConfigUUIDs(settings['chat-videos-list'])
if (uuids.includes(video.uuid)) {
return true
}
return false
}
export {
videoHasWebchat
}