UNPKG

camstreamerlib

Version:

Helper library for CamStreamer ACAP applications.

60 lines (59 loc) 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CamStreamerAPI = void 0; const utils_1 = require("./internal/utils"); const CamStreamerAPI_1 = require("./types/CamStreamerAPI"); class CamStreamerAPI { client; constructor(client) { this.client = client; } async getStreamList() { const streamListRes = await this.get('/local/camstreamer/stream/list.cgi'); return CamStreamerAPI_1.streamListSchema.parse(streamListRes.data); } async getStream(streamID) { const stream = await this.get(`/local/camstreamer/stream/get.cgi?stream_id=${streamID}`); return CamStreamerAPI_1.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 (0, utils_1.responseStringify)(res)); } } } exports.CamStreamerAPI = CamStreamerAPI;