16K Star 16.2K Fork 3.8K

zuohuaijun/Admin.NET

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
signalR.ts 1.18 KB
一键复制 编辑 原始数据 按行查看 历史
import * as SignalR from '@microsoft/signalr';
import { ElNotification } from 'element-plus';
import { getToken } from '/@/utils/axios-utils';
// 初始化SignalR对象
const connection = new SignalR.HubConnectionBuilder()
.configureLogging(SignalR.LogLevel.Information)
.withUrl(`${window.__env__.VITE_API_URL}/hubs/onlineUser?token=${getToken()}`, { transport: SignalR.HttpTransportType.WebSockets, skipNegotiation: true })
.withAutomaticReconnect({
nextRetryDelayInMilliseconds: () => {
return 5000; // 每5秒重连一次
},
})
.build();
connection.keepAliveIntervalInMilliseconds = 15 * 1000; // 心跳检测15s
connection.serverTimeoutInMilliseconds = 30 * 60 * 1000; // 超时时间30m
// 启动连接
connection.start().then(() => {
console.log('启动连接');
});
// 断开连接
connection.onclose(async () => {
console.log('断开连接');
});
// 重连中
connection.onreconnecting(() => {
ElNotification({
title: '提示',
message: '服务器已断线...',
type: 'error',
position: 'bottom-right',
});
});
// 重连成功
connection.onreconnected(() => {
console.log('重连成功');
});
connection.on('OnlineUserList', () => {});
export { connection as signalR };
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/zuohuaijun/Admin.NET.git
git@gitee.com:zuohuaijun/Admin.NET.git
zuohuaijun
Admin.NET
Admin.NET
next

搜索帮助