RingExtToExtNotificationHandler.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Hotline.Caching.Interfaces;
  2. using Hotline.CallCenter.Calls;
  3. using Hotline.Realtimes;
  4. using Hotline.Share.Dtos.Realtime;
  5. using Hotline.Share.Enums.CallCenter;
  6. using Hotline.Share.Notifications.NewRockCallCenter;
  7. using MediatR;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace Hotline.Application.Handlers.CallCenter.CallState
  14. {
  15. public class RingExtToExtNotificationHandler : INotificationHandler<RingExtToExtNotification>
  16. {
  17. private readonly IRealtimeService _realtimeService;
  18. private readonly IUserCacheManager _userCacheManager;
  19. public RingExtToExtNotificationHandler(IRealtimeService realtimeService,IUserCacheManager userCacheManager)
  20. {
  21. _realtimeService = realtimeService;
  22. _userCacheManager = userCacheManager;
  23. }
  24. public async Task Handle(RingExtToExtNotification notification, CancellationToken cancellationToken)
  25. {
  26. //通知前端主叫
  27. //获取主叫工作信息
  28. var fromWork = _userCacheManager.GetWorkByTel(notification.FromTelNo);
  29. if (fromWork != null)
  30. {
  31. await _realtimeService.RingAsync(fromWork.UserId, new RingDto() { Id = notification.FromTelNo, From = notification.FromTelNo, To = notification.ToTelNo, CallType = ECallType.ExtToExt }, cancellationToken);
  32. }
  33. //通知前端被叫
  34. var toWork = _userCacheManager.GetWorkByTel(notification.ToTelNo);
  35. if (toWork != null)
  36. {
  37. await _realtimeService.RingAsync(toWork.UserId, new RingDto() { Id = notification.ToTelNo, From = notification.FromTelNo, To = notification.ToTelNo, CallType = ECallType.ExtToExt }, cancellationToken);
  38. }
  39. }
  40. }
  41. }