封装socket.js
class Socket {
/**
* @description: 初始化实例属性,保存参数
*
*/
constructor(options) {
this.url = options.url;
this.callback = options.received;
this.name = options.name || 'default';
this.ws = null;
this.status = null;
this.pingInterval = null;
// 心跳检测频率
this._timeout = 3000;
this.isHeart = options.isHeart;
this.isReconnection = options.isReconnection;
}
connect(data) {
this.ws = new WebSocket(this.url);
// 建立连接
this.ws.onopen = (e) => {
this.status = &