UNPKG

fcr-core

Version:

Core APIs for building online scenes

30 lines 1.08 kB
import { FcrPlatform, FcrUserStringToRoleMap } from '../type'; import { FcrPrivilegeUserRoleToStringMap, FcrPrivilegeUserStringToRoleMap } from '../room-control/privilege-control/type'; export const convertRteUserToFcrUser = (user, cache) => { const userRole = FcrUserStringToRoleMap[user.userRole]; if (!userRole) { return undefined; } let platform = cache.getUserPlatform(user.userId) ?? FcrPlatform.UNSUPPORTED; const avatar = cache.getUserAvatar(user.userId) ?? ''; const isValidPlatform = platform in FcrPlatform; platform = isValidPlatform ? platform : FcrPlatform.UNSUPPORTED; return { userId: user.userId, userName: user.userName, connectorType: user.connectorType, platform, userRole, avatar }; }; export const checkFcrUserRole = user => { if (!user?.userRole) return; return user; }; export const convertStringPrivilegeRoleToFcrPrivilegeRole = role => { return FcrPrivilegeUserStringToRoleMap[role]; }; export const convertFcrPrivilegeRoleToStringPrivilegeRole = role => { return FcrPrivilegeUserRoleToStringMap[role]; };