123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- using JsonRpcLite.Rpc;
- using System;
- using System.Collections.Generic;
- using Vinno.IUS.Common.Log;
- using Vinno.vCloud.Common.FIS.Remedicals;
- using Vinno.vCloud.FIS.CrossPlatform.Common;
- using Vinno.vCloud.FIS.CrossPlatform.Common.Enum;
- using Vinno.vCloud.FIS.CrossPlatform.Common.LiveVideo;
- using Vinno.vCloud.Protocol.Infrastructures;
- using WingInterfaceLibrary.DTO.Device;
- using WingInterfaceLibrary.Interface;
- using WingInterfaceLibrary.LiveConsultation;
- namespace Vinno.vCloud.Common.FIS.Consultation
- {
- internal class ConsultationV2 : IConsultationV2
- {
- private readonly string _deviceId;
- private readonly JsonRpcClient _client;
- private readonly string _deviceToken;
- private bool _disposed;
- public string ConsultationUrl { get; private set; }
- /// <summary>
- /// device image frame arrived
- /// </summary>
- public event EventHandler<CPVideoFrameData> UltrasoundImageFrameArrived;
- /// <summary>
- /// device camera frame arrived
- /// </summary>
- public event EventHandler<CPVideoFrameData> UltrasoundCameraFrameArrived;
- /// <summary>
- /// Local camera video frame arrived only for consultation
- /// </summary>
- public event EventHandler<ConsultationVideoFrameData> ConsultationLocalVideoFrameArrived;
- /// <summary>
- /// Remote camera frame arrived only for consultation
- /// </summary>
- public event EventHandler<ConsultationVideoFrameData> ConsultationRemoteVideoFrameArrived;
- /// <summary>
- /// Raised when receive a consultation request from server.
- /// </summary>
- public event EventHandler<ConsultationInfo> ConsultationRequestArrived;
- /// <summary>
- /// Raised when the consultation is disconnect.
- /// </summary>
- public event EventHandler<ConsultationDisconnectedType> ConsultationDisconnected;
- /// <summary>
- /// Raised when consultation Member Changed
- /// </summary>
- public event EventHandler<ConsultationMemberNotificaiton> ConsultationMemberChangedNotificationArrived;
- /// <summary>
- /// The consultation recipient
- /// </summary>
- public ConsultationRecipientV2 ConsultationRecipient { get; }
- /// <summary>
- /// Chat live video provider, handle different video
- /// </summary>
- public ConsultationLiveVideoProviderV2 ConsultationLiveVideoProvider { get; }
- public ConsultationManagerV2 ConsultationManager { get; }
- /// <summary>
- /// 接收到其他用户的白板信息
- /// </summary>
- public event EventHandler<InteractiveBoardInfo> InteractiveBoardInfoArrived;
- /// <summary>
- /// 接收到清除白板信息
- /// </summary>
- public event EventHandler<string> ClearInteractiveBoardArrived;
- /// <summary>
- /// 收到关闭摄像头的通知
- /// </summary>
- public event EventHandler<List<string>> MuteVideoUserListNotifyArrived;
- /// <summary>
- /// 通知切换到本地病人,当vCloudExamInfo的ExamPairInfo的PatientIdInUSMachine为空时需先创建病人及检查,否则直接跳到该病人。
- /// </summary>
- public event EventHandler<vCloudExamInfo> SwitchToLocalPatientEvent;
- /// <summary>
- /// 当开始Web会诊时
- /// </summary>
- public event EventHandler<string> StartWebConsultationEvent;
- /// <summary>
- /// 当切换病人时触发,病人信息与会诊code变更
- /// </summary>
- public event EventHandler<ChangeLiveConsultationrResult> ChangeLiveConsultationEvent;
- /// <summary>
- /// 当扫查手法摄像头开启或关闭时触发
- /// </summary>
- public event EventHandler<TerminalInfo> TerminalInfoChangedEvent;
- public ConsultationV2(JsonRpcClient client, string token, CacheDeviceDTO deviceInfo)
- {
- if (!string.IsNullOrEmpty(vCloudServerConfig.Instance.FISWebUrl))
- {
- ConsultationUrl = vCloudServerConfig.Instance.FISWebUrl + "#/login/";
- }
- _deviceId = deviceInfo?.DeviceCode;
- _client = client;
- _deviceToken = token;
- var liveConsultationService = _client?.CreateProxy<ILiveConsultationService>();
- var userService = _client?.CreateProxy<IUserService>();
- var deviceService = _client?.CreateProxy<IDeviceService>();
- var organizationService = _client?.CreateProxy<IOrganizationService>();
- ConsultationLiveVideoProvider = new ConsultationLiveVideoProviderV2(liveConsultationService, organizationService);
- ConsultationLiveVideoProvider.OnTRTCRoomEnterError += OnTRTCRoomEnterErrorHappened;
- ConsultationLiveVideoProvider.ConsultationLocalVideoFrameArrived += OnConsultationLocalVideoFrameArrived;
- ConsultationLiveVideoProvider.ConsultationRemoteVideoFrameArrived += OnConsultationRemoteVideoFrameArrived;
- ConsultationLiveVideoProvider.DeviceCameraFrameArrived += OnUltrasoundCameraFrameArrived;
- ConsultationManager = new ConsultationManagerV2(liveConsultationService);
- ConsultationManager.SwitchToLocalPatientEvent += OnSwitchToLocalPatientEvent;
- ConsultationRecipient = new ConsultationRecipientV2(ConsultationLiveVideoProvider, ConsultationManager, _deviceId, liveConsultationService, userService, deviceService);
- ConsultationRecipient.ConsultationDisconnected += OnConsultationDisconnected;
- ConsultationRecipient.ConsultationRequestArrived += OnConcultationRequestArrived;
- ConsultationRecipient.ConsultationMemberChangedNotificationArrived += OnConsultationMemberChangedNotificationArrived;
- ConsultationRecipient.InteractiveBoardInfoArrived += OnInteractiveBoardInfoArrived;
- ConsultationRecipient.ClearInteractiveBoardArrived += OnClearInteractiveBoardArrived;
- ConsultationRecipient.MuteVideoUserListNotifyArrived += OnMuteVideoUserListNotifyArrived;
- ConsultationRecipient.StartWebConsultationEvent += OnStartWebConsultationEvent;
- ConsultationRecipient.ChangeLiveConsultationEvent += OnChangeLiveConsultationEvent;
- ConsultationRecipient.TerminalInfoChangedEvent += OnTerminalInfoChangedEvent;
- }
- private void OnTerminalInfoChangedEvent(object sender, TerminalInfo e)
- {
- TerminalInfoChangedEvent?.Invoke(this, e);
- }
- private void OnStartWebConsultationEvent(object sender, string e)
- {
- StartWebConsultationEvent?.Invoke(this, e);
- }
- private void OnSwitchToLocalPatientEvent(object sender, vCloudExamInfo e)
- {
- SwitchToLocalPatientEvent?.Invoke(this, e);
- }
- private void OnMuteVideoUserListNotifyArrived(object sender, List<string> muteVideoUserList)
- {
- MuteVideoUserListNotifyArrived?.Invoke(this, muteVideoUserList);
- }
- private void OnInteractiveBoardInfoArrived(object sender, InteractiveBoardInfo e)
- {
- InteractiveBoardInfoArrived?.Invoke(this, e);
- }
- private void OnClearInteractiveBoardArrived(object sender, string e)
- {
- ClearInteractiveBoardArrived?.Invoke(this, e);
- }
- /// <summary>
- /// Gets the live states of the current chat.
- /// </summary>
- /// <returns></returns>
- public LiveStates GetCurrentConsultationLiveStates()
- {
- return ConsultationRecipient.CurrentLiveStatus;
- }
- /// <summary>
- /// Dispose consultation
- /// </summary>
- public void Dispose()
- {
- DoDispose();
- GC.SuppressFinalize(this);
- }
- private void DoDispose()
- {
- if (!_disposed)
- {
- var consultationtatus = GetCurrentConsultationLiveStates();
- var isConsultation = consultationtatus == LiveStates.RecipientAcceptted
- || consultationtatus == LiveStates.ChatRequestArrived
- || consultationtatus == LiveStates.InitiatorRequestingChat
- || consultationtatus == LiveStates.RecipientAcceptting;
- if (isConsultation)
- {
- HangupLiveConsultationFromFlutter(true);
- }
- ConsultationLiveVideoProvider.OnTRTCRoomEnterError -= OnTRTCRoomEnterErrorHappened;
- ConsultationLiveVideoProvider.ConsultationLocalVideoFrameArrived -= OnConsultationLocalVideoFrameArrived;
- ConsultationLiveVideoProvider.ConsultationRemoteVideoFrameArrived -= OnConsultationRemoteVideoFrameArrived;
- ConsultationLiveVideoProvider.DeviceCameraFrameArrived -= OnUltrasoundCameraFrameArrived;
- ConsultationLiveVideoProvider.Dispose();
- ConsultationRecipient.ConsultationDisconnected -= OnConsultationDisconnected;
- ConsultationRecipient.ConsultationRequestArrived -= OnConcultationRequestArrived;
- ConsultationRecipient.ConsultationMemberChangedNotificationArrived -= OnConsultationMemberChangedNotificationArrived;
- ConsultationRecipient.InteractiveBoardInfoArrived -= OnInteractiveBoardInfoArrived;
- ConsultationRecipient.ClearInteractiveBoardArrived -= OnClearInteractiveBoardArrived;
- ConsultationRecipient.MuteVideoUserListNotifyArrived -= OnMuteVideoUserListNotifyArrived;
- ConsultationRecipient.StartWebConsultationEvent -= OnStartWebConsultationEvent;
- ConsultationRecipient.ChangeLiveConsultationEvent -= OnChangeLiveConsultationEvent;
- ConsultationRecipient.TerminalInfoChangedEvent -= OnTerminalInfoChangedEvent;
- ConsultationRecipient.Dispose();
- ConsultationManager.SwitchToLocalPatientEvent -= OnSwitchToLocalPatientEvent;
- ConsultationManager.Dispose();
- _disposed = true;
- }
- }
- private void OnChangeLiveConsultationEvent(object sender, ChangeLiveConsultationrResult e)
- {
- ChangeLiveConsultationEvent?.Invoke(this, e);
- }
- private void OnConcultationRequestArrived(object sender, ConsultationInfo e)
- {
- CrossPlatformHelper.Instance.HardwareDetector.StopCameraPreview();
- ConsultationRequestArrived?.Invoke(this, e);
- }
- private void OnConsultationMemberChangedNotificationArrived(object sender, ConsultationMemberNotificaiton e)
- {
- ConsultationMemberChangedNotificationArrived?.Invoke(this, e);
- }
- private void OnTRTCRoomEnterErrorHappened(object sender, EnumTRTCRoomError e)
- {
- Logger.WriteLineError($"Consultation TRTCRoomEnterErrorHappened:{e}");
- }
- private void OnUltrasoundCameraFrameArrived(object sender, CPVideoFrameData e)
- {
- UltrasoundCameraFrameArrived?.Invoke(this, e);
- }
- private void OnConsultationRemoteVideoFrameArrived(object sender, ConsultationVideoFrameData e)
- {
- ConsultationRemoteVideoFrameArrived?.Invoke(this, e);
- }
- private void OnConsultationLocalVideoFrameArrived(object sender, ConsultationVideoFrameData e)
- {
- ConsultationLocalVideoFrameArrived?.Invoke(this, e);
- }
- private void OnConsultationDisconnected(object sender, ConsultationDisconnectedType e)
- {
- ConsultationDisconnected?.Invoke(this, e);
- }
- public ResultInfoDTO StartLiveConsultationFromFlutter(LiveConsultationRequestDTO liveConsultationRequestDTO, string cameraId, string micId, string speakerId)
- {
- if (liveConsultationRequestDTO == null)
- {
- return new ResultInfoDTO
- {
- IsSuccess = false,
- FailMessage = "ConsultationV2 StartLiveConsultationFromFlutter Fail:Args is null",
- };
- }
- return ConsultationRecipient.StartLiveConsultation(liveConsultationRequestDTO, cameraId, micId, speakerId);
- }
- public ResultInfoDTO StartLiveConsultationFromFlutter(StartOnlyForRtmpPushingDTO startOnlyForRtmpPushingDTO, string cameraId, string micId)
- {
- if (startOnlyForRtmpPushingDTO == null)
- {
- return new ResultInfoDTO
- {
- IsSuccess = false,
- FailMessage = "ConsultationV2 StartLiveConsultationFromFlutter Fail:Args is null",
- };
- }
- return ConsultationRecipient.StartLiveConsultation(startOnlyForRtmpPushingDTO, cameraId, micId);
- }
- public string GetUserInfo(string token)
- {
- return ConsultationRecipient.GetUserInfo(token);
- }
- public ResultInfoDTO HangupLiveConsultationFromFlutter(bool isInteractiveExit)
- {
- var result = ConsultationRecipient.Hangup();
- if (isInteractiveExit)
- {
- OnConsultationDisconnected(this, ConsultationDisconnectedType.HangUpBySelf);
- }
- else
- {
- OnConsultationDisconnected(this, ConsultationDisconnectedType.HangupByOther);
- }
- return result;
- }
- /// <summary>
- /// 切换会诊病人
- /// </summary>
- /// <param name="changeLiveConsultation0RequestDTO"></param>
- /// <returns></returns>
- public ResultInfoDTO ChangeLiveConsultationFromFlutter(ChangeLiveConsultationRequestDTO changeLiveConsultation0RequestDTO)
- {
- return ConsultationRecipient.ChangeLiveConsultation(changeLiveConsultation0RequestDTO);
- }
- public ResultInfoDTO SwitchToLocalPatientFromFlutter(SwitchToLocalPatientRequestDTO switchToLocalPatientRequestDTO)
- {
- return ConsultationManager.SwitchToLocalPatientFromFlutter(switchToLocalPatientRequestDTO);
- }
- /// <summary>
- /// 上报本地与云端病人的关联信息
- /// </summary>
- /// <param name="patientPairInfo"></param>
- /// <returns></returns>
- public bool UpdatePatientPairInfo(PatientPairInfo patientPairInfo)
- {
- return ConsultationManager.UpdatePatientPairInfo(patientPairInfo);
- }
- public ResultInfoDTO LiveConsultationMemberChangedFromFlutter(ConsultationMemberChangeDTO consultationMemberChangeDTO)
- {
- return ConsultationRecipient.LiveConsultationMemberChanged(consultationMemberChangeDTO);
- }
- /// <summary>
- /// 当收到白板信息的时候
- /// </summary>
- /// <param name="whiteBoardDataDTO"></param>
- /// <returns></returns>
- public ResultInfoDTO ReceiveWhiteBoardDataFromFlutter(WhiteBoardDataDTO whiteBoardDataDTO)
- {
- return ConsultationRecipient.ReceiveWhiteBoardData(whiteBoardDataDTO);
- }
- public ResultInfoDTO SendFlutterLiveConsultationInfo(FlutterLiveConsultationInfo flutterLiveConsultationInfo)
- {
- if (flutterLiveConsultationInfo == null)
- {
- Logger.WriteLineError($"SendFlutterLiveConsultationInfo Error:Args is null");
- return new ResultInfoDTO
- {
- IsSuccess = false,
- FailMessage = "Args is null",
- };
- }
- if (!flutterLiveConsultationInfo.IsStartLiveConsultation)
- {
- ConsultationRecipient.Hangup(true);
- OnConsultationDisconnected(this, ConsultationDisconnectedType.HangUpBySelf);
- return new ResultInfoDTO
- {
- IsSuccess = true,
- };
- }
- else
- {
- if (string.IsNullOrEmpty(flutterLiveConsultationInfo.LiveConsultationFlutterUrl))
- {
- Logger.WriteLineError($"SendFlutterLiveConsultationInfo Error:url is null");
- return new ResultInfoDTO
- {
- IsSuccess = false,
- FailMessage = "Url is null",
- };
- }
- if (string.IsNullOrEmpty(flutterLiveConsultationInfo.ConsulationId))
- {
- Logger.WriteLineError($"SendFlutterLiveConsultationInfo Error:consultationId is null");
- return new ResultInfoDTO
- {
- IsSuccess = false,
- FailMessage = "consultationId is null",
- };
- }
- else
- {
- return ConsultationRecipient.StartWebConsultation(flutterLiveConsultationInfo);
- }
- }
- }
- public ResultInfoDTO SwitchVideoPlayFromFlutter(string userId, bool isVideoOpen)
- {
- if (string.IsNullOrEmpty(userId))
- {
- return new ResultInfoDTO
- {
- IsSuccess = false,
- FailMessage = "UserId is null",
- };
- }
- return ConsultationRecipient.SwitchVideoPlay(userId, isVideoOpen);
- }
- /// <summary>
- /// 是否第二屏会诊或者使用FIS会诊中
- /// </summary>
- /// <returns></returns>
- public bool CheckLiveConsultationState()
- {
- return ConsultationRecipient.IsSecondViewMode || ConsultationRecipient.CurrentLiveStatus == LiveStates.RecipientAcceptted || ConsultationRecipient.CurrentLiveStatus == LiveStates.RecipientAcceptting;
- }
- }
- }
|