SignaIr 了解连接已在服务器端结束

SignaIr Understanding that the connection has ended on the server side

signaIr 中的这个套接字 io 代码等效于什么?

socket.on('disconnect', () => {
    count--;
    io.emit('disUser', count);
    console.log('user disconnected');
})

请记住,SignalR 使用 'hubs' 的想法,这使得 socket.io 的翻译有点混乱。这是 SignalR 代码:

public class MyHub : Hub
{
    public override async Task OnDisconnectedAsync(Exception exception)
    {
        count--;
        await Clients.All.SendAsync("disUser", count);
        Console.WriteLine("user disconnected");
        await base.OnDisconnectedAsync(exception);
    }
}

可在此处找到处理连接事件的文档:

https://docs.microsoft.com/en-us/aspnet/core/signalr/hubs?view=aspnetcore-3.1#handle-events-for-a-connection