ActionsHandler.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. import Actions from "./enum/Actions.js"
  2. import {eventsManager} from "./EventsManager.js"
  3. import util from "./util.js"
  4. import Person from "./enum/Person.js"
  5. import ClickType from "./enum/ClickType.js"
  6. import Logger from "./Logger.js"
  7. import Response from "./Response.js"
  8. import { VDecoder } from "./h264Decoder/VDecoder.js";
  9. import { SrsRTC } from "./srsRtc.js";
  10. import { Connection } from "./connection.js";
  11. const ossVideoDir = "https://laser-data.oss-cn-shenzhen.aliyuncs.com/new-video/720p/"
  12. const walkVideoFrame = 29
  13. window.currentFrame = null
  14. const logger = new Logger('actions-handler')
  15. const QueueActions = [Actions.Transfer, Actions.ChangeSkin, Actions.GetOnVehicle, Actions.GetOffVehicle];
  16. export default class ActionsHandler {
  17. constructor(e) {
  18. this.currentActiveAction = null
  19. this.room = e
  20. //xst
  21. window.workerReady = false
  22. this.vDecoder = new VDecoder({
  23. maxChip: 3,
  24. });
  25. window.vDecoder = this.vDecoder
  26. this.init()
  27. }
  28. init(){
  29. this.vDecoder.on('ready', () => {
  30. console.log("ready");
  31. window.workerReady = true
  32. })
  33. this.initSocket()
  34. }
  35. initSocket() {
  36. // const sdk = new SrsRTC();
  37. const testConfig = {
  38. sceneCode: "testApp",
  39. userId: "testUser",
  40. roomId: "8888",
  41. };
  42. const connection = new Connection(testConfig);
  43. // console.log("sdk", sdk);
  44. // console.log("sdk", connection);
  45. // const url = "webrtc://demo-kms.4dage.com/live/test1";
  46. // sdk.start(url);
  47. window.connection = connection
  48. window.connection.socket.on("getRoute", (pathArr) => {
  49. console.log("getRoute", pathArr);
  50. if(!pathArr) return
  51. let {anglePlus, dircNum} = window.room.sceneManager.correctCameraDirec()
  52. pathArr.forEach(point => {
  53. let ue4Pos = util.xversePosition2Ue4({x: -point.location.x, y: point.location.y, z: point.location.z})
  54. point.location = new BABYLON.Vector3(ue4Pos.x, ue4Pos.y, ue4Pos.z)
  55. })
  56. const walkSpeed = 1 // m/s
  57. const frameRate = 29 // fps
  58. let walkPoints = []
  59. let sumWalkFrame = 0
  60. let videoArr = []
  61. for(let i = 0; i < pathArr.length - 1; i++) {
  62. // 目前视频返回帧数到159条会停止
  63. if(sumWalkFrame + walkFrame > 159) break
  64. let point0 = new BABYLON.Vector3(pathArr[i].location.x, pathArr[i].location.y, pathArr[i].location.z)
  65. let point1 = new BABYLON.Vector3(pathArr[i+1].location.x, pathArr[i+1].location.y, pathArr[i+1].location.z)
  66. let distanceVec = point1.clone().subtract(point0)
  67. let distance = distanceVec.length() / 100 // m
  68. let distancePerFrame = walkSpeed / frameRate // m/帧 // walkVideoFrame
  69. let walkFrame = Math.round(distance / distancePerFrame) // 帧
  70. let dir = distanceVec.normalize()
  71. videoArr.push( {
  72. path: ossVideoDir + pathArr[i].id + "/" + pathArr[i].id + "_" + pathArr[i+1].id + "_" + dircNum,
  73. frame: walkFrame
  74. })
  75. sumWalkFrame += walkFrame
  76. for(let currentFrame = 1; currentFrame <= walkFrame; currentFrame++) {
  77. walkPoints.push(point0.add(dir.scale(distancePerFrame * 100 * currentFrame))) // 单位转换成cm
  78. }
  79. }
  80. console.log("[Walk]::path", walkPoints)
  81. window.walkSettings = {
  82. "frameNum": sumWalkFrame,
  83. "walkPoints": walkPoints,
  84. }
  85. window.walking = true
  86. this.mutiFetchData({
  87. type: 'move',
  88. videoDataArr: videoArr
  89. })
  90. });
  91. }
  92. async avatarComponentsSync(e){
  93. const t = {
  94. action_type: Actions.SetPlayerState,
  95. set_player_state_action: {
  96. player_state: {
  97. avatar_components: JSON.stringify(e)
  98. }
  99. }
  100. };
  101. this.sendData({
  102. data: t
  103. })
  104. }
  105. async sendData(e) {
  106. /*
  107. //console.log('发送数据:'+JSON.stringify(e))
  108. await this.beforeSend(e);
  109. const t = util.uuid();
  110. this.room.networkController.sendRtcData(le(oe({}, e.data), {
  111. trace_id: t,
  112. user_id: this.room.options.userId
  113. }));
  114. if (e.track === !1)
  115. {
  116. return Promise.resolve(null);
  117. }
  118. const {sampleRate: r=1, timeout: n=2e3, tag: o, data: a, special: s} = e;
  119. return eventsManager.track({
  120. timeout: n,
  121. traceId: t,
  122. event: a.action_type,
  123. tag: o,
  124. extra: a
  125. }, {
  126. special: s,
  127. sampleRate: r,
  128. noReport: this.room.viewMode === "serverless" || this.room.options.viewMode === "serverless"
  129. }).finally(()=>{
  130. QueueActions.includes(e.data.action_type) && (this.currentActiveAction = void 0)
  131. }
  132. )
  133. */
  134. }
  135. //async sendData(e) {
  136. //console.log('发送数据:'+JSON.stringify(e))
  137. //旋转
  138. //window.room.sceneManager.scene.activeCamera.rotation.y
  139. //心跳:要去掉
  140. //邻居点:要去掉
  141. //漫游
  142. //人物所在位置和角度,相机的位置和角度,相机的目标点,点击的坐标
  143. //}
  144. async beforeSend(e) {
  145. var o;
  146. const t = (o = this.room._userAvatar) == null ? void 0 : o.isMoving
  147. , r = e.data.action_type;
  148. if (QueueActions.includes(r)) {
  149. if (this.currentActiveAction)
  150. return logger.error(`${Actions[this.currentActiveAction]} still pending, reject ${Actions[r]}`),
  151. Promise.reject(new FrequencyLimitError(`${Actions[r]} action request frequency limit`));
  152. this.currentActiveAction = r
  153. }
  154. if (t && QueueActions.includes(e.data.action_type))
  155. try {
  156. await this.stopMoving()
  157. } catch (a) {
  158. this.currentActiveAction = void 0,
  159. logger.error("before action stopMoving failed", a)
  160. }
  161. }
  162. async moveTo(e) {
  163. // 镜头矫正
  164. let {anglePlus, dircNum} = window.room.sceneManager.correctCameraDirec()
  165. let anglePlusFrame = Math.floor(anglePlus / (Math.PI/30))
  166. anglePlus = anglePlusFrame * (Math.PI/30)
  167. if(Math.abs(anglePlus) > 0.0001) {
  168. window.moveCallBack = {
  169. func: this.moveTo.bind(this),
  170. args: [e]
  171. }
  172. window.rotateCallBack = {
  173. func: this.rotate.bind(this),
  174. args: [{type: 'rotate', angle: Math.PI/30 * Math.sign(anglePlus)}],
  175. frame: anglePlusFrame,
  176. currentFrame: 0,
  177. }
  178. this.rotate({type: 'rotate', angle: Math.PI/30 * Math.sign(anglePlus)})
  179. return
  180. }
  181. const {point: t, extra: r="", motionType: n} = e
  182. , o = {
  183. action_type: Actions.Clicking,
  184. clicking_action: {
  185. clicking_point: t,
  186. clicking_type: ClickType.IgnoreView,
  187. extra: encodeURIComponent(r),
  188. attitude: n
  189. },
  190. clicking_state: this.room._currentClickingState
  191. };
  192. let player = window.room.sceneManager.avatarComponent._mainUser
  193. let closestPoint = window.room.sceneManager.getClosestPointData(t)
  194. let closestPointSelf = window.room.sceneManager.getClosestPointData(player.position)
  195. console.log("[Walk]::from", closestPointSelf.position0, ":to", closestPoint.position0)
  196. window.connection.socket.emit("getRoute", {
  197. sceneCode: "testApp",
  198. userId: "testUser",
  199. roomId: "8888",
  200. s_location: {
  201. x: closestPointSelf.position0.x,
  202. y: closestPointSelf.position0.y,
  203. z: closestPointSelf.position0.z,
  204. },
  205. e_location: {
  206. x: closestPoint.position0.x,
  207. y: closestPoint.position0.y,
  208. z: closestPoint.position0.z,
  209. },
  210. });
  211. // if(this.walkHandle) clearInterval(this.walkHandle)
  212. // // window.room.moveTo(t)
  213. // let currentFrame = 0
  214. // this.walkHandle = setInterval(() => {
  215. // currentFrame++
  216. // let targetPos = {
  217. // "x": player.position.x + distanceVec.x / frameNum,
  218. // "y": player.position.y + distanceVec.y / frameNum,
  219. // "z": player.position.z + distanceVec.z / frameNum
  220. // }
  221. // if(currentFrame < frameNum) {
  222. // window.room.moveTo({
  223. // position: targetPos,
  224. // isEnd: false
  225. // })
  226. // } else {
  227. // window.room.moveTo({
  228. // position: targetPos,
  229. // isEnd: true
  230. // })
  231. // clearInterval(this.walkHandle)
  232. // }
  233. // }, 1000 / fps)
  234. // let date = new Date()
  235. // console.error(date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds())
  236. // console.error(closestPointSelf.id)
  237. // return this.sendData({
  238. // data: o
  239. // })
  240. }
  241. transfer(e) {
  242. const {renderType: t, player: r, camera: n, areaName: o, attitude: a, pathName: s, person: l, noMedia: u, timeout: c, tag: h, special: f} = e
  243. , d = {
  244. data: {
  245. action_type: Actions.Transfer,
  246. transfer_action: {
  247. render_type: t,
  248. player: r,
  249. camera: n,
  250. areaName: o,
  251. attitude: a,
  252. pathName: s,
  253. person: {
  254. type: l
  255. },
  256. noMedia: u,
  257. tiles: [0, 1, 2, 4]
  258. }
  259. },
  260. special: f,
  261. timeout: c || 4e3,
  262. tag: h
  263. };
  264. return this.sendData(d).then(_=>(typeof l != "undefined" && this.room.updateCurrentNetworkOptions({
  265. person: l,
  266. rotationRenderType: t
  267. }),
  268. _))
  269. }
  270. changeRotationRenderType(e) {
  271. const {renderType: t, player: r, camera: n, areaName: o, attitude: a, pathName: s} = e;
  272. return this.transfer({
  273. renderType: t,
  274. player: r,
  275. camera: n,
  276. areaName: o,
  277. attitude: a,
  278. pathName: s,
  279. tag: "changeToRotationVideo"
  280. })
  281. }
  282. requestPanorama(e, noMedia, timeout) {
  283. const {camera: camera, player: player, areaName: areaName, attitude: attitude, pathName: pathName, tag: tag} = e;
  284. return this.transfer({
  285. renderType: RenderType.ClientRotationPano,
  286. player: player,
  287. camera: camera,
  288. person: Person.First,
  289. areaName: areaName,
  290. attitude: attitude,
  291. pathName: pathName,
  292. noMedia: noMedia,
  293. timeout: timeout,
  294. tag: tag || "requestPanorama",
  295. special: !noMedia
  296. })
  297. }
  298. setMotionType(e) {
  299. return this.transfer({
  300. attitude: e,
  301. tag: "setMotionType"
  302. })
  303. }
  304. setNickName(e) {
  305. const t = {
  306. action_type: Actions.ChangeNickname,
  307. change_nickname_action: {
  308. nickname: e
  309. }
  310. };
  311. return this.sendData({
  312. data: t
  313. })
  314. }
  315. getReserveSeat({routeId: e, name: t}) {
  316. const r = {
  317. action_type: Actions.ReserveSeat,
  318. reserve_seat_action: {
  319. route_id: e,
  320. name: t
  321. }
  322. };
  323. return this.sendData({
  324. data: r
  325. })
  326. }
  327. getReserveStatus({routeId: e, name: t, need_detail: r}) {
  328. const n = {
  329. action_type: Actions.GetReserveStatus,
  330. get_reserve_status_action: {
  331. route_id: e,
  332. name: t,
  333. need_detail: r
  334. }
  335. };
  336. return this.sendData({
  337. data: n,
  338. timeout: 2e3
  339. }).then(o=>o.reserveDetail)
  340. }
  341. stopMoving() {
  342. const e = {
  343. action_type: Actions.StopMoving,
  344. stop_move_action: {}
  345. };
  346. return this.sendData({
  347. data: e
  348. })
  349. }
  350. getOnVehicle({routeId: e, name: t, camera: r}) {
  351. const n = {
  352. action_type: Actions.GetOnVehicle,
  353. get_on_vehicle_action: {
  354. route_id: e,
  355. name: t,
  356. camera: r
  357. }
  358. };
  359. return this.sendData({
  360. data: n
  361. })
  362. }
  363. getOffVehicle({renderType: e, player: t, camera: r}) {
  364. const n = {
  365. action_type: Actions.GetOffVehicle,
  366. get_off_vehicle_action: {
  367. render_type: e,
  368. player: t,
  369. camera: r
  370. }
  371. };
  372. return this.sendData({
  373. data: n
  374. })
  375. }
  376. confirmEvent(e) {
  377. const t = {
  378. action_type: Actions.ConfirmEvent,
  379. confirm_event_action: {
  380. id: e
  381. }
  382. };
  383. return this.sendData({
  384. data: t,
  385. track: !1
  386. })
  387. }
  388. echo(e) {
  389. const t = {
  390. action_type: Actions.Echo,
  391. echo_msg: {
  392. echoMsg: e
  393. }
  394. };
  395. return this.sendData({
  396. data: t,
  397. track: !1
  398. })
  399. }
  400. async changeSkin(e) {
  401. const t = e.special === void 0 ? e.renderType === RenderType.ClientRotationPano : e.special
  402. , {skinId: r, mode: n, landingType: o=LandingType.Stay, landingPoint: a, landingCamera: s, renderType: l, areaName: u, attitude: c, pathName: h, person: f, noMedia: d, timeout: _, roomTypeId: g=""} = e
  403. , m = this.room.skinList.filter(y=>y.id === r)[0];
  404. if (!m) {
  405. const y = `skin ${r} is invalid`;
  406. return logger.error(y),
  407. Promise.reject(new ParamError(y))
  408. }
  409. const v = {
  410. action_type: Actions.ChangeSkin,
  411. change_skin_action: {
  412. skinID: r,
  413. mode: n === ChangeMode.Preview ? ChangeMode.Preview : ChangeMode.Confirm,
  414. skin_data_version: r + m.versionId,
  415. landing_type: o,
  416. landing_point: a,
  417. landing_camera: s,
  418. render_wrapper: {
  419. render_type: l
  420. },
  421. areaName: u,
  422. attitude: c,
  423. noMedia: d,
  424. person: f,
  425. pathName: h,
  426. roomTypeId: g
  427. }
  428. };
  429. return this.sendData({
  430. data: v,
  431. timeout: _ || 6e3,
  432. special: t
  433. }).then(async y=>{
  434. if (l === RenderType.ClientRotationPano && y) {
  435. const b = await this.room.modelManager.findRoute(r, h)
  436. , {camera: T} = util.getRandomItem(b.birthPointList) || {};
  437. await this.room.panorama.handleReceivePanorama(y, T)
  438. }
  439. return this.handleChangeSkin(e)
  440. }
  441. ).catch(y=>d ? this.handleChangeSkin(e) : Promise.reject(y))
  442. }
  443. handleChangeSkin(e) {
  444. const {skinId: t, mode: r, renderType: n, areaName: o, attitude: a, pathName: s} = e;
  445. return this.room.sceneManager.staticmeshComponent.getCgMesh().show(),
  446. this.room.sceneManager.cameraComponent.switchToCgCamera(),
  447. this.room.engineProxy._updateSkinAssets(t).then(()=>{
  448. this.room.sceneManager.staticmeshComponent.getCgMesh().hide(),
  449. this.room.sceneManager.cameraComponent.switchToMainCamera(),
  450. this.room.pathManager.currentArea = o,
  451. logger.info("changeSkin _updateSkinAssets susccss"),
  452. this.room.updateCurrentNetworkOptions({
  453. pathName: s,
  454. attitude: a,
  455. areaName: o
  456. }),
  457. this.room.skinChangedHook(),
  458. this.room.emit("skinChanged", {
  459. skin: {
  460. id: t
  461. },
  462. mode: r
  463. }),
  464. n === RenderType.ClientRotationPano && this.room.sceneManager.cameraComponent.allowMainCameraController()
  465. }
  466. )
  467. }
  468. /***********************************************************************xst****************************************************************/
  469. /*
  470. rotate({pitch: e, yaw: t}) {
  471. var n;
  472. if (this.room.disableRotate || this.room.isPano || ((n = this.room._userAvatar) == null ? void 0 : n._isChangingComponentsMode))
  473. return;
  474. const r = {
  475. action_type: Actions.Rotation,
  476. rotation_action: {
  477. vertical_move: e,
  478. horizontal_move: -t
  479. }
  480. };
  481. //console.log('发送数据rotate:'+JSON.stringify(r.rotation_action))
  482. this.sendData({
  483. data: r,
  484. sampleRate: .02
  485. })
  486. }
  487. */
  488. //zeg
  489. rotate({type: type, angle: angle}) {
  490. //camera的position,angle
  491. //起始和结束的帧
  492. let endRotation = util.xverseRotation2Ue4(window.room.sceneManager.cameraComponent.mainCamera.rotation).yaw
  493. endRotation = (endRotation % 360 + 360) % 360
  494. // todo 矫正
  495. let sfns = Math.round((endRotation + 180)/6) // 仅视频贴图偏移矫正180度
  496. endRotation += angle/Math.PI*180
  497. endRotation = (endRotation % 360 + 360) % 360
  498. let efns = Math.round((endRotation + 180)/6)
  499. if(window.currentFrame == null){
  500. window.currentFrame = efns
  501. }
  502. else if(window.currentFrame != efns){
  503. window.currentFrame = efns
  504. }
  505. else if(window.currentFrame == efns){
  506. return
  507. }
  508. // 起始帧不需要传入
  509. if(efns>sfns) sfns = (sfns + 1 + 60) % 60
  510. if(efns<sfns) sfns = (sfns - 1 + 60) % 60
  511. efns = sfns // (efns + 60) % 60 // 目前一帧一帧跳,防止漂移和跨0问题
  512. // console.error(angle/Math.PI*180, endRotation, efns, sfns)
  513. window.rotating = true // 标记旋转中
  514. window.rotateFrame = efns - sfns // 旋转帧数
  515. window.camera_endRotation = endRotation
  516. window.star_angle = angle
  517. let player = window.room.sceneManager.avatarComponent._mainUser
  518. let closestPointSelf = window.room.sceneManager.getClosestPointData(player.position)
  519. console.log('取帧:'+sfns+','+efns);
  520. this.fetchData({
  521. type: type,
  522. path: ossVideoDir + closestPointSelf.id + "/" + closestPointSelf.id,
  523. sFrame: sfns,
  524. eFrame: efns
  525. })
  526. if(typeof(window.star_angle) == 'undefined'){
  527. return
  528. }
  529. this.room.sceneManager.materialComponent.initreceveFrames()
  530. // this.room.doRotate()
  531. //window.room.sceneManager.cameraComponent.mainCamera.rotation.y += angle
  532. //window.room.sceneManager.cameraComponent.setCameraPose(cameraState)
  533. }
  534. /*
  535. rotate({type: type, angle: angle}) {
  536. let endRotation = window.room.sceneManager.cameraComponent.mainCamera.rotation.y
  537. if(endRotation<0){
  538. endRotation += 2*Math.PI
  539. }
  540. else if(endRotation>2*Math.PI){
  541. endRotation -= 2*Math.PI
  542. }
  543. let sfns = Math.round(endRotation/Math.PI * 180 /6)
  544. //每6°一帧
  545. for(let i=0;i<60;++i){
  546. if(Math.abs(Math.abs(angle) - i/60 * 2 * Math.PI)<0.01){
  547. //找到了
  548. endRotation += angle
  549. break;
  550. }
  551. }
  552. let efns = Math.round(endRotation/Math.PI * 180 /6)
  553. console.log('取帧:'+sfns+','+efns);
  554. this.fetchData({
  555. type:type,
  556. sFrame:sfns,
  557. eFrame:efns
  558. })
  559. this.room.sceneManager.materialComponent.initreceveFrames()
  560. // this.room.sceneManager.cameraComponent.mainCamera.rotation.y = endRotation
  561. // window.room.sceneManager.cameraComponent._cameraPose.rotation._y = endRotation
  562. // window.room.sceneManager.cameraComponent.mainCamera.rotation.y=endRotation
  563. let response = JSON.parse(JSON.stringify(Response))
  564. response.signal.newUserStates[0].playerState.player.position.x = this.room.avatarManager.avatars.get(nickname).position.x
  565. response.signal.newUserStates[0].playerState.player.position.y = this.room.avatarManager.avatars.get(nickname).position.y
  566. response.signal.newUserStates[0].playerState.player.position.z = this.room.avatarManager.avatars.get(nickname).position.z
  567. response.signal.newUserStates[0].playerState.player.angle.pitch = this.room.avatarManager.avatars.get(nickname).rotation.pitch
  568. response.signal.newUserStates[0].playerState.player.angle.yaw = this.room.avatarManager.avatars.get(nickname).rotation.yaw
  569. response.signal.newUserStates[0].playerState.player.angle.roll = this.room.avatarManager.avatars.get(nickname).rotation.roll
  570. response.signal.newUserStates[0].playerState.camera.position =
  571. response.signal.newUserStates[0].playerState.camera.angle =
  572. response.signal.newUserStates[0].playerState.cameraCenter.x = this.room.avatarManager.avatars.get(nickname).position.x
  573. response.signal.newUserStates[0].playerState.cameraCenter.y = this.room.avatarManager.avatars.get(nickname).position.y
  574. response.signal.newUserStates[0].playerState.cameraCenter.z = this.room.avatarManager.avatars.get(nickname).position.z
  575. }
  576. */
  577. fetchData({type, path, sFrame: sfns, eFrame: efns}){
  578. // alert(path)
  579. if(window.workerReady){
  580. this.vDecoder.fetch({
  581. // path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/res/720p",
  582. path: path,
  583. // range: [sfns, efns],
  584. range: sfns == efns ? [efns] : [sfns, efns],
  585. });
  586. }
  587. else{
  588. console.error('还没准备好')
  589. }
  590. }
  591. mutiFetchData({type, videoDataArr}){
  592. console.log("[Walk]::videoData", videoDataArr)
  593. if(window.workerReady){
  594. // https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/optest/0/0_1_0/
  595. let sendData = []
  596. // let videoPathArr = [
  597. // "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1011",
  598. // "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1",
  599. // ]
  600. videoDataArr.forEach(data => {
  601. for(let i = 0; i < data.frame; i++) {
  602. sendData.push({
  603. path: data.path,
  604. frame: i,
  605. })
  606. }
  607. })
  608. this.vDecoder.mutiFetch(sendData);
  609. }
  610. else{
  611. console.error('还没准备好')
  612. }
  613. }
  614. /*******************************************************************************************************************************************/
  615. turnTo(e) {
  616. const {point: t, timeout: r=2e3, offset: n=8} = e || {}
  617. , o = {
  618. action_type: Actions.TurnTo,
  619. turn_to_action: {
  620. turn_to_point: t,
  621. offset: n
  622. }
  623. };
  624. return this.sendData({
  625. data: o,
  626. timeout: r
  627. })
  628. }
  629. rotateTo(e) {
  630. const {point: t, offset: r=0, speed: n=3} = e || {}
  631. , o = {
  632. action_type: Actions.RotateTo,
  633. rotate_to_action: {
  634. rotate_to_point: t,
  635. offset: r,
  636. speed: n
  637. }
  638. };
  639. console.log('发送数据rotateTo:'+JSON.stringify(o.rotate_to_action))
  640. return this.sendData({
  641. data: o
  642. })
  643. }
  644. broadcast(e) {
  645. const {data: t, msgType: r=MessageHandleType.MHT_FollowListMulticast, targetUserIds: n} = e;
  646. if (r === MessageHandleType.MHT_CustomTargetSync && !Array.isArray(n))
  647. return Promise.reject(new ParamError(`param targetUserIds is required when msgType is ${MessageHandleType[r]}`));
  648. const o = {
  649. action_type: Actions.Broadcast,
  650. broadcast_action: {
  651. data: JSON.stringify(t),
  652. user_id: this.room.options.userId,
  653. msgType: r
  654. }
  655. };
  656. return Array.isArray(n) && r === MessageHandleType.MHT_CustomTargetSync && (o.broadcast_action.target_user_ids = n),
  657. this.room.actionsHandler.sendData({
  658. data: o,
  659. tag: t.broadcastType
  660. })
  661. }
  662. getNeighborPoints(e) {
  663. const {point: t, containSelf: r=!1, searchRange: n=500} = e
  664. , o = {
  665. action_type: Actions.GetNeighborPoints,
  666. get_neighbor_points_action: {
  667. point: t,
  668. level: 1,
  669. containSelf: r,
  670. searchRange: n
  671. }
  672. };
  673. return this.sendData({
  674. data: o
  675. }).then(a=>a.nps)
  676. }
  677. playCG(e) {
  678. const t = {
  679. action_type: Actions.PlayCG,
  680. play_cg_action: {
  681. cg_name: e
  682. }
  683. };
  684. return this.sendData({
  685. data: t
  686. })
  687. }
  688. audienceToVisitor(e) {
  689. const {avatarId: t, avatarComponents: r, player: n, camera: o} = e
  690. , a = {
  691. action_type: Actions.AudienceChangeToVisitor,
  692. audienceChangeToVisitorAction: {
  693. avatarID: t,
  694. avatarComponents: r,
  695. player: n,
  696. camera: o
  697. }
  698. };
  699. return logger.debug("send data: audience to visitor"),
  700. this.sendData({
  701. data: a
  702. })
  703. }
  704. visitorToAudience(e) {
  705. const {renderType: t, player: r, camera: n, areaName: o, attitude: a, pathName: s, person: l, noMedia: u} = e
  706. , c = {
  707. action_type: Actions.VisitorChangeToAudience,
  708. visitorChangeToAudienceAction: {
  709. transferAction: {
  710. render_type: t,
  711. player: r,
  712. camera: n,
  713. areaName: o,
  714. attitude: a,
  715. pathName: s,
  716. person: {
  717. type: l
  718. },
  719. noMedia: u,
  720. tiles: [0, 1, 2, 4]
  721. }
  722. }
  723. };
  724. return logger.debug("send data: visitor to audience"),
  725. this.sendData({
  726. data: c
  727. })
  728. }
  729. removeVisitor(e) {
  730. const {removeType: t, userIDList: r, extraInfo: n=""} = e
  731. , o = {
  732. action_type: Actions.RemoveVisitor,
  733. removeVisitorAction: {
  734. removeVisitorEvent: t,
  735. userIDList: r,
  736. extraInfo: encodeURIComponent(n)
  737. }
  738. };
  739. return logger.debug("send data: remove visitor"),
  740. this.sendData({
  741. data: o
  742. })
  743. }
  744. getUserWithAvatar(e, t) {
  745. const r = {
  746. action_type: Actions.GetUserWithAvatar,
  747. getUserWithAvatarAction: {
  748. userType: e,
  749. roomID: t
  750. }
  751. };
  752. return logger.debug("send data: get user with avatar"),
  753. this.sendData({
  754. data: r
  755. }).then(n=>n.userWithAvatarList)
  756. }
  757. joystick(e) {
  758. const {degree: t, level: r=1} = e
  759. , n = util.uuid();
  760. let o = -t + 90 + 360;
  761. o >= 360 && (o -= 360);
  762. const a = {
  763. action_type: Actions.Joystick,
  764. dir_action: {
  765. move_angle: o,
  766. speed_level: r
  767. },
  768. trace_id: n,
  769. user_id: this.room.options.userId,
  770. packet_id: n
  771. };
  772. return this.sendData({
  773. data: a,
  774. track: !1
  775. })
  776. }
  777. }