{"_id":"@b9g/broadcastchannel-redis","name":"@b9g/broadcastchannel-redis","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@b9g/broadcastchannel-redis","version":"0.1.0","description":"Redis pub/sub backend for Shovel BroadcastChannel","keywords":["broadcast-channel","redis","pubsub","service-workers","shovel"],"author":{"name":"Shovel Team"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/bikeshaving/shovel.git","directory":"packages/broadcastchannel-redis"},"dependencies":{"@logtape/logtape":"^1.2.0","redis":"^4.6.10"},"devDependencies":{"@b9g/libuild":"^0.1.18"},"peerDependencies":{"@b9g/platform":"^0.1.19"},"type":"module","types":"src/index.d.ts","module":"src/index.js","exports":{".":{"types":"./src/index.d.ts","import":"./src/index.js"},"./index":{"types":"./src/index.d.ts","import":"./src/index.js"},"./index.js":{"types":"./src/index.d.ts","import":"./src/index.js"},"./package.json":"./package.json"},"gitHead":"4746a77de0329102f7f6a88fed1083afdbe82512","_id":"@b9g/broadcastchannel-redis@0.1.0","bugs":{"url":"https://github.com/bikeshaving/shovel/issues"},"homepage":"https://github.com/bikeshaving/shovel#readme","_nodeVersion":"25.5.0","_npmVersion":"11.8.0","dist":{"integrity":"sha512-YRuiXQ/XoGcjFJFbk4hKIvAOsvR2tXxHGVokQsrLohJsTaog09EoX3G2ZGXj+ROvkQ511OSk1mEnqPMhbFnSbA==","shasum":"f6e90a52dff8c36f6b8311e69e90d9da6cf6795e","tarball":"https://registry.npmjs.org/@b9g/broadcastchannel-redis/-/broadcastchannel-redis-0.1.0.tgz","fileCount":4,"unpackedSize":7737,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDAjvc2oODbmVe6ypdmitCsPlIKDTZpPLS1s0v6Ez2eWgIhAIND2NrRyAQAeYLAzOrHenlUmwrhWHXH6yDPdDtaz3OI"}]},"_npmUser":{"name":"brainkim","email":"briankimpossible@gmail.com"},"directories":{},"maintainers":[{"name":"brainkim","email":"briankimpossible@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/broadcastchannel-redis_0.1.0_1773684521555_0.9739920958009127"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-16T18:08:41.482Z","0.1.0":"2026-03-16T18:08:41.721Z","modified":"2026-03-16T18:08:41.914Z"},"maintainers":[{"name":"brainkim","email":"briankimpossible@gmail.com"}],"description":"Redis pub/sub backend for Shovel BroadcastChannel","homepage":"https://github.com/bikeshaving/shovel#readme","keywords":["broadcast-channel","redis","pubsub","service-workers","shovel"],"repository":{"type":"git","url":"git+https://github.com/bikeshaving/shovel.git","directory":"packages/broadcastchannel-redis"},"author":{"name":"Shovel Team"},"bugs":{"url":"https://github.com/bikeshaving/shovel/issues"},"license":"MIT","readme":"# @b9g/broadcastchannel-redis\n\nRedis pub/sub backend for Shovel's [BroadcastChannel](https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel) implementation. Enables cross-process message delivery using Redis `PUBLISH`/`SUBSCRIBE`.\n\n## Features\n\n- Cross-process BroadcastChannel relay via Redis\n- Automatic echo prevention (messages don't loop back to sender)\n- Two Redis connections created automatically (Redis requires separate connections for pub and sub)\n- Drop-in backend -- no changes to application BroadcastChannel code\n\n## Installation\n\n```bash\nnpm install @b9g/broadcastchannel-redis redis\n```\n\nRequires `@b9g/platform` as a peer dependency.\n\n## Usage\n\n```typescript\nimport {RedisPubSubBackend} from \"@b9g/broadcastchannel-redis\";\nimport {setBroadcastChannelBackend} from \"@b9g/platform/runtime\";\n\nsetBroadcastChannelBackend(new RedisPubSubBackend({\n  url: \"redis://localhost:6379\",\n}));\n```\n\nOnce configured, any `BroadcastChannel.postMessage()` call publishes to Redis, and messages from other processes are delivered to local BroadcastChannel instances automatically.\n\n### In Shovel Config\n\nConfigure in `shovel.json` to enable cross-process BroadcastChannel in production:\n\n```json\n{\n  \"broadcastChannel\": {\n    \"module\": \"@b9g/broadcastchannel-redis\",\n    \"export\": \"RedisPubSubBackend\",\n    \"url\": \"redis://localhost:6379\"\n  }\n}\n```\n\n## API\n\n### `new RedisPubSubBackend(options?)`\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `url` | `string?` | Redis default | Redis connection URL (e.g. `\"redis://localhost:6379\"`) |\n\nCreates two Redis client connections (publisher + subscriber) and connects them immediately.\n\n### Methods\n\nImplements the `BroadcastChannelBackend` interface:\n\n- **`publish(channelName, data)`** -- Publishes to Redis channel `shovel:bc:{channelName}` with sender ID\n- **`subscribe(channelName, callback)`** -- Subscribes to Redis channel, filters out own messages, returns unsubscribe function\n- **`dispose()`** -- Gracefully closes both Redis connections\n\n### Echo Prevention\n\nEach backend instance generates a random UUID on creation. Published messages include this sender ID in the payload. When a message is received via subscription, the sender ID is checked -- messages from the same instance are silently dropped. This prevents duplicate delivery when a process both publishes and subscribes to the same channel.\n\n## How It Works\n\n```\nProcess A                    Redis                    Process B\n─────────                    ─────                    ─────────\nbc.postMessage(\"hi\")\n  → publish(\"shovel:bc:chat\", {data:\"hi\", sender:\"A\"})\n                              → PUBLISH\n                              → subscriber B receives\n                                                      → sender !== \"B\" ✓\n                                                      → deliverBroadcastMessage(\"chat\", \"hi\")\n                              → subscriber A receives\n  → sender === \"A\" ✗ (skip)\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-a805df5ba51e919bcb085e227dc61e85"}