camstreamerlib 3.5.2 → 4.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/CamOverlayAPI.d.ts +11 -28
  2. package/CamOverlayAPI.js +116 -138
  3. package/CamOverlayDrawingAPI.js +26 -18
  4. package/CamOverlayPainter/Frame.js +167 -182
  5. package/CamOverlayPainter/Painter.js +80 -101
  6. package/CamOverlayPainter/ResourceManager.js +31 -46
  7. package/CamScripterAPI.d.ts +19 -0
  8. package/CamScripterAPI.js +66 -0
  9. package/CamScripterAPICameraEventsGenerator.js +22 -16
  10. package/CamStreamerAPI.d.ts +5 -27
  11. package/CamStreamerAPI.js +45 -71
  12. package/CamSwitcherAPI.d.ts +38 -71
  13. package/CamSwitcherAPI.js +329 -91
  14. package/CamSwitcherEvents.d.ts +15 -33
  15. package/CamSwitcherEvents.js +53 -97
  16. package/CreatePackage.js +5 -7
  17. package/README.md +3 -1
  18. package/VapixAPI.d.ts +66 -0
  19. package/VapixAPI.js +454 -0
  20. package/VapixEvents.js +18 -16
  21. package/errors/errors.d.ts +34 -0
  22. package/errors/errors.js +66 -0
  23. package/events/AxisCameraStationEvents.js +29 -42
  24. package/events/GenetecAgent.d.ts +14 -15
  25. package/events/GenetecAgent.js +81 -100
  26. package/internal/Digest.js +5 -11
  27. package/internal/ProxyClient.d.ts +11 -0
  28. package/internal/ProxyClient.js +40 -0
  29. package/internal/common.d.ts +19 -4
  30. package/internal/common.js +11 -26
  31. package/internal/constants.d.ts +1 -0
  32. package/internal/constants.js +1 -0
  33. package/internal/transformers.d.ts +5 -0
  34. package/internal/transformers.js +25 -0
  35. package/internal/utils.d.ts +11 -0
  36. package/internal/utils.js +34 -0
  37. package/internal/versionCompare.d.ts +6 -0
  38. package/internal/versionCompare.js +44 -0
  39. package/node/DefaultClient.d.ts +15 -0
  40. package/node/DefaultClient.js +50 -0
  41. package/{internal → node}/HttpRequestSender.d.ts +2 -2
  42. package/node/HttpRequestSender.js +85 -0
  43. package/{HttpServer.d.ts → node/HttpServer.d.ts} +1 -1
  44. package/{HttpServer.js → node/HttpServer.js} +22 -24
  45. package/{internal → node}/WsClient.d.ts +1 -1
  46. package/{internal → node}/WsClient.js +32 -39
  47. package/node/WsEventClient.d.ts +13 -0
  48. package/node/WsEventClient.js +18 -0
  49. package/package.json +7 -3
  50. package/types/CamOverlayAPI.d.ts +188 -0
  51. package/types/CamOverlayAPI.js +44 -0
  52. package/types/CamScripterAPI.d.ts +67 -0
  53. package/types/CamScripterAPI.js +17 -0
  54. package/types/CamStreamerAPI.d.ts +139 -0
  55. package/types/CamStreamerAPI.js +25 -0
  56. package/types/CamSwitcherAPI.d.ts +814 -0
  57. package/types/CamSwitcherAPI.js +134 -0
  58. package/types/CamswitcherEvents.d.ts +491 -0
  59. package/types/CamswitcherEvents.js +59 -0
  60. package/types/VapixAPI.d.ts +1704 -0
  61. package/types/VapixAPI.js +129 -0
  62. package/types/common.d.ts +37 -0
  63. package/types/common.js +11 -0
  64. package/web/DefaultClient.d.ts +6 -0
  65. package/web/DefaultClient.js +16 -0
  66. package/web/WsClient.d.ts +13 -0
  67. package/web/WsClient.js +58 -0
  68. package/CameraVapix.d.ts +0 -98
  69. package/CameraVapix.js +0 -441
  70. package/DefaultAgent.d.ts +0 -15
  71. package/DefaultAgent.js +0 -68
  72. package/internal/HttpRequestSender.js +0 -117
@@ -1,36 +1,18 @@
1
1
  /// <reference types="node" />
2
- import { HttpOptions, IClient } from './internal/common';
3
- export type CamOverlayOptions = HttpOptions;
4
- export type TField = {
5
- field_name: string;
6
- text: string;
7
- color?: string;
8
- };
9
- export type TService = Record<string, any>;
10
- export type TServiceList = {
11
- services: TService[];
12
- };
13
- export type TNetworkCameraList = {
14
- name: string;
15
- ip: string;
16
- }[];
17
- export type TImage = {
18
- name: string;
19
- path: string;
20
- storage: string;
21
- };
22
- export declare enum ImageType {
23
- PNG = 0,
24
- JPEG = 1
25
- }
26
- export type TCoordinates = 'top_left' | 'top_right' | 'top' | 'bottom_left' | 'bottom_right' | 'bottom' | 'left' | 'right' | 'center' | '';
2
+ import { IClient } from './internal/common';
3
+ import { CamOverlayOptions, ImageType, TCoordinates, TField, TFile, TFileList, TFileType, TService, TServiceList, TStorage } from './types/CamOverlayAPI';
4
+ import { TNetworkCamera } from './types/common';
27
5
  export declare class CamOverlayAPI {
28
6
  private client;
29
7
  constructor(options?: CamOverlayOptions | IClient);
30
8
  checkCameraTime(): Promise<boolean>;
31
- listImages(): Promise<TImage[]>;
32
- uploadImage(file: Buffer, fileName: string): Promise<void>;
33
- getNetworkCameraList(): Promise<TNetworkCameraList>;
9
+ getNetworkCameraList(): Promise<TNetworkCamera[]>;
10
+ wsAutoratization(): Promise<string>;
11
+ getMjpegStreamImage(mjpegUrl: string): Promise<Blob>;
12
+ listFiles(fileType: TFileType): Promise<TFileList>;
13
+ uploadFile(fileType: TFileType, file: Blob, fileName: string): Promise<void>;
14
+ removeFile(fileType: TFileType, file: TFile): Promise<void>;
15
+ getFileStorage(fileType: TFileType): Promise<TStorage>;
34
16
  updateInfoticker(serviceID: number, text: string): Promise<void>;
35
17
  setEnabled(serviceID: number, enabled: boolean): Promise<void>;
36
18
  isEnabled(serviceID: number): Promise<boolean>;
@@ -45,4 +27,5 @@ export declare class CamOverlayAPI {
45
27
  private promiseCGUpdate;
46
28
  private get;
47
29
  private post;
30
+ private parseBlobResponse;
48
31
  }
package/CamOverlayAPI.js CHANGED
@@ -1,122 +1,95 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.CamOverlayAPI = exports.ImageType = void 0;
13
- const common_1 = require("./internal/common");
14
- const DefaultAgent_1 = require("./DefaultAgent");
15
- var ImageType;
16
- (function (ImageType) {
17
- ImageType[ImageType["PNG"] = 0] = "PNG";
18
- ImageType[ImageType["JPEG"] = 1] = "JPEG";
19
- })(ImageType || (exports.ImageType = ImageType = {}));
20
- class CamOverlayAPI {
1
+ import { isClient, responseStringify } from './internal/common';
2
+ import { DefaultClient } from './node/DefaultClient';
3
+ import { fileListSchema, ImageType, serviceSchema, storageSchema, } from './types/CamOverlayAPI';
4
+ import { ParsingBlobError, ServiceNotFoundError } from './errors/errors';
5
+ import { networkCameraListSchema } from './types/common';
6
+ export class CamOverlayAPI {
7
+ client;
21
8
  constructor(options = {}) {
22
- if ((0, common_1.isClient)(options)) {
9
+ if (isClient(options)) {
23
10
  this.client = options;
24
11
  }
25
12
  else {
26
- this.client = new DefaultAgent_1.DefaultAgent(options);
13
+ this.client = new DefaultClient(options);
27
14
  }
28
15
  }
29
- checkCameraTime() {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- const cameraTime = yield this.get('/local/camoverlay/api/camera_time.cgi');
32
- return cameraTime.state;
33
- });
34
- }
35
- listImages() {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const images = yield this.get('/local/camoverlay/api/upload_image.cgi?action=list');
38
- return images.list;
39
- });
40
- }
41
- uploadImage(file, fileName) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const formData = new FormData();
44
- formData.append('target', 'SD0');
45
- formData.append('uploadedFile[]', file, fileName);
46
- const path = '/local/camoverlay/api/upload_image.cgi?action=upload';
47
- yield this.post(path, formData);
48
- });
49
- }
50
- getNetworkCameraList() {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const response = yield this.get('/local/camoverlay/api/network_camera_list.cgi');
53
- return response.camera_list;
54
- });
55
- }
56
- updateInfoticker(serviceID, text) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- const path = `/local/camoverlay/api/infoticker.cgi?service_id=${serviceID}&text=${text}`;
59
- const res = yield this.client.get(path);
60
- if (!res.ok) {
61
- throw new Error(yield (0, common_1.responseStringify)(res));
62
- }
63
- });
64
- }
65
- setEnabled(serviceID, enabled) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- const path = `/local/camoverlay/api/enabled.cgi?id_${serviceID}=${enabled ? 1 : 0}`;
68
- const res = yield this.client.post(path, '');
69
- if (!res.ok) {
70
- throw new Error(yield (0, common_1.responseStringify)(res));
71
- }
72
- });
73
- }
74
- isEnabled(serviceID) {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- const path = '/local/camoverlay/api/services.cgi?action=get';
77
- const res = yield this.client.get(path);
78
- if (res.ok) {
79
- const data = JSON.parse(yield res.text());
80
- for (const service of data.services) {
81
- if (service.id === serviceID) {
82
- return service.enabled === 1;
83
- }
16
+ async checkCameraTime() {
17
+ const cameraTime = await this.get('/local/camoverlay/api/camera_time.cgi');
18
+ return cameraTime.state;
19
+ }
20
+ async getNetworkCameraList() {
21
+ const response = await this.get('/local/camoverlay/api/network_camera_list.cgi');
22
+ return networkCameraListSchema.parse(response.camera_list);
23
+ }
24
+ async wsAutoratization() {
25
+ const response = await this.get(`/local/camoverlay/api/ws_authorization.cgi`);
26
+ return response.data;
27
+ }
28
+ async getMjpegStreamImage(mjpegUrl) {
29
+ const res = await this.get(`/local/camoverlay/api/fetch_mjpeg_image.cgi?mjpeg_url=${encodeURIComponent(decodeURIComponent(mjpegUrl))}`);
30
+ return await this.parseBlobResponse(res);
31
+ }
32
+ async listFiles(fileType) {
33
+ const files = await this.get(`/local/camoverlay/api/upload_${fileType}.cgi?action=list`);
34
+ return fileListSchema.parse(files.list);
35
+ }
36
+ async uploadFile(fileType, file, fileName) {
37
+ const formData = new FormData();
38
+ formData.append('target', 'SD0');
39
+ formData.append('uploadedFile[]', file, fileName);
40
+ const path = `/local/camoverlay/api/upload_${fileType}.cgi?action=upload`;
41
+ await this.post(path, formData);
42
+ }
43
+ async removeFile(fileType, file) {
44
+ const path = `/local/camoverlay/api/upload_${fileType}.cgi?action=remove`;
45
+ await this.post(path, JSON.stringify(file));
46
+ }
47
+ async getFileStorage(fileType) {
48
+ const data = await this.get(`/local/camoverlay/api/upload_${fileType}.cgi?action=get_storage`);
49
+ return storageSchema.parse(data);
50
+ }
51
+ async updateInfoticker(serviceID, text) {
52
+ await this.get(`/local/camoverlay/api/infoticker.cgi?service_id=${serviceID}&text=${text}`);
53
+ }
54
+ async setEnabled(serviceID, enabled) {
55
+ await this.post(`/local/camoverlay/api/enabled.cgi?id_${serviceID}=${enabled ? 1 : 0}`, '');
56
+ }
57
+ async isEnabled(serviceID) {
58
+ const res = await this.client.get('/local/camoverlay/api/services.cgi?action=get');
59
+ if (res.ok) {
60
+ const data = JSON.parse(await res.text());
61
+ for (const service of data.services) {
62
+ if (service.id === serviceID) {
63
+ return service.enabled === 1;
84
64
  }
85
- throw new Error('Service not found.');
86
65
  }
87
- else {
88
- throw new Error(yield (0, common_1.responseStringify)(res));
89
- }
90
- });
66
+ throw new ServiceNotFoundError();
67
+ }
68
+ else {
69
+ throw new Error(await responseStringify(res));
70
+ }
91
71
  }
92
- getSingleService(serviceId) {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- return this.get('/local/camoverlay/api/services.cgi', { action: 'get', service_id: serviceId.toString() });
72
+ async getSingleService(serviceId) {
73
+ const data = await this.get('/local/camoverlay/api/services.cgi', {
74
+ action: 'get',
75
+ service_id: serviceId.toString(),
95
76
  });
77
+ return serviceSchema.parse(data);
96
78
  }
97
- getServices() {
98
- return __awaiter(this, void 0, void 0, function* () {
99
- const serviceList = yield this.get('/local/camoverlay/api/services.cgi?action=get');
100
- return serviceList.services;
101
- });
79
+ async getServices() {
80
+ const serviceList = await this.get('/local/camoverlay/api/services.cgi?action=get');
81
+ return serviceSchema.parse(serviceList).services;
102
82
  }
103
- updateSingleService(serviceId, serviceJson) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- const path = '/local/camoverlay/api/services.cgi';
106
- yield this.post(path, JSON.stringify(serviceJson), {
107
- action: 'set',
108
- service_id: serviceId.toString(),
109
- });
83
+ async updateSingleService(serviceId, serviceJson) {
84
+ const path = '/local/camoverlay/api/services.cgi';
85
+ await this.post(path, JSON.stringify(serviceJson), {
86
+ action: 'set',
87
+ service_id: serviceId.toString(),
110
88
  });
111
89
  }
112
- updateServices(servicesJson) {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- const path = '/local/camoverlay/api/services.cgi?action=set';
115
- const res = yield this.client.post(path, JSON.stringify(servicesJson));
116
- if (!res.ok) {
117
- throw new Error(yield (0, common_1.responseStringify)(res));
118
- }
119
- });
90
+ async updateServices(servicesJson) {
91
+ const path = '/local/camoverlay/api/services.cgi?action=set';
92
+ await this.post(path, JSON.stringify(servicesJson));
120
93
  }
121
94
  updateCGText(serviceID, fields) {
122
95
  const params = {};
@@ -155,40 +128,45 @@ class CamOverlayAPI {
155
128
  };
156
129
  return this.promiseCGUpdate(serviceID, 'update_image', params, contentType, imageData);
157
130
  }
158
- promiseCGUpdate(serviceID, action, params = {}, contentType, data) {
159
- return __awaiter(this, void 0, void 0, function* () {
160
- const path = `/local/camoverlay/api/customGraphics.cgi`;
161
- let headers = {};
162
- if (contentType !== undefined && data) {
163
- headers = { 'Content-Type': contentType };
164
- }
165
- const res = yield this.client.post(path, data !== null && data !== void 0 ? data : '', Object.assign({ action: action, service_id: serviceID.toString() }, params), headers);
166
- if (!res.ok) {
167
- throw new Error(yield (0, common_1.responseStringify)(res));
168
- }
169
- });
131
+ async promiseCGUpdate(serviceID, action, params = {}, contentType, data) {
132
+ const path = `/local/camoverlay/api/customGraphics.cgi`;
133
+ let headers = {};
134
+ if (contentType !== undefined && data) {
135
+ headers = { 'Content-Type': contentType };
136
+ }
137
+ const res = await this.client.post(path, data ?? '', {
138
+ action: action,
139
+ service_id: serviceID.toString(),
140
+ ...params,
141
+ }, headers);
142
+ if (!res.ok) {
143
+ throw new Error(await responseStringify(res));
144
+ }
170
145
  }
171
- get(path, params) {
172
- return __awaiter(this, void 0, void 0, function* () {
173
- const res = yield this.client.get(path, params);
174
- if (res.ok) {
175
- return yield res.json();
176
- }
177
- else {
178
- throw new Error(yield (0, common_1.responseStringify)(res));
179
- }
180
- });
146
+ async get(path, params) {
147
+ const res = await this.client.get(path, params);
148
+ if (res.ok) {
149
+ return await res.json();
150
+ }
151
+ else {
152
+ throw new Error(await responseStringify(res));
153
+ }
181
154
  }
182
- post(path, data, params) {
183
- return __awaiter(this, void 0, void 0, function* () {
184
- const res = yield this.client.post(path, data, params);
185
- if (res.ok) {
186
- return yield res.json();
187
- }
188
- else {
189
- throw new Error(yield (0, common_1.responseStringify)(res));
190
- }
191
- });
155
+ async post(path, data, params) {
156
+ const res = await this.client.post(path, data, params);
157
+ if (res.ok) {
158
+ return await res.json();
159
+ }
160
+ else {
161
+ throw new Error(await responseStringify(res));
162
+ }
163
+ }
164
+ async parseBlobResponse(response) {
165
+ try {
166
+ return await response.blob();
167
+ }
168
+ catch (err) {
169
+ throw new ParsingBlobError(err);
170
+ }
192
171
  }
193
172
  }
194
- exports.CamOverlayAPI = CamOverlayAPI;
@@ -1,24 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CamOverlayDrawingAPI = void 0;
4
- const EventEmitter = require("events");
5
- const WsClient_1 = require("./internal/WsClient");
6
- class CamOverlayDrawingAPI extends EventEmitter {
1
+ import * as EventEmitter from 'events';
2
+ import { WsClient } from './node/WsClient';
3
+ export class CamOverlayDrawingAPI extends EventEmitter {
4
+ tls;
5
+ tlsInsecure;
6
+ ip;
7
+ port;
8
+ user;
9
+ pass;
10
+ cameraList;
11
+ zIndex;
12
+ callId;
13
+ sendMessages;
14
+ timeoutCheckTimer;
15
+ wsConnected;
16
+ ws;
7
17
  constructor(options) {
8
- var _a, _b, _c, _d, _e, _f, _g;
9
18
  super();
10
- this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
11
- this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
12
- this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
13
- this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : (this.tls ? 443 : 80);
14
- this.user = (_e = options === null || options === void 0 ? void 0 : options.user) !== null && _e !== void 0 ? _e : '';
15
- this.pass = (_f = options === null || options === void 0 ? void 0 : options.pass) !== null && _f !== void 0 ? _f : '';
16
- this.zIndex = (_g = options === null || options === void 0 ? void 0 : options.zIndex) !== null && _g !== void 0 ? _g : 0;
19
+ this.tls = options?.tls ?? false;
20
+ this.tlsInsecure = options?.tlsInsecure ?? false;
21
+ this.ip = options?.ip ?? '127.0.0.1';
22
+ this.port = options?.port ?? (this.tls ? 443 : 80);
23
+ this.user = options?.user ?? '';
24
+ this.pass = options?.pass ?? '';
25
+ this.zIndex = options?.zIndex ?? 0;
17
26
  this.cameraList = [0];
18
27
  if (options && Array.isArray(options.camera)) {
19
28
  this.cameraList = options.camera;
20
29
  }
21
- else if (typeof (options === null || options === void 0 ? void 0 : options.camera) === 'number') {
30
+ else if (typeof options?.camera === 'number') {
22
31
  this.cameraList = [options.camera];
23
32
  }
24
33
  this.callId = 0;
@@ -88,7 +97,7 @@ class CamOverlayDrawingAPI extends EventEmitter {
88
97
  tls: this.tls,
89
98
  tlsInsecure: this.tlsInsecure,
90
99
  };
91
- this.ws = new WsClient_1.WsClient(options);
100
+ this.ws = new WsClient(options);
92
101
  this.ws.on('open', () => {
93
102
  console.log('CamOverlay connection opened');
94
103
  this.wsConnected = true;
@@ -110,7 +119,7 @@ class CamOverlayDrawingAPI extends EventEmitter {
110
119
  if ('error' in dataJSON) {
111
120
  errorResponse = dataJSON;
112
121
  }
113
- if (dataJSON.call_id !== undefined && this.sendMessages[dataJSON.call_id] !== undefined) {
122
+ if (dataJSON.call_id !== undefined) {
114
123
  if (errorResponse !== undefined) {
115
124
  this.sendMessages[dataJSON.call_id].reject(new Error(errorResponse.error));
116
125
  }
@@ -217,4 +226,3 @@ class CamOverlayDrawingAPI extends EventEmitter {
217
226
  this.emit('close');
218
227
  }
219
228
  }
220
- exports.CamOverlayDrawingAPI = CamOverlayDrawingAPI;