1.0.0 • Published 1 year ago

websocket-easy-js v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

websocket-easy-js

A client-websocket written in TypeScript for browser-applications. Focus is on simplicity, reliability and extensibility. It provides convenient features to automatically reconnect, Support multiple connections at the same time and Manual destruction.

install

npm install websocket-easy-js --save

 or
 
yarn add websocket-easy-js

Usage

import { Socket } from 'websocket-easy-js'

// 参数配置,见下面参数属性
let config = {
  ....
}

// 创建对象
this.wbSocket = new Socket(config)

// 连接
this.wbSocket.connection()

// 发送信息
this.wbSocket.sendMessage(message)

//关闭(销毁)
this.wbSocket.close()
...

config 对象属性说明

config对象中有以下属性

属性类型默认值描述
urlstringnull必填,链接的通道的地址
heartTimenumber5000心跳时间间隔
heartMsgstring'ping'心跳信息
isReconnectbooleantrue是否自动重连
reconnectTimenumber2000重连时间间隔
reconnectCountnumber-1重连次数 -1 则不限制
openCbfunction-连接成功的回调
closeCbfunction-关闭的回调
messageCbfunction-消息的回调
errorCbfunction-错误的回调