@couch-kit/host 1.1.0 → 1.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@couch-kit/host",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
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,11 +1,5 @@
1
1
  import { useEffect, useState } from "react";
2
- import {
3
- documentDirectory,
4
- getInfoAsync,
5
- deleteAsync,
6
- makeDirectoryAsync,
7
- copyAsync,
8
- } from "expo-file-system/legacy";
2
+ import { Paths, Directory, File } from "expo-file-system/next";
9
3
  import { Platform } from "react-native";
10
4
  import { toErrorMessage } from "@couch-kit/core";
11
5
 
@@ -28,7 +22,7 @@ export interface ExtractAssetsResult {
28
22
  *
29
23
  * On Android, assets live inside the APK and cannot be served directly by
30
24
  * a native HTTP server. This hook copies each file listed in the manifest
31
- * from `asset:///www/<file>` to `${documentDirectory}www/<file>`.
25
+ * from `asset:///www/<file>` to `<Paths.document>/www/<file>`.
32
26
  *
33
27
  * On iOS, assets are accessible from the bundle directory, so extraction
34
28
  * is skipped and `staticDir` is returned as `undefined` (the server falls
@@ -53,42 +47,41 @@ export function useExtractAssets(manifest: AssetManifest): ExtractAssetsResult {
53
47
 
54
48
  const extractAssets = async () => {
55
49
  try {
56
- if (!documentDirectory) {
57
- throw new Error("Document directory is not available");
58
- }
59
-
60
- const targetDir = `${documentDirectory}www/`;
50
+ const documentDir = Paths.document;
51
+ const targetDir = new Directory(documentDir, "www");
61
52
 
62
53
  // Clean previous extraction to ensure fresh assets after app updates
63
- const dirInfo = await getInfoAsync(targetDir);
64
- if (dirInfo.exists) {
65
- await deleteAsync(targetDir, { idempotent: true });
54
+ if (targetDir.exists) {
55
+ targetDir.delete();
66
56
  }
67
57
 
68
58
  // Create the root target directory
69
- await makeDirectoryAsync(targetDir, { intermediates: true });
59
+ targetDir.create({ intermediates: true });
70
60
 
71
61
  // Copy each file from APK assets to filesystem
72
- for (const file of manifest.files) {
62
+ for (const filePath of manifest.files) {
73
63
  if (cancelled) return;
74
64
 
75
- const sourceUri = `asset:///www/${file}`;
76
- const destUri = `${targetDir}${file}`;
65
+ const sourceFile = new File(`asset:///www/${filePath}`);
66
+ const destFile = new File(targetDir, filePath);
77
67
 
78
68
  // Ensure subdirectory exists (e.g., "assets/" in "assets/index.js")
79
- const lastSlash = file.lastIndexOf("/");
69
+ const lastSlash = filePath.lastIndexOf("/");
80
70
  if (lastSlash > 0) {
81
- const subDir = `${targetDir}${file.substring(0, lastSlash)}`;
82
- await makeDirectoryAsync(subDir, { intermediates: true });
71
+ const subDir = new Directory(
72
+ targetDir,
73
+ filePath.substring(0, lastSlash),
74
+ );
75
+ subDir.create({ intermediates: true, idempotent: true });
83
76
  }
84
77
 
85
- await copyAsync({ from: sourceUri, to: destUri });
78
+ sourceFile.copy(destFile);
86
79
  }
87
80
 
88
81
  if (cancelled) return;
89
82
 
90
83
  // Strip file:// prefix for the native HTTP server
91
- const rawPath = targetDir.replace(/^file:\/\//, "");
84
+ const rawPath = targetDir.uri.replace(/^file:\/\//, "");
92
85
  setStaticDir(rawPath);
93
86
  } catch (e) {
94
87
  if (!cancelled) {
@@ -2,6 +2,9 @@
2
2
  * Minimal type definition for the raw TCP socket provided by react-native-tcp-socket.
3
3
  * Covers only the API surface used by GameWebSocketServer.
4
4
  */
5
+
6
+ import type { Buffer } from "buffer";
7
+
5
8
  export interface TcpSocketInstance {
6
9
  write(data: string | Buffer): void;
7
10
  destroy(): void;
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";
3
+ import { Paths } from "expo-file-system/next";
4
4
  import { getBestIpAddress } from "./network";
5
5
  import { DEFAULT_HTTP_PORT, toErrorMessage } from "@couch-kit/core";
6
6
 
@@ -51,9 +51,9 @@ export const useStaticServer = (config: CouchKitHostConfig) => {
51
51
  try {
52
52
  // Use staticDir if provided (required on Android where bundle path is undefined),
53
53
  // otherwise fall back to the iOS bundle directory via expo-file-system
54
+ const bundleUri = Paths.bundle.uri;
54
55
  const path =
55
- config.staticDir ||
56
- `${Paths.bundle.uri.replace(/^file:\/\//, "")}www`;
56
+ config.staticDir || `${bundleUri.replace(/^file:\/\//, "")}www`;
57
57
  const port = config.port || DEFAULT_HTTP_PORT;
58
58
 
59
59
  server = new StaticServer();