const Client = require('fast-ws/client')
const ws = new Client(
ws_url, // 'ws://host:port/path' or 'wss://host:port/path'
// options
{
// Ping Interval (not less then server `idleTimeout`)
pingInterval: 30000, // Default (ms)
// Reply Timeout (Event reply)
replyTimeout: 5000, // Default (ms)
// parser options (same as server)
parserOptions: {},
...// Others options for package 'ws'
}
)
Add single listener
Remove single listener
Remove all listeners by event name
Emit custom event to server
Send message to server
Send binary to server
Cllose WebSocket
'ws' open event
Connection error
Connect success
'ws' close event
'ws' ping event
Pong event with latency (ms)
ws.on('pong', (latency) => {
console.log(`Ping latency ${latency}`)
})
Normal message event
Binary event
Custom event send from server