فهرست منبع

减少clicksub

gemercheung 3 سال پیش
والد
کامیت
98277ff9ca
1فایلهای تغییر یافته به همراه45 افزوده شده و 38 حذف شده
  1. 45 38
      src/scene/scene.service.ts

+ 45 - 38
src/scene/scene.service.ts

@@ -25,7 +25,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     private rotateService: RotateService,
     private rotateService: RotateService,
     private moveService: MoveService,
     private moveService: MoveService,
     private getRouterService: GetRouterService, // @InjectQueue('rotate') private rotateQueue: Queue, // @InjectQueue('walking') private walkingQueue: Queue,
     private getRouterService: GetRouterService, // @InjectQueue('rotate') private rotateQueue: Queue, // @InjectQueue('walking') private walkingQueue: Queue,
-  ) {}
+  ) { }
   @Client(grpcClientOptions) private readonly client: ClientGrpc;
   @Client(grpcClientOptions) private readonly client: ClientGrpc;
 
 
   public _frameInteval: NodeJS.Timeout;
   public _frameInteval: NodeJS.Timeout;
@@ -55,6 +55,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   private moveQueueSubscription: any;
   private moveQueueSubscription: any;
   private walkingSub: any;
   private walkingSub: any;
   private joystickSub: any;
   private joystickSub: any;
+  private clickQueueSub: any;
 
 
   private streamServiceSub: any;
   private streamServiceSub: any;
   private roQueue: RxQueue = new DelayQueue(40);
   private roQueue: RxQueue = new DelayQueue(40);
@@ -301,45 +302,47 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   async walking(req) {
   async walking(req) {
     try {
     try {
       this.clickQueue.next(req);
       this.clickQueue.next(req);
-      this.walkingSub = this.clickQueue.subscribe(async (request) => {
-        const user = this.moveService.users[this.user_id];
-        const path = await this.getRouterService.searchRoad(
-          user.appId,
-          user.breakPointId,
-          req.clicking_action.clicking_point,
-        );
-        const walkingRes = await this.moveService.move(path, request);
+      if (!this.clickQueueSub) {
+        this.clickQueueSub = this.clickQueue.subscribe(async (request) => {
+          const user = this.moveService.users[this.user_id];
+          const path = await this.getRouterService.searchRoad(
+            user.appId,
+            user.breakPointId,
+            req.clicking_action.clicking_point,
+          );
+          const walkingRes = await this.moveService.move(path, request);
 
 
-        // console.log('walkingRes-front', walkingRes);
-        if (walkingRes && !this.onMoving.value) {
           // console.log('walkingRes-front', walkingRes);
           // console.log('walkingRes-front', walkingRes);
-          // shift出前第一个镜头数据
-          const rotateCamData = walkingRes.shift();
-          if (rotateCamData?.length) {
-            rotateCamData.forEach((item: StreamReplyType) => {
-              item.type = 'rotate';
-            });
-          } else {
-            console.log('rotateCamData无数据');
-          }
-          // walkingRes marker to everybody
-          const seqs = Array.from(
-            walkingRes,
-          ).flat() as any as StreamReplyType[];
-
-          if (seqs?.length) {
-            const lastSeq = rotateCamData?.length
-              ? (Array.from(rotateCamData).concat(
+          if (walkingRes && !this.onMoving.value) {
+            // console.log('walkingRes-front', walkingRes);
+            // shift出前第一个镜头数据
+            const rotateCamData = walkingRes.shift();
+            if (rotateCamData?.length) {
+              rotateCamData.forEach((item: StreamReplyType) => {
+                item.type = 'rotate';
+              });
+            } else {
+              console.log('rotateCamData无数据');
+            }
+            // walkingRes marker to everybody
+            const seqs = Array.from(
+              walkingRes,
+            ).flat() as any as StreamReplyType[];
+
+            if (seqs?.length) {
+              const lastSeq = rotateCamData?.length
+                ? (Array.from(rotateCamData).concat(
                   seqs,
                   seqs,
                 ) as any as StreamReplyType[])
                 ) as any as StreamReplyType[])
-              : seqs;
-            this.handleSeqMoving(lastSeq);
-          } else {
-            console.error('walking-move无数据');
+                : seqs;
+              this.handleSeqMoving(lastSeq);
+            } else {
+              console.error('walking-move无数据');
+            }
+            // this.lastMoveCnt = this.frameCnt.value + seqs.length;
           }
           }
-          // this.lastMoveCnt = this.frameCnt.value + seqs.length;
-        }
-      });
+        });
+      }
     } catch (error) {
     } catch (error) {
       this.logger.error('walking', error);
       this.logger.error('walking', error);
     }
     }
@@ -375,8 +378,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
                 console.log('joystickRes-seqs', seqs.length);
                 console.log('joystickRes-seqs', seqs.length);
                 const lastSeq = rotateCamData?.length
                 const lastSeq = rotateCamData?.length
                   ? (Array.from(rotateCamData).concat(
                   ? (Array.from(rotateCamData).concat(
-                      seqs,
-                    ) as any as StreamReplyType[])
+                    seqs,
+                  ) as any as StreamReplyType[])
                   : seqs;
                   : seqs;
                 this.handleSeqMoving(lastSeq);
                 this.handleSeqMoving(lastSeq);
               } else {
               } else {
@@ -441,6 +444,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       this.walkingSub.unsubscribe();
       this.walkingSub.unsubscribe();
       this.walkingSub = null;
       this.walkingSub = null;
     }
     }
+    if (this.clickQueueSub) {
+      this.clickQueueSub.unsubscribe();
+      this.clickQueueSub = null;
+    }
   }
   }
   handleMoveSteam() {
   handleMoveSteam() {
     this.moveQueueSubscription = this.moveQueue.subscribe(
     this.moveQueueSubscription = this.moveQueue.subscribe(
@@ -669,7 +676,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               delete redisData.mediaSrc;
               delete redisData.mediaSrc;
               this.logger.log(
               this.logger.log(
                 `user:${this.user_id}:first render stream` +
                 `user:${this.user_id}:first render stream` +
-                  JSON.stringify({ path: clipPath, meta: redisData }),
+                JSON.stringify({ path: clipPath, meta: redisData }),
               );
               );
               const status = await this.pushFirstRender(
               const status = await this.pushFirstRender(
                 clipPath,
                 clipPath,