修改WebSocket地址从nginx中读取

This commit is contained in:
GGJ
2025-04-14 11:13:18 +08:00
parent 1232322eb4
commit 7558f23c71
2 changed files with 12 additions and 8 deletions

View File

@@ -38,19 +38,23 @@ export default class SocketService {
}
// 定义连接服务器的方法
public connect(id: string): void {
public async connect(id: string) {
if (!window.WebSocket) {
console.log('您的浏览器不支持WebSocket')
return
}
const url = 'ws://192.168.1.67:10407/api/pushMessage/' + id
this.ws = new WebSocket(url)
const response = await fetch('/')
const mqttUrl = response.headers.get('X-Mqtt-Url')
setTimeout(() => {
const url = (mqttUrl || 'ws://192.168.1.67:10407/api/pushMessage/') + id
this.ws = new WebSocket(url)
this.ws.onopen = () => this.handleOpen()
this.ws.onclose = () => this.handleClose()
this.ws.onerror = () => this.handleError()
this.ws.onmessage = event => this.handleMessage(event)
this.ws.onopen = () => this.handleOpen()
this.ws.onclose = () => this.handleClose()
this.ws.onerror = () => this.handleError()
this.ws.onmessage = event => this.handleMessage(event)
}, 0)
}
// 处理连接成功事件

View File

@@ -73,7 +73,7 @@ import Shishishuju from './shishishuju/index.vue'
import router from '@/router'
defineOptions({
name: 'harmonic-boot/monitor/online'
// name: 'harmonic-boot/monitor/online'
})
const monitoringPoint = useMonitoringPoint()