增加开发时候的ws连接和打包时候的ws连接

This commit is contained in:
giaogiao 2023-09-14 10:08:35 +08:00
parent 85c6a22c05
commit 6ed99bb6db
3 changed files with 10 additions and 4 deletions

View File

@ -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 <div>你来到了没有知识的荒原</div>
}
const homemodule = useRef(null);
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/" element={<Home ref={homemodule} />} />
<Route path="/home" element={<Home />} />
<Route path="/NotFound" element={<NotFound />} />
{/* <Route path="/about" element={<About />} />

View File

@ -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)})

View File

@ -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() {
>
<span>取消</span>
</Button>
<Button variant="gradient" color="green" onClick={handleOpen}>
<Button variant="gradient" color="green" onClick={AddItemClick}>
<span>确认</span>
</Button>
</DialogFooter>