UNPKG

fcr-core

Version:

Core APIs for building online scenes

232 lines (230 loc) 10.6 kB
import "core-js/modules/esnext.iterator.constructor.js"; import "core-js/modules/esnext.iterator.some.js"; import { FcrLanguage } from './room-control/interpreter-control/types'; import { FcrPermissionAction, FcrPrivilegeUserRole, FcrSecurityAction } from './room-control/privilege-control/type'; import { FcrIPConnectorSessionType } from './room-control/room-connector-control/type'; import { FcrUserKickedOutType, FcrUserRole } from './room-control/user-control/type'; import { FcrBoardToolType } from './room-control/whiteboard-control-v2/enum'; import { FcrChatRoomMessageType } from './room-control/chatroom-control/type'; import { AgoraRtcAudioSourceType, AgoraRtcCapability, AgoraRtcEncryptionMode, AgoraRtcLatencyLevelType, AgoraRtcMediaSourceState, AgoraRtcRenderMode, AgoraRtcVideoStreamType, AgoraRteMediaStreamType, AgoraRteVideoSourceType, anySchema, booleanSchema, createRecordSchemaWithKey, numberSchema, stringSchema, unknownSchema, createUnionSchema, createArraySchema, z, objectSchema, AgoraRteStreamPrivilegeOperation, AgoraRteStreamPrivilegeAudioSourceType, AgoraRteStreamPrivilegeVideoSourceType, FcrScreenScenarioType } from './imports'; import { FcrDeviceType } from './media-control/type'; import { FcrLineType } from './room-control/type'; export { anySchema, booleanSchema, createRecordSchemaWithKey, numberSchema, stringSchema, unknownSchema, fcrRenderViewSchema, createUnionSchema, createArraySchema, z } from './imports'; export const stringOrObjectSchema = createUnionSchema([stringSchema, objectSchema]); export const stringArraySchema = createArraySchema(stringSchema); export const unknownArraySchema = createArraySchema(unknownSchema); export const stringKeyUnknownValueSchema = createRecordSchemaWithKey(stringSchema, unknownSchema); export const stringKeyNumberValueSchema = createRecordSchemaWithKey(stringSchema, numberSchema); export const fcrStreamPrivilegeOperation = z.nativeEnum(AgoraRteStreamPrivilegeOperation); export const fcrSecurityActionSchema = z.nativeEnum(FcrSecurityAction); export const fcrPermissionActionSchema = z.nativeEnum(FcrPermissionAction); export const fcrPrivilegeUserRoleSchema = z.nativeEnum(FcrPrivilegeUserRole); export const fcrLineTypeSchema = z.nativeEnum(FcrLineType); export const fcrUserRoleSchema = z.nativeEnum(FcrUserRole); export const fcrUserKickedOutTypeSchema = z.nativeEnum(FcrUserKickedOutType); export const fcrBoardToolTypeSchema = z.nativeEnum(FcrBoardToolType); export const fcrLanguageSchema = z.nativeEnum(FcrLanguage); export const fcrIPConnectorSessionTypeSchema = z.nativeEnum(FcrIPConnectorSessionType); export const fcrDeviceTypeSchema = z.nativeEnum(FcrDeviceType); export const fcrChatRoomMessageTypeSchema = z.nativeEnum(FcrChatRoomMessageType); // Native Enum Schemas export const fcrMediaStreamTypeSchema = z.nativeEnum(AgoraRteMediaStreamType); export const fcrVideoSourceTypeSchema = z.nativeEnum(AgoraRteVideoSourceType); export const fcrMediaSourceStateSchema = z.nativeEnum(AgoraRtcMediaSourceState); export const fcrCapabilitySchema = z.nativeEnum(AgoraRtcCapability); export const fcrRenderModeSchema = z.nativeEnum(AgoraRtcRenderMode); export const fcrEncryptionModeSchema = z.nativeEnum(AgoraRtcEncryptionMode); export const fcrLatencyLevelTypeSchema = z.nativeEnum(AgoraRtcLatencyLevelType); export const fcrAudioSourceTypeSchema = z.nativeEnum(AgoraRtcAudioSourceType); export const fcrVideoStreamTypeSchema = z.nativeEnum(AgoraRtcVideoStreamType); export const fcrStreamPrivilegeAudioSourceTypeSchema = z.nativeEnum(AgoraRteStreamPrivilegeAudioSourceType); export const fcrScreenScenarioTypeSchema = z.nativeEnum(FcrScreenScenarioType); export const fcrStreamPrivilegeVideoSourceTypeSchema = z.nativeEnum(AgoraRteStreamPrivilegeVideoSourceType); // Array Schemas export const fcrUserRolesSchema = z.array(fcrUserRoleSchema); export const fcrPrivilegeUserRoleArraySchema = z.array(fcrPrivilegeUserRoleSchema); // Object Schemas export const fcrLanguageConfigSchema = z.object({ sourceLanguage: fcrLanguageSchema, targetLanguage: fcrLanguageSchema.optional() }); export const fcrSessionBaseSchema = z.object({ sessionId: stringSchema, sessionKey: stringSchema, timestamp: numberSchema, duration: numberSchema, payload: stringKeyUnknownValueSchema, senderId: stringSchema, interval: numberSchema }); export const fcrInterpreterUsersParamsSchema = z.object({ userId: stringSchema, sourceLanguage: fcrLanguageSchema, targetLanguage: fcrLanguageSchema }); export const fcrSecurityPrivateChatConfigSchema = z.object({ host: booleanSchema, cohost: booleanSchema, participant: booleanSchema }); export const fcrSecuritySendChatPayloadSchema = z.object({ public: booleanSchema, private: fcrSecurityPrivateChatConfigSchema }); export const fcrPhoneConnectorSessionParamsSchema = z.object({ phoneNumber: stringSchema, userName: stringSchema, phoneUserId: stringSchema.optional() }); export const fcrIPConnectorSessionParamsSchema = z.object({ address: stringSchema, type: fcrIPConnectorSessionTypeSchema }); export const fcrRoomSessionParamsSchema = z.object({ sessionKey: stringSchema, duration: numberSchema, payload: stringKeyUnknownValueSchema }); export const colorSchema = z.object({ r: numberSchema, g: numberSchema, b: numberSchema, a: numberSchema.optional() }); export const fcrPeerSessionParamsSchema = z.object({ sessionKey: stringSchema, receiverId: stringSchema, duration: numberSchema, payload: stringKeyUnknownValueSchema }); export const fcrGroupCreateConfigSchema = z.object({ groupName: stringSchema, userList: stringArraySchema }); // Chat Room Schemas export const fcrChatRoomSendBaseMessageSchema = z.object({ type: fcrChatRoomMessageTypeSchema, properties: stringKeyUnknownValueSchema.optional(), to: stringArraySchema.optional() }); export const fcrChatRoomSendTextMessageSchema = z.object({ content: stringSchema }).merge(fcrChatRoomSendBaseMessageSchema); export const fcrChatRoomFileSchema = z.object({ fileName: stringSchema, fileType: stringSchema, filePath: stringSchema.optional(), data: anySchema.optional() }); export const fcrChatRoomSendImageMessageSchema = z.object({ file: fcrChatRoomFileSchema }).merge(fcrChatRoomSendBaseMessageSchema); export const messageSchema = z.union([fcrChatRoomSendTextMessageSchema, fcrChatRoomSendImageMessageSchema]); export const progressSchema = z.function().args(z.number()) // 定义参数类型 .returns(z.void()) // 定义返回值类型 .describe('A callback function that takes a progress and returns void'); // RTC Schemas export const agoraRtcEncryptionConfig = z.object({ encryptionKey: stringSchema, encryptionMode: fcrEncryptionModeSchema }); export const AgoraRtcDimensions = z.object({ width: numberSchema, height: numberSchema }); export const agoraRtcVideoEncoderConfigurationSchema = z.object({ dimensions: AgoraRtcDimensions, frameRate: numberSchema, bitrate: numberSchema, isMirror: booleanSchema }); // Stream Config Schemas export const fcrStreamJoinConfig = z.object({ videoEncoderConfig: agoraRtcVideoEncoderConfigurationSchema.optional(), videoSourceId: stringSchema.optional(), audioSourceId: stringSchema.optional(), streamName: stringSchema.optional(), streamType: fcrMediaStreamTypeSchema, videoSourceType: fcrVideoSourceTypeSchema, audioSourceType: fcrAudioSourceTypeSchema, audioSourceState: fcrMediaSourceStateSchema.optional(), videoSourceState: fcrMediaSourceStateSchema.optional() }); export const fcrRoomJoinOptionsSchema = z.object({ userName: stringSchema, userRole: fcrUserRoleSchema, userProperties: stringKeyUnknownValueSchema.optional(), roomToken: stringSchema, streamLatency: fcrLatencyLevelTypeSchema, streamEncryptionConfig: agoraRtcEncryptionConfig.optional(), createStreamConfigs: z.array(fcrStreamJoinConfig), password: stringSchema.optional(), platform: numberSchema.optional(), avatar: stringSchema.optional() }); // Other Schemas export const fcrRenderConfigSchema = z.object({ renderMode: fcrRenderModeSchema, isMirror: booleanSchema }); export const fcrGroupUpdateOptionsSchema = z.object({ groupId: stringSchema, groupName: stringSchema }); export const fcrRoomJoinOptionsWithTicketSchema = z.object({ ticket: stringSchema.optional() }).merge(fcrRoomJoinOptionsSchema); export const fcrMediaStreamCreateConfigSchema = z.object({ streamName: stringSchema, streamType: fcrMediaStreamTypeSchema, videoSourceType: fcrVideoSourceTypeSchema, audioSourceType: fcrAudioSourceTypeSchema, ownerId: stringSchema, videoSourceId: stringSchema, audioSourceId: stringSchema, generateToken: booleanSchema.optional() }); export const fcrStreamBindConfigSchema = z.object({ streamId: stringSchema, videoSourceId: stringSchema.optional(), audioSourceId: stringSchema.optional() }); // Array Collection Schemas export const fcrScreenStreamCreateConfigSchema = z.object({ streamType: fcrMediaStreamTypeSchema, audioDeviceName: stringSchema.optional(), videoSourceId: stringSchema.optional(), audioSourceId: stringSchema.optional() }); export const fcrScreenStreamCreateConfigSize = z.object({ width: numberSchema, height: numberSchema }); export const fcrSizeSchema = z.object({ width: numberSchema, height: numberSchema }).optional(); export const fcrGroupCreateConfigArraySchema = z.array(fcrGroupCreateConfigSchema); export const fcrGroupUpdateOptionsArraySchema = z.array(fcrGroupUpdateOptionsSchema); export const fcrLocalStreamCreateArrayConfigSchema = z.array(fcrMediaStreamCreateConfigSchema); export const fcrInterpreterUsersParamsArraySchema = z.array(fcrInterpreterUsersParamsSchema); export const fcrStreamBindConfigArrySchema = z.array(fcrStreamBindConfigSchema); export const fcrUpdateStreamPrivilegeScopeSchema = z.object({ videoSourceType: fcrStreamPrivilegeVideoSourceTypeSchema.optional(), audioSourceType: fcrStreamPrivilegeAudioSourceTypeSchema.optional(), targetRoleType: z.array(fcrUserRoleSchema), targetRoleTypeIsInclude: booleanSchema }); export const fcrUpdateStreamCustomSchema = z.custom(obj => { const hasBothInSelf = Object.keys(obj).includes('videoPrivilege') && Object.keys(obj).includes('audioPrivilege'); if (hasBothInSelf) { return true; } return Object.values(obj).some(value => { if (typeof value === 'object' && value !== null && !Array.isArray(value)) { return Object.keys(value).includes('videoPrivilege') && Object.keys(value).includes('audioPrivilege'); } return false; }); }); export const fcrMobileDeviceIdOrNameSchema = z.string().optional();