@tangentfeed/transport-broadcast 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sreeraj T A
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @tangentfeed/transport-broadcast
2
+
3
+ BroadcastChannel transport for tangentfeed. Syncs replicas across tabs and workers on the same device, with no infrastructure.
4
+
5
+ Part of [tangentfeed](https://github.com/sreerajta/tangentfeed). MIT licensed.
@@ -0,0 +1,25 @@
1
+ import { Transport, WireMsg } from '@tangentfeed/core';
2
+
3
+ /**
4
+ * BroadcastChannel transport — same-origin, same-device sync (tabs, workers).
5
+ *
6
+ * BroadcastChannel is already a bus with exactly our Transport semantics:
7
+ * postMessage reaches every other listener on the channel name, never
8
+ * ourselves. Structured clone carries WireMsg objects natively. This file
9
+ * being ~30 lines is the proof the Transport interface is cut right; the
10
+ * WebRTC transport (M4) implements the same four members.
11
+ *
12
+ * Works in browsers and in Node ≥18 (worker_threads-backed), which is why the
13
+ * tests need no mocks.
14
+ */
15
+
16
+ declare class BroadcastTransport implements Transport {
17
+ private readonly channel;
18
+ private readonly listeners;
19
+ constructor(space: string);
20
+ send(msg: WireMsg): void;
21
+ onMessage(cb: (msg: WireMsg) => void): () => void;
22
+ close(): void;
23
+ }
24
+
25
+ export { BroadcastTransport };
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ // src/index.ts
2
+ var BroadcastTransport = class {
3
+ channel;
4
+ listeners = /* @__PURE__ */ new Set();
5
+ constructor(space) {
6
+ this.channel = new BroadcastChannel(`tangentfeed:${space}`);
7
+ this.channel.onmessage = (ev) => {
8
+ for (const cb of this.listeners) cb(ev.data);
9
+ };
10
+ }
11
+ send(msg) {
12
+ this.channel.postMessage(msg);
13
+ }
14
+ onMessage(cb) {
15
+ this.listeners.add(cb);
16
+ return () => this.listeners.delete(cb);
17
+ }
18
+ close() {
19
+ this.listeners.clear();
20
+ this.channel.close();
21
+ }
22
+ };
23
+ export {
24
+ BroadcastTransport
25
+ };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@tangentfeed/transport-broadcast",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "scripts": {
7
+ "test": "vitest run",
8
+ "build": "tsup src/index.ts --format esm --dts --clean",
9
+ "prepack": "npm run build"
10
+ },
11
+ "dependencies": {
12
+ "@tangentfeed/core": "0.2.0"
13
+ },
14
+ "devDependencies": {
15
+ "@types/node": "^20.0.0",
16
+ "typescript": "^5.5.0",
17
+ "vitest": "^2.0.0",
18
+ "tsup": "^8.5.0"
19
+ },
20
+ "description": "BroadcastChannel transport for tangentfeed (same-device tabs)",
21
+ "license": "MIT",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/sreerajta/tangentfeed.git",
25
+ "directory": "packages/transport-broadcast"
26
+ },
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md",
37
+ "LICENSE"
38
+ ],
39
+ "engines": {
40
+ "node": ">=20"
41
+ }
42
+ }