This project demonstrates how to integrate Five (Realsee's VR rendering engine) into a Next.js application. It serves as a reference implementation for getting started with Realsee's VR capabilities.
This project follows Next.js App Router and Vercel Best Practices:
- Server Components:
app/(pages)/[resourceCode]/page.tsxhandles routing and metadata (SEO). It imports the heavy VR client component dynamically. - Client Components:
components/FiveCanvas.tsxcontains all browser-specific logic (Five SDK, DOM manipulation, Window events). - Dynamic Imports:
components/FiveCanvasWrapper.tsxusesnext/dynamicwith{ ssr: false }to prevent server-side rendering of the VR engine, reducing the initial bundle size.
- Zustand: Used for global state management. The
Fiveinstance is stored inhooks/useFiveStore.ts, keeping it accessible to any component in the application without prop drilling. - SWR: Used for robust data fetching in
FiveCanvas.tsx. It handles caching, revalidation, and loading states automatically, ensuring a snappy user experience.
app/(pages): Contains UI routes (e.g., the VR demo page).app/(apis): Contains Backend API routes (e.g.,/api/vr/info).components/: Reusable React components.hooks/: Custom hooks (Zustand store).
- Backend Proxy: The
api/vr/inforoute acts as a proxy to the Realsee Gateway. It securely handlesApp KeyandApp Secreton the server, ensuring credentials are never exposed to the client.
app/(pages)/[resourceCode]/page.tsx: Main entry point for the VR demo.app/(apis)/api/vr/info/route.ts: Backend handler for fetching VR data.components/FiveCanvas.tsx: Core VR rendering component.hooks/useFiveStore.ts: Global state store.
Before you begin, ensure you have the following:
- Node.js: Version 18.17 or later.
- Realsee Developer Account: You need a valid
App KeyandApp Secret. - VR Resource Code: A valid code (e.g., a Work Code) for the VR content you wish to display.
-
Clone the repository or navigate to the project directory:
cd five-nextjs-demo -
Install the dependencies:
npm install # or yarn install # or pnpm install
Note: If you encounter issues with
sharp, the installation script handles compatibility automatically.
You must configure your Realsee credentials before running the application.
-
Create a
.env.localfile in the root directory. You can copy the example file:cp .env.example .env.local
-
Open
.env.localand update the following variables with your actual credentials:# The endpoint for the Realsee Gateway (usually https://app-gateway.realsee.ai) REALSEE_GATEWAY_ENDPOINT=https://app-gateway.realsee.ai # Your Realsee App Key REALSEE_GATEWAY_APP_KEY=your_app_key_here # Your Realsee App Secret REALSEE_GATEWAY_APP_SECRET=your_app_secret_here
Important: Never commit your
.env.localfile to version control to keep your secrets safe.
-
Start the development server:
npm run dev
-
Open your browser and navigate to the following URL format:
http://localhost:3000/<YOUR_RESOURCE_CODE>Replace
<YOUR_RESOURCE_CODE>with your actual VR resource code (e.g.,81gM551K00000000). -
The VR scene should load and become interactive.
- Cause: The
.env.localfile is missing or variables are empty. - Fix: Ensure
.env.localexists and containsREALSEE_GATEWAY_APP_KEYandREALSEE_GATEWAY_APP_SECRET.
- Cause: The App Secret provided in
.env.localdoes not match the App Key. - Fix: Double-check your credentials. Ensure there are no trailing spaces/newlines in the
.env.localfile.
- Cause: Network connectivity issues or incorrect Gateway Endpoint.
- Fix: Verify your internet connection and check if
REALSEE_GATEWAY_ENDPOINTis correct.
- Cause: The API might be failing silently or returning invalid data.
- Fix: Open the browser developer console (F12) and check for red error messages.
This project is licensed under the Realsee SDK License Agreement. See the LICENSE file for details.