2023-04-20 14:07:00 +00:00
|
|
|
import type { RegisterServerOptions } from '@peertube/peertube-types'
|
|
|
|
import type { RemoteVideoHandlerParams } from './types'
|
2023-05-19 10:52:52 +00:00
|
|
|
import { storeVideoLiveChatInfos, storeRemoteServerInfos } from './storage'
|
2023-04-20 16:28:08 +00:00
|
|
|
import { sanitizePeertubeLiveChatInfos } from './sanitize'
|
2023-04-20 14:07:00 +00:00
|
|
|
|
2023-04-20 16:28:08 +00:00
|
|
|
/**
|
|
|
|
* This function reads incoming ActivityPub data, to detect LiveChat informations.
|
|
|
|
* @param options server options
|
|
|
|
* @param param1 handler parameters
|
|
|
|
* @returns void
|
|
|
|
*/
|
2023-04-20 14:07:00 +00:00
|
|
|
async function readIncomingAPVideo (
|
|
|
|
options: RegisterServerOptions,
|
|
|
|
{ video, videoAPObject }: RemoteVideoHandlerParams
|
|
|
|
): Promise<void> {
|
2023-04-20 16:28:08 +00:00
|
|
|
let peertubeLiveChat = ('peertubeLiveChat' in videoAPObject) ? videoAPObject.peertubeLiveChat : false
|
|
|
|
|
|
|
|
// We must sanitize peertubeLiveChat, as it comes for the outer world.
|
2023-05-31 14:19:45 +00:00
|
|
|
peertubeLiveChat = sanitizePeertubeLiveChatInfos(options, peertubeLiveChat, video.url)
|
2023-04-20 16:28:08 +00:00
|
|
|
|
|
|
|
await storeVideoLiveChatInfos(options, video, peertubeLiveChat)
|
2023-05-19 10:52:52 +00:00
|
|
|
if (video.remote) {
|
2023-05-24 14:09:55 +00:00
|
|
|
if (peertubeLiveChat !== false && peertubeLiveChat.xmppserver) {
|
|
|
|
await storeRemoteServerInfos(options, peertubeLiveChat.xmppserver)
|
|
|
|
}
|
2023-05-19 10:52:52 +00:00
|
|
|
}
|
2023-04-20 14:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
readIncomingAPVideo
|
|
|
|
}
|