@cloudflare/realtimekit-react 1.2.4 → 1.2.5-staging.3
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/AGENTS.md +45 -0
- package/package.json +3 -4
package/AGENTS.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# react/ — @cloudflare/realtimekit-react
|
|
2
|
+
|
|
3
|
+
Thin React wrapper (~2 source files) around `@cloudflare/realtimekit` providing a context provider, lifecycle hook, selector hook, and media pre-init utility.
|
|
4
|
+
|
|
5
|
+
## PUBLIC API
|
|
6
|
+
|
|
7
|
+
| Export | File | Purpose |
|
|
8
|
+
|--------|------|---------|
|
|
9
|
+
| `RealtimeKitProvider` | `src/context.tsx` | Context provider; renders `fallback` when `value` is falsy |
|
|
10
|
+
| `useRealtimeKitMeeting()` | `src/context.tsx` | Returns `{ meeting: RTKClient }`; throws outside provider |
|
|
11
|
+
| `useRealtimeKitClient(params?)` | `src/index.ts` | Manages client lifecycle; returns `[client, initClient]` |
|
|
12
|
+
| `useRealtimeKitSelector(selector)` | `src/index.ts` | Extracts + subscribes to a slice of `RTKClient` state |
|
|
13
|
+
| `initRTKMedia(options?, skipAwaits?, cachedUserDetails?)` | `src/index.ts` | Pre-inits media before `RTKClient.init`; wraps `RTKClient.initMedia` |
|
|
14
|
+
|
|
15
|
+
## REACTIVITY MODEL
|
|
16
|
+
|
|
17
|
+
`RealtimeKitProvider` creates an `RTKUpdates` instance (internal class, `src/context.tsx:12`) that attaches wildcard `'*'` listeners to every major SDK sub-module (`self`, `meta`, `participants`, `participants.joined/active/waitlisted`, `stage`, `livestream`, `chat`, `plugins.all`, `recording`, `connectedMeetings`, `polls`). Any event on any sub-module fans out to all registered `RTKUpdates` listeners.
|
|
18
|
+
|
|
19
|
+
`useRealtimeKitSelector` has two subscription modes:
|
|
20
|
+
1. **Direct** — if `selector(meeting)` returns an object with `addListener`, subscribes `'*'` on that object directly (e.g. `meeting.participants.joined`).
|
|
21
|
+
2. **Global fallback** — otherwise subscribes to the `RTKUpdates` bus.
|
|
22
|
+
|
|
23
|
+
Re-renders use a `useReducer` counter (`forceUpdate`) to bypass React's shallow-equality bailout when the same object reference is mutated.
|
|
24
|
+
|
|
25
|
+
`shouldUpdate` (`src/index.ts:125`) gates re-renders: fires if reference differs, or if both sides are arrays with different lengths.
|
|
26
|
+
|
|
27
|
+
## WHERE TO LOOK
|
|
28
|
+
|
|
29
|
+
| Task | Location |
|
|
30
|
+
|------|---------|
|
|
31
|
+
| Provider + `useRealtimeKitMeeting` | `src/context.tsx` |
|
|
32
|
+
| `useRealtimeKitClient`, `useRealtimeKitSelector`, `initRTKMedia` | `src/index.ts` |
|
|
33
|
+
| All re-exported core types | `src/index.ts:177–238` |
|
|
34
|
+
| Demo app (Chat, Meeting, Participants) | `example/` |
|
|
35
|
+
| Publish-time `package.json` rewrite | `prepublish.js` |
|
|
36
|
+
|
|
37
|
+
## GOTCHAS
|
|
38
|
+
|
|
39
|
+
- **100ms null-flash on `meetingChanged`** (`src/index.ts:108`): `useRealtimeKitClient` sets `client` to `undefined` then restores the new client after 100ms via `setTimeout`. This is intentional — React won't re-render when an object reference changes to a same-shape new object. Any UI reading `client` will briefly see `undefined`.
|
|
40
|
+
|
|
41
|
+
- **`cachedUserDetails` is experimental** (`src/index.ts:61`): The third param to `initRTKMedia` skips blocking network calls (chat, polls, etc.) using cached data. Not production-hardened; may silently miss fresh data.
|
|
42
|
+
|
|
43
|
+
- **`prepublish.js` rewrites `package.json`** before npm publish: pins `@cloudflare/realtimekit` dependency to the exact build version, strips dev scripts, sets `private: false`, and rewrites `publishConfig.tag` based on the `ENVIRONMENT` env var (`staging` → `tag: "staging"`, else `latest`). Never manually edit the published `package.json`.
|
|
44
|
+
|
|
45
|
+
- **`RTKUpdates.clean()` is called on provider unmount** but only via `updatesRef.current` — note `updatesRef` is never assigned in `context.tsx` (the `useRef` is unused). `setUpdates` state is what propagates `updates` to context; the `clean()` call on unmount uses the stale ref and is a no-op. Wildcard listeners are not removed on `value` change.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/realtimekit-react",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5-staging.3",
|
|
4
4
|
"description": "A real-time video and audio SDK for building custom, collaborative communication experiences.",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"module": "./dist/index.es.js",
|
|
@@ -17,14 +17,13 @@
|
|
|
17
17
|
},
|
|
18
18
|
"private": false,
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@cloudflare/realtimekit": "1.2.
|
|
20
|
+
"@cloudflare/realtimekit": "1.2.5-staging.3"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"react": ">=16.8.6"
|
|
24
24
|
},
|
|
25
25
|
"publishConfig": {
|
|
26
|
-
"
|
|
27
|
-
"tag": "latest"
|
|
26
|
+
"tag": "staging"
|
|
28
27
|
},
|
|
29
28
|
"scripts": {
|
|
30
29
|
"postpublish": "mv package.json.bak package.json"
|