ConsultationClient.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Vinno.IUS.Common.Log;
  5. using Vinno.IUS.Common.Network.Leaf;
  6. using Vinno.IUS.Common.Network.Transfer;
  7. using Vinno.IUS.Common.Utilities;
  8. using Vinno.vCloud.Common.FIS.FLYINSONOLogin;
  9. using Vinno.vCloud.Common.FIS.Helper;
  10. using Vinno.vCloud.FIS.CrossPlatform.Common.Consultation;
  11. using Vinno.vCloud.Protocol.Infrastructures;
  12. using Vinno.vCloud.Protocol.Messages.Client.Account;
  13. using Vinno.vCloud.Protocol.Messages.Client.Chat;
  14. using Vinno.vCloud.Protocol.Messages.Common;
  15. using Vinno.vCloud.Protocol.Messages.Live;
  16. namespace Vinno.vCloud.Common.FIS.Consultation
  17. {
  18. public class ConsultationSubscriberInfo
  19. {
  20. /// <summary>
  21. /// The Subscriber unique id
  22. /// </summary>
  23. public string Id { get; set; }
  24. /// <summary>
  25. /// roomId = chat table id
  26. /// </summary>
  27. public string RoomId { get; set; }
  28. }
  29. public enum ConsultationDisconnectedType
  30. {
  31. Timeout,
  32. ByClient,
  33. ByServer,
  34. CancelledByInitiator,
  35. NotOnline,
  36. HangupByOther,
  37. AcceptedInOtherDeivce,
  38. ExceptionHappend,
  39. KickBySomeone,
  40. RejecteByInitiator,
  41. SelfClientOffline,
  42. HangUpBySelf
  43. }
  44. internal abstract class ConsultationClient : IDisposable
  45. {
  46. private ConsultationInfo _consultationInfo;
  47. private EmergencyConsultationInfo _emergencyConsultationInfo;
  48. protected readonly object ConsultationInfoLocker = new object();
  49. protected readonly object EmergencyConsultationLocker = new object();
  50. protected int count = 0;
  51. /// <summary>
  52. /// Gets or sets the current live status
  53. /// </summary>
  54. public LiveStates CurrentLiveStatus { get; set; }
  55. /// <summary>
  56. /// Raised when meeting disconnected.
  57. /// </summary>
  58. public event EventHandler<ConsultationDisconnectedType> ConsultationDisconnected;
  59. /// <summary>
  60. /// Raised when meeting member changed
  61. /// </summary>
  62. public event EventHandler<ConsultationMemberNotificaiton> ConsultationMemberChangedNotificationArrived;
  63. /// <summary>
  64. /// other reject notify arrived from server
  65. /// </summary>
  66. public event EventHandler<ConsultationSubscriberInfo> RejectConsultationNotifyArrived;
  67. /// <summary>
  68. /// 接收到其他用户的白板信息
  69. /// </summary>
  70. public event EventHandler<InteractiveBoardInfo> InteractiveBoardInfoArrived;
  71. /// <summary>
  72. /// 接收到清除白板信息
  73. /// </summary>
  74. public event EventHandler<string> ClearInteractiveBoardArrived;
  75. /// <summary>
  76. /// Other one join the Consultation notification Arrived from server
  77. /// </summary>
  78. public event EventHandler<ConsultationInfo> JoinConsultationNotifyArrived;
  79. public event EventHandler<List<string>> MuteVideoUserListNotifyArrived;
  80. public ConsultationInfo ConsultationInfo
  81. {
  82. get => _consultationInfo;
  83. set
  84. {
  85. if (_consultationInfo != value)
  86. {
  87. _consultationInfo = value;
  88. count = 0;
  89. }
  90. }
  91. }
  92. public EmergencyConsultationInfo EmergencyConsultationInfo
  93. {
  94. get => _emergencyConsultationInfo;
  95. set
  96. {
  97. if (_emergencyConsultationInfo != value)
  98. {
  99. _emergencyConsultationInfo = value;
  100. }
  101. }
  102. }
  103. protected ConsultationLiveVideoProvider VideoProvider { get; }
  104. protected FLYINSONOUser FLYINSONOUser { get; set; }
  105. protected ClientLeaf ClientLeaf { get; set; }
  106. protected ConsultationClient(ConsultationLiveVideoProvider videoProvider)
  107. {
  108. CurrentLiveStatus = LiveStates.Idle;
  109. VideoProvider = videoProvider;
  110. VideoProvider.RemoteUserLeaveRoomArrived += OnRemoteUserLeaveRoomArrived;
  111. VideoProvider.CloseConsultation += OnCloseMeeting;
  112. VideoProvider.TryToReconnect += OnTryToReconnect;
  113. }
  114. protected void OnTryToReconnect(object sender, EventArgs e)
  115. {
  116. if (count > 1)
  117. {
  118. var member = ConsultationInfo?.ConsultationMemberInfos?.FirstOrDefault(f => f.Id == FLYINSONOUser?.AccountId);
  119. if (member != null)
  120. {
  121. OnDisconnected(ConsultationDisconnectedType.SelfClientOffline);
  122. }
  123. }
  124. else
  125. {
  126. count++;
  127. }
  128. }
  129. private void OnRemoteUserLeaveRoomArrived(object sender, RemoteUserLeaveRoomArgs e)
  130. {
  131. Logger.WriteLineInfo($"OnRemoteUserLeaveRoomArrived Arrived,UserId:{e.UserId},Reason:{e.Reason}");
  132. if (ConsultationInfo != null)
  133. {
  134. var member = ConsultationInfo?.ConsultationMemberInfos?.FirstOrDefault(f => f.Id == e.UserId);
  135. if (member != null)
  136. {
  137. if (member.Id == FLYINSONOUser?.AccountId && (member.RoleType == ConsultationRoleType.Initiator || member.RoleType == ConsultationRoleType.Recipient))
  138. {
  139. DestroyMeeting();
  140. OnDisconnected(ConsultationDisconnectedType.SelfClientOffline);
  141. }
  142. else if (member.Id != FLYINSONOUser?.AccountId && (member.RoleType == ConsultationRoleType.Initiator || member.RoleType == ConsultationRoleType.Recipient))
  143. {
  144. DestroyMeeting();
  145. OnDisconnected(ConsultationDisconnectedType.HangupByOther);
  146. }
  147. else
  148. {
  149. VideoProvider.RemoveVideoProvider(member.Id);
  150. ConsultationInfo.ConsultationMemberInfos.Remove(member);
  151. }
  152. }
  153. }
  154. }
  155. private void OnCloseMeeting(object sender, EventArgs e)
  156. {
  157. OnDisconnected(ConsultationDisconnectedType.SelfClientOffline);
  158. }
  159. protected void OnJoinConsultationNotifyArrived()
  160. {
  161. JoinConsultationNotifyArrived?.Invoke(this, ConsultationInfo);
  162. }
  163. /// <summary>
  164. /// Update client leaf after flyinsono user login.
  165. /// </summary>
  166. /// <param name="clientLeaf"></param>
  167. /// <param name="flyinsonoUser"></param>
  168. public void Update(ClientLeaf clientLeaf, FLYINSONOUser flyinsonoUser)
  169. {
  170. FLYINSONOUser = flyinsonoUser;
  171. if (ClientLeaf != null)
  172. {
  173. ClientLeaf.MessageArrived -= OnMessageArrived;
  174. ClientLeaf = null;
  175. }
  176. ClientLeaf = clientLeaf;
  177. if (ClientLeaf != null)
  178. {
  179. ClientLeaf.MessageArrived += OnMessageArrived;
  180. }
  181. }
  182. protected EmergencyConsultationInfo GetEmergencyConsultationExpertsInfo()
  183. {
  184. using (var request = MessagePool.GetMessage<FindSortedExpertsRequest2>())
  185. {
  186. var result = ClientLeaf?.Send(request);
  187. if (result != null)
  188. {
  189. var resultMessage = FindSortedExpertsResult2.Convert(result);
  190. if (resultMessage != null)
  191. {
  192. var sortExperts = resultMessage.SortedExperts.Select(f => new EmergencyConsultationExpertInfo()
  193. {
  194. UserId = f.UserId,
  195. HospitalId = f.HospitalId,
  196. Sort = f.Sort,
  197. UserName = f.UserName,
  198. ShowName = f.ShowName,
  199. }).OrderBy(x => x.Sort).ToList();
  200. return new EmergencyConsultationInfo()
  201. {
  202. CurrentSort = sortExperts.FirstOrDefault() != null ? sortExperts.FirstOrDefault().Sort : 0,
  203. SortExperts = sortExperts,
  204. NoExpertCause = resultMessage.NoExpertCause
  205. };
  206. }
  207. }
  208. }
  209. return new EmergencyConsultationInfo()
  210. {
  211. CurrentSort = 0,
  212. SortExperts = new List<EmergencyConsultationExpertInfo>(),
  213. };
  214. }
  215. protected virtual void OnMessageArrived(object sender, Message e)
  216. {
  217. if (ConsultationInfo == null)
  218. {
  219. return;
  220. }
  221. var muteVideoUserChangeNotification = MuteVideoUserChangeNotification.Convert(e);
  222. if (muteVideoUserChangeNotification != null)
  223. {
  224. HandleMuteVideoUserChangeNotification(muteVideoUserChangeNotification);
  225. }
  226. var hangupNotification = MeetingHangupNotification.Convert(e); //挂断
  227. if (hangupNotification != null)
  228. {
  229. HandleMeetingHangupNotification(hangupNotification);
  230. }
  231. var chatPendingMemberTimeoutNotification = ChatPendingMemberTimeoutNotification.Convert(e);
  232. if (chatPendingMemberTimeoutNotification != null)
  233. {
  234. HandleChatPendingMemberTimeoutNotification(chatPendingMemberTimeoutNotification);
  235. }
  236. var meetingMemberNotification = MeetingMemberNotification.Convert(e); //用户发生变化
  237. if (meetingMemberNotification != null)
  238. {
  239. Logger.WriteLineInfo("LiveMeeting MeetingMemberNotification Arrived");
  240. HandleConsultationMemberNotificationArrived(meetingMemberNotification);
  241. }
  242. var chatMemberHeartBeatStatusNotification = ChatMemberHeartbeatStatusNotification.Convert(e);
  243. if (chatMemberHeartBeatStatusNotification != null)
  244. {
  245. HandleConsultationMemberHeartbeatStatusNotificationArrived(chatMemberHeartBeatStatusNotification);
  246. }
  247. var rejectMeetingNotification = RejectMeetingNotification.Convert(e); //拒绝会诊通知
  248. if (rejectMeetingNotification != null)
  249. {
  250. HandleRejectConsultationNotification(rejectMeetingNotification);
  251. }
  252. var interactiveBoardNotification = InteractiveBoardNotification.Convert(e);
  253. if (interactiveBoardNotification != null)
  254. {
  255. HandleInteractiveBoardNotification(interactiveBoardNotification);
  256. }
  257. var clearInteractiveBoardNotification = ClearInteractiveBoardNotification.Convert(e);
  258. if (clearInteractiveBoardNotification != null)
  259. {
  260. HandleClearInteractiveBoardNotification(clearInteractiveBoardNotification);
  261. }
  262. }
  263. private void HandleMuteVideoUserChangeNotification(MuteVideoUserChangeNotification muteVideoUserChangeNotification)
  264. {
  265. Logger.WriteLineInfo("HandleMuteVideoUserChangeNotification Arrived");
  266. if (muteVideoUserChangeNotification.RoomId != ConsultationInfo?.RoomId)
  267. {
  268. Logger.WriteLineInfo($"Consultation Client HandleMuteVideoUserChangeNotification,RoomId:{ConsultationInfo?.RoomId},NotificationRoomId:{muteVideoUserChangeNotification.RoomId}");
  269. return;
  270. }
  271. MuteVideoUserListNotifyArrived?.Invoke(this, muteVideoUserChangeNotification.MuteVideoUsers.ToList() ?? new List<string>());
  272. }
  273. private void HandleMeetingHangupNotification(MeetingHangupNotification hangupNotification)
  274. {
  275. Logger.WriteLineInfo("HandleMeetingHangupNotification Arrived");
  276. switch (hangupNotification.HangupReason)
  277. {
  278. case LiveStates.HeartBeatDown:
  279. OnDisconnected(ConsultationDisconnectedType.ExceptionHappend);
  280. break;
  281. case LiveStates.InitiativeExit:
  282. OnDisconnected(ConsultationDisconnectedType.HangupByOther);
  283. break;
  284. case LiveStates.Cancelled:
  285. OnDisconnected(ConsultationDisconnectedType.CancelledByInitiator);
  286. break;
  287. default:
  288. OnDisconnected(ConsultationDisconnectedType.HangupByOther);
  289. break;
  290. }
  291. Logger.WriteLineInfo($"EndMeetingNotification handled");
  292. }
  293. private void HandleChatPendingMemberTimeoutNotification(ChatPendingMemberTimeoutNotification chatPendingMemberTimeoutNotification)
  294. {
  295. Logger.WriteLineInfo("HandleChatPendingMemberTimeoutNotification Arrived");
  296. if (chatPendingMemberTimeoutNotification.RoomId != ConsultationInfo?.RoomId)
  297. {
  298. Logger.WriteLineInfo($"Consultation Client OnChatPendingMemberTimeoutNotificationArrived,RoomId:{ConsultationInfo?.RoomId},NotificationRoomId:{chatPendingMemberTimeoutNotification.RoomId}");
  299. return;
  300. }
  301. Logger.WriteLineInfo($"Consultation Client OnChatPendingMemberTimeoutNotificationArrived");
  302. foreach (var userId in chatPendingMemberTimeoutNotification.UserIds)
  303. {
  304. var member = ConsultationInfo?.ConsultationMemberInfos?.FirstOrDefault(f => f.Id == userId);
  305. if (member != null)
  306. {
  307. if (member.Id == FLYINSONOUser.AccountId)
  308. {
  309. OnDisconnected(ConsultationDisconnectedType.Timeout);
  310. }
  311. else
  312. {
  313. VideoProvider.RemoveVideoProvider(member.Id);
  314. member.State = LiveStates.RecipientRejected;
  315. member.OperationType = ClientMessageOperationType.Delete;
  316. OnConsultationMemberChangedNotificationArrived(new ConsultationMemberNotificaiton()
  317. {
  318. RoomId = chatPendingMemberTimeoutNotification.RoomId,
  319. Members = new List<ConsultationMemberInfo> { member },
  320. LiveTerminals = new List<TerminalInfo>()
  321. });
  322. ConsultationInfo.ConsultationMemberInfos.Remove(member);
  323. }
  324. }
  325. }
  326. }
  327. private void HandleClearInteractiveBoardNotification(ClearInteractiveBoardNotification clearInteractiveBoardNotification)
  328. {
  329. Logger.WriteLineInfo($"HandleClearInteractiveBoardNotification Arrived,Current Id:{FLYINSONOUser?.AccountId},RecipientId:{clearInteractiveBoardNotification.RecipientId}");
  330. if (clearInteractiveBoardNotification.RecipientId == FLYINSONOUser.AccountId)
  331. {
  332. ClearInteractiveBoardArrived?.Invoke(this, clearInteractiveBoardNotification.ChatSubscriberId);
  333. }
  334. }
  335. private void HandleInteractiveBoardNotification(InteractiveBoardNotification interactiveBoardNotification)
  336. {
  337. Logger.WriteLineInfo($"InteractiveBoardNotification Arrived,Current Id:{FLYINSONOUser?.AccountId},RecipientId:{interactiveBoardNotification.RecipientId}");
  338. if (interactiveBoardNotification.RecipientId == FLYINSONOUser.AccountId)
  339. {
  340. InteractiveBoardInfoArrived?.Invoke(this,
  341. new InteractiveBoardInfo(interactiveBoardNotification.SubscriberId,
  342. interactiveBoardNotification.RecipientId,
  343. interactiveBoardNotification.ChatSubscriberId,
  344. interactiveBoardNotification.JsonData));
  345. }
  346. }
  347. private void HandleRejectConsultationNotification(RejectMeetingNotification rejectMeetingNotification)
  348. {
  349. Logger.WriteLineInfo("RejectConsultationNotification Arrived");
  350. var arg = new ConsultationSubscriberInfo()
  351. {
  352. Id = rejectMeetingNotification.UserId,
  353. RoomId = rejectMeetingNotification.RoomId
  354. };
  355. var member = ConsultationInfo.ConsultationMemberInfos.FirstOrDefault(f => f.Id == arg.Id);
  356. if (member != null)
  357. {
  358. VideoProvider.RemoveVideoProvider(member.Id);
  359. member.State = LiveStates.RecipientRejected;
  360. member.OperationType = ClientMessageOperationType.Delete;
  361. if (ConsultationInfo.ChatRole == ChatRole.Initiator)
  362. {
  363. if (ConsultationInfo.ConsultationMemberInfos.Count() <= 2)
  364. {
  365. CurrentLiveStatus = LiveStates.RecipientRejected;
  366. }
  367. OnRejectConsultationNotifyArrived(arg);
  368. }
  369. else
  370. {
  371. OnConsultationMemberChangedNotificationArrived(new ConsultationMemberNotificaiton()
  372. {
  373. RoomId = rejectMeetingNotification.RoomId,
  374. Members = new List<ConsultationMemberInfo> { member },
  375. LiveTerminals = new List<TerminalInfo>()
  376. });
  377. }
  378. ConsultationInfo.ConsultationMemberInfos.Remove(member);
  379. }
  380. Logger.WriteLineInfo($"RejectConsultationNotification handled Id:{arg.Id},RoomId:{arg.RoomId}");
  381. }
  382. protected void OnRejectConsultationNotifyArrived(ConsultationSubscriberInfo e)
  383. {
  384. RejectConsultationNotifyArrived?.Invoke(this, e);
  385. }
  386. private void HandleConsultationMemberHeartbeatStatusNotificationArrived(ChatMemberHeartbeatStatusNotification chatMemberHeartBeatStatusNotification)
  387. {
  388. Logger.WriteLineInfo($"LiveMeeting ChatMemberHeartbeatStatusNotification Arrived, Current Id:{FLYINSONOUser?.AccountId}, Heart Beat Member Id:{chatMemberHeartBeatStatusNotification.HeartBeatMemberId}");
  389. if (FLYINSONOUser?.AccountId == chatMemberHeartBeatStatusNotification.HeartBeatMemberId)
  390. {
  391. OnDisconnected(ConsultationDisconnectedType.ByServer);
  392. }
  393. else
  394. {
  395. var member = ConsultationInfo?.ConsultationMemberInfos?.FirstOrDefault(f => f.Id == chatMemberHeartBeatStatusNotification.HeartBeatMemberId);
  396. if (member != null && (member.RoleType == ConsultationRoleType.Administrator || member.RoleType == ConsultationRoleType.Expert))
  397. {
  398. VideoProvider.RemoveVideoProvider(chatMemberHeartBeatStatusNotification.HeartBeatMemberId);
  399. member.State = chatMemberHeartBeatStatusNotification.LiveStates;
  400. member.OperationType = ClientMessageOperationType.Delete;
  401. OnConsultationMemberChangedNotificationArrived(new ConsultationMemberNotificaiton()
  402. {
  403. RoomId = chatMemberHeartBeatStatusNotification.RoomId,
  404. Members = new List<ConsultationMemberInfo> { member },
  405. LiveTerminals = new List<TerminalInfo>()
  406. });
  407. ConsultationInfo.ConsultationMemberInfos.Remove(member);
  408. }
  409. }
  410. }
  411. protected virtual void HandleConsultationMemberNotificationArrived(MeetingMemberNotification meetingMemberNotification)
  412. {
  413. var consultationMemberNotification = DTOConverter.ConvertMeetingMemberNotificationToConsultationMemberNotificaiton(meetingMemberNotification);
  414. OnConsultationMemberChangedNotificationArrived(consultationMemberNotification);
  415. }
  416. private void OnConsultationMemberChangedNotificationArrived(ConsultationMemberNotificaiton consultationMemberNotificaiton)
  417. {
  418. ConsultationMemberChangedNotificationArrived?.Invoke(this, consultationMemberNotificaiton);
  419. }
  420. protected string GetAccoutNameByAccountId(string accountId)
  421. {
  422. using (var request = MessagePool.GetMessage<FindUserInfoByIdRequest>())
  423. {
  424. request.AccountId = accountId;
  425. var result = ClientLeaf.Send(request);
  426. if (result != null)
  427. {
  428. var resultMessage = FindUserInfoByIdResult.Convert(result);
  429. if (resultMessage != null)
  430. {
  431. if (!string.IsNullOrWhiteSpace(resultMessage.FullName))
  432. {
  433. return resultMessage.FullName;
  434. }
  435. if (!string.IsNullOrWhiteSpace(resultMessage.NickName))
  436. {
  437. return resultMessage.NickName;
  438. }
  439. return resultMessage.Name;
  440. }
  441. }
  442. }
  443. return null;
  444. }
  445. protected void OnDisconnected(ConsultationDisconnectedType e)
  446. {
  447. try
  448. {
  449. StopConsultation();
  450. }
  451. catch (Exception ex)
  452. {
  453. Logger.WriteLineError($"Consultationclient- error happended while disconnectting: {ex}");
  454. }
  455. finally
  456. {
  457. ConsultationDisconnected?.Invoke(this, e);
  458. lock (ConsultationInfoLocker)
  459. {
  460. Logger.WriteLineInfo($"Current consultation info is set to null on reson: {e}");
  461. ConsultationInfo = null;
  462. }
  463. ////Here create a window period for exiting rtc room
  464. //Thread.Sleep(100);
  465. CurrentLiveStatus = LiveStates.Disconnected;
  466. }
  467. }
  468. protected void StopConsultation()
  469. {
  470. var isMeetting = CurrentLiveStatus == LiveStates.RecipientAcceptted || CurrentLiveStatus == LiveStates.RecipientAcceptting;
  471. if (isMeetting)
  472. {
  473. VideoProvider.Hangup();
  474. CurrentLiveStatus = LiveStates.Idle;
  475. }
  476. else
  477. {
  478. Logger.WriteLineInfo($"Don't do stop consultation video since no rtc consultation is not started");
  479. }
  480. }
  481. protected void StartConsultation(string cameraHardwareId, string micHardwareId, string speakerHardwareId)
  482. {
  483. try
  484. {
  485. VideoProvider.StartConsultationVideo(ConsultationInfo, FLYINSONOUser.AccountId, FLYINSONOUser.Name, cameraHardwareId, micHardwareId, speakerHardwareId, ClientLeaf);
  486. }
  487. catch (Exception ex)
  488. {
  489. Logger.WriteLineError($"Error happened while start meeting {ex}");
  490. }
  491. }
  492. /// <summary>
  493. /// 发送画板数据
  494. /// </summary>
  495. /// <param name="jsonData"></param>
  496. /// <returns></returns>
  497. public bool SendInteractiveBoardData(string jsonData)
  498. {
  499. try
  500. {
  501. if (ConsultationInfo == null)
  502. {
  503. return false;
  504. }
  505. if (jsonData != null && ConsultationInfo.ConsultationMemberInfos?.Count() > 1)
  506. {
  507. var userIds = ConsultationInfo.ConsultationMemberInfos.FindAll(x => x.Id != FLYINSONOUser.AccountId).ToList().Select(x => x.Id).ToList(); ;
  508. using (var request = MessagePool.GetMessage<InteractiveBoardRequest>())
  509. {
  510. request.SubscriberId = FLYINSONOUser.AccountId;
  511. request.RecipientIds = userIds;
  512. request.ChatSubscriberId = ConsultationInfo.TerminalInfo?.Id;
  513. request.JsonData = jsonData;
  514. var result = ClientLeaf.Send(request);
  515. if (result != null)
  516. {
  517. var resultMessage = ResultMessage.Convert(result);
  518. if (resultMessage != null && resultMessage.ResultCode == OKResult.Code)
  519. {
  520. return true;
  521. }
  522. }
  523. }
  524. }
  525. return false;
  526. }
  527. catch (Exception e)
  528. {
  529. Logger.WriteLineError($"Send InteractiveBoard Data error {e}");
  530. return false;
  531. }
  532. }
  533. /// <summary>
  534. /// 清除画板数据
  535. /// </summary>
  536. /// <returns></returns>
  537. public bool ClearInteractiveBoardData()
  538. {
  539. try
  540. {
  541. if (ConsultationInfo == null)
  542. {
  543. return false;
  544. }
  545. if (ConsultationInfo.ConsultationMemberInfos?.Count() > 1)
  546. {
  547. var userIds = ConsultationInfo.ConsultationMemberInfos.FindAll(x => x.Id != FLYINSONOUser.AccountId).ToList().Select(x => x.Id).ToList(); ;
  548. using (var request = MessagePool.GetMessage<ClearInteractiveBoardRequest>())
  549. {
  550. request.SubscriberId = FLYINSONOUser.AccountId;
  551. request.RecipientIds = userIds;
  552. request.ChatSubscriberId = ConsultationInfo.TerminalInfo?.Id; ;
  553. var result = ClientLeaf.Send(request);
  554. if (result != null)
  555. {
  556. var resultMessage = ResultMessage.Convert(result);
  557. if (resultMessage != null && resultMessage.ResultCode == OKResult.Code)
  558. {
  559. return true;
  560. }
  561. }
  562. }
  563. }
  564. return false;
  565. }
  566. catch (Exception e)
  567. {
  568. Logger.WriteLineError($"Clear InteractiveBoard Data error {e}");
  569. return false;
  570. }
  571. }
  572. public LiveStates Hangup(bool forceClosed)
  573. {
  574. var result = LiveStates.UnknowException;
  575. if (ConsultationInfo == null)
  576. {
  577. Logger.WriteLineWarn($"ConsultationHangup: Consultation is null");
  578. return result;
  579. }
  580. try
  581. {
  582. using (var request = new ExitMeetingRequest())
  583. {
  584. request.UserId = FLYINSONOUser.AccountId;
  585. request.RoomId = ConsultationInfo?.RoomId;
  586. request.RecipientIds = new List<string> { FLYINSONOUser.AccountId };
  587. request.LoginSource = FLYINSONOUser.LoginSource;
  588. request.ForceClosed = forceClosed;
  589. request.ClientLanguage = GetCurrentLanguage();
  590. var messageResult = ClientLeaf.Send(request);
  591. if (messageResult != null)
  592. {
  593. var resultMessage = ExitMeetingResult.Convert(messageResult);
  594. if (resultMessage != null)
  595. {
  596. result = resultMessage.State;
  597. }
  598. }
  599. }
  600. lock (ConsultationInfoLocker)
  601. {
  602. ConsultationInfo = null;
  603. }
  604. StopConsultation();
  605. CurrentLiveStatus = LiveStates.ChatHangup;
  606. Logger.WriteLineInfo($"ConsultationLive-- {FLYINSONOUser.Name} hangup end with result {result}");
  607. return result;
  608. }
  609. catch (Exception ex)
  610. {
  611. Logger.WriteLineWarn($"ConsultationHangup error: {ex}");
  612. }
  613. return result;
  614. }
  615. public LiveStates DestroyMeeting()
  616. {
  617. try
  618. {
  619. var result = LiveStates.UnknowException;
  620. if (string.IsNullOrEmpty(ConsultationInfo?.RoomId))
  621. {
  622. Logger.WriteLineError($"MeetingClient chat room id is null while sending destroyed request to server");
  623. return LiveStates.UnknowException;
  624. }
  625. using (var request = new DestroyMeetingRoomRequest())
  626. {
  627. request.RoomId = ConsultationInfo?.RoomId;
  628. request.UserId = FLYINSONOUser?.AccountId;
  629. var messageResult = ClientLeaf.Send(request);
  630. if (messageResult != null)
  631. {
  632. var resultMessage = ExitMeetingResult.Convert(messageResult);
  633. if (resultMessage != null)
  634. {
  635. result = resultMessage.State;
  636. }
  637. }
  638. }
  639. return result;
  640. }
  641. catch (Exception ex)
  642. {
  643. Logger.WriteLineError($"Error happened while sending destroyed room request with room id {ConsultationInfo?.RoomId} {ex}");
  644. return LiveStates.UnknowException;
  645. }
  646. }
  647. protected LanguageType GetCurrentLanguage()
  648. {
  649. switch (TranslateHelper.CurrentLanguage)
  650. {
  651. case TranslateHelper.ChineseLanguageKey:
  652. return LanguageType.Chinese;
  653. case TranslateHelper.EnglishLanguageKey:
  654. return LanguageType.English;
  655. case TranslateHelper.PortugueseLanguageKey:
  656. return LanguageType.Portuguese;
  657. case TranslateHelper.RomanianLanguageKey:
  658. return LanguageType.Romanian;
  659. default:
  660. return LanguageType.Unknown;
  661. }
  662. }
  663. protected void ConsultationMemberChange(MeetingMemberNotification meetingChangeMember)
  664. {
  665. VideoProvider.ConsultationMemberChange(meetingChangeMember);
  666. }
  667. public virtual void Dispose()
  668. {
  669. VideoProvider.RemoteUserLeaveRoomArrived -= OnRemoteUserLeaveRoomArrived;
  670. VideoProvider.CloseConsultation -= OnCloseMeeting;
  671. VideoProvider.TryToReconnect -= OnTryToReconnect;
  672. if (ClientLeaf != null)
  673. {
  674. ClientLeaf.MessageArrived -= OnMessageArrived;
  675. }
  676. }
  677. }
  678. }