Browse Source

Merge branch 'master' of http://git.ius.plus:88/Project-Wing/WingDeviceService

Conflicts:
	Service/DeviceService.cs
Jeremy 2 years ago
parent
commit
13722f4349
1 changed files with 80 additions and 2 deletions
  1. 80 2
      Service/DeviceService.cs

+ 80 - 2
Service/DeviceService.cs

@@ -64,6 +64,7 @@ namespace WingDeviceService.Service
         private int _liveConsultationRateSeconds = 0;
         private bool _isRTCSelf = false;
         private int _sdkAppId = 0;
+        private int _remoteControlAskTimeoutSec = 0;
         private int _reportStateIntervalSeconds = 0;
         private int _reportStateTimeout = 0;
 
@@ -93,6 +94,7 @@ namespace WingDeviceService.Service
             {
                 _sdkAppId = sdkAppId;
             }
+            _remoteControlAskTimeoutSec = ConfigurationManager.GetParammeter<IntParameter>("Device", "RemoteControlAskTimeoutSec").Value;
             var _reportStateIntervalSeconds = ConfigurationManager.GetParammeter<IntParameter>("Live", "ReportStateIntervalSeconds").Value;
             var _reportStateTimeout = ConfigurationManager.GetParammeter<IntParameter>("Live", "ReportStateTimeout").Value;
         }
@@ -718,7 +720,8 @@ namespace WingDeviceService.Service
                 MergedChannel = deviceInfo.MergedChannel,
                 MergedVideoOutputWidth = deviceInfo.MergedVideoOutputWidth,
                 MergedVideoOutputHeight = deviceInfo.MergedVideoOutputHeight,
-                IsSelfRtcService = _isRTCSelf
+                IsSelfRtcService = _isRTCSelf,
+                RemoteControlAskTimeoutSec = _remoteControlAskTimeoutSec
             };
             return result;
         }
@@ -1312,7 +1315,6 @@ namespace WingDeviceService.Service
                 RoomNo = intRoomNo,
             };
         }
-
         private async Task<bool> BroadcastNotificationAsync(string roomId, IList<string> clientIds, NotificationDTO message)
         {
             var broadcastNotificationRequest = new BroadcastRoomNotificationRequest
@@ -1327,6 +1329,82 @@ namespace WingDeviceService.Service
             };
             return await _rtcService.BroadcastRoomNotificationAsync(broadcastNotificationRequest);
         }
+
+        /// <summary>
+        /// 拒绝远程控制
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<bool> RejectRemoteControl(RemoteControlRequest request)
+        {
+            string deviceCode = await GetClientIdByTokenAsync(request.Token);
+            string userCode = request.ControlUserCode;
+            //发送控制人通知
+            if (string.IsNullOrWhiteSpace(userCode))
+            {
+                ThrowCustomerException(CustomerRpcCode.UsercodeIsEmpty, "User code is empty");
+            }
+            var userDTO = await _userServiceProxy.FindUserByCodeAsync(userCode);
+            if (userDTO == null)
+            {
+                ThrowCustomerException(CustomerRpcCode.UserNotExistError, "User does not exist");
+            }
+            var notify = new DeviceRejectRemoteControlNotification()
+            {
+                DeviceCode = deviceCode,
+            };
+            var notificationRequest = new SendNotificationRequest()
+            {
+                ClientId = userCode,
+                Message = notify,
+                JsonMessage = Newtonsoft.Json.JsonConvert.SerializeObject(notify),
+                NotificationType = notify.NotificationType,
+                TransactionType = TransactionTypeEnum.RemoteControl,
+                RelevanceCode = userCode,
+                ReceiverType = ApplicantTypeEnum.Client
+            };
+            await _notificationService.PostMessageAsync(notificationRequest);
+            //todo 更改房间调参状态 1 根据设备code获取房间 2 修改房间内某个人的调参状态
+            return true;
+        }
+
+        /// <summary>
+        /// 断开远程控制
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<bool> DisconnectRemoteControl(RemoteControlRequest request)
+        {
+            string deviceCode = await GetClientIdByTokenAsync(request.Token);
+            string userCode = request.ControlUserCode;
+            //发送控制人通知
+            if (string.IsNullOrWhiteSpace(userCode))
+            {
+                ThrowCustomerException(CustomerRpcCode.UsercodeIsEmpty, "User code is empty");
+            }
+            var userDTO = await _userServiceProxy.FindUserByCodeAsync(userCode);
+            if (userDTO == null)
+            {
+                ThrowCustomerException(CustomerRpcCode.UserNotExistError, "User does not exist");
+            }
+            var notify = new DeviceDisconnectRemoteControlNotification()
+            {
+                DeviceCode = deviceCode,
+            };
+            var notificationRequest = new SendNotificationRequest()
+            {
+                ClientId = userCode,
+                Message = notify,
+                JsonMessage = Newtonsoft.Json.JsonConvert.SerializeObject(notify),
+                NotificationType = notify.NotificationType,
+                TransactionType = TransactionTypeEnum.RemoteControl,
+                RelevanceCode = userCode,
+                ReceiverType = ApplicantTypeEnum.Client
+            };
+            await _notificationService.PostMessageAsync(notificationRequest);
+            //todo 更改房间调参状态 1 根据设备code获取房间 2 修改房间内某个人的调参状态
+            return true;
+        }
     }
 
 }