smart-socket
npm i smart-socket --save
API
SmartSocket inherits from events.EventEmitter
SmartSocket.start()
/** * Starts the WebSocket connection tasks loop over given addresses */SmartSocketprototype { /* ... */ }
SmartSocket.stop()
/** * Prevents SmartSocket from retrying connection tasks in the future */SmartSocketprototype { /* ... */ }
SmartSocket.close()
/** * Immediately close() connected WebSocket (does nothing if none connected) * @param stop */SmartSocketprototype { /* ... */ }
Events
open
ss;
message
ss;
close
ss;
error
ss;
loopStart
ss;
loopEnd
ss;
Example
var SmartSocket = ; var ss = addresses: '127.0.0.1:8042' // array of addresses to try to connect to (order is kept) timeout: 10000 // [optional] connection timeout for Web sockets in milliseconds loopBreak: 2000 // [optional] time between two loops in milliseconds; ss;ss;ss;ss;ss;ss;ss; ssstart; // once you are done loopingss; // note that stop() won't force stop, it will wait for the remote server to hang-up the connection before stopping // if you don't want to wait, you can call close() // immediately close the connection to the connected server but let the connection loop activess;// or immediately close the connection to the connected server and stops connection loopss; // ss.close(); is the same