UNPKG

camstreamerlib

Version:

Helper library for CamStreamer ACAP applications.

172 lines (171 loc) 5.75 kB
import { z } from 'zod'; import { toCamelCase, toCamelCaseDeep } from '../internal/transformers'; import { storageTypeSchema, keyboardShortcutsSchema, h264ProfileSchema, audioChannelCountSchema, keyboardShortcutSchema, } from './common'; const channelTypeSchema = z.union([z.literal('audio'), z.literal('video'), z.literal('av')]); const playlistPlayTypeSchema = z.union([ z.literal('PLAY_ALL'), z.literal('PLAY_ALL_LOOP'), z.literal('PLAY_ALL_SHUFFLED'), z.literal('PLAY_ALL_LOOP_SHUFFLED'), z.literal('PLAY_ONE_RANDOM'), ]); export const storageInfoListSchema = z.array(z.object({ storage: storageTypeSchema, writable: z.boolean(), size: z.number(), available: z.number(), })); export const outputInfoSchema = z .object({ rtsp_url: z.string(), ws: z.string(), ws_initial_message: z.string(), }) .transform(toCamelCase); export const audioPushInfoSchema = z .object({ ws: z.string(), ws_initial_message: z.string(), }) .transform(toCamelCase); const streamSaveSchema = z.object({ niceName: z.string(), ip: z.string(), mdnsName: z.string(), port: z.number(), enabled: z.boolean(), auth: z.string(), query: z.string(), channel: channelTypeSchema, keyboard: keyboardShortcutsSchema, sortIndexOverview: z.number().optional(), viewNumber: z.number(), }); export const streamSaveLoadSchema = z.record(z.string(), streamSaveSchema.partial()); export const clipSaveSchema = z.object({ niceName: z.string(), channel: channelTypeSchema, keyboard: keyboardShortcutsSchema, sortIndexOverview: z.number(), }); export const clipSaveLoadSchema = z.record(z.string(), clipSaveSchema.partial()); const playlistStreamSaveSchema = z .object({ stream_name: z.string(), clip_name: z.string(), tracker_name: z.string(), storage: storageTypeSchema, }) .partial(); const playlistSaveSchema = z.object({ channel: channelTypeSchema, isFavourite: z.boolean(), keyboard: keyboardShortcutsSchema, niceName: z.string(), sortIndexFavourite: z.number().optional(), sortIndexOverview: z.number().optional(), play_type: playlistPlayTypeSchema, default: z.boolean().optional(), stream_list: z.array(z.object({ id: z.string(), isTimeoutCustom: z.boolean(), ptz_preset_pos_name: z.string(), repeat: z.number(), timeout: z.number(), video: playlistStreamSaveSchema, audio: playlistStreamSaveSchema.optional(), })), }); export const playlistSaveLoadSchema = z.record(z.string(), playlistSaveSchema.partial()); export const trackerSaveSchema = z.object({ id: z.string(), name: z.string(), previewId: z.string(), duration: z.number(), keyboard: keyboardShortcutsSchema, channel: channelTypeSchema, sortIndexOverview: z.number(), width: z.number(), height: z.number(), fps: z.number(), motion_history_frames: z.number(), include_zone: z.array(z.array(z.number()).length(2)), include_node_ids: z.array(z.string()), camera_list: z.array(z.object({ id: z.string(), name: z.string(), overview: z.boolean(), zone: z.array(z.number()).length(4), playlist_name: z.string(), ptz_preset_pos_no: z.number(), })), viewNumber: z.number(), camera_view_number: z.number(), }); export const trackerSaveLoadSchema = z.record(z.string(), trackerSaveSchema.partial()); export const playlistQueueSchema = z .object({ playlist_queue_list: z.array(z.string()), }) .transform(toCamelCaseDeep); export const clipListSchema = z.object({ clip_list: z.record(z.string(), z.object({ storage: storageTypeSchema, duration: z.number(), stream_list: z.array(z.union([ z.object({ type: z.literal('video'), width: z.number(), height: z.number(), sample_rate: z.number(), h264_profile: h264ProfileSchema, h264_level: z.literal('4.1'), gop: z.number(), fps: z.number(), bitrate: z.number(), }), z.object({ type: z.literal('audio'), sample_rate: z.number(), channel_count: audioChannelCountSchema, }), ])), })), }); export const bitrateModeSchema = z.union([z.literal('VBR'), z.literal('MBR'), z.literal('ABR')]); export const bitrateVapixParamsSchema = z.object({ bitrateMode: bitrateModeSchema, maximumBitRate: z.number(), retentionTime: z.number(), bitRateLimit: z.number(), }); export const cameraOptionsSchema = bitrateVapixParamsSchema .extend({ resolution: z.string(), h264Profile: h264ProfileSchema, fps: z.number(), compression: z.number().min(0).max(100), govLength: z.number(), bitrateVapixParams: z.string().nullable(), audioSampleRate: z.number(), audioChannelCount: audioChannelCountSchema, keyboard: z.object({ fromSource: keyboardShortcutSchema, none: keyboardShortcutSchema, }), }) .partial(); export const globalAudioSettingsTypeSchema = z.union([z.literal('fromSource'), z.literal('source')]); export const globalAudioSettingsSchema = z.object({ type: globalAudioSettingsTypeSchema, source: z.string(), storage: z.string().optional(), }); export const secondaryAudioSettingsSchema = z.object({ type: z.union([z.literal('CLIP'), z.literal('STREAM'), z.literal('NONE')]), streamName: z.string().optional(), clipName: z.string().optional(), storage: storageTypeSchema, secondaryAudioLevel: z.number(), masterAudioLevel: z.number(), });