rescue-driver/utils/tebBarSocket.js

46 lines
789 B
JavaScript
Raw Permalink Normal View History

2024-08-28 22:02:00 +08:00
import {
startMsgSocket
} from '../main.js'
import config from '@/config'
export function tabBarconnect(userId) {
console.log("通知socket链接");
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()
}