lanan-old/rescue-driver/utils/tebBarSocket.js
愉快的大福 7dc28dc701 init
2024-07-17 14:16:22 +08:00

46 lines
789 B
JavaScript

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()
}