gemercheung 3 jaren geleden
bovenliggende
commit
370c8461fc
3 gewijzigde bestanden met toevoegingen van 487 en 409 verwijderingen
  1. 8 3
      src/get-router/get-router.service.ts
  2. 255 247
      src/move/move.service.ts
  3. 224 159
      src/scene/scene.service.ts

+ 8 - 3
src/get-router/get-router.service.ts

@@ -58,9 +58,9 @@ export class GetRouterService implements OnModuleInit {
       for (const key in this.breakPointInfo) {
         //const breakPointRes = await this.cacheService.get(keys[i]);
         //const breakPoint = JSON.parse(breakPointRes);
-        if (Number(key) == startPointId) {
-          continue;
-        }
+        // if (Number(key) == startPointId) {
+        //   continue;
+        // }
         //const position = breakPoint.position;
         const breakPoint = this.breakPointInfo[key];
         if (minDis == null) {
@@ -80,6 +80,11 @@ export class GetRouterService implements OnModuleInit {
         return null;
       }
 
+      if (startPointId == endPoint.breakPointId) {
+        console.log('点击的点和当前点是同一个点');
+        return null;
+      }
+
       // const startPointRes = await this.cacheService.get(
       //   'breakpoints:app_id:' + appId + ':break_point_id:' + startPointId,
       // );

+ 255 - 247
src/move/move.service.ts

@@ -48,7 +48,7 @@ export class MoveService implements OnModuleInit {
     traceIds: [],
     vehicle: null,
     mediaSrc: null,
-    moveOver: false,
+    //moveOver: false,
     moveStart: false,
     newUserStates: [
       {
@@ -214,10 +214,6 @@ export class MoveService implements OnModuleInit {
     end_break_point_id,
     angleIndex,
   ) {
-    if (angleIndex < 0) {
-      debugger;
-    }
-
     let moveFramesRes, moveFrames;
     let key =
       'moveframe:app_id:' +
@@ -256,7 +252,6 @@ export class MoveService implements OnModuleInit {
       const traceId = actionRequest['trace_id'];
       const actionType = actionRequest['action_type'];
       const user = this.users[userId];
-
       const appId = user.appId;
       const path = pathArray || [100, 101, 102]; //需要计算路径
       const angle = user.camera.angle.yaw % 45; //纠正需要
@@ -868,171 +863,70 @@ export class MoveService implements OnModuleInit {
   // }
 
   async joystick(actionRequest) {
-    //try {
-
-    if (this.sendingFrameForJoystick) {
-      return null;
-    }
-
-    const userId = actionRequest['user_id'];
-    const traceId = actionRequest['trace_id'];
-    const dir_action = actionRequest['dir_action'];
-    const actionType = actionRequest['action_type'];
-    const user = this.users[userId];
-    const breakPointId = user.breakPointId;
-    const appId = user.appId;
-    //const step = 0.3;
-    const step = 0.8;
-    const closestDis = 80; //小于这个距离就跳到邻居呼吸点
-    const distance = step * dir_action.speed_level;
-    let angle = null;
-    if (dir_action.move_angle < 0 || user.camera.angle.yaw < 0) {
-      debugger;
-    }
-
-    let move_angle = dir_action.move_angle + user.camera.angle.yaw;
-    move_angle = move_angle % 360;
-
-    //TODO 临时增加断言
-    const playerPosition: Point = { x: 0, y: 0, z: 0 };
-    playerPosition.x =
-      user.player.position.x +
-      distance * Math.cos((move_angle / 360) * 2 * Math.PI);
-    playerPosition.y =
-      user.player.position.y +
-      distance * Math.sin((move_angle / 360) * 2 * Math.PI);
-
-    //找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
-    let chooseBreakPointId = null;
-    const breakPoint = this.breakPointInfo[breakPointId];
-    const surroundPointIds = breakPoint.contact;
-    const traceIds = [];
-
-    user.player.angle.yaw = move_angle;
-    traceIds.push(traceId);
-    this.reply.traceIds = traceIds;
-    this.reply['newUserStates'][0].userId = userId;
-    this.reply['actionResponses'][0].traceId = traceId;
-    this.reply['newUserStates'][0].playerState.player.angle.yaw = move_angle;
+    try {
+      if (this.sendingFrameForJoystick) {
+        return null;
+      }
 
-    this.reply['newUserStates'][0].playerState.camera.angle = JSON.parse(
-      JSON.stringify(user.camera.angle),
-    );
-    this.reply['newUserStates'][0].playerState.camera.position = JSON.parse(
-      JSON.stringify(user.camera.position),
-    );
-    this.reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(
-      JSON.stringify(breakPoint.position),
-    );
-    this.reply['newUserStates'][0].renderInfo.isMoving = 1;
-    this.reply['actionResponses'][0].traceId = traceId;
-    this.reply.mediaSrc = null;
+      const userId = actionRequest['user_id'];
+      const traceId = actionRequest['trace_id'];
+      const dir_action = actionRequest['dir_action'];
+      const actionType = actionRequest['action_type'];
+      const user = this.users[userId];
+      const breakPointId = user.breakPointId;
+      const appId = user.appId;
+      //const step = 0.3;
+      const step = 0.8;
+      const closestDis = 80; //小于这个距离就跳到邻居呼吸点
+      const distance = step * dir_action.speed_level;
+      let angle = null;
+      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;
+
+      //TODO 临时增加断言
+      const playerPosition: Point = { x: 0, y: 0, z: 0 };
+      playerPosition.x =
+        user.player.position.x +
+        distance * Math.cos((move_angle / 360) * 2 * Math.PI);
+      playerPosition.y =
+        user.player.position.y +
+        distance * Math.sin((move_angle / 360) * 2 * Math.PI);
+
+      //找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
+      let chooseBreakPointId = null;
+      const breakPoint = this.breakPointInfo[breakPointId];
+      const surroundPointIds = breakPoint.contact;
+      const traceIds = [];
 
-    console.log('joystickjoystick:' + this.cameraInfos.length);
+      user.player.angle.yaw = move_angle;
+      traceIds.push(traceId);
+      this.reply.traceIds = traceIds;
+      this.reply['newUserStates'][0].userId = userId;
+      this.reply['actionResponses'][0].traceId = traceId;
+      this.reply['newUserStates'][0].playerState.player.angle.yaw = move_angle;
 
-    if (surroundPointIds.length == 1) {
-      // console.log(
-      //   'joystick校验--->' + breakPointId + '-' + surroundPointIds[0],
-      // );
-      console.log(
-        'handlejoysticktesttest:actionRequest-笔直' + new Date().getTime(),
+      this.reply['newUserStates'][0].playerState.camera.angle = JSON.parse(
+        JSON.stringify(user.camera.angle),
       );
-      return await this.moveDirect(
-        playerPosition,
-        closestDis,
-        breakPointId,
-        surroundPointIds[0],
-        appId,
-        userId,
-        traceId,
-        actionType,
+      this.reply['newUserStates'][0].playerState.camera.position = JSON.parse(
+        JSON.stringify(user.camera.position),
       );
-    }
-
-    let count = 0;
-    const neighPoints = [];
-    //人在哪个角度
-    const _angle = this.getAngle(
-      breakPoint.position,
-      { x: breakPoint.position.x + 1, y: breakPoint.position.y },
-      playerPosition,
-    );
-
-    let singleInfo = null;
-    for (let i = 0; i < surroundPointIds.length; ++i) {
-      const neighPoint = this.breakPointInfo[surroundPointIds[i]];
-      neighPoint.breakPointId = surroundPointIds[i];
-      angle = this.getAngle(
-        breakPoint.position,
-        { x: breakPoint.position.x + 1, y: breakPoint.position.y },
-        neighPoint.position,
+      this.reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(
+        JSON.stringify(breakPoint.position),
       );
+      this.reply['newUserStates'][0].renderInfo.isMoving = 1;
+      this.reply['actionResponses'][0].traceId = traceId;
+      this.reply.mediaSrc = null;
 
-      //if(angle<45&&angle!=0){
-      if (
-        // Math.abs(angle - move_angle) < 45 &&
-        // Math.abs(angle - move_angle) != 0
-        Math.abs(angle - _angle) < 45 &&
-        Math.abs(angle - _angle) != 0
-      ) {
-        neighPoint.angle = angle;
-        neighPoints.push(neighPoint);
-        ++count;
-      } else if (Math.abs(angle - move_angle) == 0) {
-        neighPoint.angle = angle;
-        neighPoints.push(neighPoint);
-        ++count;
-        //console.log('handlejoysticktesttest:45°的倍数');
-        //debugger;
-        break;
-
-        // console.log(
-        //   'joystick直走--->' + breakPointId + '-' + surroundPointIds[i],
-        // );
-        // return await this.moveDirect(
-        //   playerPosition,
-        //   closestDis,
-        //   breakPointId,
-        //   surroundPointIds[i],
-        //   appId,
-        //   userId,
-        //   traceId,
-        //   actionType,
-        // );
-      }
-
-      //if (angle == 0 && Math.abs(360 - move_angle) < 45) {
-      if (angle == 0 && Math.abs(360 - _angle) < 45) {
-        neighPoint.angle = angle;
-        neighPoints.push(neighPoint);
-        ++count;
-      }
-
-      if (
-        Math.abs(angle - move_angle) < 45 ||
-        Math.abs(angle + 360 - move_angle) < 45
-      ) {
-        if (singleInfo == null) {
-          singleInfo = {
-            angle: angle,
-            breakPointId: surroundPointIds[i],
-          };
-        }
-      }
-    }
+      console.log('joystickjoystick:' + this.cameraInfos.length);
 
-    if (count == 2) {
-      //人物移动
-      user.player.position = JSON.parse(JSON.stringify(playerPosition));
-      this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
-        JSON.stringify(playerPosition),
-      );
-    } else {
-      if (singleInfo != null) {
+      if (surroundPointIds.length == 1) {
         // console.log(
-        //   'joystick校验--->' + breakPointId + '-' + singleInfo.breakPointId,
+        //   'joystick校验--->' + breakPointId + '-' + surroundPointIds[0],
         // );
-        //console.log('handlejoysticktesttest校验0角度:'+_angle+','+move_angle)       //这个没办法,得换方案
         console.log(
           'handlejoysticktesttest:actionRequest-笔直' + new Date().getTime(),
         );
@@ -1040,112 +934,213 @@ export class MoveService implements OnModuleInit {
           playerPosition,
           closestDis,
           breakPointId,
-          singleInfo.breakPointId,
+          surroundPointIds[0],
           appId,
           userId,
           traceId,
           actionType,
         );
-      } else if (count == 1) {
+      }
+
+      let count = 0;
+      const neighPoints = [];
+      //人在哪个角度
+      const _angle = this.getAngle(
+        breakPoint.position,
+        { x: breakPoint.position.x + 1, y: breakPoint.position.y },
+        playerPosition,
+      );
+
+      let singleInfo = null;
+      for (let i = 0; i < surroundPointIds.length; ++i) {
+        const neighPoint = this.breakPointInfo[surroundPointIds[i]];
+        neighPoint.breakPointId = surroundPointIds[i];
+        angle = this.getAngle(
+          breakPoint.position,
+          { x: breakPoint.position.x + 1, y: breakPoint.position.y },
+          neighPoint.position,
+        );
+
+        //if(angle<45&&angle!=0){
+        if (
+          // Math.abs(angle - move_angle) < 45 &&
+          // Math.abs(angle - move_angle) != 0
+          Math.abs(angle - _angle) < 45 &&
+          Math.abs(angle - _angle) != 0
+        ) {
+          neighPoint.angle = angle;
+          neighPoints.push(neighPoint);
+          ++count;
+        } else if (Math.abs(angle - move_angle) == 0) {
+          neighPoint.angle = angle;
+          neighPoints.push(neighPoint);
+          ++count;
+          //console.log('handlejoysticktesttest:45°的倍数');
+          //debugger;
+          break;
+
+          // console.log(
+          //   'joystick直走--->' + breakPointId + '-' + surroundPointIds[i],
+          // );
+          // return await this.moveDirect(
+          //   playerPosition,
+          //   closestDis,
+          //   breakPointId,
+          //   surroundPointIds[i],
+          //   appId,
+          //   userId,
+          //   traceId,
+          //   actionType,
+          // );
+        }
+
+        //if (angle == 0 && Math.abs(360 - move_angle) < 45) {
+        if (angle == 0 && Math.abs(360 - _angle) < 45) {
+          neighPoint.angle = angle;
+          neighPoints.push(neighPoint);
+          ++count;
+        }
+
+        if (
+          Math.abs(angle - move_angle) < 45 ||
+          Math.abs(angle + 360 - move_angle) < 45
+        ) {
+          if (singleInfo == null) {
+            singleInfo = {
+              angle: angle,
+              breakPointId: surroundPointIds[i],
+            };
+          }
+        }
+      }
+
+      if (count == 2) {
+        //人物移动
+        user.player.position = JSON.parse(JSON.stringify(playerPosition));
+        this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
+          JSON.stringify(playerPosition),
+        );
+      } 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,
+            breakPointId,
+            singleInfo.breakPointId,
+            appId,
+            userId,
+            traceId,
+            actionType,
+          );
+        } else if (count == 1) {
+          // console.log(
+          //   'joystick校验--->' + breakPointId + '-' + neighPoints[0].breakPointId,
+          // );
+          console.log(
+            'handlejoysticktesttest:actionRequest-笔直' + new Date().getTime(),
+          );
+          return await this.moveDirect(
+            playerPosition,
+            closestDis,
+            breakPointId,
+            neighPoints[0].breakPointId,
+            appId,
+            userId,
+            traceId,
+            actionType,
+          );
+        } else if (count == 0) {
+          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;
+        }
+      }
+
+      //count == 2
+      //超出范围了
+      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;
+        }
         // console.log(
-        //   'joystick校验--->' + breakPointId + '-' + neighPoints[0].breakPointId,
+        //   'joystick镜头过渡--->' + breakPointId + '-' + chooseBreakPointId,
         // );
-        console.log(
-          'handlejoysticktesttest:actionRequest-笔直' + new Date().getTime(),
-        );
-        return await this.moveDirect(
-          playerPosition,
-          closestDis,
+        //this.reply.moveOver = true;
+        return await this.moveCamera(
           breakPointId,
-          neighPoints[0].breakPointId,
+          chooseBreakPointId,
           appId,
           userId,
           traceId,
           actionType,
         );
-      } else if (count == 0) {
+      } else {
+        user.player.position = JSON.parse(JSON.stringify(playerPosition));
         this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
           JSON.stringify(user.player.position),
         );
         this.reply.actionResponses[0].actionType = actionType;
+        const cameraInfo = this.getCameraInfo();
+        if (cameraInfo != null) {
+          console.log('joystick自由--->合并');
+          this.reply['newUserStates'][0].playerState.camera.position =
+            cameraInfo.camera_position;
+          this.reply['newUserStates'][0].playerState.camera.angle =
+            cameraInfo.camera_angle;
+
+          if (cameraInfo.mediaSrc) {
+            this.reply.mediaSrc = cameraInfo.mediaSrc;
+            if (this.cameraInfos.length == 0) {
+              this.reply.moveStart = true;
+            } else {
+              this.reply.moveStart = false;
+            }
+          }
+          // if (this.cameraInfos.length == 0) {
+          //   this.reply.moveOver = true;
+          // }
+
+          user.camera.position = JSON.parse(
+            JSON.stringify(cameraInfo.camera_position),
+          );
+          user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
+
+          this.sendingFrameForJoystick = true;
+        } else {
+          console.log('joystick自由--->不合并');
+        }
         console.log(
-          'handlejoysticktesttest:actionRequest-停止' + new Date().getTime(),
+          'handlejoysticktesttest:actionRequest-自由' + new Date().getTime(),
         );
         return this.reply;
       }
+    } catch (error) {
+      console.log('MoveService', error);
+      return null;
     }
-
-    //count == 2
-    //超出范围了
-    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;
-      }
-      // console.log(
-      //   'joystick镜头过渡--->' + breakPointId + '-' + chooseBreakPointId,
-      // );
-      //this.reply.moveOver = true;
-      return await this.moveCamera(
-        breakPointId,
-        chooseBreakPointId,
-        appId,
-        userId,
-        traceId,
-        actionType,
-      );
-    } else {
-      user.player.position = JSON.parse(JSON.stringify(playerPosition));
-      this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
-        JSON.stringify(user.player.position),
-      );
-      this.reply.actionResponses[0].actionType = actionType;
-      const cameraInfo = this.getCameraInfo();
-      if (cameraInfo != null) {
-        console.log('joystick自由--->合并');
-        this.reply['newUserStates'][0].playerState.camera.position =
-          cameraInfo.camera_position;
-        this.reply['newUserStates'][0].playerState.camera.angle =
-          cameraInfo.camera_angle;
-
-        if (cameraInfo.mediaSrc) {
-          this.reply.mediaSrc = cameraInfo.mediaSrc;
-        }
-        // if (this.cameraInfos.length == 0) {
-        //   this.reply.moveOver = true;
-        // }
-
-        user.camera.position = JSON.parse(
-          JSON.stringify(cameraInfo.camera_position),
-        );
-        user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
-
-        this.sendingFrameForJoystick = true;
-      } else {
-        console.log('joystick自由--->不合并');
-      }
-      console.log(
-        'handlejoysticktesttest:actionRequest-自由' + new Date().getTime(),
-      );
-      return this.reply;
-    }
-    // }
-    // catch (error) {
-    //   console.log('MoveService', error);
-    //   debugger;
-    //   return null;
-    // }
   }
 
   //沿着最合适的neighBreakPointId走
@@ -1200,6 +1195,11 @@ export class MoveService implements OnModuleInit {
 
         if (cameraInfo.mediaSrc) {
           this.reply.mediaSrc = cameraInfo.mediaSrc;
+          if (this.cameraInfos.length == 0) {
+            this.reply.moveStart = true;
+          } else {
+            this.reply.moveStart = false;
+          }
         }
         // if (this.cameraInfos.length == 0) {
         //   this.reply.moveOver = true;
@@ -1300,8 +1300,8 @@ export class MoveService implements OnModuleInit {
 
         if (cameraInfo.mediaSrc) {
           this.reply.mediaSrc = cameraInfo.mediaSrc;
+          this.reply.moveStart = true;
         }
-        this.reply.moveStart = true;
         this.sendingFrameForJoystick = true;
       }
       console.log(
@@ -1369,7 +1369,10 @@ export class MoveService implements OnModuleInit {
   complementFrame(userId) {
     if (this.cameraInfos.length > 0) {
       console.log(
-        'handlejoysticktesttest:complementFrame-1 继续' + new Date().getTime(),
+        'handlejoysticktesttest:complementFrame-1 继续' +
+          userId +
+          ',' +
+          new Date().getTime(),
       );
       const user = this.users[userId];
       const cameraInfo = this.cameraInfos.shift();
@@ -1396,6 +1399,11 @@ export class MoveService implements OnModuleInit {
 
       if (cameraInfo.mediaSrc) {
         this.reply.mediaSrc = cameraInfo.mediaSrc;
+        if (this.cameraInfos.length == 0) {
+          this.reply.moveStart = true;
+        } else {
+          this.reply.moveStart = false;
+        }
       }
 
       user.camera.position = JSON.parse(

+ 224 - 159
src/scene/scene.service.ts

@@ -83,6 +83,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   private latestBreakPointId: number;
   private isHoldingStream = false;
   private lastMovingPointArray: MovingLastUpdateType[] = [];
+  private latestRotateRequest: any; // 最新Rotate的接收值
   private latestWalkingRequest: any; // 最新waking的接收值
   private hasJoystickMoveRequest = false; // 最新joystick的接收值
 
@@ -208,24 +209,21 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   async rotate(request: RotateRequest) {
     if (this.isHasWalkingJoints()) {
       this.globalOptLock = true;
+    } else {
+      console.log('开锁rotate或正常rotate');
     }
-
-    if (
-      this.onMoving.getValue() &&
-      this.globalOptLock &&
-      // this._rotateCount > 5 &&
-      !this.rotateStopThrottle
-    ) {
-      this.handleRotateStop(request);
-      debugger;
-    }
+    this.latestRotateRequest = request;
+    // if (
+    //   this.onMoving.getValue() &&
+    //   this.globalOptLock &&
+    //   // this._rotateCount > 5 &&
+    //   !this.rotateStopThrottle
+    // ) {
+    //   this.handleRotateStop(request);
+    //   // debugger;
+    // }
     this.handleRotate(request);
     this._rotateCount += 1;
-    //this.logger.log('request', request)
-    // this.roRequestQueue.next(request);
-    // if (!this.roRequestQueueSub) {
-    //   this.handleRotate();
-    // }
   }
   /**
    * rotate请求队列
@@ -234,7 +232,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   async handleRotate(request) {
     // try {
     const rotateKey = this.firstRender && !this.globalOptLock;
-    console.log('handleRotate条件--->' + rotateKey);
+    console.log('handleRotate条件--->' + rotateKey, this.globalOptLock);
 
     if (rotateKey) {
       if (!this.roQueueSubscription) {
@@ -295,16 +293,90 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   }
 
   /**
+   * rotate 推送队列
+   */
+  handleRotateStream() {
+    if (!this.roQueueSubscription) {
+      this.roQueueSubscription = this.roQueue.subscribe(
+        async (stream: StreamFrameType) => {
+          this.rotateTimeStamp = Date.now();
+          if (this.rotateframeCnt === -1) {
+            this.rotateframeCnt = this.frameCnt.value;
+          }
+          this.rotateframeCnt += 1;
+
+          stream.frame = this.rotateframeCnt;
+          this._rotateCurrentFame += 1;
+
+          const IDRflag = this._rotateCurrentFame % 5 === 0 ? 1 : 3;
+          this.logger.log(
+            `当前rotate ,mainframeCnt:${this.frameCnt.getValue()}, _rotateCurrentFame:${this._rotateCurrentFame
+            } IDRflag:${IDRflag}`,
+          );
+          stream.DIR = this.rotateFirstIDR ? 1 : IDRflag;
+
+          if (this.rotateFirstIDR) {
+            this.rotateFirstIDR = false;
+          }
+
+          this.logger.log(
+            '[media-rotate]: ' +
+            ', frame: ' +
+            stream.frame +
+            ', rotateframeCnt: ' +
+            this.rotateframeCnt +
+            ', clipPath: ' +
+            stream.clipPath,
+            // stream.metaData,
+          );
+          // this.logger.log(
+          //   `roQueueSubscription:frame:${this.rotateframeCnt}  ` +
+          //   JSON.stringify(stream.metaData),
+          // );
+
+          const res = await this.streamService.pushFrameToSteam(stream);
+          if (res.done) {
+            clearTimeout(this._rotateTimeout);
+            this._rotateTimeout = setTimeout(() => {
+              this.logger.log('rotate end', Date.now());
+              this.frameCnt.next(res.frame);
+              this.rotateframeCnt = -1;
+              this._rotateCurrentFame = -1;
+              // this.onMoving.next(false);
+              // this.onRotating.next(false);
+              this.latestRotateRequest = null;
+              this.rotateFirstIDR = true;
+              this.resumeStream();
+              //TODO rotate完后清除request队列
+              if (this.roRequestQueueSub) {
+                this.roRequestQueueSub.unsubscribe();
+                this.roRequestQueueSub = null;
+              }
+            }, 50);
+          } else {
+            console.error('流地址有误::', res.frame, JSON.stringify(res));
+            this.logger.error('流地址有误::', res.frame, JSON.stringify(res));
+            this.resumeStream();
+          }
+        },
+      );
+    }
+  }
+
+  /**
    * 旋转中断逻辑
    * 1. 行走间
    * 1.1 行走间中断只能在每段最后一帧,当前段一定要消费掉,在未消费,globalOptLock锁rotate,消费完 rotate
    * 1.2 消费完要处理点位上传,清除当前段往后的都要清掉,回调各种stop function
    * 2.joystick间 complementFrame pools 解锁就可以
    */
-  async handleRotateStop(request) {
+  async handleRotateOrWalkingStop(request): Promise<boolean> {
     this.rotateStopThrottle = true;
     const lastStreamFrame = this.lastMoveStreamFrame.getValue();
-    this.logger.log('lastStreamFrame', JSON.stringify(lastStreamFrame));
+    this.logger.log(
+      'handleRotateOrWalkingStop-frame',
+      JSON.stringify(lastStreamFrame),
+    );
 
     const metaData: StreamReplyType = JSON.parse(
       lastStreamFrame.metaData,
@@ -315,7 +387,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     console.log('stop-5', request.trace_id);
     //判断request是否是新的
     if (metaData.traceIds.indexOf(request.trace_id) > -1) {
-      return;
+      return Promise.resolve(false);
     }
     console.log('currentUser-user_id', this.user_id);
     const newUserStates: NewUserStatesType = metaData.newUserStates.find(
@@ -350,9 +422,34 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       cameraAngle,
       playerAngle,
     );
-    this.logger.log('stop-redisMeta', redisMeta);
-    this.onMoving.next(false);
-    this.cleanMoveSteam();
+    this.logger.log('stop-redisMeta-frame', JSON.stringify(redisMeta));
+    if (redisMeta) {
+      const src = redisMeta.mediaSrc.split('?')[0];
+      const mediaSrc = this.configService.get('app.prefix') + src;
+      const streamData: StreamFrameType = {
+        frame: this.frameCnt.value + 1,
+        clipPath: mediaSrc,
+        metaData: JSON.stringify(redisMeta),
+        serverTime: this.mockserverTime,
+        DIR: 1,
+      };
+      //推最后一个STOPFrame
+      const hasPush = await this.streamService.pushFrameToSteam(streamData);
+      if (hasPush.done) {
+        this.frameCnt.next(hasPush.frame);
+        // this.onMoving.next(false);
+        // this.cleanMoveSteam();
+        return Promise.resolve(true);
+        // this.resumeStream();
+      } else {
+        console.error(
+          '暂停STOP::帧有问题',
+          hasPush.frame,
+          JSON.stringify(streamData),
+        );
+        return Promise.resolve(false);
+      }
+    }
   }
 
   /**
@@ -363,68 +460,104 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   async walking(request: MoveRequest) {
     this.latestWalkingRequest = request;
     this.logger.log('walking-trace_id', request.trace_id);
+
+    // if (this.isHasWalkingJoints()) {
+    //   console.log('lock-锁-walking', this.latestWalkingRequest);
+    //   this.globalOptLock = true;
+    // } 
+
     // 进入正常walking流程
     if (!this.onMoving.getValue()) {
       console.log('walking-step-main-1', request.trace_id);
       this.latestWalkingRequest = null;
       this.handleWalking(request);
+    } else {
+      this.globalOptLock = true;
+      console.log('lock-锁-walking', this.latestWalkingRequest);
     }
-    this.handleWalkingJoints(request);
+    this.handleWalkingJoints();
   }
   /**
    * 一段walking每个Joints关节点
    * @param request
    */
-  handleWalkingJoints(request) {
-    // 监听每小段最后一帧
+  handleWalkingJoints() {
+    // 每个关节点
     if (!this.moveSliceLastFrameSub) {
       this.moveSliceLastFrameSub = this.moveSliceLastFrame.subscribe(
         async (frame: MovingLastUpdateType) => {
           //TODO 正在行走时,有新的reqest
           if (frame) {
+            console.log('unlock-Joints', JSON.stringify(frame));
             this.logger.log('Joints', JSON.stringify(frame));
-            if (this.latestWalkingRequest && this.onMoving.value) {
-              this.logger.log('stop-data-1', frame);
-              this.moveQueueSubscription.unsubscribe();
-              this.moveQueueSubscription = null;
-              this.moveQueue.clean();
-              //step1 执行stop方法
-              const metaData: StreamReplyType = frame.metaData;
-              const newUserStates: NewUserStatesType =
-                metaData.newUserStates.find(
-                  (item) => item.userId === this.user_id,
+            // 在全局锁的情况下
+            if (this.globalOptLock) {
+              // 这个旋转暂停
+              // if (!!this.latestRotateRequest && this.onMoving.value) {
+              //   const hasStop = await this.handleRotateOrWalkingStop(
+              //     this.latestRotateRequest,
+              //   );
+              //   console.log('旋转-hasStop', hasStop);
+              //   this.clearWalkingJoints();
+              //   this.cleanMoveSteam();
+              //   this.globalOptLock = false;
+              // }
+              // 这个行走暂停
+              if (!!this.latestWalkingRequest && this.onMoving.value) {
+                const hasStop = await this.handleRotateOrWalkingStop(
+                  this.latestWalkingRequest,
                 );
-              const trace_id = metaData.traceIds[0];
-              const userId = newUserStates.userId;
-              const breakPointId = metaData.endBreakPointId;
-              const cameraAngle = newUserStates.playerState.camera.angle;
-              const playerAngle = newUserStates.playerState.player.angle;
-              this.logger.log(
-                'stop-data-2',
-                trace_id,
-                userId,
-                cameraAngle,
-                cameraAngle,
-              );
-              console.log('moveService.stop-2:' + breakPointId);
-              const redisMeta = await this.moveService.stop(
-                trace_id,
-                userId,
-                breakPointId,
-                cameraAngle,
-                playerAngle,
-              );
-              this.logger.log('stop-redisMeta', JSON.stringify(redisMeta));
-              // 2. 中断重新walking
-              console.log(
-                'walking-step-reWalking-1',
-                request.trace_id + ',' + this.latestWalkingRequest.trace_id,
-              );
-
-              this.logger.debug('重新行走---handleReWalking');
-              console.log('重新行走---handleReWalking');
-              this.handleReWalking(this.latestWalkingRequest);
+                console.log('walking-hasStop', hasStop);
+                this.clearWalkingJoints();
+                this.cleanMoveSteam();
+                this.globalOptLock = false;
+                console.log('unlock-walking');
+                this.handleReWalking(this.latestWalkingRequest);
+                // console.log('this', this.rewalking);
+              }
             }
+            // if (this.latestWalkingRequest && this.onMoving.value) {
+            //   this.logger.log('stop-data-1', frame);
+            //   this.moveQueueSubscription.unsubscribe();
+            //   this.moveQueueSubscription = null;
+            //   this.moveQueue.clean();
+            //   //step1 执行stop方法
+            //   const metaData: StreamReplyType = frame.metaData;
+            //   const newUserStates: NewUserStatesType =
+            //     metaData.newUserStates.find(
+            //       (item) => item.userId === this.user_id,
+            //     );
+            //   const trace_id = metaData.traceIds[0];
+            //   const userId = newUserStates.userId;
+            //   const breakPointId = metaData.endBreakPointId;
+            //   const cameraAngle = newUserStates.playerState.camera.angle;
+            //   const playerAngle = newUserStates.playerState.player.angle;
+            //   this.logger.log(
+            //     'stop-data-2',
+            //     trace_id,
+            //     userId,
+            //     cameraAngle,
+            //     cameraAngle,
+            //   );
+            //   console.log('moveService.stop-2:' + breakPointId);
+            //   const redisMeta = await this.moveService.stop(
+            //     trace_id,
+            //     userId,
+            //     breakPointId,
+            //     cameraAngle,
+            //     playerAngle,
+            //   );
+            //   this.logger.log('stop-redisMeta', JSON.stringify(redisMeta));
+            //   // 2. 中断重新walking
+            //   console.log(
+            //     'walking-step-reWalking-1',
+            //     request.trace_id + ',' + this.latestWalkingRequest.trace_id,
+            //   );
+
+            //   this.logger.debug('重新行走---handleReWalking');
+            //   console.log('重新行走---handleReWalking');
+            //   this.handleReWalking(this.latestWalkingRequest);
+            // }
           }
         },
       );
@@ -559,7 +692,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
    * @param request MoveRequest
    */
   handleReWalking(request: MoveRequest) {
-    this.latestWalkingRequest = null;
+    // this.latestWalkingRequest = null;
     this.rewalking = true;
     this.handleWalking(request);
   }
@@ -780,27 +913,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     });
   }
 
-  cleanMoveSteam() {
-    this.moveQueue.clean();
-    if (this.moveQueueSubscription) {
-      this.moveQueueSubscription.unsubscribe();
-      this.moveQueueSubscription = null;
-    }
-    if (this.walkingSub) {
-      this.walkingSub.unsubscribe();
-      this.walkingSub = null;
-    }
-    if (this.moveSliceLastFrameSub) {
-      this.lastMoveStreamFrame.next(null);
-      this.moveSliceLastFrameSub.unsubscribe();
-      this.moveSliceLastFrameSub = null;
-    }
-    // if (this.clickQueueSub) {
-    //   this.clickQueueSub.unsubscribe();
-    //   this.clickQueueSub = null;
-    // }
-    this.rotateStopThrottle = false;
-  }
+
   handleMoveSteam() {
     this.moveQueueSubscription = this.moveQueue.subscribe(
       async (stream: StreamFrameType) => {
@@ -870,7 +983,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               this.lastMovingPointArray = [];
               this.hasJoystickMoveRequest = false;
               this.cleanMoveSteam();
-              // this.globalOptLock = false;
+              this.globalOptLock = false;
               this.resumeStream();
               this.logger.log('move end');
             }, 200);
@@ -888,6 +1001,28 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     );
   }
 
+  cleanMoveSteam() {
+    this.moveQueue.clean();
+    if (this.moveQueueSubscription) {
+      this.moveQueueSubscription.unsubscribe();
+      this.moveQueueSubscription = null;
+    }
+    if (this.walkingSub) {
+      this.walkingSub.unsubscribe();
+      this.walkingSub = null;
+    }
+    if (this.moveSliceLastFrameSub) {
+      this.lastMoveStreamFrame.next(null);
+      this.moveSliceLastFrameSub.unsubscribe();
+      this.moveSliceLastFrameSub = null;
+    }
+    // if (this.clickQueueSub) {
+    //   this.clickQueueSub.unsubscribe();
+    //   this.clickQueueSub = null;
+    // }
+    this.rotateStopThrottle = false;
+  }
+
   handleDataChanelOpen(channel: DataChannel, peer: PeerConnection): void {
     this.channel = channel;
     this.peer = peer;
@@ -920,7 +1055,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           const msg: RTCMessageRequest = JSON.parse(parseData);
           this.logger.error('lostIframe-message', JSON.stringify(msg));
           if (Number(msg.MstType) === 0) {
-            this.handleIframeRequest();
+            // this.handleIframeRequest();
           }
         } else {
           const msg: RTCMessageRequest = JSON.parse(message);
@@ -1007,76 +1142,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       this.logger.error('updateUserStatus::function', error.message);
     }
   }
-  /**
-   * rotate 推送队列
-   */
-  handleRotateStream() {
-    if (!this.roQueueSubscription) {
-      this.roQueueSubscription = this.roQueue.subscribe(
-        async (stream: StreamFrameType) => {
-          this.rotateTimeStamp = Date.now();
-          if (this.rotateframeCnt === -1) {
-            this.rotateframeCnt = this.frameCnt.value;
-          }
-          this.rotateframeCnt += 1;
-
-          stream.frame = this.rotateframeCnt;
-          this._rotateCurrentFame += 1;
-
-          const IDRflag = this._rotateCurrentFame % 5 === 0 ? 1 : 3;
-          this.logger.log(
-            `当前rotate ,mainframeCnt:${this.frameCnt.getValue()}, _rotateCurrentFame:${this._rotateCurrentFame
-            } IDRflag:${IDRflag}`,
-          );
-          stream.DIR = this.rotateFirstIDR ? 1 : IDRflag;
-
-          if (this.rotateFirstIDR) {
-            this.rotateFirstIDR = false;
-          }
-
-          this.logger.log(
-            '[media-rotate]: ' +
-            ', frame: ' +
-            stream.frame +
-            ', rotateframeCnt: ' +
-            this.rotateframeCnt +
-            ', clipPath: ' +
-            stream.clipPath,
-            // stream.metaData,
-          );
-          // this.logger.log(
-          //   `roQueueSubscription:frame:${this.rotateframeCnt}  ` +
-          //   JSON.stringify(stream.metaData),
-          // );
-
-          const res = await this.streamService.pushFrameToSteam(stream);
-          if (res.done) {
-            clearTimeout(this._rotateTimeout);
-            this._rotateTimeout = setTimeout(() => {
-              this.logger.log('rotate end', Date.now());
-              this.frameCnt.next(res.frame);
-              this.resumeStream();
-              this.rotateframeCnt = -1;
-              this._rotateCurrentFame = -1;
-              this.onMoving.next(false);
-              this.onRotating.next(false);
-              this.rotateFirstIDR = true;
-              //TODO rotate完后清除request队列
-              if (this.roRequestQueueSub) {
-                this.roRequestQueueSub.unsubscribe();
-                this.roRequestQueueSub = null;
-              }
-              this.moveQueue.clean();
-            }, 50);
-          } else {
-            console.error('流地址有误::', res.frame, JSON.stringify(res));
-            this.logger.error('流地址有误::', res.frame, JSON.stringify(res));
-            this.resumeStream();
-          }
-        },
-      );
-    }
-  }
 
   pushFirstRender(clipPath: string, metaData: string): Promise<boolean> {
     return new Promise<boolean>(async (resolve, reject) => {