How to determine server disconnection from SignalR client?

前端 未结 6 710
Happy的楠姐
Happy的楠姐 2020-12-28 14:45

The question is how can SignalR JavaScript client detect when connection with server is lost?

Thanks for any reply!

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-28 15:05

    Starting with SignalR v0.5.1 it works this way:

    $.connection.hub.stateChanged(function (change) {
        if (change.newState === $.signalR.connectionState.reconnecting) {
            console.log("liveFeed is reconnecting!");
        }
        else if (change.newState === $.signalR.connectionState.connected) {
            console.log("liveFeed is connected!");
        }
    });
    

    For more details check this website:

    http://weblogs.asp.net/davidfowler/archive/2012/06/10/signalr-0-5-1-released.aspx

提交回复
热议问题