index.js
5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* 전역으로 사용되는 mixin 지정입니다.
*/
import calcDistanceFromCoord from '@/utils/CommonFunction/calcDistanceFromCoord';
import calcAngleFromCoord from '@/utils/CommonFunction/calcAngleFromCoord';
import { mapActions, mapGetters } from 'vuex';
export default {
data() {
return {
socketServerCnt: 5,
droneCnt: 1000,
selectedDroneLog: {},
accumulatedDistance: 0,
socketOnGoing: 0,
};
},
computed: {
...mapGetters('Drone/drone', {
getDroneLogs: 'getDroneLogs',
getSelectedLogList: 'getSelectedLogList',
getSelectedDroneId: 'getSelectedDroneId',
getSelectedLastLog: 'getSelectedLastLog',
getAccumulatedDistance: 'getAccumulatedDistance',
}),
...mapGetters('Drone/Map', {
getZoomLevel: 'getZoomLevel',
getBoundary: 'getBoundary',
isBoundary: 'isBoundary',
zoomToActivateTime: 'zoomToActivateTime',
getStateChange: 'getStateChange',
}),
mc_dateTime() {
return (dateTime) => {
if (dateTime == null || dateTime === 'Invalid Date' || dateTime === '') return '';
return this.$dayjs(dateTime).format('YYYY-MM-DD HH:mm:ss');
};
},
mc_date() {
return (date) => {
if (date == null || date === 'Invalid Date' || date === '') return '';
return this.$dayjs(date).format('YYYY-MM-DD');
};
},
zoomToSee() {
return (index) => {
const div = index % 10;
switch (this.zoom) {
case 8:
return div < 2;
case 9:
return div < 4;
case 10:
return div < 6;
case 11:
return div < 8;
default:
return true;
}
};
},
},
methods: {
...mapActions('Drone/drone', {
setDroneLogs: 'setDroneLogs',
setSelectedLogList: 'setSelectedLogList',
setAccumulatedDistance: 'setAccumulatedDistance',
setSelectedDroneId: 'setSelectedDroneId',
}),
...mapActions('Drone/Map', {
clearStateChange: 'clearStateChange',
}),
connect() {
if (window.clientSocket == null || window.clientSocket?.readyState === 3) {
window.clientSocket = new WebSocket('ws://14.33.35.148:20206/drone');
window.clientSocket.onopen = () => {
console.log('socket on open');
};
window.clientSocket.onerror = () => {
console.log('socket on error');
};
window.clientSocket.onmessage = (data) => {
const logData = JSON.parse(data.data);
let logInfo = null;
const filterDroneLogs = logData.data.droneLog.filter((v, idx) => {
if (this.getSelectedDroneId && v.droneId === this.getSelectedDroneId) logInfo = v;
return this.isBoundary(v) && this.zoomToSee(idx);
});
if (this.socketOnGoing % this.zoomToActivateTime === 0 || this.getStateChange) {
this.setDroneLogs({ logs: filterDroneLogs, mutation: 'SET_DRONE_LOGS' });
this.setDroneLogs({ logs: logData.data.droneLog, mutation: 'SET_WHOLE_DRONE_LOGS' });
this.clearStateChange();
}
if (logInfo) {
this.setAccumulatedDistance(calcDistanceFromCoord(this.getSelectedLastLog, logInfo) || 0);
logInfo.angle = calcAngleFromCoord(this.getSelectedLastLog, logInfo) || 0;
logInfo.distance = this.getAccumulatedDistance;
this.setSelectedLogList(logInfo);
}
this.socketOnGoing += 1;
};
window.clientSocket.onclose = () => {
console.log('socket on close');
};
}
},
// connectMultiClient() {
// for (let j = 0; j < this.droneCnt * this.socketServerCnt; j += 1) {
// this.drones.push({ x: 0, y: 0 });
// }
// for (let i = 0; i < this.socketServerCnt; i += 1) {
// if (
// window[`wsSocket${i}`] == null
// || window[`wsSocket${i}`].readyState === 3
// ) {
// window[`wsSocket${i}`] = new WebSocket(
// 'ws://14.33.35.148:20206/drone',
// );
// window[`wsSocket${i}`].onopen = () => {
// console.log(`socket${i} on open`);
// };
// window[`wsSocket${i}`].onerror = (e) => {
// console.log(`socket${i} on error occur ${e}`);
// };
// window[`wsSocket${i}`].onmessage = (data) => {
// const logData = JSON.parse(data.data);
// console.log(
// `message${i} ${this.$dayjs().format('HH:mm:ss')} : `,
// logData.droneData,
// );
// setTimeout(() => {
// for (let k = 0; k < this.droneCnt; k += 1) {
// this.drones[i * (k + 1) + k].x = logData.droneData[k].x;
// this.drones[i * (k + 1) + k].y = logData.droneData[k].y;
// }
// }, 0);
// };
// window[`wsSocket${i}`].onclose = () => {
// console.log(`socket${i} closed`);
// };
// }
// }
// },
disconnect() {
if (window.clientSocket && window.clientSocket.readyState === 1) {
window.clientSocket.close();
window.clientSocket = null;
}
},
},
};