gemercheung 3 years ago
parent
commit
50f9f7198f
5 changed files with 31 additions and 11 deletions
  1. 2 2
      config.production1.yaml
  2. 1 1
      config.yaml
  3. 5 6
      src/meta.gateway.ts
  4. 12 1
      src/scene/scene.service.ts
  5. 11 1
      src/scene/stream/stream.service.ts

+ 2 - 2
config.production1.yaml

@@ -3,8 +3,8 @@ app:
   prefix: /mnt/metaverse/scene
   prefix: /mnt/metaverse/scene
 
 
 queueConfig:
 queueConfig:
-  move: 8
-  rotate: 8
+  move: 10
+  rotate: 5
 
 
 
 
 http:
 http:

+ 1 - 1
config.yaml

@@ -3,7 +3,7 @@ app:
 
 
 queueConfig:
 queueConfig:
   move: 10
   move: 10
-  rotate: 10
+  rotate: 5
 
 
 http:
 http:
   host: '0.0.0.0'
   host: '0.0.0.0'

+ 5 - 6
src/meta.gateway.ts

@@ -35,12 +35,11 @@ initLogger('Debug');
   path: '/ws',
   path: '/ws',
 })
 })
 export class MetaGateway
 export class MetaGateway
-  implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect
-{
+  implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect {
   constructor(
   constructor(
     private readonly sceneService: SceneService,
     private readonly sceneService: SceneService,
     private readonly configService: ConfigService,
     private readonly configService: ConfigService,
-  ) {}
+  ) { }
   private logger: Logger = new Logger('MetaGateway');
   private logger: Logger = new Logger('MetaGateway');
   private peer: PeerConnection = null;
   private peer: PeerConnection = null;
   private timer: NodeJS.Timeout;
   private timer: NodeJS.Timeout;
@@ -134,7 +133,7 @@ export class MetaGateway
 
 
       if (/192.168\./.test(candidate)) {
       if (/192.168\./.test(candidate)) {
         if (!/192.168.0\./.test(candidate) || !/192.168.10\./.test(candidate)) {
         if (!/192.168.0\./.test(candidate) || !/192.168.10\./.test(candidate)) {
-          console.warn('不是192.168.0./192.168.10测试网段', candidate);
+          this.logger.warn('不是192.168.0./192.168.10测试网段' + candidate);
           return;
           return;
         }
         }
         // if (candidate.includes(process.env.PRIVATE_IP)) {
         // if (candidate.includes(process.env.PRIVATE_IP)) {
@@ -142,7 +141,7 @@ export class MetaGateway
         //   candidate = replaceToPublic(candidate);
         //   candidate = replaceToPublic(candidate);
         // }
         // }
       }
       }
-      console.warn('onLocalCandidate last Candidate:', candidate);
+      this.logger.warn('onLocalCandidate last Candidate:' + candidate);
 
 
       const iceRes = {
       const iceRes = {
         candidate,
         candidate,
@@ -283,7 +282,7 @@ export class MetaGateway
           }
           }
         },
         },
       );
       );
-    } catch (error) {}
+    } catch (error) { }
   }
   }
 
 
   handleConnection(client: WebSocket, ...args: any[]) {
   handleConnection(client: WebSocket, ...args: any[]) {

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

@@ -256,6 +256,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         }
         }
         let redisMeta: StreamReplyType;
         let redisMeta: StreamReplyType;
         this.onRotating.next(true);
         this.onRotating.next(true);
+        const start = performance.now();
         // 当move时处理
         // 当move时处理
         if (this.onMoving.value) {
         if (this.onMoving.value) {
           this.onMoving.next(false);
           this.onMoving.next(false);
@@ -315,6 +316,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               clearTimeout(this._rotateTimeout);
               clearTimeout(this._rotateTimeout);
 
 
               // console.log('进入roQueue3', stream.clipPath);
               // console.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.roQueue.next(stream);
               this.roQueue.next(stream);
             } else {
             } else {
               // this.onRotating.next(false);
               // this.onRotating.next(false);
@@ -340,6 +345,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       console.log('walking', this.clickQueueSub, JSON.stringify(req));
       console.log('walking', this.clickQueueSub, JSON.stringify(req));
       // if (!this.clickQueueSub) {
       // if (!this.clickQueueSub) {
       this.clickQueueSub = this.clickQueue.subscribe(async (request) => {
       this.clickQueueSub = this.clickQueue.subscribe(async (request) => {
+        const start = performance.now();
         const user = this.moveService.users[this.user_id];
         const user = this.moveService.users[this.user_id];
         console.log('进入1 - searchRoad');
         console.log('进入1 - searchRoad');
         console.log('path-start' + user.breakPointId);
         console.log('path-start' + user.breakPointId);
@@ -357,7 +363,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         // debugger;
         // debugger;
         const walkingRes = await this.moveService.move(path, request);
         const walkingRes = await this.moveService.move(path, request);
 
 
-        console.log('walking', walkingRes);
+        // console.log('walking', walkingRes);
         // debugger;
         // debugger;
         if (walkingRes && !this.onMoving.value) {
         if (walkingRes && !this.onMoving.value) {
           // console.log('walkingRes-front', walkingRes);
           // console.log('walkingRes-front', walkingRes);
@@ -404,6 +410,11 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
 
           if (seqs?.length) {
           if (seqs?.length) {
             console.log('walking --总序列--seqs-2', seqs.length);
             console.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.handleSeqMoving(seqs);
             this.handleSeqMoving(seqs);
           } else {
           } else {
             console.error('walking-move无数据');
             console.error('walking-move无数据');

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

@@ -19,7 +19,7 @@ export class StreamService {
     clipPath: '',
     clipPath: '',
     metaData: '',
     metaData: '',
   });
   });
-  constructor(private cacheService: CacheService) {}
+  constructor(private cacheService: CacheService) { }
 
 
   setChannel(channel: DataChannel) {
   setChannel(channel: DataChannel) {
     this.channel = channel;
     this.channel = channel;
@@ -96,6 +96,9 @@ export class StreamService {
       try {
       try {
         // console.log('process.env', process.env.node_env);
         // console.log('process.env', process.env.node_env);
         //TODO 开发替换path
         //TODO 开发替换path
+        // let start, stop;
+        const start = performance.now();
+
         // const src = stream.clipPath.replace('/mnt/metaverse/scene', '');
         // const src = stream.clipPath.replace('/mnt/metaverse/scene', '');
         // const srcTmp = join(__dirname, `../ws/${src}`);
         // const srcTmp = join(__dirname, `../ws/${src}`);
         // const clipPath = srcTmp;
         // const clipPath = srcTmp;
@@ -113,11 +116,13 @@ export class StreamService {
           serverTime: serverTime,
           serverTime: serverTime,
           DIR: dir,
           DIR: dir,
         });
         });
+
         const metaDataString = metaData.replace(/\s/g, '');
         const metaDataString = metaData.replace(/\s/g, '');
         const coordBuff = Buffer.from(metaDataString, 'utf-8');
         const coordBuff = Buffer.from(metaDataString, 'utf-8');
         // console.warn('coordBuff', coordBuff.byteLength);
         // console.warn('coordBuff', coordBuff.byteLength);
         // const steamStat = statSync(clipPath);
         // const steamStat = statSync(clipPath);
         // const steamTotalSize = metaData.length + steamStat.size;
         // const steamTotalSize = metaData.length + steamStat.size;
+
         const clipBuffer = readFileSync(clipPath);
         const clipBuffer = readFileSync(clipPath);
         const steam = new streamBuffers.ReadableStreamBuffer({
         const steam = new streamBuffers.ReadableStreamBuffer({
           frequency: 1, // in milliseconds.
           frequency: 1, // in milliseconds.
@@ -130,6 +135,7 @@ export class StreamService {
 
 
         steam.on('data', (data: Buffer) => {
         steam.on('data', (data: Buffer) => {
           this.onSteaming.next(true);
           this.onSteaming.next(true);
+
           // console.log('data', data, data.byteLength);
           // console.log('data', data, data.byteLength);
           const blockBuffStart = Buffer.alloc(this.block);
           const blockBuffStart = Buffer.alloc(this.block);
           const packBuffer = Buffer.concat([blockBuffStart, data]);
           const packBuffer = Buffer.concat([blockBuffStart, data]);
@@ -179,6 +185,10 @@ export class StreamService {
         steam.on('end', () => {
         steam.on('end', () => {
           steamByteLength = 0;
           steamByteLength = 0;
           // console.log('stream end');
           // console.log('stream end');
+          const stop = performance.now();
+          const inMillSeconds = stop - start;
+          const rounded = Number(inMillSeconds).toFixed(3);
+          console.log(`[timer]-当前流:${src}流耗时-->${rounded}ms`);
           if (this.onSteaming.value) {
           if (this.onSteaming.value) {
             this.onSteaming.next(false);
             this.onSteaming.next(false);
           }
           }