|
@@ -34,7 +34,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
public _rotateTimeout: NodeJS.Timeout;
|
|
|
public _moveTimeout: NodeJS.Timeout;
|
|
|
public _JoyStickingTimeout: NodeJS.Timeout;
|
|
|
- public _JoyStickingSteamTimeout: NodeJS.Timeout;
|
|
|
public startSteaming = new BehaviorSubject<boolean>(false);
|
|
|
public onRotating = new BehaviorSubject<boolean>(false);
|
|
|
public onMoving = new BehaviorSubject<boolean>(false);
|
|
@@ -103,6 +102,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
|
|
|
private isJoystickHasStream = false;
|
|
|
|
|
|
+
|
|
|
public users = {};
|
|
|
|
|
|
public sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -568,76 +568,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
*/
|
|
|
|
|
|
async handlejoystick(request: JoystickRequest) {
|
|
|
- // 二级方法start,为了 drain干complementFrame的pool
|
|
|
- const pushJoyStickSteam = async (joystickRes: StreamReplyType) => {
|
|
|
- this.holdSteam();
|
|
|
- console.log('joystickRes有mediaSrc', joystickRes.mediaSrc);
|
|
|
- const mediaSrc = joystickRes.mediaSrc.split('?')[0];
|
|
|
- // IDR flag设置为I帧
|
|
|
- const setDIR = joystickRes.moveOver || joystickRes.moveStart ? 1 : 3;
|
|
|
- // 过滤新东西, 推完给回false
|
|
|
- this.moveService.sendingFrameForJoystick = true;
|
|
|
-
|
|
|
- if (this.joystickFrameCnt === -1) {
|
|
|
- this.joystickFrameCnt = this.frameCnt.getValue();
|
|
|
- }
|
|
|
- this.joystickFrameCnt += 1;
|
|
|
- const streamData: StreamFrameType = {
|
|
|
- frame: this.joystickFrameCnt,
|
|
|
- clipPath: mediaSrc,
|
|
|
- metaData: JSON.stringify(joystickRes),
|
|
|
- serverTime: this.mockserverTime,
|
|
|
- DIR: setDIR,
|
|
|
- };
|
|
|
-
|
|
|
- const hasPush = await this.streamService.pushFrameToSteam(streamData);
|
|
|
- if (hasPush.done) {
|
|
|
- this.isJoystickHasStream = true;
|
|
|
- console.log('joystick-hasPush', hasPush);
|
|
|
- if (this.isJoystickHasStream) {
|
|
|
- await this.sleep(30);
|
|
|
- }
|
|
|
- this.moveService.sendingFrameForJoystick = false;
|
|
|
- const data = joystickRes as StreamReplyType;
|
|
|
- console.log('handlejoystick-moveOver:' + data.moveOver);
|
|
|
- if (data?.moveOver && data.moveOver) {
|
|
|
- // moveOver
|
|
|
- console.log('回传updateUser', data);
|
|
|
- // const userId = this.user_id;
|
|
|
- // 回传点暂时有问题,待修复
|
|
|
- //const breakPointId = data.endBreakPointId || data.breakPointId;
|
|
|
- //const lastReply = JSON.stringify(joystickRes);
|
|
|
- //this.moveService.updateUser(userId, breakPointId, lastReply);
|
|
|
- }
|
|
|
- clearTimeout(this._JoyStickingSteamTimeout);
|
|
|
- this._JoyStickingSteamTimeout = setTimeout(() => {
|
|
|
- // const complementFrame = this.moveService.complementFrame(
|
|
|
- // this.user_id,
|
|
|
- // ) as StreamReplyType;
|
|
|
- // console.log('has-complementFrame', complementFrame);
|
|
|
- // if (complementFrame) {
|
|
|
- // pushJoyStickSteam(complementFrame);
|
|
|
- // } else {
|
|
|
- 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;
|
|
|
- this.isJoystickHasStream = false;
|
|
|
- // }
|
|
|
- }, 200);
|
|
|
- } else {
|
|
|
- console.error('joystick-流地址有误::', joystickRes.mediaSrc);
|
|
|
- this.logger.error('joystick-流地址有误::', joystickRes.mediaSrc);
|
|
|
- this.resumeStream();
|
|
|
- }
|
|
|
-
|
|
|
- return hasPush;
|
|
|
- };
|
|
|
- // 二级方法end
|
|
|
-
|
|
|
try {
|
|
|
//const joystickRes = await this.moveService.joystick(request);
|
|
|
this._rotateCount = 0;
|
|
@@ -647,7 +577,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.moveService.users[this.user_id].breakPointId,
|
|
|
);
|
|
|
// 有数据 [0]是rotate数据,[1-infinity]是walking数据
|
|
|
- this.logger.log('joystickRes', JSON.stringify(joystickRes));
|
|
|
+ this.logger.log('joystickRes-1', joystickRes);
|
|
|
|
|
|
if (joystickRes) {
|
|
|
this.onJoysticking.next(true);
|
|
@@ -667,8 +597,71 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
),
|
|
|
);
|
|
|
if (joystickRes.mediaSrc) {
|
|
|
- pushJoyStickSteam(joystickRes);
|
|
|
+ this.holdSteam();
|
|
|
+ console.log('joystickRes有mediaSrc', joystickRes.mediaSrc);
|
|
|
+ const mediaSrc = joystickRes.mediaSrc.split('?')[0];
|
|
|
+ // IDR flag设置为I帧
|
|
|
+ const setDIR = joystickRes.moveOver || joystickRes.moveStart ? 1 : 3;
|
|
|
+ // 过滤新东西, 推完给回false
|
|
|
+ this.moveService.sendingFrameForJoystick = true;
|
|
|
+
|
|
|
+ if (this.joystickFrameCnt === -1) {
|
|
|
+ this.joystickFrameCnt = this.frameCnt.getValue();
|
|
|
+ }
|
|
|
+ this.joystickFrameCnt += 1;
|
|
|
+ const streamData: StreamFrameType = {
|
|
|
+ frame: this.joystickFrameCnt,
|
|
|
+ clipPath: mediaSrc,
|
|
|
+ metaData: JSON.stringify(joystickRes),
|
|
|
+ serverTime: this.mockserverTime,
|
|
|
+ DIR: setDIR,
|
|
|
+ };
|
|
|
+
|
|
|
+ const hasPush = await this.streamService.pushFrameToSteam(streamData);
|
|
|
+ if (hasPush.done) {
|
|
|
+ this.isJoystickHasStream = true;
|
|
|
+ console.log('joystick-hasPush', hasPush);
|
|
|
+ if (this.isJoystickHasStream) {
|
|
|
+ await this.sleep(30);
|
|
|
+ }
|
|
|
+ this.moveService.sendingFrameForJoystick = false;
|
|
|
+ const data = joystickRes as StreamReplyType;
|
|
|
+ console.log('handlejoystick-moveOver:' + data.moveOver);
|
|
|
+ if (data?.moveOver && data.moveOver) {
|
|
|
+ // moveOver
|
|
|
+ console.log('回传updateUser', data);
|
|
|
+ // const userId = this.user_id;
|
|
|
+ // 回传点暂时有问题,待修复
|
|
|
+ //const breakPointId = data.endBreakPointId || data.breakPointId;
|
|
|
+ //const lastReply = JSON.stringify(joystickRes);
|
|
|
+ //this.moveService.updateUser(userId, breakPointId, lastReply);
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ this.isJoystickHasStream = false;
|
|
|
+ }, 200);
|
|
|
+ } else {
|
|
|
+ console.error(
|
|
|
+ 'joystick-流地址有误::',
|
|
|
+ hasPush.frame,
|
|
|
+ joystickRes.mediaSrc,
|
|
|
+ );
|
|
|
+ this.logger.error(
|
|
|
+ 'joystick-流地址有误::',
|
|
|
+ hasPush.frame,
|
|
|
+ joystickRes.mediaSrc,
|
|
|
+ );
|
|
|
+ this.resumeStream();
|
|
|
+ }
|
|
|
} else {
|
|
|
+ this.logger.log('joystick-接收人物数据', this.onMoving.getValue());
|
|
|
if (!this.onMoving.getValue()) {
|
|
|
// 在非行走时接受
|
|
|
this.holdSteam();
|
|
@@ -686,15 +679,12 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
//this.logger.log('rotate', stream, Date.now());
|
|
|
const res = await this.streamService.pushMetaDataToSteam(stream);
|
|
|
if (res.done) {
|
|
|
- this.logger.log('joystick-位置流', res.frame);
|
|
|
+ this.logger.log('joystick-frame', res.frame);
|
|
|
this.frameCnt.next(res.frame);
|
|
|
clearTimeout(this._JoyStickingTimeout);
|
|
|
this._JoyStickingTimeout = setTimeout(() => {
|
|
|
- this.logger.log('joystick-位置流 opt done');
|
|
|
- this.logger.log(
|
|
|
- 'joystick-位置流 交权给空流,当前pts',
|
|
|
- res.frame,
|
|
|
- );
|
|
|
+ this.logger.log('joystick opt done');
|
|
|
+ this.logger.log('joystick 交权给空流,当前pts', res.frame);
|
|
|
// this.frameCnt.next(res.frame);
|
|
|
this.onJoysticking.next(false);
|
|
|
this.resumeStream();
|
|
@@ -711,8 +701,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
res.frame,
|
|
|
joystickRes.mediaSrc,
|
|
|
);
|
|
|
- this.onJoysticking.next(false);
|
|
|
- this.joystickFrameCnt = -1;
|
|
|
this.resumeStream();
|
|
|
}
|
|
|
}
|
|
@@ -728,6 +716,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 主要处理moving的序列动作
|
|
|
* @param seqs StreamReplyType[]
|