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