@couch-kit/host 1.7.10 → 1.7.11
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/README.md +55 -6
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -26,10 +26,10 @@ Then install the required peer dependencies:
|
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
28
|
npx expo install expo-file-system expo-network
|
|
29
|
-
bun add react-native-
|
|
29
|
+
bun add react-native-nitro-modules
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
> **Note:** This library requires Expo modules (`expo-file-system`, `expo-network`)
|
|
32
|
+
> **Note:** This library requires Expo modules (`expo-file-system`, `expo-network`) and `react-native-nitro-modules` as peer dependencies. These must be installed in your consumer app. React Native's autolinking will handle native setup automatically.
|
|
33
33
|
|
|
34
34
|
## Compatibility
|
|
35
35
|
|
|
@@ -39,9 +39,8 @@ bun add react-native-tcp-socket react-native-nitro-modules
|
|
|
39
39
|
| `react-native` | `>= 0.72.0` |
|
|
40
40
|
| `react-native-nitro-modules` | `>= 0.33.0` |
|
|
41
41
|
| `expo` | `>= 51.0.0` |
|
|
42
|
-
| `expo-file-system` | `>=
|
|
42
|
+
| `expo-file-system` | `>= 19.0.0` |
|
|
43
43
|
| `expo-network` | `>= 7.0.0` |
|
|
44
|
-
| `react-native-tcp-socket` | `>= 6.0.0` |
|
|
45
44
|
|
|
46
45
|
> **New Architecture:** This package supports React Native's New Architecture (Fabric/TurboModules) via React Native 0.83+.
|
|
47
46
|
|
|
@@ -58,6 +57,8 @@ Config:
|
|
|
58
57
|
- `staticDir?`: absolute path to the directory of static files to serve. **Required on Android** — APK assets live inside a zip archive and cannot be served directly, so use this to point to a writable filesystem path where you've extracted the `www/` assets at runtime. On iOS, defaults to the bundle directory + `/www`.
|
|
59
58
|
- `devMode?`: if true, do not start the TV static file server; instead point phones at `devServerUrl`
|
|
60
59
|
- `devServerUrl?`: URL of your laptop dev server (e.g. `http://192.168.1.50:5173`)
|
|
60
|
+
- `stateThrottleMs?`: minimum interval (ms) between state broadcasts (default `33` ≈ 30fps)
|
|
61
|
+
- `disconnectTimeout?`: time (ms) before a disconnected player is permanently removed (default `300000` = 5 minutes)
|
|
61
62
|
- `debug?`: enable verbose logs
|
|
62
63
|
|
|
63
64
|
### `useGameHost()`
|
|
@@ -183,8 +184,8 @@ function GameScreen() {
|
|
|
183
184
|
|
|
184
185
|
To iterate on your web controller without rebuilding the Android app constantly:
|
|
185
186
|
|
|
186
|
-
1.
|
|
187
|
-
2.
|
|
187
|
+
1. Start your web project locally (`vite dev` usually runs on `localhost:5173`).
|
|
188
|
+
2. Configure the Host to point to your laptop:
|
|
188
189
|
|
|
189
190
|
```tsx
|
|
190
191
|
<GameHostProvider
|
|
@@ -206,3 +207,51 @@ Important: when the controller is served from the laptop, the client-side hook c
|
|
|
206
207
|
In production, the host serves static controller assets from the iOS bundle directory + `/www` by default. On Android, `staticDir` must be provided since bundle assets live inside the APK.
|
|
207
208
|
|
|
208
209
|
The CLI `couch-kit bundle` copies your web build output into `android/app/src/main/assets/www` (default). Ensure your app packaging makes those assets available under the expected `www` folder.
|
|
210
|
+
|
|
211
|
+
## Additional Hooks
|
|
212
|
+
|
|
213
|
+
### `useActionRecorder()`
|
|
214
|
+
|
|
215
|
+
Records game actions with timestamps for session replay and debugging. Useful for testing, bug reproduction, and replay-based features.
|
|
216
|
+
|
|
217
|
+
```tsx
|
|
218
|
+
import { useActionRecorder, useGameHost } from "@couch-kit/host";
|
|
219
|
+
|
|
220
|
+
function GameScreen() {
|
|
221
|
+
const { state } = useGameHost();
|
|
222
|
+
const { isRecording, recordedCount, startRecording, stopRecording, recordAction } =
|
|
223
|
+
useActionRecorder();
|
|
224
|
+
|
|
225
|
+
const handleStartRecording = () => startRecording(state);
|
|
226
|
+
const handleStop = () => {
|
|
227
|
+
const recording = stopRecording();
|
|
228
|
+
// Save recording JSON for later replay via `couch-kit replay`
|
|
229
|
+
console.log(JSON.stringify(recording));
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
return (
|
|
233
|
+
<View>
|
|
234
|
+
<Text>Actions recorded: {recordedCount}</Text>
|
|
235
|
+
<Button title={isRecording ? "Stop" : "Record"} onPress={isRecording ? handleStop : handleStartRecording} />
|
|
236
|
+
</View>
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Returns:
|
|
242
|
+
|
|
243
|
+
- `isRecording`: whether a recording session is active
|
|
244
|
+
- `recordedCount`: number of actions captured so far
|
|
245
|
+
- `startRecording(currentState, metadata?)`: begin recording from the given state
|
|
246
|
+
- `stopRecording()`: end recording and return the `ActionRecording` object (or `null`)
|
|
247
|
+
- `recordAction(action, state)`: capture a single action + resulting state
|
|
248
|
+
|
|
249
|
+
### `getBestIpAddress()`
|
|
250
|
+
|
|
251
|
+
Returns the device's best LAN IPv4 address (or `null`). Used internally by the provider but exported for custom networking UI (e.g., displaying a manual connect URL).
|
|
252
|
+
|
|
253
|
+
```tsx
|
|
254
|
+
import { getBestIpAddress } from "@couch-kit/host";
|
|
255
|
+
|
|
256
|
+
const ip = await getBestIpAddress(); // e.g. "192.168.1.99"
|
|
257
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@couch-kit/host",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.11",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -58,13 +58,13 @@
|
|
|
58
58
|
"prepublishOnly": "bun run build"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@couch-kit/core": "0.9.
|
|
61
|
+
"@couch-kit/core": "0.9.2",
|
|
62
62
|
"buffer": "^6.0.3",
|
|
63
63
|
"js-sha1": "^0.7.0",
|
|
64
64
|
"react-native-nitro-http-server": "^1.6.1"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@types/react": "^19.
|
|
67
|
+
"@types/react": "^19.2.17",
|
|
68
68
|
"react": "19.0.4",
|
|
69
69
|
"react-native": "0.83.2",
|
|
70
70
|
"del-cli": "^5.1.0",
|