Skip to content

zack24q/smart-websocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

smart-websocket

npm npm

Features

  • 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

DEMO

DEMO

CODE

Installing

npm i -S smart-websocket

or

yarn add smart-websocket

Usage

import SmartWebsocket from 'smart-websocket'

let socket = new SmartWebsocket(URL, OPTIONS)

Options

defaultOptions = {
  autoOpen: true,
  smartSend: true,
  autoReconnect: true,
  reconnectDelay: 500,
  maxReconnectCount: 3
}

Methods

socket.open()
socket.send(data)
socket.close()

Events

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}) => {})

About

A smart websocket library, simple to use.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published