gemercheung vor 3 Jahren
Ursprung
Commit
fe3a030f20
1 geänderte Dateien mit 80 neuen und 24 gelöschten Zeilen
  1. 80 24
      src/scene/scene.service.ts

+ 80 - 24
src/scene/scene.service.ts

@@ -13,7 +13,7 @@ import { CacheService } from 'src/cache/cache.service';
 import { StreamService } from './stream/stream.service';
 
 const frameMetaReply = {
-  traceIds: [],
+  traceIds: [''],
   vehicle: null,
   newUserStates: [
     {
@@ -91,6 +91,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   private onSteaming = false;
   private testFrame = -1;
   private RotateframeCnt = -1;
+  private mockserverTime = Date.now() - 1653000000478;
 
   setConfig(user_id: string, roomId: string) {
     this.user_id = user_id;
@@ -153,6 +154,58 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   async rotate(request: RotateRequest) {
     try {
       // const reply = this.sceneGrpcService.rotate(request);
+      if (!this.onSteaming) {
+        this.RotateframeCnt = this.frameCnt;
+        const redisMeta = await this.cacheService.rpop(
+          `updateFrameMetadata:${this.user_id}`,
+        );
+        console.log('rotate信息', this.user_id, request);
+        // console.log('rotate.user_id', this.user_id, redisMeta);
+        if (redisMeta && redisMeta.length > 0) {
+          const meta = JSON.parse(redisMeta);
+          const mediaSrc: string = meta.mediaSrc || '';
+
+          console.log('meta', meta);
+          console.log('mediaSrc', mediaSrc);
+
+          if (mediaSrc.length > 0) {
+            this.frameCnt += 1;
+            // this.onSteaming = true;
+            const src = meta.mediaSrc.split('?')[0];
+            const testclipPath = src.replace(
+              '/mnt/oss/metaverse/scene/0000000001/100/',
+              '',
+            );
+            console.log('testclipPath', testclipPath);
+            const demoPath = path.join(
+              __dirname,
+              `../ws/video/${testclipPath}`,
+            );
+            delete meta.mediaSrc;
+            const stream: StreamFrameType = {
+              frame: this.frameCnt,
+              clipPath: demoPath,
+              metaData: JSON.stringify(meta),
+              serverTime: this.mockserverTime,
+              DIR: 3,
+            };
+            this.streamService.pushFrameToSteam(stream);
+          }
+        }
+      }
+
+      // reply.subscribe((res: NormalReply) => {
+      //   if (res.code === 200) {
+      //   }
+      // });
+    } catch (error) {
+      this.logger.error('rotate', error);
+    }
+  }
+
+  async rotatebk(request: RotateRequest) {
+    try {
+      const reply = this.sceneGrpcService.rotate(request);
       const res = await this.cacheService.publish(
         'test',
         JSON.stringify(request),
@@ -216,10 +269,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
           }
         }
       }
-      // reply.subscribe((res: NormalReply) => {
-      //   if (res.code === 200) {
-      //   }
-      // });
+      reply.subscribe((res: NormalReply) => {
+        if (res.code === 200) {
+        }
+      });
     } catch (error) {
       this.logger.error('rotate', error);
     }
@@ -281,12 +334,14 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
   walking(request) {
     console.log('walking', request);
+    console.log('walking-onSteaming', this.onSteaming);
+
     const walk1 = {
       traceIds: [request.trace_id],
       vehicle: null,
       newUserStates: [
         {
-          userId: '31251ce814121',
+          userId: request.user_id,
           playerState: {
             roomTypeId: '',
             person: 0,
@@ -359,24 +414,25 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       code: 0,
       msg: 'OK',
     };
+    this.frameCnt += 1;
     const stream: StreamFrameType = {
       frame: this.frameCnt,
       clipPath: path.join(__dirname, `../ws/video/2.h264`),
       metaData: JSON.stringify(walk1),
-      serverTime: Date.now(),
-      DIR: 1,
+      serverTime: this.mockserverTime,
+      DIR: 3,
     };
     console.log('walking', this.frameCnt, stream.clipPath);
     this.streamService.pushFrameToSteam(stream);
   }
 
   handleBreath(request) {
-    console.log('request', request);
+    // console.log('handleBreath', request);
     const nps = {
       actionType: 1004,
       pointType: 100,
       extra: '',
-      traceId: 'bd152140-d352-4ad7-8f4c-d0246659372c',
+      traceId: request.trace_id,
       packetId: '',
       nps: [
         { x: 235, y: -1791.875, z: -0.25 },
@@ -503,7 +559,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   }
 
   async updateUserStatus(request) {
-    console.log('1024', request);
+    // console.log('1024', request);
     const reply = {
       actionType: 1024,
       pointType: 100,
@@ -575,20 +631,20 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       code: 0,
       msg: '',
     };
-    const redisMeta = await this.cacheService.rpop(
-      `updateFrameMetadata:${this.user_id}`,
-    );
+    // const redisMeta = await this.cacheService.rpop(
+    //   `updateFrameMetadata:${this.user_id}`,
+    // );
     //TODO 接入redis数据
-    console.log('redisMeta', redisMeta);
-    if (redisMeta && redisMeta.length > 0) {
-      const meta = JSON.parse(redisMeta);
-      'mediaSrc' in meta && delete meta.mediaSrc;
-      meta.action_type = 1024;
-      this.streamService.pushNormalDataToStream(meta);
-    } else {
-      this.streamService.pushNormalDataToStream(reply);
-    }
-    // this.streamService.pushNormalDataToStream(reply);
+    // console.log('redisMeta', redisMeta);
+    // if (redisMeta && redisMeta.length > 0) {
+    //   const meta = JSON.parse(redisMeta);
+    //   'mediaSrc' in meta && delete meta.mediaSrc;
+    //   meta.action_type = 1024;
+    //   this.streamService.pushNormalDataToStream(meta);
+    // } else {
+    //   this.streamService.pushNormalDataToStream(reply);
+    // }
+    this.streamService.pushNormalDataToStream(reply);
   }
   handleStartCountingFrame() {
     this._frameInteval = setInterval(async () => {