| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- //请求池,key是userId,value是数组
- var actionRequestPool = {};
- var Actions = {
- Clicking:1,
- Rotation:1014,
- Joystick:15
- }
- //用户信息,包括:用户Id
- var users = {};
- var reply = {
- "traceIds": [],
- "vehicle": null,
- "newUserStates": [{
- "userId": "dcff36ae4fc1d",
- "playerState": {
- "roomTypeId": "",
- "person": 0,
- "avatarId": "",
- "skinId": "",
- "roomId": "",
- "isHost": false,
- "isFollowHost": false,
- "skinDataVersion": "",
- "avatarComponents": "",
- "nickName": "",
- "movingMode": 0,
- "attitude": "",
- "areaName": "",
- "pathName": "",
- "pathId": "",
- "avatarSize": 1,
- "extra": "",
- "prioritySync": false,
- "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
- }
- },
- "cameraCenter": {"x": -700, "y": 0, "z": 0}
- },
- "renderInfo": {
- "renderType": 0,
- "videoFrame": null,
- "cameraStateType": 3,
- "isMoving": 1,
- "needIfr": 0,
- "isVideo": 0,
- "stillFrame": 0,
- "isRotating": 0,
- "isFollowing": 0,
- "clientPanoTitlesBitmap": [],
- "clientPanoTreceId": "",
- "prefetchVideoId": "",
- "noMedia": false
- },
- "event": null,
- "relation": 1
- }],
- "actionResponses": [
- // {
- // "actionType": 15,
- // "pointType": 100,
- // "extra": "",
- // "traceId": "d0864cd0-378d-4d49-b7b0-3e8e1b9494c3",
- // "packetId": "d44bd2f5-f877-4dd7-868b-803c64f99082",
- // "nps": [],
- // "peopleNum": 0,
- // "zoneId": "",
- // "echoMsg": "",
- // "reserveDetail": null,
- // "userWithAvatarList": [],
- // "newUserStates": [],
- // "code": 0,
- // "msg": ""
- // }
- ],
- "getStateType": 0,
- "code": 0,
- "msg": "OK"
- };
- function init(app_id,userId){
- var user = {
- appId:null,
- userId:null,
- breakPointId: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:null,
- horizontal_move:0,
- mediaSrc:null
- },
- moveInfo:{
-
- },
- traceIds:[]
- };
- user.appId = app_id;
- user.userId = userId;
- users[userId] = user;
- reply["newUserStates"][0]["userId"] = userId;
- return reply;
- }
- function rotate(actionRequest){
- let userId = actionRequest["user_id"];
- if(actionRequestPool[userId]){
- actionRequestPool[userId].push(actionRequest);
- }
- else{
- actionRequestPool[userId] = [];
- actionRequestPool[userId].push(actionRequest);
- }
- let actionRequests = actionRequestPool[userId];
- let user = users[userId];
- let horizontal_move = user.rotateInfo.horizontal_move;
- let traceIds = user.traceIds;
- let sub = 0;
- for(let i=0;i<actionRequests.length;++i){
- if(actionRequests[i].action_type == Actions.Rotation){
- horizontal_move+=actionRequests[i].rotation_action.horizontal_move;
- traceIds.push(actionRequests[i].trace_id)
- ++sub;
- }
- else{
- break;
- }
- }
- actionRequests.splice(0,sub);
- let hAngle = horizontal_move * 90;
- if(Math.abs(hAngle)<1){
- user.rotateInfo.horizontal_move = horizontal_move;
- user.traceIds = traceIds;
- }
- else{
- user.rotateInfo.frameIndex += Math.floor(hAngle);
- }
- reply["newUserStates"][0]["userId"] = userId;
- //从redis里取
- //let key = user.appId + "-"+user.breakPointId+"-"+user.rotateInfo.frameIndex;
- let key = "rotateframe:app_id:"+user.appId+":frame_index:"+user.rotateInfo.frameIndex+":break_point_id:"+user.breakPointId;
- let value = null;
- //
- user.camera["position"] = value.camera_position;
- user.camera["angle"] = value.camera_angle;
-
- reply.mediaSrc = metaConfig.getVideoFramePath()+"/"+"0000000001"+"/"+user.breakPointId+"/"+value.directory+"/"+value.fileName()+"?m="+new Date().getTime();
- return reply;
- }
|