-
Notifications
You must be signed in to change notification settings - Fork 36
[ux] sync dom elements to live view #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
raiden-staging
wants to merge
18
commits into
kernel:main
Choose a base branch
from
raiden-staging:ux-domsync
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,403
−1
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0e99dc7
[domsync]
raiden-staging 1cb0430
[domsync]
raiden-staging 76c5727
[domsync]
raiden-staging d8babbd
[domsync]
raiden-staging f1cb2e5
[domsync]
raiden-staging 33f7cbe
[domsync]
raiden-staging f1fd43d
[domsync]
raiden-staging a21eba4
[domsync]
raiden-staging ef8c060
[domsync]
raiden-staging b46bdec
[domsync]
raiden-staging b111ad5
[domsync]
raiden-staging 09c0c7a
[domsync]
raiden-staging 17b16c4
[domsync]
raiden-staging 71f5671
[domsync]
raiden-staging 61edc8d
[domsync]
raiden-staging f9d228c
[domsync]
raiden-staging 1489337
[domsync]
raiden-staging 2abd2e7
[domsync]
raiden-staging File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
images/chromium-headful/client/src/components/dom-overlay.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| <template> | ||
| <div v-if="enabled && showOverlay && hasFilteredElements" ref="overlay" class="dom-overlay" :class="{ disabled: tempDisabled }"> | ||
| <div | ||
| v-for="el in filteredTransformedElements" | ||
| :key="el.id" | ||
| class="dom-element" | ||
| :style="getElementStyle(el)" | ||
| @touchstart="onInputTap" | ||
| @mousedown="onInputTap" | ||
| /> | ||
| </div> | ||
| </template> | ||
|
|
||
| <style lang="scss" scoped> | ||
| .dom-overlay { | ||
| position: absolute; | ||
| top: 0; | ||
| left: 0; | ||
| width: 100%; | ||
| height: 100%; | ||
| pointer-events: none; | ||
| z-index: 110; | ||
|
|
||
| &.disabled { | ||
| pointer-events: none !important; | ||
| .dom-element { | ||
| pointer-events: none !important; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .dom-element { | ||
| position: absolute; | ||
| pointer-events: auto; | ||
| cursor: pointer; | ||
| border-radius: 3px; | ||
| /* Default style - will be overridden by inline styles */ | ||
| background: rgba(139, 92, 246, 0.1); | ||
| border: 1px solid rgba(139, 92, 246, 0.3); | ||
| } | ||
| </style> | ||
|
|
||
| <script lang="ts"> | ||
| import { Component, Vue, Prop } from 'vue-property-decorator' | ||
| import { DomElement, DomWindowBounds, DomElementType, DOM_TYPE_COLORS } from '~/neko/dom-types' | ||
|
|
||
| interface TransformedElement extends DomElement { | ||
| screenX: number | ||
| screenY: number | ||
| } | ||
|
|
||
| @Component({ | ||
| name: 'dom-overlay', | ||
| }) | ||
| export default class extends Vue { | ||
| @Prop({ type: Number, default: 1920 }) screenWidth!: number | ||
| @Prop({ type: Number, default: 1080 }) screenHeight!: number | ||
| @Prop({ type: Boolean, default: true }) showOverlay!: boolean | ||
| @Prop({ type: Array, default: () => ['inputs'] }) enabledTypes!: DomElementType[] | ||
|
|
||
| tempDisabled = false | ||
|
|
||
| get enabled(): boolean { | ||
| return this.$accessor.dom.enabled | ||
| } | ||
|
|
||
| get elements(): DomElement[] { | ||
| return this.$accessor.dom.elements | ||
| } | ||
|
|
||
| get hasElements(): boolean { | ||
| return this.$accessor.dom.hasElements | ||
| } | ||
|
|
||
| get windowBounds(): DomWindowBounds { | ||
| return this.$accessor.dom.windowBounds | ||
| } | ||
|
|
||
| // Filter elements by enabled types | ||
| get filteredElements(): DomElement[] { | ||
| if (this.enabledTypes.length === 0) return [] | ||
| return this.elements.filter((el) => this.enabledTypes.includes(el.type)) | ||
| } | ||
|
|
||
| get hasFilteredElements(): boolean { | ||
| return this.filteredElements.length > 0 | ||
| } | ||
|
|
||
| get filteredTransformedElements(): TransformedElement[] { | ||
| const bounds = this.windowBounds | ||
| const offsetX = bounds.x + bounds.chromeLeft | ||
| const offsetY = bounds.y + bounds.chromeTop | ||
|
|
||
| return this.filteredElements.map((el) => ({ | ||
| ...el, | ||
| screenX: offsetX + el.rect.x, | ||
| screenY: offsetY + el.rect.y, | ||
| })) | ||
| } | ||
|
|
||
| getElementStyle(el: TransformedElement): Record<string, string> { | ||
| const xPercent = (el.screenX / this.screenWidth) * 100 | ||
| const yPercent = (el.screenY / this.screenHeight) * 100 | ||
| const wPercent = (el.rect.w / this.screenWidth) * 100 | ||
| const hPercent = (el.rect.h / this.screenHeight) * 100 | ||
|
|
||
| // Get colors for this element type | ||
| const colors = DOM_TYPE_COLORS[el.type] || DOM_TYPE_COLORS.inputs | ||
|
|
||
| return { | ||
| left: `${xPercent}%`, | ||
| top: `${yPercent}%`, | ||
| width: `${wPercent}%`, | ||
| height: `${hPercent}%`, | ||
| background: colors.bg, | ||
| borderColor: colors.border, | ||
| } | ||
| } | ||
|
|
||
| onInputTap(e: MouseEvent | TouchEvent) { | ||
| e.preventDefault() | ||
| e.stopPropagation() | ||
|
|
||
| // Get click coordinates | ||
| let clientX: number, clientY: number | ||
| if ('touches' in e && e.touches.length > 0) { | ||
| clientX = e.touches[0].clientX | ||
| clientY = e.touches[0].clientY | ||
| } else if ('clientX' in e) { | ||
| clientX = e.clientX | ||
| clientY = e.clientY | ||
| } else { | ||
| return | ||
| } | ||
|
|
||
| // Find the neko overlay textarea - this is what handles input events | ||
| const overlay = document.querySelector('.player-container .overlay') as HTMLTextAreaElement | ||
|
|
||
| // Focus the textarea to trigger mobile keyboard | ||
| if (overlay) { | ||
| overlay.focus() | ||
|
|
||
| // Create event options | ||
| const eventInit: MouseEventInit = { | ||
| bubbles: true, | ||
| cancelable: true, | ||
| clientX, | ||
| clientY, | ||
| screenX: clientX, | ||
| screenY: clientY, | ||
| view: window, | ||
| button: 0, | ||
| buttons: 1, | ||
| } | ||
|
|
||
| // Temporarily enable pointer events on overlay if needed | ||
| const oldPointerEvents = overlay.style.pointerEvents | ||
| overlay.style.pointerEvents = 'auto' | ||
|
|
||
| // Dispatch mouse events to simulate a click | ||
| overlay.dispatchEvent(new MouseEvent('mousedown', eventInit)) | ||
| setTimeout(() => { | ||
| overlay.dispatchEvent(new MouseEvent('mouseup', { ...eventInit, buttons: 0 })) | ||
| // Restore pointer events | ||
| overlay.style.pointerEvents = oldPointerEvents | ||
| }, 20) | ||
| } | ||
|
|
||
| // Temporarily disable dom overlay for follow-up interactions | ||
| this.tempDisabled = true | ||
| setTimeout(() => { | ||
| this.tempDisabled = false | ||
| }, 500) | ||
| } | ||
| } | ||
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing CONNECTING state check causes orphaned WebSocket connections
Medium Severity
The
connectDomSync()guard only checks forWebSocket.OPENstate, notWebSocket.CONNECTING. When the main connection rapidly disconnects and reconnects, the old WebSocket'sonclosehandler fires asynchronously and schedules a reconnect timer. When this timer fires, if the new WebSocket is still inCONNECTINGstate, another WebSocket is created, orphaning the previous one. This causes resource leaks (orphaned connections that can't be closed) and state confusion as multiple handlers compete.