WIP on Prosody integration.
This commit is contained in:
@ -1,26 +1,36 @@
|
||||
import { initSettings } from './lib/settings'
|
||||
import { initRouters } from './lib/routers/index'
|
||||
import type { Logger } from 'winston'
|
||||
import { ensureProsodyRunning, ensureProsodyNotRunning } from './lib/prosody/ctl'
|
||||
import decache from 'decache'
|
||||
|
||||
let logger: Logger | undefined
|
||||
// FIXME: in Peertube <= 3.1.0, unregister don't have any parameter.
|
||||
// Using this global variable to fix this.
|
||||
let OPTIONS: RegisterServerOptions | undefined
|
||||
|
||||
async function register (options: RegisterServerOptions): Promise<any> {
|
||||
const { peertubeHelpers } = options
|
||||
|
||||
logger = peertubeHelpers.logger
|
||||
OPTIONS = options
|
||||
|
||||
await initSettings(options)
|
||||
await initRouters(options)
|
||||
|
||||
await ensureProsodyRunning(options)
|
||||
}
|
||||
|
||||
async function unregister (): Promise<any> {
|
||||
if (OPTIONS) {
|
||||
try {
|
||||
await ensureProsodyNotRunning(OPTIONS)
|
||||
} catch (error) {
|
||||
OPTIONS.peertubeHelpers.logger.error('Error when trying to unload Prosody: ' + (error as string))
|
||||
}
|
||||
}
|
||||
|
||||
const module = __filename
|
||||
logger?.info(`Unloading module ${module}...`)
|
||||
OPTIONS?.peertubeHelpers.logger.info(`Unloading module ${module}...`)
|
||||
// In peertube <= 3.1.0 sub modules are not removed from require.cache
|
||||
decache(module)
|
||||
logger?.info(`Successfully unloaded the module ${module}`)
|
||||
logger = undefined
|
||||
OPTIONS?.peertubeHelpers.logger.info(`Successfully unloaded the module ${module}`)
|
||||
OPTIONS = undefined
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
Reference in New Issue
Block a user