修改WebSocket地址从nginx中读取
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
// 处理连接成功事件
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user