lanan-repair-app/utils/tebBarSocket.js

44 lines
880 B
JavaScript
Raw Normal View History

2024-10-09 13:34:36 +08:00
import {
startMsgSocket
} from '../main.js'
2024-10-17 15:22:37 +08:00
import {
getTenantId,
getStrData
} from '@/utils/auth'
2024-10-09 13:34:36 +08:00
import config from '@/config'
2024-10-17 15:22:37 +08:00
export function tabBarconnect(tenantId, userId) {
console.log("通知socket链接", tenantId, userId);
2024-10-09 13:34:36 +08:00
var socketTask = uni.connectSocket({
2024-10-17 15:22:37 +08:00
url: config.wsUrl + '/websocket/message/'+tenantId+'/' + userId,
2024-10-09 13:34:36 +08:00
success(res) {
},
fail(err) {
}
}
);
return socketTask;
}
export function sendMsg(SocketTask) {
if (SocketTask) {
SocketTask.send({
data: 'beat',
success: res => {
console.log('消息链接正常')
},
fail: err => {
2024-10-17 15:22:37 +08:00
console.log('消息链接异常 重新链接' + err, getStrData('userId'));
startMsgSocket(getTenantId(),getStrData('userId'));
2024-10-09 13:34:36 +08:00
}
});
} else {
2024-10-17 15:22:37 +08:00
startMsgSocket(getTenantId(),getStrData('userId'));
2024-10-09 13:34:36 +08:00
}
}
export function closeMsgSocket(SocketTask) {
SocketTask.close()
2024-10-17 15:22:37 +08:00
}