test pc 3 سال پیش
والد
کامیت
3f3374673e

+ 0 - 1
src/app.module.ts

@@ -14,7 +14,6 @@ import {
 } from 'nest-winston';
 // import * as winston from 'winston';
 // import { join } from 'path';
-
 @Module({
   imports: [
     ConfigModule.forRoot({ isGlobal: true, load: [configuration] }),

+ 44 - 11
src/move/move.service.ts

@@ -45,8 +45,8 @@ export class MoveService implements OnModuleInit {
     traceIds: [],
     vehicle: null,
     mediaSrc: null,
-    moveOver:false,
-    moveStart:false,
+    moveOver: false,
+    moveStart: false,
     newUserStates: [
       {
         userId: 'dcff36ae4fc1d',
@@ -1011,6 +1011,7 @@ export class MoveService implements OnModuleInit {
 
         if (cameraInfo.mediaSrc) {
           this.reply.mediaSrc = cameraInfo.mediaSrc;
+<<<<<<< HEAD
         } 
         // if (this.cameraInfos.length == 0) {
         //   this.reply.moveOver = true;
@@ -1021,6 +1022,12 @@ export class MoveService implements OnModuleInit {
         );
         user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
 
+=======
+        }
+        if (this.cameraInfos.length == 0) {
+          this.reply.moveOver = true;
+        }
+>>>>>>> 7a74beedb6f8bfe0401e0fc837cd96cd26026949
         this.sendingFrameForJoystick = true;
       } else {
         console.log('joystick自由--->不合并');
@@ -1087,6 +1094,7 @@ export class MoveService implements OnModuleInit {
 
         if (cameraInfo.mediaSrc) {
           this.reply.mediaSrc = cameraInfo.mediaSrc;
+<<<<<<< HEAD
         } 
         // if (this.cameraInfos.length == 0) {
         //   this.reply.moveOver = true;
@@ -1097,6 +1105,12 @@ export class MoveService implements OnModuleInit {
         );
         user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
         
+=======
+        }
+        if (this.cameraInfos.length == 0) {
+          this.reply.moveOver = true;
+        }
+>>>>>>> 7a74beedb6f8bfe0401e0fc837cd96cd26026949
         this.sendingFrameForJoystick = true;
       }
       return this.reply;
@@ -1178,7 +1192,7 @@ export class MoveService implements OnModuleInit {
 
         if (cameraInfo.mediaSrc) {
           this.reply.mediaSrc = cameraInfo.mediaSrc;
-        } 
+        }
         this.reply.moveStart = true;
         this.sendingFrameForJoystick = true;
       }
@@ -1186,10 +1200,23 @@ export class MoveService implements OnModuleInit {
     }
   }
 
-  setCameraInfo(appId,moveFrames,startBreakPointId,endBreakPointId) {
+  setCameraInfo(appId, moveFrames, startBreakPointId, endBreakPointId) {
     for (let i = 0; i < moveFrames.length; i += 5) {
       moveFrames[i].endBreakPointId = endBreakPointId;
-      moveFrames[i].mediaSrc =  '/' + appId +'/' + startBreakPointId +'/' + moveFrames[i].file_name.substring( 0, moveFrames[i].file_name.indexOf('.'), ) + '/' +moveFrames[i].file_name + '?m=' +new Date().getTime();
+      moveFrames[i].mediaSrc =
+        '/' +
+        appId +
+        '/' +
+        startBreakPointId +
+        '/' +
+        moveFrames[i].file_name.substring(
+          0,
+          moveFrames[i].file_name.indexOf('.'),
+        ) +
+        '/' +
+        moveFrames[i].file_name +
+        '?m=' +
+        new Date().getTime();
       this.cameraInfos.push(moveFrames[i]);
     }
   }
@@ -1211,14 +1238,15 @@ export class MoveService implements OnModuleInit {
     }
   }
 
-  complementFrame(userId){
+  complementFrame(userId) {
     if (this.cameraInfos.length > 0) {
       const user = this.users[userId];
       const cameraInfo = this.cameraInfos.shift();
       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),
       );
@@ -1234,18 +1262,23 @@ export class MoveService implements OnModuleInit {
       );
       this.reply['newUserStates'][0].renderInfo.isMoving = 0;
       this.reply['actionResponses'][0].traceId = null;
-      
+
       if (cameraInfo.mediaSrc) {
         this.reply.mediaSrc = cameraInfo.mediaSrc;
-      } 
+      }
 
+<<<<<<< HEAD
       // if(this.cameraInfos.length == 0){
       //   this.reply.moveOver = true;
       // }
       this.sendingFrameForJoystick = true;
+=======
+      if (this.cameraInfos.length == 0) {
+        this.reply.moveOver = true;
+      }
+>>>>>>> 7a74beedb6f8bfe0401e0fc837cd96cd26026949
       return this.reply;
-    } 
-    else {
+    } else {
       return null;
     }
   }

+ 10 - 6
src/scene/scene.module.ts

@@ -10,7 +10,7 @@ import { StreamService } from './stream/stream.service';
 import { RotateService } from '../rotate/rotate.service';
 import { MoveService } from '../move/move.service';
 import { GetRouterService } from 'src/get-router/get-router.service';
-
+import { StreamWorkerService } from './stream-worker/stream-worker.service';
 @Module({
   imports: [
     CacheModule,
@@ -31,14 +31,18 @@ import { GetRouterService } from 'src/get-router/get-router.service';
     // WalkingConsumer,
     MoveService,
     GetRouterService,
+    StreamWorkerService,
+  ],
+  exports: [
+    SceneService,
+    CacheService,
+    RotateService,
+    MoveService,
+    StreamWorkerService,
   ],
-  exports: [SceneService, CacheService, RotateService, MoveService],
 })
 export class SceneModule implements OnModuleInit {
   onModuleInit() {
-    // BullModule.registerQueue({
-    //   configKey: 'rotate-queue',
-    //   name: 'rotate',
-    // });
+    //
   }
 }

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

@@ -628,9 +628,23 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               // 回传点暂时有问题,待修复
               const breakPointId = data.endBreakPointId || data.breakPointId;
               const lastReply = JSON.stringify(joystickRes);
+<<<<<<< HEAD
               //this.moveService.updateUser(userId, breakPointId, lastReply);
               this.resumeStream();
+=======
+              this.moveService.updateUser(userId, breakPointId, lastReply);
+>>>>>>> 7a74beedb6f8bfe0401e0fc837cd96cd26026949
             }
+            clearTimeout(this._JoyStickingTimeout);
+            this._JoyStickingTimeout = setTimeout(() => {
+              this.frameCnt.next(hasPush.frame);
+              this.logger.log('joystick opt done');
+              this.logger.log('joystick 交权给空流,当前pts', hasPush.frame);
+              // this.frameCnt.next(res.frame);
+              this.onJoysticking.next(false);
+              this.resumeStream();
+              this.joystickFrameCnt = -1;
+            }, 200);
           } else {
             console.error(
               'joystick-流地址有误::',
@@ -673,7 +687,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
                 this.onJoysticking.next(false);
                 this.resumeStream();
                 this.joystickFrameCnt = -1;
-              }, 50);
+              }, 200);
             } else {
               console.error(
                 'joystick-位置流有误::',

+ 18 - 0
src/scene/stream-worker/stream-worker.service.spec.ts

@@ -0,0 +1,18 @@
+import { Test, TestingModule } from '@nestjs/testing';
+import { StreamWorkerService } from './stream-worker.service';
+
+describe('StreamWorkerService', () => {
+  let service: StreamWorkerService;
+
+  beforeEach(async () => {
+    const module: TestingModule = await Test.createTestingModule({
+      providers: [StreamWorkerService],
+    }).compile();
+
+    service = module.get<StreamWorkerService>(StreamWorkerService);
+  });
+
+  it('should be defined', () => {
+    expect(service).toBeDefined();
+  });
+});

+ 4 - 0
src/scene/stream-worker/stream-worker.service.ts

@@ -0,0 +1,4 @@
+import { Injectable } from '@nestjs/common';
+
+@Injectable()
+export class StreamWorkerService {}

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

@@ -6,14 +6,12 @@ import * as streamBuffers from 'stream-buffers';
 import { BehaviorSubject } from 'rxjs';
 import { CacheService } from 'src/cache/cache.service';
 import { join } from 'path';
-import { SceneService } from '../scene.service';
 
 @Injectable()
 export class StreamService {
   private channel: DataChannel;
   private readonly chunk_size = 16000;
   private readonly block = 36;
-  private SceneService: SceneService;
   private logger: Logger = new Logger('StreamService');
   public onSteaming = new BehaviorSubject<boolean>(false);
   public lastStreamFrame = new BehaviorSubject<StreamFrameType>({
@@ -21,7 +19,8 @@ export class StreamService {
     clipPath: '',
     metaData: '',
   });
-  // constructor() {}
+
+  // constructor() { }
 
   setChannel(channel: DataChannel) {
     this.channel = channel;
@@ -213,6 +212,7 @@ export class StreamService {
           if (this.onSteaming.value) {
             this.onSteaming.next(false);
           }
+
           return resolve({ frame: stream.frame, done: true });
         });
         steam.on('error', (error) => {