Search code examples
javascriptasp.net-coreconnectionsignalrasp.net-core-signalr

Detect lost connection from SignalR Core connection


I'm trying to detect when a SignalR Core connection is lost so that I can create a new one or at least warn the user.

connection.on('closed', data => {
    alert('Connection Closed');
});

This seems to have no effect. The messages stop arriving but this handler isn't fired.

On a related note, where is the documentation for event handling for the new version of this library?


Solution

  • Use onclose:

    connection.onclose(function (e) {
        alert('Connection Closed');
    }
    

    There's no documentation yet, but a handful of samples on GitHub.