mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 03:14:40 +03:00
Fix love metadata update (#7124)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
parent
e34f59ca37
commit
e5f07b9134
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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 }))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user