gemercheung 3 jaren geleden
bovenliggende
commit
f22a4741dc
2 gewijzigde bestanden met toevoegingen van 49 en 47 verwijderingen
  1. 48 46
      src/scene/scene.service.ts
  2. 1 1
      src/scene/stream/stream.service.ts

+ 48 - 46
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;
@@ -301,59 +301,61 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
   async walking(req) {
     try {
+      // if(this.clickQueueSub){
+      //   this.clickQueueSub.unsubscribe();
+      // }
       this.clickQueue.next(req);
       console.log('walking', this.clickQueueSub, JSON.stringify(req));
-      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);
+      // 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-length',
-            Array.from(walkingRes).flat().length,
-          );
+        console.log('walkingRes-length', Array.from(walkingRes).flat().length);
 
-          if (walkingRes && !this.onMoving.value) {
-            // console.log('walkingRes-front', walkingRes);
-            // shift出前第一个镜头数据
-            const rotateCamData = walkingRes.shift();
+        if (walkingRes && !this.onMoving.value) {
+          // console.log('walkingRes-front', walkingRes);
+          // shift出前第一个镜头数据
+          const rotateCamData = walkingRes.shift();
 
-            console.log('rotateCamData', rotateCamData.length);
+          console.log('rotateCamData', rotateCamData.length);
 
-            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 (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,
                 ) as any as StreamReplyType[])
-                : seqs;
-              console.log('walking --总序列--seqs', seqs.length);
-              this.handleSeqMoving(lastSeq);
-            } else {
-              console.error('walking-move无数据');
-            }
-            // this.lastMoveCnt = this.frameCnt.value + seqs.length;
+              : seqs;
+            console.log('walking --总序列--seqs', seqs.length);
+            this.handleSeqMoving(lastSeq);
+          } else {
+            console.error('walking-move无数据');
+            this.cleanMoveSteam();
           }
-        });
-      }
+          // this.lastMoveCnt = this.frameCnt.value + seqs.length;
+        }
+      });
+      // }
     } catch (error) {
       this.logger.error('walking', error);
+      this.cleanMoveSteam();
     }
   }
 
@@ -387,8 +389,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
                 console.log('joystickRes-seqs', seqs.length);
                 const lastSeq = rotateCamData?.length
                   ? (Array.from(rotateCamData).concat(
-                    seqs,
-                  ) as any as StreamReplyType[])
+                      seqs,
+                    ) as any as StreamReplyType[])
                   : seqs;
                 this.handleSeqMoving(lastSeq);
               } else {
@@ -694,7 +696,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,

+ 1 - 1
src/scene/stream/stream.service.ts

@@ -18,7 +18,7 @@ export class StreamService {
     clipPath: '',
     metaData: '',
   });
-  constructor(private cacheService: CacheService) { }
+  constructor(private cacheService: CacheService) {}
 
   setChannel(channel: DataChannel) {
     this.channel = channel;