Detect lost connection from SignalR Core connectio

2019-07-11 18:58发布

问题:

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?

回答1:

Use onclose:

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

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