Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
SatelliteDigital
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
nijiawen
SatelliteDigital
Commits
a38057f4
提交
a38057f4
authored
3月 09, 2026
作者:
zhuyongshuai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化websocket
上级
37d45d6d
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
84 行增加
和
18 行删除
+84
-18
requestSocekt.js
src/utils/requestSocekt.js
+84
-18
没有找到文件。
src/utils/requestSocekt.js
浏览文件 @
a38057f4
/*
// /*
* @Author: Z 1518051043@qq.com
// * @Author: Z 1518051043@qq.com
* @Date: 2025-12-01 13:52:20
// * @Date: 2025-12-01 13:52:20
* @LastEditors: zwy 1518051043@qq.com
// * @LastEditors: zwy 1518051043@qq.com
* @LastEditTime: 2026-01-21 13:08:28
// * @LastEditTime: 2026-01-21 13:08:28
* @FilePath: \yuanxinPro\src\utils\requestSocekt.js
// * @FilePath: \yuanxinPro\src\utils\requestSocekt.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
// * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
// */
import
HeartbeatInterval
from
'@/store/module/app.js'
// import useAppStore from '@/store/module/app.js'
// const apiUrl = `ws://121.229.107.155:19021/trackInfo`
// import { cs } from 'element-plus/es/locales.mjs';
const
apiUrl
=
`ws://121.229.107.155:19021/TestTimeSend`
// // const apiUrl = `ws://121.229.107.155:19021/trackInfo`
const
wss
=
new
WebSocket
(
apiUrl
);
// const apiUrl = `ws://121.229.107.155:19021/TestTimeSend`
// const wss = new WebSocket(apiUrl);
// const appStore = useAppStore()
// wss.onopen = () => {
// console.log('WebSocket已连接11');
// };
// wss.onmessage = (event) => {
// console.log('接收到消息:', event.data);
// };
// wss.onerror = (error) => {
// console.error('WebSocket错误:', error);
// };
// wss.onclose = () => {
// wss.onclose = () => {
// clearInterval(HeartbeatInterval);
// // console.log('主星级WebSocket正在重新连接, attempting reconnect...');
// //console.log('主星级WebSocket正在重新连接, attempting reconnect...');
// let timer = setTimeout(() => {
// setTimeout(() => {
// // 自动重连逻辑
// // 自动重连逻辑
// wss = new WebSocket(apiUrl);
// wss = new WebSocket(apiUrl);
// //console.log('主星级WebSocket...',wss);
// console.log('主星级WebSocket...',wss);
// clearTimeout(timer);
// }, 1000);
// }, 1000);
// };
// };
export
default
wss
;
// // wss.onclose = () => {
// // clearInterval(HeartbeatInterval);
// // //console.log('主星级WebSocket正在重新连接, attempting reconnect...');
// // setTimeout(() => {
// // // 自动重连逻辑
// // wss = new WebSocket(apiUrl);
// // //console.log('主星级WebSocket...',wss);
// // }, 1000);
// // };
// export default wss;
import
useAppStore
from
'@/store/module/app.js'
;
const
apiUrl
=
`ws://121.229.107.155:19021/TestTimeSend`
;
let
wss
=
null
;
let
timer
=
null
;
const
appStore
=
useAppStore
();
function
createWebSocket
()
{
wss
=
new
WebSocket
(
apiUrl
);
wss
.
onopen
=
()
=>
{
console
.
log
(
'WebSocket已连接'
);
};
wss
.
onmessage
=
(
event
)
=>
{
console
.
log
(
'接收到消息:'
,
event
.
data
);
};
wss
.
onerror
=
(
error
)
=>
{
console
.
error
(
'WebSocket错误:'
,
error
);
};
wss
.
onclose
=
()
=>
{
console
.
log
(
'连接关闭,1秒后重连...'
);
timer
=
setTimeout
(()
=>
{
wss
=
createWebSocket
();
// 重新创建连接
clearTimeout
(
timer
);
timer
=
null
;
//释放内存
},
1000
);
};
}
// 初始化连接
if
(
!
wss
||
wss
.
readyState
===
WebSocket
.
CLOSED
)
{
createWebSocket
();
}
export
default
wss
;
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论