Program Flow
-
A window is opened and loads the client script (
logic.js). -
It connects to the
SharedWorkerand registers its unique ID (viawindow.name). -
Every 500 ms, the window calculates and sends its current metrics:
x,y: screen positionwidth,height: window dimensionscenterX,centerY: computed midpoint
-
The
SharedWorkerstores this data and sends updates to all other windows (except the sender). -
Windows can manually request:
- Their own metrics (
getMyMetrics) - Other windows' metrics (
getOtherMetrics)
- Their own metrics (
- The UI reflects incoming updates with visual changes and logs.
Provided Functionality
- Real-time broadcasting of window metrics to all other connected windows
- Centralized state management for all windows (using IDs)
- Automatic polling and sync of:
- position (
x,y) - window size (
width,height) - center (
centerX,centerY)
- position (
- Manual querying of:
- own metrics (
getMyMetrics) - others' metrics (
getOtherMetrics)
- own metrics (
- UI integration for displaying and updating live values
- Loose coupling – windows don't know each other directly, only via shared state
Worker Code
This code is executed in the SharedWorker context.