lanan-repair/utils/tebBarSocket.js
2024-09-24 16:58:29 +08:00

44 lines
795 B
JavaScript

import {
startMsgSocket
} from '../main.js'
import config from '@/config'
export function tabBarconnect(userId) {
console.log("通知socket链接", userId);
var socketTask = uni.connectSocket({
url: config.wsUrl + '/websocket/announcement/' + userId,
success(res) {
},
fail(err) {
}
}
);
return socketTask;
}
export function sendMsg(SocketTask) {
if (SocketTask) {
SocketTask.send({
data: 'beat',
success: res => {
console.log('消息链接正常')
},
fail: err => {
console.log('消息链接异常 重新链接' + err, uni.getStorageSync('userId'));
startMsgSocket(uni.getStorageSync('userId'));
}
});
} else {
startMsgSocket(uni.getStorageSync('userId'));
}
}
export function closeMsgSocket(SocketTask) {
SocketTask.close()
}