Ravvioli GitHub avatar

browsertabs-talking

Ravvioli

一个浏览器实验,利用 localStorage 作为跨窗口消息总线,让一个乒乓球在多个浏览器窗口之间无缝移动。

Stars

144

7 天增长

暂无数据

Fork 数

8

开放 Issue

0

开源协议

暂无数据

最近更新

2026-07-05

AI 仓库情报摘要
FR-AI / ANALYSIS

为什么值得关注

它展示了无需外部依赖的创意跨窗口协作方式,将任意桌面布局变成共享游戏台面。

适合谁使用

  • 探索窗口间通信的 Web 开发者
  • 构建多屏浏览器体验的创意编程者
  • 对新颖输入/输出设置感兴趣的游戏爱好者

典型使用场景

  • 学习如何用 localStorage 同步多窗口状态
  • 原型化横跨多块显示器的游戏或可视化
  • 创建让用户任意排列窗口的互动装置

项目优势

  • 无运行时依赖——仅使用浏览器 API
  • 简单的主机选举机制,即使标签页隐藏也能工作
  • 碰撞模型将窗口之间的间隙视为墙壁,相邻窗口视为房间

使用前须知

  • 碰撞检测仅使用前缘点,可能穿过极小的间隙
  • 需要多个独立浏览器窗口(不是标签页)
  • 必须通过 localhost 提供服务,不支持 file:// 协议

README 快速开始

Multi-Window Pong

A tiny browser experiment where one glowing Pong ball moves across multiple real browser windows as if the desktop were one shared table.

Open the same URL in two or three separate windows, arrange them on your screen, and the ball will cross between touching windows. Empty space between windows behaves like a wall.

How It Works

Browser windows from the same origin can communicate through localStorage. When one window writes to localStorage, every other open window receives a storage event.

This project uses that as a tiny message bus:

  1. Each window writes its screen rectangle: screenX, screenY, innerWidth, and innerHeight.
  2. All windows keep a live registry of the other windows.
  3. The window with the lowest id becomes the host.
  4. Only the host runs physics.
  5. The host broadcasts the ball position through localStorage.
  6. Every window renders the same global ball position relative to its own screenX/screenY.

That means each canvas is just a viewport into one shared screen-space coordinate system.

The collision model asks one simple question: is this screen point covered by any open window? If yes, the ball can move there. If no, it bounces. This makes touching windows behave like connected rooms while gaps behave like walls.

Run

Serve the folder over localhost. Do not open index.html directly with file://.

node server.js

Then open:

http://127.0.0.1:8000/

Use separate browser windows, not tabs.

Test

node physics.test.js
node windowRegistry.test.js
node viewport.test.js

The tests cover the important weird parts: open-room collision, hidden tab host election, and shared screen coordinates.

Files

  • index.html - full-window canvas and minimal styling
  • main.js - app wiring and animation loop
  • windowRegistry.js - window heartbeat, cleanup, and host election
  • physics.js - host-only ball physics
  • renderer.js - glowing trail renderer
  • viewport.js - shared screen-space window rectangle

Notes

This is intentionally dependency-free at runtime. It uses browser APIs, canvas, and localStorage.

The collision check probes the ball's leading edge, not its full swept circle. That is enough for normal window layouts. If you make tiny gaps or tight concave shapes, it may clip a corner.

相关仓库与替代方案

根据分类、Topic 和编程语言匹配的相似项目。

react
精选
react GitHub avatar

react

React is a JavaScript library for building user interfaces with declarative, component-based, and cross-platform design.

Web 开发前端框架
246,741
tandpfun
精选
tandpfun GitHub avatar

wardrobe

A GPT‑image powered app that extracts individual garment cutouts from photos, organizes them into a digital wardrobe, and generates modeled outfit previews.

JavaScript
1,570
mshumer
精选
mshumer GitHub avatar

Claude-of-Duty

A browser-based first-person shooter built entirely with procedural generation and orchestrated AI agents, featuring 55k lines of Three.js/WebGL2 code and no art assets.

AI 与机器学习AI 智能体
1,234