|
@@ -9,6 +9,10 @@ import configuration from 'src/config/configuration';
|
|
|
// import * as BreakPointIds from '../../ws/points-BreakPointId.json';
|
|
|
// import { SceneService } from 'src/scene/scene.service';
|
|
|
|
|
|
+const MaxDelayTime = 80; //超过这个值就需要干预(操作杆)
|
|
|
+const MaxBufferCameraInfo = 3; //超过这个值就需要干预(操作杆)
|
|
|
+const MaxNet = 3;
|
|
|
+
|
|
|
const seqExeAsyncFn = (asyncFn) => {
|
|
|
let runPromise = null;
|
|
|
return function seq(...args) {
|
|
@@ -27,8 +31,6 @@ const seqExeAsyncFn = (asyncFn) => {
|
|
|
};
|
|
|
};
|
|
|
|
|
|
-let moveInterval = 3;
|
|
|
-
|
|
|
@Injectable()
|
|
|
export class MoveService implements OnModuleInit {
|
|
|
constructor(
|
|
@@ -357,7 +359,7 @@ export class MoveService implements OnModuleInit {
|
|
|
);
|
|
|
const user = this.users[userId];
|
|
|
let i;
|
|
|
- for (i = 1; i < moveFrames.length; i += moveInterval) {
|
|
|
+ for (i = 1; i < moveFrames.length; i+=3) {
|
|
|
const moveFrame = moveFrames[i];
|
|
|
const reply = JSON.parse(JSON.stringify(this.reply));
|
|
|
if (reply.traceIds.indexOf(traceId) == -1) {
|
|
@@ -660,12 +662,13 @@ export class MoveService implements OnModuleInit {
|
|
|
const traceId = actionRequest['trace_id'];
|
|
|
const dir_action = actionRequest['dir_action'];
|
|
|
const actionType = actionRequest['action_type'];
|
|
|
+ const time_delay = actionRequest['time_delay'];
|
|
|
const user = this.users[userId];
|
|
|
const breakPointId = user.breakPointId;
|
|
|
const appId = user.appId;
|
|
|
- moveInterval = 1;
|
|
|
const replys = [];
|
|
|
- const step = 0.5;
|
|
|
+ const step = 0.4;
|
|
|
+ //const step = 1;
|
|
|
const closestDis = 50; //小于这个距离就跳到邻居呼吸点
|
|
|
const distance = step * dir_action.speed_level;
|
|
|
let angle = null;
|
|
@@ -794,6 +797,21 @@ export class MoveService implements OnModuleInit {
|
|
|
);
|
|
|
this.reply.actionResponses[0].actionType = actionType;
|
|
|
|
|
|
+ console.log('20220708_延时->'+time_delay);
|
|
|
+ // //网络延迟的情况下,就暂时不推流
|
|
|
+ if(time_delay && time_delay>MaxDelayTime){
|
|
|
+ user.netQua = 0;
|
|
|
+ }
|
|
|
+ else if(time_delay && time_delay<MaxDelayTime && user.netQua<MaxNet){
|
|
|
+ ++user.netQua
|
|
|
+ }
|
|
|
+
|
|
|
+ if(user.netQua<MaxNet){
|
|
|
+ if(user.lastJoyStickMediaSrc){
|
|
|
+ user.lastJoyStickMediaSrc = false;
|
|
|
+ return this.reply;
|
|
|
+ }
|
|
|
+ }
|
|
|
const cameraInfo = this.getCameraInfo();
|
|
|
if (cameraInfo != null) {
|
|
|
console.log(
|
|
@@ -807,6 +825,8 @@ export class MoveService implements OnModuleInit {
|
|
|
if (cameraInfo.mediaSrc) {
|
|
|
this.reply.mediaSrc = cameraInfo.mediaSrc;
|
|
|
this.reply.isIDR = cameraInfo.isIDR;
|
|
|
+ user.lastJoyStickMediaSrc = true;
|
|
|
+ console.log('20220708_mediaSrc1:'+cameraInfo.mediaSrc);
|
|
|
}
|
|
|
|
|
|
user.camera.position = JSON.parse(
|
|
@@ -1060,9 +1080,9 @@ export class MoveService implements OnModuleInit {
|
|
|
// } else {
|
|
|
// chooseBreakPointId = neighPoints[0].breakPointId;
|
|
|
// }
|
|
|
- if (closestNeighorId == null) {
|
|
|
- debugger;
|
|
|
- }
|
|
|
+ // if (closestNeighorId == null) {
|
|
|
+ // debugger;
|
|
|
+ // }
|
|
|
chooseBreakPointId = closestNeighorId;
|
|
|
return await this.moveCamera(
|
|
|
breakPointId,
|
|
@@ -1255,7 +1275,7 @@ export class MoveService implements OnModuleInit {
|
|
|
chooseBreakPointId,
|
|
|
index,
|
|
|
);
|
|
|
- this.setCameraInfo(appId, moveFrames, breakPointId, chooseBreakPointId);
|
|
|
+ this.setCameraInfo(appId, userId, moveFrames, breakPointId, chooseBreakPointId);
|
|
|
|
|
|
user.breakPointId = chooseBreakPointId;
|
|
|
|
|
@@ -1294,8 +1314,23 @@ export class MoveService implements OnModuleInit {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- setCameraInfo(appId, moveFrames, startBreakPointId, endBreakPointId) {
|
|
|
- for (let i = 0; i < moveFrames.length; i += moveInterval) {
|
|
|
+ setCameraInfo(appId, userId,moveFrames, startBreakPointId, endBreakPointId) {
|
|
|
+ // let moveInterval = 1;
|
|
|
+ // console.log('20220708_cameraInfos设置->'+this.cameraInfos.length);
|
|
|
+ // if(this.cameraInfos.length>MaxBufferCameraInfo){
|
|
|
+ // moveInterval = 1;
|
|
|
+ // }
|
|
|
+ const user = this.users[userId];
|
|
|
+ let moveInterval = 2;
|
|
|
+ let flag = false;
|
|
|
+ for (let i = 0; i < moveFrames.length; ++i) {
|
|
|
+ if(user.netQua<MaxNet){
|
|
|
+ if(i!= 0 && i!= moveFrames.length-1 && i%moveInterval == 0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ moveFrames[i].startBreakPointId = startBreakPointId;
|
|
|
moveFrames[i].endBreakPointId = endBreakPointId;
|
|
|
moveFrames[i].mediaSrc =
|
|
|
'/' +
|
|
@@ -1328,13 +1363,55 @@ export class MoveService implements OnModuleInit {
|
|
|
'?m=' +
|
|
|
new Date().getTime();
|
|
|
}
|
|
|
+ console.log('20220708_mediaSrc3:'+moveFrames[i].mediaSrc);
|
|
|
if (i == 0 || i == moveFrames.length - 1) {
|
|
|
moveFrames[i].isIDR = true;
|
|
|
+ if(i == moveFrames.length - 1){
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
} else {
|
|
|
moveFrames[i].isIDR = false;
|
|
|
}
|
|
|
this.cameraInfos.push(moveFrames[i]);
|
|
|
}
|
|
|
+ if(!flag){
|
|
|
+ const cameraInfo = moveFrames[moveFrames.length-1];
|
|
|
+ cameraInfo.endBreakPointId = endBreakPointId;
|
|
|
+ cameraInfo.mediaSrc =
|
|
|
+ '/' +
|
|
|
+ appId +
|
|
|
+ '/' +
|
|
|
+ startBreakPointId +
|
|
|
+ '/' +
|
|
|
+ cameraInfo.file_name.substring(
|
|
|
+ 0,
|
|
|
+ cameraInfo.file_name.indexOf('.'),
|
|
|
+ ) +
|
|
|
+ '/' +
|
|
|
+ cameraInfo.file_name +
|
|
|
+ '?m=' +
|
|
|
+ new Date().getTime();
|
|
|
+
|
|
|
+ if (startBreakPointId > endBreakPointId) {
|
|
|
+ cameraInfo.mediaSrc =
|
|
|
+ '/' +
|
|
|
+ appId +
|
|
|
+ '/' +
|
|
|
+ endBreakPointId +
|
|
|
+ '/' +
|
|
|
+ cameraInfo.file_name.substring(
|
|
|
+ 0,
|
|
|
+ cameraInfo.file_name.indexOf('.'),
|
|
|
+ ) +
|
|
|
+ '/' +
|
|
|
+ cameraInfo.file_name +
|
|
|
+ '?m=' +
|
|
|
+ new Date().getTime();
|
|
|
+ }
|
|
|
+ cameraInfo.isIDR = true;
|
|
|
+ this.cameraInfos.push(cameraInfo);
|
|
|
+ console.log('20220708_mediaSrc4:'+cameraInfo.mediaSrc);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
addCameraInfo(cameraPosition, cameraAngle, mediaSrc, isIDR) {
|
|
@@ -1349,6 +1426,7 @@ export class MoveService implements OnModuleInit {
|
|
|
getCameraInfo() {
|
|
|
if (this.cameraInfos.length > 0) {
|
|
|
const item = this.cameraInfos.shift();
|
|
|
+ console.log('20220708_cameraInfos取值->'+this.cameraInfos.length);
|
|
|
return item;
|
|
|
} else {
|
|
|
return null;
|
|
@@ -1389,7 +1467,6 @@ export class MoveService implements OnModuleInit {
|
|
|
user.camera.position = JSON.parse(
|
|
|
JSON.stringify(cameraInfo.camera_position),
|
|
|
);
|
|
|
-
|
|
|
user.camera.angle = JSON.parse(JSON.stringify(cameraInfo.camera_angle));
|
|
|
|
|
|
this.sendingFrameForJoystick = true;
|
|
@@ -1405,6 +1482,152 @@ export class MoveService implements OnModuleInit {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // createDefaultReply(userId){
|
|
|
+ // const user = this.users[userId];
|
|
|
+ // this.reply.traceIds = [];
|
|
|
+ // this.reply['newUserStates'][0].userId = userId;
|
|
|
+ // this.reply['actionResponses'][0].traceId = null;
|
|
|
+ // this.reply['newUserStates'][0].playerState.player.angle.yaw =
|
|
|
+ // user.player.angle.yaw;
|
|
|
+ // this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
|
|
|
+ // JSON.stringify(user.player.position),
|
|
|
+ // );
|
|
|
+ // this.reply['newUserStates'][0].playerState.camera.angle = JSON.parse(
|
|
|
+ // JSON.stringify(user.camera.angle),
|
|
|
+ // );
|
|
|
+ // this.reply['newUserStates'][0].playerState.camera.position = JSON.parse(
|
|
|
+ // JSON.stringify(user.camera.position),
|
|
|
+ // );
|
|
|
+
|
|
|
+ // this.reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(
|
|
|
+ // JSON.stringify(user.player.position),
|
|
|
+ // );
|
|
|
+ // this.reply['newUserStates'][0].renderInfo.isMoving = 0;
|
|
|
+ // this.reply['actionResponses'][0].traceId = null;
|
|
|
+ // return JSON.parse(JSON.stringify(this.reply));
|
|
|
+ // }
|
|
|
+
|
|
|
+ async updateCameraInfoForDely(appId,userId,path){
|
|
|
+
|
|
|
+ if(path == null){
|
|
|
+ this.cameraInfos = [];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const user = this.users[userId];
|
|
|
+ const index = this.getMoveIndex(user.camera.angle.yaw);
|
|
|
+ let frames = [];
|
|
|
+
|
|
|
+ let pointIds = [];
|
|
|
+
|
|
|
+ for (let i = 0; i < path.length - 1; ++i) {
|
|
|
+ const start_break_point_id = path[i];
|
|
|
+ const end_break_point_id = path[i + 1];
|
|
|
+ const moveFrames = await this.getMoveFrames(
|
|
|
+ appId,
|
|
|
+ start_break_point_id,
|
|
|
+ end_break_point_id,
|
|
|
+ index,
|
|
|
+ );
|
|
|
+ if (!moveFrames) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ frames = frames.concat(moveFrames)
|
|
|
+ pointIds.push({
|
|
|
+ index:frames.length,
|
|
|
+ startBreakPointId:start_break_point_id,
|
|
|
+ endBreakPointId:end_break_point_id
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this.cameraInfos = [];
|
|
|
+ const interval = Math.floor(frames.length/12);
|
|
|
+ for (let i = 0; i < frames.length-1; i+=interval) {
|
|
|
+ const frame = frames[i];
|
|
|
+ let isIDR = false;
|
|
|
+ if(i == 0){
|
|
|
+ isIDR = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ let startBreakPointId,endBreakPointId;
|
|
|
+ for(let j=0;j<pointIds.length;++j){
|
|
|
+ if(i<pointIds[j].index+1){
|
|
|
+ startBreakPointId = pointIds[j].startBreakPointId;
|
|
|
+ endBreakPointId = pointIds[j].endBreakPointId;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let mediaSrc =
|
|
|
+ '/' +
|
|
|
+ appId +
|
|
|
+ '/' +
|
|
|
+ startBreakPointId +
|
|
|
+ '/' +
|
|
|
+ frame.file_name.substring(0, frame.file_name.indexOf('.')) +
|
|
|
+ '/' +
|
|
|
+ frame.file_name +
|
|
|
+ '?m=' +
|
|
|
+ new Date().getTime();
|
|
|
+ if (startBreakPointId > endBreakPointId) {
|
|
|
+ mediaSrc =
|
|
|
+ '/' +
|
|
|
+ appId +
|
|
|
+ '/' +
|
|
|
+ endBreakPointId +
|
|
|
+ '/' +
|
|
|
+ frame.file_name.substring(0, frame.file_name.indexOf('.')) +
|
|
|
+ '/' +
|
|
|
+ frame.file_name +
|
|
|
+ '?m=' +
|
|
|
+ new Date().getTime();
|
|
|
+ }
|
|
|
+ console.log('20220708_mediaSrc2:'+mediaSrc);
|
|
|
+ this.cameraInfos.push({
|
|
|
+ startBreakPointId:startBreakPointId,
|
|
|
+ endBreakPointId:endBreakPointId,
|
|
|
+ camera_position: frame.camera_position,
|
|
|
+ camera_angle: frame.camera_angle,
|
|
|
+ mediaSrc: mediaSrc,
|
|
|
+ isIDR: isIDR,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ const startBreakPointId = pointIds[pointIds.length-1].startBreakPointId;
|
|
|
+ const endBreakPointId = pointIds[pointIds.length-1].endBreakPointId;
|
|
|
+ const frame = frames[frames.length-1];
|
|
|
+ let mediaSrc =
|
|
|
+ '/' +
|
|
|
+ appId +
|
|
|
+ '/' +
|
|
|
+ startBreakPointId +
|
|
|
+ '/' +
|
|
|
+ frame.file_name.substring(0, frame.file_name.indexOf('.')) +
|
|
|
+ '/' +
|
|
|
+ frame.file_name +
|
|
|
+ '?m=' +
|
|
|
+ new Date().getTime();
|
|
|
+ if (startBreakPointId > endBreakPointId) {
|
|
|
+ frame.mediaSrc =
|
|
|
+ '/' +
|
|
|
+ appId +
|
|
|
+ '/' +
|
|
|
+ endBreakPointId +
|
|
|
+ '/' +
|
|
|
+ frame.file_name.substring(0, frame.file_name.indexOf('.')) +
|
|
|
+ '/' +
|
|
|
+ frame.file_name +
|
|
|
+ '?m=' +
|
|
|
+ new Date().getTime();
|
|
|
+ }
|
|
|
+ this.cameraInfos.push({
|
|
|
+ startBreakPointId:startBreakPointId,
|
|
|
+ endBreakPointId:endBreakPointId,
|
|
|
+ camera_position: frame.camera_position,
|
|
|
+ camera_angle: frame.camera_angle,
|
|
|
+ mediaSrc: mediaSrc,
|
|
|
+ isIDR: true,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
stopJoystick(userId) {
|
|
|
console.log('20220627test:stopJoystick');
|
|
|
this.reply.traceIds = [];
|