xushiting преди 3 години
родител
ревизия
1fef8014c7
променени са 3 файла, в които са добавени 343 реда и са изтрити 336 реда
  1. 215 191
      src/move/move.service.ts
  2. 21 54
      src/rotate/rotate.service.ts
  3. 107 91
      src/scene/scene.service.ts

+ 215 - 191
src/move/move.service.ts

@@ -5,13 +5,15 @@ import { join } from 'path';
 import { CacheService } from 'src/cache/cache.service';
 import { RotateService } from 'src/rotate/rotate.service';
 import configuration from 'src/config/configuration';
+// import ShareData from 'src/ShareData';
 
 // import * as  BreakPointIds from '../../ws/points-BreakPointId.json';
 // import { SceneService } from 'src/scene/scene.service';
 
-const MaxDelayTime = 80;   //超过这个值就需要干预(操作杆)
-const MaxBufferCameraInfo = 3;   //超过这个值就需要干预(操作杆)
-const MaxNet = 3;
+const MaxDelayTime = 80; //超过这个值就需要干预(操作杆)
+const MaxBufferCameraInfo = 3; //超过这个值就需要干预(操作杆)
+const MaxNet = 30000000;
+const MaxWalkCount = 2;
 
 const seqExeAsyncFn = (asyncFn) => {
   let runPromise = null;
@@ -95,7 +97,7 @@ export class MoveService implements OnModuleInit {
           renderType: 0,
           videoFrame: null,
           cameraStateType: 3,
-          isMoving: 1,
+          isMoving: 0,
           needIfr: 0,
           isVideo: 0,
           stillFrame: 0,
@@ -197,7 +199,10 @@ export class MoveService implements OnModuleInit {
         frameIndex: 0,
         horizontal_move: 0,
       },
-      moveInfo: {},
+      netQua:0,
+      walkState:0,
+      isMoving:0,
+      IDRCount:0,
       // traceIds: [],
       // actionResponses:[]
     };
@@ -271,7 +276,8 @@ export class MoveService implements OnModuleInit {
       );
       for (let i = 0; i < checkReplys.length; ++i) {
         checkReplys[i].actionResponses[0].actionType = actionType;
-        if (i == 0 || i == checkReplys.length - 1) {
+        //if (i == 0 || i == checkReplys.length - 1) {
+        if (i == 0) {
           checkReplys[i].isIDR = true;
         } else {
           checkReplys[i].isIDR = false;
@@ -359,7 +365,7 @@ export class MoveService implements OnModuleInit {
     );
     const user = this.users[userId];
     let i;
-    for (i = 1; i < moveFrames.length; i+=3) {
+    for (i = 1; i < moveFrames.length; i += 3) {
       const moveFrame = moveFrames[i];
       const reply = JSON.parse(JSON.stringify(this.reply));
       if (reply.traceIds.indexOf(traceId) == -1) {
@@ -408,7 +414,13 @@ export class MoveService implements OnModuleInit {
 
       reply['newUserStates'][0].playerState.camera.angle =
         moveFrame.camera_angle;
-      reply['newUserStates'][0].renderInfo.isMoving = 1;
+      if(user.walkState>MaxWalkCount){
+        reply['newUserStates'][0].renderInfo.isMoving = 2;
+      }
+      else{
+        reply['newUserStates'][0].renderInfo.isMoving = 1;
+      }
+      
       reply['actionResponses'][0].traceId = traceId;
 
       reply.mediaSrc =
@@ -423,6 +435,7 @@ export class MoveService implements OnModuleInit {
         '?m=' +
         new Date().getTime();
       if (startBreakPointId > endBreakPointId) {
+        //console.log('change move437:'+startBreakPointId+','+endBreakPointId)
         reply.mediaSrc =
           '/' +
           appId +
@@ -435,14 +448,10 @@ export class MoveService implements OnModuleInit {
           '?m=' +
           new Date().getTime();
       }
+      console.log('mediaSrc_1:'+reply.mediaSrc)
 
       reply.startBreakPointId = startBreakPointId;
       reply.endBreakPointId = endBreakPointId;
-      // if (i == moveFrames.length - 1) {
-      //   reply.isIDR = true;
-      // } else {
-      //   reply.isIDR = false;
-      // }
       reply.isIDR = false;
       replys.push(reply);
     }
@@ -452,7 +461,12 @@ export class MoveService implements OnModuleInit {
       const reply = JSON.parse(JSON.stringify(this.reply));
       reply.traceIds.push(traceId);
       reply['newUserStates'][0].userId = userId;
-      reply['newUserStates'][0].renderInfo.isMoving = 1;
+      if(user.walkState>MaxWalkCount){
+        reply['newUserStates'][0].renderInfo.isMoving = 2;
+      }
+      else{
+        reply['newUserStates'][0].renderInfo.isMoving = 1;
+      }
       if (!isFromUser) {
         reply['newUserStates'][0].playerState.player.position = {
           x:
@@ -506,6 +520,7 @@ export class MoveService implements OnModuleInit {
         new Date().getTime();
 
       if (startBreakPointId > endBreakPointId) {
+        console.log('change move526:'+startBreakPointId+','+endBreakPointId)
         reply.mediaSrc =
           '/' +
           appId +
@@ -518,11 +533,12 @@ export class MoveService implements OnModuleInit {
           '?m=' +
           new Date().getTime();
       }
+      console.log('mediaSrc_2:'+reply.mediaSrc)
       reply.startBreakPointId = startBreakPointId;
       reply.endBreakPointId = endBreakPointId;
       replys.push(reply);
     }
-    replys[replys.length - 1].isIDR = true;
+    //replys[replys.length - 1].isIDR = true;
     return replys;
   }
 
@@ -637,6 +653,7 @@ export class MoveService implements OnModuleInit {
     reply['newUserStates'][0].playerState.camera.angle = rotateData.cameraAngle;
     reply['newUserStates'][0].playerState.cameraCenter = breakPoint.position;
     reply['actionResponses'][0].traceId = traceId;
+    console.log('stop658:'+breakPointId+','+rotateData.directory)
     reply.mediaSrc =
       '/' +
       appId +
@@ -667,7 +684,11 @@ export class MoveService implements OnModuleInit {
       const breakPointId = user.breakPointId;
       const appId = user.appId;
       const replys = [];
-      const step = 0.4;
+      console.log('joystickActionRequest=>'+traceId+'_'+new Date().getTime());
+      let step = 0.4;
+      if(user.walkState>MaxWalkCount){
+        step = 1.2;
+      }
       //const step = 1;
       const closestDis = 50; //小于这个距离就跳到邻居呼吸点
       const distance = step * dir_action.speed_level;
@@ -692,6 +713,8 @@ export class MoveService implements OnModuleInit {
         { x: 550, y: -300 },
       ];
 
+      //更新行走状态
+      ++user.walkState;
       //找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
       const breakPoint = this.breakPointInfo[breakPointId];
       const surroundPointIds = breakPoint.contact;
@@ -714,7 +737,13 @@ export class MoveService implements OnModuleInit {
       this.reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(
         JSON.stringify(user.player.position),
       );
-      this.reply['newUserStates'][0].renderInfo.isMoving = 1;
+
+      if(user.walkState>MaxWalkCount){
+        this.reply['newUserStates'][0].renderInfo.isMoving = 2;
+      }
+      else{
+        this.reply['newUserStates'][0].renderInfo.isMoving = 1;
+      }
       this.reply['actionResponses'][0].traceId = traceId;
       this.reply.mediaSrc = null;
 
@@ -758,24 +787,38 @@ export class MoveService implements OnModuleInit {
           closestAngleNeighor = angle;
         }
       }
-
+      console.log('joystickjoystick:' + this.cameraInfos.length);
+      this.reply.actionResponses[0].actionType = actionType;
       //超出范围了
       if (this.getDistance(playerPosition, breakPoint.position) > closestDis) {
-        console.log('20220627test-joystick-moveCamera');
-        return await this.moveCamera(
-          breakPointId,
-          closestNeighorId,
-          appId,
-          userId,
-          traceId,
-          actionType,
-        );
+        if (user.lastJoyStickMediaSrc) {
+          user.player.position = JSON.parse(JSON.stringify(playerPosition));
+          this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
+            JSON.stringify(user.player.position),
+          );
+          user.lastJoyStickMediaSrc = false;
+          console.log('joystickActionRequest_1=>'+traceId+'_'+new Date().getTime());
+          return this.reply;
+        }
+        else{
+          return await this.moveCamera(
+            breakPointId,
+            closestNeighorId,
+            appId,
+            userId,
+            traceId,
+            actionType,
+          );
+        }
       } else {
         const inside = this.isPointInPoly(playerPosition, area);
         //超出区域
         if (!inside) {
           if (minAngleNeighorId != null) {
-            console.log('20220627test-joystick-moveDirect');
+            if (user.lastJoyStickMediaSrc) {
+              user.lastJoyStickMediaSrc = false;
+              return null;
+            }
             return await this.moveDirect(
               playerPosition,
               closestDis,
@@ -795,28 +838,30 @@ export class MoveService implements OnModuleInit {
         this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
           JSON.stringify(user.player.position),
         );
-        this.reply.actionResponses[0].actionType = actionType;
 
-        console.log('20220708_延时->'+time_delay);
-        // //网络延迟的情况下,就暂时不推流
-        if(time_delay && time_delay>MaxDelayTime){
-          user.netQua = 0;
-        }
-        else if(time_delay && time_delay<MaxDelayTime && user.netQua<MaxNet){
-          ++user.netQua
+        console.log('20220719_延时->' + time_delay);
+        //网络延迟的情况下,就暂时不推流
+        if (
+          time_delay &&
+          time_delay < MaxDelayTime &&
+          user.netQua < MaxNet
+        ) {
+          ++user.netQua;
         }
+        else if (time_delay && time_delay > MaxDelayTime) {
+          user.netQua = 0;
+        }  
 
-        if(user.netQua<MaxNet){
-          if(user.lastJoyStickMediaSrc){
+        if (user.netQua < MaxNet) {
+          if (user.lastJoyStickMediaSrc) {
             user.lastJoyStickMediaSrc = false;
+            console.log('joystickActionRequest_1=>'+traceId+'_'+new Date().getTime());
             return this.reply;
           }
         }
+        
         const cameraInfo = this.getCameraInfo();
         if (cameraInfo != null) {
-          console.log(
-            '20220627test-joystick-自由-合并,' + this.cameraInfos.length,
-          );
           this.reply['newUserStates'][0].playerState.camera.position =
             cameraInfo.camera_position;
           this.reply['newUserStates'][0].playerState.camera.angle =
@@ -825,22 +870,19 @@ export class MoveService implements OnModuleInit {
           if (cameraInfo.mediaSrc) {
             this.reply.mediaSrc = cameraInfo.mediaSrc;
             this.reply.isIDR = cameraInfo.isIDR;
+            console.log('joystickActionRequest_2=>'+traceId+'_'+new Date().getTime());
             user.lastJoyStickMediaSrc = true;
-            console.log('20220708_mediaSrc1:'+cameraInfo.mediaSrc);
           }
 
           user.camera.position = JSON.parse(
             JSON.stringify(cameraInfo.camera_position),
           );
-          // console.log(
-          //   'handlejoystick-angle->:自由并过渡更新user.angle' +
-          //     cameraInfo.camera_angle.yaw,
-          // );
+
           user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
 
           this.sendingFrameForJoystick = true;
         } else {
-          console.log('20220627test-joystick-自由-不合并');
+
         }
         return this.reply;
       }
@@ -869,17 +911,13 @@ export class MoveService implements OnModuleInit {
       const closestDis = 80; //小于这个距离就跳到邻居呼吸点
       const distance = step * dir_action.speed_level;
       let angle = null;
-      // console.log(
-      //   'handlejoystick-angle->:dir_action.move_angle' + dir_action.move_angle,
-      // );
+
       if (user.camera.angle.yaw < 0) {
         user.camera.angle.yaw = 360 + user.camera.angle.yaw;
       }
       let move_angle = dir_action.move_angle + user.camera.angle.yaw;
       move_angle = move_angle % 360;
-      // console.log(
-      //   'handlejoystick-angle->:叠加后move_angle(也是user.angle)' + move_angle,
-      // );
+
       //TODO 临时增加断言
       const playerPosition: Point = { x: 0, y: 0, z: 0 };
       playerPosition.x =
@@ -891,10 +929,7 @@ export class MoveService implements OnModuleInit {
 
       // const offsetX = playerPosition.x - user.player.position.x;
       // const offsetY = playerPosition.y - user.player.position.y;
-      console.log(
-        'handlejoysticktesttest:actionRequest-playerPosition' +
-          JSON.stringify(playerPosition),
-      );
+
       //找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
       let chooseBreakPointId = null;
       const breakPoint = this.breakPointInfo[breakPointId];
@@ -917,7 +952,13 @@ export class MoveService implements OnModuleInit {
       this.reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(
         JSON.stringify(breakPoint.position),
       );
-      this.reply['newUserStates'][0].renderInfo.isMoving = 1;
+
+      if(user.walkState>MaxWalkCount){
+        this.reply['newUserStates'][0].renderInfo.isMoving = 2;
+      }
+      else{
+        this.reply['newUserStates'][0].renderInfo.isMoving = 1;
+      }
       this.reply['actionResponses'][0].traceId = traceId;
       this.reply.mediaSrc = null;
 
@@ -1018,11 +1059,6 @@ export class MoveService implements OnModuleInit {
         );
       } else {
         if (singleInfo != null) {
-          // console.log(
-          //   'joystick校验--->' + breakPointId + '-' + singleInfo.breakPointId,
-          // );
-          //console.log('handlejoysticktesttest校验0角度:'+_angle+','+move_angle)       //这个没办法,得换方案
-          //console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
           return await this.moveDirect(
             playerPosition,
             closestDis,
@@ -1034,7 +1070,6 @@ export class MoveService implements OnModuleInit {
             actionType,
           );
         } else if (count == 1) {
-          //console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
           return await this.moveDirect(
             playerPosition,
             closestDis,
@@ -1049,7 +1084,6 @@ export class MoveService implements OnModuleInit {
           this.reply['newUserStates'][0].playerState.player.position =
             JSON.parse(JSON.stringify(user.player.position));
           this.reply.actionResponses[0].actionType = actionType;
-          //console.log('handlejoysticktesttest:actionRequest-停止'+new Date().getTime());
           return this.reply;
         }
       }
@@ -1065,24 +1099,6 @@ export class MoveService implements OnModuleInit {
           this.getDistance(playerPosition, breakPoint.position),
       );
       if (this.getDistance(playerPosition, breakPoint.position) > closestDis) {
-        // let offsetAngle1 = Math.abs(_angle - neighPoints[0].angle);
-        // if (neighPoints[0].angle == 0) {
-        //   offsetAngle1 = Math.min(offsetAngle1, Math.abs(_angle - 360));
-        // }
-
-        // let offsetAngle2 = Math.abs(_angle - neighPoints[1].angle);
-        // if (neighPoints[1].angle == 0) {
-        //   offsetAngle2 = Math.min(offsetAngle2, Math.abs(_angle - 360));
-        // }
-
-        // if (offsetAngle1 > offsetAngle2) {
-        //   chooseBreakPointId = neighPoints[1].breakPointId;
-        // } else {
-        //   chooseBreakPointId = neighPoints[0].breakPointId;
-        // }
-        // if (closestNeighorId == null) {
-        //   debugger;
-        // }
         chooseBreakPointId = closestNeighorId;
         return await this.moveCamera(
           breakPointId,
@@ -1113,17 +1129,13 @@ export class MoveService implements OnModuleInit {
           user.camera.position = JSON.parse(
             JSON.stringify(cameraInfo.camera_position),
           );
-          // console.log(
-          //   'handlejoystick-angle->:自由并过渡更新user.angle' +
-          //     cameraInfo.camera_angle.yaw,
-          // );
+
           user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
 
           this.sendingFrameForJoystick = true;
         } else {
-          //console.log('joystick自由--->不合并');
         }
-        //console.log('handlejoysticktesttest:actionRequest-自由'+new Date().getTime());
+
         console.log(
           'handlejoysticktesttest:自由:' +
             this.reply.mediaSrc +
@@ -1156,10 +1168,7 @@ export class MoveService implements OnModuleInit {
       breakPoint.position,
       this.breakPointInfo[neighBreakPointId].position,
     );
-    // console.log('handlejoysticktesttest校验1线段:'+breakPointId+','+neighBreakPointId)
-    // console.log('handlejoysticktesttest校验2计算后的:'+JSON.stringify(player_Position))
-    // console.log('handlejoysticktesttest校验3人物变化前:'+JSON.stringify(user.player.position))
-    // console.log('handlejoysticktesttest校验4人物本应该的坐标:'+JSON.stringify(playerPosition))
+
     if (player_Position != null) {
       playerPosition.x = player_Position.x;
       playerPosition.y = player_Position.y;
@@ -1242,7 +1251,8 @@ export class MoveService implements OnModuleInit {
 
       for (let i = 0; i < checkReplys.length; ++i) {
         let isIDR = false;
-        if (i == 0 || i == checkReplys.length - 1) {
+        //if (i == 0 || i == checkReplys.length - 1) {
+        if (i == 0) {
           isIDR = true;
         }
         this.addCameraInfo(
@@ -1253,21 +1263,6 @@ export class MoveService implements OnModuleInit {
         );
       }
 
-      //replys.push(checkReplys);
-      //读redis里的数据,按照frame_index的大小排序
-      /*
-      const key =
-        'moveframe:app_id:' +
-        appId +
-        ':start_break_point_id:' +
-        breakPointId +
-        ':end_break_point_id:' +
-        chooseBreakPointId +
-        ':angle:' +
-        Math.floor(user.camera.angle.yaw / 45);
-      const moveFramesRes = await this.cacheService.get(key);
-      const moveFrames = JSON.parse(moveFramesRes);
-      */
       const index = this.getMoveIndex(user.camera.angle.yaw);
       const moveFrames = await this.getMoveFrames(
         appId,
@@ -1275,7 +1270,13 @@ export class MoveService implements OnModuleInit {
         chooseBreakPointId,
         index,
       );
-      this.setCameraInfo(appId, userId, moveFrames, breakPointId, chooseBreakPointId);
+      this.setCameraInfo(
+        appId,
+        userId,
+        moveFrames,
+        breakPointId,
+        chooseBreakPointId,
+      );
 
       user.breakPointId = chooseBreakPointId;
 
@@ -1289,10 +1290,7 @@ export class MoveService implements OnModuleInit {
         user.camera.position = JSON.parse(
           JSON.stringify(cameraInfo.camera_position),
         );
-        // console.log(
-        //   'handlejoystick-angle->:刚刚过渡更新user.angle' +
-        //     cameraInfo.camera_angle.yaw,
-        // );
+
         user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
 
         if (cameraInfo.mediaSrc) {
@@ -1301,7 +1299,7 @@ export class MoveService implements OnModuleInit {
         }
         this.sendingFrameForJoystick = true;
       }
-      //console.log('handlejoysticktesttest:actionRequest-镜头过渡'+new Date().getTime());
+
       console.log(
         'handlejoysticktesttest:actionRequest-镜头过渡:从' +
           breakPointId +
@@ -1314,18 +1312,29 @@ export class MoveService implements OnModuleInit {
     }
   }
 
-  setCameraInfo(appId, userId,moveFrames, startBreakPointId, endBreakPointId) {
-    // let moveInterval = 1;
-    // console.log('20220708_cameraInfos设置->'+this.cameraInfos.length);
-    // if(this.cameraInfos.length>MaxBufferCameraInfo){
-    //   moveInterval = 1;
-    // }
+  setCameraInfo(appId, userId, moveFrames, startBreakPointId, endBreakPointId) {
+    console.log('setCameraInfo前:'+this.cameraInfos.length);
     const user = this.users[userId];
-    let moveInterval = 2;
+    //let moveInterval = 2;
     let flag = false;
     for (let i = 0; i < moveFrames.length; ++i) {
-      if(user.netQua<MaxNet){
-        if(i!= 0 && i!= moveFrames.length-1 && i%moveInterval == 0){
+      if(user.walkState > MaxWalkCount){
+        //网络差
+        if (user.netQua < MaxNet) {
+          if (i != 0 && i != moveFrames.length - 1 && i % 5 != 0) {
+            continue;
+          }
+        }
+        //网络正常
+        else{
+          if (i != 0 && i != moveFrames.length - 1 && i % 4 != 0) {
+            continue;
+          }
+        }
+      }
+      //网络差
+      else if (user.netQua < MaxNet) {
+        if (i != 0 && i != moveFrames.length - 1 && i % 2 == 0) {
           continue;
         }
       }
@@ -1348,6 +1357,7 @@ export class MoveService implements OnModuleInit {
         new Date().getTime();
 
       if (startBreakPointId > endBreakPointId) {
+        console.log('change move1341:'+startBreakPointId+','+endBreakPointId)
         moveFrames[i].mediaSrc =
           '/' +
           appId +
@@ -1363,19 +1373,32 @@ export class MoveService implements OnModuleInit {
           '?m=' +
           new Date().getTime();
       }
-      console.log('20220708_mediaSrc3:'+moveFrames[i].mediaSrc);
-      if (i == 0 || i == moveFrames.length - 1) {
+                                                                // if (i == 0 || i == moveFrames.length - 1) {
+                                                                //   moveFrames[i].isIDR = true;
+                                                                //   if (i == moveFrames.length - 1) {
+                                                                //     flag = true;
+                                                                //   }
+                                                                // } else {
+                                                                //   moveFrames[i].isIDR = false; }
+                  
+      
+      if(user.IDRCount % 10 == 0){
         moveFrames[i].isIDR = true;
-        if(i == moveFrames.length - 1){
-          flag = true;
-        }
-      } else {
+        user.IDRCount = 0;
+      }    
+      else{
         moveFrames[i].isIDR = false;
       }
+      if (i == moveFrames.length - 1) {
+        flag = true;
+      }
+      ++user.IDRCount;                                         
       this.cameraInfos.push(moveFrames[i]);
+      console.log('mediaSrc_3:'+moveFrames[i].mediaSrc+',isIDR:'+moveFrames[i].isIDR)
     }
-    if(!flag){
-      const cameraInfo = moveFrames[moveFrames.length-1];
+    //最后一个元素跳过了,要补上
+    if (!flag) {
+      const cameraInfo = moveFrames[moveFrames.length - 1];
       cameraInfo.endBreakPointId = endBreakPointId;
       cameraInfo.mediaSrc =
         '/' +
@@ -1383,35 +1406,36 @@ export class MoveService implements OnModuleInit {
         '/' +
         startBreakPointId +
         '/' +
-        cameraInfo.file_name.substring(
-          0,
-          cameraInfo.file_name.indexOf('.'),
-        ) +
+        cameraInfo.file_name.substring(0, cameraInfo.file_name.indexOf('.')) +
         '/' +
         cameraInfo.file_name +
         '?m=' +
         new Date().getTime();
 
       if (startBreakPointId > endBreakPointId) {
+        console.log('change move1384:'+startBreakPointId+','+endBreakPointId)
         cameraInfo.mediaSrc =
           '/' +
           appId +
           '/' +
           endBreakPointId +
           '/' +
-          cameraInfo.file_name.substring(
-            0,
-            cameraInfo.file_name.indexOf('.'),
-          ) +
+          cameraInfo.file_name.substring(0, cameraInfo.file_name.indexOf('.')) +
           '/' +
           cameraInfo.file_name +
           '?m=' +
           new Date().getTime();
       }
-      cameraInfo.isIDR = true;
+                                                                            //cameraInfo.isIDR = true;
+      if(user.IDRCount % 10 == 0){
+        cameraInfo.isIDR = true;
+        user.IDRCount = 0;
+      } 
+      ++user.IDRCount;
       this.cameraInfos.push(cameraInfo);
-      console.log('20220708_mediaSrc4:'+cameraInfo.mediaSrc);
+      console.log('mediaSrc_4:'+cameraInfo.mediaSrc+',isIDR:'+cameraInfo.isIDR)
     }
+    console.log('setCameraInfo后:'+this.cameraInfos.length);
   }
 
   addCameraInfo(cameraPosition, cameraAngle, mediaSrc, isIDR) {
@@ -1426,7 +1450,6 @@ export class MoveService implements OnModuleInit {
   getCameraInfo() {
     if (this.cameraInfos.length > 0) {
       const item = this.cameraInfos.shift();
-      console.log('20220708_cameraInfos取值->'+this.cameraInfos.length);
       return item;
     } else {
       return null;
@@ -1434,9 +1457,10 @@ export class MoveService implements OnModuleInit {
   }
 
   complementFrame(userId) {
+    const user = this.users[userId];
+    user.walkState = 0;
+    user.IDRCount = 0;
     if (this.cameraInfos.length > 0) {
-      console.log('20220627test-执行complementFrame,' + new Date().getTime());
-      const user = this.users[userId];
       const cameraInfo = this.cameraInfos.shift();
       this.reply.traceIds = [];
       this.reply['newUserStates'][0].userId = userId;
@@ -1472,11 +1496,9 @@ export class MoveService implements OnModuleInit {
       this.sendingFrameForJoystick = true;
       return this.reply;
     } else if (this.cameraInfos.length == 0) {
-      if (this.reply['newUserStates'][0].renderInfo.isMoving == 1) {
-        //console.log('handlejoysticktesttest:complementFrame-2 停止1'+new Date().getTime())
+      if (this.reply['newUserStates'][0].renderInfo.isMoving != 0) {
         return this.stopJoystick(userId);
       } else {
-        //console.log('handlejoysticktesttest:complementFrame-2 停止2'+new Date().getTime())
         return null;
       }
     }
@@ -1507,9 +1529,8 @@ export class MoveService implements OnModuleInit {
   //   return JSON.parse(JSON.stringify(this.reply));
   // }
 
-  async updateCameraInfoForDely(appId,userId,path){
-
-    if(path == null){
+  async updateCameraInfoForDely(appId, userId, path) {
+    if (path == null) {
       this.cameraInfos = [];
       return;
     }
@@ -1531,32 +1552,32 @@ export class MoveService implements OnModuleInit {
       if (!moveFrames) {
         return null;
       }
-      frames = frames.concat(moveFrames)
+      frames = frames.concat(moveFrames);
       pointIds.push({
-        index:frames.length,
-        startBreakPointId:start_break_point_id,
-        endBreakPointId:end_break_point_id
+        index: frames.length,
+        startBreakPointId: start_break_point_id,
+        endBreakPointId: end_break_point_id,
       });
     }
     this.cameraInfos = [];
-    const interval = Math.floor(frames.length/12);
-    for (let i = 0; i < frames.length-1; i+=interval) {
+    const interval = Math.floor(frames.length / 12);
+    for (let i = 0; i < frames.length - 1; i += interval) {
       const frame = frames[i];
       let isIDR = false;
-      if(i == 0){
+      if (i == 0) {
         isIDR = true;
       }
 
-      let startBreakPointId,endBreakPointId;
-      for(let j=0;j<pointIds.length;++j){
-        if(i<pointIds[j].index+1){
+      let startBreakPointId, endBreakPointId;
+      for (let j = 0; j < pointIds.length; ++j) {
+        if (i < pointIds[j].index + 1) {
           startBreakPointId = pointIds[j].startBreakPointId;
           endBreakPointId = pointIds[j].endBreakPointId;
           break;
         }
       }
 
-        let mediaSrc =
+      let mediaSrc =
         '/' +
         appId +
         '/' +
@@ -1568,6 +1589,7 @@ export class MoveService implements OnModuleInit {
         '?m=' +
         new Date().getTime();
       if (startBreakPointId > endBreakPointId) {
+        console.log('change move1552:'+startBreakPointId+','+endBreakPointId)
         mediaSrc =
           '/' +
           appId +
@@ -1580,10 +1602,10 @@ export class MoveService implements OnModuleInit {
           '?m=' +
           new Date().getTime();
       }
-      console.log('20220708_mediaSrc2:'+mediaSrc);
+      console.log('mediaSrc_5:'+mediaSrc)
       this.cameraInfos.push({
-        startBreakPointId:startBreakPointId,
-        endBreakPointId:endBreakPointId,
+        startBreakPointId: startBreakPointId,
+        endBreakPointId: endBreakPointId,
         camera_position: frame.camera_position,
         camera_angle: frame.camera_angle,
         mediaSrc: mediaSrc,
@@ -1591,45 +1613,47 @@ export class MoveService implements OnModuleInit {
       });
     }
 
-    const startBreakPointId = pointIds[pointIds.length-1].startBreakPointId;
-    const endBreakPointId = pointIds[pointIds.length-1].endBreakPointId;
-    const frame = frames[frames.length-1];
+    const startBreakPointId = pointIds[pointIds.length - 1].startBreakPointId;
+    const endBreakPointId = pointIds[pointIds.length - 1].endBreakPointId;
+    const frame = frames[frames.length - 1];
     let mediaSrc =
+      '/' +
+      appId +
+      '/' +
+      startBreakPointId +
+      '/' +
+      frame.file_name.substring(0, frame.file_name.indexOf('.')) +
+      '/' +
+      frame.file_name +
+      '?m=' +
+      new Date().getTime();
+    if (startBreakPointId > endBreakPointId) {
+      console.log('change move1591:'+startBreakPointId+','+endBreakPointId)
+      mediaSrc =
         '/' +
         appId +
         '/' +
-        startBreakPointId +
+        endBreakPointId +
         '/' +
         frame.file_name.substring(0, frame.file_name.indexOf('.')) +
         '/' +
         frame.file_name +
         '?m=' +
         new Date().getTime();
-      if (startBreakPointId > endBreakPointId) {
-        frame.mediaSrc =
-          '/' +
-          appId +
-          '/' +
-          endBreakPointId +
-          '/' +
-          frame.file_name.substring(0, frame.file_name.indexOf('.')) +
-          '/' +
-          frame.file_name +
-          '?m=' +
-          new Date().getTime();
-      }
-      this.cameraInfos.push({
-        startBreakPointId:startBreakPointId,
-        endBreakPointId:endBreakPointId,
-        camera_position: frame.camera_position,
-        camera_angle: frame.camera_angle,
-        mediaSrc: mediaSrc,
-        isIDR: true,
-      });
+    }
+    console.log('mediaSrc_6:'+mediaSrc)
+    this.cameraInfos.push({
+      startBreakPointId: startBreakPointId,
+      endBreakPointId: endBreakPointId,
+      camera_position: frame.camera_position,
+      camera_angle: frame.camera_angle,
+      mediaSrc: mediaSrc,
+      isIDR: true,
+    });
   }
 
   stopJoystick(userId) {
-    console.log('20220627test:stopJoystick');
+
     this.reply.traceIds = [];
     const user = this.users[userId];
     this.reply['newUserStates'][0].userId = userId;

+ 21 - 54
src/rotate/rotate.service.ts

@@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common';
 import { ConfigService } from '@nestjs/config';
 import { CacheService } from 'src/cache/cache.service';
 // import { SceneService } from 'src/scene/scene.service';
+// import ShareData from 'src/ShareData';
 
 const seqExeAsyncFn = (asyncFn) => {
   let runPromise = null;
@@ -34,8 +35,9 @@ export class RotateService {
     Rotation: 1014,
     Joystick: 15,
   };
+
   public users = {};
-  private replies = {};
+  private replys = {};
   private firstPoint = {
     player: {
       position: { x: -600.0, y: -250.0, z: 0.0 }, //position: { x: -560.0, y: 320.0, z: 0.0 }, //{ x: -800.0, y: 100.0, z: 0.0 },
@@ -89,8 +91,10 @@ export class RotateService {
         frameIndex: 0,
         horizontal_move: 0,
       },
-      moveInfo: {},
-      netQua:3,
+      netQua:0,
+      walkState:0,
+      isMoving:0,
+      IDRCount:0,
       // traceIds: [],
       // actionResponses:[]
     };
@@ -108,9 +112,9 @@ export class RotateService {
     user.camera.position = JSON.parse(
       JSON.stringify(this.firstPoint.camera.position),
     );
-    
-    console.log('user-init', user);
+    console.log('user-init1', userId);
     this.users[userId] = user;
+    console.log('user-init2', JSON.stringify(this.users));
 
     const reply = {
       traceIds: [],
@@ -204,14 +208,14 @@ export class RotateService {
     reply['newUserStates'][0].playerState.camera.position = JSON.parse(
       JSON.stringify(this.firstPoint.camera.position),
     );
-    this.replies[userId] = reply;
+    this.replys[userId] = reply;
     return reply;
   }
 
   //首帧
   getFirstStreamData(appId, userId) {
     const user = this.users[userId];
-    const reply = this.replies[userId];
+    const reply = this.replys[userId];
     reply.traceIds = [];
     reply['newUserStates'][0].userId = userId;
     reply['newUserStates'][0].playerState.player.position = JSON.parse(
@@ -244,7 +248,7 @@ export class RotateService {
       '?m=' +
       new Date().getTime();
     reply['newUserStates'][0].renderInfo.isMoving = 0;
-    this.replies[userId] = reply;
+    this.replys[userId] = reply;
     return reply;
   }
 
@@ -274,7 +278,7 @@ export class RotateService {
         this.actionRequestPool[userId].push(actionRequest);
       }
 
-      let reply = this.replies[userId];
+      let reply = this.replys[userId];
 
       const actionRequests = this.actionRequestPool[userId];
       const user = this.users[userId];
@@ -302,7 +306,7 @@ export class RotateService {
       if (Math.abs(hAngle) < 1) {
         user.rotateInfo.horizontal_move = horizontal_move;
         //user.traceIds = traceIds;
-        this.replies[userId] = reply;
+        this.replys[userId] = reply;
         return null;
       }
       reply = await this.rotateForAngle(userId, Math.floor(hAngle));
@@ -347,7 +351,7 @@ export class RotateService {
         } else if (user.camera.angle.yaw > 359) {
           user.camera.angle.yaw -= 360;
         }
-        const reply = JSON.parse(JSON.stringify(this.replies[userId]));
+        const reply = JSON.parse(JSON.stringify(this.replys[userId]));
         reply['newUserStates'][0]['userId'] = userId;
         //从redis里取
         //let key = user.appId + "-"+user.breakPointId+"-"+user.rotateInfo.frameIndex;
@@ -421,8 +425,8 @@ export class RotateService {
             value.fileName,
         );
         reply.breakPointId = user.breakPointId;
-        this.replies[userId].traceIds = [];
-        this.replies[userId].actionResponses = [];
+        this.replys[userId].traceIds = [];
+        this.replys[userId].actionResponses = [];
 
         user.rotateInfo.horizontal_move = 0;
         return resolve(reply);
@@ -480,8 +484,9 @@ export class RotateService {
         code: 0,
         msg: '',
       };
-
+      
       const userIds = Object.keys(this.users);
+      console.log('getNewUserStateRequest'+userIds);
       for (let i = 0; i < userIds.length; ++i) {
         const _user = this.users[userIds[i]];
         const newUserState = {
@@ -547,7 +552,7 @@ export class RotateService {
 
   async echo(userId: string, isFirst: boolean) {
     const user = this.users[userId];
-    const reply = JSON.parse(JSON.stringify(this.replies[userId]));
+    const reply = JSON.parse(JSON.stringify(this.replys[userId]));
     reply['newUserStates'][0]['userId'] = userId;
     reply['newUserStates'][0]['playerState'].player.position =
       user.player.position;
@@ -574,41 +579,6 @@ export class RotateService {
       reply.breakPointId = user.breakPointId;
       return reply;
     } else {
-      /*
-      const key =
-        'rotateframe:app_id:' +
-        user.appId +
-        ':frame_index:' +
-        user.camera.angle.yaw +
-        ':break_point_id:' +
-        user.breakPointId;
-      const redisData = await this.cacheService.get(key);
-      if (redisData && redisData.length > 0) {
-        const value = redisData ? JSON.parse(redisData) : null;
-        reply.mediaSrc =
-          '/' +
-          user.appId +
-          '/' +
-          user.breakPointId +
-          '/' +
-          value.directory +
-          '/' +
-          value.fileName +
-          '?m=' +
-          new Date().getTime();
-        reply.breakPointId = user.breakPointId;
-        // console.log(
-        //   'joystick:->echo' +
-        //     'playerPosition:' +
-        //     JSON.stringify(
-        //       reply['newUserStates'][0].playerState.player.position,
-        //     ) +
-        //     ',cameraPosition:' +
-        //     JSON.stringify(
-        //       reply['newUserStates'][0].playerState.camera.position,
-        //     ),
-        // );
-        */
       let fileName = user.camera.angle.yaw + '.h264';
       if (fileName.length == 8) {
         fileName = '0' + fileName;
@@ -617,7 +587,7 @@ export class RotateService {
       } else if (fileName.length == 6) {
         fileName = '000' + fileName;
       }
-
+      reply['newUserStates'][0].renderInfo.isMoving = user.isMoving;
       reply.mediaSrc =
         '/' +
         user.appId +
@@ -633,9 +603,6 @@ export class RotateService {
         new Date().getTime();
       reply.breakPointId = user.breakPointId;
       return reply;
-      // } else {
-      //   this.logger.error('echo返回null', key);
-      //   return {};
     }
   }
 }

+ 107 - 91
src/scene/scene.service.ts

@@ -1,7 +1,7 @@
 import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
 import { ClientGrpc, Client } from '@nestjs/microservices';
 import { grpcClientOptions } from './grpc-scene.options';
-import { Logger } from '@nestjs/common';
+import { Inject } from '@nestjs/common';
 import { DataChannel, PeerConnection } from 'node-datachannel';
 import { BehaviorSubject } from 'rxjs';
 // import * as streamBuffers from 'stream-buffers';
@@ -16,6 +16,13 @@ import { DelayQueue, RxQueue, DebounceQueue } from '../queue/mod';
 import { MoveService } from 'src/move/move.service';
 import { GetRouterService } from 'src/get-router/get-router.service';
 import { ConfigService } from '@nestjs/config';
+import { Logger } from 'winston';
+import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
+// import ShareData from 'src/ShareData';
+// interface UserInfo {
+//   userId: string;
+//   roomId: string;
+// }
 
 const seqExeAsyncFn = (asyncFn) => {
   let runPromise = null;
@@ -37,7 +44,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     private streamService: StreamService,
     private rotateService: RotateService,
     private moveService: MoveService,
-    private getRouterService: GetRouterService, // @InjectQueue('rotate') private rotateQueue: Queue, // @InjectQueue('walking') private walkingQueue: Queue,
+    private getRouterService: GetRouterService,
+    @Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger,
   ) {}
   @Client(grpcClientOptions) private readonly client: ClientGrpc;
 
@@ -61,7 +69,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
   private channel: DataChannel;
   private peer: PeerConnection;
-  private logger: Logger = new Logger('SceneService');
+  // private logger: Logger = new Logger('SceneService');
   private frameCntInterval = 1000;
   private user_id: string;
   private roomId: string;
@@ -115,9 +123,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   private isJoystickHasStream = false;
   private hasJoystickFocusRepeat = false;
   private startSub: any;
-
-  public users = {};
-
   public sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
 
   private globalOptLock = false;
@@ -130,8 +135,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     Number.prototype.padLeft = function (n, str) {
       return Array(n - String(this).length + 1).join(str || '0') + this;
     };
-    // this.logger.log('roQueue-period :' + Number(this.roQueue.period));
-    this.logger.log('moveQueue-period :' + Number(this.moveQueue.period));
+    // this.logger.info('roQueue-period :' + Number(this.roQueue.period));
+    this.logger.info('moveQueue-period :' + Number(this.moveQueue.period));
   }
 
   public isHeaderOrLast(index: number, length: number): boolean {
@@ -230,10 +235,17 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     }
   }
 
-  exit() {
+  async exit() {
     this.frameCnt.next(-1);
     this.rotateService.deleteUser(this.user_id);
     this.hasJoystickFocusRepeat = false;
+    const userId = this.user_id;
+    const roomId = this.roomId;
+    const roomKey =
+      process.env.NODE_ENV === 'development'
+        ? `test-room:${roomId}`
+        : `room:${roomId}`;
+    this.cacheService.hDel(roomKey, userId);
     if (this.startSub) {
       this.startSub.unsubscribe();
       this.startSub = null;
@@ -267,9 +279,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     // try {
     const rotateUnlock = this.firstRender && !this.globalOptLock;
     console.log('rotateUnlock条件--->' + rotateUnlock, this.globalOptLock);
-
     if (rotateUnlock && this._rotateCount > 2) {
-      console.log('20220627test:handleRotate');
       const start = performance.now();
       // 当move时处理 _rotateCount是移动端同时触发的问题,rotateStopThrottle是减少重复抖动stop的处理。
       this.holdSteam();
@@ -295,7 +305,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             const stop = performance.now();
             const inMillSeconds = stop - start;
             const rounded = Number(inMillSeconds).toFixed(3);
-            this.logger.log(
+            this.logger.info(
               `[timer]-rotate-入队列前: ${rounded}ms -->` +
                 JSON.stringify(stream),
             );
@@ -358,6 +368,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       IDRflag,
       new Date().getTime(),
     );
+
+    const user = this.moveService.users[this.user_id];
+    user.isMoving = JSON.parse(stream.metaData)['newUserStates'][0].renderInfo.isMoving
     const res = await this.streamService.pushFrameToSteam(stream);
     if (res.done) {
       this.frameCnt.next(res.frame);
@@ -369,7 +382,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
       clearTimeout(this._rotateTimeout);
       this._rotateTimeout = setTimeout(() => {
-        this.logger.log('rotate end', Date.now());
+        this.logger.info('rotate end', Date.now());
         this.rotateframeCnt = -1;
         this._rotateCountFame = -1;
         this._rotateCount = 0;
@@ -401,7 +414,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   //         this._rotateCountFame += 1;
 
   //         const IDRflag = this._rotateCountFame % 5 === 0 ? 1 : 3;
-  //         this.logger.log(
+  //         this.logger.info(
   //           `当前rotate ,mainframeCnt:${this.frameCnt.getValue()}, _rotateCountFame:${this._rotateCountFame
   //           } IDRflag:${IDRflag}`,
   //         );
@@ -410,7 +423,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   //           this.rotateFirstIDR = false;
   //         }
 
-  //         this.logger.log(
+  //         this.logger.info(
   //           '[media-rotate]: ' +
   //           ', frame: ' +
   //           stream.frame +
@@ -420,7 +433,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   //           stream.clipPath,
   //           // stream.metaData,
   //         );
-  //         // this.logger.log(
+  //         // this.logger.info(
   //         //   `roQueueSubscription:frame:${this.rotateframeCnt}  ` +
   //         //   JSON.stringify(stream.metaData),
   //         // );
@@ -429,7 +442,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   //         if (res.done) {
   //           clearTimeout(this._rotateTimeout);
   //           this._rotateTimeout = setTimeout(() => {
-  //             this.logger.log('rotate end', Date.now());
+  //             this.logger.info('rotate end', Date.now());
   //             this.frameCnt.next(res.frame);
   //             this.rotateframeCnt = -1;
   //             this._rotateCountFame = -1;
@@ -465,7 +478,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     this.rotateStopThrottle = true;
     this.isStopJointing = true;
     const lastStreamFrame = this.lastMoveStreamFrame.getValue();
-    this.logger.log(
+    this.logger.info(
       'handleRotateOrWalkingStop-frame',
       JSON.stringify(lastStreamFrame),
     );
@@ -492,7 +505,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     const breakPointId = metaData.endBreakPointId || metaData.breakPointId;
     const cameraAngle = newUserStates.playerState.camera.angle;
     const playerAngle = newUserStates.playerState.player.angle;
-    this.logger.log(
+    this.logger.info(
       'stop-data-0' +
         'trace_id: ' +
         trace_id +
@@ -515,7 +528,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       cameraAngle,
       playerAngle,
     );
-    this.logger.log('stop-redisMeta-frame', JSON.stringify(redisMeta));
+    this.logger.info('stop-redisMeta-frame', JSON.stringify(redisMeta));
     if (redisMeta) {
       const src = redisMeta.mediaSrc.split('?')[0];
       const mediaSrc = this.configService.get('app.prefix') + src;
@@ -547,18 +560,23 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     }
   }
 
-  async getSimplestCameraInfo(appId,userId){
-    if(this.moveService.cameraInfos.length>20){
-      const startBreakPointId = this.moveService.cameraInfos[0].startBreakPointId;
-      const endBreakPointId = this.moveService.cameraInfos[this.moveService.cameraInfos.length-1].endBreakPointId;
-
-      const path = this.getRouterService.searchRoad2(startBreakPointId,endBreakPointId);
-      if(path == null){
+  async getSimplestCameraInfo(appId, userId) {
+    if (this.moveService.cameraInfos.length > 20) {
+      const startBreakPointId =
+        this.moveService.cameraInfos[0].startBreakPointId;
+      const endBreakPointId =
+        this.moveService.cameraInfos[this.moveService.cameraInfos.length - 1]
+          .endBreakPointId;
+
+      const path = this.getRouterService.searchRoad2(
+        startBreakPointId,
+        endBreakPointId,
+      );
+      if (path == null) {
         //可以清空cameraInfos
         this.moveService.cameraInfos = [];
-      }
-      else{
-        await this.moveService.updateCameraInfoForDely(appId,userId,path);
+      } else {
+        await this.moveService.updateCameraInfoForDely(appId, userId, path);
       }
     }
   }
@@ -570,7 +588,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
    */
   async walking(request: MoveRequest) {
     this.latestWalkingRequest = request;
-    this.logger.log('walking-trace_id', request.trace_id);
+    this.logger.info('walking-trace_id', request.trace_id);
 
     // if (this.isHasWalkingJoints()) {
     //   console.log('lock-锁-walking', this.latestWalkingRequest);
@@ -600,7 +618,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           //TODO 正在行走时,有新的reqest
           if (frame) {
             // console.log('unlock-Joints', JSON.stringify(frame));
-            this.logger.log('Joints', JSON.stringify(frame));
+            this.logger.info('Joints', JSON.stringify(frame));
             this.resumeRotate();
             let isRotateStop = false;
             let isWalkingStop = false;
@@ -681,13 +699,13 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       this._rotateCount = 0;
       const user = this.moveService.users[this.user_id];
       console.log('进入1 - searchRoad');
-      this.logger.log(
+      this.logger.info(
         'handleWalking-users' +
           JSON.stringify(this.moveService.users) +
           ' this.user_id: ' +
           this.user_id,
       );
-      this.logger.log(
+      this.logger.info(
         'handleWalking-currentUser' +
           JSON.stringify(user) +
           ' this.user_id: ' +
@@ -700,7 +718,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         user.breakPointId,
         request.clicking_action.clicking_point,
       );
-      this.logger.log('walking-path', path);
+      this.logger.info('walking-path', path);
       if (!path) {
         console.log('不存在--path', path);
         this.cleanMoveSteam();
@@ -721,10 +739,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           for (let i = 0; i <= walkingRes.length - 1; i++) {
             Array.from(walkingRes[i]).forEach(
               (item: StreamReplyType, index: number) => {
-                console.log(
-                  '20220628test:handleWalking->' +
-                    item['newUserStates'][0].renderInfo.isMoving,
-                );
                 //const IDRflag = index % 5 === 0 ? 1 : 3;
                 const IDRflag = item.isIDR ? 1 : 3;
                 const dir = this.isHeaderOrLast(
@@ -748,7 +762,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const seqs = Array.from(walkingRes).flat() as any as StreamReplyType[];
 
         if (seqs?.length) {
-          this.logger.log(
+          this.logger.info(
             'walking --队列总览:' +
               ' 总段数: ' +
               walkingRes.length +
@@ -764,7 +778,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           const stop = performance.now();
           const inMillSeconds = stop - start;
           const rounded = Number(inMillSeconds).toFixed(3);
-          this.logger.log(`[timer]-move-入队列前:-->${rounded}ms`);
+          this.logger.info(`[timer]-move-入队列前:-->${rounded}ms`);
 
           this.handleSeqMoving(seqs);
         } else {
@@ -798,7 +812,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
    */
   async joystick(request: JoystickRequest) {
     // TODO hasJoystickMoveRequest中断
-    this.logger.log('this.hasJoystickMoveRequest', this.hasJoystickMoveRequest);
+    this.logger.info(
+      'this.hasJoystickMoveRequest',
+      this.hasJoystickMoveRequest,
+    );
     if (!this.hasJoystickMoveRequest) {
       this.handlejoystick(request);
     }
@@ -826,6 +843,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     const hasMedia = joystickRes?.mediaSrc && joystickRes?.mediaSrc.length > 0;
 
     if (hasMedia) {
+      console.log('mediaSrc_7:'+joystickRes.mediaSrc);
       const src = joystickRes.mediaSrc.split('?')[0];
       const mediaSrc = this.configService.get('app.prefix') + src;
       // IDR flag设置为I帧
@@ -852,10 +870,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       };
     }
 
-    console.log(
-      '20220627test-complementFrame 进行1' + '***' + streamData.frame,
-    );
-
+    const user = this.moveService.users[this.user_id];
+    user.isMoving = JSON.parse(streamData.metaData)['newUserStates'][0].renderInfo.isMoving;
+    console.log('handlePushJoyStickSteam:'+user.IDRCount+','+joystickRes.isIDR+','+joystickRes.traceIds);
     // 过滤新东西, 推完给回false
     this.moveService.sendingFrameForJoystick = true;
 
@@ -898,18 +915,11 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           this.user_id,
         ) as StreamReplyType;
         if (complementFrame) {
-          console.log(
-            '20220627test-complementFrame 进行' +
-              complementFrame.mediaSrc +
-              '***' +
-              this.frameCnt.value,
-          );
           // 第二次或N次进入时如果有值直接重新进入流主程
           this.holdSteam();
           this.handlePushJoyStickSteamSeq(complementFrame);
           this.globalOptLock = true;
         } else {
-          console.log('20220627test-complementFrame 结束');
           // 第二次或N次无pool数据再次trigger handleJoystickStop
           this.hasJoystickFocusRepeat = false;
           this.testTimer = 0;
@@ -921,6 +931,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         this.handleJoystickStop(hasPush);
       }
     } else {
+      debugger;
       console.error('joystick-流地址有误::', joystickRes.mediaSrc);
       this.logger.error('joystick-流地址有误::', joystickRes.mediaSrc);
       this.resumeStream();
@@ -933,14 +944,13 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     // 最后一帧200ms
     clearTimeout(this._JoyStickingSteamTimeout);
     this._JoyStickingSteamTimeout = setTimeout(async () => {
-      console.log('20220627test-complementFrame handleJoystickStop 200ms之后');
       const user = this.moveService.users[this.user_id];
-      await this.getSimplestCameraInfo(user.appId,this.user_id);
+      await this.getSimplestCameraInfo(user.appId, this.user_id);
       const complementFrame = this.moveService.complementFrame(
         this.user_id,
       ) as StreamReplyType;
       // console.log('has-complementFrame', complementFrame);
-      console.log('gemer-test-complementFrame', complementFrame);
+      //console.log('gemer-test-complementFrame', complementFrame);
       if (complementFrame) {
         this.hasJoystickFocusRepeat = true;
         this.globalOptLock = true;
@@ -949,14 +959,14 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const start = performance.now();
         this.handlePushJoyStickSteamSeq(complementFrame);
         const stop = performance.now();
-        console.log('handlePushJoyStickSteam', this.testTimer);
+        //console.log('handlePushJoyStickSteam', this.testTimer);
         const inMillSeconds = stop - start;
         const rounded = Number(inMillSeconds).toFixed(3);
         console.log(`complementFrame调用时间---->${rounded}`);
       } else {
         console.log('complementFrame-空1');
-        this.logger.log('joystick opt done');
-        this.logger.log('joystick 交权给空流,当前pts', hasPush.frame);
+        this.logger.info('joystick opt done');
+        this.logger.info('joystick 交权给空流,当前pts', hasPush.frame);
         this.hasJoystickFocusRepeat = false;
         this.onJoysticking.next(false);
         this.resumeStream();
@@ -975,23 +985,15 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       //const joystickRes = await this.moveService.joystick(request);
       this._rotateCount = 0;
       const joystickRes = await this.moveService.seqExeJoystick(request);
-      this.logger.log(
+      this.logger.info(
         'joystick-breakPointId:' +
           this.moveService.users[this.user_id].breakPointId,
       );
       // 有数据 [0]是rotate数据,[1-infinity]是walking数据
-      //this.logger.log('joystickRes', JSON.stringify(joystickRes));
+      //this.logger.info('joystickRes', JSON.stringify(joystickRes));
 
       if (joystickRes) {
         this.onJoysticking.next(true);
-        // console.log(
-        //   'handlejoysticktesttest:' +
-        //     joystickRes.mediaSrc +
-        //     ',相机坐标:' +
-        //     JSON.stringify(
-        //       joystickRes.newUserStates[0].playerState.player.position,
-        //     ),
-        // );
         if (!this.onMoving.getValue()) {
           console.log('handlejoystick:data', JSON.stringify(joystickRes));
           this.handlePushJoyStickSteamSeq(joystickRes);
@@ -1015,7 +1017,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     // if (!this.moveQueueSubscription) {
     //   this.handleMoveSteam();
     // }
-    // this.logger.log('moving-seqs', seqs.length);
+    // this.logger.info('moving-seqs', seqs.length);
     this.onMoving.next(true);
     this.holdSteam();
     // 保证每一段都是序列动作的前面队列是空的
@@ -1047,11 +1049,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     try {
       if (!this.isStopJointing) {
         const metaData: StreamReplyType = JSON.parse(stream.metaData);
-        // if (this.moveframeCnt === -1) {
-        //   this.moveframeCnt = this.frameCnt.getValue();
-        // }
-        // this.moveframeCnt += 1;
-        // this.latestBreakPointId = metaData.endBreakPointId;
         this.moveframeCnt = this.frameCnt.value + 1;
         const streamData: StreamFrameType = {
           frame: this.moveframeCnt,
@@ -1060,7 +1057,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           serverTime: this.mockserverTime,
           DIR: stream.DIR,
         };
-        this.logger.log(
+        this.logger.info(
           '[media-move]: ' +
             ', moveframeCnt: ' +
             this.moveframeCnt +
@@ -1072,10 +1069,13 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             stream.DIR,
           // stream.metaData,
         );
-        this.logger.log(
+        this.logger.info(
           '[media-move-lastMovingPointArray]',
           this.lastMovingPointArray?.length,
         );
+
+        const user = this.moveService.users[this.user_id];
+        user.isMoving = JSON.parse(streamData.metaData)['newUserStates'][0].renderInfo.isMoving;
         // 记录lastMoveStreamFrame给打断逻辑使用
         this.lastMoveStreamFrame.next(streamData);
         // this.lastMoveStreamFrameBk = streamData;
@@ -1088,7 +1088,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const isLastFrameIndex = this.lastMovingPointArray.findIndex(
           (item) => item.mediaSrc === metaData.mediaSrc,
         );
-        // this.logger.log('path-update-index', isLastFrameIndex);
+        // this.logger.info('path-update-index', isLastFrameIndex);
 
         if (res.done) {
           const frameTimeEnd = performance.now();
@@ -1098,7 +1098,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           this.frameCnt.next(res.frame);
           //关节点入库
           if (isLastFrameIndex > -1) {
-            //this.logger.log('path-update-array', this.lastMovingPointArray);
+            //this.logger.info('path-update-array', this.lastMovingPointArray);
             const currentMeta = this.lastMovingPointArray[isLastFrameIndex];
             const userId = this.user_id;
             const breakPointId = currentMeta.metaData.endBreakPointId;
@@ -1111,7 +1111,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           clearTimeout(this._moveTimeout);
 
           this._moveTimeout = setTimeout(() => {
-            this.logger.log('move 交权给空流,当前pts', res.frame);
+            this.logger.info('move 交权给空流,当前pts', res.frame);
             this.rewalking = false;
             this.frameCnt.next(res.frame);
             this.rotateframeCnt = -1;
@@ -1122,7 +1122,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             this.cleanMoveSteam();
             this.globalOptLock = false;
             this.resumeStream();
-            this.logger.log('move end');
+            this.logger.info('move end');
           }, 200);
         } else {
           console.error('流地址有误::', res.frame, JSON.stringify(res));
@@ -1159,13 +1159,27 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     this.rotateStopThrottle = false;
   }
 
-  handleDataChanelOpen(channel: DataChannel, peer: PeerConnection): void {
+  async handleDataChanelOpen(
+    channel: DataChannel,
+    peer: PeerConnection,
+  ): Promise<void> {
     this.channel = channel;
     this.peer = peer;
     this.streamService.setChannel(channel);
     this.startSteaming.next(true);
+
     // this.startStream();
     // this.handleStream();
+    //TODO 正式channel打开记录,记录多少人在线
+    const userId = this.user_id;
+    const roomId = this.roomId;
+    const roomKey =
+      process.env.NODE_ENV === 'development'
+        ? `test-room:${roomId}`
+        : `room:${roomId}`;
+
+    this.cacheService.hset(roomKey, userId, 1);
+    // debugger;
     this.channel.onBufferedAmountLow(() => {
       console.error('onBufferedAmountLow-rtt', this.peer.rtt());
       console.error('onBufferedAmountLow', this.channel.bufferedAmount());
@@ -1246,7 +1260,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           if (frameData) {
             this.globalOptLock = true;
             const nextFrame = this.frameCnt.getValue() + 1;
-            this.logger.warn('lostIframe', nextFrame);
+            this.logger.warn('lostIframe:' + nextFrame);
             frameData.frame = nextFrame;
             frameData.DIR = 1;
             const res = await this.streamService.pushFrameToSteam(frameData);
@@ -1271,7 +1285,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
   handleBreath(request) {
     const npsRes = this.moveService.getBreakPoints(request);
-    //this.logger.log('npsRes', npsRes.nps);
+    //this.logger.info('npsRes', npsRes.nps);
     this.streamService.pushNormalDataToStream(npsRes);
   }
 
@@ -1287,7 +1301,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       const usersData = this.rotateService.getNewUserStateRequest(request);
       if (usersData) {
         usersData.actionType = 1024;
-        //this.logger.log(
+        //this.logger.info(
         //   'joystick:->updateUserStatus' +
         //   'playerPosition:' +
         //   JSON.stringify(
@@ -1321,12 +1335,12 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     });
   }
   handleStream() {
-    this.logger.log('this.frameCntSubscription', this.frameCntSubscription);
+    this.logger.info('this.frameCntSubscription', this.frameCntSubscription);
     let redisData;
     if (!this.frameCntSubscription) {
       this.frameCntSubscription = this.frameCnt.subscribe(async (frame) => {
         try {
-          this.logger.log('frame', frame);
+          this.logger.info('frame: ' + frame);
           console.log(
             'networkState:::--->' +
               ' maxMessageSize: ' +
@@ -1348,7 +1362,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               app_id,
               this.user_id,
             );
-            this.logger.log('获取-首屏', redisData);
+            this.logger.warn(
+              'bootstrap:socket::首屏 --->' + JSON.stringify(redisData),
+            );
             this.onSteaming = true;
             this.holdSteam();
             if (redisData && 'mediaSrc' in redisData) {
@@ -1357,7 +1373,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
                 const src = mediaSrc.split('?')[0];
                 const clipPath = this.configService.get('app.prefix') + src;
                 delete redisData.mediaSrc;
-                this.logger.log(
+                this.logger.info(
                   `user:${this.user_id}:first render stream` +
                     JSON.stringify({ path: clipPath, meta: redisData }),
                 );
@@ -1416,7 +1432,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               false,
             );
             if (redisDataAuto) {
-              this.logger.log(`空白流::有数据:${frame}`);
+              this.logger.info(`空白流::有数据:${frame}`);
               'mediaSrc' in redisDataAuto && delete redisDataAuto.mediaSrc;
               const streamMeta: StreamMetaType = {
                 frame: frame,
@@ -1425,7 +1441,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               this.streamService.pushMetaDataToSteam(streamMeta);
             } else {
               this.stopStream();
-              this.logger.log('空流无Redis数据');
+              this.logger.info('空流无Redis数据');
             }
           }
         } catch (error) {