chenjunkai 5 anos atrás
pai
commit
93170bbc25
1 arquivos alterados com 31 adições e 9 exclusões
  1. 31 9
      controller/index.py

+ 31 - 9
controller/index.py

@@ -171,6 +171,7 @@ class oa2RtspStartView(TemplateView):
         VVDHCVBYDKFMJRWA111A
         '''
         access_token = request_dict.get("access_token", '')
+        st = request_dict.get("st", 0)
         id = request_dict.get("id", '')
         redisObj = RedisObject(db=9)
         key = '{UID}_rtsp_key'.format(UID=id)
@@ -193,7 +194,13 @@ class oa2RtspStartView(TemplateView):
             print(UID)
             print(PWD)
             print(MSG)
-            self.runSendRtspMsg(UID, PWD, MSG)
+            if st:
+                send_flag = self.runSendStop(UID, PWD, MSG)
+                if send_flag:
+                    return JsonResponse({'msg': 'stop yes', 'code': 0})
+                else:
+                    return JsonResponse({'msg': 'stop no', 'code': 0})
+            send_flag = self.runSendRtspMsg(UID, PWD, MSG)
             res_json = {
                 'endpointId': id,
                 'manufacturerName': 'Axis',
@@ -209,7 +216,8 @@ class oa2RtspStartView(TemplateView):
                 'authorizationTypes': ['NONE'],
                 'uri': 'rtsp://rtsp.zositech.xyz:443/{stream_name}'.format(stream_name=ur_qs[0]['rtsp_url'])
             }
-            redisObj.set_data(key=key,val=str(res_json),expire=30)
+            if send_flag:
+                redisObj.set_data(key=key, val=str(res_json), expire=30)
             return JsonResponse(res_json, safe=False)
         else:
             return JsonResponse({'msg': 'wrong'})
@@ -217,14 +225,28 @@ class oa2RtspStartView(TemplateView):
     def runSendRtspMsg(self, UID, PWD, MSG):
         command = "./pushtool {UID} {PWD} {MSG} 1".format(UID=UID, PWD=PWD, MSG=MSG)
         print('command=>{command}'.format(command=command))
-        back = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate(
-            timeout=10)
-        print("back0----", back[0].decode())  # 注意需要进行解码操作,默认输出的是字节
-        print("back1----", back[1].decode())  # back是一个元祖,可以通过元祖取值的方式获取结果
-        return
-
-
+        try:
+            back = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate(
+                timeout=10)
+        except Exception as e:
+            return False
+        else:
+            print("back0----", back[0].decode())  # 注意需要进行解码操作,默认输出的是字节
+            print("back1----", back[1].decode())  # back是一个元祖,可以通过元祖取值的方式获取结果
+            return True
 
+    def runSendStop(self, UID, PWD, MSG):
+        command = "./pushtool {UID} {PWD} {MSG} 0".format(UID=UID, PWD=PWD, MSG=MSG)
+        print('command=>{command}'.format(command=command))
+        try:
+            back = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate(
+                timeout=10)
+        except Exception as e:
+            return False
+        else:
+            print("back0----", back[0].decode())  # 注意需要进行解码操作,默认输出的是字节
+            print("back1----", back[1].decode())  # back是一个元祖,可以通过元祖取值的方式获取结果
+            return True
 
 
 class oa2DiscoveryDevice(TemplateView):