WIP: store and get relation between rooms and channels:
* rebuildData * handling video update (to check for channel changes)
This commit is contained in:
41
server/lib/prosody/api/host.ts
Normal file
41
server/lib/prosody/api/host.ts
Normal file
@ -0,0 +1,41 @@
|
||||
interface ProsodyHost {
|
||||
host: string
|
||||
port: string
|
||||
}
|
||||
|
||||
let current: ProsodyHost | undefined
|
||||
|
||||
/**
|
||||
* When loading Prosody, keep track of the current host and port.
|
||||
* @param host host
|
||||
* @param port port
|
||||
*/
|
||||
function setCurrentProsody (host: string, port: string): void {
|
||||
current = {
|
||||
host,
|
||||
port
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When stopping Prosody, delete current host and port.
|
||||
*/
|
||||
function delCurrentProsody (): void {
|
||||
current = undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current Prosody host infos.
|
||||
* @returns Prosody host info
|
||||
*/
|
||||
function getCurrentProsody (): ProsodyHost | null {
|
||||
// cloning to avoid issues
|
||||
if (!current) { return null }
|
||||
return Object.assign({}, current)
|
||||
}
|
||||
|
||||
export {
|
||||
setCurrentProsody,
|
||||
delCurrentProsody,
|
||||
getCurrentProsody
|
||||
}
|
41
server/lib/prosody/api/list-rooms.ts
Normal file
41
server/lib/prosody/api/list-rooms.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import type { RegisterServerOptions } from '@peertube/peertube-types'
|
||||
import { getCurrentProsody } from './host'
|
||||
import { getAPIKey } from '../../apikey'
|
||||
const got = require('got')
|
||||
|
||||
interface ProsodyRoomDesc {
|
||||
jid: string
|
||||
localpart: string
|
||||
name: string
|
||||
lang: string
|
||||
description: string
|
||||
lasttimestamp?: number
|
||||
}
|
||||
|
||||
async function listProsodyRooms (options: RegisterServerOptions): Promise<ProsodyRoomDesc[]> {
|
||||
const logger = options.peertubeHelpers.logger
|
||||
|
||||
const currentProsody = getCurrentProsody()
|
||||
if (!currentProsody) {
|
||||
throw new Error('It seems that prosody is not binded... Cant list rooms.')
|
||||
}
|
||||
|
||||
// Requesting on localhost, because currentProsody.host does not always resolves correctly (docker use case, ...)
|
||||
const apiUrl = `http://localhost:${currentProsody.port}/peertubelivechat_list_rooms/list-rooms`
|
||||
logger.debug('Calling list rooms API on url: ' + apiUrl)
|
||||
const rooms = await got(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
authorization: 'Bearer ' + await getAPIKey(options),
|
||||
host: currentProsody.host
|
||||
},
|
||||
responseType: 'json',
|
||||
resolveBodyOnly: true
|
||||
})
|
||||
|
||||
return rooms
|
||||
}
|
||||
|
||||
export {
|
||||
listProsodyRooms
|
||||
}
|
Reference in New Issue
Block a user