feat: 测试
This commit is contained in:
@@ -27,31 +27,34 @@ import testmpkv from "../../images/test.mp4";
|
|||||||
|
|
||||||
const Index = () => {
|
const Index = () => {
|
||||||
// ws://(或者 wss:// 对于 HTTPS 环境
|
// ws://(或者 wss:// 对于 HTTPS 环境
|
||||||
const [message, setMessage] = useState('11');
|
const [message, setMessage] = useState("");
|
||||||
|
const [messageArr, setMessageArr] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 创建 WebSocket 连接
|
// 创建 WebSocket 连接
|
||||||
const socket = new WebSocket('ws://127.0.0.1:8888'); // 注意使用 ws://
|
const socket = new WebSocket("ws://127.0.0.1:8888"); // 注意使用 ws://
|
||||||
|
|
||||||
// WebSocket 打开时触发
|
// WebSocket 打开时触发
|
||||||
socket.onopen = () => {
|
socket.onopen = () => {
|
||||||
console.log('WebSocket 连接已建立');
|
console.log("WebSocket 连接已建立");
|
||||||
socket.send('Hello from the client!');
|
// socket.send('Hello from the client!');
|
||||||
};
|
};
|
||||||
|
|
||||||
// WebSocket 接收到消息时触发
|
// WebSocket 接收到消息时触发
|
||||||
socket.onmessage = (event) => {
|
socket.onmessage = (event) => {
|
||||||
console.log('接收到消息:', event.data);
|
console.log("接收到消息:", event.data);
|
||||||
setMessage(event.data); // 更新消息状态
|
setMessage(event.data); // 更新消息状态
|
||||||
|
setMessageArr((messageArr) => [event.data,...messageArr]); // 更新消息数组
|
||||||
};
|
};
|
||||||
|
|
||||||
// WebSocket 关闭时触发
|
// WebSocket 关闭时触发
|
||||||
socket.onclose = () => {
|
socket.onclose = () => {
|
||||||
console.log('WebSocket 连接已关闭');
|
console.log("WebSocket 连接已关闭");
|
||||||
};
|
};
|
||||||
|
|
||||||
// WebSocket 错误时触发
|
// WebSocket 错误时触发
|
||||||
socket.onerror = (error) => {
|
socket.onerror = (error) => {
|
||||||
console.error('WebSocket 错误:', error);
|
console.error("WebSocket 错误:", error);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 清理 WebSocket 连接
|
// 清理 WebSocket 连接
|
||||||
@@ -60,7 +63,6 @@ const Index = () => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
// TTS播放语言
|
// TTS播放语言
|
||||||
const speak = (text) => {
|
const speak = (text) => {
|
||||||
const synth = window.speechSynthesis;
|
const synth = window.speechSynthesis;
|
||||||
@@ -99,9 +101,18 @@ const Index = () => {
|
|||||||
// speak("欢迎使用"); // 语音播报
|
// speak("欢迎使用"); // 语音播报
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// 在线测试地址
|
||||||
|
// http://wstool.jackxiang.com/
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View className="index">
|
<View className="index">
|
||||||
<View>{message}</View>
|
<View className="messageArr">
|
||||||
|
{messageArr.map((item, index) => (
|
||||||
|
<View key={index} className="message_item">
|
||||||
|
{item}
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
{/* <View className="index_backImg">
|
{/* <View className="index_backImg">
|
||||||
<Image className="index_backImg_bg" mode={"scaleToFill"} src={iphone} />
|
<Image className="index_backImg_bg" mode={"scaleToFill"} src={iphone} />
|
||||||
</View> */}
|
</View> */}
|
||||||
|
|||||||
@@ -4,13 +4,24 @@
|
|||||||
// overflow: hidden; // 防止溢出
|
// overflow: hidden; // 防止溢出
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
// align-items: center;
|
||||||
justify-content: center;
|
// justify-content: center;
|
||||||
// background-image: url('../../images/iphone.jpg');
|
// background-image: url('../../images/iphone.jpg');
|
||||||
// background-size: cover; // 拉伸铺满容器
|
// background-size: cover; // 拉伸铺满容器
|
||||||
// background-position: center; // 居中
|
// background-position: center; // 居中
|
||||||
// background-repeat: no-repeat; // 不重复
|
// background-repeat: no-repeat; // 不重复
|
||||||
|
|
||||||
|
.messageArr{
|
||||||
|
padding: 40px;
|
||||||
|
font-size: 30px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
.message_item{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.index_backImg {
|
.index_backImg {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@@ -55,12 +66,26 @@
|
|||||||
transform-origin: top left;
|
transform-origin: top left;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
// align-items: center;
|
||||||
justify-content: center;
|
// justify-content: center;
|
||||||
background-image: url('../../images/iphone.jpg');
|
background-image: url('../../images/iphone.jpg');
|
||||||
background-size: cover; // 拉伸铺满容器
|
background-size: cover; // 拉伸铺满容器
|
||||||
background-position: center; // 居中
|
background-position: center; // 居中
|
||||||
background-repeat: no-repeat; // 不重复
|
background-repeat: no-repeat; // 不重复
|
||||||
|
color: white;
|
||||||
|
|
||||||
|
.messageArr{
|
||||||
|
// padding: 40px;
|
||||||
|
font-size: 40px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
.message_item{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.index_backImg {
|
.index_backImg {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
Reference in New Issue
Block a user