Skip to content

Commit

Permalink
fix(fjagejs): try to figure out if a send was successful and return t…
Browse files Browse the repository at this point in the history
…he appopriate status
  • Loading branch information
notthetup committed Aug 1, 2024
1 parent 66d13ff commit 6534288
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gateways/js/src/TCPConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class TCPconnector {
this.sock.on('connect', this._onSockOpen.bind(this));
this.sock.on('error', this._sockReconnect.bind(this));
this.sock.on('close', () => {this._sendConnEvent(false);});
this.sock.send = data => {this.sock.write(data);};
this.sock.send = data => this.sock.write(data);
} catch (error) {
if(this.debug) console.log('Connection failed to ', this.sock.host + ':' + this.sock.port);
return;
Expand Down
26 changes: 19 additions & 7 deletions gateways/js/src/WSConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,22 @@ export default class WSConnector {
this.sock.onmessage = event => { if (this._onWebsockRx) this._onWebsockRx.call(this,event.data); };
this._firstConn = false;
this._firstReConn = true;
this.pendingOnOpen.forEach(cb => cb());
this.pendingOnOpen.length = 0;
this.pendingOnOpen = this.pendingOnOpen.filter(cb => !cb());
}

/**
* Converts the websocket send API to return a boolean
*
* @param {String} msg message to be sent to the server
* @returns {boolean} true if the message was sent successfully
*/
_send(msg){
try {
this.sock.send(msg+'\n');
return true;
} catch (error) {
return false;
}
}

toString(){
Expand All @@ -79,16 +93,14 @@ export default class WSConnector {
/**
* Write a string to the connector
* @param {string} s - string to be written out of the connector to the master
* @returns {boolean} - true if the string was written successfully
*/
write(s){
if (!this.sock || this.sock.readyState == this.sock.CONNECTING){
this.pendingOnOpen.push(() => {
this.sock.send(s+'\n');
});
this.pendingOnOpen.push(() => this._send(s));
return true;
} else if (this.sock.readyState == this.sock.OPEN) {
this.sock.send(s+'\n');
return true;
return this.sock.send(s+'\n');
}
return false;
}
Expand Down

0 comments on commit 6534288

Please sign in to comment.