123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Vinno.IUS.Common.Args;
- using Vinno.IUS.Common.Log;
- using Vinno.IUS.Common.Network.Leaf;
- using Vinno.vCloud.Common.FIS.FLYINSONOLogin;
- 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 Vinno.vCloud.Protocol.Messages.Live;
- namespace Vinno.vCloud.Common.FIS.Consultation
- {
- internal class Consultation : IConsultation
- {
- private readonly string _terminalId;
- private readonly string _terminalName;
- private readonly string _url;
- private readonly LoginSource _loginSource;
- private readonly string _qrTagString = "TAG_QRLogin|";
- private FLYINSONOUser _flyinsonoUser;
- private ClientLeaf _leaf;
- private bool _disposed;
- private bool _isPrimaryDoctor;
- private string _currentConsultationDeviceId;
- private ScanLogin _scanLogin;
- /// <summary>
- /// Raised when the flyinsono user status is changed.
- /// </summary>
- public event EventHandler<FLYINSONOUserLoginStatusArgs> UserStatusChanged;
- /// <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>
- /// Other one join the consultation notification Arrived from server
- /// </summary>
- public event EventHandler<ConsultationInfo> JoinConsultationNotifyArrived;
- /// <summary>
- /// other reject notify arrived from server
- /// </summary>
- public event EventHandler<ConsultationSubscriberInfo> RejectConsultationNotifyArrived;
- /// <summary>
- /// Raised when the consultation is disconnect.
- /// </summary>
- public event EventHandler<ConsultationDisconnectedType> ConsultationDisconnected;
- /// <summary>
- /// Raised when consultation records collection changed.
- /// </summary>
- public event EventHandler<CollectionChangedArgs<ConsultationRecord>> ConsultationRecordsChanged;
- /// <summary>
- /// Raised when a consultation record updated.
- /// </summary>
- public event EventHandler<ConsultationRecord> ConsultationRecordUpdated;
- /// <summary>
- /// Raised when consultation Member Changed
- /// </summary>
- public event EventHandler<ConsultationMemberNotificaiton> ConsultationMemberChangedNotificationArrived;
- /// <summary>
- /// FLYINOSO User
- /// </summary>
- public FLYINSONOUser FLYINSONOUser => _flyinsonoUser;
- /// <summary>
- /// The consultation initiator
- /// </summary>
- public ConsultationIntiator ConsultationIntiator { get; }
- /// <summary>
- /// The consultation recipient
- /// </summary>
- public ConsultationRecipient ConsultationRecipient { get; }
- /// <summary>
- /// Chat live video provider, handle different video
- /// </summary>
- public ConsultationLiveVideoProvider ConsultationLiveVideoProvider { get; }
- /// <summary>
- /// Gets the manager for consultations.
- /// </summary>
- public ConsultationManager ConsultationManager { get; }
- /// <summary>
- /// 接收到其他用户的白板信息
- /// </summary>
- public event EventHandler<InteractiveBoardInfo> InteractiveBoardInfoArrived;
- /// <summary>
- /// 接收到清除白板信息
- /// </summary>
- public event EventHandler<string> ClearInteractiveBoardArrived;
- /// <summary>
- /// 收到即时会诊的通知
- /// </summary>
- public event EventHandler<DoctorInfo> EmergencyConsultationRequestArrived;
- /// <summary>
- /// 收到关闭摄像头的通知
- /// </summary>
- public event EventHandler<List<string>> MuteVideoUserListNotifyArrived;
- public Consultation(string terminalId, string terminalName, string url, LoginSource loginSource, string uniqueId)
- {
- _terminalId = terminalId;
- _terminalName = terminalName;
- _url = url;
- _loginSource = loginSource;
- ConsultationLiveVideoProvider = new ConsultationLiveVideoProvider();
- ConsultationLiveVideoProvider.OnTRTCRoomEnterError += OnTRTCRoomEnterErrorHappened;
- ConsultationLiveVideoProvider.ConsultationLocalVideoFrameArrived += OnConsultationLocalVideoFrameArrived;
- ConsultationLiveVideoProvider.ConsultationRemoteVideoFrameArrived += OnConsultationRemoteVideoFrameArrived;
- ConsultationLiveVideoProvider.TerminalImageFrameArrived += OnUltrasoundImageFrameArrived;
- ConsultationLiveVideoProvider.TerminalCameraFrameArrived += OnUltrasoundCameraFrameArrived;
- ConsultationIntiator = new ConsultationIntiator(ConsultationLiveVideoProvider, terminalId);
- ConsultationIntiator.ConsultationDisconnected += OnConsultationDisconnected;
- ConsultationIntiator.ConsultationMemberChangedNotificationArrived += OnConsultationMemberChangedNotificationArrived;
- ConsultationIntiator.JoinConsultationNotifyArrived += OnJoinConsultationNotifyArrived;
- ConsultationIntiator.RejectConsultationNotifyArrived += OnRejectConsultationNotifyArrived;
- ConsultationIntiator.InteractiveBoardInfoArrived += OnInteractiveBoardInfoArrived;
- ConsultationIntiator.ClearInteractiveBoardArrived += OnClearInteractiveBoardArrived;
- ConsultationIntiator.EmergencyConsultationRequestArrived += OnEmergencyConsultationRequestArrived;
- ConsultationIntiator.MuteVideoUserListNotifyArrived += OnMuteVideoUserListNotifyArrived;
- ConsultationRecipient = new ConsultationRecipient(ConsultationLiveVideoProvider, terminalId, uniqueId);
- ConsultationRecipient.ConsultationDisconnected += OnConsultationDisconnected;
- ConsultationRecipient.ConsultationRequestArrived += OnConcultationRequestArrived;
- ConsultationRecipient.JoinConsultationNotifyArrived += OnJoinConsultationNotifyArrived;
- ConsultationRecipient.ConsultationMemberChangedNotificationArrived += OnConsultationMemberChangedNotificationArrived;
- ConsultationRecipient.RejectConsultationNotifyArrived += OnRejectConsultationNotifyArrived;
- ConsultationRecipient.InteractiveBoardInfoArrived += OnInteractiveBoardInfoArrived;
- ConsultationRecipient.ClearInteractiveBoardArrived += OnClearInteractiveBoardArrived;
- ConsultationRecipient.MuteVideoUserListNotifyArrived += OnMuteVideoUserListNotifyArrived;
- ConsultationManager = new ConsultationManager(_terminalId, _terminalName);
- ConsultationManager.ConsultationRecordsChanged += OnConsultationRecordsChanged;
- ConsultationManager.ConsultationRecordUpdated += OnConsultationRecordUpdated;
- CreateScanLogin();
- }
- private void OnMuteVideoUserListNotifyArrived(object sender, List<string> muteVideoUserList)
- {
- MuteVideoUserListNotifyArrived?.Invoke(this, muteVideoUserList);
- }
- private void OnEmergencyConsultationRequestArrived(object sender, DoctorInfo e)
- {
- EmergencyConsultationRequestArrived?.Invoke(this, e);
- }
- public void CreateScanLogin()
- {
- if (_scanLogin == null)
- {
- _scanLogin = new ScanLogin(_url);
- _scanLogin.ScanLoginEvent += OnScanLoginEvent;
- }
- }
- public void CloseScanLogin()
- {
- if (_scanLogin != null)
- {
- _scanLogin.ScanLoginEvent -= OnScanLoginEvent;
- _scanLogin.Dispose();
- _scanLogin = null;
- }
- }
- private void OnScanLoginEvent(object sender, QRLoginInfo e)
- {
- if (e != null)
- {
- if (FLYINSONOUser == null)
- {
- Login(e.UserName, e.EncryptedPassword, true);
- return;
- }
- switch (FLYINSONOUser.Status)
- {
- case FLYINSONOUserLoginStatus.Online:
- case FLYINSONOUserLoginStatus.Logon:
- case FLYINSONOUserLoginStatus.ReLogin:
- break;
- case FLYINSONOUserLoginStatus.Offline:
- case FLYINSONOUserLoginStatus.DuplicateLogin:
- case FLYINSONOUserLoginStatus.Replaced:
- case FLYINSONOUserLoginStatus.LoginFailed:
- case FLYINSONOUserLoginStatus.WrongAccount:
- case FLYINSONOUserLoginStatus.WrongPassword:
- case FLYINSONOUserLoginStatus.Unknown:
- case FLYINSONOUserLoginStatus.IsNotDoctor:
- case FLYINSONOUserLoginStatus.Logoff:
- case FLYINSONOUserLoginStatus.HasNoPermission:
- default:
- Login(e.UserName, e.EncryptedPassword, true);
- return;
- }
- }
- }
- private void OnInteractiveBoardInfoArrived(object sender, InteractiveBoardInfo e)
- {
- InteractiveBoardInfoArrived?.Invoke(this, e);
- }
- private void OnClearInteractiveBoardArrived(object sender, string e)
- {
- ClearInteractiveBoardArrived?.Invoke(this, e);
- }
- /// <summary>
- /// Flyinsono user login
- /// </summary>
- /// <param name="userName">The flyinsono user name.</param>
- /// <param name="password">The password</param>
- /// <param name="isScanLogin">Is scan Login</param>
- public void Login(string userName, string password, bool isScanLogin)
- {
- DisposeFLYINSONOUser();
- _flyinsonoUser = FLYINSONOUserManager.Instance.CreateFLYINSONOUser(_url, userName, password, _loginSource, TerminalFeatureType.Consultation, isScanLogin);
- _flyinsonoUser.StatusChanged += OnUserStatusChanged;
- _flyinsonoUser.Login();
- }
- /// <summary>
- /// Flyinsono user log off.
- /// </summary>
- public void LogOff()
- {
- if (_flyinsonoUser != null)
- {
- _flyinsonoUser.LogOff();
- DisposeFLYINSONOUser();
- }
- }
- /// <summary>
- /// Get QRCode Info For Scan Login
- /// </summary>
- /// <returns></returns>
- public string GetQRCodeInfoForScanLogin()
- {
- if (_scanLogin != null)
- {
- return _qrTagString + _scanLogin.LeafId;
- }
- else
- {
- return "";
- }
- }
- /// <summary>
- /// Accept the consultation request.
- /// </summary>
- /// <param name="videoHardwareId">The camera id.</param>
- /// <param name="micHardwareId">The micphone id.</param>
- /// <param name="speakerHardwareId">The speakder id.</param>
- /// <returns>The chat live states.</returns>
- public LiveStates AcceptConsultation(string videoHardwareId, string micHardwareId, string speakerHardwareId)
- {
- return ConsultationRecipient.AcceptConsultation(videoHardwareId, micHardwareId, speakerHardwareId);
- }
- /// <summary>
- /// Reject the consultation request.
- /// </summary>
- public LiveStates RejectConsultation()
- {
- return ConsultationRecipient.RejectConsultation();
- }
- /// <summary>
- /// Hang up a chating.
- /// </summary>
- public LiveStates HangupConsultation()
- {
- var result = LiveStates.UnknowException;
- if (ConsultationRecipient.ConsultationInfo != null)
- {
- var recipientId = ConsultationRecipient?.ConsultationInfo?.ConsultationMemberInfos.FirstOrDefault(x => x.RoleType == ConsultationRoleType.Recipient)?.Id;
- if (recipientId == FLYINSONOUser.AccountId)
- {
- result = ConsultationRecipient.Hangup(true);
- }
- else
- {
- result = ConsultationRecipient.Hangup(false);
- }
- OnConsultationDisconnected(this, ConsultationDisconnectedType.HangUpBySelf);
- }
- else if (ConsultationIntiator.ConsultationInfo != null)
- {
- result = ConsultationIntiator.Hangup(true);
- ConsultationManager.UpdateCurrentConsultationToWaitForReportUpload();
- OnConsultationDisconnected(this, ConsultationDisconnectedType.HangUpBySelf);
- }
- else
- {
- Logger.WriteLineInfo($"Didn't do hang up since no consultation info");
- }
- return result;
- }
- /// <summary>
- /// 发送画板数据
- /// </summary>
- /// <param name="jsonData"></param>
- /// <returns></returns>
- public bool SendInteractiveBoardData(string jsonData)
- {
- if (ConsultationRecipient.ConsultationInfo != null)
- {
- return ConsultationRecipient.SendInteractiveBoardData(jsonData);
- }
- else if (ConsultationIntiator.ConsultationInfo != null)
- {
- return ConsultationIntiator.SendInteractiveBoardData(jsonData);
- }
- else
- {
- Logger.WriteLineInfo($"Didn't Send Interactive BoardData since no consultation info");
- return false;
- }
- }
- /// <summary>
- /// 清除画板数据
- /// </summary>
- /// <returns></returns>
- public bool ClearInteractiveBoardData()
- {
- if (ConsultationRecipient.ConsultationInfo != null)
- {
- return ConsultationRecipient.ClearInteractiveBoardData();
- }
- else if (ConsultationIntiator.ConsultationInfo != null)
- {
- return ConsultationIntiator.ClearInteractiveBoardData();
- }
- else
- {
- Logger.WriteLineInfo($"Didn't Clear Interactive BoardData since no consultation info");
- return false;
- }
- }
- /// <summary>
- /// Start a chat request.
- /// </summary>
- /// <param name="recipientIds">The ids of the recipient.</param>
- /// <returns>The chat live status</returns>
- public LiveStates RequestConsultation(List<RecipientInfo> recipientIds, string cameraHardwareId, string micHardwareId, string speakerHardwareId)
- {
- CrossPlatformHelper.Instance.HardwareDetector.StopCameraPreview();
- _currentConsultationDeviceId = ConsultationManager.CurrentConsultationRecord?.TerminalInfo?.Id;
- var result = ConsultationIntiator.RequestConsultation(recipientIds, cameraHardwareId, micHardwareId, speakerHardwareId, ConsultationManager.CurrentConsultationRecord?.TerminalInfo?.Id);
- if (result == null)
- {
- return LiveStates.UnknowException;
- }
- return result.State;
- }
- /// <summary>
- /// Cancel chat request
- /// </summary>
- public LiveStates CancelConsultationRequest(bool forceClosed)
- {
- return ConsultationIntiator.CancelConsultationRequest(forceClosed);
- }
- /// <summary>
- /// Gets the hospital info of the flyinsono user.
- /// </summary>
- /// <returns></returns>
- public OrganizationInfo GetHospitalInfo()
- {
- return _flyinsonoUser?.Hospital;
- }
- /// <summary>
- /// Doctor apply consultation.
- /// </summary>
- /// <param name="consultationRecord">The consultation record info to apply.</param>
- /// <returns>True: success. False: falied./returns>
- public bool ApplyConsultationRecord(ConsultationRecord consultationRecord)
- {
- return ConsultationManager.AddConsultationRecord(consultationRecord);
- }
- /// <summary>
- /// Doctor delete consultation
- /// </summary>
- /// <param name="consultationId"></param>
- /// <returns></returns>
- public bool DeleteConsultationRecord(string consultationId)
- {
- return ConsultationManager.DeleteConsultationRecord(consultationId);
- }
- /// <summary>
- /// Doctor withdraw consultation.
- /// </summary>
- /// <param name="consultationId">The consultation id.</param>
- /// <returns>True: success. False: falied.</returns>
- public bool WithDrawConsultationRecord(string consultationId)
- {
- return ConsultationManager.WithDrawConsultationRecord(consultationId);
- }
- /// <summary>
- /// Doctor update consultation.
- /// </summary>
- /// <param name="consultationRecord">The consultation record info to update.</param>
- /// <returns>True: success. False: falied./returns>
- public bool UpdateConsultationRecord(ConsultationRecord consultationRecord)
- {
- return ConsultationManager.UpdateConsultation(consultationRecord);
- }
- /// <summary>
- /// Expert arrange consultation.
- /// </summary>
- /// <param name="consultationRecord">The consultation to be arranged.</param>
- /// <returns>True: success. False: falied./returns>
- public bool ArrangeConsultationRecord(ConsultationRecord consultationRecord)
- {
- return ConsultationManager.ArrangeConsultation(consultationRecord);
- }
- /// <summary>
- /// Gets the experts list by hospital id.
- /// </summary>
- /// <param name="hospitalId">The hospital id.</param>
- /// <returns>The experts of the hospital.</returns>
- public IEnumerable<DoctorInfo> GetExperts(string hospitalId)
- {
- return ConsultationManager.GetExperts(hospitalId);
- }
- /// <summary>
- /// Gets the live states of the current chat.
- /// </summary>
- /// <returns></returns>
- public LiveStates GetCurrentConsultationLiveStates()
- {
- var isInitiator = false;
- var consultationInfo = ConsultationIntiator.ConsultationInfo;
- if (consultationInfo != null)
- {
- isInitiator = true;
- }
- if (isInitiator)
- {
- return ConsultationIntiator.CurrentLiveStatus;
- }
- else
- {
- return ConsultationRecipient.CurrentLiveStatus;
- }
- }
- /// <summary>
- /// Set current consultation record.
- /// </summary>
- /// <param name="consultationId">The current consultation record id.</param>
- public void SetCurrentConsultationRecord(string consultationId)
- {
- ConsultationManager.SetCurrentConsultationRecord(consultationId);
- }
- /// <summary>
- /// Dispose consultation
- /// </summary>
- public void Dispose()
- {
- DoDispose();
- GC.SuppressFinalize(this);
- }
- private void DoDispose()
- {
- if (!_disposed)
- {
- ConsultationLiveVideoProvider.OnTRTCRoomEnterError -= OnTRTCRoomEnterErrorHappened;
- ConsultationLiveVideoProvider.ConsultationLocalVideoFrameArrived -= OnConsultationLocalVideoFrameArrived;
- ConsultationLiveVideoProvider.ConsultationRemoteVideoFrameArrived -= OnConsultationRemoteVideoFrameArrived;
- ConsultationLiveVideoProvider.TerminalImageFrameArrived -= OnUltrasoundImageFrameArrived;
- ConsultationLiveVideoProvider.TerminalCameraFrameArrived -= OnUltrasoundCameraFrameArrived;
- ConsultationLiveVideoProvider.Dispose();
- ConsultationIntiator.ConsultationDisconnected -= OnConsultationDisconnected;
- ConsultationIntiator.JoinConsultationNotifyArrived -= OnJoinConsultationNotifyArrived;
- ConsultationIntiator.RejectConsultationNotifyArrived -= OnRejectConsultationNotifyArrived;
- ConsultationIntiator.ConsultationMemberChangedNotificationArrived -= OnConsultationMemberChangedNotificationArrived;
- ConsultationIntiator.InteractiveBoardInfoArrived -= OnInteractiveBoardInfoArrived;
- ConsultationIntiator.ClearInteractiveBoardArrived -= OnClearInteractiveBoardArrived;
- ConsultationIntiator.EmergencyConsultationRequestArrived -= OnEmergencyConsultationRequestArrived;
- ConsultationIntiator.MuteVideoUserListNotifyArrived -= OnMuteVideoUserListNotifyArrived;
- ConsultationIntiator.Dispose();
- ConsultationRecipient.ConsultationDisconnected -= OnConsultationDisconnected;
- ConsultationRecipient.ConsultationRequestArrived -= OnConcultationRequestArrived;
- ConsultationRecipient.JoinConsultationNotifyArrived -= OnJoinConsultationNotifyArrived;
- ConsultationRecipient.ConsultationMemberChangedNotificationArrived -= OnConsultationMemberChangedNotificationArrived;
- ConsultationRecipient.RejectConsultationNotifyArrived -= OnRejectConsultationNotifyArrived;
- ConsultationRecipient.InteractiveBoardInfoArrived -= OnInteractiveBoardInfoArrived;
- ConsultationRecipient.ClearInteractiveBoardArrived -= OnClearInteractiveBoardArrived;
- ConsultationRecipient.MuteVideoUserListNotifyArrived -= OnMuteVideoUserListNotifyArrived;
- ConsultationRecipient.Dispose();
- ConsultationManager.ClearConsultationRecordCache();
- ConsultationManager.ConsultationRecordsChanged -= OnConsultationRecordsChanged;
- ConsultationManager.ConsultationRecordUpdated -= OnConsultationRecordUpdated;
- ConsultationManager.Dispose();
- DisposeFLYINSONOUser();
- CloseScanLogin();
- _disposed = true;
- }
- }
- 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 OnUltrasoundImageFrameArrived(object sender, CPVideoFrameData e)
- {
- if (!_isPrimaryDoctor || (_isPrimaryDoctor && _terminalId != _currentConsultationDeviceId))
- {
- UltrasoundImageFrameArrived?.Invoke(this, 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 DisposeFLYINSONOUser()
- {
- if (_flyinsonoUser != null)
- {
- _flyinsonoUser.Dispose();
- _flyinsonoUser.StatusChanged -= OnUserStatusChanged;
- _flyinsonoUser = null;
- }
- }
- private void OnUserStatusChanged(object sender, FLYINSONOUserLoginStatusArgs e)
- {
- try
- {
- switch (FLYINSONOUser.Status)
- {
- case FLYINSONOUserLoginStatus.Logon:
- CloseScanLogin();
- _leaf = _flyinsonoUser.ClientLeaf;
- ConsultationIntiator.Update(_leaf, _flyinsonoUser);
- ConsultationRecipient.Update(_leaf, _flyinsonoUser);
- ConsultationManager.Update(_leaf, _flyinsonoUser);
- break;
- case FLYINSONOUserLoginStatus.Offline:
- case FLYINSONOUserLoginStatus.Logoff:
- case FLYINSONOUserLoginStatus.Replaced:
- var consultationtatus = GetCurrentConsultationLiveStates();
- var isConsultation = consultationtatus == LiveStates.RecipientAcceptted
- || consultationtatus == LiveStates.ChatRequestArrived
- || consultationtatus == LiveStates.InitiatorRequestingChat
- || consultationtatus == LiveStates.RecipientAcceptting;
- if (isConsultation)
- {
- HangupConsultation();
- }
- ConsultationManager.ClearConsultationRecordCache();
- CreateScanLogin();
- break;
- }
- UserStatusChanged?.Invoke(this, e);
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"Consultation OnUserStatus Changed Error:{ex}");
- }
- }
- /// <summary>
- /// GetConsultationRecordList
- /// </summary>
- /// <param name="startIndex">Start Index</param>
- /// <param name="pageSize">page Size</param>
- /// <param name="consultationRecordFilter">Filter</param>
- public bool GetConsultationRecordList(int startIndex, int pageSize, ConsultationRecordFilter consultationRecordFilter)
- {
- return ConsultationManager.GetConsultationRecordList(startIndex, pageSize, consultationRecordFilter);
- }
- /// <summary>
- /// 获取当前会诊记录的报告
- /// </summary>
- /// <returns></returns>
- public IEnumerable<byte[]> GetCurrentConsultationRecordReportImage()
- {
- return ConsultationManager.GetReportImagesByConsultationId();
- }
- private void OnConsultationRecordUpdated(object sender, ConsultationRecord e)
- {
- ConsultationRecordUpdated?.Invoke(this, e);
- }
- private void OnConsultationRecordsChanged(object sender, CollectionChangedArgs<ConsultationRecord> e)
- {
- ConsultationRecordsChanged?.Invoke(this, e);
- }
- private void OnConcultationRequestArrived(object sender, ConsultationInfo e)
- {
- var primaryDoctorId = e?.ConsultationMemberInfos?.FirstOrDefault(x => x.RoleType == ConsultationRoleType.Recipient)?.Id;
- if (primaryDoctorId == FLYINSONOUser.AccountId)
- {
- _isPrimaryDoctor = true;
- }
- else
- {
- _isPrimaryDoctor = false;
- }
- _currentConsultationDeviceId = e?.TerminalInfo?.Id;
- CrossPlatformHelper.Instance.HardwareDetector.StopCameraPreview();
- ConsultationRequestArrived?.Invoke(this, e);
- }
- private void OnRejectConsultationNotifyArrived(object sender, ConsultationSubscriberInfo e)
- {
- RejectConsultationNotifyArrived?.Invoke(this, e);
- }
- private void OnJoinConsultationNotifyArrived(object sender, ConsultationInfo e)
- {
- var primaryDoctorId = e?.ConsultationMemberInfos?.FirstOrDefault(x => x.RoleType == ConsultationRoleType.Recipient)?.Id;
- if (primaryDoctorId == FLYINSONOUser.AccountId)
- {
- _isPrimaryDoctor = true;
- }
- else
- {
- _isPrimaryDoctor = false;
- }
- JoinConsultationNotifyArrived?.Invoke(this, e);
- if (ConsultationIntiator.ConsultationInfo != null)
- {
- ConsultationManager.UpdateCurrentConsultationToStarted();
- }
- }
- private void OnConsultationDisconnected(object sender, ConsultationDisconnectedType e)
- {
- _currentConsultationDeviceId = null;
- ConsultationDisconnected?.Invoke(this, e);
- if (ConsultationIntiator.ConsultationInfo != null)
- {
- ConsultationManager.UpdateCurrentConsultationToWaitForReportUpload();
- }
- }
- /// <summary>
- /// 开始即时呼叫
- /// </summary>
- /// <param name="cameraId"></param>
- /// <param name="micId"></param>
- /// <param name="speakerId"></param>
- /// <returns></returns>
- public EnumEmergencyConsultationResult RequestEmergencyConsultation(string cameraId, string micId, string speakerId)
- {
- _currentConsultationDeviceId = _terminalId;
- return ConsultationRecipient.RequestEmergencyConsultation(cameraId, micId, speakerId);
- }
- /// <summary>
- /// 发起者取消即时呼叫
- /// </summary>
- public LiveStates CancelEmergencyConsultation()
- {
- return ConsultationRecipient.CancelEmergencyConsultation();
- }
- public LiveStates AcceptEmergencyConsultation(string cameraHardwareId, string micHardwareId, string speakerHardwareId)
- {
- return ConsultationIntiator.AcceptEmergencyConsultation(cameraHardwareId, micHardwareId, speakerHardwareId);
- }
- public LiveStates RejectEmergencyConsultation()
- {
- return ConsultationIntiator.RejectEmergencyConsultation();
- }
- }
- }
|