gemercheung 3 년 전
부모
커밋
e424cdae71
3개의 변경된 파일39개의 추가작업 그리고 32개의 파일을 삭제
  1. 1 1
      src/cache/cache.service.ts
  2. 1 0
      src/move/move.service.ts
  3. 37 31
      src/scene/scene.service.ts

+ 1 - 1
src/cache/cache.service.ts

@@ -25,7 +25,7 @@ export class CacheService implements OnModuleInit, OnModuleDestroy {
     this.client = null;
   }
 
-  async getClient() {
+  public async getClient() {
     this.client = await this.redisService.getClient();
   }
 

+ 1 - 0
src/move/move.service.ts

@@ -507,6 +507,7 @@ export class MoveService implements OnModuleInit {
 
   async stop(traceId, userId, breakPointId, cameraAngle, playerAngle) {
     //const breakPointId = movePointIds.substring(movePointIds.indexOf('-') + 1);
+
     const user = this.users[userId];
     const startBreakPointId = user.breakPointId;
     user.breakPointId = breakPointId;

+ 37 - 31
src/scene/scene.service.ts

@@ -26,7 +26,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;
@@ -230,6 +230,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   init(request: InitRequest) {
     try {
       this.rotateService.init(request.app_id, request.user_id);
+      this.cacheService.getClient();
       // 加载
       // let path: string;
       // if (process.env.NODE_ENV === 'development') {
@@ -250,9 +251,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
       // this.moveService.loadJSON(path);
       // this.getRouterService.loadJSON(path);
-      this.startSteaming.next(true);
-      this.startStream();
-      this.handleStream();
 
       // this.moveService.init(request.app_id, request.user_id);
 
@@ -313,21 +311,28 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         if (metaData.traceIds.indexOf(request.trace_id) > -1) {
           return;
         }
-
+        console.log('currentUser-user_id', this.user_id);
         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-0',
-          trace_id,
-          userId,
-          cameraAngle,
-          cameraAngle,
+          'stop-data-0' +
+            'trace_id: ' +
+            trace_id +
+            'userId:' +
+            userId +
+            'breakPointId :' +
+            breakPointId +
+            'cameraAngle :' +
+            JSON.stringify(cameraAngle) +
+            'playerAngle: ' +
+            JSON.stringify(playerAngle),
         );
         //debugger;
         redisMeta = await this.moveService.stop(
@@ -582,7 +587,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);
@@ -748,14 +753,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(
@@ -811,6 +816,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   handleDataChanelOpen(channel: DataChannel): void {
     this.channel = channel;
     this.streamService.setChannel(channel);
+    this.startSteaming.next(true);
+    this.startStream();
+    this.handleStream();
   }
 
   handleDataChanelClose(): void {
@@ -941,7 +949,8 @@ 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;
@@ -952,12 +961,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(
@@ -1021,14 +1030,11 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               const mediaSrc: string = redisData.mediaSrc || '';
               if (mediaSrc.length > 0) {
                 const src = mediaSrc.split('?')[0];
-                // 临时本地替换路经
-                // src = src.replace('/10086/', '');
-                // const clipPath = join(__dirname, `../ws/${src}`);
                 const clipPath = this.configService.get('app.prefix') + src;
                 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,
@@ -1043,7 +1049,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
                 }
               }
             } else {
-              this.logger.error(`首屏::无数据:${frame}`);
+              this.logger.error(`first render problem:${frame}`);
             }
           }
           if (