|
|
@@ -0,0 +1,57 @@
|
|
|
+import axios from "axios"
|
|
|
+import { WebSocket } from "ws"
|
|
|
+import { setTimeout } from "timers/promises"
|
|
|
+const {
|
|
|
+ data: { access_token }
|
|
|
+} = await axios.post("http://8.149.128.251/api/auth/admin/login", {
|
|
|
+ username: "admin",
|
|
|
+ password: "r&po^a9$Nc2AP9",
|
|
|
+ code: "123123",
|
|
|
+ bindingCode: ""
|
|
|
+})
|
|
|
+const axiosInstance = axios.create({
|
|
|
+ // baseURL: "http://47.98.225.28/api",
|
|
|
+ // headers: {
|
|
|
+ // Authorization: `Bearer ${access_token}`
|
|
|
+ // }
|
|
|
+ baseURL: "http://8.149.128.251/api",
|
|
|
+ headers: {
|
|
|
+ Authorization: `Bearer ${access_token}`
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+const {
|
|
|
+ data: { items: devices }
|
|
|
+} = await axiosInstance.post("/device", {
|
|
|
+ page: { page: 1, limit: 1000 },
|
|
|
+ search: { where: { online: true }, order: { name: "ASC" } }
|
|
|
+})
|
|
|
+
|
|
|
+const ws = new WebSocket("ws://121.40.132.44:6001")
|
|
|
+let xwDevices = []
|
|
|
+ws.onopen = async () => {
|
|
|
+ console.log("Connected to WebSocket")
|
|
|
+
|
|
|
+ await setTimeout(2000)
|
|
|
+ let i = 0
|
|
|
+ for (let device of devices) {
|
|
|
+ ws.send(
|
|
|
+ JSON.stringify({
|
|
|
+ action: "updateDevices",
|
|
|
+ devices: device.ip + ":5555",
|
|
|
+ data: {
|
|
|
+ sort: i++ + 600,
|
|
|
+ name: device.name
|
|
|
+ }
|
|
|
+ })
|
|
|
+ )
|
|
|
+ await setTimeout(100)
|
|
|
+ }
|
|
|
+}
|
|
|
+ws.onmessage = e => {
|
|
|
+ const data = JSON.parse(e.data)
|
|
|
+ if (data.code === 10000 && data.data instanceof Array) {
|
|
|
+ xwDevices = data.data
|
|
|
+ console.log("found " + xwDevices.length + " devices")
|
|
|
+ }
|
|
|
+}
|