EventsController.js 2.7 KB

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