44 lines
880 B
JavaScript
44 lines
880 B
JavaScript
import {
|
|
startMsgSocket
|
|
} from '../main.js'
|
|
import {
|
|
getTenantId,
|
|
getStrData
|
|
} from '@/utils/auth'
|
|
import config from '@/config'
|
|
|
|
export function tabBarconnect(tenantId, userId) {
|
|
console.log("通知socket链接", tenantId, userId);
|
|
var socketTask = uni.connectSocket({
|
|
url: config.wsUrl + '/websocket/message/'+tenantId+'/' + 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, getStrData('userId'));
|
|
startMsgSocket(getTenantId(),getStrData('userId'));
|
|
}
|
|
});
|
|
} else {
|
|
startMsgSocket(getTenantId(),getStrData('userId'));
|
|
}
|
|
}
|
|
|
|
export function closeMsgSocket(SocketTask) {
|
|
SocketTask.close()
|
|
}
|