fix: ws接收信息ue事件
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, onMounted } from 'vue';
|
||||
import { reactive, ref, onMounted, onBeforeUnmount } from 'vue';
|
||||
import {
|
||||
listCacheName,
|
||||
listCacheKey,
|
||||
@@ -16,8 +16,12 @@ import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||
import { WS, OptionsType } from '@/plugins/ws-websocket';
|
||||
import useI18n from '@/hooks/useI18n';
|
||||
const { t } = useI18n();
|
||||
|
||||
const ws = new WS();
|
||||
|
||||
onMounted(() => {
|
||||
const options: OptionsType = {
|
||||
url: '/ws',
|
||||
params: {
|
||||
subGroupID: '1005',
|
||||
},
|
||||
@@ -29,12 +33,16 @@ onMounted(() => {
|
||||
// 接收数据后回调
|
||||
console.log(ev);
|
||||
},
|
||||
// 保活周期 10s
|
||||
heartTimer: 0,
|
||||
// 断线重连
|
||||
reconnectTimer: 0,
|
||||
};
|
||||
const ws = new WS(options);
|
||||
ws.connect(options);
|
||||
|
||||
setInterval(() => {
|
||||
ws.send({ a: 1 });
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
ws.close();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ export default function useWS() {
|
||||
/**接收数据后回调 */
|
||||
function wsMessage(res: Record<string, any>) {
|
||||
console.log(res);
|
||||
const { code, requestId, groupId, data } = res;
|
||||
const { code, requestId, data } = res;
|
||||
if (code === RESULT_CODE_ERROR) {
|
||||
console.warn(res.msg);
|
||||
return;
|
||||
@@ -44,8 +44,11 @@ export default function useWS() {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!data?.groupId) {
|
||||
return;
|
||||
}
|
||||
// 订阅组信息
|
||||
switch (groupId) {
|
||||
switch (data.groupId) {
|
||||
// ueEvent UE会话事件
|
||||
case '1010':
|
||||
if (data.data) {
|
||||
@@ -76,17 +79,19 @@ export default function useWS() {
|
||||
|
||||
/**ueEvent UE会话事件 数据解析 */
|
||||
function ueEventParse(item: Record<string, any>) {
|
||||
let evData: Record<string, any> = {};
|
||||
try {
|
||||
evData = JSON.parse(item.eventJSON);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return false;
|
||||
let evData: Record<string, any> = item.eventJSON;
|
||||
if (typeof evData === 'string') {
|
||||
try {
|
||||
evData = JSON.parse(item.eventJSON);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (Reflect.has(evData, 'authTime')) {
|
||||
if (item.eventType === 'auth-result') {
|
||||
return {
|
||||
id: item.id,
|
||||
id: item.id || item.timestamp,
|
||||
type: item.eventType,
|
||||
time: evData.authTime,
|
||||
imsi: evData.imsi,
|
||||
@@ -94,9 +99,9 @@ export default function useWS() {
|
||||
};
|
||||
}
|
||||
|
||||
if (Reflect.has(evData, 'detachTime')) {
|
||||
if (item.eventType === 'detach') {
|
||||
return {
|
||||
id: item.id,
|
||||
id: item.id || item.timestamp,
|
||||
type: item.eventType,
|
||||
time: evData.detachTime,
|
||||
imsi: evData.imsi,
|
||||
@@ -104,9 +109,9 @@ export default function useWS() {
|
||||
};
|
||||
}
|
||||
|
||||
if (Reflect.has(evData, 'changeTime')) {
|
||||
if (item.eventType === 'cm-state') {
|
||||
return {
|
||||
id: item.id,
|
||||
id: item.id || item.timestamp,
|
||||
type: item.eventType,
|
||||
time: evData.changeTime,
|
||||
imsi: evData.imsi,
|
||||
|
||||
Reference in New Issue
Block a user