camstreamerlib 2.0.3 → 2.0.5

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.
@@ -48,9 +48,10 @@ export declare class CamOverlayDrawingAPI extends EventEmitter {
48
48
  private zIndex;
49
49
  private callId;
50
50
  private sendMessages;
51
- private ws;
51
+ private ws?;
52
52
  constructor(options?: CamOverlayDrawingOptions);
53
53
  connect(): Promise<void>;
54
+ disconnect(): void;
54
55
  cairo(command: string, ...params: any[]): Promise<CairoResponse | CairoCreateResponse>;
55
56
  writeText(...params: WriteTextParams): Promise<CairoResponse>;
56
57
  uploadImageData(imgBuffer: Buffer): Promise<UploadImageResponse>;
@@ -16,7 +16,6 @@ class CamOverlayDrawingAPI extends EventEmitter {
16
16
  constructor(options) {
17
17
  var _a, _b, _c, _d, _e, _f;
18
18
  super();
19
- this.ws = null;
20
19
  this.tls = (_a = options === null || options === void 0 ? void 0 : options.tls) !== null && _a !== void 0 ? _a : false;
21
20
  this.tlsInsecure = (_b = options === null || options === void 0 ? void 0 : options.tlsInsecure) !== null && _b !== void 0 ? _b : false;
22
21
  this.ip = (_c = options === null || options === void 0 ? void 0 : options.ip) !== null && _c !== void 0 ? _c : '127.0.0.1';
@@ -45,6 +44,11 @@ class CamOverlayDrawingAPI extends EventEmitter {
45
44
  }
46
45
  });
47
46
  }
47
+ disconnect() {
48
+ if (this.ws !== undefined) {
49
+ this.ws.close();
50
+ }
51
+ }
48
52
  cairo(command, ...params) {
49
53
  return this.sendMessage({ command: command, params: params });
50
54
  }
@@ -123,6 +127,7 @@ class CamOverlayDrawingAPI extends EventEmitter {
123
127
  reject(error);
124
128
  });
125
129
  this.ws.on('close', () => {
130
+ this.ws = undefined;
126
131
  this.reportClose();
127
132
  });
128
133
  this.ws.open();
@@ -133,6 +138,9 @@ class CamOverlayDrawingAPI extends EventEmitter {
133
138
  try {
134
139
  this.sendMessages[this.callId] = { resolve, reject };
135
140
  msgJson['call_id'] = this.callId++;
141
+ if (this.ws === undefined) {
142
+ throw new Error('No CamOverlay connection');
143
+ }
136
144
  this.ws.send(JSON.stringify(msgJson));
137
145
  }
138
146
  catch (err) {
@@ -151,6 +159,9 @@ class CamOverlayDrawingAPI extends EventEmitter {
151
159
  headerView.setInt8(0, 1);
152
160
  headerView.setInt32(1, jsonBuffer.byteLength);
153
161
  const msgBuffer = Buffer.concat([Buffer.from(header), jsonBuffer, data]);
162
+ if (this.ws === undefined) {
163
+ throw new Error('No CamOverlay connection');
164
+ }
154
165
  this.ws.send(msgBuffer);
155
166
  }
156
167
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camstreamerlib",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "Helper library for CamStreamer ACAP applications.",
5
5
  "prettier": "@camstreamer/prettier-config",
6
6
  "dependencies": {