|
@@ -1,7 +1,7 @@
|
|
|
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
|
|
import { ClientGrpc, Client } from '@nestjs/microservices';
|
|
|
import { grpcClientOptions } from './grpc-scene.options';
|
|
|
-import { Logger } from '@nestjs/common';
|
|
|
+import { Inject } from '@nestjs/common';
|
|
|
import { DataChannel, PeerConnection } from 'node-datachannel';
|
|
|
import { BehaviorSubject } from 'rxjs';
|
|
|
// import * as streamBuffers from 'stream-buffers';
|
|
@@ -16,6 +16,13 @@ import { DelayQueue, RxQueue, DebounceQueue } from '../queue/mod';
|
|
|
import { MoveService } from 'src/move/move.service';
|
|
|
import { GetRouterService } from 'src/get-router/get-router.service';
|
|
|
import { ConfigService } from '@nestjs/config';
|
|
|
+import { Logger } from 'winston';
|
|
|
+import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
|
|
+// import ShareData from 'src/ShareData';
|
|
|
+// interface UserInfo {
|
|
|
+// userId: string;
|
|
|
+// roomId: string;
|
|
|
+// }
|
|
|
|
|
|
const seqExeAsyncFn = (asyncFn) => {
|
|
|
let runPromise = null;
|
|
@@ -37,7 +44,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
private streamService: StreamService,
|
|
|
private rotateService: RotateService,
|
|
|
private moveService: MoveService,
|
|
|
- private getRouterService: GetRouterService, // @InjectQueue('rotate') private rotateQueue: Queue, // @InjectQueue('walking') private walkingQueue: Queue,
|
|
|
+ private getRouterService: GetRouterService,
|
|
|
+ @Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger,
|
|
|
) {}
|
|
|
@Client(grpcClientOptions) private readonly client: ClientGrpc;
|
|
|
|
|
@@ -61,7 +69,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
|
|
|
private channel: DataChannel;
|
|
|
private peer: PeerConnection;
|
|
|
- private logger: Logger = new Logger('SceneService');
|
|
|
+ // private logger: Logger = new Logger('SceneService');
|
|
|
private frameCntInterval = 1000;
|
|
|
private user_id: string;
|
|
|
private roomId: string;
|
|
@@ -115,9 +123,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
private isJoystickHasStream = false;
|
|
|
private hasJoystickFocusRepeat = false;
|
|
|
private startSub: any;
|
|
|
-
|
|
|
- public users = {};
|
|
|
-
|
|
|
public sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
|
|
|
|
private globalOptLock = false;
|
|
@@ -130,8 +135,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
Number.prototype.padLeft = function (n, str) {
|
|
|
return Array(n - String(this).length + 1).join(str || '0') + this;
|
|
|
};
|
|
|
- // this.logger.log('roQueue-period :' + Number(this.roQueue.period));
|
|
|
- this.logger.log('moveQueue-period :' + Number(this.moveQueue.period));
|
|
|
+ // this.logger.info('roQueue-period :' + Number(this.roQueue.period));
|
|
|
+ this.logger.info('moveQueue-period :' + Number(this.moveQueue.period));
|
|
|
}
|
|
|
|
|
|
public isHeaderOrLast(index: number, length: number): boolean {
|
|
@@ -230,10 +235,17 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- exit() {
|
|
|
+ async exit() {
|
|
|
this.frameCnt.next(-1);
|
|
|
this.rotateService.deleteUser(this.user_id);
|
|
|
this.hasJoystickFocusRepeat = false;
|
|
|
+ const userId = this.user_id;
|
|
|
+ const roomId = this.roomId;
|
|
|
+ const roomKey =
|
|
|
+ process.env.NODE_ENV === 'development'
|
|
|
+ ? `test-room:${roomId}`
|
|
|
+ : `room:${roomId}`;
|
|
|
+ this.cacheService.hDel(roomKey, userId);
|
|
|
if (this.startSub) {
|
|
|
this.startSub.unsubscribe();
|
|
|
this.startSub = null;
|
|
@@ -267,9 +279,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// try {
|
|
|
const rotateUnlock = this.firstRender && !this.globalOptLock;
|
|
|
console.log('rotateUnlock条件--->' + rotateUnlock, this.globalOptLock);
|
|
|
-
|
|
|
if (rotateUnlock && this._rotateCount > 2) {
|
|
|
- console.log('20220627test:handleRotate');
|
|
|
const start = performance.now();
|
|
|
// 当move时处理 _rotateCount是移动端同时触发的问题,rotateStopThrottle是减少重复抖动stop的处理。
|
|
|
this.holdSteam();
|
|
@@ -295,7 +305,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
const stop = performance.now();
|
|
|
const inMillSeconds = stop - start;
|
|
|
const rounded = Number(inMillSeconds).toFixed(3);
|
|
|
- this.logger.log(
|
|
|
+ this.logger.info(
|
|
|
`[timer]-rotate-入队列前: ${rounded}ms -->` +
|
|
|
JSON.stringify(stream),
|
|
|
);
|
|
@@ -358,6 +368,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
IDRflag,
|
|
|
new Date().getTime(),
|
|
|
);
|
|
|
+
|
|
|
+ const user = this.moveService.users[this.user_id];
|
|
|
+ user.isMoving = JSON.parse(stream.metaData)['newUserStates'][0].renderInfo.isMoving
|
|
|
const res = await this.streamService.pushFrameToSteam(stream);
|
|
|
if (res.done) {
|
|
|
this.frameCnt.next(res.frame);
|
|
@@ -369,7 +382,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
|
|
|
clearTimeout(this._rotateTimeout);
|
|
|
this._rotateTimeout = setTimeout(() => {
|
|
|
- this.logger.log('rotate end', Date.now());
|
|
|
+ this.logger.info('rotate end', Date.now());
|
|
|
this.rotateframeCnt = -1;
|
|
|
this._rotateCountFame = -1;
|
|
|
this._rotateCount = 0;
|
|
@@ -401,7 +414,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// this._rotateCountFame += 1;
|
|
|
|
|
|
// const IDRflag = this._rotateCountFame % 5 === 0 ? 1 : 3;
|
|
|
- // this.logger.log(
|
|
|
+ // this.logger.info(
|
|
|
// `当前rotate ,mainframeCnt:${this.frameCnt.getValue()}, _rotateCountFame:${this._rotateCountFame
|
|
|
// } IDRflag:${IDRflag}`,
|
|
|
// );
|
|
@@ -410,7 +423,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// this.rotateFirstIDR = false;
|
|
|
// }
|
|
|
|
|
|
- // this.logger.log(
|
|
|
+ // this.logger.info(
|
|
|
// '[media-rotate]: ' +
|
|
|
// ', frame: ' +
|
|
|
// stream.frame +
|
|
@@ -420,7 +433,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// stream.clipPath,
|
|
|
// // stream.metaData,
|
|
|
// );
|
|
|
- // // this.logger.log(
|
|
|
+ // // this.logger.info(
|
|
|
// // `roQueueSubscription:frame:${this.rotateframeCnt} ` +
|
|
|
// // JSON.stringify(stream.metaData),
|
|
|
// // );
|
|
@@ -429,7 +442,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// if (res.done) {
|
|
|
// clearTimeout(this._rotateTimeout);
|
|
|
// this._rotateTimeout = setTimeout(() => {
|
|
|
- // this.logger.log('rotate end', Date.now());
|
|
|
+ // this.logger.info('rotate end', Date.now());
|
|
|
// this.frameCnt.next(res.frame);
|
|
|
// this.rotateframeCnt = -1;
|
|
|
// this._rotateCountFame = -1;
|
|
@@ -465,7 +478,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.rotateStopThrottle = true;
|
|
|
this.isStopJointing = true;
|
|
|
const lastStreamFrame = this.lastMoveStreamFrame.getValue();
|
|
|
- this.logger.log(
|
|
|
+ this.logger.info(
|
|
|
'handleRotateOrWalkingStop-frame',
|
|
|
JSON.stringify(lastStreamFrame),
|
|
|
);
|
|
@@ -492,7 +505,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
const breakPointId = metaData.endBreakPointId || metaData.breakPointId;
|
|
|
const cameraAngle = newUserStates.playerState.camera.angle;
|
|
|
const playerAngle = newUserStates.playerState.player.angle;
|
|
|
- this.logger.log(
|
|
|
+ this.logger.info(
|
|
|
'stop-data-0' +
|
|
|
'trace_id: ' +
|
|
|
trace_id +
|
|
@@ -515,7 +528,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
cameraAngle,
|
|
|
playerAngle,
|
|
|
);
|
|
|
- this.logger.log('stop-redisMeta-frame', JSON.stringify(redisMeta));
|
|
|
+ this.logger.info('stop-redisMeta-frame', JSON.stringify(redisMeta));
|
|
|
if (redisMeta) {
|
|
|
const src = redisMeta.mediaSrc.split('?')[0];
|
|
|
const mediaSrc = this.configService.get('app.prefix') + src;
|
|
@@ -547,18 +560,23 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async getSimplestCameraInfo(appId,userId){
|
|
|
- if(this.moveService.cameraInfos.length>20){
|
|
|
- const startBreakPointId = this.moveService.cameraInfos[0].startBreakPointId;
|
|
|
- const endBreakPointId = this.moveService.cameraInfos[this.moveService.cameraInfos.length-1].endBreakPointId;
|
|
|
-
|
|
|
- const path = this.getRouterService.searchRoad2(startBreakPointId,endBreakPointId);
|
|
|
- if(path == null){
|
|
|
+ async getSimplestCameraInfo(appId, userId) {
|
|
|
+ if (this.moveService.cameraInfos.length > 20) {
|
|
|
+ const startBreakPointId =
|
|
|
+ this.moveService.cameraInfos[0].startBreakPointId;
|
|
|
+ const endBreakPointId =
|
|
|
+ this.moveService.cameraInfos[this.moveService.cameraInfos.length - 1]
|
|
|
+ .endBreakPointId;
|
|
|
+
|
|
|
+ const path = this.getRouterService.searchRoad2(
|
|
|
+ startBreakPointId,
|
|
|
+ endBreakPointId,
|
|
|
+ );
|
|
|
+ if (path == null) {
|
|
|
//可以清空cameraInfos
|
|
|
this.moveService.cameraInfos = [];
|
|
|
- }
|
|
|
- else{
|
|
|
- await this.moveService.updateCameraInfoForDely(appId,userId,path);
|
|
|
+ } else {
|
|
|
+ await this.moveService.updateCameraInfoForDely(appId, userId, path);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -570,7 +588,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
*/
|
|
|
async walking(request: MoveRequest) {
|
|
|
this.latestWalkingRequest = request;
|
|
|
- this.logger.log('walking-trace_id', request.trace_id);
|
|
|
+ this.logger.info('walking-trace_id', request.trace_id);
|
|
|
|
|
|
// if (this.isHasWalkingJoints()) {
|
|
|
// console.log('lock-锁-walking', this.latestWalkingRequest);
|
|
@@ -600,7 +618,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
//TODO 正在行走时,有新的reqest
|
|
|
if (frame) {
|
|
|
// console.log('unlock-Joints', JSON.stringify(frame));
|
|
|
- this.logger.log('Joints', JSON.stringify(frame));
|
|
|
+ this.logger.info('Joints', JSON.stringify(frame));
|
|
|
this.resumeRotate();
|
|
|
let isRotateStop = false;
|
|
|
let isWalkingStop = false;
|
|
@@ -681,13 +699,13 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this._rotateCount = 0;
|
|
|
const user = this.moveService.users[this.user_id];
|
|
|
console.log('进入1 - searchRoad');
|
|
|
- this.logger.log(
|
|
|
+ this.logger.info(
|
|
|
'handleWalking-users' +
|
|
|
JSON.stringify(this.moveService.users) +
|
|
|
' this.user_id: ' +
|
|
|
this.user_id,
|
|
|
);
|
|
|
- this.logger.log(
|
|
|
+ this.logger.info(
|
|
|
'handleWalking-currentUser' +
|
|
|
JSON.stringify(user) +
|
|
|
' this.user_id: ' +
|
|
@@ -700,7 +718,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
user.breakPointId,
|
|
|
request.clicking_action.clicking_point,
|
|
|
);
|
|
|
- this.logger.log('walking-path', path);
|
|
|
+ this.logger.info('walking-path', path);
|
|
|
if (!path) {
|
|
|
console.log('不存在--path', path);
|
|
|
this.cleanMoveSteam();
|
|
@@ -721,10 +739,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
for (let i = 0; i <= walkingRes.length - 1; i++) {
|
|
|
Array.from(walkingRes[i]).forEach(
|
|
|
(item: StreamReplyType, index: number) => {
|
|
|
- console.log(
|
|
|
- '20220628test:handleWalking->' +
|
|
|
- item['newUserStates'][0].renderInfo.isMoving,
|
|
|
- );
|
|
|
//const IDRflag = index % 5 === 0 ? 1 : 3;
|
|
|
const IDRflag = item.isIDR ? 1 : 3;
|
|
|
const dir = this.isHeaderOrLast(
|
|
@@ -748,7 +762,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
const seqs = Array.from(walkingRes).flat() as any as StreamReplyType[];
|
|
|
|
|
|
if (seqs?.length) {
|
|
|
- this.logger.log(
|
|
|
+ this.logger.info(
|
|
|
'walking --队列总览:' +
|
|
|
' 总段数: ' +
|
|
|
walkingRes.length +
|
|
@@ -764,7 +778,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.info(`[timer]-move-入队列前:-->${rounded}ms`);
|
|
|
|
|
|
this.handleSeqMoving(seqs);
|
|
|
} else {
|
|
@@ -798,7 +812,10 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
*/
|
|
|
async joystick(request: JoystickRequest) {
|
|
|
// TODO hasJoystickMoveRequest中断
|
|
|
- this.logger.log('this.hasJoystickMoveRequest', this.hasJoystickMoveRequest);
|
|
|
+ this.logger.info(
|
|
|
+ 'this.hasJoystickMoveRequest',
|
|
|
+ this.hasJoystickMoveRequest,
|
|
|
+ );
|
|
|
if (!this.hasJoystickMoveRequest) {
|
|
|
this.handlejoystick(request);
|
|
|
}
|
|
@@ -826,6 +843,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
const hasMedia = joystickRes?.mediaSrc && joystickRes?.mediaSrc.length > 0;
|
|
|
|
|
|
if (hasMedia) {
|
|
|
+ console.log('mediaSrc_7:'+joystickRes.mediaSrc);
|
|
|
const src = joystickRes.mediaSrc.split('?')[0];
|
|
|
const mediaSrc = this.configService.get('app.prefix') + src;
|
|
|
// IDR flag设置为I帧
|
|
@@ -852,10 +870,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- console.log(
|
|
|
- '20220627test-complementFrame 进行1' + '***' + streamData.frame,
|
|
|
- );
|
|
|
-
|
|
|
+ const user = this.moveService.users[this.user_id];
|
|
|
+ user.isMoving = JSON.parse(streamData.metaData)['newUserStates'][0].renderInfo.isMoving;
|
|
|
+ console.log('handlePushJoyStickSteam:'+user.IDRCount+','+joystickRes.isIDR+','+joystickRes.traceIds);
|
|
|
// 过滤新东西, 推完给回false
|
|
|
this.moveService.sendingFrameForJoystick = true;
|
|
|
|
|
@@ -898,18 +915,11 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.user_id,
|
|
|
) as StreamReplyType;
|
|
|
if (complementFrame) {
|
|
|
- console.log(
|
|
|
- '20220627test-complementFrame 进行' +
|
|
|
- complementFrame.mediaSrc +
|
|
|
- '***' +
|
|
|
- this.frameCnt.value,
|
|
|
- );
|
|
|
// 第二次或N次进入时如果有值直接重新进入流主程
|
|
|
this.holdSteam();
|
|
|
this.handlePushJoyStickSteamSeq(complementFrame);
|
|
|
this.globalOptLock = true;
|
|
|
} else {
|
|
|
- console.log('20220627test-complementFrame 结束');
|
|
|
// 第二次或N次无pool数据再次trigger handleJoystickStop
|
|
|
this.hasJoystickFocusRepeat = false;
|
|
|
this.testTimer = 0;
|
|
@@ -921,6 +931,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.handleJoystickStop(hasPush);
|
|
|
}
|
|
|
} else {
|
|
|
+ debugger;
|
|
|
console.error('joystick-流地址有误::', joystickRes.mediaSrc);
|
|
|
this.logger.error('joystick-流地址有误::', joystickRes.mediaSrc);
|
|
|
this.resumeStream();
|
|
@@ -933,14 +944,13 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// 最后一帧200ms
|
|
|
clearTimeout(this._JoyStickingSteamTimeout);
|
|
|
this._JoyStickingSteamTimeout = setTimeout(async () => {
|
|
|
- console.log('20220627test-complementFrame handleJoystickStop 200ms之后');
|
|
|
const user = this.moveService.users[this.user_id];
|
|
|
- await this.getSimplestCameraInfo(user.appId,this.user_id);
|
|
|
+ await this.getSimplestCameraInfo(user.appId, this.user_id);
|
|
|
const complementFrame = this.moveService.complementFrame(
|
|
|
this.user_id,
|
|
|
) as StreamReplyType;
|
|
|
// console.log('has-complementFrame', complementFrame);
|
|
|
- console.log('gemer-test-complementFrame', complementFrame);
|
|
|
+ //console.log('gemer-test-complementFrame', complementFrame);
|
|
|
if (complementFrame) {
|
|
|
this.hasJoystickFocusRepeat = true;
|
|
|
this.globalOptLock = true;
|
|
@@ -949,14 +959,14 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
const start = performance.now();
|
|
|
this.handlePushJoyStickSteamSeq(complementFrame);
|
|
|
const stop = performance.now();
|
|
|
- console.log('handlePushJoyStickSteam', this.testTimer);
|
|
|
+ //console.log('handlePushJoyStickSteam', this.testTimer);
|
|
|
const inMillSeconds = stop - start;
|
|
|
const rounded = Number(inMillSeconds).toFixed(3);
|
|
|
console.log(`complementFrame调用时间---->${rounded}`);
|
|
|
} else {
|
|
|
console.log('complementFrame-空1');
|
|
|
- this.logger.log('joystick opt done');
|
|
|
- this.logger.log('joystick 交权给空流,当前pts', hasPush.frame);
|
|
|
+ this.logger.info('joystick opt done');
|
|
|
+ this.logger.info('joystick 交权给空流,当前pts', hasPush.frame);
|
|
|
this.hasJoystickFocusRepeat = false;
|
|
|
this.onJoysticking.next(false);
|
|
|
this.resumeStream();
|
|
@@ -975,23 +985,15 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
//const joystickRes = await this.moveService.joystick(request);
|
|
|
this._rotateCount = 0;
|
|
|
const joystickRes = await this.moveService.seqExeJoystick(request);
|
|
|
- this.logger.log(
|
|
|
+ this.logger.info(
|
|
|
'joystick-breakPointId:' +
|
|
|
this.moveService.users[this.user_id].breakPointId,
|
|
|
);
|
|
|
// 有数据 [0]是rotate数据,[1-infinity]是walking数据
|
|
|
- //this.logger.log('joystickRes', JSON.stringify(joystickRes));
|
|
|
+ //this.logger.info('joystickRes', JSON.stringify(joystickRes));
|
|
|
|
|
|
if (joystickRes) {
|
|
|
this.onJoysticking.next(true);
|
|
|
- // console.log(
|
|
|
- // 'handlejoysticktesttest:' +
|
|
|
- // joystickRes.mediaSrc +
|
|
|
- // ',相机坐标:' +
|
|
|
- // JSON.stringify(
|
|
|
- // joystickRes.newUserStates[0].playerState.player.position,
|
|
|
- // ),
|
|
|
- // );
|
|
|
if (!this.onMoving.getValue()) {
|
|
|
console.log('handlejoystick:data', JSON.stringify(joystickRes));
|
|
|
this.handlePushJoyStickSteamSeq(joystickRes);
|
|
@@ -1015,7 +1017,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
// if (!this.moveQueueSubscription) {
|
|
|
// this.handleMoveSteam();
|
|
|
// }
|
|
|
- // this.logger.log('moving-seqs', seqs.length);
|
|
|
+ // this.logger.info('moving-seqs', seqs.length);
|
|
|
this.onMoving.next(true);
|
|
|
this.holdSteam();
|
|
|
// 保证每一段都是序列动作的前面队列是空的
|
|
@@ -1047,11 +1049,6 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
try {
|
|
|
if (!this.isStopJointing) {
|
|
|
const metaData: StreamReplyType = JSON.parse(stream.metaData);
|
|
|
- // if (this.moveframeCnt === -1) {
|
|
|
- // this.moveframeCnt = this.frameCnt.getValue();
|
|
|
- // }
|
|
|
- // this.moveframeCnt += 1;
|
|
|
- // this.latestBreakPointId = metaData.endBreakPointId;
|
|
|
this.moveframeCnt = this.frameCnt.value + 1;
|
|
|
const streamData: StreamFrameType = {
|
|
|
frame: this.moveframeCnt,
|
|
@@ -1060,7 +1057,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
serverTime: this.mockserverTime,
|
|
|
DIR: stream.DIR,
|
|
|
};
|
|
|
- this.logger.log(
|
|
|
+ this.logger.info(
|
|
|
'[media-move]: ' +
|
|
|
', moveframeCnt: ' +
|
|
|
this.moveframeCnt +
|
|
@@ -1072,10 +1069,13 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
stream.DIR,
|
|
|
// stream.metaData,
|
|
|
);
|
|
|
- this.logger.log(
|
|
|
+ this.logger.info(
|
|
|
'[media-move-lastMovingPointArray]',
|
|
|
this.lastMovingPointArray?.length,
|
|
|
);
|
|
|
+
|
|
|
+ const user = this.moveService.users[this.user_id];
|
|
|
+ user.isMoving = JSON.parse(streamData.metaData)['newUserStates'][0].renderInfo.isMoving;
|
|
|
// 记录lastMoveStreamFrame给打断逻辑使用
|
|
|
this.lastMoveStreamFrame.next(streamData);
|
|
|
// this.lastMoveStreamFrameBk = streamData;
|
|
@@ -1088,7 +1088,7 @@ 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.info('path-update-index', isLastFrameIndex);
|
|
|
|
|
|
if (res.done) {
|
|
|
const frameTimeEnd = performance.now();
|
|
@@ -1098,7 +1098,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.frameCnt.next(res.frame);
|
|
|
//关节点入库
|
|
|
if (isLastFrameIndex > -1) {
|
|
|
- //this.logger.log('path-update-array', this.lastMovingPointArray);
|
|
|
+ //this.logger.info('path-update-array', this.lastMovingPointArray);
|
|
|
const currentMeta = this.lastMovingPointArray[isLastFrameIndex];
|
|
|
const userId = this.user_id;
|
|
|
const breakPointId = currentMeta.metaData.endBreakPointId;
|
|
@@ -1111,7 +1111,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
clearTimeout(this._moveTimeout);
|
|
|
|
|
|
this._moveTimeout = setTimeout(() => {
|
|
|
- this.logger.log('move 交权给空流,当前pts', res.frame);
|
|
|
+ this.logger.info('move 交权给空流,当前pts', res.frame);
|
|
|
this.rewalking = false;
|
|
|
this.frameCnt.next(res.frame);
|
|
|
this.rotateframeCnt = -1;
|
|
@@ -1122,7 +1122,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.cleanMoveSteam();
|
|
|
this.globalOptLock = false;
|
|
|
this.resumeStream();
|
|
|
- this.logger.log('move end');
|
|
|
+ this.logger.info('move end');
|
|
|
}, 200);
|
|
|
} else {
|
|
|
console.error('流地址有误::', res.frame, JSON.stringify(res));
|
|
@@ -1159,13 +1159,27 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.rotateStopThrottle = false;
|
|
|
}
|
|
|
|
|
|
- handleDataChanelOpen(channel: DataChannel, peer: PeerConnection): void {
|
|
|
+ async handleDataChanelOpen(
|
|
|
+ channel: DataChannel,
|
|
|
+ peer: PeerConnection,
|
|
|
+ ): Promise<void> {
|
|
|
this.channel = channel;
|
|
|
this.peer = peer;
|
|
|
this.streamService.setChannel(channel);
|
|
|
this.startSteaming.next(true);
|
|
|
+
|
|
|
// this.startStream();
|
|
|
// this.handleStream();
|
|
|
+ //TODO 正式channel打开记录,记录多少人在线
|
|
|
+ const userId = this.user_id;
|
|
|
+ const roomId = this.roomId;
|
|
|
+ const roomKey =
|
|
|
+ process.env.NODE_ENV === 'development'
|
|
|
+ ? `test-room:${roomId}`
|
|
|
+ : `room:${roomId}`;
|
|
|
+
|
|
|
+ this.cacheService.hset(roomKey, userId, 1);
|
|
|
+ // debugger;
|
|
|
this.channel.onBufferedAmountLow(() => {
|
|
|
console.error('onBufferedAmountLow-rtt', this.peer.rtt());
|
|
|
console.error('onBufferedAmountLow', this.channel.bufferedAmount());
|
|
@@ -1246,7 +1260,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
if (frameData) {
|
|
|
this.globalOptLock = true;
|
|
|
const nextFrame = this.frameCnt.getValue() + 1;
|
|
|
- this.logger.warn('lostIframe', nextFrame);
|
|
|
+ this.logger.warn('lostIframe:' + nextFrame);
|
|
|
frameData.frame = nextFrame;
|
|
|
frameData.DIR = 1;
|
|
|
const res = await this.streamService.pushFrameToSteam(frameData);
|
|
@@ -1271,7 +1285,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
|
|
|
handleBreath(request) {
|
|
|
const npsRes = this.moveService.getBreakPoints(request);
|
|
|
- //this.logger.log('npsRes', npsRes.nps);
|
|
|
+ //this.logger.info('npsRes', npsRes.nps);
|
|
|
this.streamService.pushNormalDataToStream(npsRes);
|
|
|
}
|
|
|
|
|
@@ -1287,7 +1301,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
const usersData = this.rotateService.getNewUserStateRequest(request);
|
|
|
if (usersData) {
|
|
|
usersData.actionType = 1024;
|
|
|
- //this.logger.log(
|
|
|
+ //this.logger.info(
|
|
|
// 'joystick:->updateUserStatus' +
|
|
|
// 'playerPosition:' +
|
|
|
// JSON.stringify(
|
|
@@ -1321,12 +1335,12 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
});
|
|
|
}
|
|
|
handleStream() {
|
|
|
- this.logger.log('this.frameCntSubscription', this.frameCntSubscription);
|
|
|
+ this.logger.info('this.frameCntSubscription', this.frameCntSubscription);
|
|
|
let redisData;
|
|
|
if (!this.frameCntSubscription) {
|
|
|
this.frameCntSubscription = this.frameCnt.subscribe(async (frame) => {
|
|
|
try {
|
|
|
- this.logger.log('frame', frame);
|
|
|
+ this.logger.info('frame: ' + frame);
|
|
|
console.log(
|
|
|
'networkState:::--->' +
|
|
|
' maxMessageSize: ' +
|
|
@@ -1348,7 +1362,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
app_id,
|
|
|
this.user_id,
|
|
|
);
|
|
|
- this.logger.log('获取-首屏', redisData);
|
|
|
+ this.logger.warn(
|
|
|
+ 'bootstrap:socket::首屏 --->' + JSON.stringify(redisData),
|
|
|
+ );
|
|
|
this.onSteaming = true;
|
|
|
this.holdSteam();
|
|
|
if (redisData && 'mediaSrc' in redisData) {
|
|
@@ -1357,7 +1373,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
const src = mediaSrc.split('?')[0];
|
|
|
const clipPath = this.configService.get('app.prefix') + src;
|
|
|
delete redisData.mediaSrc;
|
|
|
- this.logger.log(
|
|
|
+ this.logger.info(
|
|
|
`user:${this.user_id}:first render stream` +
|
|
|
JSON.stringify({ path: clipPath, meta: redisData }),
|
|
|
);
|
|
@@ -1416,7 +1432,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
false,
|
|
|
);
|
|
|
if (redisDataAuto) {
|
|
|
- this.logger.log(`空白流::有数据:${frame}`);
|
|
|
+ this.logger.info(`空白流::有数据:${frame}`);
|
|
|
'mediaSrc' in redisDataAuto && delete redisDataAuto.mediaSrc;
|
|
|
const streamMeta: StreamMetaType = {
|
|
|
frame: frame,
|
|
@@ -1425,7 +1441,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.streamService.pushMetaDataToSteam(streamMeta);
|
|
|
} else {
|
|
|
this.stopStream();
|
|
|
- this.logger.log('空流无Redis数据');
|
|
|
+ this.logger.info('空流无Redis数据');
|
|
|
}
|
|
|
}
|
|
|
} catch (error) {
|