UNPKG

camstreamerlib

Version:

Helper library for CamStreamer ACAP applications.

200 lines (199 loc) 6.54 kB
import { boolean, z } from 'zod'; import { facebookSchema } from './facebookSchema'; import { windySchema } from './windySchema'; import { youtubeSchema } from './youtubeSchema'; import { daCastSchema, dailymotionSchema, facebookRtmpSchema, gameChangerSchema, hlsPullSchema, hlsPushSchema, ibmSchema, microsoftAzureSchema, microsoftStreamSchema, mpegDvbSchema, rtmpSchema, sdCardSchema, srtSchema, streamPlatforms, twitchSchema, vimeoSchema, wowzaSchema, youtubeRtmpSchema, } from './streamsSchema'; import { fileSchema } from '../common'; export const streamSchema = z.discriminatedUnion('platform', [ facebookSchema, facebookRtmpSchema, mpegDvbSchema, rtmpSchema, sdCardSchema, windySchema, youtubeSchema, vimeoSchema, twitchSchema, srtSchema, daCastSchema, hlsPullSchema, hlsPushSchema, wowzaSchema, dailymotionSchema, ibmSchema, microsoftAzureSchema, microsoftStreamSchema, gameChangerSchema, youtubeRtmpSchema, ]); export const streamListSchema = z.object({ streamList: z.array(streamSchema) }); export const isFacebookStream = (stream) => { return stream.platform === streamPlatforms.facebook; }; export const isFacebookRtmpStream = (stream) => { return stream.platform === streamPlatforms.facebook_rtmp; }; export const isMpegDvbStream = (stream) => { return stream.platform === streamPlatforms.mpeg_dvb; }; export const isRtmpStream = (stream) => { return stream.platform === streamPlatforms.rtmp; }; export const isSdCardStream = (stream) => { return stream.platform === streamPlatforms.sd_card; }; export const isWindyStream = (stream) => { return stream.platform === streamPlatforms.windy; }; export const isYouTubeStream = (stream) => { return stream.platform === streamPlatforms.youtube; }; export const isVimeoStream = (stream) => { return stream.platform === streamPlatforms.vimeo; }; export const isTwitchStream = (stream) => { return stream.platform === streamPlatforms.twitch; }; export const isSrtStream = (stream) => { return stream.platform === streamPlatforms.srt; }; export const isDaCastStream = (stream) => { return stream.platform === streamPlatforms.da_cast; }; export const isHlsPullStream = (stream) => { return stream.platform === streamPlatforms.hls_pull; }; export const isHlsPushStream = (stream) => { return stream.platform === streamPlatforms.hls_push; }; export const isWowzaStream = (stream) => { return stream.platform === streamPlatforms.wowza; }; export const isDailymotionStream = (stream) => { return stream.platform === streamPlatforms.dailymotion; }; export const isIbmStream = (stream) => { return stream.platform === streamPlatforms.ibm; }; export const isMicrosoftAzureStream = (stream) => { return stream.platform === streamPlatforms.microsoft_azure; }; export const isMicrosoftStream = (stream) => { return stream.platform === streamPlatforms.microsoft_stream; }; export const isGameChangerStream = (stream) => { return stream.platform === streamPlatforms.game_changer; }; export const isYoutubeRtmpStream = (stream) => { return stream.platform === streamPlatforms.youtube_rtmp; }; export var AudioType; (function (AudioType) { AudioType[AudioType["MP3"] = 0] = "MP3"; AudioType[AudioType["AAC"] = 1] = "AAC"; })(AudioType || (AudioType = {})); export const audioFileStorageTypeSchema = z.union([z.literal('flash'), z.literal('SD0'), z.literal('url')]); export const storageListSchema = z.array(z.discriminatedUnion('type', [ z.object({ type: z.literal('flash'), flash: z.string(), }), z.object({ type: z.literal('SD0'), SD0: z.string(), }), ])); export const audioFileSchema = z.object({ name: z.string(), path: z.string(), storage: audioFileStorageTypeSchema, }); export const audioFileListSchema = z.array(audioFileSchema); export const audioUrlSchema = z.object({ fileUrl: z.string(), name: z.string(), storage: z.literal('url'), }); export const audioLocalSchema = z.object({ file: fileSchema, name: z.string(), storage: z.enum(['flash', 'SD0']), }); export const streamStatsSchema = z.object({ net_stats: z.string(), stream_bytes_time_ms: z.number().nonnegative(), stream_bytes: z.number().nonnegative(), start_count: z.number().nonnegative(), is_streaming: z.literal(0).or(z.literal(1)), }); export const srtStreamStatisticsSchema = z.object({ msTimeStamp: z.number().nonnegative(), pktSentTotal: z.number().nonnegative(), byteSentTotal: z.number().nonnegative(), pktRetransTotal: z.number().nonnegative(), byteRetransTotal: z.number().nonnegative(), pktSndDropTotal: z.number().nonnegative(), byteSndDropTotal: z.number().nonnegative(), mbpsSendRate: z.number().nonnegative(), mbpsBandwidth: z.number().nonnegative(), mbpsMaxBW: z.number().nonnegative(), msRTT: z.number().nonnegative(), msSndBuf: z.number().nonnegative(), }); export const diagnosticsParamsSchema = z.object({ camerainfo: boolean().optional(), checkserver: boolean().optional(), checkservertime: boolean().optional(), speedtest: boolean().optional(), pingtest: boolean().optional(), videoHostPort: z.string().optional(), audioHostPort: z.string().optional(), }); export const diagnosticsSchema = z.object({ status: z.number(), message: z.string(), data: z.object({ audioHostPort: z .object({ code: z.number(), message: z.string(), }) .optional(), cameraInfo: z .object({ uptime: z.string(), availableRAM: z.number(), availableInternal: z.number(), }) .optional(), checkServer: z .object({ state: z.string(), message: z.string(), }) .optional(), checkServerTime: z .object({ code: z.number(), message: z.string(), }) .optional(), videoHostPort: z .object({ code: z.number(), message: z.string(), }) .optional(), speedTest: z .object({ code: z.string(), data: z.array(z.object({ timestamp: z.number(), speed: z.number() })), }) .optional(), pingTest: z .object({ output: z.string(), }) .optional(), }), });