camstreamerlib 2.0.4 → 2.0.6
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.
- package/CamOverlayDrawingAPI.d.ts +2 -1
- package/CamOverlayDrawingAPI.js +15 -3
- package/WsClient.js +6 -5
- package/package.json +1 -1
|
@@ -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>;
|
package/CamOverlayDrawingAPI.js
CHANGED
|
@@ -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';
|
|
@@ -41,10 +40,14 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
41
40
|
this.emit('open');
|
|
42
41
|
}
|
|
43
42
|
catch (err) {
|
|
44
|
-
this.reportError(err);
|
|
45
43
|
}
|
|
46
44
|
});
|
|
47
45
|
}
|
|
46
|
+
disconnect() {
|
|
47
|
+
if (this.ws !== undefined) {
|
|
48
|
+
this.ws.close();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
48
51
|
cairo(command, ...params) {
|
|
49
52
|
return this.sendMessage({ command: command, params: params });
|
|
50
53
|
}
|
|
@@ -123,6 +126,7 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
123
126
|
reject(error);
|
|
124
127
|
});
|
|
125
128
|
this.ws.on('close', () => {
|
|
129
|
+
this.ws = undefined;
|
|
126
130
|
this.reportClose();
|
|
127
131
|
});
|
|
128
132
|
this.ws.open();
|
|
@@ -133,6 +137,9 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
133
137
|
try {
|
|
134
138
|
this.sendMessages[this.callId] = { resolve, reject };
|
|
135
139
|
msgJson['call_id'] = this.callId++;
|
|
140
|
+
if (this.ws === undefined) {
|
|
141
|
+
throw new Error('No CamOverlay connection');
|
|
142
|
+
}
|
|
136
143
|
this.ws.send(JSON.stringify(msgJson));
|
|
137
144
|
}
|
|
138
145
|
catch (err) {
|
|
@@ -151,6 +158,9 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
151
158
|
headerView.setInt8(0, 1);
|
|
152
159
|
headerView.setInt32(1, jsonBuffer.byteLength);
|
|
153
160
|
const msgBuffer = Buffer.concat([Buffer.from(header), jsonBuffer, data]);
|
|
161
|
+
if (this.ws === undefined) {
|
|
162
|
+
throw new Error('No CamOverlay connection');
|
|
163
|
+
}
|
|
154
164
|
this.ws.send(msgBuffer);
|
|
155
165
|
}
|
|
156
166
|
catch (err) {
|
|
@@ -162,7 +172,9 @@ class CamOverlayDrawingAPI extends EventEmitter {
|
|
|
162
172
|
this.emit('message', msg);
|
|
163
173
|
}
|
|
164
174
|
reportError(err) {
|
|
165
|
-
this.ws
|
|
175
|
+
if (this.ws !== undefined) {
|
|
176
|
+
this.ws.close();
|
|
177
|
+
}
|
|
166
178
|
this.emit('error', err);
|
|
167
179
|
}
|
|
168
180
|
reportClose() {
|
package/WsClient.js
CHANGED
|
@@ -69,14 +69,14 @@ class WsClient extends EventEmitter {
|
|
|
69
69
|
this.open(res.headers['www-authenticate']);
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
const e = new Error('
|
|
72
|
+
const e = new Error('Status code: ' + res.statusCode);
|
|
73
73
|
this.emit('error', e);
|
|
74
74
|
}
|
|
75
75
|
}));
|
|
76
76
|
this.ws.on('open', () => this.emit('open'));
|
|
77
77
|
this.ws.on('message', (data) => this.emit('message', data));
|
|
78
78
|
this.ws.on('error', (error) => this.emit('error', error));
|
|
79
|
-
this.ws.on('close', () => this.
|
|
79
|
+
this.ws.on('close', () => this.handleCloseEvent());
|
|
80
80
|
}
|
|
81
81
|
send(data) {
|
|
82
82
|
if (this.ws.readyState === this.ws.OPEN) {
|
|
@@ -86,13 +86,14 @@ class WsClient extends EventEmitter {
|
|
|
86
86
|
close() {
|
|
87
87
|
try {
|
|
88
88
|
this.handleCloseEvent();
|
|
89
|
-
this.ws.
|
|
89
|
+
if (this.ws.readyState !== this.ws.CLOSING && this.ws.readyState !== this.ws.CLOSED) {
|
|
90
|
+
this.ws.close();
|
|
91
|
+
}
|
|
90
92
|
}
|
|
91
93
|
catch (err) {
|
|
92
|
-
this.emit('error', err);
|
|
93
94
|
}
|
|
94
95
|
setTimeout(() => {
|
|
95
|
-
if (this.ws.readyState
|
|
96
|
+
if (this.ws.readyState !== this.ws.CLOSED) {
|
|
96
97
|
this.ws.terminate();
|
|
97
98
|
}
|
|
98
99
|
}, 5000);
|