gemercheung 3 years ago
parent
commit
65a438e0c2

+ 48 - 0
config.p0000005-bk.yaml

@@ -0,0 +1,48 @@
+app:
+  prefix: /mnt/metaverse/scene
+  startPoint: 17
+  appId: "0000000005"
+
+log:
+  logFolder: /var/log/metaverse
+
+queueConfig:
+  move: 80
+  rotate: 2
+
+http:
+  host: '0.0.0.0'
+  port: 6688
+
+grpc:
+  url: '221.4.210.172:23000'
+# grpc:
+#   url: '192.168.0.47:3000'
+
+redis:
+  port: 6379
+  host: '47.107.125.202' #远程调试需要设置bindip 为0.0.0.0 并且设置密码
+  password: 'Happy@Pass#@!7' # 非远程不需要密码
+  decode_responses: true
+  db: 9
+# queueRedis:
+#   port: 6379
+#   host: '127.0.0.1' #远程调试需要设置bindip 为0.0.0.0 并且设置密码
+#   password: 'sxz123321SxZ@' # 非远程不需要密码
+#   decode_responses: true
+#   db: 14
+# server: ['stun:47.107.125.202:3478','stun:120.24.252.95:3478']
+#  server: ['stun:4dage:4dage168@47.107.125.202:3478','stun:120.24.252.95:3478']
+stun:
+  server: ['turn:4dage:4dage168@turn.4dage.com:4478', 'stun:120.24.252.95:3478']
+  portRangeBegin: 49152
+  portRangeEnd: 65535
+
+server:
+  private_ip: 172.18.144.42
+  public_ip: 47.107.125.202
+# PRIVATE_IP=172.18.197.114
+# PUBLIC_IP=120.24.252.95
+# STUNS_SEVER="stun:172.18.156.41:3478,stun:120.24.252.95:3478"
+# GRPC_URL="192.168.0.48:3000"
+# REDIS_URL="redis://:192.168.0.47:6379/9"

+ 3 - 3
config.production1.yaml

@@ -1,7 +1,7 @@
 app:
   prefix: /mnt/metaverse/scene
-  startPoint: 17
-  appId: "0000000005"
+  startPoint: 29
+  appId: "0000000003"
 
 log:
   logFolder: /var/log/metaverse
@@ -21,7 +21,7 @@ grpc:
 
 redis:
   port: 6379
-  host: '47.107.125.202' #远程调试需要设置bindip 为0.0.0.0 并且设置密码
+  host: '127.0.0.1' #远程调试需要设置bindip 为0.0.0.0 并且设置密码
   password: 'Happy@Pass#@!7' # 非远程不需要密码
   decode_responses: true
   db: 9

+ 14 - 3
src/queue/delay-queue/delay-queue.ts

@@ -1,4 +1,13 @@
-import { concat, empty, of, Subject, Subscription, timer, EMPTY } from 'rxjs';
+import {
+  concat,
+  empty,
+  of,
+  Subject,
+  Subscription,
+  timer,
+  EMPTY,
+  BehaviorSubject,
+} from 'rxjs';
 import {
   concatMap,
   ignoreElements,
@@ -55,9 +64,11 @@ export class DelayQueue<T = unknown> extends RxQueue<T> {
   }
 
   override clean(): void {
-    // 1
     this.subscription.unsubscribe();
-    this.subject.pipe(ignoreElements());
+    this.subject
+      .asObservable()
+      .pipe(switchMap(() => EMPTY))
+      .pipe(ignoreElements());
     // .subscribe((item: T) => super.next(item));
 
     this.initQueue();

+ 2 - 2
src/rotate/rotate.service.ts

@@ -44,7 +44,7 @@ export class RotateService {
       breakPointId: null,
       roomId: null,
       player: {
-        position: { x: -2100, y: 200, z: 3.79 },
+        position: { x: -800.0, y: 100.0, z: 0.0 },
         angle: {
           pitch: 0,
           yaw: 0,
@@ -52,7 +52,7 @@ export class RotateService {
         },
       },
       camera: {
-        position: { x: -2538.0, y: 199.99998474121097, z: 116.2100067138672 },
+        position: { x: -1141.6719970703125, y: 94.03607940673828, z: 120.0 },
         angle: {
           pitch: 0,
           yaw: 0,

+ 9 - 25
src/scene/scene.service.ts

@@ -43,6 +43,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   private moveframeCnt = -1;
   private joystickFrameCnt = -1;
   private rotateFirstIDR = true;
+  private rotateStopThrottle = false; //防止多次瞬间解触发
 
   private sceneGrpcService: SceneGrpcService;
   private channel: DataChannel;
@@ -233,29 +234,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       this.rotateService.init(request.app_id, request.user_id);
       this.cacheService.getClient();
       // 加载
-      // 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.moveService.init(request.app_id, request.user_id);
-
-      // this.initUsers(request.app_id, request.user_id);
     } catch (error) {
       this.logger.error('error', error);
     }
@@ -291,7 +269,12 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       this.onRotating.next(true);
       const start = performance.now();
       // 当move时处理 _rotateCount是移动端同时触发的问题
-      if (this.onMoving.value && this._rotateCount > 5) {
+      if (
+        this.onMoving.value &&
+        this._rotateCount > 5 &&
+        !this.rotateStopThrottle
+      ) {
+        this.rotateStopThrottle = true;
         const lastStreamFrame = this.lastMoveStreamFrame.getValue();
         // const lastMoveStreamFrameBk = this.lastMoveStreamFrameBk;
         //TODO对比
@@ -750,6 +733,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     //   this.clickQueueSub.unsubscribe();
     //   this.clickQueueSub = null;
     // }
+    this.rotateStopThrottle = false;
   }
   handleMoveSteam() {
     this.moveQueueSubscription = this.moveQueue.subscribe(
@@ -787,7 +771,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           );
           // 记录lastMoveStreamFrame给打断逻辑使用
           this.lastMoveStreamFrame.next(streamData);
-          this.lastMoveStreamFrameBk = streamData;
+          // this.lastMoveStreamFrameBk = streamData;
           const res = await this.streamService.pushFrameToSteam(streamData);
 
           const isLastFrameIndex = this.lastMovingPointArray.findIndex(

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

@@ -1,7 +1,7 @@
 import { Injectable, Logger } from '@nestjs/common';
 import { DataChannel } from 'node-datachannel';
 // import * as path from 'path';
-import { readFileSync } from 'fs';
+import { existsSync, readFileSync } from 'fs';
 import * as streamBuffers from 'stream-buffers';
 import { BehaviorSubject } from 'rxjs';
 import { CacheService } from 'src/cache/cache.service';
@@ -132,8 +132,14 @@ export class StreamService {
         // console.warn('coordBuff', coordBuff.byteLength);
         // const steamStat = statSync(clipPath);
         // const steamTotalSize = metaData.length + steamStat.size;
+        // 增加不存在帧数据中断数据,原因有太多不准确的路径。
+        if (!existsSync(clipPath)) {
+          this.logger.error('不存在的推流路径::' + clipPath);
+          return;
+        }
 
         const clipBuffer = readFileSync(clipPath);
+
         const steam = new streamBuffers.ReadableStreamBuffer({
           frequency: 1, // in milliseconds.
           chunkSize: this.chunk_size - this.block, // in bytes.