EventsController.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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(o) {
  8. this.staticmeshEvent = null;
  9. this.rotationEvent = null;
  10. this.resize = ()=>{
  11. this.room.panorama.actived || this.room.sceneManager.cameraComponent.cameraFovChange(this.room.sceneManager.yuvInfo)
  12. };
  13. this.clickEvent = o=>{
  14. const {point: s, name: c, type: _, id: b} = o;
  15. logger.debug("pointEvent", o),
  16. this.room.proxyEvents("pointTap", {
  17. point: s,
  18. meshName: c,
  19. type: _,
  20. id: b
  21. }),
  22. this.room.proxyEvents("_coreClick", o)
  23. };
  24. this.longPressEvent = o=>{
  25. this.room.proxyEvents("_corePress", o)
  26. };
  27. this.handleActionResponseTimeout = ({error: o, event: s})=>{
  28. this.room.proxyEvents("actionResponseTimeout", {
  29. error: o,
  30. event: s
  31. })
  32. };
  33. this.handleNetworkStateChange = o=>{
  34. const {state: s, count: c} = o;
  35. s == "reconnecting" ? this.room.proxyEvents("reconnecting", {
  36. count: c || 1
  37. }) : s === "reconnected" ? (this.room.networkController.rtcp.workers.reset(),
  38. this.room.proxyEvents("reconnected"),
  39. this.room.afterReconnected()) : s === "disconnected" && this.room.proxyEvents("disconnected")
  40. };
  41. this.room = o,
  42. this.staticmeshEvent = new StaticMeshEvent(this.room.sceneManager),
  43. this.rotationEvent = new RotationEvent(o)
  44. }
  45. bindEvents() {
  46. window.addEventListener("orientationchange"in window ? "orientationchange" : "resize", this.resize),
  47. this.staticmeshEvent.on("pointTap", this.clickEvent),
  48. this.staticmeshEvent.on("longPress", this.longPressEvent),
  49. this.rotationEvent.init(),
  50. eventsManager.on("actionResponseTimeout", this.handleActionResponseTimeout),
  51. this.room.networkController.on("stateChanged", this.handleNetworkStateChange)
  52. }
  53. clearEvents() {
  54. window.removeEventListener("orientationchange"in window ? "orientationchange" : "resize", this.resize),
  55. this.staticmeshEvent.off("pointTap", this.clickEvent),
  56. this.staticmeshEvent.off("longPress", this.longPressEvent),
  57. eventsManager.off("actionResponseTimeout", this.handleActionResponseTimeout),
  58. this.room.networkController.off("stateChanged", this.handleNetworkStateChange),
  59. this.rotationEvent.clear()
  60. }
  61. }