App.xaml.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Runtime.InteropServices;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using Vinno.FIS.TRTCClient.Captures;
  11. using Vinno.FIS.TRTCClient.Common.Enum;
  12. using Vinno.FIS.TRTCClient.Common.Log;
  13. using Vinno.FIS.TRTCClient.Common.Pipe;
  14. namespace Vinno.FIS.TRTCClient
  15. {
  16. /// <summary>
  17. /// Interaction logic for App.xaml
  18. /// </summary>
  19. public partial class App : Application
  20. {
  21. private DefaultLogEngine _logEngine;
  22. private TRTCChatRoom _trtcChatRoom;
  23. private PipeServer _messageServer;
  24. private PipeClient _messageClient;
  25. private CancellationTokenSource _tokenSource;
  26. private int _processId;
  27. private PipeClient _localVideoPipeClient;
  28. private int _terminalWidth;
  29. private int _terminalHeight;
  30. private int _localImageWidth;
  31. private int _localImageHeight;
  32. private byte[] _localBuffer = new byte[0];
  33. private ConcurrentDictionary<string, PipeRemoteImageSizeData> _remoteImageList;
  34. private ConcurrentDictionary<string, PipeClient> _remoteVideoPipeClientList;
  35. private bool _isLiveMode;
  36. private bool _isSonopost;
  37. private bool _isUsMachineImage;
  38. private EnumLiveChannelCategory _category;
  39. private TRTCPusher _trtcPusher;
  40. private PipeServer _localVideoPipeServer;
  41. private bool _hasReceivedFirstImage;
  42. private bool _isPreviewing;
  43. private bool _disposed;
  44. protected override void OnStartup(StartupEventArgs e)
  45. {
  46. try
  47. {
  48. _tokenSource = new CancellationTokenSource();
  49. _remoteVideoPipeClientList = new ConcurrentDictionary<string, PipeClient>();
  50. _remoteImageList = new ConcurrentDictionary<string, PipeRemoteImageSizeData>();
  51. if (e.Args.Length > 2)
  52. {
  53. var parentPid = GetArgValue(e.Args[0], "pid");
  54. var lpt = GetArgValue(e.Args[1], "lpt");
  55. var roomInofLen = e.Args.Length - 2;
  56. var roomInfoBytes = new string[roomInofLen];
  57. Array.Copy(e.Args, 2, roomInfoBytes, 0, roomInofLen);
  58. var roomInfo = TRTCRoomInfo.ConvertFromArgs(roomInfoBytes);
  59. _isLiveMode = roomInfo.IsForLive;
  60. _isSonopost = roomInfo.IsSonopost;
  61. _isUsMachineImage = roomInfo.IsUSMachineImage;
  62. _category = roomInfo.Category;
  63. string logPath;
  64. if (!string.IsNullOrEmpty(lpt))
  65. {
  66. logPath = Path.Combine(lpt, "TRTCClientLogs");
  67. }
  68. else
  69. {
  70. logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TRTCClientLogs");
  71. }
  72. if (!Directory.Exists(logPath))
  73. {
  74. Directory.CreateDirectory(logPath);
  75. }
  76. _logEngine = new DefaultLogEngine(logPath, _category);
  77. Logger.RegisterEngine(_logEngine);
  78. Logger.WriteLineInfo("TRTCClient Start Up......");
  79. Logger.WriteLineInfo($"Parent Process Id:{parentPid},RoomInfo:{roomInfo}");
  80. _processId = Process.GetCurrentProcess().Id;
  81. Logger.WriteLineInfo($"Current Process Id:{_processId}");
  82. StartMessagePipe();
  83. StartLocalVideoPipe();
  84. StartCheckParentThread(parentPid);
  85. if (_isLiveMode)
  86. {
  87. _trtcPusher = new TRTCPusher(logPath, _category);
  88. _trtcPusher.VideoFrameReceived += OnLocalVideoFrameReceived;
  89. _trtcPusher.TRTCImageFrameDataReceived += OnOnLocalVideoFrameReceived_2;
  90. _trtcPusher.EnterRoom(roomInfo);
  91. Logger.WriteLineInfo($"MessageClient Send BootUp");
  92. var bootUp = new PipeMessageData(PipeMessage.BootUp, new byte[0]);
  93. _messageClient?.SendBytes(bootUp.ToBytes());
  94. }
  95. else
  96. {
  97. _trtcChatRoom = new TRTCChatRoom(logPath);
  98. _trtcChatRoom.LocalVideoFrameArrived += OnLocalVideoFrameReceived;
  99. _trtcChatRoom.RemoteVideoFrameArrived += OnRemoteVideoFrameReceived;
  100. _trtcChatRoom.OnTRTCEnterRoomError += OnEnterRoomError;
  101. _trtcChatRoom.RemoteUserLeaveRoomArrived += OnRemoteUserLeaveRoomArrived;
  102. _trtcChatRoom.TryToReconnect += OnTryToReconnect;
  103. _trtcChatRoom.Enter(roomInfo);
  104. if (roomInfo.TerminalIsPushing && roomInfo.TerminalRoomId > 0)
  105. {
  106. _trtcChatRoom.ConnectTerminalRoom(roomInfo.TerminalRoomId, roomInfo.TerminalId);
  107. if (roomInfo.IsMultiChannel && !string.IsNullOrEmpty(roomInfo.CameraId))
  108. {
  109. _trtcChatRoom.ConnectTerminalCameraRoom(roomInfo.TerminalRoomId, roomInfo.CameraId);
  110. }
  111. }
  112. }
  113. }
  114. else
  115. {
  116. Process.GetCurrentProcess().Kill();
  117. }
  118. }
  119. catch (Exception ex)
  120. {
  121. Logger.WriteLineError($"Start TrtcClient error:{ex}");
  122. Process.GetCurrentProcess().Kill();
  123. }
  124. }
  125. protected override void OnExit(ExitEventArgs e)
  126. {
  127. try
  128. {
  129. Dispose();
  130. }
  131. catch (Exception ex)
  132. {
  133. Logger.WriteLineError($"Exit TrtcClient error:{ex}");
  134. }
  135. finally
  136. {
  137. base.OnExit(e);
  138. }
  139. }
  140. public void Dispose()
  141. {
  142. if (!_disposed)
  143. {
  144. _tokenSource.Cancel();
  145. StopPusher();
  146. StopRTCRoom();
  147. StopMessagePipe();
  148. StopLocalVideoPipe();
  149. StopRemoteVideoPipeClient();
  150. _disposed = true;
  151. Process.GetCurrentProcess().Kill();
  152. }
  153. }
  154. #region Start
  155. private void StartLocalVideoPipe()
  156. {
  157. StartLocalVideoPipeClient();
  158. if (_isUsMachineImage)
  159. {
  160. StartLocalVideoPipeServer();
  161. }
  162. }
  163. private void StartLocalVideoPipeClient()
  164. {
  165. _localVideoPipeClient = new PipeClient($"{_processId}_LocalVideo");
  166. _localVideoPipeClient.LogMsgThrow += OnLogMsgThrow;
  167. Logger.WriteLineInfo($"Create Local Video Pipe Client :{_localVideoPipeClient.PipeName}");
  168. _localVideoPipeClient.Start();
  169. }
  170. private void StartLocalVideoPipeServer()
  171. {
  172. _localVideoPipeServer = new PipeServer($"{_processId}_TerminalImage");
  173. _localVideoPipeServer.DataReceived += OnTerminalVideoDataReceived;
  174. _localVideoPipeServer.LogMsgThrow += OnLogMsgThrow;
  175. Logger.WriteLineInfo($"Create Local Video Pipe Server :{_localVideoPipeServer.PipeName}");
  176. _localVideoPipeServer.StartAndReceive();
  177. }
  178. private void StartNewRemoteVideoPipeClient(string userId, int width, int height)
  179. {
  180. var remoteVideoPipeClient = new PipeClient($"{_processId}_{userId}_RemoteVideo");
  181. if (!_remoteVideoPipeClientList.TryAdd(userId, remoteVideoPipeClient))
  182. {
  183. Logger.WriteLineError($"Remote Video Pipe Client List Try Add Failed, Id: {userId}");
  184. return;
  185. }
  186. else
  187. {
  188. Logger.WriteLineInfo($"MessageClient Send AddRemoteVideoPipe Client :{remoteVideoPipeClient.PipeName},Width:{width},Height:{height}");
  189. var remoteImageData = new PipeRemoteImageSizeData(userId, width, height);
  190. var pipeMessageData = new PipeMessageData(PipeMessage.AddRemoteVideoPipe, remoteImageData.ToBytes());
  191. _messageClient?.SendBytes(pipeMessageData.ToBytes());
  192. remoteVideoPipeClient.LogMsgThrow += OnLogMsgThrow;
  193. remoteVideoPipeClient.Start();
  194. }
  195. }
  196. private void StartMessagePipe()
  197. {
  198. _messageServer = new PipeServer($"{_processId}_FIS2TRTCClientMessage");
  199. _messageServer.LogMsgThrow += OnLogMsgThrow;
  200. _messageServer.DataReceived += OnMessageDataReceived;
  201. _messageServer.StartAndReceive();
  202. _messageClient = new PipeClient($"{_processId}_TRTCClient2FISMessage");
  203. _messageClient.LogMsgThrow += OnLogMsgThrow;
  204. _messageClient.Start();
  205. }
  206. private void StartCheckParentThread(string parentProcessId)
  207. {
  208. if (string.IsNullOrEmpty(parentProcessId))
  209. {
  210. return;
  211. }
  212. if (int.TryParse(parentProcessId, out var pid))
  213. {
  214. Task.Run(() =>
  215. {
  216. Logger.WriteLineInfo($"Start Check Thread");
  217. while (true)
  218. {
  219. if (_tokenSource.IsCancellationRequested)
  220. {
  221. break;
  222. }
  223. try
  224. {
  225. if (pid == 0)
  226. {
  227. Process.GetCurrentProcess().Kill();
  228. return;
  229. }
  230. var existApp = Process.GetProcessById(pid);
  231. if (existApp == null)
  232. {
  233. Logger.WriteLineInfo("Parent process not exit,kill myself!");
  234. Process.GetCurrentProcess().Kill();
  235. return;
  236. }
  237. }
  238. catch (Exception ex)
  239. {
  240. Logger.WriteLineInfo($"Check Parent Error:{ex}");
  241. Process.GetCurrentProcess().Kill();
  242. }
  243. finally
  244. {
  245. Thread.Sleep(5000);
  246. }
  247. }
  248. }, _tokenSource.Token);
  249. }
  250. }
  251. #endregion Start
  252. #region Stop
  253. private void StopMessagePipe()
  254. {
  255. if (_messageServer != null)
  256. {
  257. _messageServer.DataReceived -= OnMessageDataReceived;
  258. _messageServer.Dispose();
  259. _messageServer.LogMsgThrow -= OnLogMsgThrow;
  260. _messageServer = null;
  261. }
  262. if (_messageClient != null)
  263. {
  264. _messageClient.Dispose();
  265. _messageClient.LogMsgThrow -= OnLogMsgThrow;
  266. _messageClient = null;
  267. }
  268. }
  269. private void StopLocalVideoPipe()
  270. {
  271. StopLocalVideoPipeClient();
  272. StopLocalVideoPipeServer();
  273. }
  274. private void StopLocalVideoPipeClient()
  275. {
  276. if (_localVideoPipeClient != null)
  277. {
  278. Logger.WriteLineInfo($"Close Pipe Client Local Video{_localVideoPipeClient.PipeName}");
  279. _localVideoPipeClient.Dispose();
  280. _localVideoPipeClient.LogMsgThrow -= OnLogMsgThrow;
  281. _localVideoPipeClient = null;
  282. }
  283. }
  284. private void StopLocalVideoPipeServer()
  285. {
  286. if (_localVideoPipeServer != null)
  287. {
  288. Logger.WriteLineInfo($"Close Pipe Server Local Video{_localVideoPipeServer.PipeName}");
  289. _localVideoPipeServer.DataReceived -= OnTerminalVideoDataReceived;
  290. _localVideoPipeServer.Dispose();
  291. _localVideoPipeServer.LogMsgThrow -= OnLogMsgThrow;
  292. _localVideoPipeServer = null;
  293. }
  294. }
  295. private void StopRemoteVideoPipeClient()
  296. {
  297. foreach (var userId in _remoteVideoPipeClientList.Keys)
  298. {
  299. Logger.WriteLineInfo($"Close Pipe Client Remote Video{_remoteVideoPipeClientList[userId].PipeName}");
  300. _remoteVideoPipeClientList[userId].Dispose();
  301. _remoteVideoPipeClientList[userId].LogMsgThrow -= OnLogMsgThrow;
  302. }
  303. _remoteVideoPipeClientList.Clear();
  304. _remoteImageList.Clear();
  305. }
  306. private void StopRTCRoom()
  307. {
  308. if (_trtcChatRoom != null)
  309. {
  310. _trtcChatRoom.LocalVideoFrameArrived -= OnLocalVideoFrameReceived;
  311. _trtcChatRoom.RemoteVideoFrameArrived -= OnRemoteVideoFrameReceived;
  312. _trtcChatRoom.OnTRTCEnterRoomError -= OnEnterRoomError;
  313. _trtcChatRoom.RemoteUserLeaveRoomArrived -= OnRemoteUserLeaveRoomArrived;
  314. _trtcChatRoom.TryToReconnect -= OnTryToReconnect;
  315. _trtcChatRoom.Exit();
  316. _trtcChatRoom = null;
  317. Logger.WriteLineInfo("Exit RTCRoom success");
  318. }
  319. }
  320. private void StopPusher()
  321. {
  322. if (_trtcPusher != null)
  323. {
  324. _trtcPusher.VideoFrameReceived -= OnLocalVideoFrameReceived;
  325. _trtcPusher.TRTCImageFrameDataReceived -= OnOnLocalVideoFrameReceived_2;
  326. _trtcPusher.Dispose();
  327. _trtcPusher = null;
  328. Logger.WriteLineInfo("Stop Pusher success");
  329. }
  330. }
  331. #endregion Stop
  332. private void OnEnterRoomError(object sender, EventArgs e)
  333. {
  334. Logger.WriteLineInfo($"MessageClient Send EnterRoomError");
  335. var pipeMessageData = new PipeMessageData(PipeMessage.EnterRoomError, new byte[0]);
  336. _messageClient?.SendBytes(pipeMessageData.ToBytes());
  337. }
  338. private void OnTryToReconnect(object sender, EventArgs e)
  339. {
  340. Logger.WriteLineInfo($"MessageClient Send TryToReconnect");
  341. var pipeMessageData = new PipeMessageData(PipeMessage.TryToReconnect, new byte[0]);
  342. _messageClient?.SendBytes(pipeMessageData.ToBytes());
  343. }
  344. private void OnRemoteUserLeaveRoomArrived(object sender, RemoteUserLeaveRoomArgs args)
  345. {
  346. Logger.WriteLineInfo($"MessageClient Send RemoteUserLeaveRoom,userId:{args.UserId},reason:{args.Reason}");
  347. var pipeRemoteUserLeaveRoomMessage = new PipeRemoteUserLeaveRoomMessage(args.UserId, args.Reason);
  348. var pipeMessageData = new PipeMessageData(PipeMessage.RemoteUserLeaveRoom, pipeRemoteUserLeaveRoomMessage.ToBytes());
  349. _messageClient?.SendBytes(pipeMessageData.ToBytes());
  350. }
  351. private void OnTerminalVideoDataReceived(object sender, byte[] e)
  352. {
  353. if (e.Length != _terminalHeight * _terminalWidth * 3 / 2)
  354. {
  355. Logger.WriteLineError($"OnTerminalVideoDataReceived Error,Byte Length:{e.Length},TerminalHeight:{_terminalHeight},TerminalWidth:{_terminalWidth},ImageSize Should be {_terminalWidth * _terminalHeight * 3 / 2}");
  356. return;
  357. }
  358. _trtcPusher?.SendData((uint)_terminalWidth, (uint)_terminalHeight, e);
  359. }
  360. private void OnLocalVideoFrameReceived(object sender, VideoFrameArrivedArgs e)
  361. {
  362. if (_localImageHeight != (int)e.Frame.height || _localImageWidth != (int)e.Frame.width)
  363. {
  364. _localImageWidth = (int)e.Frame.width;
  365. _localImageHeight = (int)e.Frame.height;
  366. Logger.WriteLineInfo($"MessageClient Send ImageSizeChanged,Width:{_localImageWidth},Height:{_localImageHeight}");
  367. var imageSizeMessage = new PipeMessageData(PipeMessage.ImageSizeChanged, new PipeImageSizeData(_localImageWidth, _localImageHeight).ToBytes());
  368. _messageClient?.SendBytes(imageSizeMessage.ToBytes());
  369. }
  370. if (!_hasReceivedFirstImage)
  371. {
  372. Logger.WriteLineInfo($"MessageClient Send FirstFrameReceived");
  373. var firstImageMessage = new PipeMessageData(PipeMessage.FirstFrameReceived, new byte[0]);
  374. _messageClient?.SendBytes(firstImageMessage.ToBytes());
  375. _hasReceivedFirstImage = true;
  376. }
  377. if (!_isLiveMode || _isPreviewing)
  378. {
  379. _localVideoPipeClient?.SendBytes(e.Frame.data);
  380. }
  381. }
  382. private void OnOnLocalVideoFrameReceived_2(object sender, TRTCImageFrameData e)
  383. {
  384. if (_localImageHeight != e.Height || _localImageWidth != e.Width)
  385. {
  386. _localImageWidth = e.Width;
  387. _localImageHeight = e.Height;
  388. Array.Resize(ref _localBuffer, _localImageHeight * _localImageWidth * 4);
  389. Logger.WriteLineInfo($"MessageClient Send ImageSizeChanged,Width:{_localImageWidth},Height:{_localImageHeight}");
  390. var imageSizeMessage = new PipeMessageData(PipeMessage.ImageSizeChanged, new PipeImageSizeData(_localImageWidth, _localImageHeight).ToBytes());
  391. _messageClient?.SendBytes(imageSizeMessage.ToBytes());
  392. }
  393. if (!_hasReceivedFirstImage)
  394. {
  395. Logger.WriteLineInfo($"MessageClient Send FirstFrameReceived");
  396. var firstImageMessage = new PipeMessageData(PipeMessage.FirstFrameReceived, new byte[0]);
  397. _messageClient?.SendBytes(firstImageMessage.ToBytes());
  398. _hasReceivedFirstImage = true;
  399. }
  400. if (!_isLiveMode || _isPreviewing)
  401. {
  402. Marshal.Copy(e.Data, _localBuffer, 0, _localBuffer.Length);
  403. _localVideoPipeClient?.SendBytes(_localBuffer);
  404. }
  405. }
  406. private string GetArgValue(string arg, string tag)
  407. {
  408. var args = arg.Split('=');
  409. if (args.Count() == 2 && args[0] == tag)
  410. {
  411. return args[1];
  412. }
  413. return string.Empty;
  414. }
  415. private void OnMessageDataReceived(object sender, byte[] e)
  416. {
  417. if (e == null)
  418. {
  419. return;
  420. }
  421. var pipeMessageData = PipeMessageData.FromBytes(e);
  422. Logger.WriteLineInfo($"Message Pipe Server Receive PipeMessage{pipeMessageData?.PipeMessage}");
  423. switch (pipeMessageData.PipeMessage)
  424. {
  425. case PipeMessage.Exit:
  426. Dispose();
  427. break;
  428. case PipeMessage.ConnectToOtherRoom:
  429. var connectOtherRoomInfo = PipeConnectOtherRoomMessage.FromBytes(pipeMessageData.MessageData);
  430. if (connectOtherRoomInfo != null && !connectOtherRoomInfo.UserId.Contains("Auxiliary1"))
  431. {
  432. _trtcChatRoom.ConnectTerminalRoom((uint)connectOtherRoomInfo.RoomId, connectOtherRoomInfo.UserId);
  433. }
  434. else
  435. {
  436. _trtcChatRoom.ConnectTerminalCameraRoom((uint)connectOtherRoomInfo.RoomId, connectOtherRoomInfo.UserId);
  437. }
  438. break;
  439. case PipeMessage.Mute:
  440. var muteMessage = PipeBoolMessage.FromBytes(pipeMessageData.MessageData);
  441. if (muteMessage != null)
  442. {
  443. if (_trtcChatRoom != null)
  444. {
  445. _trtcChatRoom.Mute(muteMessage.Value);
  446. }
  447. if (_trtcPusher != null)
  448. {
  449. _trtcPusher.SetMute(muteMessage.Value);
  450. }
  451. }
  452. break;
  453. case PipeMessage.SwitchMic:
  454. var micMessage = PipeUserIdMessage.FromBytes(pipeMessageData.MessageData);
  455. if (micMessage != null)
  456. {
  457. if (_trtcChatRoom != null)
  458. {
  459. _trtcChatRoom.SwitchMic(micMessage.UserId);
  460. }
  461. if (_trtcPusher != null)
  462. {
  463. _trtcPusher.SwitchMic(micMessage.UserId);
  464. }
  465. }
  466. break;
  467. case PipeMessage.ImageSizeChanged:
  468. var imageSizeMessage = PipeImageSizeData.FromBytes(pipeMessageData.MessageData);
  469. if (_terminalHeight != imageSizeMessage.Height || _terminalWidth != imageSizeMessage.Width)
  470. {
  471. _terminalWidth = imageSizeMessage.Width;
  472. _terminalHeight = imageSizeMessage.Height;
  473. }
  474. break;
  475. case PipeMessage.StartPreview:
  476. _isPreviewing = true;
  477. break;
  478. case PipeMessage.StopPreview:
  479. _isPreviewing = false;
  480. break;
  481. }
  482. }
  483. private void OnRemoteVideoFrameReceived(object sender, VideoFrameArrivedArgs e)
  484. {
  485. if (string.IsNullOrEmpty(e.UserId))
  486. {
  487. return;
  488. }
  489. if (!_remoteVideoPipeClientList.ContainsKey(e.UserId))
  490. {
  491. StartNewRemoteVideoPipeClient(e.UserId, (int)e.Frame.width, (int)e.Frame.height);
  492. }
  493. if (!_remoteImageList.ContainsKey(e.UserId))
  494. {
  495. if (_remoteImageList.TryAdd(e.UserId, new PipeRemoteImageSizeData(e.UserId, (int)e.Frame.width, (int)e.Frame.height)))
  496. {
  497. SendRemoteImageSizeChanged(e.UserId, (int)e.Frame.width, (int)e.Frame.height);
  498. }
  499. }
  500. if (_remoteImageList[e.UserId].Width != (int)e.Frame.width || _remoteImageList[e.UserId].Height != (int)e.Frame.height)
  501. {
  502. _remoteImageList[e.UserId].Width = (int)e.Frame.width;
  503. _remoteImageList[e.UserId].Height = (int)e.Frame.height;
  504. SendRemoteImageSizeChanged(e.UserId, (int)e.Frame.width, (int)e.Frame.height);
  505. }
  506. _remoteVideoPipeClientList[e.UserId].SendBytes(e.Frame.data);
  507. }
  508. private void SendRemoteImageSizeChanged(string userId, int width, int height)
  509. {
  510. Logger.WriteLineInfo($"MessageClient Send RemoteImageSizeChanged UserId:{userId},Width:{width},Height:{height}");
  511. var remoteImageData = new PipeRemoteImageSizeData(userId, width, height);
  512. var pipeMessageData = new PipeMessageData(PipeMessage.RemoteImageSizeChanged, remoteImageData.ToBytes());
  513. _messageClient?.SendBytes(pipeMessageData.ToBytes());
  514. }
  515. private void OnLogMsgThrow(object sender, LogEventArgs e)
  516. {
  517. if (e == null)
  518. {
  519. return;
  520. }
  521. switch (e.LogType)
  522. {
  523. case DeviceLogCategory.Error:
  524. Logger.WriteLineError(e.Msg);
  525. break;
  526. case DeviceLogCategory.Warn:
  527. Logger.WriteLineWarn(e.Msg);
  528. break;
  529. case DeviceLogCategory.Verb:
  530. Logger.WriteLineVerbose(e.Msg);
  531. break;
  532. case DeviceLogCategory.Info:
  533. default:
  534. Logger.WriteLineInfo(e.Msg);
  535. break;
  536. }
  537. }
  538. }
  539. }