You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

  1. using JT1078.SignalR.Test.Services;
  2. using Microsoft.AspNetCore.SignalR;
  3. using Microsoft.Extensions.Logging;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Security.Claims;
  8. using System.Text.Json;
  9. using System.Threading.Tasks;
  10. namespace JT1078.SignalR.Test.Hubs
  11. {
  12. public class FMp4Hub : Hub
  13. {
  14. private readonly ILogger logger;
  15. private readonly WsSession wsSession;
  16. public FMp4Hub(
  17. WsSession wsSession,
  18. ILoggerFactory loggerFactory)
  19. {
  20. this.wsSession = wsSession;
  21. logger = loggerFactory.CreateLogger<FMp4Hub>();
  22. }
  23. public override Task OnConnectedAsync()
  24. {
  25. if (logger.IsEnabled(LogLevel.Debug))
  26. {
  27. logger.LogDebug($"链接上:{Context.ConnectionId}");
  28. }
  29. wsSession.TryAdd(Context.ConnectionId);
  30. return base.OnConnectedAsync();
  31. }
  32. public override Task OnDisconnectedAsync(Exception exception)
  33. {
  34. if (logger.IsEnabled(LogLevel.Debug))
  35. {
  36. logger.LogDebug($"断开链接:{Context.ConnectionId}");
  37. }
  38. wsSession.TryRemove(Context.ConnectionId);
  39. return base.OnDisconnectedAsync(exception);
  40. }
  41. }
  42. }