locked
How to notify the user about disconnections? RRS feed

  • Question

  • User1152062383 posted

    I need some help figuring out how to let our users know the connection is disconnected. I'm using the latest version 2.2.2

    I read this https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/handling-connection-lifetime-events#notifydisconnect

    However none of these events are being fired.  I took it a step further and put logging on all the events I could yet none of them are being called the connection drops.

    $.connection.hub.connectionSlow = RealTimeInboxConnectionSlow;
    $.connection.hub.reconnecting = RealTimeInboxReconnecting;
    $.connection.hub.reconnected = RealTimeInboxReconnected;
    $.connection.hub.disconnected = RealTimeInboxDisconnected;
    $.connection.hub.stateChanged = function () { RealTimeInboxSignalRConsoleLog("StateChange"); };
    $.connection.hub.error(function (error) { RealTimeInboxSignalRConsoleLog('Error: ' + error) });
    $.connection.hub.received(function (data) { RealTimeInboxSignalRConsoleLog('Received: ' +JSON.stringify(data)) });
    $.connection.hub.logging = true;

    This is What I see in the browser console when the app pool is stopped is a loop of trying to reconnect 

    14:36:16 GMT-0700 (US Mountain Standard Time)] SignalR: EventSource readyState: 0.

    [14:36:16 GMT-0700 (US Mountain Standard Time)] SignalR: EventSource reconnecting due to the server connection ending.

    [14:36:18 GMT-0700 (US Mountain Standard Time)] SignalR: EventSource calling close().

    [14:36:18 GMT-0700 (US Mountain Standard Time)] SignalR: serverSentEvents reconnecting.

    14:36:18 GMT-0700 (US Mountain Standard Time)] SignalR: Attempting to connect to SSE endpoint

    [14:36:18 GMT-0700 (US Mountain Standard Time)] SignalR: EventSource readyState: 2.

    [14:36:18 GMT-0700 (US Mountain Standard Time)] SignalR: EventSource reconnecting due to the server connection ending.

    [14:36:20 GMT-0700 (US Mountain Standard Time)] SignalR: EventSource calling close().

    Over and Over again.

    I reported this as a issue on github but I dont see how I can be the only one facing this problem.

    Any one have any suggustions?

    I am using SSE, forever frames, and long polling (we dont have the newer version of Windows so we cant use winsockets)

    Thursday, June 15, 2017 9:44 PM

Answers

  • User1152062383 posted

    A co-worker finally pointed me to the problem I was overriding the handlers instead of passing my function to them 

    $.connection.hub.disconnected = RealTimeInboxDisconnected;

    vs

    $.connection.hub.disconnected( RealTimeInboxDisconnected);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 16, 2017 7:24 PM

All replies

  • User-271186128 posted

    Hi jakeb16,

    However none of these events are being fired.  I took it a step further and put logging on all the events I could yet none of them are being called the connection drops.

    Try to use the following code, I test it on my side, it seems that the disconnected event works well on my side:

                $.connection.hub.disconnected(function () {
                    alert("disconnected");
                });

    Best regards,
    Dillion

    Friday, June 16, 2017 5:12 AM
  • User1152062383 posted

    Thank you for your quick response, I already tried that method and I even tried that exact code and its not triggering when I stop the app pool for example. Could something be conflicting with just these events? When its connected everything works great.

    Friday, June 16, 2017 4:40 PM
  • User1152062383 posted

    A co-worker finally pointed me to the problem I was overriding the handlers instead of passing my function to them 

    $.connection.hub.disconnected = RealTimeInboxDisconnected;

    vs

    $.connection.hub.disconnected( RealTimeInboxDisconnected);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 16, 2017 7:24 PM