Task #42 — Timmy Harness: Expo Mobile App ## What was built - New Expo artifact at artifacts/mobile, slug `mobile`, preview path `/mobile/` - Three-tab bottom navigation (Face, Matrix, Feed) — NativeTabs with liquid glass on iOS 26+ - Dark wizard theme (#0A0A12 background, #7C3AED accent) ## WebSocket context (context/TimmyContext.tsx) - Full WebSocket connection to /api/ws with exponential backoff reconnect (1s→30s cap) - Sends visitor_enter handshake on connect, handles ping/pong - Derives timmyMood from agent_state events (idle/thinking/working/speaking) - recentEvents list capped at 100 - sendVisitorMessage() sets mood to "thinking" immediately on send (deterministic waiting state) - speaking mood auto-reverts after estimated TTS duration ## Face tab (app/(tabs)/index.tsx) - Animated 2D wizard face via react-native-svg (hat, head, beard, eyes, pupils, mouth arc, magic orb) - AnimatedPupils: pupilScaleAnim drives actual rendered pupil Circle radius (BASE_PUPIL_R * scale) - AnimatedEyelids: eyeScaleYAnim drives top eyelid overlay via Animated.Value listener - AnimatedMouth: smileAnim + mouthOscAnim combined; SVG Path rebuilt on each frame via listener - speaking mood: 1Hz mouth oscillation via Animated.loop; per-mood body bob speed/amplitude - @react-native-voice/voice installed and statically imported; Voice.onSpeechResults wired properly - startMicPulse/stopMicPulse declared before native voice useEffect (correct hook order) - Web Speech API typed with SpeechRecognitionWindow local interface (zero `any` casts) - sendVisitorMessage() called on final transcript (also triggers thinking mood immediately) - expo-speech TTS speaks Timmy's chat replies on native ## Matrix tab (app/(tabs)/matrix.tsx) - URL normalization: strips existing protocol, uses http for localhost, https for all other hosts - Full-screen WebView with loading spinner and error/retry state; iframe fallback for web ## Feed tab (app/(tabs)/feed.tsx) - FlatList<WsEvent> with proper generics; EventConfig discriminated union (Feather|MaterialCommunityIcons) - Icon names typed via React.ComponentProps["name"] (no `any`) - Color-coded events; event count in header; empty state with connection-aware message ## Type safety - TypeScript typecheck passes with 0 errors - No `any` casts anywhere in new code ## Deviations - expo-av removed (not used; voice input handled via @react-native-voice/voice + Web Speech API) - expo-speech/expo-av NOT in app.json plugins (no config plugins — causes PluginError if listed) - app.json extra.apiDomain added for env-driven domain configuration per requirement - expo-speech pinned ~14.0.8, react-native-webview 13.15.0 for Expo SDK 54 compat - artifact.toml ensurePreviewReachable removed (Expo uses expo-domain router) - @react-native-voice/voice works in Expo Go Android; iOS needs native build (graceful fallback) Replit-Task-Id: 0748cbbf-7b84-4149-8fc0-9d697287a0e6
136 lines
4.1 KiB
JavaScript
136 lines
4.1 KiB
JavaScript
/**
|
|
* Standalone production server for Expo static builds.
|
|
*
|
|
* Serves the output of build.js (static-build/) with two special routes:
|
|
* - GET / or /manifest with expo-platform header → platform manifest JSON
|
|
* - GET / without expo-platform → landing page HTML
|
|
* Everything else falls through to static file serving from ./static-build/.
|
|
*
|
|
* Zero external dependencies — uses only Node.js built-ins (http, fs, path).
|
|
*/
|
|
|
|
const http = require("http");
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const STATIC_ROOT = path.resolve(__dirname, "..", "static-build");
|
|
const TEMPLATE_PATH = path.resolve(__dirname, "templates", "landing-page.html");
|
|
const basePath = (process.env.BASE_PATH || "/").replace(/\/+$/, "");
|
|
|
|
const MIME_TYPES = {
|
|
".html": "text/html; charset=utf-8",
|
|
".js": "application/javascript; charset=utf-8",
|
|
".json": "application/json; charset=utf-8",
|
|
".css": "text/css; charset=utf-8",
|
|
".png": "image/png",
|
|
".jpg": "image/jpeg",
|
|
".jpeg": "image/jpeg",
|
|
".gif": "image/gif",
|
|
".svg": "image/svg+xml",
|
|
".ico": "image/x-icon",
|
|
".woff": "font/woff",
|
|
".woff2": "font/woff2",
|
|
".ttf": "font/ttf",
|
|
".otf": "font/otf",
|
|
".map": "application/json",
|
|
};
|
|
|
|
function getAppName() {
|
|
try {
|
|
const appJsonPath = path.resolve(__dirname, "..", "app.json");
|
|
const appJson = JSON.parse(fs.readFileSync(appJsonPath, "utf-8"));
|
|
return appJson.expo?.name || "App Landing Page";
|
|
} catch {
|
|
return "App Landing Page";
|
|
}
|
|
}
|
|
|
|
function serveManifest(platform, res) {
|
|
const manifestPath = path.join(STATIC_ROOT, platform, "manifest.json");
|
|
|
|
if (!fs.existsSync(manifestPath)) {
|
|
res.writeHead(404, { "content-type": "application/json" });
|
|
res.end(
|
|
JSON.stringify({ error: `Manifest not found for platform: ${platform}` }),
|
|
);
|
|
return;
|
|
}
|
|
|
|
const manifest = fs.readFileSync(manifestPath, "utf-8");
|
|
res.writeHead(200, {
|
|
"content-type": "application/json",
|
|
"expo-protocol-version": "1",
|
|
"expo-sfv-version": "0",
|
|
});
|
|
res.end(manifest);
|
|
}
|
|
|
|
function serveLandingPage(req, res, landingPageTemplate, appName) {
|
|
const forwardedProto = req.headers["x-forwarded-proto"];
|
|
const protocol = forwardedProto || "https";
|
|
const host = req.headers["x-forwarded-host"] || req.headers["host"];
|
|
const baseUrl = `${protocol}://${host}`;
|
|
const expsUrl = `${host}`;
|
|
|
|
const html = landingPageTemplate
|
|
.replace(/BASE_URL_PLACEHOLDER/g, baseUrl)
|
|
.replace(/EXPS_URL_PLACEHOLDER/g, expsUrl)
|
|
.replace(/APP_NAME_PLACEHOLDER/g, appName);
|
|
|
|
res.writeHead(200, { "content-type": "text/html; charset=utf-8" });
|
|
res.end(html);
|
|
}
|
|
|
|
function serveStaticFile(urlPath, res) {
|
|
const safePath = path.normalize(urlPath).replace(/^(\.\.(\/|\\|$))+/, "");
|
|
const filePath = path.join(STATIC_ROOT, safePath);
|
|
|
|
if (!filePath.startsWith(STATIC_ROOT)) {
|
|
res.writeHead(403);
|
|
res.end("Forbidden");
|
|
return;
|
|
}
|
|
|
|
if (!fs.existsSync(filePath) || fs.statSync(filePath).isDirectory()) {
|
|
res.writeHead(404);
|
|
res.end("Not Found");
|
|
return;
|
|
}
|
|
|
|
const ext = path.extname(filePath).toLowerCase();
|
|
const contentType = MIME_TYPES[ext] || "application/octet-stream";
|
|
const content = fs.readFileSync(filePath);
|
|
res.writeHead(200, { "content-type": contentType });
|
|
res.end(content);
|
|
}
|
|
|
|
const landingPageTemplate = fs.readFileSync(TEMPLATE_PATH, "utf-8");
|
|
const appName = getAppName();
|
|
|
|
const server = http.createServer((req, res) => {
|
|
const url = new URL(req.url || "/", `http://${req.headers.host}`);
|
|
let pathname = url.pathname;
|
|
|
|
if (basePath && pathname.startsWith(basePath)) {
|
|
pathname = pathname.slice(basePath.length) || "/";
|
|
}
|
|
|
|
if (pathname === "/" || pathname === "/manifest") {
|
|
const platform = req.headers["expo-platform"];
|
|
if (platform === "ios" || platform === "android") {
|
|
return serveManifest(platform, res);
|
|
}
|
|
|
|
if (pathname === "/") {
|
|
return serveLandingPage(req, res, landingPageTemplate, appName);
|
|
}
|
|
}
|
|
|
|
serveStaticFile(pathname, res);
|
|
});
|
|
|
|
const port = parseInt(process.env.PORT || "3000", 10);
|
|
server.listen(port, "0.0.0.0", () => {
|
|
console.log(`Serving static Expo build on port ${port}`);
|
|
});
|