gemercheung 3 лет назад
Родитель
Сommit
767fdba2ad
1 измененных файлов с 39 добавлено и 12 удалено
  1. 39 12
      src/scene/scene.service.ts

+ 39 - 12
src/scene/scene.service.ts

@@ -569,7 +569,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
 
   async handlejoystick(request: JoystickRequest) {
     // 二级方法start,为了 drain干complementFrame的pool
-    const pushJoyStickSteam = async (joystickRes: StreamReplyType) => {
+    const pushJoyStickSteam = async (
+      joystickRes: StreamReplyType,
+      _noNeedSleep = false,
+    ) => {
       this.holdSteam();
       console.log('joystickRes有mediaSrc', joystickRes.mediaSrc);
       const mediaSrc = joystickRes.mediaSrc.split('?')[0];
@@ -594,7 +597,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       if (hasPush.done) {
         this.isJoystickHasStream = true;
         console.log('joystick-hasPush', hasPush);
-        if (this.isJoystickHasStream) {
+        if (this.isJoystickHasStream && !_noNeedSleep) {
           await this.sleep(20);
         }
         this.moveService.sendingFrameForJoystick = false;
@@ -611,7 +614,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
         }
         // 共用_JoyStickingTimeout
         clearTimeout(this._JoyStickingSteamTimeout);
-        this._JoyStickingSteamTimeout = setTimeout(() => {
+        this._JoyStickingSteamTimeout = setTimeout(async () => {
           const complementFrame = this.moveService.complementFrame(
             this.user_id,
           ) as StreamReplyType;
@@ -622,12 +625,21 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
             this.frameCnt.next(hasPush.frame);
             this.logger.log('joystick opt done');
             this.logger.log('joystick 交权给空流,当前pts', hasPush.frame);
-            this.moveService.stopJoystick(this.user_id);
+            const stopFrameData = this.moveService.stopJoystick(this.user_id);
+            const stopFrame: StreamMetaType = {
+              frame: hasPush.frame + 1,
+              metaData: JSON.stringify(stopFrameData),
+            };
+            const stopRes = await this.streamService.pushMetaDataToSteam(
+              stopFrame,
+            );
+            if (stopRes.done) {
+              this.onJoysticking.next(false);
+              this.resumeStream();
+              this.joystickFrameCnt = -1;
+              this.isJoystickHasStream = false;
+            }
             // this.frameCnt.next(res.frame);
-            this.onJoysticking.next(false);
-            this.resumeStream();
-            this.joystickFrameCnt = -1;
-            this.isJoystickHasStream = false;
           }
         }, 200);
       } else {
@@ -689,7 +701,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
               this.logger.log('joystick-位置流', res.frame);
               this.frameCnt.next(res.frame);
               clearTimeout(this._JoyStickingTimeout);
-              this._JoyStickingTimeout = setTimeout(() => {
+              this._JoyStickingTimeout = setTimeout(async () => {
                 this.logger.log('joystick-位置流 opt done');
                 this.logger.log(
                   'joystick-位置流 交权给空流,当前pts',
@@ -702,9 +714,24 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
                 // if (complementFrame) {
                 //   pushJoyStickSteam(complementFrame);
                 // } else {
-                this.moveService.stopJoystick(this.user_id);
-                this.onJoysticking.next(false);
-                this.resumeStream();
+                // this.moveService.stopJoystick(this.user_id);
+                const stopFrameData = this.moveService.stopJoystick(
+                  this.user_id,
+                );
+                const stopFrame: StreamMetaType = {
+                  frame: res.frame + 1,
+                  metaData: JSON.stringify(stopFrameData),
+                };
+                const stopRes = await this.streamService.pushMetaDataToSteam(
+                  stopFrame,
+                );
+                if (stopRes.done) {
+                  this.resumeStream();
+                  this.joystickFrameCnt = -1;
+                  this.isJoystickHasStream = false;
+                  this.onJoysticking.next(false);
+                }
+
                 // }
               }, 200);
             } else {