import base from '@/config/baseUrl';
import store from'@/store';
class socket {
constructor(options) {//地址
this.socketUrl =base.socketUrl;this.socketStart = false;this.monitorSocketError();this.monitorSocketClose();this.socketReceive();
}
init(callback) {
const _this= this;if(base.socketUrl) {if(this.socketStart){
console.log('webSocket已经启动了');
}else{
uni.connectSocket({
url:this.socketUrl,
method:'GET'});
uni.onSocketOpen((res)=>{this.socketStart = true;
callback&&callback();
console.log('WebSocket连接已打开!');
});/*setTimeout(() => {
_this.getHeartbeat();
}, 5000);*/}
}else{
console.log('config/baseUrl socketUrl为空');