|
@@ -14,6 +14,7 @@ import { Queue } from 'bull';
|
|
|
import { RotateService } from 'src/rotate/rotate.service';
|
|
|
import { DelayQueue, RxQueue, ThrottleQueue, DebounceQueue } from 'rx-queue';
|
|
|
import { MoveService } from 'src/move/move.service';
|
|
|
+import { GetRouterService } from 'src/get-router/get-router.service';
|
|
|
|
|
|
@Injectable()
|
|
|
export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
@@ -22,6 +23,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
private streamService: StreamService,
|
|
|
private rotateService: RotateService,
|
|
|
private moveService: MoveService,
|
|
|
+ private getRouterService: GetRouterService,
|
|
|
@InjectQueue('rotate') private rotateQueue: Queue,
|
|
|
) { }
|
|
|
@Client(grpcClientOptions) private readonly client: ClientGrpc;
|
|
@@ -46,7 +48,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
private walkingSub: any;
|
|
|
|
|
|
private streamServiceSub: any;
|
|
|
- private roQueue: RxQueue = new ThrottleQueue(120);
|
|
|
+ private roQueue: RxQueue = new DelayQueue(80);
|
|
|
private clickQueue: RxQueue = new DebounceQueue(500);
|
|
|
private moveQueue: RxQueue = new DelayQueue(100);
|
|
|
private rotateTimeStamp: number;
|
|
@@ -55,6 +57,14 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
private onMoving = false;
|
|
|
private onRotating = false;
|
|
|
private firstRender = false;
|
|
|
+ private currentPoint = '';
|
|
|
+
|
|
|
+
|
|
|
+ public lastMoveStreamFrame = new BehaviorSubject<StreamFrameType>({
|
|
|
+ frame: -1,
|
|
|
+ clipPath: '',
|
|
|
+ metaData: '',
|
|
|
+ });
|
|
|
|
|
|
onModuleInit(): void {
|
|
|
this.sceneGrpcService =
|
|
@@ -153,15 +163,42 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
|
|
|
async rotate(request: RotateRequest) {
|
|
|
try {
|
|
|
- // this.rotateQueue.add(request, {
|
|
|
- // jobId: request.trace_id,
|
|
|
- // });
|
|
|
if (!this.roQueueSubscription) {
|
|
|
this.handleRotateStream();
|
|
|
}
|
|
|
if (!this.onSteaming) {
|
|
|
- this.onMoving = false;
|
|
|
- const redisMeta = await this.rotateService.rotate(request);
|
|
|
+ let redisMeta: StreamReplyType;
|
|
|
+ this.onRotating = true;
|
|
|
+ if (this.onMoving) {
|
|
|
+ const lastStreamFrame = this.lastMoveStreamFrame.getValue();
|
|
|
+ const metaData: StreamReplyType = JSON.parse(
|
|
|
+ lastStreamFrame.metaData,
|
|
|
+ ) as any as StreamReplyType;
|
|
|
+ const newUserStates: NewUserStatesType = metaData.newUserStates.find(
|
|
|
+ (item) => item.userId === this.user_id,
|
|
|
+ );
|
|
|
+ const trace_id = metaData.traceIds[0];
|
|
|
+ const userId = newUserStates.userId;
|
|
|
+ const breakPointId = lastStreamFrame.marker
|
|
|
+ .replace('P', '')
|
|
|
+ .replace('T', '-');
|
|
|
+ const cameraAngle = newUserStates.playerState.camera.angle;
|
|
|
+ const playerAngle = newUserStates.playerState.player.angle;
|
|
|
+ this.onMoving = false;
|
|
|
+ console.log('stop-data', trace_id, userId, cameraAngle, cameraAngle);
|
|
|
+ redisMeta = await this.moveService.stop(
|
|
|
+ trace_id,
|
|
|
+ userId,
|
|
|
+ breakPointId,
|
|
|
+ cameraAngle,
|
|
|
+ playerAngle,
|
|
|
+ );
|
|
|
+ console.log('stop-redisMeta', redisMeta);
|
|
|
+ // redisMeta = await this.rotateService.rotate(request);
|
|
|
+ } else {
|
|
|
+ redisMeta = await this.rotateService.rotate(request);
|
|
|
+ }
|
|
|
+
|
|
|
if (redisMeta && 'mediaSrc' in redisMeta) {
|
|
|
const mediaSrc: string = redisMeta.mediaSrc || '';
|
|
|
if (mediaSrc.length > 0) {
|
|
@@ -170,9 +207,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
src = src.replace('/0000000001/', '');
|
|
|
// 判断不是同一条源时才推出
|
|
|
if (this.lastRenderMedia !== src) {
|
|
|
- console.log('[media]', src);
|
|
|
// console.log('不同源');
|
|
|
// this.frameCnt += 1;
|
|
|
+ console.log('[core-src]', src);
|
|
|
|
|
|
this.holdSteam();
|
|
|
this.lastRenderMedia = src;
|
|
@@ -276,7 +313,15 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
console.log('walking', req);
|
|
|
this.clickQueue.next(req);
|
|
|
this.walkingSub = this.clickQueue.subscribe(async (request) => {
|
|
|
- const walkingRes = await this.moveService.move(request);
|
|
|
+ const user = this.moveService.users[this.user_id];
|
|
|
+ const path = await this.getRouterService.searchRoad(
|
|
|
+ user.appId,
|
|
|
+ user.breakPointId,
|
|
|
+ req.clicking_action.clicking_point,
|
|
|
+ );
|
|
|
+ const walkingRes = await this.moveService.move(path, request);
|
|
|
+ console.log('walkingRes', walkingRes)
|
|
|
+ debugger;
|
|
|
if (walkingRes && !this.onMoving) {
|
|
|
this.onMoving = true;
|
|
|
this.holdSteam();
|
|
@@ -309,128 +354,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- handleBreath(request) {
|
|
|
- // console.log('handleBreath', request);
|
|
|
- const nps = {
|
|
|
- actionType: 1004,
|
|
|
- pointType: 100,
|
|
|
- extra: '',
|
|
|
- traceId: request.trace_id,
|
|
|
- packetId: '',
|
|
|
- nps: [
|
|
|
- { x: 235, y: -1791.875, z: -0.25 },
|
|
|
- { x: 235, y: -1750, z: 0.5045047 },
|
|
|
- { x: 235, y: -1722.5, z: 1 },
|
|
|
- { x: 235, y: -1700, z: 1.4054055 },
|
|
|
- { x: 235, y: -1653.125, z: 2.25 },
|
|
|
- { x: 235, y: -1600, z: 3.2072072 },
|
|
|
- { x: 235, y: -1583.75, z: 3.5 },
|
|
|
- { x: 235, y: -1550, z: 4.108108 },
|
|
|
- { x: 235, y: -1514.375, z: 4.75 },
|
|
|
- { x: 235, y: -1499.9999, z: 5.0090113 },
|
|
|
- { x: 235, y: -1445, z: 6 },
|
|
|
- { x: 200, y: -1900, z: -1.8723404 },
|
|
|
- { x: 200, y: -1850, z: -0.80851054 },
|
|
|
- { x: 200, y: -1800, z: 0.23423433 },
|
|
|
- { x: 200, y: -1750, z: 1.1351352 },
|
|
|
- { x: 200, y: -1700, z: 2.036036 },
|
|
|
- { x: 200, y: -1650, z: 2.9369369 },
|
|
|
- { x: 200, y: -1600, z: 3.837838 },
|
|
|
- { x: 200, y: -1550, z: 4.738739 },
|
|
|
- { x: 200, y: -1500, z: 5.63964 },
|
|
|
- { x: 200, y: -1444.2554, z: 6 },
|
|
|
- { x: 176.25, y: -1443.75, z: 6 },
|
|
|
- { x: 150, y: -2000, z: -4 },
|
|
|
- { x: 150, y: -1950, z: -2.93617 },
|
|
|
- { x: 150, y: -1932.8572, z: -2.5714293 },
|
|
|
- { x: 150, y: -1900, z: -1.8723404 },
|
|
|
- { x: 150, y: -1865.7142, z: -1.1428561 },
|
|
|
- { x: 150, y: -1850.0001, z: -0.8085134 },
|
|
|
- { x: 150, y: -1798.5714, z: 0.28571463 },
|
|
|
- { x: 150, y: -1750, z: 1.319149 },
|
|
|
- { x: 150, y: -1731.4286, z: 1.7142854 },
|
|
|
- { x: 150, y: -1700, z: 2.382979 },
|
|
|
- { x: 150, y: -1664.2856, z: 3.142859 },
|
|
|
- { x: 150, y: -1650.0001, z: 3.446806 },
|
|
|
- { x: 150, y: -1597.1428, z: 4.5714293 },
|
|
|
- { x: 150, y: -1550, z: 5.5744677 },
|
|
|
- { x: 150, y: -1443.1917, z: 6 },
|
|
|
- { x: 150, y: -1500, z: 6 },
|
|
|
- { x: 150, y: -1530, z: 6 },
|
|
|
- { x: 117.5, y: -1442.5, z: 6 },
|
|
|
- { x: 115, y: -1495, z: 6 },
|
|
|
- { x: 100, y: -1442.1277, z: 6 },
|
|
|
- { x: 100, y: -1495, z: 6 },
|
|
|
- { x: 58.75, y: -1441.25, z: 6 },
|
|
|
- { x: 57.5, y: -1495, z: 6 },
|
|
|
- { x: 0, y: -1440, z: 6 },
|
|
|
- { x: 0, y: -1495, z: 6 },
|
|
|
- { x: -50, y: -1494.9999, z: 6 },
|
|
|
- { x: -50, y: -1439.3378, z: 7.324497 },
|
|
|
- { x: -64.16667, y: -1495, z: 6 },
|
|
|
- { x: -68.63635, y: -1439.091, z: 7.8181725 },
|
|
|
- { x: -100, y: -1494.9999, z: 6 },
|
|
|
- { x: -100, y: -1438.6755, z: 8.648995 },
|
|
|
- { x: -128.33334, y: -1495, z: 6 },
|
|
|
- { x: -137.2727, y: -1438.1818, z: 9.636378 },
|
|
|
- { x: -150, y: -1494.9999, z: 6 },
|
|
|
- { x: -150, y: -1438.0132, z: 9.973526 },
|
|
|
- { x: -192.50002, y: -1495, z: 6 },
|
|
|
- { x: -200, y: -1450, z: 7.936013 },
|
|
|
- { x: -205.90906, y: -1437.2727, z: 11.45455 },
|
|
|
- { x: -250, y: -1450, z: 9.084496 },
|
|
|
- { x: -250, y: -1436.6887, z: 12.622522 },
|
|
|
- { x: -256.6667, y: -1495, z: 6 },
|
|
|
- { x: -274.5454, y: -1436.3636, z: 13.272723 },
|
|
|
- { x: -300, y: -1494.9999, z: 6 },
|
|
|
- { x: -300, y: -1450, z: 10.232978 },
|
|
|
- { x: -300, y: -1436.0264, z: 13.947053 },
|
|
|
- { x: -320.83337, y: -1495, z: 6 },
|
|
|
- { x: -343.1818, y: -1435.4546, z: 15.090897 },
|
|
|
- { x: -350, y: -1494.9999, z: 6 },
|
|
|
- { x: -350, y: -1450, z: 11.38146 },
|
|
|
- { x: -385, y: -1495, z: 6 },
|
|
|
- { x: -400, y: -1450, z: 10.610336 },
|
|
|
- { x: -405, y: -1475, z: 6 },
|
|
|
- { x: -411.81818, y: -1434.5454, z: 11.454548 },
|
|
|
- { x: -450, y: -1474.9999, z: 0.8571429 },
|
|
|
- { x: -450, y: -1450, z: 3.8835106 },
|
|
|
- { x: -450, y: -1434.0398, z: 6.3973427 },
|
|
|
- { x: -475, y: -1475, z: -2 },
|
|
|
- { x: -480.45453, y: -1433.6364, z: 2.3636398 },
|
|
|
- { x: -500, y: -1474.9999, z: -4.8571415 },
|
|
|
- { x: -500, y: -1450, z: -2.8433151 },
|
|
|
- { x: -500, y: -1433.3776, z: -0.22517776 },
|
|
|
- { x: -545, y: -1475, z: -10 },
|
|
|
- { x: -549.0909, y: -1432.7273, z: -6.727272 },
|
|
|
- { x: -550, y: -1450, z: -9.570139 },
|
|
|
- { x: -600, y: -1450, z: -16.285715 },
|
|
|
- { x: -600, y: -1474.9999, z: -16.285715 },
|
|
|
- { x: -600, y: -1432.053, z: -13.4702 },
|
|
|
- { x: -615, y: -1475, z: -18 },
|
|
|
- { x: -617.7273, y: -1431.8182, z: -15.818193 },
|
|
|
- { x: -650, y: -1450, z: -22 },
|
|
|
- { x: -650, y: -1474.9999, z: -22 },
|
|
|
- { x: -650, y: -1431.3907, z: -20.09272 },
|
|
|
- { x: -685, y: -1475, z: -26 },
|
|
|
- { x: -686.36365, y: -1430.909, z: -24.909088 },
|
|
|
- { x: -700, y: -1450, z: -27.714287 },
|
|
|
- { x: -700, y: -1474.9999, z: -27.714283 },
|
|
|
- { x: -700, y: -1430.7284, z: -26.71522 },
|
|
|
- { x: -755, y: -1430, z: -34 },
|
|
|
- { x: -755, y: -1450, z: -34 },
|
|
|
- { x: -755, y: -1475, z: -34 },
|
|
|
- ],
|
|
|
- peopleNum: 0,
|
|
|
- zoneId: '',
|
|
|
- echoMsg: '',
|
|
|
- reserveDetail: null,
|
|
|
- userWithAvatarList: [],
|
|
|
- newUserStates: [],
|
|
|
- code: 0,
|
|
|
- msg: '',
|
|
|
- };
|
|
|
- this.streamService.pushNormalDataToStream(nps);
|
|
|
+ async handleBreath(request) {
|
|
|
+ const npsRes = await this.moveService.getBreakPoints(request);
|
|
|
+ console.log('npsRes', npsRes);
|
|
|
+ this.streamService.pushNormalDataToStream(npsRes);
|
|
|
}
|
|
|
|
|
|
updateStatus() {
|
|
@@ -537,8 +464,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
}
|
|
|
this.rotateframeCnt += 1;
|
|
|
stream.frame = this.rotateframeCnt;
|
|
|
+ console.log('[media]', stream.clipPath);
|
|
|
this.logger.log(
|
|
|
- `roQueueSubscription:frame:${this.rotateframeCnt} ` +
|
|
|
+ `roQueueSubscription:frame:${this.rotateframeCnt} ` +
|
|
|
JSON.stringify(stream.metaData),
|
|
|
);
|
|
|
await this.streamService.pushFrameToSteam(stream);
|
|
@@ -549,6 +477,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.resumeStream(next);
|
|
|
this.rotateframeCnt = -1;
|
|
|
this.onMoving = false;
|
|
|
+ this.onRotating = false;
|
|
|
}
|
|
|
}, 300);
|
|
|
},
|
|
@@ -571,6 +500,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
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) {
|
|
@@ -581,7 +512,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.resumeStream(next);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
let src = stream.clipPath.split('?')[0];
|
|
|
// // 临时本地替换路经
|
|
|
src = src.replace('/0000000001/', '');
|
|
@@ -601,6 +531,11 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
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);
|
|
|
}
|
|
|
},
|
|
|
);
|