12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import {eventsManager} from "./EventsManager.js"
- import StaticMeshEvent from "./StaticMeshEvent.js"
- import RotationEvent from "./RotationEvent.js"
- import Logger from "./Logger.js"
- const logger = new Logger('eventsController')
- export default class EventsController {
- constructor(o) {
- this.staticmeshEvent = null;
- this.rotationEvent = null;
- this.resize = ()=>{
- this.room.panorama.actived || this.room.sceneManager.cameraComponent.cameraFovChange(this.room.sceneManager.yuvInfo)
- };
- this.clickEvent = o=>{
- const {point: s, name: c, type: _, id: b} = o;
- logger.debug("pointEvent", o),
- this.room.proxyEvents("pointTap", {
- point: s,
- meshName: c,
- type: _,
- id: b
- }),
- this.room.proxyEvents("_coreClick", o)
- };
- this.longPressEvent = o=>{
- this.room.proxyEvents("_corePress", o)
- };
- this.handleActionResponseTimeout = ({error: o, event: s})=>{
- this.room.proxyEvents("actionResponseTimeout", {
- error: o,
- event: s
- })
- };
- this.handleNetworkStateChange = o=>{
- const {state: s, count: c} = o;
- s == "reconnecting" ? this.room.proxyEvents("reconnecting", {
- count: c || 1
- }) : s === "reconnected" ? (this.room.networkController.rtcp.workers.reset(),
- this.room.proxyEvents("reconnected"),
- this.room.afterReconnected()) : s === "disconnected" && this.room.proxyEvents("disconnected")
- };
- this.room = o,
- this.staticmeshEvent = new StaticMeshEvent(this.room.sceneManager),
- this.rotationEvent = new RotationEvent(o)
- }
- bindEvents() {
- window.addEventListener("orientationchange"in window ? "orientationchange" : "resize", this.resize),
- this.staticmeshEvent.on("pointTap", this.clickEvent),
- this.staticmeshEvent.on("longPress", this.longPressEvent),
- this.rotationEvent.init(),
- eventsManager.on("actionResponseTimeout", this.handleActionResponseTimeout),
- this.room.networkController.on("stateChanged", this.handleNetworkStateChange)
- }
- clearEvents() {
- window.removeEventListener("orientationchange"in window ? "orientationchange" : "resize", this.resize),
- this.staticmeshEvent.off("pointTap", this.clickEvent),
- this.staticmeshEvent.off("longPress", this.longPressEvent),
- eventsManager.off("actionResponseTimeout", this.handleActionResponseTimeout),
- this.room.networkController.off("stateChanged", this.handleNetworkStateChange),
- this.rotationEvent.clear()
- }
- }
|