- autoReconnect: In non-user disconnected case, the websocket is automatically reconnected after disconnecting
- smartSend: The message will not be sent until the Websocket is opened
npm i -S smart-websocket
or
yarn add smart-websocket
import SmartWebsocket from 'smart-websocket'
let socket = new SmartWebsocket(URL, OPTIONS)
defaultOptions = {
autoOpen: true,
smartSend: true,
autoReconnect: true,
reconnectDelay: 500,
maxReconnectCount: 3
}
socket.open()
socket.send(data)
socket.close()
socket.addEventListener('connecting', ({reconnectCount}) => {})
socket.addEventListener('open', ({reconnectCount}) => {}) // When the connection is successfully opened, reconnectCount will be set to 0
socket.addEventListener('close', ({reconnectCount}) => {})
socket.addEventListener('error', ({reconnectCount}) => {})
socket.addEventListener('message', ({reconnectCount}) => {})