# RCWeb Notepad App

The **RCWeb Notepad App** (`app/notepad`) is a massively simplified, real-time shared text editor. Engineered on the **Symmetric Pattern**, it enforces peer-to-peer data syncing so any participant in a virtual room can collaborate on a single plain-text document.

![icon](pwa-512x512.png "Notepad App Icon")

## Screenshot
![screenshot](screenshot.png "Notepad App")

## What it does

- **Real-Time Text Syncing**: Any user can type into the provided text area. Their entire text block is seamlessly transmitted and duplicated on the screen of every other peer almost instantly.
- **Discoverability via QR**: Automatically renders a QR Code of the current URL, letting users in the same physical space immediately pull the document up on their phones by scanning the screen.
- **Optimistic Joining**: When a new participant connects to a pre-existing room, the application politely queries active peers to blast their most recent document states backward to it so it catches up instantaneously.

## How it works

The application `script.js` relies strictly on raw HTML `<textarea>` polling paired with debounced RCWeb string payloads.

- **Payload Sync Mechanics**: The app binds to the native DOM `input` event (`addEventListener("input", maybeSendNotes)`). When triggered, it grabs the raw value of the textarea, escapes newline (`\n`) and quote markers (`\'`), and forcefully builds an `rc.send` proxy transmission designed to execute `notepad.updateNotes` indiscriminately on all active peers in the session.
- **Debounced Transmission**: Constantly evaluating the input tree would drown the WebSocket router in fragmented packets. The `maybeSendNotes` mechanism uses `window.setTimeout(sendNotes, 50)` to coalesce and debounce multiple keystrokes hit within 50 milliseconds into a single decisive network operation block.
- **Peer Discovery Integration**: Listens to server loop `rc.onUpdateNetworkStatus`; upon full connection, fires `notepad.requestRefresh()`. Remote clients counter this by running `notepad.refresh()`, forcing out a debounced `notepad.sendNotes()` response back to the newly attached device so there are no disparate text states across peers.
