|
@@ -1,25 +1,25 @@
|
|
|
-const os = require('os');
|
|
|
|
|
|
|
+const os = require("os");
|
|
|
|
|
|
|
|
// 获取本机IP地址
|
|
// 获取本机IP地址
|
|
|
function getLocalIP() {
|
|
function getLocalIP() {
|
|
|
const interfaces = os.networkInterfaces();
|
|
const interfaces = os.networkInterfaces();
|
|
|
for (const iface of Object.values(interfaces)) {
|
|
for (const iface of Object.values(interfaces)) {
|
|
|
for (const config of iface) {
|
|
for (const config of iface) {
|
|
|
- if (config.family === 'IPv4' && !config.internal) {
|
|
|
|
|
|
|
+ if (config.family === "IPv4" && !config.internal) {
|
|
|
return config.address;
|
|
return config.address;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return '127.0.0.1';
|
|
|
|
|
|
|
+ return "127.0.0.1";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//数据格式
|
|
//数据格式
|
|
|
let theme = [
|
|
let theme = [
|
|
|
- { name: "空中成像", val: "历史" },
|
|
|
|
|
- { name: "文物互动墙", val: "历史" },
|
|
|
|
|
- { name: "透明展示柜A", val: "历史" },
|
|
|
|
|
- { name: "透明展示柜B", val: "历史" },
|
|
|
|
|
- { name: "AI数字人", val: "历史" },
|
|
|
|
|
|
|
+ { name: "空中成像", val: "历史", switch: "open" },
|
|
|
|
|
+ { name: "文物互动墙", val: "历史", switch: "open" },
|
|
|
|
|
+ { name: "透明展示柜A", val: "历史", switch: "open" },
|
|
|
|
|
+ { name: "透明展示柜B", val: "历史", switch: "open" },
|
|
|
|
|
+ { name: "AI数字人", val: "历史", switch: "open" },
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
// 通信数据格式
|
|
// 通信数据格式
|
|
@@ -52,7 +52,7 @@ let screen = [
|
|
|
// {type:'screen',data:{ name: "户外裸眼3D", val: "open" }'}
|
|
// {type:'screen',data:{ name: "户外裸眼3D", val: "open" }'}
|
|
|
|
|
|
|
|
const localIP = getLocalIP();
|
|
const localIP = getLocalIP();
|
|
|
-const port = 12345;
|
|
|
|
|
|
|
+const port = 8501;
|
|
|
|
|
|
|
|
const io = require("socket.io")(port, {
|
|
const io = require("socket.io")(port, {
|
|
|
pingInterval: 30005,
|
|
pingInterval: 30005,
|
|
@@ -63,12 +63,12 @@ const io = require("socket.io")(port, {
|
|
|
serveClient: true,
|
|
serveClient: true,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-console.log('Socket.IO 服务器已启动!');
|
|
|
|
|
-console.log('本机访问地址: http://localhost:' + port);
|
|
|
|
|
-console.log('局域网访问地址: http://' + localIP + ':' + port);
|
|
|
|
|
|
|
+console.log("Socket.IO 服务器已启动!");
|
|
|
|
|
+console.log("本机访问地址: http://localhost:" + port);
|
|
|
|
|
+console.log("局域网访问地址: http://" + localIP + ":" + port);
|
|
|
|
|
|
|
|
io.on("connection", (socket) => {
|
|
io.on("connection", (socket) => {
|
|
|
-console.log('✅ 用户通过 Socket.IO 连接成功:', socket.id);
|
|
|
|
|
|
|
+ console.log("✅ 用户通过 Socket.IO 连接成功:", socket.id);
|
|
|
|
|
|
|
|
io.emit("UpdateDeviceInfo", { type: "cut", data: theme });
|
|
io.emit("UpdateDeviceInfo", { type: "cut", data: theme });
|
|
|
io.emit("UpdateDeviceInfo", { type: "show", data: show });
|
|
io.emit("UpdateDeviceInfo", { type: "show", data: show });
|
|
@@ -82,21 +82,30 @@ console.log('✅ 用户通过 Socket.IO 连接成功:', socket.id);
|
|
|
val: name === "all" ? val : v.name === name ? val : v.val,
|
|
val: name === "all" ? val : v.name === name ? val : v.val,
|
|
|
}));
|
|
}));
|
|
|
// 然后向前端广播 数据 {type:'cut',data:theme}
|
|
// 然后向前端广播 数据 {type:'cut',data:theme}
|
|
|
- io.emit("UpdateDeviceInfo", { type: "cut", data: theme });
|
|
|
|
|
|
|
+ io.emit("UpdateDeviceInfo", { type: "cut", data: theme, code: 0 });
|
|
|
} else if (info.type === "show") {
|
|
} else if (info.type === "show") {
|
|
|
show = show.map((v) => ({
|
|
show = show.map((v) => ({
|
|
|
...v,
|
|
...v,
|
|
|
val: v.name === name ? val : v.val,
|
|
val: v.name === name ? val : v.val,
|
|
|
}));
|
|
}));
|
|
|
// 然后向前端广播 数据 {type:'show',data:show}
|
|
// 然后向前端广播 数据 {type:'show',data:show}
|
|
|
- io.emit("UpdateDeviceInfo", { type: "show", data: show });
|
|
|
|
|
|
|
+ io.emit("UpdateDeviceInfo", { type: "show", data: show, code: 0 });
|
|
|
} else if (info.type === "screen") {
|
|
} else if (info.type === "screen") {
|
|
|
screen = screen.map((v) => ({
|
|
screen = screen.map((v) => ({
|
|
|
...v,
|
|
...v,
|
|
|
val: v.name === name ? val : v.val,
|
|
val: v.name === name ? val : v.val,
|
|
|
}));
|
|
}));
|
|
|
// 然后向前端广播 数据 {type:'screen',data:screen}
|
|
// 然后向前端广播 数据 {type:'screen',data:screen}
|
|
|
- io.emit("UpdateDeviceInfo", { type: "screen", data: screen });
|
|
|
|
|
|
|
+ io.emit("UpdateDeviceInfo", { type: "screen", data: screen, code: 0 });
|
|
|
|
|
+ } else if (info.type === "switch") {
|
|
|
|
|
+ theme = theme.map((v) => ({
|
|
|
|
|
+ ...v,
|
|
|
|
|
+ switch: name === "all" ? val : v.name === name ? val : v.switch,
|
|
|
|
|
+ }));
|
|
|
|
|
+ // 然后向前端广播 数据 {type:'cut',data:theme}
|
|
|
|
|
+ io.emit("UpdateDeviceInfo", { type: "cut", data: theme, code: 0 });
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+
|