0.1.0 • Published 4 years ago

ws-plugin v0.1.0

Weekly downloads
-
License
-
Repository
-
Last release
4 years ago

ws-plugin

使用说明

npm i ws-plugin --save
import Socket from 'ws-plugin'
const ws = new Socket({
  url: null, // 链接的通道的地址
  heartTime: 60 * 1000 * 3, // 心跳时间间隔
  heartMsg: 'ping', // 心跳信息,默认为'ping'
  isRestroy: false, // 是否销毁
  reconnectCount: 10, // 自动重连次数,-1为无限次重连
  reconnectTime: 5000, // 自动重连时间间隔,单位毫秒,默认5秒
  onOpen: null, // 连接成功的回调
  onClose: null, // 关闭的回调
  onMessage: null, // 消息的回调
  onError: null // 错误的回调
})

// 方法调用
ws.onopen(() => {
  // do something here
})

参数说明

参数名称参数说明默认值
url链接的通道的地址
heartTime心跳时间间隔3 * 60 * 1000(单位:毫秒)
heartMsg心跳信息默认为'ping'(String 类型)
reconnectCount自动重连次数默认为 10,-1 为无限次(Numbe 类型)
reconnectTime自动重连时间间隔默认值 5 * 1000(单位:毫秒)
onOpen连接成功的回调null
onClose关闭的回调null
onMessage消息的回调null
onError错误的回调null

方法说明

方法名称方法说明参数
onopen连接成功的回调函数传一个回调函数
onclose关闭 ws 连接,传一个回调函数
onmessage接受信息回调传一个回调函数
onerror连接错误回调传一个回调函数
onreconnect重连默认值 5 * 1000(单位:毫秒)

安装依赖

npm install

启动项目

npm run serve

项目构建

npm run build

构建 npm 包

npm run lib

规范检测

npm run lint