|
1 |
| -import {Device} from '@/domain/models' |
2 |
| -import {appStore} from '@/store/app-store' |
3 | 1 | import {autorun, makeAutoObservable} from 'mobx'
|
4 | 2 | import {WheelEvent as ReactWheelEvent, RefObject} from 'react'
|
5 | 3 |
|
@@ -110,49 +108,6 @@ export class AppUIStore {
|
110 | 108 | const zoomAmount = -(event.deltaY / ZOOM_SENSITIVITY)
|
111 | 109 | this.setZoom(Math.max(Math.min(this.zoom + zoomAmount, 2), 0.2))
|
112 | 110 | }
|
113 |
| - |
114 |
| - private iframeListenUrlChange( |
115 |
| - iframe: HTMLIFrameElement, |
116 |
| - callback: (url: string) => void, |
117 |
| - ) { |
118 |
| - let lastDispatched: string |
119 |
| - let isFirstLoad: boolean = true |
120 |
| - |
121 |
| - const getUrl = () => iframe?.contentWindow?.location.href ?? '' |
122 |
| - |
123 |
| - const getUrlHandler = () => { |
124 |
| - const href = getUrl() |
125 |
| - |
126 |
| - if (lastDispatched !== href && !isFirstLoad) { |
127 |
| - console.log('dispatch') |
128 |
| - callback(href) |
129 |
| - lastDispatched = href |
130 |
| - } else { |
131 |
| - // prevent to dispatch when it's still the initial page |
132 |
| - isFirstLoad = false |
133 |
| - lastDispatched = href |
134 |
| - } |
135 |
| - } |
136 |
| - |
137 |
| - let intervalId: NodeJS.Timeout |
138 |
| - |
139 |
| - iframe.contentWindow?.addEventListener('load', () => { |
140 |
| - // clear interval if there's some |
141 |
| - if (intervalId) clearInterval(intervalId) |
142 |
| - intervalId = setInterval(getUrlHandler, 100) |
143 |
| - }) |
144 |
| - } |
145 |
| - |
146 |
| - syncLocation(devices: Device[]) { |
147 |
| - devices.forEach(device => { |
148 |
| - const selector = `#screen-${device.id} iframe` |
149 |
| - const iframe = document.querySelector<HTMLIFrameElement>(selector) |
150 |
| - |
151 |
| - if (!iframe) return |
152 |
| - |
153 |
| - this.iframeListenUrlChange(iframe, url => appStore.setUrl(url)) |
154 |
| - }) |
155 |
| - } |
156 | 111 | }
|
157 | 112 |
|
158 | 113 | export const appUIStore = new AppUIStore()
|
0 commit comments