|
@@ -106,7 +106,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
|
|
|
private globalOptLock = false;
|
|
|
|
|
|
-
|
|
|
onModuleInit(): void {
|
|
|
this.streamServiceSub = this.streamService.onSteaming.subscribe((val) => {
|
|
|
this.onSteaming = val;
|
|
@@ -207,6 +206,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
}
|
|
|
|
|
|
async rotate(request: RotateRequest) {
|
|
|
+
|
|
|
+ if (this.isHasWalkingJoints()) {
|
|
|
+ this.globalOptLock = true;
|
|
|
+ }
|
|
|
this.handleRotate(request);
|
|
|
this._rotateCount += 1;
|
|
|
//this.logger.log('request', request)
|
|
@@ -223,84 +226,36 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// try {
|
|
|
const rotateKey = this.firstRender && !this.globalOptLock;
|
|
|
console.log('handleRotate条件--->' + rotateKey);
|
|
|
+
|
|
|
if (rotateKey) {
|
|
|
if (!this.roQueueSubscription) {
|
|
|
this.handleRotateStream();
|
|
|
}
|
|
|
- let redisMeta: StreamReplyType;
|
|
|
- this.onRotating.next(true);
|
|
|
const start = performance.now();
|
|
|
+
|
|
|
// 当move时处理 _rotateCount是移动端同时触发的问题,rotateStopThrottle是减少重复抖动stop的处理。
|
|
|
+
|
|
|
if (
|
|
|
this.onMoving.getValue() &&
|
|
|
- this._rotateCount > 5 &&
|
|
|
+ this.globalOptLock &&
|
|
|
+ // this._rotateCount > 5 &&
|
|
|
!this.rotateStopThrottle
|
|
|
) {
|
|
|
- this.rotateStopThrottle = true;
|
|
|
- const lastStreamFrame = this.lastMoveStreamFrame.getValue();
|
|
|
- this.logger.log('lastStreamFrame', JSON.stringify(lastStreamFrame));
|
|
|
- // this.logger.log(
|
|
|
- // 'lastMoveStreamFrameBk',
|
|
|
- // JSON.stringify(lastMoveStreamFrameBk),
|
|
|
- // );
|
|
|
|
|
|
- const metaData: StreamReplyType = JSON.parse(
|
|
|
- lastStreamFrame.metaData,
|
|
|
- ) as any as StreamReplyType;
|
|
|
- if (!metaData.endBreakPointId) {
|
|
|
- }
|
|
|
- console.log('stop-4', metaData.traceIds[0]);
|
|
|
- console.log('stop-5', request.trace_id);
|
|
|
- //判断request是否是新的
|
|
|
- if (metaData.traceIds.indexOf(request.trace_id) > -1) {
|
|
|
- return;
|
|
|
- }
|
|
|
- console.log('currentUser-user_id', this.user_id);
|
|
|
- const newUserStates: NewUserStatesType = metaData.newUserStates.find(
|
|
|
- (item) => item.userId === this.user_id,
|
|
|
- );
|
|
|
-
|
|
|
- const trace_id = metaData.traceIds[0];
|
|
|
- const userId = newUserStates.userId;
|
|
|
- //TODO 临时,可能数据会不对
|
|
|
- const breakPointId = metaData.endBreakPointId || metaData.breakPointId;
|
|
|
- const cameraAngle = newUserStates.playerState.camera.angle;
|
|
|
- const playerAngle = newUserStates.playerState.player.angle;
|
|
|
- this.logger.log(
|
|
|
- 'stop-data-0' +
|
|
|
- 'trace_id: ' +
|
|
|
- trace_id +
|
|
|
- 'userId:' +
|
|
|
- userId +
|
|
|
- 'breakPointId :' +
|
|
|
- breakPointId +
|
|
|
- 'cameraAngle :' +
|
|
|
- JSON.stringify(cameraAngle) +
|
|
|
- 'playerAngle: ' +
|
|
|
- JSON.stringify(playerAngle),
|
|
|
- );
|
|
|
- //debugger;
|
|
|
- console.log('moveService.stop-1:' + breakPointId);
|
|
|
- redisMeta = await this.moveService.stop(
|
|
|
- trace_id,
|
|
|
- userId,
|
|
|
- breakPointId,
|
|
|
- cameraAngle,
|
|
|
- playerAngle,
|
|
|
- );
|
|
|
- this.logger.log('stop-redisMeta', redisMeta);
|
|
|
- this.onMoving.next(false);
|
|
|
- this.cleanMoveSteam();
|
|
|
- // redisMeta = await this.rotateService.rotate(request);
|
|
|
- } else {
|
|
|
- // 正常rotate
|
|
|
- redisMeta = await this.rotateService.seqExeRotate(request);
|
|
|
+ // this.handleRotateStop(request);
|
|
|
+ debugger;
|
|
|
+
|
|
|
+ // return;
|
|
|
}
|
|
|
|
|
|
+ this.onRotating.next(true);
|
|
|
+
|
|
|
+ const redisMeta: StreamReplyType = await this.rotateService.seqExeRotate(
|
|
|
+ request,
|
|
|
+ );
|
|
|
if (redisMeta && 'mediaSrc' in redisMeta) {
|
|
|
- const mediaSrc: string = redisMeta.mediaSrc || '';
|
|
|
- if (mediaSrc.length > 0) {
|
|
|
- const src = mediaSrc.split('?')[0];
|
|
|
+ if (redisMeta.mediaSrc?.length) {
|
|
|
+ const src = redisMeta.mediaSrc.split('?')[0];
|
|
|
//this.logger.log('进入roQueue1', redisMeta.newUserStates[0].playerState.camera.angle.yaw);
|
|
|
//this.logger.log('进入roQueue2', src);
|
|
|
if (src.length > 0) {
|
|
@@ -317,10 +272,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
serverTime: this.mockserverTime,
|
|
|
DIR: 3,
|
|
|
};
|
|
|
- //this.logger.log('rotate', stream, Date.now());
|
|
|
- clearTimeout(this._rotateTimeout);
|
|
|
|
|
|
- //this.logger.log('进入roQueue3', stream.clipPath);
|
|
|
const stop = performance.now();
|
|
|
const inMillSeconds = stop - start;
|
|
|
const rounded = Number(inMillSeconds).toFixed(3);
|
|
@@ -331,7 +283,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
|
|
|
this.roQueue.next(stream);
|
|
|
} else {
|
|
|
- // this.onRotating.next(false);
|
|
|
+ this.onRotating.next(false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -347,6 +299,72 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 旋转中断逻辑
|
|
|
+ * 1. 行走间
|
|
|
+ * 1.1 行走间中断只能在每段最后一帧,当前段一定要消费掉,在未消费,globalOptLock锁rotate,消费完 rotate
|
|
|
+ * 1.2 消费完要处理点位上传,清除当前段往后的都要清掉,回调各种stop function
|
|
|
+ * 2.joystick间 complementFrame pools 解锁就可以
|
|
|
+ */
|
|
|
+ async handleRotateStop(request) {
|
|
|
+ this.rotateStopThrottle = true;
|
|
|
+ const lastStreamFrame = this.lastMoveStreamFrame.getValue();
|
|
|
+ this.logger.log('lastStreamFrame', JSON.stringify(lastStreamFrame));
|
|
|
+
|
|
|
+ const metaData: StreamReplyType = JSON.parse(
|
|
|
+ lastStreamFrame.metaData,
|
|
|
+ ) as any as StreamReplyType;
|
|
|
+ if (!metaData.endBreakPointId) {
|
|
|
+ }
|
|
|
+ console.log('stop-4', metaData.traceIds[0]);
|
|
|
+ console.log('stop-5', request.trace_id);
|
|
|
+ //判断request是否是新的
|
|
|
+ if (metaData.traceIds.indexOf(request.trace_id) > -1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.log('currentUser-user_id', this.user_id);
|
|
|
+ const newUserStates: NewUserStatesType = metaData.newUserStates.find(
|
|
|
+ (item) => item.userId === this.user_id,
|
|
|
+ );
|
|
|
+
|
|
|
+ const trace_id = metaData.traceIds[0];
|
|
|
+ const userId = newUserStates.userId;
|
|
|
+ //TODO 临时,可能数据会不对
|
|
|
+ const breakPointId = metaData.endBreakPointId || metaData.breakPointId;
|
|
|
+ const cameraAngle = newUserStates.playerState.camera.angle;
|
|
|
+ const playerAngle = newUserStates.playerState.player.angle;
|
|
|
+ this.logger.log(
|
|
|
+ 'stop-data-0' +
|
|
|
+ 'trace_id: ' +
|
|
|
+ trace_id +
|
|
|
+ 'userId:' +
|
|
|
+ userId +
|
|
|
+ 'breakPointId :' +
|
|
|
+ breakPointId +
|
|
|
+ 'cameraAngle :' +
|
|
|
+ JSON.stringify(cameraAngle) +
|
|
|
+ 'playerAngle: ' +
|
|
|
+ JSON.stringify(playerAngle),
|
|
|
+ );
|
|
|
+ //debugger;
|
|
|
+ console.log('moveService.stop-1:' + breakPointId);
|
|
|
+ const redisMeta = await this.moveService.stop(
|
|
|
+ trace_id,
|
|
|
+ userId,
|
|
|
+ breakPointId,
|
|
|
+ cameraAngle,
|
|
|
+ playerAngle,
|
|
|
+ );
|
|
|
+ this.logger.log('stop-redisMeta', redisMeta);
|
|
|
+ this.onMoving.next(false);
|
|
|
+ this.cleanMoveSteam();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 行走动作
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ */
|
|
|
async walking(request: MoveRequest) {
|
|
|
this.latestWalkingRequest = request;
|
|
|
this.logger.log('walking-trace_id', request.trace_id);
|
|
@@ -356,16 +374,20 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.latestWalkingRequest = null;
|
|
|
this.handleWalking(request);
|
|
|
}
|
|
|
-
|
|
|
- console.log('moveSliceLastFrameSub', !!this.moveSliceLastFrameSub);
|
|
|
-
|
|
|
+ this.handleWalkingJoints(request);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 一段walking每个Joints关节点
|
|
|
+ * @param request
|
|
|
+ */
|
|
|
+ handleWalkingJoints(request) {
|
|
|
// 监听每小段最后一帧
|
|
|
if (!this.moveSliceLastFrameSub) {
|
|
|
this.moveSliceLastFrameSub = this.moveSliceLastFrame.subscribe(
|
|
|
async (frame: MovingLastUpdateType) => {
|
|
|
//TODO 正在行走时,有新的reqest
|
|
|
if (frame) {
|
|
|
- //this.logger.log('行走每段最后一帧', JSON.stringify(frame));
|
|
|
+ this.logger.log('Joints', JSON.stringify(frame));
|
|
|
if (this.latestWalkingRequest && this.onMoving.value) {
|
|
|
this.logger.log('stop-data-1', frame);
|
|
|
this.moveQueueSubscription.unsubscribe();
|
|
@@ -403,11 +425,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
'walking-step-reWalking-1',
|
|
|
request.trace_id + ',' + this.latestWalkingRequest.trace_id,
|
|
|
);
|
|
|
- // 中断清除上一次最后小段队列
|
|
|
- // if (this.moveSliceLastFrameSub) {
|
|
|
- // this.moveSliceLastFrameSub.unsubscribe();
|
|
|
- // this.moveSliceLastFrameSub = null;
|
|
|
- // }
|
|
|
|
|
|
this.logger.debug('重新行走---handleReWalking');
|
|
|
console.log('重新行走---handleReWalking');
|
|
@@ -420,6 +437,23 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 清除所有的节点信信息
|
|
|
+ * @param request
|
|
|
+ */
|
|
|
+ clearWalkingJoints() {
|
|
|
+ this.moveSliceLastFrame.next(null);
|
|
|
+ this.lastMovingPointArray = [];
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 是否有行走关节点
|
|
|
+ * @returns boolean
|
|
|
+ */
|
|
|
+
|
|
|
+ isHasWalkingJoints(): boolean {
|
|
|
+ return this.lastMovingPointArray.length > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 行走队列处理器
|
|
|
* @param request MoveRequest
|
|
|
* @returns void
|
|
@@ -461,32 +495,11 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// debugger;
|
|
|
const walkingRes = await this.moveService.move(path, request);
|
|
|
|
|
|
- //this.logger.log('walking', walkingRes);
|
|
|
- // debugger;
|
|
|
- // console.log('walking:'+JSON.stringify(walkingRes))
|
|
|
- // console.log('this.onMoving.value:'+this.onMoving.value)
|
|
|
if (walkingRes && (!this.onMoving.value || this.rewalking)) {
|
|
|
- //this.logger.log('walkingRes-front', walkingRes);
|
|
|
- // shift出前第一个镜头数据
|
|
|
- const rotateCamData = walkingRes[0];
|
|
|
- this.logger.log('rotateCamData', rotateCamData.length);
|
|
|
- if (rotateCamData?.length) {
|
|
|
- // 头数组[0] rotate 序列, 头是关键key
|
|
|
- walkingRes[0].forEach((item: StreamReplyType, index: number) => {
|
|
|
- item.mType = 'rotate';
|
|
|
- // item.DIR = index === 0 ? 1 : 3;
|
|
|
- const IDRflag = (index + 1) % 5 === 0 ? 1 : 3;
|
|
|
- const dir = this.isHeaderOrLast(index, walkingRes[0].length - 1);
|
|
|
- item.DIR = dir ? 1 : IDRflag;
|
|
|
- });
|
|
|
- } else {
|
|
|
- this.logger.log('rotateCamData无数据');
|
|
|
- }
|
|
|
-
|
|
|
// 二维数组 做move 序列, move类型
|
|
|
//console.log('move-walkingRes:' + JSON.stringify(walkingRes));
|
|
|
if (walkingRes && walkingRes?.length >= 1) {
|
|
|
- for (let i = 1; i < walkingRes.length; i++) {
|
|
|
+ for (let i = 0; i <= walkingRes.length - 1; i++) {
|
|
|
Array.from(walkingRes[i]).forEach(
|
|
|
(item: StreamReplyType, index: number) => {
|
|
|
const IDRflag = index % 5 === 0 ? 1 : 3;
|
|
@@ -527,7 +540,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
const stop = performance.now();
|
|
|
const inMillSeconds = stop - start;
|
|
|
const rounded = Number(inMillSeconds).toFixed(3);
|
|
|
- //this.logger.log(`[timer]-move-入队列前:-->${rounded}ms`);
|
|
|
+ this.logger.log(`[timer]-move-入队列前:-->${rounded}ms`);
|
|
|
|
|
|
this.handleSeqMoving(seqs);
|
|
|
} else {
|
|
@@ -836,8 +849,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
const isLastFrameIndex = this.lastMovingPointArray.findIndex(
|
|
|
(item) => item.mediaSrc === metaData.mediaSrc,
|
|
|
);
|
|
|
- //this.logger.log('path-update-index', isLastFrameIndex);
|
|
|
- //每一段的最后一帧
|
|
|
+ // this.logger.log('path-update-index', isLastFrameIndex);
|
|
|
+ //关节点入库
|
|
|
if (isLastFrameIndex > -1) {
|
|
|
//this.logger.log('path-update-array', this.lastMovingPointArray);
|
|
|
const currentMeta = this.lastMovingPointArray[isLastFrameIndex];
|
|
@@ -845,9 +858,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
const breakPointId = currentMeta.metaData.endBreakPointId;
|
|
|
const lastReply = currentMeta.metaData;
|
|
|
this.moveService.updateUser(userId, breakPointId, lastReply);
|
|
|
- //debugger
|
|
|
this.lastMovingPointArray.splice(isLastFrameIndex, 1);
|
|
|
- //TODO 队列每一段最后one frame
|
|
|
this.moveSliceLastFrame.next(currentMeta);
|
|
|
}
|
|
|
|
|
@@ -912,7 +923,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
: `{"MstType":1}`;
|
|
|
const msg: RTCMessageRequest = JSON.parse(parseData);
|
|
|
this.logger.error('lostIframe-message', JSON.stringify(msg));
|
|
|
- if (msg.MstType === 0) {
|
|
|
+ if (Number(msg.MstType) === 0) {
|
|
|
this.handleIframeRequest();
|
|
|
}
|
|
|
} else {
|
|
@@ -1059,6 +1070,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.roRequestQueueSub.unsubscribe();
|
|
|
this.roRequestQueueSub = null;
|
|
|
}
|
|
|
+ this.moveQueue.clean();
|
|
|
}, 50);
|
|
|
} else {
|
|
|
console.error('流地址有误::', res.frame, JSON.stringify(res));
|