|
@@ -49,24 +49,65 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
private mockserverTime = Date.now() - 1653000000478;
|
|
|
private lastRenderMedia = '';
|
|
|
private frameCntSubscription: any;
|
|
|
- // private roQueueSubscription: any;
|
|
|
- // private moveQueueSubscription: any;
|
|
|
+
|
|
|
+ private roQueueSubscription: any;
|
|
|
+ private moveQueueSubscription: any;
|
|
|
private walkingSub: any;
|
|
|
|
|
|
private streamServiceSub: any;
|
|
|
-
|
|
|
+ private roQueue: RxQueue = new DelayQueue(100);
|
|
|
private clickQueue: RxQueue = new DebounceQueue(500);
|
|
|
- private moveQueue: RxQueue = new DelayQueue(100);
|
|
|
+ private moveQueue: RxQueue = new DelayQueue(600);
|
|
|
private rotateTimeStamp: number;
|
|
|
private lastMoveCnt = -1;
|
|
|
|
|
|
private firstRender = false;
|
|
|
+ private currentMoveMaker = '';
|
|
|
|
|
|
public lastMoveStreamFrame = new BehaviorSubject<StreamFrameType>({
|
|
|
frame: -1,
|
|
|
clipPath: '',
|
|
|
metaData: '',
|
|
|
});
|
|
|
+ public users = {};
|
|
|
+
|
|
|
+ initUsers(app_id, userId) {
|
|
|
+ const user = {
|
|
|
+ appId: null,
|
|
|
+ userId: null,
|
|
|
+ breakPointId: null,
|
|
|
+ roomId: null,
|
|
|
+ player: {
|
|
|
+ position: { x: -700, y: 0, z: 0 },
|
|
|
+ angle: {
|
|
|
+ pitch: 0,
|
|
|
+ yaw: 0,
|
|
|
+ roll: 0,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ camera: {
|
|
|
+ position: { x: -1145, y: 0, z: 160 },
|
|
|
+ angle: {
|
|
|
+ pitch: 0,
|
|
|
+ yaw: 0,
|
|
|
+ roll: 0,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ rotateInfo: {
|
|
|
+ frameIndex: 0,
|
|
|
+ horizontal_move: 0,
|
|
|
+ mediaSrc: null,
|
|
|
+ },
|
|
|
+ moveInfo: {},
|
|
|
+ // traceIds: [],
|
|
|
+ // actionResponses:[]
|
|
|
+ };
|
|
|
+
|
|
|
+ user.appId = app_id;
|
|
|
+ user.userId = userId;
|
|
|
+ user.breakPointId = 100;
|
|
|
+ this.users[userId] = user;
|
|
|
+ }
|
|
|
|
|
|
onModuleInit(): void {
|
|
|
this.sceneGrpcService =
|
|
@@ -80,6 +121,13 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ public getConfig() {
|
|
|
+ return {
|
|
|
+ userId: this.user_id,
|
|
|
+ roomId: this.roomId,
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
public startStream(): void {
|
|
|
clearInterval(this._frameInteval);
|
|
|
if (this.frameCnt.value === -1) {
|
|
@@ -110,14 +158,14 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.frameCntSubscription.unsubscribe();
|
|
|
this.frameCntSubscription = null;
|
|
|
}
|
|
|
- // if (this.roQueueSubscription) {
|
|
|
- // this.roQueueSubscription.unsubscribe();
|
|
|
- // this.roQueueSubscription = null;
|
|
|
- // }
|
|
|
- // if (this.moveQueueSubscription) {
|
|
|
- // this.moveQueueSubscription.unsubscribe();
|
|
|
- // this.moveQueueSubscription = null;
|
|
|
- // }
|
|
|
+ if (this.roQueueSubscription) {
|
|
|
+ this.roQueueSubscription.unsubscribe();
|
|
|
+ this.roQueueSubscription = null;
|
|
|
+ }
|
|
|
+ if (this.moveQueueSubscription) {
|
|
|
+ this.moveQueueSubscription.unsubscribe();
|
|
|
+ this.moveQueueSubscription = null;
|
|
|
+ }
|
|
|
this.frameCnt.next(-1);
|
|
|
clearInterval(this._frameInteval);
|
|
|
this.rotateframeCnt = -1;
|
|
@@ -148,7 +196,11 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// console.log('initReply', reply);
|
|
|
// });
|
|
|
this.rotateService.init(request.app_id, request.user_id);
|
|
|
- this.moveService.init(request.app_id, request.user_id);
|
|
|
+ // this.moveService.init(request.app_id, request.user_id);
|
|
|
+
|
|
|
+ // this.initUsers(request.app_id, request.user_id);
|
|
|
+ this.rotateQueue.empty();
|
|
|
+ this.walkingQueue.empty();
|
|
|
} catch (error) {
|
|
|
console.log('error', error);
|
|
|
}
|
|
@@ -211,23 +263,24 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
const clipPath = join(__dirname, `../ws/video/${src}`);
|
|
|
// console.log('src-clipPath', src, clipPath);
|
|
|
delete redisMeta.mediaSrc;
|
|
|
- if (this.rotateframeCnt === -1) {
|
|
|
- this.rotateframeCnt = this.frameCnt.value;
|
|
|
- }
|
|
|
- this.rotateframeCnt += 1;
|
|
|
- const random_boolean = Math.random() < 0.5;
|
|
|
+ // if (this.rotateframeCnt === -1) {
|
|
|
+ // this.rotateframeCnt = this.frameCnt.value;
|
|
|
+ // }
|
|
|
+ const nextFrame = this.frameCnt.getValue() + 1;
|
|
|
+ this.frameCnt.next(nextFrame);
|
|
|
+ const random_boolean = Math.random() < 0.3;
|
|
|
|
|
|
const stream: StreamFrameType = {
|
|
|
- frame: this.rotateframeCnt,
|
|
|
+ frame: this.frameCnt.getValue(),
|
|
|
clipPath: clipPath,
|
|
|
metaData: JSON.stringify(redisMeta),
|
|
|
serverTime: this.mockserverTime,
|
|
|
DIR: random_boolean ? 1 : 3,
|
|
|
};
|
|
|
this.rotateQueue.add(stream, {
|
|
|
- delay: 5,
|
|
|
- jobId: `rotate:${this.user_id}:${this.rotateframeCnt}`,
|
|
|
- // lifo: true,
|
|
|
+ delay: 10,
|
|
|
+ jobId: `rotate:${this.user_id}:${this.frameCnt.getValue()}`,
|
|
|
+ removeOnComplete: true,
|
|
|
});
|
|
|
} else {
|
|
|
this.onRotating.next(false);
|
|
@@ -308,22 +361,23 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
}
|
|
|
|
|
|
async handleIframeRequest() {
|
|
|
- // const lastStreamFrame = this.streamService.lastStreamFrame.getValue();
|
|
|
- // lastStreamFrame.DIR = 1;
|
|
|
- // console.log('lastStreamFrame', lastStreamFrame);
|
|
|
+ const lastStreamFrame = this.streamService.lastStreamFrame.getValue();
|
|
|
+ lastStreamFrame.DIR = 1;
|
|
|
+ console.log('lastStreamFrame', lastStreamFrame);
|
|
|
const nextFrame = this.frameCnt.getValue() + 1;
|
|
|
- // lastStreamFrame.frame = nextFrame;
|
|
|
- // this.streamService.pushFrameToSteam(lastStreamFrame);
|
|
|
-
|
|
|
- const redisDataAuto = await this.rotateService.echo(this.user_id);
|
|
|
- if (redisDataAuto) {
|
|
|
- 'mediaSrc' in redisDataAuto && delete redisDataAuto.mediaSrc;
|
|
|
- const streamMeta: StreamMetaType = {
|
|
|
- frame: nextFrame,
|
|
|
- metaData: JSON.stringify(redisDataAuto),
|
|
|
- };
|
|
|
- this.streamService.pushMetaDataToSteam(streamMeta);
|
|
|
- }
|
|
|
+ lastStreamFrame.frame = nextFrame;
|
|
|
+ this.frameCnt.next(nextFrame);
|
|
|
+ this.streamService.pushFrameToSteam(lastStreamFrame);
|
|
|
+
|
|
|
+ // const redisDataAuto = await this.rotateService.echo(this.user_id);
|
|
|
+ // if (redisDataAuto) {
|
|
|
+ // 'mediaSrc' in redisDataAuto && delete redisDataAuto.mediaSrc;
|
|
|
+ // const streamMeta: StreamMetaType = {
|
|
|
+ // frame: nextFrame,
|
|
|
+ // metaData: JSON.stringify(redisDataAuto),
|
|
|
+ // };
|
|
|
+ // this.streamService.pushMetaDataToSteam(streamMeta);
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
async walking(req) {
|
|
@@ -338,49 +392,63 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
req.clicking_action.clicking_point,
|
|
|
);
|
|
|
const walkingRes = await this.moveService.move(path, request);
|
|
|
- // console.log('walkingRes', walkingRes);
|
|
|
+ // this.moveService.rotateForAngle();
|
|
|
+ console.log('walkingRes', walkingRes);
|
|
|
+ // debugger;
|
|
|
+
|
|
|
if (walkingRes && !this.onMoving.value) {
|
|
|
- this.onMoving.next(true);
|
|
|
- this.holdSteam();
|
|
|
- // if (!this.moveQueueSubscription) {
|
|
|
- // this.handleMoveSteam();
|
|
|
- // }
|
|
|
- if (this.moveframeCnt === -1) {
|
|
|
- this.moveframeCnt = this.frameCnt.value;
|
|
|
- }
|
|
|
|
|
|
- const res = Object.keys(walkingRes).map((item) => {
|
|
|
- console.log('item', item);
|
|
|
- return Array.from(walkingRes[item]).map((i) => {
|
|
|
- i['marker'] = item;
|
|
|
- return i;
|
|
|
- });
|
|
|
- });
|
|
|
+ // walkingRes marker to everybody
|
|
|
+ const res: ArrayLike<unknown> = Object.keys(walkingRes).map(
|
|
|
+ (item) => {
|
|
|
+ console.log('item', item);
|
|
|
+ return Array.from(walkingRes[item]).map((i) => {
|
|
|
+ i['marker'] = item;
|
|
|
+ return i;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ );
|
|
|
+ //
|
|
|
const seqs = Array.from(res).flat();
|
|
|
- // this.lastMoveCnt = this.frameCnt.value + seqs.length;
|
|
|
- seqs.forEach((frame: StreamReplyType) => {
|
|
|
- const mediaSrc = frame.mediaSrc;
|
|
|
- let src = mediaSrc.split('?')[0];
|
|
|
- // 临时本地替换路经
|
|
|
- src = src.replace('/0000000001/', '');
|
|
|
- const clipPath = join(__dirname, `../ws/video/${src}`);
|
|
|
- this.moveframeCnt += 1;
|
|
|
- delete frame.mediaSrc;
|
|
|
- const stream: StreamFrameType = {
|
|
|
- frame: this.moveframeCnt,
|
|
|
- clipPath: clipPath,
|
|
|
- metaData: JSON.stringify(frame),
|
|
|
- serverTime: this.mockserverTime,
|
|
|
- DIR: 1,
|
|
|
- };
|
|
|
|
|
|
- this.walkingQueue.add(stream, {
|
|
|
- delay: 5,
|
|
|
- jobId: `walking:${this.user_id}:${this.moveframeCnt}`,
|
|
|
- // lifo: true,
|
|
|
+ if (seqs?.length) {
|
|
|
+ if (!this.moveQueueSubscription) {
|
|
|
+ this.handleMoveSteam();
|
|
|
+ }
|
|
|
+ console.log('walking-seqs', seqs);
|
|
|
+ this.onMoving.next(true);
|
|
|
+ this.holdSteam();
|
|
|
+ // if (this.moveframeCnt === -1) {
|
|
|
+ // this.moveframeCnt = this.frameCnt.value;
|
|
|
+ // }
|
|
|
+ this.moveframeCnt = this.frameCnt.value;
|
|
|
+ seqs.forEach((frame: StreamReplyType) => {
|
|
|
+ const mediaSrc = frame.mediaSrc;
|
|
|
+ let src = mediaSrc.split('?')[0];
|
|
|
+ // 临时本地替换路经
|
|
|
+ src = src.replace('/0000000001/', '');
|
|
|
+ const clipPath = join(__dirname, `../ws/video/${src}`);
|
|
|
+ this.moveframeCnt += 1;
|
|
|
+ delete frame.mediaSrc;
|
|
|
+ const stream: StreamFrameType = {
|
|
|
+ frame: this.moveframeCnt,
|
|
|
+ clipPath: clipPath,
|
|
|
+ metaData: JSON.stringify(frame),
|
|
|
+ serverTime: this.mockserverTime,
|
|
|
+ DIR: 1,
|
|
|
+ };
|
|
|
+
|
|
|
+ // this.walkingQueue.add(stream, {
|
|
|
+ // delay: 10,
|
|
|
+ // jobId: `walking:${this.user_id}:${this.moveframeCnt}`,
|
|
|
+ // // lifo: true,
|
|
|
+ // });
|
|
|
+ this.moveQueue.next(stream);
|
|
|
});
|
|
|
- // this.moveQueue.next(stream);
|
|
|
- });
|
|
|
+ } else {
|
|
|
+ console.log('walking无数据');
|
|
|
+ }
|
|
|
+ // this.lastMoveCnt = this.frameCnt.value + seqs.length;
|
|
|
}
|
|
|
});
|
|
|
} catch (error) {
|
|
@@ -518,60 +586,55 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// );
|
|
|
// }
|
|
|
|
|
|
- // cleanMoveSteam() {
|
|
|
- // if (this.moveQueueSubscription) {
|
|
|
- // this.moveQueueSubscription.unsubscribe();
|
|
|
- // this.lastMoveCnt = -1;
|
|
|
- // this.moveQueueSubscription = null;
|
|
|
- // }
|
|
|
- // if (this.walkingSub) {
|
|
|
- // this.walkingSub.unsubscribe();
|
|
|
- // this.walkingSub = null;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // handleMoveSteam() {
|
|
|
- // this.moveQueueSubscription = this.moveQueue.subscribe(
|
|
|
- // async (stream: StreamFrameType) => {
|
|
|
- // const metaData: StreamReplyType = JSON.parse(stream.metaData);
|
|
|
- // console.log('handleMoveSteam-onMoving', this.onMoving);
|
|
|
- // stream.marker = metaData.marker;
|
|
|
- // this.lastMoveStreamFrame.next(stream);
|
|
|
- // const next = this.frameCnt.value + 1;
|
|
|
- // this.currentMoveMaker = metaData.marker;
|
|
|
- // if (this.onMoving) {
|
|
|
- // this.frameCnt.next(next);
|
|
|
- // } else {
|
|
|
- // console.log('handleMoveSteam stop', next, this.currentMoveMaker);
|
|
|
- // this.cleanMoveSteam();
|
|
|
- // this.resumeStream(next);
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // let src = stream.clipPath.split('?')[0];
|
|
|
- // // // 临时本地替换路经
|
|
|
- // src = src.replace('/0000000001/', '');
|
|
|
- // const clipPath = path.join(__dirname, `../ws/video/${src}`);
|
|
|
-
|
|
|
- // const streamData: StreamFrameType = {
|
|
|
- // frame: next,
|
|
|
- // clipPath: clipPath,
|
|
|
- // metaData: stream.metaData,
|
|
|
- // serverTime: this.mockserverTime,
|
|
|
- // DIR: 3,
|
|
|
- // };
|
|
|
- // await this.streamService.pushFrameToSteam(streamData);
|
|
|
-
|
|
|
- // if (this.lastMoveCnt == this.frameCnt.getValue()) {
|
|
|
- // const next = this.frameCnt.getValue() + 1;
|
|
|
- // console.log('last', next);
|
|
|
- // this.resumeStream(next);
|
|
|
- // this.cleanMoveSteam();
|
|
|
- // const lastFrame = this.lastMoveStreamFrame.getValue();
|
|
|
- // const userId = this.user_id;
|
|
|
- // const breakPointId = lastFrame.marker.split('T')[1];
|
|
|
- // const lastReply = JSON.parse(lastFrame.metaData);
|
|
|
- // this.moveService.updateUser(userId, breakPointId, lastReply);
|
|
|
- // }
|
|
|
- // },
|
|
|
- // );
|
|
|
- // }
|
|
|
+ cleanMoveSteam() {
|
|
|
+ if (this.moveQueueSubscription) {
|
|
|
+ this.moveQueueSubscription.unsubscribe();
|
|
|
+ this.lastMoveCnt = -1;
|
|
|
+ this.moveQueueSubscription = null;
|
|
|
+ }
|
|
|
+ if (this.walkingSub) {
|
|
|
+ this.walkingSub.unsubscribe();
|
|
|
+ this.walkingSub = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ handleMoveSteam() {
|
|
|
+ this.moveQueueSubscription = this.moveQueue.subscribe(
|
|
|
+ async (stream: StreamFrameType) => {
|
|
|
+ const metaData: StreamReplyType = JSON.parse(stream.metaData);
|
|
|
+ console.log('handleMoveSteam-onMoving', this.onMoving.value);
|
|
|
+ stream.marker = metaData.marker;
|
|
|
+ this.lastMoveStreamFrame.next(stream);
|
|
|
+ const next = this.frameCnt.value + 1;
|
|
|
+ this.currentMoveMaker = metaData.marker;
|
|
|
+ if (this.onMoving) {
|
|
|
+ this.frameCnt.next(next);
|
|
|
+ } else {
|
|
|
+ console.log('handleMoveSteam stop', next, this.currentMoveMaker);
|
|
|
+ this.cleanMoveSteam();
|
|
|
+ this.resumeStream();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const streamData: StreamFrameType = {
|
|
|
+ frame: next,
|
|
|
+ clipPath: stream.clipPath,
|
|
|
+ metaData: stream.metaData,
|
|
|
+ serverTime: this.mockserverTime,
|
|
|
+ DIR: 3,
|
|
|
+ };
|
|
|
+ await this.streamService.pushFrameToSteam(streamData);
|
|
|
+
|
|
|
+ if (this.lastMoveCnt == this.frameCnt.getValue()) {
|
|
|
+ const next = this.frameCnt.getValue() + 1;
|
|
|
+ console.log('last', next);
|
|
|
+ this.resumeStream();
|
|
|
+ this.cleanMoveSteam();
|
|
|
+ const lastFrame = this.lastMoveStreamFrame.getValue();
|
|
|
+ const userId = this.user_id;
|
|
|
+ const breakPointId = lastFrame.marker.split('T')[1];
|
|
|
+ const lastReply = JSON.parse(lastFrame.metaData);
|
|
|
+ this.moveService.updateUser(userId, breakPointId, lastReply);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|