123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Vinno.IUS.Common.Log;
- using Vinno.IUS.Common.Network.Leaf;
- using Vinno.IUS.Common.Network.Transfer;
- using Vinno.IUS.Common.Utilities;
- using Vinno.vCloud.Common.FIS.FLYINSONOLogin;
- using Vinno.vCloud.Common.FIS.Helper;
- using Vinno.vCloud.FIS.CrossPlatform.Common.Consultation;
- using Vinno.vCloud.Protocol.Infrastructures;
- using Vinno.vCloud.Protocol.Messages.Client.Account;
- using Vinno.vCloud.Protocol.Messages.Client.Chat;
- using Vinno.vCloud.Protocol.Messages.Common;
- using Vinno.vCloud.Protocol.Messages.Live;
- namespace Vinno.vCloud.Common.FIS.Consultation
- {
- public class ConsultationSubscriberInfo
- {
- /// <summary>
- /// The Subscriber unique id
- /// </summary>
- public string Id { get; set; }
- /// <summary>
- /// roomId = chat table id
- /// </summary>
- public string RoomId { get; set; }
- }
- public enum ConsultationDisconnectedType
- {
- Timeout,
- ByClient,
- ByServer,
- CancelledByInitiator,
- NotOnline,
- HangupByOther,
- AcceptedInOtherDeivce,
- ExceptionHappend,
- KickBySomeone,
- RejecteByInitiator,
- SelfClientOffline,
- HangUpBySelf
- }
- internal abstract class ConsultationClient : IDisposable
- {
- private ConsultationInfo _consultationInfo;
- private EmergencyConsultationInfo _emergencyConsultationInfo;
- protected readonly object ConsultationInfoLocker = new object();
- protected readonly object EmergencyConsultationLocker = new object();
- protected int count = 0;
- /// <summary>
- /// Gets or sets the current live status
- /// </summary>
- public LiveStates CurrentLiveStatus { get; set; }
- /// <summary>
- /// Raised when meeting disconnected.
- /// </summary>
- public event EventHandler<ConsultationDisconnectedType> ConsultationDisconnected;
- /// <summary>
- /// Raised when meeting member changed
- /// </summary>
- public event EventHandler<ConsultationMemberNotificaiton> ConsultationMemberChangedNotificationArrived;
- /// <summary>
- /// other reject notify arrived from server
- /// </summary>
- public event EventHandler<ConsultationSubscriberInfo> RejectConsultationNotifyArrived;
- /// <summary>
- /// 接收到其他用户的白板信息
- /// </summary>
- public event EventHandler<InteractiveBoardInfo> InteractiveBoardInfoArrived;
- /// <summary>
- /// 接收到清除白板信息
- /// </summary>
- public event EventHandler<string> ClearInteractiveBoardArrived;
- /// <summary>
- /// Other one join the Consultation notification Arrived from server
- /// </summary>
- public event EventHandler<ConsultationInfo> JoinConsultationNotifyArrived;
- public event EventHandler<List<string>> MuteVideoUserListNotifyArrived;
- public ConsultationInfo ConsultationInfo
- {
- get => _consultationInfo;
- set
- {
- if (_consultationInfo != value)
- {
- _consultationInfo = value;
- count = 0;
- }
- }
- }
- public EmergencyConsultationInfo EmergencyConsultationInfo
- {
- get => _emergencyConsultationInfo;
- set
- {
- if (_emergencyConsultationInfo != value)
- {
- _emergencyConsultationInfo = value;
- }
- }
- }
- protected ConsultationLiveVideoProvider VideoProvider { get; }
- protected FLYINSONOUser FLYINSONOUser { get; set; }
- protected ClientLeaf ClientLeaf { get; set; }
- protected ConsultationClient(ConsultationLiveVideoProvider videoProvider)
- {
- CurrentLiveStatus = LiveStates.Idle;
- VideoProvider = videoProvider;
- VideoProvider.RemoteUserLeaveRoomArrived += OnRemoteUserLeaveRoomArrived;
- VideoProvider.CloseConsultation += OnCloseMeeting;
- VideoProvider.TryToReconnect += OnTryToReconnect;
- }
- protected void OnTryToReconnect(object sender, EventArgs e)
- {
- if (count > 1)
- {
- var member = ConsultationInfo?.ConsultationMemberInfos?.FirstOrDefault(f => f.Id == FLYINSONOUser?.AccountId);
- if (member != null)
- {
- OnDisconnected(ConsultationDisconnectedType.SelfClientOffline);
- }
- }
- else
- {
- count++;
- }
- }
- private void OnRemoteUserLeaveRoomArrived(object sender, RemoteUserLeaveRoomArgs e)
- {
- Logger.WriteLineInfo($"OnRemoteUserLeaveRoomArrived Arrived,UserId:{e.UserId},Reason:{e.Reason}");
- if (ConsultationInfo != null)
- {
- var member = ConsultationInfo?.ConsultationMemberInfos?.FirstOrDefault(f => f.Id == e.UserId);
- if (member != null)
- {
- if (member.Id == FLYINSONOUser?.AccountId && (member.RoleType == ConsultationRoleType.Initiator || member.RoleType == ConsultationRoleType.Recipient))
- {
- DestroyMeeting();
- OnDisconnected(ConsultationDisconnectedType.SelfClientOffline);
- }
- else if (member.Id != FLYINSONOUser?.AccountId && (member.RoleType == ConsultationRoleType.Initiator || member.RoleType == ConsultationRoleType.Recipient))
- {
- DestroyMeeting();
- OnDisconnected(ConsultationDisconnectedType.HangupByOther);
- }
- else
- {
- VideoProvider.RemoveVideoProvider(member.Id);
- ConsultationInfo.ConsultationMemberInfos.Remove(member);
- }
- }
- }
- }
- private void OnCloseMeeting(object sender, EventArgs e)
- {
- OnDisconnected(ConsultationDisconnectedType.SelfClientOffline);
- }
- protected void OnJoinConsultationNotifyArrived()
- {
- JoinConsultationNotifyArrived?.Invoke(this, ConsultationInfo);
- }
- /// <summary>
- /// Update client leaf after flyinsono user login.
- /// </summary>
- /// <param name="clientLeaf"></param>
- /// <param name="flyinsonoUser"></param>
- public void Update(ClientLeaf clientLeaf, FLYINSONOUser flyinsonoUser)
- {
- FLYINSONOUser = flyinsonoUser;
- if (ClientLeaf != null)
- {
- ClientLeaf.MessageArrived -= OnMessageArrived;
- ClientLeaf = null;
- }
- ClientLeaf = clientLeaf;
- if (ClientLeaf != null)
- {
- ClientLeaf.MessageArrived += OnMessageArrived;
- }
- }
- protected EmergencyConsultationInfo GetEmergencyConsultationExpertsInfo()
- {
- using (var request = MessagePool.GetMessage<FindSortedExpertsRequest2>())
- {
- var result = ClientLeaf?.Send(request);
- if (result != null)
- {
- var resultMessage = FindSortedExpertsResult2.Convert(result);
- if (resultMessage != null)
- {
- var sortExperts = resultMessage.SortedExperts.Select(f => new EmergencyConsultationExpertInfo()
- {
- UserId = f.UserId,
- HospitalId = f.HospitalId,
- Sort = f.Sort,
- UserName = f.UserName,
- ShowName = f.ShowName,
- }).OrderBy(x => x.Sort).ToList();
- return new EmergencyConsultationInfo()
- {
- CurrentSort = sortExperts.FirstOrDefault() != null ? sortExperts.FirstOrDefault().Sort : 0,
- SortExperts = sortExperts,
- NoExpertCause = resultMessage.NoExpertCause
- };
- }
- }
- }
- return new EmergencyConsultationInfo()
- {
- CurrentSort = 0,
- SortExperts = new List<EmergencyConsultationExpertInfo>(),
- };
- }
- protected virtual void OnMessageArrived(object sender, Message e)
- {
- if (ConsultationInfo == null)
- {
- return;
- }
- var muteVideoUserChangeNotification = MuteVideoUserChangeNotification.Convert(e);
- if (muteVideoUserChangeNotification != null)
- {
- HandleMuteVideoUserChangeNotification(muteVideoUserChangeNotification);
- }
- var hangupNotification = MeetingHangupNotification.Convert(e); //挂断
- if (hangupNotification != null)
- {
- HandleMeetingHangupNotification(hangupNotification);
- }
- var chatPendingMemberTimeoutNotification = ChatPendingMemberTimeoutNotification.Convert(e);
- if (chatPendingMemberTimeoutNotification != null)
- {
- HandleChatPendingMemberTimeoutNotification(chatPendingMemberTimeoutNotification);
- }
- var meetingMemberNotification = MeetingMemberNotification.Convert(e); //用户发生变化
- if (meetingMemberNotification != null)
- {
- Logger.WriteLineInfo("LiveMeeting MeetingMemberNotification Arrived");
- HandleConsultationMemberNotificationArrived(meetingMemberNotification);
- }
- var chatMemberHeartBeatStatusNotification = ChatMemberHeartbeatStatusNotification.Convert(e);
- if (chatMemberHeartBeatStatusNotification != null)
- {
- HandleConsultationMemberHeartbeatStatusNotificationArrived(chatMemberHeartBeatStatusNotification);
- }
- var rejectMeetingNotification = RejectMeetingNotification.Convert(e); //拒绝会诊通知
- if (rejectMeetingNotification != null)
- {
- HandleRejectConsultationNotification(rejectMeetingNotification);
- }
- var interactiveBoardNotification = InteractiveBoardNotification.Convert(e);
- if (interactiveBoardNotification != null)
- {
- HandleInteractiveBoardNotification(interactiveBoardNotification);
- }
- var clearInteractiveBoardNotification = ClearInteractiveBoardNotification.Convert(e);
- if (clearInteractiveBoardNotification != null)
- {
- HandleClearInteractiveBoardNotification(clearInteractiveBoardNotification);
- }
- }
- private void HandleMuteVideoUserChangeNotification(MuteVideoUserChangeNotification muteVideoUserChangeNotification)
- {
- Logger.WriteLineInfo("HandleMuteVideoUserChangeNotification Arrived");
- if (muteVideoUserChangeNotification.RoomId != ConsultationInfo?.RoomId)
- {
- Logger.WriteLineInfo($"Consultation Client HandleMuteVideoUserChangeNotification,RoomId:{ConsultationInfo?.RoomId},NotificationRoomId:{muteVideoUserChangeNotification.RoomId}");
- return;
- }
- MuteVideoUserListNotifyArrived?.Invoke(this, muteVideoUserChangeNotification.MuteVideoUsers.ToList() ?? new List<string>());
- }
- private void HandleMeetingHangupNotification(MeetingHangupNotification hangupNotification)
- {
- Logger.WriteLineInfo("HandleMeetingHangupNotification Arrived");
- switch (hangupNotification.HangupReason)
- {
- case LiveStates.HeartBeatDown:
- OnDisconnected(ConsultationDisconnectedType.ExceptionHappend);
- break;
- case LiveStates.InitiativeExit:
- OnDisconnected(ConsultationDisconnectedType.HangupByOther);
- break;
- case LiveStates.Cancelled:
- OnDisconnected(ConsultationDisconnectedType.CancelledByInitiator);
- break;
- default:
- OnDisconnected(ConsultationDisconnectedType.HangupByOther);
- break;
- }
- Logger.WriteLineInfo($"EndMeetingNotification handled");
- }
- private void HandleChatPendingMemberTimeoutNotification(ChatPendingMemberTimeoutNotification chatPendingMemberTimeoutNotification)
- {
- Logger.WriteLineInfo("HandleChatPendingMemberTimeoutNotification Arrived");
- if (chatPendingMemberTimeoutNotification.RoomId != ConsultationInfo?.RoomId)
- {
- Logger.WriteLineInfo($"Consultation Client OnChatPendingMemberTimeoutNotificationArrived,RoomId:{ConsultationInfo?.RoomId},NotificationRoomId:{chatPendingMemberTimeoutNotification.RoomId}");
- return;
- }
- Logger.WriteLineInfo($"Consultation Client OnChatPendingMemberTimeoutNotificationArrived");
- foreach (var userId in chatPendingMemberTimeoutNotification.UserIds)
- {
- var member = ConsultationInfo?.ConsultationMemberInfos?.FirstOrDefault(f => f.Id == userId);
- if (member != null)
- {
- if (member.Id == FLYINSONOUser.AccountId)
- {
- OnDisconnected(ConsultationDisconnectedType.Timeout);
- }
- else
- {
- VideoProvider.RemoveVideoProvider(member.Id);
- member.State = LiveStates.RecipientRejected;
- member.OperationType = ClientMessageOperationType.Delete;
- OnConsultationMemberChangedNotificationArrived(new ConsultationMemberNotificaiton()
- {
- RoomId = chatPendingMemberTimeoutNotification.RoomId,
- Members = new List<ConsultationMemberInfo> { member },
- LiveTerminals = new List<TerminalInfo>()
- });
- ConsultationInfo.ConsultationMemberInfos.Remove(member);
- }
- }
- }
- }
- private void HandleClearInteractiveBoardNotification(ClearInteractiveBoardNotification clearInteractiveBoardNotification)
- {
- Logger.WriteLineInfo($"HandleClearInteractiveBoardNotification Arrived,Current Id:{FLYINSONOUser?.AccountId},RecipientId:{clearInteractiveBoardNotification.RecipientId}");
- if (clearInteractiveBoardNotification.RecipientId == FLYINSONOUser.AccountId)
- {
- ClearInteractiveBoardArrived?.Invoke(this, clearInteractiveBoardNotification.ChatSubscriberId);
- }
- }
- private void HandleInteractiveBoardNotification(InteractiveBoardNotification interactiveBoardNotification)
- {
- Logger.WriteLineInfo($"InteractiveBoardNotification Arrived,Current Id:{FLYINSONOUser?.AccountId},RecipientId:{interactiveBoardNotification.RecipientId}");
- if (interactiveBoardNotification.RecipientId == FLYINSONOUser.AccountId)
- {
- InteractiveBoardInfoArrived?.Invoke(this,
- new InteractiveBoardInfo(interactiveBoardNotification.SubscriberId,
- interactiveBoardNotification.RecipientId,
- interactiveBoardNotification.ChatSubscriberId,
- interactiveBoardNotification.JsonData));
- }
- }
- private void HandleRejectConsultationNotification(RejectMeetingNotification rejectMeetingNotification)
- {
- Logger.WriteLineInfo("RejectConsultationNotification Arrived");
- var arg = new ConsultationSubscriberInfo()
- {
- Id = rejectMeetingNotification.UserId,
- RoomId = rejectMeetingNotification.RoomId
- };
- var member = ConsultationInfo.ConsultationMemberInfos.FirstOrDefault(f => f.Id == arg.Id);
- if (member != null)
- {
- VideoProvider.RemoveVideoProvider(member.Id);
- member.State = LiveStates.RecipientRejected;
- member.OperationType = ClientMessageOperationType.Delete;
- if (ConsultationInfo.ChatRole == ChatRole.Initiator)
- {
- if (ConsultationInfo.ConsultationMemberInfos.Count() <= 2)
- {
- CurrentLiveStatus = LiveStates.RecipientRejected;
- }
- OnRejectConsultationNotifyArrived(arg);
- }
- else
- {
- OnConsultationMemberChangedNotificationArrived(new ConsultationMemberNotificaiton()
- {
- RoomId = rejectMeetingNotification.RoomId,
- Members = new List<ConsultationMemberInfo> { member },
- LiveTerminals = new List<TerminalInfo>()
- });
- }
- ConsultationInfo.ConsultationMemberInfos.Remove(member);
- }
- Logger.WriteLineInfo($"RejectConsultationNotification handled Id:{arg.Id},RoomId:{arg.RoomId}");
- }
- protected void OnRejectConsultationNotifyArrived(ConsultationSubscriberInfo e)
- {
- RejectConsultationNotifyArrived?.Invoke(this, e);
- }
- private void HandleConsultationMemberHeartbeatStatusNotificationArrived(ChatMemberHeartbeatStatusNotification chatMemberHeartBeatStatusNotification)
- {
- Logger.WriteLineInfo($"LiveMeeting ChatMemberHeartbeatStatusNotification Arrived, Current Id:{FLYINSONOUser?.AccountId}, Heart Beat Member Id:{chatMemberHeartBeatStatusNotification.HeartBeatMemberId}");
- if (FLYINSONOUser?.AccountId == chatMemberHeartBeatStatusNotification.HeartBeatMemberId)
- {
- OnDisconnected(ConsultationDisconnectedType.ByServer);
- }
- else
- {
- var member = ConsultationInfo?.ConsultationMemberInfos?.FirstOrDefault(f => f.Id == chatMemberHeartBeatStatusNotification.HeartBeatMemberId);
- if (member != null && (member.RoleType == ConsultationRoleType.Administrator || member.RoleType == ConsultationRoleType.Expert))
- {
- VideoProvider.RemoveVideoProvider(chatMemberHeartBeatStatusNotification.HeartBeatMemberId);
- member.State = chatMemberHeartBeatStatusNotification.LiveStates;
- member.OperationType = ClientMessageOperationType.Delete;
- OnConsultationMemberChangedNotificationArrived(new ConsultationMemberNotificaiton()
- {
- RoomId = chatMemberHeartBeatStatusNotification.RoomId,
- Members = new List<ConsultationMemberInfo> { member },
- LiveTerminals = new List<TerminalInfo>()
- });
- ConsultationInfo.ConsultationMemberInfos.Remove(member);
- }
- }
- }
- protected virtual void HandleConsultationMemberNotificationArrived(MeetingMemberNotification meetingMemberNotification)
- {
- var consultationMemberNotification = DTOConverter.ConvertMeetingMemberNotificationToConsultationMemberNotificaiton(meetingMemberNotification);
- OnConsultationMemberChangedNotificationArrived(consultationMemberNotification);
- }
- private void OnConsultationMemberChangedNotificationArrived(ConsultationMemberNotificaiton consultationMemberNotificaiton)
- {
- ConsultationMemberChangedNotificationArrived?.Invoke(this, consultationMemberNotificaiton);
- }
- protected string GetAccoutNameByAccountId(string accountId)
- {
- using (var request = MessagePool.GetMessage<FindUserInfoByIdRequest>())
- {
- request.AccountId = accountId;
- var result = ClientLeaf.Send(request);
- if (result != null)
- {
- var resultMessage = FindUserInfoByIdResult.Convert(result);
- if (resultMessage != null)
- {
- if (!string.IsNullOrWhiteSpace(resultMessage.FullName))
- {
- return resultMessage.FullName;
- }
- if (!string.IsNullOrWhiteSpace(resultMessage.NickName))
- {
- return resultMessage.NickName;
- }
- return resultMessage.Name;
- }
- }
- }
- return null;
- }
- protected void OnDisconnected(ConsultationDisconnectedType e)
- {
- try
- {
- StopConsultation();
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"Consultationclient- error happended while disconnectting: {ex}");
- }
- finally
- {
- ConsultationDisconnected?.Invoke(this, e);
- lock (ConsultationInfoLocker)
- {
- Logger.WriteLineInfo($"Current consultation info is set to null on reson: {e}");
- ConsultationInfo = null;
- }
- ////Here create a window period for exiting rtc room
- //Thread.Sleep(100);
- CurrentLiveStatus = LiveStates.Disconnected;
- }
- }
- protected void StopConsultation()
- {
- var isMeetting = CurrentLiveStatus == LiveStates.RecipientAcceptted || CurrentLiveStatus == LiveStates.RecipientAcceptting;
- if (isMeetting)
- {
- VideoProvider.Hangup();
- CurrentLiveStatus = LiveStates.Idle;
- }
- else
- {
- Logger.WriteLineInfo($"Don't do stop consultation video since no rtc consultation is not started");
- }
- }
- protected void StartConsultation(string cameraHardwareId, string micHardwareId, string speakerHardwareId)
- {
- try
- {
- VideoProvider.StartConsultationVideo(ConsultationInfo, FLYINSONOUser.AccountId, FLYINSONOUser.Name, cameraHardwareId, micHardwareId, speakerHardwareId, ClientLeaf);
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"Error happened while start meeting {ex}");
- }
- }
- /// <summary>
- /// 发送画板数据
- /// </summary>
- /// <param name="jsonData"></param>
- /// <returns></returns>
- public bool SendInteractiveBoardData(string jsonData)
- {
- try
- {
- if (ConsultationInfo == null)
- {
- return false;
- }
- if (jsonData != null && ConsultationInfo.ConsultationMemberInfos?.Count() > 1)
- {
- var userIds = ConsultationInfo.ConsultationMemberInfos.FindAll(x => x.Id != FLYINSONOUser.AccountId).ToList().Select(x => x.Id).ToList(); ;
- using (var request = MessagePool.GetMessage<InteractiveBoardRequest>())
- {
- request.SubscriberId = FLYINSONOUser.AccountId;
- request.RecipientIds = userIds;
- request.ChatSubscriberId = ConsultationInfo.TerminalInfo?.Id;
- request.JsonData = jsonData;
- var result = ClientLeaf.Send(request);
- if (result != null)
- {
- var resultMessage = ResultMessage.Convert(result);
- if (resultMessage != null && resultMessage.ResultCode == OKResult.Code)
- {
- return true;
- }
- }
- }
- }
- return false;
- }
- catch (Exception e)
- {
- Logger.WriteLineError($"Send InteractiveBoard Data error {e}");
- return false;
- }
- }
- /// <summary>
- /// 清除画板数据
- /// </summary>
- /// <returns></returns>
- public bool ClearInteractiveBoardData()
- {
- try
- {
- if (ConsultationInfo == null)
- {
- return false;
- }
- if (ConsultationInfo.ConsultationMemberInfos?.Count() > 1)
- {
- var userIds = ConsultationInfo.ConsultationMemberInfos.FindAll(x => x.Id != FLYINSONOUser.AccountId).ToList().Select(x => x.Id).ToList(); ;
- using (var request = MessagePool.GetMessage<ClearInteractiveBoardRequest>())
- {
- request.SubscriberId = FLYINSONOUser.AccountId;
- request.RecipientIds = userIds;
- request.ChatSubscriberId = ConsultationInfo.TerminalInfo?.Id; ;
- var result = ClientLeaf.Send(request);
- if (result != null)
- {
- var resultMessage = ResultMessage.Convert(result);
- if (resultMessage != null && resultMessage.ResultCode == OKResult.Code)
- {
- return true;
- }
- }
- }
- }
- return false;
- }
- catch (Exception e)
- {
- Logger.WriteLineError($"Clear InteractiveBoard Data error {e}");
- return false;
- }
- }
- public LiveStates Hangup(bool forceClosed)
- {
- var result = LiveStates.UnknowException;
- if (ConsultationInfo == null)
- {
- Logger.WriteLineWarn($"ConsultationHangup: Consultation is null");
- return result;
- }
- try
- {
- using (var request = new ExitMeetingRequest())
- {
- request.UserId = FLYINSONOUser.AccountId;
- request.RoomId = ConsultationInfo?.RoomId;
- request.RecipientIds = new List<string> { FLYINSONOUser.AccountId };
- request.LoginSource = FLYINSONOUser.LoginSource;
- request.ForceClosed = forceClosed;
- request.ClientLanguage = GetCurrentLanguage();
- var messageResult = ClientLeaf.Send(request);
- if (messageResult != null)
- {
- var resultMessage = ExitMeetingResult.Convert(messageResult);
- if (resultMessage != null)
- {
- result = resultMessage.State;
- }
- }
- }
- lock (ConsultationInfoLocker)
- {
- ConsultationInfo = null;
- }
- StopConsultation();
- CurrentLiveStatus = LiveStates.ChatHangup;
- Logger.WriteLineInfo($"ConsultationLive-- {FLYINSONOUser.Name} hangup end with result {result}");
- return result;
- }
- catch (Exception ex)
- {
- Logger.WriteLineWarn($"ConsultationHangup error: {ex}");
- }
- return result;
- }
- public LiveStates DestroyMeeting()
- {
- try
- {
- var result = LiveStates.UnknowException;
- if (string.IsNullOrEmpty(ConsultationInfo?.RoomId))
- {
- Logger.WriteLineError($"MeetingClient chat room id is null while sending destroyed request to server");
- return LiveStates.UnknowException;
- }
- using (var request = new DestroyMeetingRoomRequest())
- {
- request.RoomId = ConsultationInfo?.RoomId;
- request.UserId = FLYINSONOUser?.AccountId;
- var messageResult = ClientLeaf.Send(request);
- if (messageResult != null)
- {
- var resultMessage = ExitMeetingResult.Convert(messageResult);
- if (resultMessage != null)
- {
- result = resultMessage.State;
- }
- }
- }
- return result;
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"Error happened while sending destroyed room request with room id {ConsultationInfo?.RoomId} {ex}");
- return LiveStates.UnknowException;
- }
- }
- protected LanguageType GetCurrentLanguage()
- {
- switch (TranslateHelper.CurrentLanguage)
- {
- case TranslateHelper.ChineseLanguageKey:
- return LanguageType.Chinese;
- case TranslateHelper.EnglishLanguageKey:
- return LanguageType.English;
- case TranslateHelper.PortugueseLanguageKey:
- return LanguageType.Portuguese;
- case TranslateHelper.RomanianLanguageKey:
- return LanguageType.Romanian;
- default:
- return LanguageType.Unknown;
- }
- }
- protected void ConsultationMemberChange(MeetingMemberNotification meetingChangeMember)
- {
- VideoProvider.ConsultationMemberChange(meetingChangeMember);
- }
- public virtual void Dispose()
- {
- VideoProvider.RemoteUserLeaveRoomArrived -= OnRemoteUserLeaveRoomArrived;
- VideoProvider.CloseConsultation -= OnCloseMeeting;
- VideoProvider.TryToReconnect -= OnTryToReconnect;
- if (ClientLeaf != null)
- {
- ClientLeaf.MessageArrived -= OnMessageArrived;
- }
- }
- }
- }
|