camstreamerlib 3.0.0 → 3.2.0

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.
@@ -1,5 +1,6 @@
1
- import { Options } from './internal/common';
2
- export type CamOverlayOptions = Options;
1
+ /// <reference types="node" />
2
+ import { HttpOptions, IClient } from './internal/common';
3
+ export type CamOverlayOptions = HttpOptions;
3
4
  export type TField = {
4
5
  field_name: string;
5
6
  text: string;
@@ -21,13 +22,8 @@ export declare enum ImageType {
21
22
  JPEG = 1
22
23
  }
23
24
  export declare class CamOverlayAPI {
24
- private tls;
25
- private tlsInsecure;
26
- private ip;
27
- private port;
28
- private user;
29
- private pass;
30
- constructor(options?: CamOverlayOptions);
25
+ private client;
26
+ constructor(options?: CamOverlayOptions | IClient);
31
27
  updateCGText(serviceID: number, fields: TField[]): Promise<void>;
32
28
  updateCGImagePos(serviceID: number, coordinates?: string, x?: number, y?: number): Promise<void>;
33
29
  updateCGImage(serviceID: number, path: string, coordinates?: string, x?: number, y?: number): Promise<void>;
@@ -38,5 +34,4 @@ export declare class CamOverlayAPI {
38
34
  updateCGImageFromData(serviceID: number, imageType: ImageType, imageData: Buffer, coordinates?: string, x?: number, y?: number): Promise<void>;
39
35
  promiseCGUpdate(serviceID: number, action: string, params: string, contentType?: string, data?: Buffer): Promise<void>;
40
36
  private formCoordinates;
41
- private getBaseVapixConnectionParams;
42
37
  }
package/CamOverlayAPI.js CHANGED
@@ -10,21 +10,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CamOverlayAPI = exports.ImageType = void 0;
13
- const HttpRequest_1 = require("./internal/HttpRequest");
13
+ const common_1 = require("./internal/common");
14
+ const DefaultAgent_1 = require("./DefaultAgent");
14
15
  var ImageType;
15
16
  (function (ImageType) {
16
17
  ImageType[ImageType["PNG"] = 0] = "PNG";
17
18
  ImageType[ImageType["JPEG"] = 1] = "JPEG";
18
19
  })(ImageType || (exports.ImageType = ImageType = {}));
19
20
  class CamOverlayAPI {
20
- constructor(options) {
21
- var _a, _b, _c, _d, _e, _f;
22
- this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
23
- this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
24
- this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
25
- this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : (this.tls ? 443 : 80);
26
- this.user = (_e = options === null || options === void 0 ? void 0 : options.user) !== null && _e !== void 0 ? _e : '';
27
- this.pass = (_f = options === null || options === void 0 ? void 0 : options.pass) !== null && _f !== void 0 ? _f : '';
21
+ constructor(options = {}) {
22
+ if ((0, common_1.isClient)(options)) {
23
+ this.client = options;
24
+ }
25
+ else {
26
+ this.client = new DefaultAgent_1.DefaultAgent(options);
27
+ }
28
28
  }
29
29
  updateCGText(serviceID, fields) {
30
30
  let field_specs = '';
@@ -49,8 +49,7 @@ class CamOverlayAPI {
49
49
  updateInfoticker(serviceID, text) {
50
50
  return __awaiter(this, void 0, void 0, function* () {
51
51
  const path = `/local/camoverlay/api/infoticker.cgi?service_id=${serviceID}&text=${text}`;
52
- const options = this.getBaseVapixConnectionParams(path);
53
- const res = yield (0, HttpRequest_1.sendRequest)(options);
52
+ const res = yield this.client.get(path);
54
53
  if (!res.ok) {
55
54
  throw new Error(JSON.stringify(res));
56
55
  }
@@ -59,8 +58,7 @@ class CamOverlayAPI {
59
58
  setEnabled(serviceID, enabled) {
60
59
  return __awaiter(this, void 0, void 0, function* () {
61
60
  const path = `/local/camoverlay/api/enabled.cgi?id_${serviceID}=${enabled ? 1 : 0}`;
62
- const options = this.getBaseVapixConnectionParams(path, 'POST');
63
- const res = yield (0, HttpRequest_1.sendRequest)(options);
61
+ const res = yield this.client.post(path, '');
64
62
  if (!res.ok) {
65
63
  throw new Error(JSON.stringify(res));
66
64
  }
@@ -69,8 +67,7 @@ class CamOverlayAPI {
69
67
  isEnabled(serviceID) {
70
68
  return __awaiter(this, void 0, void 0, function* () {
71
69
  const path = '/local/camoverlay/api/services.cgi?action=get';
72
- const options = this.getBaseVapixConnectionParams(path);
73
- const res = yield (0, HttpRequest_1.sendRequest)(options);
70
+ const res = yield this.client.get(path);
74
71
  if (res.ok) {
75
72
  const data = JSON.parse(yield res.text());
76
73
  for (const service of data.services) {
@@ -88,8 +85,7 @@ class CamOverlayAPI {
88
85
  updateServices(servicesJson) {
89
86
  return __awaiter(this, void 0, void 0, function* () {
90
87
  const path = '/local/camoverlay/api/services.cgi?action=set';
91
- const options = this.getBaseVapixConnectionParams(path, 'POST');
92
- const res = yield (0, HttpRequest_1.sendRequest)(options, JSON.stringify(servicesJson));
88
+ const res = yield this.client.post(path, JSON.stringify(servicesJson));
93
89
  if (!res.ok) {
94
90
  throw new Error(JSON.stringify(res));
95
91
  }
@@ -103,11 +99,11 @@ class CamOverlayAPI {
103
99
  promiseCGUpdate(serviceID, action, params, contentType, data) {
104
100
  return __awaiter(this, void 0, void 0, function* () {
105
101
  const path = `/local/camoverlay/api/customGraphics.cgi?action=${action}&service_id=${serviceID}${params}`;
106
- const options = this.getBaseVapixConnectionParams(path, 'POST');
102
+ let headers = {};
107
103
  if (contentType !== undefined && data) {
108
- options.headers = { 'Content-Type': contentType };
104
+ headers = { 'Content-Type': contentType };
109
105
  }
110
- const res = yield (0, HttpRequest_1.sendRequest)(options, data);
106
+ const res = yield this.client.post(path, data !== null && data !== void 0 ? data : '', {}, headers);
111
107
  if (!res.ok) {
112
108
  throw new Error(JSON.stringify(res));
113
109
  }
@@ -116,17 +112,5 @@ class CamOverlayAPI {
116
112
  formCoordinates(coordinates, x, y) {
117
113
  return coordinates !== '' ? `&coord_system=${coordinates}&pos_x=${x}&pos_y=${y}` : '';
118
114
  }
119
- getBaseVapixConnectionParams(path, method = 'GET') {
120
- return {
121
- method: method,
122
- protocol: this.tls ? 'https:' : 'http:',
123
- host: this.ip,
124
- port: this.port,
125
- path: path,
126
- user: this.user,
127
- pass: this.pass,
128
- rejectUnauthorized: !this.tlsInsecure,
129
- };
130
- }
131
115
  }
132
116
  exports.CamOverlayAPI = CamOverlayAPI;
@@ -1,6 +1,8 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import * as EventEmitter from 'events';
2
- import { Options } from './internal/common';
3
- export type CamOverlayDrawingOptions = Options & {
4
+ import { WsOptions } from './internal/common';
5
+ export type CamOverlayDrawingOptions = WsOptions & {
4
6
  camera?: number | number[];
5
7
  zIndex?: number;
6
8
  };
@@ -43,11 +45,12 @@ export declare class CamOverlayDrawingAPI extends EventEmitter {
43
45
  private zIndex;
44
46
  private callId;
45
47
  private sendMessages;
46
- private connected;
47
- private ws?;
48
+ private wsConnected;
49
+ private ws;
48
50
  constructor(options?: CamOverlayDrawingOptions);
49
- connect(): Promise<void>;
51
+ connect(): void;
50
52
  disconnect(): void;
53
+ isConnected(): boolean;
51
54
  cairo(command: string, ...params: unknown[]): Promise<TCairoResponse | TCairoCreateResponse>;
52
55
  writeText(...params: TWriteTextParams): Promise<TCairoResponse>;
53
56
  uploadImageData(imgBuffer: Buffer): Promise<TUploadImageResponse>;
@@ -55,7 +58,7 @@ export declare class CamOverlayDrawingAPI extends EventEmitter {
55
58
  showCairoImage(cairoImage: string, posX: number, posY: number): Promise<TCairoResponse>;
56
59
  showCairoImageAbsolute(cairoImage: string, posX: number, posY: number, width: number, height: number): Promise<TCairoResponse>;
57
60
  removeImage(): Promise<TCairoResponse>;
58
- private openWebsocket;
61
+ private createWsClient;
59
62
  private sendMessage;
60
63
  private sendBinaryMessage;
61
64
  private reportMessage;
@@ -1,23 +1,12 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.CamOverlayDrawingAPI = void 0;
13
4
  const EventEmitter = require("events");
14
- const promises_1 = require("timers/promises");
15
5
  const WsClient_1 = require("./internal/WsClient");
16
6
  class CamOverlayDrawingAPI extends EventEmitter {
17
7
  constructor(options) {
18
8
  var _a, _b, _c, _d, _e, _f, _g;
19
9
  super();
20
- this.connected = false;
21
10
  this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
22
11
  this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
23
12
  this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
@@ -34,23 +23,18 @@ class CamOverlayDrawingAPI extends EventEmitter {
34
23
  }
35
24
  this.callId = 0;
36
25
  this.sendMessages = {};
26
+ this.wsConnected = false;
27
+ this.createWsClient();
37
28
  EventEmitter.call(this);
38
29
  }
39
30
  connect() {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- try {
42
- yield this.openWebsocket();
43
- this.connected = true;
44
- }
45
- catch (err) {
46
- }
47
- });
31
+ this.ws.open();
48
32
  }
49
33
  disconnect() {
50
- this.connected = false;
51
- if (this.ws !== undefined) {
52
- this.ws.close();
53
- }
34
+ this.ws.close();
35
+ }
36
+ isConnected() {
37
+ return this.wsConnected;
54
38
  }
55
39
  cairo(command, ...params) {
56
40
  return this.sendMessage({ command: command, params: params });
@@ -91,58 +75,46 @@ class CamOverlayDrawingAPI extends EventEmitter {
91
75
  removeImage() {
92
76
  return this.sendMessage({ command: 'remove_image_v2' });
93
77
  }
94
- openWebsocket() {
95
- return new Promise((resolve, reject) => {
96
- const options = {
97
- ip: this.ip,
98
- port: this.port,
99
- address: '/local/camoverlay/ws',
100
- protocol: 'cairo-api',
101
- user: this.user,
102
- pass: this.pass,
103
- tls: this.tls,
104
- tlsInsecure: this.tlsInsecure,
105
- };
106
- this.ws = new WsClient_1.WsClient(options);
107
- this.ws.on('open', () => {
108
- this.emit('open');
109
- resolve();
110
- });
111
- this.ws.on('message', (data) => {
112
- const dataJSON = JSON.parse(data.toString());
113
- if (Object.hasOwn(dataJSON, 'call_id') && dataJSON['call_id'] in this.sendMessages) {
114
- if (Object.hasOwn(dataJSON, 'error')) {
115
- this.sendMessages[dataJSON.call_id].reject(new Error(dataJSON.error));
116
- }
117
- else {
118
- this.sendMessages[dataJSON.call_id].resolve(dataJSON);
119
- }
120
- delete this.sendMessages[dataJSON['call_id']];
121
- }
78
+ createWsClient() {
79
+ const options = {
80
+ ip: this.ip,
81
+ port: this.port,
82
+ address: '/local/camoverlay/ws',
83
+ protocol: 'cairo-api',
84
+ user: this.user,
85
+ pass: this.pass,
86
+ tls: this.tls,
87
+ tlsInsecure: this.tlsInsecure,
88
+ };
89
+ this.ws = new WsClient_1.WsClient(options);
90
+ this.ws.on('open', () => {
91
+ this.wsConnected = true;
92
+ this.emit('open');
93
+ });
94
+ this.ws.on('message', (data) => {
95
+ const dataJSON = JSON.parse(data.toString());
96
+ if (Object.hasOwn(dataJSON, 'call_id') && dataJSON['call_id'] in this.sendMessages) {
122
97
  if (Object.hasOwn(dataJSON, 'error')) {
123
- this.reportError(new Error(dataJSON.error));
98
+ this.sendMessages[dataJSON.call_id].reject(new Error(dataJSON.error));
124
99
  }
125
100
  else {
126
- this.reportMessage(data.toString());
127
- }
128
- });
129
- this.ws.on('error', (error) => {
130
- this.reportError(error);
131
- reject(error);
132
- });
133
- this.ws.on('close', () => __awaiter(this, void 0, void 0, function* () {
134
- this.ws = undefined;
135
- this.reportClose();
136
- if (this.connected) {
137
- try {
138
- yield (0, promises_1.setTimeout)(10000);
139
- void this.openWebsocket();
140
- }
141
- catch (err) {
142
- }
101
+ this.sendMessages[dataJSON.call_id].resolve(dataJSON);
143
102
  }
144
- }));
145
- this.ws.open();
103
+ delete this.sendMessages[dataJSON['call_id']];
104
+ }
105
+ if (Object.hasOwn(dataJSON, 'error')) {
106
+ this.reportError(new Error(dataJSON.error));
107
+ }
108
+ else {
109
+ this.reportMessage(data.toString());
110
+ }
111
+ });
112
+ this.ws.on('error', (error) => {
113
+ this.reportError(error);
114
+ });
115
+ this.ws.on('close', () => {
116
+ this.wsConnected = false;
117
+ this.reportClose();
146
118
  });
147
119
  }
148
120
  sendMessage(msgJson) {
@@ -150,13 +122,14 @@ class CamOverlayDrawingAPI extends EventEmitter {
150
122
  try {
151
123
  this.sendMessages[this.callId] = { resolve, reject };
152
124
  msgJson['call_id'] = this.callId++;
153
- if (this.ws === undefined) {
125
+ if (!this.wsConnected) {
154
126
  throw new Error('No CamOverlay connection');
155
127
  }
156
128
  this.ws.send(JSON.stringify(msgJson));
157
129
  }
158
130
  catch (err) {
159
- this.reportError(new Error(`Send message error: ${err}`));
131
+ const errorMessage = err instanceof Error ? err.message : err;
132
+ this.reportError(new Error(`Send message error: ${errorMessage}`));
160
133
  }
161
134
  });
162
135
  }
@@ -171,13 +144,14 @@ class CamOverlayDrawingAPI extends EventEmitter {
171
144
  headerView.setInt8(0, 1);
172
145
  headerView.setInt32(1, jsonBuffer.byteLength);
173
146
  const msgBuffer = Buffer.concat([Buffer.from(header), jsonBuffer, data]);
174
- if (this.ws === undefined) {
147
+ if (!this.wsConnected) {
175
148
  throw new Error('No CamOverlay connection');
176
149
  }
177
150
  this.ws.send(msgBuffer);
178
151
  }
179
152
  catch (err) {
180
- this.reportError(new Error(`Send binary message error: ${err}`));
153
+ const errorMessage = err instanceof Error ? err.message : err;
154
+ this.reportError(new Error(`Send binary message error: ${errorMessage}`));
181
155
  }
182
156
  });
183
157
  }
@@ -185,9 +159,6 @@ class CamOverlayDrawingAPI extends EventEmitter {
185
159
  this.emit('message', msg);
186
160
  }
187
161
  reportError(err) {
188
- if (this.ws !== undefined) {
189
- this.ws.close();
190
- }
191
162
  this.emit('error', err);
192
163
  }
193
164
  reportClose() {
@@ -78,8 +78,8 @@ class Frame {
78
78
  disable() {
79
79
  this.enabled = false;
80
80
  }
81
- displayImage(cod_1, rm_1, cairo_1, ppX_1, ppY_1) {
82
- return __awaiter(this, arguments, void 0, function* (cod, rm, cairo, ppX, ppY, scale = 1) {
81
+ displayImage(cod, rm, cairo, ppX, ppY, scale = 1) {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
83
  if (this.enabled) {
84
84
  ppX += this.posX;
85
85
  ppY += this.posY;
@@ -18,8 +18,9 @@ export default class Painter extends Frame {
18
18
  get camOverlayDrawingAPI(): CamOverlayDrawingAPI;
19
19
  get resourceManager(): ResourceManager;
20
20
  constructor(opt: PainterOptions, coopt: CamOverlayDrawingOptions);
21
- connect(): Promise<void>;
21
+ connect(): void;
22
22
  disconnect(): void;
23
+ isConnected(): boolean;
23
24
  registerImage(moniker: string, fileName: string): void;
24
25
  registerFont(moniker: string, fileName: string): void;
25
26
  setScreenSize(sw: number, sh: number): void;
@@ -42,16 +42,20 @@ class Painter extends Frame_1.Frame {
42
42
  this.rm = new ResourceManager_1.default(this.cod);
43
43
  }
44
44
  connect() {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- this.cod.on('open', () => {
47
- this.rm.clear();
48
- });
49
- return this.cod.connect();
45
+ this.cod.on('open', () => {
46
+ this.rm.clear();
47
+ });
48
+ this.cod.on('error', (err) => {
49
+ console.error('Painter:', err);
50
50
  });
51
+ this.cod.connect();
51
52
  }
52
53
  disconnect() {
53
54
  this.cod.disconnect();
54
55
  }
56
+ isConnected() {
57
+ return this.cod.isConnected();
58
+ }
55
59
  registerImage(moniker, fileName) {
56
60
  this.rm.registerImage(moniker, fileName);
57
61
  }
@@ -65,8 +69,8 @@ class Painter extends Frame_1.Frame {
65
69
  setCoAlignment(coa) {
66
70
  this.coAlignment = exports.COORD[coa];
67
71
  }
68
- display() {
69
- return __awaiter(this, arguments, void 0, function* (scale = 1) {
72
+ display(scale = 1) {
73
+ return __awaiter(this, void 0, void 0, function* () {
70
74
  if (this.enabled) {
71
75
  [this.surface, this.cairo] = yield this.prepareDrawing(scale);
72
76
  yield this.displayOwnImage(this.cod, this.rm, this.cairo, 0, 0, scale);
@@ -1,6 +1,9 @@
1
+ /// <reference types="node" />
1
2
  import * as EventEmitter from 'events';
2
- import { Options } from './internal/common';
3
- export type CamScripterOptions = Options;
3
+ import { WsOptions } from './internal/common';
4
+ export type CamScripterOptions = WsOptions & {
5
+ camScripterAcapName?: string;
6
+ };
4
7
  export type TDeclaration = {
5
8
  type?: '' | 'SOURCE' | 'DATA';
6
9
  namespace: string;
@@ -39,16 +42,19 @@ export declare class CamScripterAPICameraEventsGenerator extends EventEmitter {
39
42
  private port;
40
43
  private user;
41
44
  private pass;
45
+ private camScripterAcapName;
42
46
  private callId;
43
47
  private sendMessages;
44
- private ws?;
48
+ private wsConnected;
49
+ private ws;
45
50
  constructor(options?: CamScripterOptions);
46
- connect(): Promise<void>;
51
+ connect(): void;
52
+ disconnect(): void;
47
53
  declareEvent(eventDeclaration: TEventDeclaration): Promise<TResponse>;
48
54
  undeclareEvent(eventUndeclaration: TEventUndeclaration): Promise<TResponse>;
49
55
  sendEvent(event: TEvent): Promise<TResponse>;
56
+ private createWsClient;
50
57
  private sendMessage;
51
- private openWebsocket;
52
58
  private reportErr;
53
59
  private reportClose;
54
60
  }
@@ -1,20 +1,11 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.CamScripterAPICameraEventsGenerator = void 0;
13
4
  const EventEmitter = require("events");
14
5
  const WsClient_1 = require("./internal/WsClient");
15
6
  class CamScripterAPICameraEventsGenerator extends EventEmitter {
16
7
  constructor(options) {
17
- var _a, _b, _c, _d, _e, _f;
8
+ var _a, _b, _c, _d, _e, _f, _g;
18
9
  super();
19
10
  this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
20
11
  this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
@@ -22,20 +13,18 @@ class CamScripterAPICameraEventsGenerator extends EventEmitter {
22
13
  this.port = (_d = options === null || options === void 0 ? void 0 : options.port) !== null && _d !== void 0 ? _d : (this.tls ? 443 : 80);
23
14
  this.user = (_e = options === null || options === void 0 ? void 0 : options.user) !== null && _e !== void 0 ? _e : '';
24
15
  this.pass = (_f = options === null || options === void 0 ? void 0 : options.pass) !== null && _f !== void 0 ? _f : '';
16
+ this.camScripterAcapName = (_g = options === null || options === void 0 ? void 0 : options.camScripterAcapName) !== null && _g !== void 0 ? _g : 'camscripter';
25
17
  this.callId = 0;
26
18
  this.sendMessages = {};
19
+ this.wsConnected = false;
20
+ this.createWsClient();
27
21
  EventEmitter.call(this);
28
22
  }
29
23
  connect() {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- try {
32
- yield this.openWebsocket();
33
- this.emit('open');
34
- }
35
- catch (err) {
36
- this.reportErr(err);
37
- }
38
- });
24
+ this.ws.open();
25
+ }
26
+ disconnect() {
27
+ this.ws.close();
39
28
  }
40
29
  declareEvent(eventDeclaration) {
41
30
  return this.sendMessage({
@@ -58,9 +47,48 @@ class CamScripterAPICameraEventsGenerator extends EventEmitter {
58
47
  data: event,
59
48
  });
60
49
  }
50
+ createWsClient() {
51
+ const options = {
52
+ user: this.user,
53
+ pass: this.pass,
54
+ tlsInsecure: this.tlsInsecure,
55
+ tls: this.tls,
56
+ ip: this.ip,
57
+ port: this.port,
58
+ address: `/local/${this.camScripterAcapName}/ws`,
59
+ protocol: 'camera-events',
60
+ };
61
+ this.ws = new WsClient_1.WsClient(options);
62
+ this.ws.on('open', () => {
63
+ this.wsConnected = true;
64
+ this.emit('open');
65
+ });
66
+ this.ws.on('message', (data) => {
67
+ const dataJSON = JSON.parse(data.toString());
68
+ if (Object.hasOwn(dataJSON, 'call_id') && dataJSON['call_id'] in this.sendMessages) {
69
+ if (Object.hasOwn(dataJSON, 'error')) {
70
+ this.sendMessages[dataJSON['call_id']].reject(new Error(dataJSON.error));
71
+ }
72
+ else {
73
+ this.sendMessages[dataJSON['call_id']].resolve(dataJSON);
74
+ }
75
+ delete this.sendMessages[dataJSON['call_id']];
76
+ }
77
+ if (Object.hasOwn(dataJSON, 'error')) {
78
+ this.reportErr(new Error(dataJSON.error));
79
+ }
80
+ });
81
+ this.ws.on('error', (error) => {
82
+ this.reportErr(error);
83
+ });
84
+ this.ws.on('close', () => {
85
+ this.wsConnected = false;
86
+ this.reportClose();
87
+ });
88
+ }
61
89
  sendMessage(msgJson) {
62
90
  return new Promise((resolve, reject) => {
63
- if (this.ws === undefined) {
91
+ if (!this.wsConnected) {
64
92
  throw new Error("Websocket hasn't been opened yet.");
65
93
  }
66
94
  try {
@@ -73,50 +101,7 @@ class CamScripterAPICameraEventsGenerator extends EventEmitter {
73
101
  }
74
102
  });
75
103
  }
76
- openWebsocket() {
77
- return new Promise((resolve, reject) => {
78
- const options = {
79
- user: this.user,
80
- pass: this.pass,
81
- tlsInsecure: this.tlsInsecure,
82
- tls: this.tls,
83
- ip: this.ip,
84
- port: this.port,
85
- address: '/local/camscripter/ws',
86
- protocol: 'camera-events',
87
- };
88
- this.ws = new WsClient_1.WsClient(options);
89
- this.ws.on('open', () => {
90
- resolve();
91
- });
92
- this.ws.on('message', (data) => {
93
- const dataJSON = JSON.parse(data.toString());
94
- if (Object.hasOwn(dataJSON, 'call_id') && dataJSON['call_id'] in this.sendMessages) {
95
- if (Object.hasOwn(dataJSON, 'error')) {
96
- this.sendMessages[dataJSON['call_id']].reject(new Error(dataJSON.error));
97
- }
98
- else {
99
- this.sendMessages[dataJSON['call_id']].resolve(dataJSON);
100
- }
101
- delete this.sendMessages[dataJSON['call_id']];
102
- }
103
- if (Object.hasOwn(dataJSON, 'error')) {
104
- this.reportErr(new Error(dataJSON.error));
105
- }
106
- });
107
- this.ws.on('error', (error) => {
108
- this.reportErr(error);
109
- reject(error);
110
- });
111
- this.ws.on('close', () => {
112
- this.reportClose();
113
- });
114
- this.ws.open();
115
- });
116
- }
117
104
  reportErr(err) {
118
- var _a;
119
- (_a = this.ws) === null || _a === void 0 ? void 0 : _a.close();
120
105
  this.emit('error', err);
121
106
  }
122
107
  reportClose() {
@@ -1,17 +1,35 @@
1
- import { Options } from './internal/common';
2
- export type CamStreamerAPIOptions = Options;
1
+ import { IClient, HttpOptions } from './internal/common';
2
+ export type CamStreamerAPIOptions = HttpOptions;
3
+ export type TStreamAttributes = {
4
+ enabled: string;
5
+ active: string;
6
+ audioSource: string;
7
+ avSyncMsec: string;
8
+ internalVapixParameters: string;
9
+ userVapixParameters: string;
10
+ outputParameters: string;
11
+ outputType: string;
12
+ mediaServerUrl: string;
13
+ inputType: string;
14
+ inputUrl: string;
15
+ forceStereo: string;
16
+ streamDelay: string;
17
+ statusLed: string;
18
+ statusPort: string;
19
+ callApi: string;
20
+ trigger: string;
21
+ schedule: string;
22
+ prepareAhead: string;
23
+ startTime: string;
24
+ stopTime: string;
25
+ };
26
+ export type TStreamList = Record<string, TStreamAttributes>;
3
27
  export declare class CamStreamerAPI {
4
- private tls;
5
- private tlsInsecure;
6
- private ip;
7
- private port;
8
- private user;
9
- private pass;
10
- constructor(options?: CamStreamerAPIOptions);
11
- getStreamList(): Promise<any>;
12
- getStreamParameter(streamID: string, paramName: string): Promise<any>;
13
- setStreamParameter(streamID: string, paramName: string, value: string): Promise<any>;
14
- isStreaming(streamID: string): Promise<any>;
28
+ private client;
29
+ constructor(options?: CamStreamerAPIOptions | IClient);
30
+ getStreamList(): Promise<TStreamList>;
31
+ getStreamParameter(streamID: string, paramName: string): Promise<string>;
32
+ setStreamParameter(streamID: string, paramName: string, value: string): Promise<void>;
33
+ isStreaming(streamID: string): Promise<boolean>;
15
34
  get(path: string): Promise<any>;
16
- private getBaseConnectionParams;
17
35
  }