gemercheung 3 tahun lalu
induk
melakukan
7c7f0d73cd

+ 5 - 2
src/get-router/get-router.service.ts

@@ -9,9 +9,12 @@ export class GetRouterService implements OnModuleInit {
   private breakPointInfo: any;
   private logger: Logger = new Logger('GetRouterService');
 
-  async onModuleInit() {
+  // eslint-disable-next-line @typescript-eslint/no-empty-function
+  async onModuleInit() {}
+
+  async loadJSON(path) {
     try {
-      const path = join(__dirname, '../ws/points-BreakPointId.json');
+      // const path = join(__dirname, '../ws/points-BreakPointId.json');
       // const path = join(__dirname, '../ws/demo1.json');
       const data = await readFileSync(path);
       const BreakPointInfo = JSON.parse(Buffer.from(data).toString('utf-8'));

+ 1 - 0
src/meta.gateway.ts

@@ -322,6 +322,7 @@ export class MetaGateway
     this.peer && this.peer.close();
     if (this.startstreamingSub) {
       this.startstreamingSub.unsubscribe();
+      this.startstreamingSub = null;
     }
     this.sceneService.stopStream();
   }

+ 6 - 8
src/move/move.service.ts

@@ -1,9 +1,4 @@
-import {
-  ConsoleLogger,
-  Injectable,
-  Logger,
-  OnModuleInit,
-} from '@nestjs/common';
+import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
 import { ConfigService } from '@nestjs/config';
 import { readFileSync } from 'fs';
 import { join } from 'path';
@@ -133,9 +128,12 @@ export class MoveService implements OnModuleInit {
   };
   private breakPointInfo: any;
 
-  async onModuleInit() {
+  // eslint-disable-next-line @typescript-eslint/no-empty-function
+  async onModuleInit() {}
+
+  async loadJSON(path) {
     try {
-      const path = join(__dirname, '../ws/points-BreakPointId.json');
+      // const path = join(__dirname, '../ws/points-BreakPointId.json');
       // const path = join(__dirname, '../ws/demo1.json');
       const data = await readFileSync(path);
       const BreakPointInfo = JSON.parse(Buffer.from(data).toString('utf-8'));

+ 41 - 18
src/scene/scene.service.ts

@@ -16,6 +16,7 @@ import { DelayQueue, RxQueue, DebounceQueue } from '../queue/mod';
 import { MoveService } from 'src/move/move.service';
 import { GetRouterService } from 'src/get-router/get-router.service';
 import { ConfigService } from '@nestjs/config';
+import { join } from 'path';
 
 @Injectable()
 export class SceneService implements OnModuleInit, OnModuleDestroy {
@@ -26,7 +27,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;
@@ -224,9 +225,30 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   init(request: InitRequest) {
     try {
       this.rotateService.init(request.app_id, request.user_id);
+      // 加载
+      let path: string;
+      if (process.env.NODE_ENV === 'development') {
+        path = join(
+          __dirname,
+          `../ws/${request.app_id}/points-${request.app_id}.json`,
+        );
+        console.log('测试服JSON', path);
+      }
+      if (process.env.NODE_ENV === 'production') {
+        path = join(
+          `${this.configService.get('app.prefix')}/${request.app_id}/points-${
+            request.app_id
+          }.json`,
+        );
+        console.log('正式服JSON', path);
+      }
+
+      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);
 
       // this.initUsers(request.app_id, request.user_id);
@@ -540,7 +562,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);
@@ -706,14 +728,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(
@@ -893,7 +915,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;
@@ -904,12 +927,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(
@@ -980,7 +1003,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,