Refactoring getProsodyConfig stuffs. Preparing the http bind router.
This commit is contained in:
@ -75,14 +75,20 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise<Pro
|
||||
}
|
||||
}
|
||||
|
||||
async function getProsodyConfigContent (options: RegisterServerOptions): Promise<string> {
|
||||
interface ProsodyConfig {
|
||||
content: string
|
||||
paths: ProsodyFilePaths
|
||||
port: string
|
||||
}
|
||||
async function getProsodyConfig (options: RegisterServerOptions): Promise<ProsodyConfig> {
|
||||
const logger = options.peertubeHelpers.logger
|
||||
logger.debug('Calling getProsodyConfigContent')
|
||||
logger.debug('Calling getProsodyConfig')
|
||||
|
||||
const port = '5280'
|
||||
const peertubeDomain = 'localhost'
|
||||
const paths = await getProsodyFilePaths(options)
|
||||
const logMode: LogMode = 'debug'
|
||||
return `
|
||||
const content = `
|
||||
|
||||
admins = { }
|
||||
plugin_paths = { }
|
||||
@ -153,36 +159,35 @@ Component "room.localhost" "muc"
|
||||
muc_room_default_change_subject = false
|
||||
muc_room_default_history_length = 20
|
||||
`
|
||||
return {
|
||||
content,
|
||||
paths,
|
||||
port
|
||||
}
|
||||
}
|
||||
|
||||
async function getProsodyConfigPath (options: RegisterServerOptions): Promise<string> {
|
||||
const logger = options.peertubeHelpers.logger
|
||||
logger.debug('Calling getProsodyConfigPath')
|
||||
|
||||
const paths = await getProsodyFilePaths(options)
|
||||
return paths.config
|
||||
}
|
||||
|
||||
async function writeProsodyConfig (options: RegisterServerOptions): Promise<void> {
|
||||
async function writeProsodyConfig (options: RegisterServerOptions): Promise<ProsodyConfig> {
|
||||
const logger = options.peertubeHelpers.logger
|
||||
logger.debug('Calling writeProsodyConfig')
|
||||
|
||||
logger.debug('Ensuring that the working dir exists')
|
||||
await ensureWorkingDir(options)
|
||||
logger.debug('Computing the Prosody config content')
|
||||
const content = await getProsodyConfigContent(options)
|
||||
const config = await getProsodyConfig(options)
|
||||
const content = config.content
|
||||
const fileName = config.paths.config
|
||||
|
||||
const fileName = await getProsodyConfigPath(options)
|
||||
logger.info(`Writing prosody configuration file to ${fileName}`)
|
||||
await fs.promises.writeFile(fileName, content)
|
||||
logger.debug('Prosody configuration file writen')
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
export {
|
||||
getProsodyConfigContent,
|
||||
getProsodyConfig,
|
||||
getWorkingDir,
|
||||
ensureWorkingDir,
|
||||
getProsodyFilePaths,
|
||||
getProsodyConfigPath,
|
||||
writeProsodyConfig
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { getProsodyConfigContent, getProsodyConfigPath, getProsodyFilePaths, writeProsodyConfig } from './config'
|
||||
import { getProsodyConfig, getProsodyFilePaths, writeProsodyConfig } from './config'
|
||||
import { changeHttpBindRoute } from '../routers/webchat'
|
||||
import * as fs from 'fs'
|
||||
import * as child_process from 'child_process'
|
||||
|
||||
@ -99,14 +100,16 @@ async function testProsodyCorrectlyRunning (options: RegisterServerOptions): Pro
|
||||
result.ok = false // more tests to come
|
||||
|
||||
try {
|
||||
const filePath = await getProsodyConfigPath(options)
|
||||
const wantedConfig = await getProsodyConfig(options)
|
||||
const filePath = wantedConfig.paths.config
|
||||
|
||||
await fs.promises.access(filePath, fs.constants.R_OK) // throw an error if file does not exist.
|
||||
result.messages.push(`The prosody configuration file (${filePath}) exists`)
|
||||
const actualContent = await fs.promises.readFile(filePath, {
|
||||
encoding: 'utf-8'
|
||||
})
|
||||
|
||||
const wantedContent = await getProsodyConfigContent(options)
|
||||
const wantedContent = wantedConfig.content
|
||||
if (actualContent === wantedContent) {
|
||||
result.messages.push('Prosody configuration file content is correct.')
|
||||
} else {
|
||||
@ -150,9 +153,9 @@ async function ensureProsodyRunning (options: RegisterServerOptions): Promise<vo
|
||||
|
||||
// writing the configuration file
|
||||
logger.debug('Writing the configuration file')
|
||||
await writeProsodyConfig(options)
|
||||
const config = await writeProsodyConfig(options)
|
||||
|
||||
const filePaths = await getProsodyFilePaths(options)
|
||||
const filePaths = config.paths
|
||||
|
||||
// launch prosody
|
||||
logger.info('Going to launch prosody')
|
||||
@ -176,6 +179,9 @@ async function ensureProsodyRunning (options: RegisterServerOptions): Promise<vo
|
||||
logger.info(`Prosody process exited with code ${code ?? 'null'}`)
|
||||
})
|
||||
|
||||
// Set the http-bind route.
|
||||
changeHttpBindRoute(options, config.port)
|
||||
|
||||
async function sleep (ms: number): Promise<any> {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms)
|
||||
|
Reference in New Issue
Block a user