UNPKG

camstreamerlib

Version:

Helper library for CamStreamer ACAP applications.

88 lines (87 loc) 4.07 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CamStreamerAPI = void 0; const common_1 = require("./internal/common"); const DefaultAgent_1 = require("./DefaultAgent"); class CamStreamerAPI { constructor(options = {}) { if ((0, common_1.isClient)(options)) { this.client = options; } else { this.client = new DefaultAgent_1.DefaultAgent(options); } } getStreamList() { return __awaiter(this, void 0, void 0, function* () { const streamListRes = yield this.get('/local/camstreamer/stream/list.cgi'); return streamListRes.data; }); } getStream(streamID) { return __awaiter(this, void 0, void 0, function* () { const stream = yield this.get(`/local/camstreamer/stream/get.cgi?stream_id=${streamID}`); return stream.data; }); } getStreamParameter(streamID, paramName) { return __awaiter(this, void 0, void 0, function* () { const stream = yield this.get(`/local/camstreamer/stream/get.cgi?stream_id=${streamID}`); return stream.data[paramName]; }); } setStream(streamID, params) { return __awaiter(this, void 0, void 0, function* () { const { streamDelay, startTime, stopTime } = params, rest = __rest(params, ["streamDelay", "startTime", "stopTime"]); yield this.get('/local/camstreamer/stream/set.cgi', Object.assign({ stream_id: streamID, streamDelay: streamDelay !== null && streamDelay !== void 0 ? streamDelay : '', startTime: startTime !== null && startTime !== void 0 ? startTime : 'null', stopTime: stopTime !== null && stopTime !== void 0 ? stopTime : 'null' }, rest)); }); } setStreamParameter(streamID, paramName, value) { return __awaiter(this, void 0, void 0, function* () { yield this.get(`/local/camstreamer/stream/set.cgi?stream_id=${streamID}&${paramName}=${value}`); }); } isStreaming(streamID) { return __awaiter(this, void 0, void 0, function* () { const response = yield this.get(`/local/camstreamer/get_streamstat.cgi?stream_id=${streamID}`); return response.data.is_streaming === 1; }); } deleteStream(streamID) { return __awaiter(this, void 0, void 0, function* () { yield this.get('/local/camstreamer/stream/remove.cgi', { stream_id: streamID }); }); } get(path, parameters) { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.get(path, parameters); if (res.ok) { return yield res.json(); } else { throw new Error(yield (0, common_1.responseStringify)(res)); } }); } } exports.CamStreamerAPI = CamStreamerAPI;