From 6ed99bb6db9c37bd2392c0c54b7c1152246c9bbc Mon Sep 17 00:00:00 2001 From: giaogiao Date: Thu, 14 Sep 2023 10:08:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=80=E5=8F=91=E6=97=B6?= =?UTF-8?q?=E5=80=99=E7=9A=84ws=E8=BF=9E=E6=8E=A5=E5=92=8C=E6=89=93?= =?UTF-8?q?=E5=8C=85=E6=97=B6=E5=80=99=E7=9A=84ws=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 5 +++-- src/api/websocket.js | 5 ++++- src/components/DefaultSpeedDial.js | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/App.js b/src/App.js index cefd414..9382bd5 100644 --- a/src/App.js +++ b/src/App.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useCallback } from 'react'; +import React, {useRef, useState, useEffect, useCallback } from 'react'; import Home from "@/page/Home" import { DefaultSpeedDial } from "@/components/DefaultSpeedDial" @@ -11,10 +11,11 @@ export default function App() { const NotFound = () => { return
你来到了没有知识的荒原
} + const homemodule = useRef(null); return ( - } /> + } /> } /> } /> {/* } /> diff --git a/src/api/websocket.js b/src/api/websocket.js index d32e5f9..cd3212f 100644 --- a/src/api/websocket.js +++ b/src/api/websocket.js @@ -7,7 +7,10 @@ class ReactWebsocket { constructor() { //首次使用构造器实例 if (!ReactWebsocket.instance) { - this.ws=new WebSocket("ws://127.0.0.1:1323/ws"); + let agreement=window.location.protocol=="http:"?"ws://":"wss://" + let wsurl=agreement+window.location.host+'/ws' + let dev_ws_url="ws://127.0.0.1:1323/ws" + this.ws=new WebSocket(dev_ws_url); this.callbackMap= new Map(); this.noMessageSent= new Queue(); this.ws.onmessage=((evt)=>{this.OnMessage(evt)}) diff --git a/src/components/DefaultSpeedDial.js b/src/components/DefaultSpeedDial.js index 0a5ff51..f18b8a5 100644 --- a/src/components/DefaultSpeedDial.js +++ b/src/components/DefaultSpeedDial.js @@ -51,6 +51,8 @@ export function DefaultSpeedDial() { // socket.sendMessage('add', {name:NameValue,mac:MacValue}, function () { updata() }) socket.sendMessage('add', {name:NameValue,mac:MacValue}, function () { }) handleOpen() + setNameValue('') + setMacValue('') }); return ( @@ -90,7 +92,7 @@ export function DefaultSpeedDial() { > 取消 -