socket onOpen 回调重复执行
连接soket之后,调用任何请求,socket的onOpen 都会在执行一次;我是通过 返回的 实例 进行回调注册的
const SocketTask = (this.SocketTask = wx.connectSocket({
url: ‘x’,
}));
SocketTask.onOpen(msg => {
console.log(‘onOpen’, msg);
//
SocketTask.send({
data: JSON.stringify({
scene: ‘shake_hands’,
openid: userInfo.openid,
uniacid: userInfo.uniacid,
}),
});
});
SocketTask.onClose(msg => {
console.log(‘onCloase’, msg);
});
SocketTask.onMessage(data => {
store.eventBus.emit(‘getSocketMsg’, data);
});