46 lines
789 B
JavaScript
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()
|
|
}
|