Kaynağa Gözat

增加turn password

gemercheung 3 yıl önce
ebeveyn
işleme
75c3af1f50

+ 3 - 1
config.production1.yaml

@@ -29,8 +29,10 @@ redis:
 #   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: ['stun:47.107.125.202:3478', 'stun:120.24.252.95:3478']
+  server: ['stun:4dage:4dage168@47.107.125.202:3478']
   portRangeBegin: 50000
   portRangeEnd: 55000
 

+ 4 - 4
config.yaml

@@ -18,11 +18,11 @@ redis:
   password: 'sxz123321SxZ@' # 非远程不需要密码
   decode_responses: true
   db: 9
-
+  # server: ['stun:47.107.125.202:3478','stun:120.24.252.95:3478']
 stun:
-  server: ['stun:120.24.252.95:3478', 'stun:172.18.156.41:3478']
-  portRangeBegin: 52000
-  portRangeEnd: 53000
+  server: ['stun:4dage:4dage168@47.107.125.202:3478','stun:120.24.252.95:3478']
+  portRangeBegin: 50000
+  portRangeEnd: 55000
 
 server:
   private_ip: 172.18.197.114

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

@@ -5,7 +5,7 @@ import { CacheService } from 'src/cache/cache.service';
 
 @Injectable()
 export class GetRouterService implements OnModuleInit {
-  constructor(private cacheService: CacheService) { }
+  constructor(private cacheService: CacheService) {}
   private breakPointInfo: any;
   private logger: Logger = new Logger('GetRouterService');
 
@@ -216,7 +216,7 @@ export class GetRouterService 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),
     );
   }
 }

+ 1 - 0
src/meta.gateway.ts

@@ -98,6 +98,7 @@ export class MetaGateway
       portRangeBegin: portRangeBegin,
       portRangeEnd: portRangeEnd,
       iceServers: stun_server,
+      enableIceTcp: true,
     });
 
     this.peer.onLocalDescription((sdp, type) => {

+ 68 - 35
src/move/move.service.ts

@@ -35,7 +35,7 @@ export class MoveService implements OnModuleInit {
   constructor(
     private cacheService: CacheService,
     private rotateService: RotateService,
-  ) { }
+  ) {}
   private logger: Logger = new Logger('MoveService');
   private Actions = {
     Clicking: 1,
@@ -247,8 +247,8 @@ export class MoveService implements OnModuleInit {
       if (checkReplys.length > 0) {
         console.log(
           'move-1' +
-          checkReplys[checkReplys.length - 1].newUserStates[0].playerState
-            .camera.angle.yaw,
+            checkReplys[checkReplys.length - 1].newUserStates[0].playerState
+              .camera.angle.yaw,
         );
       }
       //过渡传到缓存里
@@ -321,7 +321,6 @@ export class MoveService implements OnModuleInit {
     let i;
     for (i = 1; i < moveFrames.length; i += 3) {
       const moveFrame = moveFrames[i];
-
       const reply = JSON.parse(JSON.stringify(this.reply));
       reply.traceIds.push(traceId);
       reply['newUserStates'][0].userId = userId;
@@ -355,7 +354,7 @@ export class MoveService implements OnModuleInit {
         moveFrame.camera_angle;
       reply['newUserStates'][0].playerState.cameraCenter =
         reply['newUserStates'][0].playerState.player.position;
-
+      reply['newUserStates'][0].renderInfo.isMoving = 1;
       reply['actionResponses'][0].traceId = traceId;
 
       reply.mediaSrc =
@@ -570,52 +569,85 @@ export class MoveService implements OnModuleInit {
       const appId = user.appId;
 
       const replys = [];
-      const step = 1;
+      const step = 0.1;
       const closestDis = 20; //小于这个距离就跳到邻居呼吸点
       const distance = step * dir_action.speed_level;
       let angle = null;
+      console.log('joystick-1:' + JSON.stringify(user.player.position));
       // debugger;
       //TODO 临时增加断言
       const playerPosition: Point = { x: 0, y: 0, z: 0 };
       playerPosition.x =
-        user.player.position.x + distance * Math.atan(dir_action.move_angle);
+        user.player.position.x + distance * Math.tan(dir_action.move_angle);
       playerPosition.y =
-        user.player.position.y + distance * Math.tan(dir_action.move_angle);
+        user.player.position.y - distance * Math.atan(dir_action.move_angle);
 
       //找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
-      let chooseBreakPointId = null;
+      const chooseBreakPointId = null;
       const breakPoint = this.breakPointInfo[breakPointId];
       const surroundPointIds = breakPoint.contact;
       const neighAngles = [];
-      //找到和角度最贴近的邻居点
-      for (let i = 0; i < surroundPointIds.length; ++i) {
-        const neighPoint = this.breakPointInfo[surroundPointIds[i]];
-        const neighDistance = this.getDistance(
-          playerPosition,
-          neighPoint.position,
+      // //找到和角度最贴近的邻居点
+      // for (let i = 0; i < surroundPointIds.length; ++i) {
+      //   const neighPoint = this.breakPointInfo[surroundPointIds[i]];
+      //   const neighDistance = this.getDistance(
+      //     playerPosition,
+      //     neighPoint.position,
+      //   );
+      //   if (neighDistance < closestDis) {
+      //     chooseBreakPointId = surroundPointIds[i];
+      //   }
+      //   angle = -1*this.getAngle(
+      //     user.player.position,
+      //     { x: user.player.position.x + 1, y: user.player.position.y },
+      //     neighPoint.position,
+      //   );
+      //   if(angle<0){
+      //     angle += 360;
+      //   }
+      //   neighAngles.push(angle);
+      // }
+
+      // //方向不对的话,没有过渡内容
+      // if (
+      //   dir_action.move_angle > Math.max(...neighAngles) ||
+      //   dir_action.move_angle < Math.min(...neighAngles)
+      // ) {
+      //   return replys;
+      // }
+      //人物移动
+      user.player.position = JSON.parse(JSON.stringify(playerPosition));
+      user.player.angle.yaw = dir_action.move_angle;
+      if (chooseBreakPointId == null) {
+        const traceIds = [];
+        traceIds.push(traceId);
+        this.reply.traceIds = traceIds;
+        this.reply['newUserStates'][0].userId = userId;
+        this.reply['actionResponses'][0].traceId = traceId;
+
+        this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
+          JSON.stringify(playerPosition),
         );
-        if (neighDistance < closestDis) {
-          chooseBreakPointId = surroundPointIds[i];
-        }
-        angle = this.getAngle(
-          user.player.position,
-          { x: user.player.position.x + 1, y: user.player.position.y },
-          neighPoint.position,
+        this.reply['newUserStates'][0].playerState.player.angle.yaw =
+          dir_action.move_angle;
+
+        this.reply['newUserStates'][0].playerState.camera.angle = JSON.parse(
+          JSON.stringify(user.camera.angle),
+        );
+        this.reply['newUserStates'][0].playerState.camera.position = JSON.parse(
+          JSON.stringify(user.camera.position),
+        );
+        this.reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(
+          JSON.stringify(breakPoint.position),
         );
-        neighAngles.push(angle);
-      }
 
-      //方向不对的话,没有过渡内容
-      if (
-        dir_action.move_angle > Math.max(...neighAngles) ||
-        dir_action.move_angle < Math.min(...neighAngles)
-      ) {
-        return replys;
+        this.reply['newUserStates'][0].renderInfo.isMoving = 1;
+
+        this.reply['actionResponses'][0].traceId = traceId;
+        this.reply.mediaSrc = null;
+        return this.reply;
       }
 
-      //人物移动
-      user.player.position = JSON.parse(JSON.stringify(playerPosition));
-      user.player.angle.yaw = dir_action.move_angle;
       angle = user.camera.angle.yaw % 45; //纠正需要
       //通过user.camera.angle矫正相机的angle
       const checkReplys = await this.modeifyCameraAngle(
@@ -626,6 +658,7 @@ export class MoveService implements OnModuleInit {
       );
       replys.push(checkReplys);
 
+      console.log('joystick-2:' + JSON.stringify(user.player.position));
       //判断人物离该邻接点的距离是否在最小路径内,如果是,跳到这个邻接点里
       if (chooseBreakPointId != null) {
         //相机纠正
@@ -644,7 +677,7 @@ export class MoveService implements OnModuleInit {
           ':angle:' +
           Math.floor(user.camera.angle.yaw / 45);
         const moveFramesRes = await this.cacheService.get(key);
-        const moveFrames = JSON.parse(JSON.stringify(moveFramesRes));
+        const moveFrames = JSON.parse(moveFramesRes);
         const pathReplys = this.createCacheReplys(
           appId,
           moveFrames,
@@ -709,7 +742,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),
     );
   }
 }

+ 6 - 7
src/scene/scene.service.ts

@@ -25,7 +25,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;
@@ -507,9 +507,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       const joystickRes = await this.moveService.seqExeJoystick(request);
       // 有数据 [0]是rotate数据,[1-infinity]是walking数据
       if (Array.isArray(joystickRes)) {
-        // shift出前第一个镜头数据
-
-        const rotateCamData = joystickRes.shift();
+        // 处理第一个镜头数据
+        const rotateCamData = joystickRes[0];
         console.log('rotateCamData', rotateCamData.length);
         if (rotateCamData?.length) {
           // 头数组[0] rotate 序列, 头是关键key
@@ -544,8 +543,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           console.warn('joystick-move无数据');
         }
       } else {
-        console.log('转交数据');
-        // this.streamService.pushNormalDataToStream(request);
+        console.warn('joystick-接收人物数据', JSON.stringify(joystickRes));
+        this.streamService.pushNormalDataToStream(joystickRes);
       }
     } catch (error) {
       console.error('joystick错误', error);
@@ -819,7 +818,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,

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

@@ -19,7 +19,7 @@ export class StreamService {
     clipPath: '',
     metaData: '',
   });
-  constructor(private cacheService: CacheService) { }
+  constructor(private cacheService: CacheService) {}
 
   setChannel(channel: DataChannel) {
     this.channel = channel;