- if (this._ws.readyState !== WebSocket.OPEN) {
- this.openWS();
- }
- if (this._ws.readyState === WebSocket.OPEN) {
- this._ws.send(msg);
- } else {
- throw new Error(`Send request '${command}' message: connection not opened`);
+ if (this.ws.readyState !== WebSocket.OPEN) {
+ this.openWS();
+ }
+ if (this.ws.readyState === WebSocket.OPEN) {
+ const sendTimeout = setTimeout(() => {
+ this.deleteResponseHandler(uuid);
+ return reject(new Error(`Send request '${command}' message timeout`));
+ }, 60 * 1000);
+ try {
+ this.ws.send(msg);
+ this.setResponseHandler(uuid, command, resolve, reject);
+ } catch (error) {
+ this.deleteResponseHandler(uuid);
+ reject(error);
+ } finally {
+ clearTimeout(sendTimeout);