UNPKG

camstreamerlib

Version:

Helper library for CamStreamer ACAP applications.

56 lines (55 loc) 2.13 kB
import { responseStringify } from './internal/utils'; import { streamAttributesSchema, streamListSchema } from './types/CamStreamerAPI'; export class CamStreamerAPI { client; constructor(client) { this.client = client; } async getStreamList() { const streamListRes = await this.get('/local/camstreamer/stream/list.cgi'); return streamListSchema.parse(streamListRes.data); } async getStream(streamID) { const stream = await this.get(`/local/camstreamer/stream/get.cgi?stream_id=${streamID}`); return streamAttributesSchema.parse(stream.data); } async getStreamParameter(streamID, paramName) { const stream = await this.get(`/local/camstreamer/stream/get.cgi?stream_id=${streamID}`); return stream.data[paramName]; } async setStream(streamID, params) { const { streamDelay, startTime, stopTime, ...rest } = params; await this.get('/local/camstreamer/stream/set.cgi', { stream_id: streamID, streamDelay: streamDelay ?? '', startTime: startTime ?? 'null', stopTime: stopTime ?? 'null', ...rest, }); } async setStreamParameter(streamID, paramName, value) { await this.get(`/local/camstreamer/stream/set.cgi?stream_id=${streamID}&${paramName}=${value}`); } async isStreaming(streamID) { const response = await this.get(`/local/camstreamer/get_streamstat.cgi?stream_id=${streamID}`); return response.data.is_streaming === 1; } async deleteStream(streamID) { await this.get('/local/camstreamer/stream/remove.cgi', { stream_id: streamID }); } wsAutoratization() { return this.get('/local/camstreamer/ws_authorization.cgi'); } async getUtcTime() { return await this.get('/local/camstreamer/get_utc_time.cgi'); } async get(path, parameters) { const res = await this.client.get(path, parameters); if (res.ok) { return await res.json(); } else { throw new Error(await responseStringify(res)); } } }