gemercheung 3 jaren geleden
bovenliggende
commit
06fb57ad5a
1 gewijzigde bestanden met toevoegingen van 58 en 52 verwijderingen
  1. 58 52
      src/scene/scene.service.ts

+ 58 - 52
src/scene/scene.service.ts

@@ -228,7 +228,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
       // this.initUsers(request.app_id, request.user_id);
     } catch (error) {
-      console.log('error', error);
+      this.logger.error('error', error);
     }
   }
 
@@ -239,7 +239,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
   async rotate(request: RotateRequest) {
     this.handleRotate(request);
-    // console.log('request', request)
+    //this.logger.log('request', request)
     // this.roRequestQueue.next(request);
     // if (!this.roRequestQueueSub) {
     //   this.handleRotate();
@@ -274,7 +274,13 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const breakPointId = metaData.endBreakPointId;
         const cameraAngle = newUserStates.playerState.camera.angle;
         const playerAngle = newUserStates.playerState.player.angle;
-        console.log('stop-data', trace_id, userId, cameraAngle, cameraAngle);
+        this.logger.log(
+          'stop-data',
+          trace_id,
+          userId,
+          cameraAngle,
+          cameraAngle,
+        );
         //debugger;
         redisMeta = await this.moveService.stop(
           trace_id,
@@ -283,14 +289,14 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           cameraAngle,
           playerAngle,
         );
-        console.log('stop-redisMeta', redisMeta);
+        this.logger.log('stop-redisMeta', redisMeta);
         this.onMoving.next(false);
         this.cleanMoveSteam();
         // redisMeta = await this.rotateService.rotate(request);
       } else {
         // 正常rotate
         redisMeta = await this.rotateService.seqExeRotate(request);
-        // console.log(redisMeta);
+        //this.logger.log(redisMeta);
         //debugger;
       }
 
@@ -298,10 +304,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const mediaSrc: string = redisMeta.mediaSrc || '';
         if (mediaSrc.length > 0) {
           const src = mediaSrc.split('?')[0];
-          // console.log('进入roQueue1', redisMeta.newUserStates[0].playerState.camera.angle.yaw);
-          // console.log('进入roQueue2', src);
+          //this.logger.log('进入roQueue1', redisMeta.newUserStates[0].playerState.camera.angle.yaw);
+          //this.logger.log('进入roQueue2', src);
           if (src.length > 0) {
-            // console.log('不同源');
+            //this.logger.log('不同源');
             this.holdSteam();
             this.lastRenderMedia = src;
             const clipPath = this.configService.get('app.prefix') + src;
@@ -314,14 +320,14 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               serverTime: this.mockserverTime,
               DIR: 3,
             };
-            // console.log('rotate', stream, Date.now());
+            //this.logger.log('rotate', stream, Date.now());
             clearTimeout(this._rotateTimeout);
 
-            // console.log('进入roQueue3', stream.clipPath);
+            //this.logger.log('进入roQueue3', stream.clipPath);
             const stop = performance.now();
             const inMillSeconds = stop - start;
             const rounded = Number(inMillSeconds).toFixed(3);
-            console.log(`[timer]-rotate-入队列前: ${rounded}ms`);
+            this.logger.log(`[timer]-rotate-入队列前: ${rounded}ms`);
             this.roQueue.next(stream);
           } else {
             // this.onRotating.next(false);
@@ -337,7 +343,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
   async walking(request: MoveRequest) {
     this.latestWalkingRequest = request;
-    console.log('walking', request);
+    this.logger.log('walking', request);
     // 进入正常walking流程
     if (!this.onMoving.getValue()) {
       this.latestWalkingRequest = null;
@@ -349,7 +355,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         async (frame: MovingLastUpdateType) => {
           //TODO 正在行走时,有新的reqest
           if (this.latestWalkingRequest && this.onMoving.value) {
-            console.log('中断的小段', frame);
+            this.logger.log('中断的小段', frame);
             // this.moveQueue.complete();
             // this.moveQueue.of('');
             // TODO 中断move队列 ?优化如何清空
@@ -367,7 +373,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             const breakPointId = metaData.endBreakPointId;
             const cameraAngle = newUserStates.playerState.camera.angle;
             const playerAngle = newUserStates.playerState.player.angle;
-            console.log(
+            this.logger.log(
               'stop-data',
               trace_id,
               userId,
@@ -381,7 +387,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               cameraAngle,
               playerAngle,
             );
-            console.log('stop-redisMeta', redisMeta);
+            this.logger.log('stop-redisMeta', redisMeta);
             // 2. 中断重新walking
             this.handleReWalking(this.latestWalkingRequest);
           }
@@ -401,29 +407,29 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       // if (!this.onMoving.getValue()) {
       const start = performance.now();
       const user = this.moveService.users[this.user_id];
-      console.log('进入1 - searchRoad');
-      console.log('path-start' + user.breakPointId);
+      this.logger.log('进入1 - searchRoad');
+      this.logger.log('path-start' + user.breakPointId);
       const path = await this.getRouterService.searchRoad(
         user.appId,
         user.breakPointId,
         request.clicking_action.clicking_point,
       );
-      console.log('walking-path', path);
+      this.logger.log('walking-path', path);
       if (!path) {
-        console.log('不存在--path', path);
+        this.logger.log('不存在--path', path);
         this.resumeStream();
         return;
       }
       // debugger;
       const walkingRes = await this.moveService.move(path, request);
 
-      // console.log('walking', walkingRes);
+      //this.logger.log('walking', walkingRes);
       // debugger;
       if (walkingRes && !this.onMoving.value) {
-        // console.log('walkingRes-front', walkingRes);
+        //this.logger.log('walkingRes-front', walkingRes);
         // shift出前第一个镜头数据
         const rotateCamData = walkingRes[0];
-        console.log('rotateCamData', rotateCamData.length);
+        this.logger.log('rotateCamData', rotateCamData.length);
         if (rotateCamData?.length) {
           // 头数组[0] rotate 序列, 头是关键key
           walkingRes[0].forEach((item: StreamReplyType, index: number) => {
@@ -431,7 +437,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             item.DIR = index === 0 ? 1 : 3;
           });
         } else {
-          console.log('rotateCamData无数据');
+          this.logger.log('rotateCamData无数据');
         }
 
         // 二维数组 做move 序列, move类型
@@ -460,11 +466,11 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const seqs = Array.from(walkingRes).flat() as any as StreamReplyType[];
 
         if (seqs?.length) {
-          console.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);
-          console.log(`[timer]-move-入队列前:-->${rounded}ms`);
+          this.logger.log(`[timer]-move-入队列前:-->${rounded}ms`);
 
           this.handleSeqMoving(seqs);
         } else {
@@ -497,7 +503,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
    */
   async joystick(request: JoystickRequest) {
     // TODO hasJoystickMoveRequest中断
-    console.log('this.hasJoystickMoveRequest', this.hasJoystickMoveRequest);
+    this.logger.log('this.hasJoystickMoveRequest', this.hasJoystickMoveRequest);
     if (!this.hasJoystickMoveRequest) {
       this.handlejoystick(request);
     }
@@ -511,17 +517,17 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     try {
       //const joystickRes = await this.moveService.joystick(request);
       const joystickRes = await this.moveService.seqExeJoystick(request);
-      console.log(
+      this.logger.log(
         'joystick-breakPointId:' +
           this.moveService.users[this.user_id].breakPointId,
       );
       // 有数据 [0]是rotate数据,[1-infinity]是walking数据
-      console.log('joystickRes-1', joystickRes);
+      this.logger.log('joystickRes-1', joystickRes);
       this.onJoysticking.next(true);
       if (Array.isArray(joystickRes)) {
         // 处理第一个镜头数据
         const rotateCamData = joystickRes[0];
-        console.log('rotateCamData', rotateCamData.length);
+        this.logger.log('rotateCamData', rotateCamData.length);
         if (rotateCamData?.length) {
           // 头数组[0] rotate 序列, 头是关键key
           joystickRes[0].forEach((item: StreamReplyType, index: number) => {
@@ -529,12 +535,12 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             item.DIR = index === 0 ? 1 : 3;
           });
         } else {
-          console.log('rotateCamData无数据');
+          this.logger.log('rotateCamData无数据');
         }
         // 二维数组 做move 序列, move类型
         if (joystickRes?.length >= 1) {
           for (let i = 1; i < joystickRes.length; i++) {
-            console.log('joystickRes-2', joystickRes[i]);
+            this.logger.log('joystickRes-2', joystickRes[i]);
             Array.from(joystickRes[i]).forEach(
               (item: StreamReplyType, index: number) => {
                 const dir = this.isHeaderOrLast(
@@ -549,7 +555,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
                     metaData: item,
                   });
                 }
-                // console.log(
+                //this.logger.log(
                 //   'joystick:' +
                 //     JSON.stringify(
                 //       joystickRes[i][index]['newUserStates'][0].playerState
@@ -563,7 +569,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const seqs = Array.from(joystickRes).flat() as any as StreamReplyType[];
 
         if (seqs?.length > 1) {
-          console.log('joystick:-seqs', seqs.length);
+          this.logger.log('joystick:-seqs', seqs.length);
           //TODO joystick中断逻辑
           this.hasJoystickMoveRequest = true;
           this.handleSeqMoving(seqs);
@@ -571,7 +577,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           console.warn('joystick-move无数据');
         }
       } else {
-        console.log('joystick-接收人物数据', this.onMoving.getValue());
+        this.logger.log('joystick-接收人物数据', this.onMoving.getValue());
         if (!this.onMoving.getValue()) {
           // 在非行走时接受
           this.holdSteam();
@@ -583,15 +589,15 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             frame: this.joystickFrameCnt,
             metaData: JSON.stringify(joystickRes),
           };
-          // console.log('rotate', stream, Date.now());
+          //this.logger.log('rotate', stream, Date.now());
           const res = await this.streamService.pushMetaDataToSteam(stream);
           if (res.done) {
-            console.log('joystick-frame', res.frame);
+            this.logger.log('joystick-frame', res.frame);
             this.frameCnt.next(res.frame);
             clearTimeout(this._JoyStickingTimeout);
             this._JoyStickingTimeout = setTimeout(() => {
-              console.log('joystick opt done');
-              console.log('joystick 交权给空流,当前pts', res.frame);
+              this.logger.log('joystick opt done');
+              this.logger.log('joystick 交权给空流,当前pts', res.frame);
               // this.frameCnt.next(res.frame);
               this.onJoysticking.next(false);
               this.resumeStream();
@@ -613,7 +619,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     if (!this.moveQueueSubscription) {
       this.handleMoveSteam();
     }
-    console.log('moving-seqs', seqs.length);
+    this.logger.log('moving-seqs', seqs.length);
     this.onMoving.next(true);
     this.holdSteam();
     //TODO Remove
@@ -670,7 +676,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           serverTime: this.mockserverTime,
           DIR: stream.DIR,
         };
-        console.log(
+        this.logger.log(
           '[media-move]: ' +
             ', moveframeCnt: ' +
             this.moveframeCnt +
@@ -682,7 +688,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             stream.DIR,
           // stream.metaData,
         );
-        console.log(
+        this.logger.log(
           '[media-move-lastMovingPointArray]',
           this.lastMovingPointArray?.length,
         );
@@ -692,10 +698,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const isLastFrameIndex = this.lastMovingPointArray.findIndex(
           (item) => item.mediaSrc === metaData.mediaSrc,
         );
-        // console.log('path-update-index', isLastFrameIndex);
+        //this.logger.log('path-update-index', isLastFrameIndex);
         //每一段的最后一帧
         if (isLastFrameIndex > -1) {
-          // console.log('path-update-array', this.lastMovingPointArray);
+          //this.logger.log('path-update-array', this.lastMovingPointArray);
           const currentMeta = this.lastMovingPointArray[isLastFrameIndex];
           const userId = this.user_id;
           const breakPointId = currentMeta.metaData.endBreakPointId;
@@ -710,7 +716,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         if (res.done) {
           clearTimeout(this._moveTimeout);
           this._moveTimeout = setTimeout(() => {
-            console.log('move 交权给空流,当前pts', res.frame);
+            this.logger.log('move 交权给空流,当前pts', res.frame);
             this.frameCnt.next(res.frame);
             this.resumeStream();
             this.rotateframeCnt = -1;
@@ -719,7 +725,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             this.cleanMoveSteam();
             this.lastMovingPointArray = [];
             this.hasJoystickMoveRequest = false;
-            console.log('move end');
+            this.logger.log('move end');
           }, 300);
         }
       },
@@ -809,7 +815,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
   handleBreath(request) {
     const npsRes = this.moveService.getBreakPoints(request);
-    // console.log('npsRes', npsRes.nps);
+    //this.logger.log('npsRes', npsRes.nps);
     this.streamService.pushNormalDataToStream(npsRes);
   }
 
@@ -825,7 +831,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       const usersData = this.rotateService.getNewUserStateRequest(request);
       if (usersData) {
         usersData.actionType = 1024;
-        // console.log(
+        //this.logger.log(
         //   'joystick:->updateUserStatus' +
         //   'playerPosition:' +
         //   JSON.stringify(
@@ -878,7 +884,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           if (res.done) {
             clearTimeout(this._rotateTimeout);
             this._rotateTimeout = setTimeout(() => {
-              console.log('rotate end', Date.now());
+              this.logger.log('rotate end', Date.now());
               this.frameCnt.next(res.frame);
               this.resumeStream();
               this.rotateframeCnt = -1;
@@ -919,10 +925,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     if (!this.frameCntSubscription) {
       this.frameCntSubscription = this.frameCnt.subscribe(async (frame) => {
         try {
-          console.log('frame', frame);
+          this.logger.log('frame', frame);
           if (frame === 1) {
             const redisData = await this.rotateService.echo(this.user_id, true);
-            console.log('获取-首屏', redisData);
+            this.logger.log('获取-首屏', redisData);
             this.onSteaming = true;
             this.holdSteam();
             if (redisData && 'mediaSrc' in redisData) {
@@ -966,7 +972,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               false,
             );
             if (redisDataAuto) {
-              console.log(`空白流::有数据:${frame}`);
+              this.logger.log(`空白流::有数据:${frame}`);
               'mediaSrc' in redisDataAuto && delete redisDataAuto.mediaSrc;
               const streamMeta: StreamMetaType = {
                 frame: frame,
@@ -975,7 +981,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               this.streamService.pushMetaDataToSteam(streamMeta);
             } else {
               this.stopStream();
-              console.log('空流无Redis数据');
+              this.logger.log('空流无Redis数据');
               throw new Error('空流无Redis数据');
             }
           }