options参数:
url: string, // 链接的通道的地址
heartTime: 5000, // 心跳时间间隔
heartMsg: 'ping', // 心跳信息,默认为'ping'
isReconnect: true, // 是否自动重连
isDestroy: false, // 是否销毁
reconnectTime: 5000, // 重连时间间隔
reconnectCount: 5, // 重连次数 -1 则不限制
openCb: null, // 连接成功的回调
closeCb: null, // 关闭的回调
messageCb: null, // 消息的回调
errorCb: null // 错误的回调
isReconnect
参数为false则 reconnectCount
reconnectTime
不在生效,该参数默认为true(需要自动重连)
import { Socket } from 'i-socket'
let options = {
....
}
this.wbSocket = new Socket(options)
this.wbSocket.onmessage((data) => {})
import { Socket } from 'i-socket'
let options = {
....,
onmessage: (data) =>{
}
}
this.wbSocket = new Socket({ options })