52 lines
1.1 KiB
JavaScript
52 lines
1.1 KiB
JavaScript
import Client from "./ws";
|
|
|
|
export default function useWebsocket(store, path) {
|
|
// connect0(store);
|
|
connectPath(store, path);
|
|
}
|
|
|
|
const url = "ws://192.168.1.101:8082/QbMonitoring/websocket";
|
|
function connectPath(store, path) {
|
|
new Client(
|
|
{
|
|
url: url + path,
|
|
name: path,
|
|
},
|
|
(message) => {
|
|
try {
|
|
const data = JSON.parse(message.data);
|
|
|
|
if ("specificationChanges" in data) {
|
|
// 分屏推送1数据
|
|
store.updateData("1", data);
|
|
} else if ("deliveryNotification" in data) {
|
|
// 分屏推送3数据
|
|
store.updateData("3", data);
|
|
} else {
|
|
// 分屏推送2数据
|
|
store.updateData("2", data);
|
|
}
|
|
} catch (err) {
|
|
console.log("[x] 未解析的ws数据: ", err);
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
function connect0(store) {
|
|
new Client(
|
|
{
|
|
url: url + "/0",
|
|
name: "/0",
|
|
},
|
|
(message) => {
|
|
try {
|
|
const data = JSON.parse(message.data);
|
|
console.log("message --- 0 ---> ", JSON.parse(message.data));
|
|
} catch (err) {
|
|
console.log("[x] 未解析的ws数据: ", err);
|
|
}
|
|
}
|
|
);
|
|
}
|