liveconsultationmanager.dart 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. import 'dart:convert';
  2. import 'package:fis_common/event/event_type.dart';
  3. import 'package:fis_i18n/i18n.dart';
  4. import 'package:fis_jsonrpc/rpc.dart';
  5. import 'package:flyinsonolite/jsonrpc/jsonrpcclient.dart';
  6. import 'package:flyinsonolite/managers/basemanager.dart';
  7. import 'package:flyinsonolite/managers/interfaces/iappointmentmanager.dart';
  8. import 'package:flyinsonolite/managers/interfaces/iliveconsultationmanager.dart';
  9. import 'package:flyinsonolite/managers/interfaces/irtmpmockrtcmanager.dart';
  10. import 'package:flyinsonolite/consultation/records/models/consultationmember.dart';
  11. import 'package:flyinsonolite/consultation/records/models/liveconsultation.dart';
  12. import 'package:flyinsonolite/infrastructure/storage.dart';
  13. import 'package:flyinsonolite/notifications/handlers/acceptliveconsultationnotificationhandler.dart';
  14. import 'package:flyinsonolite/notifications/handlers/cancelinvitinginliveconsultationhandler.dart';
  15. import 'package:flyinsonolite/notifications/handlers/cancelinvitinginlivecoursenotificationhandler.dart';
  16. import 'package:flyinsonolite/notifications/handlers/cancelliveconsultationnotificationhandler.dart';
  17. import 'package:flyinsonolite/notifications/handlers/changeconsultationnotificationhandler.dart';
  18. import 'package:flyinsonolite/notifications/handlers/closeLiveconsultationnotificationhandler.dart';
  19. import 'package:flyinsonolite/notifications/handlers/closeconsultationduetochangenotificationhandler.dart';
  20. import 'package:flyinsonolite/notifications/handlers/consultationanswertimeouthandler.dart';
  21. import 'package:flyinsonolite/notifications/handlers/emergencycallnotificationhandler.dart';
  22. import 'package:flyinsonolite/notifications/handlers/heartRatejoinconsultationhandler.dart';
  23. import 'package:flyinsonolite/notifications/handlers/heartrateleaveconsultationhandler.dart';
  24. import 'package:flyinsonolite/notifications/handlers/inviteinliveconsultationhandler.dart';
  25. import 'package:flyinsonolite/notifications/handlers/inviteliveconsultationnotificationhandler.dart';
  26. import 'package:flyinsonolite/notifications/handlers/joininliveconsultationnotificationhandler.dart';
  27. import 'package:flyinsonolite/notifications/handlers/joinliveconsultationnotificationhandler.dart';
  28. import 'package:flyinsonolite/notifications/handlers/leaveconsultationnotificationhandler.dart';
  29. import 'package:flyinsonolite/notifications/handlers/muteliveconsultationhandler.dart';
  30. import 'package:flyinsonolite/notifications/handlers/networkerrconsultationnotificationhandler.dart';
  31. import 'package:flyinsonolite/notifications/handlers/rejectinviteliveconsultationhandler.dart';
  32. import 'package:flyinsonolite/notifications/handlers/rejectliveconsultationhandler.dart';
  33. import 'package:flyinsonolite/notifications/handlers/sendinteractiveboarddatahandler.dart';
  34. import 'package:flyinsonolite/notifications/handlers/switchvideoplayconsultationhandler.dart';
  35. import 'package:get/get.dart';
  36. class LiveConsultationManager extends BaseManager
  37. implements ILiveConsultationManager {
  38. @override
  39. late ConsultationDetailDTO consultationDetail;
  40. ///急诊的时候用到
  41. @override
  42. late LiveConsultation liveConsultation;
  43. @override
  44. late String currentConsultationCode = "";
  45. /// 白板数据接收
  46. @override
  47. FEventHandler<String> onWhiteboardDataReceive = FEventHandler<String>();
  48. ///开始会诊通知事件 11
  49. @override
  50. FEventHandler<LiveConsultation> onInviteLiveConsultation =
  51. FEventHandler<LiveConsultation>();
  52. ///会诊过程中邀请成员的通知(通知被邀请者) 8
  53. @override
  54. final FEventHandler<LiveConsultation> onInviteeInLiveConsultation =
  55. FEventHandler<LiveConsultation>();
  56. ///取消会诊过程中邀请成员的通知(通知被邀请者) 7
  57. @override
  58. final FEventHandler<LiveConsultation> onCancelInvitingConsultation =
  59. FEventHandler<LiveConsultation>();
  60. ///邀请者接受会诊通知事件(通知发起者)12
  61. @override
  62. final FEventHandler<LiveConsultation> onAcceptConsultation =
  63. FEventHandler<LiveConsultation>();
  64. ///邀请者拒绝会诊事件(通知发起者) 13
  65. @override
  66. final FEventHandler<LiveConsultation> onRejectConsultation =
  67. FEventHandler<LiveConsultation>();
  68. ///邀请者取消接听会诊事件(通知发起者) 7
  69. @override
  70. final FEventHandler<LiveConsultation> onCancelConsultation =
  71. FEventHandler<LiveConsultation>();
  72. ///关闭会诊事件(通知所有成员) 16
  73. @override
  74. final FEventHandler<LiveConsultation> onCloseConsultation =
  75. FEventHandler<LiveConsultation>();
  76. //成员加入会诊事件(通知所有成员)-
  77. @override
  78. FEventHandler<LiveConsultation> onAcceptLiveConsultation =
  79. FEventHandler<LiveConsultation>();
  80. ///成员加入会诊事件(通知所有成员)
  81. @override
  82. final FEventHandler<LiveConsultation> onJoinConsultation =
  83. FEventHandler<LiveConsultation>();
  84. ///成员加入会诊事件(通知所有成员) 被邀请者进入房间通知
  85. @override
  86. final FEventHandler<LiveConsultation> onJoinInConsultation =
  87. FEventHandler<LiveConsultation>();
  88. ///成员离开会诊事件(通知所有成员)19
  89. @override
  90. final FEventHandler<LiveConsultation> onLeaveConsultation =
  91. FEventHandler<LiveConsultation>();
  92. ///某个成员网络不佳通知事件(通知所有成员) 18
  93. @override
  94. final FEventHandler<LiveConsultation> onNetworkErrConsultation =
  95. FEventHandler<LiveConsultation>();
  96. /// 68 取消呼叫 to 客户端
  97. @override
  98. FEventHandler<CancelInvitingInLiveCourseNotification>
  99. onCancelInvitingInLiveCourseNotification =
  100. FEventHandler<CancelInvitingInLiveCourseNotification>();
  101. ///开启会诊事件
  102. @override
  103. FEventHandler<LiveConsultation> onStartLiveConsultation =
  104. FEventHandler<LiveConsultation>();
  105. //成员静音通知
  106. @override
  107. final FEventHandler<ConsultationMember> onMemberMute =
  108. FEventHandler<ConsultationMember>();
  109. //成员视频关闭与否通知
  110. @override
  111. final FEventHandler<ConsultationMember> onSwitchVideoPlay =
  112. FEventHandler<ConsultationMember>();
  113. ///会诊间改变
  114. @override
  115. final FEventHandler<LiveConsultation> onChangeConsultation =
  116. FEventHandler<LiveConsultation>();
  117. ///会诊间改变,成员不在新的会诊间,需退出
  118. @override
  119. FEventHandler<LiveConsultation> onCloseConsultationDueToChange =
  120. FEventHandler<LiveConsultation>();
  121. LiveConsultationManager() {
  122. // 互动白板数据通知
  123. var sendInteractiveBoardDataHandler =
  124. Get.find<SendInteractiveBoardDataHandler>();
  125. sendInteractiveBoardDataHandler
  126. .subscribe(_onSendInteractiveBoardDataHandler);
  127. // 取消会诊过程中邀请成员的通知 7
  128. var cancelInvitingHandler =
  129. Get.find<CancelInvitingInLiveConsultationHandler>();
  130. cancelInvitingHandler.subscribe(_onCancelInvitingHandler);
  131. //会诊过程中邀请成员的通知 8
  132. var inviteInLiveConsulationHandler =
  133. Get.find<InviteInLiveConsultationHandler>();
  134. inviteInLiveConsulationHandler.subscribe(_onInviteInLiveHandler);
  135. //开始会诊的通知 11
  136. var inviteLiveConsultHandler =
  137. Get.find<InviteLiveConsultationNotificationHandler>();
  138. inviteLiveConsultHandler.subscribe(_onInviteLiveConsultHandler);
  139. //接受会诊的通知 12
  140. var acceptLiveConsultationHandler =
  141. Get.find<AcceptLiveConsultationNotificationHandler>();
  142. acceptLiveConsultationHandler.subscribe(_onAcceptLiveConsultationHandler);
  143. //拒绝会诊的通知 13
  144. var rejectLiveConsultationHandler =
  145. Get.find<RejectLiveConsultationHandler>();
  146. rejectLiveConsultationHandler.subscribe(_onRejectLiveConsultationHandler);
  147. //拒绝会诊的通知 21
  148. var rejectInviteLiveConsultationHandler =
  149. Get.find<RejectInviteLiveConsultationHandler>();
  150. rejectInviteLiveConsultationHandler
  151. .subscribe(_onRejectInviteLiveConsultationHandler);
  152. //取消会诊通知 15
  153. var cancelLiveConsultation =
  154. Get.find<CancelLiveConsultationNotificationHandler>();
  155. cancelLiveConsultation.subscribe(_onCancelLiveConsultation);
  156. //关闭会诊通知, 基层一直不接自动取消后会发送这个通知 16
  157. var closeLiveConsultHandler =
  158. Get.find<CloseLiveConsultationNotificationHandler>();
  159. closeLiveConsultHandler.subscribe(_onCloseLiveConsultHandler);
  160. // 进入会诊通知 17
  161. var joinLiveConsultHandler =
  162. Get.find<JoinLiveConsultationNotificationHandler>();
  163. joinLiveConsultHandler.subscribe(_onJoinLiveConsultHandler);
  164. //网络质量不佳会诊通知 18
  165. var networkErrConsultationHandler =
  166. Get.find<NetworkErrConsultationNotificationHandler>();
  167. networkErrConsultationHandler.subscribe(_onNetworkErrConsultationHandler);
  168. //离开会诊通知 19
  169. var leaveConsultationHandler =
  170. Get.find<LeaveConsultationNotificationHandler>();
  171. leaveConsultationHandler.subscribe(_onleaveConsultationHandler);
  172. //20 邀请的成员加入会诊
  173. var joinInHandler = Get.find<JoinInLiveConsultationNotificationHandler>();
  174. joinInHandler.subscribe(_onJoinInLiveConsultationHandler);
  175. //成员静音通知 27
  176. var muteLiveConsultationHandler = Get.find<MuteLiveConsultationHandler>();
  177. muteLiveConsultationHandler.subscribe(_onMuteLiveConsultationHandler);
  178. //成员启用或关闭摄像头通知 28
  179. var switchVideoPlayConsultationHandler =
  180. Get.find<SwitchVideoPlayConsultationHandler>();
  181. switchVideoPlayConsultationHandler
  182. .subscribe(_onSwitchVideoPlayConsultationHandler);
  183. ///心跳加入
  184. var heartRateJoinConsultationHandler =
  185. Get.find<HeartRateJoinConsultationHandler>();
  186. heartRateJoinConsultationHandler
  187. .subscribe(_onHeartRateJoinConsultationHandler);
  188. //成员心跳断开离开 30
  189. var heartRateLeaveConsultationHandler =
  190. Get.find<HeartRateLeaveConsultationHandler>();
  191. heartRateLeaveConsultationHandler
  192. .subscribe(_onHeartRateLeaveConsultationHandler);
  193. //切换房间,但成员需离开
  194. var closeConsultationDueToChangeNotificationHandler =
  195. Get.find<CloseConsultationDueToChangeNotificationHandler>();
  196. closeConsultationDueToChangeNotificationHandler
  197. .subscribe(_onCloseConsultationDueToChangeHandler);
  198. //切换房间,但成员需离开
  199. var changeConsultationNotification =
  200. Get.find<ChangeConsultationNotificationHandler>();
  201. changeConsultationNotification.subscribe(_onChangeConsultationHandler);
  202. ///急诊呼叫专家通知 37
  203. var emergencyCallNotificationHandler =
  204. Get.find<EmergencyCallNotificationHandler>();
  205. emergencyCallNotificationHandler
  206. .subscribe(_onEmergencyCallNotificationHandler);
  207. ///呼叫超时
  208. var consultationAnswerTimeoutHandler =
  209. Get.find<ConsultationAnswerTimeoutHandler>();
  210. consultationAnswerTimeoutHandler.subscribe(_onAnswerTimeoutHandler);
  211. /// 取消呼叫 to 客户端 68
  212. var cancelInvitingInLiveCourseNotificationHandler =
  213. Get.find<CancelInvitingInLiveCourseNotificationHandler>();
  214. cancelInvitingInLiveCourseNotificationHandler
  215. .subscribe(_onCancelInvitingInLiveCourseNotificationHandler);
  216. }
  217. void _onInviteInLiveHandler(InviteInLiveConsultationNotification message) {
  218. var consulation = LiveConsultation(
  219. consultationCode: message.consultationCode,
  220. roomNo: message.roomNo,
  221. operator: message.operator,
  222. );
  223. consulation.consultationMemberConvert(message.memberLiveDatas ?? []);
  224. onInviteeInLiveConsultation.emit(
  225. this,
  226. consulation,
  227. );
  228. }
  229. void _onCancelInvitingHandler(
  230. CancelInvitingInLiveConsultationNotification message) {
  231. var consulation = LiveConsultation(
  232. consultationCode: message.consultationCode,
  233. userCode: message.userCodes!.first,
  234. );
  235. onCancelInvitingConsultation.emit(
  236. this,
  237. consulation,
  238. );
  239. }
  240. void _onEmergencyCallNotificationHandler(EmergencyCallNotification message) {
  241. var liveConsultation = LiveConsultation(
  242. consultationCode: message.consultationCode,
  243. roomNo: message.roomNo,
  244. );
  245. var initiator = message.initiator;
  246. if (initiator != null) {
  247. liveConsultation.memberLiveDatas.value = [
  248. ConsultationMember.fromDto(initiator)
  249. .fixMergedVideoOutputSize()
  250. .fixOnlyCamera()
  251. ];
  252. }
  253. onInviteLiveConsultation.emit(this, liveConsultation);
  254. }
  255. void _onAnswerTimeoutHandler(ConsultationAnswerTimeoutNotification message) {
  256. var consulation = LiveConsultation(
  257. consultationCode: message.consultationCode,
  258. userCode: message.userCode,
  259. );
  260. onCancelInvitingConsultation.emit(
  261. this,
  262. consulation,
  263. );
  264. }
  265. void _onCancelInvitingInLiveCourseNotificationHandler(
  266. CancelInvitingInLiveCourseNotification message) {
  267. var notification = message;
  268. onCancelInvitingInLiveCourseNotification.emit(
  269. this,
  270. notification,
  271. );
  272. }
  273. void _onleaveConsultationHandler(LeaveLiveConsultationNotification message) {
  274. var consulation = LiveConsultation(
  275. consultationCode: message.consultationCode,
  276. );
  277. var leaverInfo = message.leaverInfo;
  278. if (leaverInfo != null) {
  279. consulation.memberLiveDatas.value = [
  280. ConsultationMember(
  281. id: leaverInfo.id,
  282. name: leaverInfo.name,
  283. headImageToken: leaverInfo.headImageUrl,
  284. )
  285. ];
  286. }
  287. onLeaveConsultation.emit(
  288. this,
  289. consulation,
  290. );
  291. }
  292. void _onChangeConsultationHandler(ChangeConsultationNotification message) {
  293. var consulation = LiveConsultation(
  294. consultationCode: message.consultationCode,
  295. roomNo: message.roomNo,
  296. );
  297. currentConsultationCode = message.consultationCode!;
  298. consulation.consultationMemberConvert(message.memberLiveDatas ?? []);
  299. onChangeConsultation.emit(this, consulation);
  300. }
  301. void _onCloseConsultationDueToChangeHandler(
  302. CloseConsultationDueToChangeNotification message) {
  303. onCloseConsultationDueToChange.emit(
  304. this, LiveConsultation(consultationCode: message.consultationCode));
  305. }
  306. void _onSendInteractiveBoardDataHandler(
  307. SendInteractiveBoardDataNotification message) {
  308. message.boardData;
  309. if (message.boardData != null) {
  310. if (message.isClear) {
  311. onWhiteboardDataReceive.emit(
  312. this, jsonEncode({'isClear': 'true', 'u_Id': message.userCode}));
  313. } else {
  314. onWhiteboardDataReceive.emit(this, message.boardData!);
  315. }
  316. }
  317. }
  318. void _onHeartRateJoinConsultationHandler(
  319. HeartRateJoinConsultationNotification message) {
  320. var accepter = message.joiner;
  321. var consultation = LiveConsultation(
  322. consultationCode: message.consultationCode,
  323. );
  324. if (accepter != null) {
  325. consultation.memberLiveDatas.value = [
  326. ConsultationMember(
  327. isOnline: accepter.isOnline,
  328. mute: accepter.mute,
  329. liveData: accepter.liveData,
  330. id: accepter.id,
  331. name: accepter.name,
  332. headImageToken: accepter.headImageUrl,
  333. mergedChannel:
  334. accepter.consultationDeviceInfo?.mergedChannel ?? false,
  335. consultationDeviceInfo: accepter.consultationDeviceInfo,
  336. videoDeviceInfos:
  337. accepter.consultationDeviceInfo?.videoDeviceOutputList,
  338. isOldPlatform: accepter.isOldPlatform,
  339. supportRtc: accepter.supportRtc,
  340. mergedVideoOutputWidth:
  341. accepter.consultationDeviceInfo?.mergedVideoOutputWidth ?? 0,
  342. mergedVideoOutputHeight:
  343. accepter.consultationDeviceInfo?.mergedVideoOutputHeight ?? 0,
  344. ).fixMergedVideoOutputSize().fixOnlyCamera()
  345. ];
  346. }
  347. onJoinConsultation.emit(
  348. this,
  349. consultation,
  350. );
  351. }
  352. //会诊成员心跳断开离开
  353. void _onHeartRateLeaveConsultationHandler(
  354. HeartRateLeaveConsultationNotification message) {
  355. var consulation = LiveConsultation(
  356. consultationCode: message.consultationCode,
  357. );
  358. var leaverInfo = message.leaverInfo;
  359. if (leaverInfo != null) {
  360. consulation.memberLiveDatas.value = [
  361. ConsultationMember(
  362. id: leaverInfo.id,
  363. name: leaverInfo.name,
  364. headImageToken: leaverInfo.headImageUrl,
  365. )
  366. ];
  367. Get.find<IRtmpMockRtcManager>().handleRemoteLeave(leaverInfo);
  368. }
  369. onLeaveConsultation.emit(
  370. this,
  371. consulation,
  372. );
  373. }
  374. void _onJoinLiveConsultHandler(JoinLiveConsultationNotification message) {
  375. var consultation = LiveConsultation(
  376. consultationCode: message.consultationCode,
  377. );
  378. var joiner = message.joiner;
  379. if (joiner != null) {
  380. consultation.memberLiveDatas.value = [
  381. ConsultationMember(
  382. id: joiner.id,
  383. name: joiner.name,
  384. isOnline: joiner.isOnline,
  385. mute: joiner.mute,
  386. isInitiator: joiner.id == Storage.user.userCode,
  387. liveData: joiner.liveData,
  388. headImageToken: joiner.headImageUrl,
  389. index: joiner.sortNumber,
  390. )
  391. ];
  392. }
  393. onJoinConsultation.emit(
  394. this,
  395. consultation,
  396. );
  397. }
  398. void _onJoinInLiveConsultationHandler(
  399. JoinInLiveConsultationNotification message) {
  400. var consultation = LiveConsultation(
  401. consultationCode: message.consultationCode,
  402. );
  403. var joiner = message.joiner;
  404. if (joiner != null) {
  405. consultation.memberLiveDatas.value = [
  406. ConsultationMember(
  407. id: joiner.id,
  408. name: joiner.name,
  409. isOnline: joiner.isOnline,
  410. mute: joiner.mute,
  411. isInitiator: joiner.isInitiator,
  412. liveData: joiner.liveData,
  413. headImageToken: joiner.headImageUrl,
  414. sortLevel: joiner.sortLevel,
  415. )
  416. ];
  417. }
  418. onJoinInConsultation.emit(
  419. this,
  420. consultation,
  421. );
  422. }
  423. void _onMuteLiveConsultationHandler(
  424. MuteLiveConsultationNotification message) {
  425. var member = message.muterInfo;
  426. var memberId = '';
  427. if (member != null) {
  428. memberId = member.id ?? '';
  429. }
  430. Get.find<IRtmpMockRtcManager>().handleRemoteMuteAudio(
  431. memberId,
  432. message.mute,
  433. );
  434. onMemberMute.emit(
  435. this,
  436. ConsultationMember(mute: message.mute, id: memberId),
  437. );
  438. }
  439. void _onCloseLiveConsultHandler(
  440. CloseLiveConsultationNotification message) async {
  441. var consultation = LiveConsultation(
  442. consultationCode: message.consultationCode,
  443. initiatorCode: message.initiatorCode,
  444. );
  445. onCloseConsultation.emit(
  446. this,
  447. consultation,
  448. );
  449. }
  450. void _onRejectInviteLiveConsultationHandler(
  451. RejectInviteLiveConsultationNotification message) {
  452. var accepter = message.rejecter;
  453. var consultation = LiveConsultation(
  454. consultationCode: message.consultationCode,
  455. );
  456. if (accepter != null) {
  457. consultation.memberLiveDatas.value = [
  458. ConsultationMember(
  459. id: accepter.id,
  460. name: accepter.name,
  461. headImageToken: accepter.headImageUrl,
  462. )
  463. ];
  464. }
  465. onRejectConsultation.emit(
  466. this,
  467. consultation,
  468. );
  469. }
  470. void _onAcceptLiveConsultationHandler(
  471. AcceptLiveConsultationNotification message) {
  472. var accepter = message.accepter;
  473. var consultation =
  474. LiveConsultation(consultationCode: message.consultationCode);
  475. if (accepter != null) {
  476. consultation.memberLiveDatas.value = [
  477. ConsultationMember(
  478. isOnline: accepter.isOnline,
  479. mute: accepter.mute,
  480. liveData: accepter.liveData,
  481. id: accepter.id,
  482. name: accepter.name,
  483. headImageToken: accepter.headImageUrl,
  484. )
  485. ];
  486. }
  487. onAcceptConsultation.emit(
  488. this,
  489. consultation,
  490. );
  491. }
  492. void _onRejectLiveConsultationHandler(
  493. RejectLiveConsultationNotification message) async {
  494. var accepter = message.rejecter;
  495. var consultation = LiveConsultation(
  496. consultationCode: message.consultationCode,
  497. );
  498. if (accepter != null) {
  499. consultation.memberLiveDatas.value = [
  500. ConsultationMember(
  501. id: accepter.id,
  502. name: accepter.name,
  503. headImageToken: accepter.headImageUrl,
  504. )
  505. ];
  506. }
  507. onRejectConsultation.emit(
  508. this,
  509. consultation,
  510. );
  511. }
  512. void _onInviteLiveConsultHandler(InviteLiveConsultationNotification message) {
  513. var liveConsultation = LiveConsultation(
  514. consultationCode: message.consultationCode,
  515. roomNo: message.roomNo,
  516. );
  517. var initiator = message.initiator;
  518. if (initiator != null) {
  519. liveConsultation.memberLiveDatas.value = [
  520. ConsultationMember.fromDto(initiator)
  521. .fixMergedVideoOutputSize()
  522. .fixOnlyCamera()
  523. ];
  524. }
  525. onInviteLiveConsultation.emit(this, liveConsultation);
  526. }
  527. void _onCancelLiveConsultation(CancelLiveConsultationNotification message) {
  528. var consultation = LiveConsultation(
  529. consultationCode: message.consultationCode,
  530. initiatorCode: message.initiatorCode,
  531. );
  532. onCancelConsultation.emit(
  533. this,
  534. consultation,
  535. );
  536. }
  537. void _onSwitchVideoPlayConsultationHandler(
  538. SwitchLiveConsultationVideoNotification message) {
  539. var member = message.switcherInfo;
  540. var memberId = '';
  541. if (member != null) {
  542. memberId = member.id ?? '';
  543. }
  544. Get.find<IRtmpMockRtcManager>().handleRemoteMuteVideo(
  545. memberId,
  546. !message.opened,
  547. );
  548. onSwitchVideoPlay.emit(
  549. this,
  550. ConsultationMember(videoOpend: message.opened, id: memberId),
  551. );
  552. }
  553. void _onNetworkErrConsultationHandler(
  554. NetworkErrConsultationNotification message) {
  555. var networkErrMemberInfo = message.networkErrMemberInfo;
  556. var consulation = LiveConsultation(
  557. consultationCode: message.consultationCode,
  558. );
  559. if (networkErrMemberInfo != null) {
  560. consulation.memberLiveDatas.value = [
  561. ConsultationMember(
  562. id: networkErrMemberInfo.id,
  563. name: networkErrMemberInfo.name,
  564. headImageToken: networkErrMemberInfo.headImageUrl,
  565. )
  566. ];
  567. }
  568. onNetworkErrConsultation.emit(
  569. this,
  570. consulation,
  571. );
  572. }
  573. ///开始会诊
  574. @override
  575. Future<LiveConsultation?> startConsultationAsync(
  576. ConsultationDetailDTO consultationDetailDTO,
  577. {bool isJoin = false,
  578. bool checkOnly = false,
  579. bool checkMedia = false}) async {
  580. var expertUserCode = consultationDetailDTO.expertUserCode;
  581. if (isJoin) {
  582. liveConsultation = await joinInLiveConsultationAsync(
  583. consultationDetailDTO.consultationCode!,
  584. checkOnly: checkOnly);
  585. } else if (consultationDetailDTO.isEmergency &&
  586. consultationDetailDTO.applyUserCode != Storage.user.userCode) {
  587. liveConsultation = await acceptLiveConsultationAsync(
  588. consultationDetailDTO.consultationCode!,
  589. checkOnly: checkOnly);
  590. } else if (expertUserCode == Storage.user.userCode ||
  591. (consultationDetailDTO.isEmergency &&
  592. consultationDetailDTO.applyUserCode == Storage.user.userCode)) {
  593. liveConsultation = await initiateLiveConsultationAsync(
  594. consultationDetailDTO.consultationCode!,
  595. checkOnly: checkOnly);
  596. } else {
  597. liveConsultation = await acceptLiveConsultationAsync(
  598. consultationDetailDTO.consultationCode!,
  599. checkOnly: checkOnly);
  600. }
  601. return liveConsultation;
  602. }
  603. @override
  604. Future<LiveConsultation> initiateLiveConsultationAsync(
  605. String consultationCode,
  606. {bool checkOnly = false}) async {
  607. final result =
  608. await jsonRpcProxy.liveConsultation.initiateLiveConsultationAsync(
  609. InitiateLiveConsultationRequest(
  610. token: token,
  611. consultationCode: consultationCode,
  612. checkOnly: checkOnly,
  613. ),
  614. );
  615. var liveConsultation = LiveConsultation(
  616. consultationCode: result.consultationCode,
  617. initiatorCode: result.initiatorCode,
  618. roomNo: result.roomNo,
  619. appId: result.appId,
  620. userSign: result.userSign,
  621. );
  622. liveConsultation.consultationMemberConvert(result.memberLiveDatas ?? []);
  623. //this.onStartLiveConsultation.emit(this, liveConsultation);
  624. return liveConsultation;
  625. }
  626. ///会诊心跳
  627. @override
  628. Future<LiveConsultationHeartRateResult> heartRateAsync(
  629. String consultationCode) async {
  630. return await jsonRpcProxy.liveConsultation.heartRateAsync(
  631. LiveConsultationHeartRateRequest(
  632. token: token,
  633. consultationCode: consultationCode,
  634. ),
  635. );
  636. }
  637. //根据会诊单号查询会诊中可直接切换的会诊单列表
  638. @override
  639. Future<List<ConsultationPageDTO>> findCanSwitchConsultationsAsync(
  640. String consultationCode) async {
  641. return await jsonRpcProxy.liveConsultation.findCanSwitchConsultationsAsync(
  642. FindCanSwitchConsultationsRequest(
  643. consultationCode: consultationCode,
  644. language: i18nBook.locale.toCodeString('-'),
  645. token: token,
  646. ),
  647. );
  648. }
  649. ///离开房间
  650. @override
  651. Future<LeaveLiveConsultationResult> leaveLiveConsultationAsync(
  652. String consultationCode) async {
  653. return jsonRpcProxy.liveConsultation.leaveLiveConsultationAsync(
  654. LeaveLiveConsultationRequest(
  655. consultationCode: consultationCode,
  656. token: token,
  657. ),
  658. );
  659. }
  660. ///接受会诊
  661. @override
  662. Future<LiveConsultation> acceptLiveConsultationAsync(String consultationCode,
  663. {bool checkOnly = false}) async {
  664. var result =
  665. await jsonRpcProxy.liveConsultation.acceptLiveConsultationAsync(
  666. AcceptLiveConsultationRequest(
  667. token: token,
  668. consultationCode: consultationCode,
  669. checkOnly: checkOnly,
  670. ),
  671. );
  672. var liveConsultation = LiveConsultation(
  673. consultationCode: result.consultationCode,
  674. userCode: result.userCode,
  675. roomNo: result.roomNo,
  676. appId: result.appId,
  677. userSign: result.userSign,
  678. interactiveBoardDatas: result.interactiveBoardDatas,
  679. );
  680. liveConsultation.consultationMemberConvert(result.memberLiveDatas ?? []);
  681. onAcceptLiveConsultation.emit(this, liveConsultation);
  682. return liveConsultation;
  683. }
  684. ///拒绝会诊
  685. @override
  686. Future<RejectLiveConsultationResult> rejectLiveConsultationAsync(
  687. String consultationCode) async {
  688. return jsonRpcProxy.liveConsultation
  689. .rejectLiveConsultationAsync(RejectLiveConsultationRequest(
  690. consultationCode: consultationCode,
  691. token: token,
  692. ));
  693. }
  694. @override
  695. Future<LiveConsultation> joinInLiveConsultationAsync(String consultationCode,
  696. {bool checkOnly = false}) async {
  697. final result =
  698. await jsonRpcProxy.liveConsultation.joinInLiveConsultationAsync(
  699. JoinLiveConsultationRequest(
  700. token: token,
  701. consultationCode: consultationCode,
  702. checkOnly: checkOnly,
  703. ),
  704. );
  705. var liveConsultation = LiveConsultation(
  706. consultationCode: result.consultationCode,
  707. userCode: result.userCode,
  708. roomNo: result.roomNo,
  709. appId: result.appId,
  710. userSign: result.userSign,
  711. interactiveBoardDatas: result.interactiveBoardDatas,
  712. );
  713. liveConsultation.consultationMemberConvert(result.memberLiveDatas ?? []);
  714. return liveConsultation;
  715. }
  716. ///会诊设备重试进入房间
  717. @override
  718. Future<void> retryLoadDeviceAsync(String consultationCode) async {
  719. await jsonRpcProxy.liveConsultation.deviceJoinInLiveConsultationAsync(
  720. JoinLiveConsultationRequest(
  721. consultationCode: consultationCode,
  722. token: token,
  723. ),
  724. );
  725. }
  726. /// 发送白板数据
  727. @override
  728. Future sendInteractiveBoardDataAsync(
  729. String consultationCode, String boardData,
  730. [bool isClear = false]) async {
  731. await jsonRpcProxy.liveConsultation.sendInteractiveBoardDataAsync(
  732. SendInteractiveBoardDataRequest(
  733. consultationCode: consultationCode,
  734. token: token,
  735. boardData: boardData,
  736. isClear: isClear,
  737. ),
  738. );
  739. }
  740. @override
  741. Future<QueryEmergencyDataResult> queryEmergencyDataAsync() async {
  742. return await jsonRpcProxy.liveConsultation.queryEmergencyDataAsync(
  743. TokenRequest(token: token),
  744. );
  745. }
  746. @override
  747. Future<GetEmergencySettingResult> getEmergencySettingAsync() async {
  748. return await jsonRpcProxy.liveConsultation.getEmergencySettingAsync(
  749. GetEmergencySettingRequest(token: token),
  750. );
  751. }
  752. @override
  753. Future<String> applyEmergencyTreatment(String selectedUser, String deviceCode,
  754. String? patientCode, List<DataItemDTO>? patientDatas) async {
  755. return await jsonRpcProxy.liveConsultation.applyEmergencyTreatment(
  756. ApplyEmergencyTreatmentRequest(
  757. token: token,
  758. expertCode: selectedUser,
  759. deviceCode: deviceCode,
  760. patientCode: patientCode,
  761. patientDatas: patientDatas),
  762. );
  763. }
  764. @override
  765. Future<bool> startEmergencyConsultationAsync(String consultationId) async {
  766. var appointmentManager = Get.find<IAppointmentManager>();
  767. var consultationInfo =
  768. await appointmentManager.findConsultationDetailAsync(consultationId);
  769. if (consultationInfo == null) {
  770. return false;
  771. }
  772. consultationDetail = consultationInfo;
  773. var result = await startConsultationAsync(consultationInfo,
  774. checkMedia: true, checkOnly: true);
  775. return result != null;
  776. }
  777. @override
  778. Future<bool> updateConsultationFilesInfoAsync(
  779. String consultationCode,
  780. String coverUrl,
  781. String previewUrl,
  782. String sourceUrl,
  783. bool isSingle) async {
  784. final UpdateConsultationFilesInfoRequest request =
  785. UpdateConsultationFilesInfoRequest(
  786. token: token,
  787. consultationCode: consultationCode,
  788. fileInfos: [
  789. ConsultationFileBaseDTO(
  790. coverImageUrl: coverUrl,
  791. previewImageUrl: previewUrl,
  792. sourceUrl: sourceUrl,
  793. fileDataType: isSingle
  794. ? RemedicalFileDataTypeEnum.ThirdVidSingle
  795. : RemedicalFileDataTypeEnum.ThirdVidMovie)
  796. ]);
  797. return await jsonRpcProxy.liveConsultation
  798. .updateConsultationFilesInfoAsync(request);
  799. }
  800. ///取消会诊过程邀请中的成员
  801. @override
  802. Future<CancelInvitingInLiveConsultationResult>
  803. cancelInvitingInLiveConsultationAsync(
  804. String consultationCode, List<String> inviteCodes) {
  805. return jsonRpcProxy.liveConsultation.cancelInvitingInLiveConsultationAsync(
  806. CancelInvitingInLiveConsultationRequest(
  807. consultationCode: consultationCode,
  808. inviteCodes: inviteCodes,
  809. token: token,
  810. ));
  811. }
  812. ///切换会诊病人
  813. @override
  814. Future<ChangeConsultationResult> changeConsultationAsync(
  815. String originalConsultationId, String currentConsultationId) async {
  816. var result = await jsonRpcProxy.liveConsultation.changeConsultationAsync(
  817. ChangeConsultationRequest(
  818. token: token,
  819. originalCode: originalConsultationId,
  820. currentCode: currentConsultationId,
  821. ),
  822. );
  823. return result;
  824. }
  825. ///会诊过程中邀请其他成员
  826. @override
  827. Future<InviteInLiveConsultationResult> inviteInLiveConsultationAsync(
  828. String consultationCode, List<String> inviteCodes, int roomNo) async {
  829. return await jsonRpcProxy.liveConsultation
  830. .inviteInLiveConsultationAsync(InviteInLiveConsultationRequest(
  831. token: token,
  832. consultationCode: consultationCode,
  833. inviteCodes: inviteCodes,
  834. roomNo: roomNo,
  835. ));
  836. }
  837. }