demo.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //请求池,key是userId,value是数组
  2. var actionRequestPool = {};
  3. var Actions = {
  4. Clicking:1,
  5. Rotation:1014,
  6. Joystick:15
  7. }
  8. //用户信息,包括:用户Id
  9. var users = {};
  10. var reply = {
  11. "traceIds": [],
  12. "vehicle": null,
  13. "newUserStates": [{
  14. "userId": "dcff36ae4fc1d",
  15. "playerState": {
  16. "roomTypeId": "",
  17. "person": 0,
  18. "avatarId": "",
  19. "skinId": "",
  20. "roomId": "",
  21. "isHost": false,
  22. "isFollowHost": false,
  23. "skinDataVersion": "",
  24. "avatarComponents": "",
  25. "nickName": "",
  26. "movingMode": 0,
  27. "attitude": "",
  28. "areaName": "",
  29. "pathName": "",
  30. "pathId": "",
  31. "avatarSize": 1,
  32. "extra": "",
  33. "prioritySync": false,
  34. "player": {
  35. "position":{"x": -700, "y": 0, "z": 0},
  36. "angle": {
  37. "pitch": 0,
  38. "yaw": 0,
  39. "roll": 0
  40. }
  41. },
  42. "camera": {
  43. "position": {"x": -1145, "y": 0, "z": 160},
  44. "angle": {
  45. "pitch": 0,
  46. "yaw": 0,
  47. "roll": 0
  48. }
  49. },
  50. "cameraCenter": {"x": -700, "y": 0, "z": 0}
  51. },
  52. "renderInfo": {
  53. "renderType": 0,
  54. "videoFrame": null,
  55. "cameraStateType": 3,
  56. "isMoving": 1,
  57. "needIfr": 0,
  58. "isVideo": 0,
  59. "stillFrame": 0,
  60. "isRotating": 0,
  61. "isFollowing": 0,
  62. "clientPanoTitlesBitmap": [],
  63. "clientPanoTreceId": "",
  64. "prefetchVideoId": "",
  65. "noMedia": false
  66. },
  67. "event": null,
  68. "relation": 1
  69. }],
  70. "actionResponses": [
  71. // {
  72. // "actionType": 15,
  73. // "pointType": 100,
  74. // "extra": "",
  75. // "traceId": "d0864cd0-378d-4d49-b7b0-3e8e1b9494c3",
  76. // "packetId": "d44bd2f5-f877-4dd7-868b-803c64f99082",
  77. // "nps": [],
  78. // "peopleNum": 0,
  79. // "zoneId": "",
  80. // "echoMsg": "",
  81. // "reserveDetail": null,
  82. // "userWithAvatarList": [],
  83. // "newUserStates": [],
  84. // "code": 0,
  85. // "msg": ""
  86. // }
  87. ],
  88. "getStateType": 0,
  89. "code": 0,
  90. "msg": "OK"
  91. };
  92. function init(app_id,userId){
  93. var user = {
  94. appId:null,
  95. userId:null,
  96. breakPointId:null,
  97. player: {
  98. "position":{"x": -700, "y": 0, "z": 0},
  99. "angle": {
  100. "pitch": 0,
  101. "yaw": 0,
  102. "roll": 0
  103. }
  104. },
  105. camera: {
  106. "position": {"x": -1145, "y": 0, "z": 160},
  107. "angle": {
  108. "pitch": 0,
  109. "yaw": 0,
  110. "roll": 0
  111. }
  112. },
  113. rotateInfo:{
  114. frameIndex:null,
  115. horizontal_move:0,
  116. mediaSrc:null
  117. },
  118. moveInfo:{
  119. },
  120. traceIds:[]
  121. };
  122. user.appId = app_id;
  123. user.userId = userId;
  124. users[userId] = user;
  125. reply["newUserStates"][0]["userId"] = userId;
  126. return reply;
  127. }
  128. function rotate(actionRequest){
  129. let userId = actionRequest["user_id"];
  130. if(actionRequestPool[userId]){
  131. actionRequestPool[userId].push(actionRequest);
  132. }
  133. else{
  134. actionRequestPool[userId] = [];
  135. actionRequestPool[userId].push(actionRequest);
  136. }
  137. let actionRequests = actionRequestPool[userId];
  138. let user = users[userId];
  139. let horizontal_move = user.rotateInfo.horizontal_move;
  140. let traceIds = user.traceIds;
  141. let sub = 0;
  142. for(let i=0;i<actionRequests.length;++i){
  143. if(actionRequests[i].action_type == Actions.Rotation){
  144. horizontal_move+=actionRequests[i].rotation_action.horizontal_move;
  145. traceIds.push(actionRequests[i].trace_id)
  146. ++sub;
  147. }
  148. else{
  149. break;
  150. }
  151. }
  152. actionRequests.splice(0,sub);
  153. let hAngle = horizontal_move * 90;
  154. if(Math.abs(hAngle)<1){
  155. user.rotateInfo.horizontal_move = horizontal_move;
  156. user.traceIds = traceIds;
  157. }
  158. else{
  159. user.rotateInfo.frameIndex += Math.floor(hAngle);
  160. }
  161. reply["newUserStates"][0]["userId"] = userId;
  162. //从redis里取
  163. //let key = user.appId + "-"+user.breakPointId+"-"+user.rotateInfo.frameIndex;
  164. let key = "rotateframe:app_id:"+user.appId+":frame_index:"+user.rotateInfo.frameIndex+":break_point_id:"+user.breakPointId;
  165. let value = null;
  166. //
  167. user.camera["position"] = value.camera_position;
  168. user.camera["angle"] = value.camera_angle;
  169. reply.mediaSrc = metaConfig.getVideoFramePath()+"/"+"0000000001"+"/"+user.breakPointId+"/"+value.directory+"/"+value.fileName()+"?m="+new Date().getTime();
  170. return reply;
  171. }