EventsController.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const log$6 = new Logger("eventsController");
  2. class EventsController {
  3. constructor(e) {
  4. E(this, "staticmeshEvent");
  5. E(this, "rotationEvent");
  6. E(this, "resize", ()=>{
  7. this.room.sceneManager.cameraComponent.cameraFovChange(this.room.sceneManager.yuvInfo)
  8. }
  9. );
  10. E(this, "clickEvent", e=>{
  11. const {point: t, name: r, type: n, id: o} = e;
  12. log$6.debug("pointEvent", e),
  13. this.room.proxyEvents("pointTap", {
  14. point: t,
  15. meshName: r,
  16. type: n,
  17. id: o
  18. }),
  19. this.room.proxyEvents("_coreClick", e)
  20. }
  21. );
  22. E(this, "longPressEvent", e=>{
  23. this.room.proxyEvents("_corePress", e)
  24. }
  25. );
  26. E(this, "handleActionResponseTimeout", ({error: e, event: t})=>{
  27. this.room.proxyEvents("actionResponseTimeout", {
  28. error: e,
  29. event: t
  30. })
  31. }
  32. );
  33. E(this, "handleNetworkStateChange", e=>{
  34. const {state: t, count: r} = e;
  35. t == "reconnecting" ? this.room.proxyEvents("reconnecting", {
  36. count: r || 1
  37. }) : t === "reconnected" ? (this.room.networkController.rtcp.workers.reset(),
  38. this.room.proxyEvents("reconnected"),
  39. this.room.afterReconnected()) : t === "disconnected" && this.room.proxyEvents("disconnected")
  40. }
  41. );
  42. this.room = e,
  43. this.staticmeshEvent = new StaticMeshEvent(this.room.sceneManager),
  44. this.rotationEvent = new RotationEvent(e)
  45. }
  46. bindEvents() {
  47. window.addEventListener("orientationchange"in window ? "orientationchange" : "resize", this.resize),
  48. this.staticmeshEvent.on("pointTap", this.clickEvent),
  49. this.staticmeshEvent.on("longPress", this.longPressEvent),
  50. this.rotationEvent.init(),
  51. eventsManager.on("actionResponseTimeout", this.handleActionResponseTimeout),
  52. this.room.networkController.on("stateChanged", this.handleNetworkStateChange)
  53. }
  54. clearEvents() {
  55. window.removeEventListener("orientationchange"in window ? "orientationchange" : "resize", this.resize),
  56. this.staticmeshEvent.off("pointTap", this.clickEvent),
  57. this.staticmeshEvent.off("longPress", this.longPressEvent),
  58. eventsManager.off("actionResponseTimeout", this.handleActionResponseTimeout),
  59. this.room.networkController.off("stateChanged", this.handleNetworkStateChange),
  60. this.rotationEvent.clear()
  61. }
  62. }