Kaynağa Gözat

Merge branch 'master' of http://192.168.0.115:3000/zhangyupeng/meta-server

test pc 3 yıl önce
ebeveyn
işleme
91374e5cc8

+ 4 - 4
config.production1.yaml

@@ -1,13 +1,13 @@
 app:
   prefix: /mnt/metaverse/scene
-  startPoint: 29
+  startPoint: 141
   appId: '0000000007'
 
 log:
   logFolder: /var/log/metaverse
 
 queueConfig:
-  move: 80
+  move: 60
   rotate: 2
   joystick: 5
 
@@ -34,9 +34,9 @@ redis:
 #   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']
+# ['turn:4dage:4dage168@turn.4dage.com:4478', 'stun:stun.callwithus.com:3478']
 stun:
-  server:
-    ['turn:4dage:4dage168@turn.4dage.com:4478', 'stun:stun.callwithus.com:3478']
+  server: ['stun:stun.callwithus.com:3478', 'stun:47.107.125.202:3478']
   portRangeBegin: 49152
   portRangeEnd: 65535
 

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

@@ -35,7 +35,7 @@ export class MoveService implements OnModuleInit {
     private cacheService: CacheService,
     private rotateService: RotateService,
     private configService: ConfigService,
-  ) { }
+  ) {}
   private logger: Logger = new Logger('MoveService');
   private Actions = {
     Clicking: 1,
@@ -214,7 +214,6 @@ export class MoveService implements OnModuleInit {
     end_break_point_id,
     angleIndex,
   ) {
-
     if (angleIndex < 0) {
       debugger;
     }
@@ -1352,7 +1351,8 @@ export class MoveService implements OnModuleInit {
       this.reply.traceIds = [];
       this.reply['newUserStates'][0].userId = userId;
       this.reply['actionResponses'][0].traceId = null;
-      this.reply['newUserStates'][0].playerState.player.angle.yaw = user.player.angle.yaw;
+      this.reply['newUserStates'][0].playerState.player.angle.yaw =
+        user.player.angle.yaw;
       this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
         JSON.stringify(user.player.position),
       );
@@ -1377,19 +1377,15 @@ export class MoveService implements OnModuleInit {
         JSON.stringify(cameraInfo.camera_position),
       );
 
-      user.camera.angle = JSON.parse(
-        JSON.stringify(cameraInfo.camera_angle),
-      );
+      user.camera.angle = JSON.parse(JSON.stringify(cameraInfo.camera_angle));
 
       this.sendingFrameForJoystick = true;
       return this.reply;
-    }
-    else if (this.cameraInfos.length == 0) {
+    } else if (this.cameraInfos.length == 0) {
       if (this.reply['newUserStates'][0].renderInfo.isMoving == 1) {
         //console.log('handlejoysticktesttest:complementFrame-2 停止1'+new Date().getTime())
-        return this.stopJoystick(userId)
-      }
-      else {
+        return this.stopJoystick(userId);
+      } else {
         //console.log('handlejoysticktesttest:complementFrame-2 停止2'+new Date().getTime())
         return null;
       }
@@ -1520,7 +1516,7 @@ export class MoveService implements OnModuleInit {
   getDistance(position1, position2) {
     return Math.sqrt(
       (position1.x - position2.x) * (position1.x - position2.x) +
-      (position1.y - position2.y) * (position1.y - position2.y),
+        (position1.y - position2.y) * (position1.y - position2.y),
     );
   }
 

+ 8 - 4
src/rotate/rotate.service.ts

@@ -44,7 +44,7 @@ export class RotateService {
       breakPointId: null,
       roomId: null,
       player: {
-        position: { x: -560.0, y: 320.0, z: 0.0 },    //{ x: -800.0, y: 100.0, z: 0.0 },
+        position: { x: -560.0, y: 320.0, z: 0.0 }, //{ x: -800.0, y: 100.0, z: 0.0 },
         angle: {
           pitch: 0,
           yaw: 0,
@@ -52,7 +52,7 @@ export class RotateService {
         },
       },
       camera: {
-        position: { x: -998.0, y: 319.9999694824219, z: 120.0 },          //{ x: -1141.6719970703125, y: 94.03607940673828, z: 120.0 },
+        position: { x: -998.0, y: 319.9999694824219, z: 120.0 }, //{ x: -1141.6719970703125, y: 94.03607940673828, z: 120.0 },
         angle: {
           pitch: 0,
           yaw: 0,
@@ -159,8 +159,12 @@ export class RotateService {
       msg: 'OK',
     };
 
-    reply['newUserStates'][0].playerState.player.position = JSON.parse(JSON.stringify(user.player.position))
-    reply['newUserStates'][0].playerState.camera.position = JSON.parse(JSON.stringify(user.camera.position))
+    reply['newUserStates'][0].playerState.player.position = JSON.parse(
+      JSON.stringify(user.player.position),
+    );
+    reply['newUserStates'][0].playerState.camera.position = JSON.parse(
+      JSON.stringify(user.camera.position),
+    );
     this.replies[userId] = reply;
     return reply;
   }

+ 71 - 69
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;
@@ -104,7 +104,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   public testTimer = 0;
 
   private isJoystickHasStream = false;
-  private hasJoystickFocusRepeat = false
+  private hasJoystickFocusRepeat = false;
 
   public users = {};
 
@@ -272,16 +272,16 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         const playerAngle = newUserStates.playerState.player.angle;
         this.logger.log(
           'stop-data-0' +
-          'trace_id: ' +
-          trace_id +
-          'userId:' +
-          userId +
-          'breakPointId :' +
-          breakPointId +
-          'cameraAngle :' +
-          JSON.stringify(cameraAngle) +
-          'playerAngle: ' +
-          JSON.stringify(playerAngle),
+            'trace_id: ' +
+            trace_id +
+            'userId:' +
+            userId +
+            'breakPointId :' +
+            breakPointId +
+            'cameraAngle :' +
+            JSON.stringify(cameraAngle) +
+            'playerAngle: ' +
+            JSON.stringify(playerAngle),
         );
         //debugger;
         console.log('moveService.stop-1:' + breakPointId);
@@ -330,7 +330,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             const rounded = Number(inMillSeconds).toFixed(3);
             this.logger.log(
               `[timer]-rotate-入队列前: ${rounded}ms -->` +
-              JSON.stringify(stream),
+                JSON.stringify(stream),
             );
 
             this.roQueue.next(stream);
@@ -434,15 +434,15 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       console.log('进入1 - searchRoad');
       this.logger.log(
         'handleWalking-users' +
-        JSON.stringify(this.moveService.users) +
-        ' this.user_id: ' +
-        this.user_id,
+          JSON.stringify(this.moveService.users) +
+          ' this.user_id: ' +
+          this.user_id,
       );
       this.logger.log(
         'handleWalking-currentUser' +
-        JSON.stringify(user) +
-        ' this.user_id: ' +
-        this.user_id,
+          JSON.stringify(user) +
+          ' this.user_id: ' +
+          this.user_id,
       );
       console.log('path-start' + user.breakPointId);
 
@@ -512,16 +512,16 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         if (seqs?.length) {
           this.logger.log(
             'walking --队列总览:' +
-            ' 总段数: ' +
-            walkingRes.length +
-            ' 镜头帧数:' +
-            walkingRes[0].length +
-            ' 行走段数:' +
-            (walkingRes[0]?.length
-              ? walkingRes.length - 1
-              : walkingRes.length) +
-            ' 队列总帧数:' +
-            seqs.length,
+              ' 总段数: ' +
+              walkingRes.length +
+              ' 镜头帧数:' +
+              walkingRes[0].length +
+              ' 行走段数:' +
+              (walkingRes[0]?.length
+                ? walkingRes.length - 1
+                : walkingRes.length) +
+              ' 队列总帧数:' +
+              seqs.length,
           );
           const stop = performance.now();
           const inMillSeconds = stop - start;
@@ -583,7 +583,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     const hasMedia = joystickRes?.mediaSrc && joystickRes?.mediaSrc.length > 0;
 
     if (hasMedia) {
-      const mediaSrc = joystickRes.mediaSrc.split('?')[0];
+      const src = joystickRes.mediaSrc.split('?')[0];
+      const mediaSrc = this.configService.get('app.prefix') + src;
       // IDR flag设置为I帧
       const setDIR = joystickRes.moveOver || joystickRes.moveStart ? 1 : 3;
       streamData = {
@@ -606,8 +607,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
     const hasPush = hasMedia
       ? await this.streamService.pushFrameToSteam(streamData as StreamFrameType)
       : await this.streamService.pushMetaDataToSteam(
-        streamData as StreamMetaType,
-      );
+          streamData as StreamMetaType,
+        );
 
     if (hasPush.done) {
       this.isJoystickHasStream = true;
@@ -705,7 +706,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', JSON.stringify(joystickRes));
@@ -714,11 +715,11 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         this.onJoysticking.next(true);
         console.log(
           'handlejoysticktesttest:' +
-          joystickRes.mediaSrc +
-          ',相机坐标:' +
-          JSON.stringify(
-            joystickRes.newUserStates[0].playerState.player.position,
-          ),
+            joystickRes.mediaSrc +
+            ',相机坐标:' +
+            JSON.stringify(
+              joystickRes.newUserStates[0].playerState.player.position,
+            ),
         );
         if (!this.onMoving.getValue()) {
           this.handlePushJoyStickSteam(joystickRes);
@@ -807,14 +808,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(
@@ -1010,7 +1011,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;
@@ -1021,12 +1023,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(
@@ -1088,12 +1090,12 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           this.logger.log('frame', frame);
           console.log(
             'mock' +
-            ' maxMessageSize: ' +
-            this.channel.maxMessageSize() +
-            ' bytesReceived: ' +
-            this.peer.bytesReceived() +
-            ' bytesSent: ' +
-            this.peer.bytesSent(),
+              ' maxMessageSize: ' +
+              this.channel.maxMessageSize() +
+              ' bytesReceived: ' +
+              this.peer.bytesReceived() +
+              ' bytesSent: ' +
+              this.peer.bytesSent(),
           );
           if (frame === 1) {
             redisData = await this.rotateService.echo(this.user_id, true);
@@ -1108,7 +1110,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,
@@ -1136,15 +1138,15 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
             console.log(
               '空白流条件-->:' +
-              isOk +
-              ' onMoving: ' +
-              this.onMoving.value +
-              ' onRotating: ' +
-              this.onRotating.value +
-              ' onJoysticking: ' +
-              this.onJoysticking.value +
-              ' firstRender: ' +
-              this.firstRender,
+                isOk +
+                ' onMoving: ' +
+                this.onMoving.value +
+                ' onRotating: ' +
+                this.onRotating.value +
+                ' onJoysticking: ' +
+                this.onJoysticking.value +
+                ' firstRender: ' +
+                this.firstRender,
             );
           }