gemercheung 3 yıl önce
ebeveyn
işleme
b9e8a83b73
1 değiştirilmiş dosya ile 27 ekleme ve 22 silme
  1. 27 22
      src/scene/scene.service.ts

+ 27 - 22
src/scene/scene.service.ts

@@ -25,7 +25,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     private rotateService: RotateService,
     private moveService: MoveService,
     private getRouterService: GetRouterService, // @InjectQueue('rotate') private rotateQueue: Queue, // @InjectQueue('walking') private walkingQueue: Queue,
-  ) {}
+  ) { }
   @Client(grpcClientOptions) private readonly client: ClientGrpc;
 
   public _frameInteval: NodeJS.Timeout;
@@ -267,6 +267,12 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const metaData: StreamReplyType = JSON.parse(
           lastStreamFrame.metaData,
         ) as any as StreamReplyType;
+
+        //判断request是否是新的
+        if (metaData.traceIds.indexOf(request.trace_id) > -1) {
+          return;
+        }
+
         const newUserStates: NewUserStatesType = metaData.newUserStates.find(
           (item) => item.userId === this.user_id,
         );
@@ -443,7 +449,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         }
 
         // 二维数组 做move 序列, move类型
-        console.log('move-walkingRes:'+JSON.stringify(walkingRes));
+        console.log('move-walkingRes:' + JSON.stringify(walkingRes));
         if (walkingRes && walkingRes?.length >= 1) {
           for (let i = 1; i < walkingRes.length; i++) {
             Array.from(walkingRes[i]).forEach(
@@ -470,7 +476,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const seqs = Array.from(walkingRes).flat() as any as StreamReplyType[];
 
         if (seqs?.length) {
-          this.logger.log('walking --总序列--seqs-2:'+ seqs.length);
+          this.logger.log('walking --总序列--seqs-2:' + seqs.length);
           const stop = performance.now();
           const inMillSeconds = stop - start;
           const rounded = Number(inMillSeconds).toFixed(3);
@@ -523,7 +529,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       const joystickRes = await this.moveService.seqExeJoystick(request);
       this.logger.log(
         'joystick-breakPointId:' +
-          this.moveService.users[this.user_id].breakPointId,
+        this.moveService.users[this.user_id].breakPointId,
       );
       // 有数据 [0]是rotate数据,[1-infinity]是walking数据
       this.logger.log('joystickRes-1', joystickRes);
@@ -685,14 +691,14 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         };
         this.logger.log(
           '[media-move]: ' +
-            ', moveframeCnt: ' +
-            this.moveframeCnt +
-            ', clipPath: ' +
-            stream.clipPath +
-            ', mType: ' +
-            stream.mType +
-            ', DIR: ' +
-            stream.DIR,
+          ', moveframeCnt: ' +
+          this.moveframeCnt +
+          ', clipPath: ' +
+          stream.clipPath +
+          ', mType: ' +
+          stream.mType +
+          ', DIR: ' +
+          stream.DIR,
           // stream.metaData,
         );
         this.logger.log(
@@ -771,7 +777,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           }
         } else {
           const msg: RTCMessageRequest = JSON.parse(message);
-          console.log('msg.action_type:'+msg.action_type);
+          console.log('msg.action_type:' + msg.action_type);
           switch (msg.action_type) {
             case ActionType.walk:
               const walk = msg as any as MoveRequest;
@@ -872,8 +878,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
           const IDRflag = this._rotateCurrentFame % 5 === 0 ? 1 : 3;
           this.logger.log(
-            `当前rotate ,mainframeCnt:${this.frameCnt.getValue()}, _rotateCurrentFame:${
-              this._rotateCurrentFame
+            `当前rotate ,mainframeCnt:${this.frameCnt.getValue()}, _rotateCurrentFame:${this._rotateCurrentFame
             } IDRflag:${IDRflag}`,
           );
           stream.DIR = this.rotateFirstIDR ? 1 : IDRflag;
@@ -884,12 +889,12 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
           this.logger.log(
             '[media-rotate]: ' +
-              ', frame: ' +
-              stream.frame +
-              ', rotateframeCnt: ' +
-              this.rotateframeCnt +
-              ', clipPath: ' +
-              stream.clipPath,
+            ', frame: ' +
+            stream.frame +
+            ', rotateframeCnt: ' +
+            this.rotateframeCnt +
+            ', clipPath: ' +
+            stream.clipPath,
             // stream.metaData,
           );
           // this.logger.log(
@@ -960,7 +965,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
                 delete redisData.mediaSrc;
                 this.logger.log(
                   `user:${this.user_id}:first render stream` +
-                    JSON.stringify({ path: clipPath, meta: redisData }),
+                  JSON.stringify({ path: clipPath, meta: redisData }),
                 );
                 const status = await this.pushFirstRender(
                   clipPath,