camstreamerlib
Version:
Helper library for CamStreamer ACAP applications.
113 lines (112 loc) • 4.53 kB
JavaScript
"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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CamSwitcherAPI = void 0;
const DefaultAgent_1 = require("./DefaultAgent");
const common_1 = require("./internal/common");
const cgiNames = {
camera: 'streams',
audio: 'audios',
playlist: 'playlists',
clip: 'clips',
tracker: 'trackers',
};
class CamSwitcherAPI {
constructor(options = {}) {
if ((0, common_1.isClient)(options)) {
this.client = options;
}
else {
this.client = new DefaultAgent_1.DefaultAgent(options);
}
}
generateSilence(sampleRate, channels) {
return this.get('/local/camswitcher/generate_silence.cgi', { sample_rate: sampleRate.toString(), channels });
}
getIpListFromNetworkCheck() {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.get('/local/camswitcher/network_camera_list.cgi')).data;
});
}
getMaxFps(source) {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.get('/local/camswitcher/get_max_framerate.cgi', { video_source: source.toString() })).data;
});
}
getStorageInfo() {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.get('/local/camswitcher/get_storage.cgi')).data;
});
}
getOutputInfo() {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.get('/local/camswitcher/output_info.cgi')).data;
});
}
getPlaylistList() {
return this.get('/local/camswitcher/playlists.cgi?action=get');
}
playlistSwitch(playlistName) {
return __awaiter(this, void 0, void 0, function* () {
yield this.get(`/local/camswitcher/playlist_switch.cgi?playlist_name=${playlistName}`);
});
}
playlistQueuePush(playlistName) {
return __awaiter(this, void 0, void 0, function* () {
yield this.get(`/local/camswitcher/playlist_queue_push.cgi?playlist_name=${playlistName}`);
});
}
playlistQueueClear() {
return __awaiter(this, void 0, void 0, function* () {
yield this.get('/local/camswitcher/playlist_queue_clear.cgi');
});
}
playlistQueueList() {
return this.get('/local/camswitcher/playlist_queue_list.cgi');
}
playlistQueuePlayNext() {
return __awaiter(this, void 0, void 0, function* () {
yield this.get('/local/camswitcher/playlist_queue_play_next.cgi');
});
}
getClipList() {
return this.get('/local/camswitcher/clips.cgi?action=get');
}
addNewClip(file, clipType, storage, id, fileName) {
return __awaiter(this, void 0, void 0, function* () {
const formData = new FormData();
formData.append('clip_name', id);
formData.append('clip_type', clipType);
formData.append('file', file, fileName);
const path = `/local/camswitcher/clip_upload.cgi?storage=${storage}`;
const res = yield this.client.post(path, formData);
const output = (yield res.json());
if (output.status !== 200) {
throw new Error('Error on camera: ' + output.message);
}
});
}
removeClip(id, storage) {
return this.get(`/local/camswitcher/clip_remove.cgi`, { clip_name: id, storage });
}
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.CamSwitcherAPI = CamSwitcherAPI;