Fix love metadata update (#7124)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina 2024-11-07 18:31:48 +04:00 committed by GitHub
parent e34f59ca37
commit e5f07b9134
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 10 deletions

View File

@ -26,7 +26,8 @@ import {
type Room,
RoomAccess,
RoomType,
TranscriptionStatus
TranscriptionStatus,
type RoomMetadata
} from '@hcengineering/love'
import { getEmbeddedLabel, getMetadata, getResource, type IntlString } from '@hcengineering/platform'
import presentation, {
@ -351,7 +352,7 @@ lk.on(RoomEvent.RecordingStatusChanged, (evt) => {
})
lk.on(RoomEvent.RoomMetadataChanged, (metadata) => {
try {
const data = JSON.parse(metadata)
const data = JSON.parse(metadata) as RoomMetadata
if (data.recording !== undefined) {
isRecording.set(data.recording)
}
@ -379,10 +380,9 @@ lk.on(RoomEvent.Disconnected, () => {
})
function initRoomMetadata (metadata: string | undefined): void {
if (metadata === undefined) return
let data: { transcription?: TranscriptionStatus } = {}
let data: RoomMetadata
try {
data = metadata === '' ? {} : JSON.parse(metadata)
data = metadata == null || metadata === '' ? {} : JSON.parse(metadata)
} catch (err: any) {
data = {}
Analytics.handleError(err)

View File

@ -85,6 +85,12 @@ export type RoomLanguage =
| 'uk'
| 'vi'
export interface RoomMetadata {
recording?: boolean
transcription?: TranscriptionStatus
language?: RoomLanguage
}
export interface Room extends Doc {
name: string
type: RoomType

View File

@ -19,7 +19,7 @@ import serverClient from '@hcengineering/server-client'
import { initStatisticsContext, StorageConfig, StorageConfiguration } from '@hcengineering/server-core'
import { buildStorageFromConfig, storageConfigFromEnv } from '@hcengineering/server-storage'
import serverToken, { decodeToken } from '@hcengineering/server-token'
import { TranscriptionStatus } from '@hcengineering/love'
import { RoomMetadata, TranscriptionStatus } from '@hcengineering/love'
import cors from 'cors'
import express from 'express'
import { IncomingHttpHeaders } from 'http'
@ -152,7 +152,7 @@ export const main = async (): Promise<void> => {
}
// just check token
decodeToken(token)
await roomClient.updateRoomMetadata(req.body.roomName, JSON.stringify({ recording: false }))
await updateMetadata(roomClient, req.body.roomName, { recording: false })
void stopEgress(egressClient, req.body.roomName)
res.send()
})
@ -179,7 +179,7 @@ export const main = async (): Promise<void> => {
const metadata = language != null ? { transcription, language } : { transcription }
try {
await roomClient.updateRoomMetadata(roomName, JSON.stringify(metadata))
await updateMetadata(roomClient, roomName, metadata)
res.send()
} catch (e) {
console.error(e)
@ -205,7 +205,7 @@ export const main = async (): Promise<void> => {
return
}
try {
await roomClient.updateRoomMetadata(roomName, JSON.stringify({ language }))
await updateMetadata(roomClient, roomName, { language })
res.send()
} catch (e) {
console.error(e)
@ -309,7 +309,28 @@ const startRecord = async (
})
}
})
await roomClient.updateRoomMetadata(roomName, JSON.stringify({ recording: true }))
await updateMetadata(roomClient, roomName, { recording: true })
await egressClient.startRoomCompositeEgress(roomName, { file: output }, { layout: 'grid' })
return filepath
}
function parseMetadata (metadata?: string | null): RoomMetadata {
if (metadata === '' || metadata == null) return {}
try {
return JSON.parse(metadata) as RoomMetadata
} catch (e) {
return {}
}
}
async function updateMetadata (
roomClient: RoomServiceClient,
roomName: string,
metadata: Partial<RoomMetadata>
): Promise<void> {
const room = (await roomClient.listRooms([roomName]))[0]
const currentMetadata = parseMetadata(room?.metadata)
await roomClient.updateRoomMetadata(roomName, JSON.stringify({ ...currentMetadata, ...metadata }))
}