@couch-kit/host 1.3.0 → 1.3.1

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 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-tcp-socket
29
+ bun add react-native-tcp-socket react-native-nitro-modules
30
30
  ```
31
31
 
32
- > **Note:** This library requires Expo modules (`expo-file-system`, `expo-network`) and `react-native-tcp-socket` as peer dependencies. These must be installed in your consumer app. React Native's autolinking will handle native setup automatically.
32
+ > **Note:** This library requires Expo modules (`expo-file-system`, `expo-network`), `react-native-tcp-socket`, 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
 
@@ -45,8 +45,6 @@ bun add react-native-tcp-socket
45
45
 
46
46
  > **New Architecture:** This package supports React Native's New Architecture (Fabric/TurboModules) via React Native 0.83+.
47
47
 
48
- ## Usage
49
-
50
48
  ## API
51
49
 
52
50
  ### `<GameHostProvider config={...}>`
@@ -71,6 +69,36 @@ Returns:
71
69
  - `serverUrl`: HTTP URL phones should open (or `devServerUrl` in dev mode)
72
70
  - `serverError`: static server error (if startup fails)
73
71
 
72
+ ### `useExtractAssets(manifest)`
73
+
74
+ Extracts bundled web assets from the APK to a writable directory so the native HTTP server can serve them.
75
+
76
+ On Android, assets live inside the APK and cannot be served directly. This hook copies each file listed in the manifest from the APK to the device filesystem. On iOS, extraction is skipped since assets are accessible from the bundle directory.
77
+
78
+ ```tsx
79
+ import { useExtractAssets } from "@couch-kit/host";
80
+ import manifest from "./www/manifest.json";
81
+
82
+ function App() {
83
+ const { staticDir, loading, error } = useExtractAssets(manifest);
84
+
85
+ if (loading) return <Text>Extracting assets...</Text>;
86
+ if (error) return <Text>Error: {error}</Text>;
87
+
88
+ return (
89
+ <GameHostProvider config={{ staticDir, reducer, initialState }}>
90
+ ...
91
+ </GameHostProvider>
92
+ );
93
+ }
94
+ ```
95
+
96
+ | Property | Type | Description |
97
+ | ----------- | --------------------- | ------------------------------------------------- |
98
+ | `staticDir` | `string \| undefined` | Filesystem path to extracted assets, or undefined |
99
+ | `loading` | `boolean` | Whether extraction is in progress |
100
+ | `error` | `string \| null` | Error message if extraction failed |
101
+
74
102
  ## System Actions
75
103
 
76
104
  The host automatically dispatches internal system actions (`__PLAYER_JOINED__`, `__PLAYER_LEFT__`, `__PLAYER_RECONNECTED__`, `__PLAYER_REMOVED__`, `__HYDRATE__`) into `createGameReducer`, which handles them for you. **You do not need to handle these in your reducer.**
@@ -161,6 +189,8 @@ To iterate on your web controller without rebuilding the Android app constantly:
161
189
  ```tsx
162
190
  <GameHostProvider
163
191
  config={{
192
+ reducer: gameReducer,
193
+ initialState,
164
194
  devMode: true,
165
195
  devServerUrl: 'http://192.168.1.50:5173' // Your laptop's IP
166
196
  }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@couch-kit/host",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "React Native host for local multiplayer party games on Android TV — WebSocket server, state management, and static file serving",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/assets.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useState } from "react";
2
2
  import * as FileSystem from "expo-file-system";
3
- import { Paths, Directory } from "expo-file-system/next";
3
+ import { Paths, Directory } from "expo-file-system";
4
4
  import { Platform } from "react-native";
5
5
  import { toErrorMessage } from "@couch-kit/core";
6
6
 
package/src/server.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useState } from "react";
2
2
  import { StaticServer } from "react-native-nitro-http-server";
3
- import { Paths } from "expo-file-system/next";
3
+ import { Paths } from "expo-file-system";
4
4
  import { getBestIpAddress } from "./network";
5
5
  import { DEFAULT_HTTP_PORT, toErrorMessage } from "@couch-kit/core";
6
6
 
@@ -58,7 +58,7 @@ export const useStaticServer = (config: CouchKitHostConfig) => {
58
58
  if (!bundleUri) {
59
59
  throw new Error(
60
60
  "No staticDir provided and Paths.bundle is unavailable. " +
61
- "On Android, you must pass staticDir from useExtractAssets.",
61
+ "On Android, you must pass staticDir from useExtractAssets.",
62
62
  );
63
63
  }
64
64
  path = `${bundleUri.replace(/^file:\/\//, "")}www`;