Signalr 信号恢复连接

Signalr 信号恢复连接,signalr,Signalr,如果后端服务器关闭,并在5分钟左右恢复,如何在不刷新客户端应用程序浏览器的情况下恢复连接 const connection=new signal.HubConnectionBuilder() .withUrl(`/place/${props.match.params.id}`) .withAutomaticReconnect() .build(); connection.on重新连接(函数(){ setError('连接丢失..'); var重新连接间隔=设置间隔(()=>{ if(conne

如果后端服务器关闭,并在5分钟左右恢复,如何在不刷新客户端应用程序浏览器的情况下恢复连接

const connection=new signal.HubConnectionBuilder()
.withUrl(`/place/${props.match.params.id}`)
.withAutomaticReconnect()
.build();
connection.on重新连接(函数(){
setError('连接丢失..');
var重新连接间隔=设置间隔(()=>{
if(connection.state==信号器.HubConnectionState.Disconnected){
连接。停止();
试一试{
log('尝试重新连接');
connection.start();
}捕获(e){
//不在这里,如果服务器仍然关闭,如何处理
console.log('重新连接失败');
}
}
}, 5000);
});这似乎有效

if (connection.state == signalR.HubConnectionState.Disconnected) {
                    connection.start()
                        .then(x => {
                            clearInterval(reconnectionInterval);
                            setError(null);
                        })
                        .catch(ex => setError('still disconnected'));
                }