In this tutorial, we will guide you through creating a sales tool with Matterport and SuperViz. This tool allows sales teams to interactively present Matterport 3D spaces to clients in real-time, complete with video conferencing and live presence features. Whether you're showcasing real estate, virtual tours, or any 3D environment, this tool enhances the sales experience by enabling collaborative navigation and communication within the 3D space.
We'll demonstrate how to set up Matterport with SuperViz to enable real-time presence, video conferencing, and interactive features that help sales teams engage with clients more effectively.
Let's get started!
Prerequisite
To follow this tutorial, you will need a SuperViz account and a developer token. If you already have an account and a developer token, you can move on to the next step.
Create an account
To create an account, go to https://dashboard.superviz.com/register and create an account using either Google or an email/password. It's important to note that when using an email/password, you will receive a confirmation link that you'll need to click to verify your account.
Retrieving a Developer Token
To use the SDK, you’ll need to provide a developer token, as this token is essential for associating SDK requests with your account. You can retrieve both development and production SuperViz tokens from the dashboard..
Copy and save the developer token, as you will need it in the next steps of this tutorial.
Step 1: Set Up Your React Application
To begin, you'll need to set up a new React project where we will integrate SuperViz and Matterport Viewer.
1. Create a New React Project
First, create a new React application using Create React App with TypeScript.
1npm create vite@latest matterport-sales-tool -- --template react-ts2cd matterport-sales-tool
2. Install Required Libraries
Next, install the necessary libraries for our project:
1npm install @superviz/sdk @superviz/matterport-plugin uuid
- @superviz/sdk: SDK for integrating real-time collaboration features, including video conferencing and presence.
- @superviz/matterport-plugin: Plugin for adding SuperViz presence and interaction features to a Matterport Viewer.
- uuid: A library for generating unique identifiers, useful for creating unique participant IDs.
3. Configure tailwind
In this tutorial, we'll use the Tailwind css framework. First, install the tailwind package.
1npm install -D tailwindcss postcss autoprefixer2npx tailwindcss init -p
We then need to configure the template path. Open tailwind.config.js
in the root of the project and insert the following code.
1/** @type {import('tailwindcss').Config} */2export default {3content: [4"./index.html",5"./src/**/*.{js,ts,jsx,tsx}",6],7theme: {8extend: {},9},10plugins: [],11}
Then we need to add the tailwind directives to the global CSS file. (src/index.css)
1@tailwind base;2@tailwind components;3@tailwind utilities;
4. Set Up Environment Variables
Create a .env
file in your project root and add your SuperViz developer key and Matterport application key. These credentials will be used to authenticate your application with SuperViz and Matterport services.
1VITE_SUPERVIZ_API_KEY=YOUR_SUPERVIZ_DEVELOPER_KEY2VITE_MATTERPORT_KEY=YOUR_MATTERPORT_KEY
Step 2: Implement the Main Application
In this step, we'll implement the main application logic to initialize SuperViz and Matterport Viewer, and handle real-time presence and video conferencing.
1. Implement the App Component
Open src/App.tsx
and set up the main application component using SuperViz to manage the collaborative environment.
1import { v4 as generateId } from 'uuid';2import { useCallback, useEffect, useRef } from "react";3import SuperVizRoom, { VideoConference } from '@superviz/sdk';4import { Presence3D } from '@superviz/matterport-plugin';5import type { MpSdk } from '@superviz/matterport-plugin/dist/common/types/matterport.types.d.ts';
Explanation:
- Imports: Import necessary components from React, SuperViz SDK, Matterport Plugin, and UUID for managing state, initializing SuperViz, enabling video conferencing, and handling Matterport SDK interactions.
2. Define Constants
Define constants for the API key, Matterport key, and room ID.
1const apiKey = import.meta.env.VITE_SUPERVIZ_API_KEY as string;2const matterportKey = import.meta.env.VITE_MATTERPORT_KEY as string;34const ROOM_ID = 'matterport-sales-tool';5const PLAYER_ID = generateId();
Explanation:
- apiKey & matterportKey: Retrieves the SuperViz and Matterport API keys from environment variables.
- ROOM_ID & PLAYER_ID: Defines the room ID for the SuperViz session and generates a unique player ID.
3. Create the App Component
Set up the main App
component and initialize references for the Matterport SDK.
1export default function App() {2const matterportSDK = useRef<MpSdk | null>(null);34useEffect(() => {5initializeMatterport();6}, []);
Explanation:
- matterportSDK: A ref to store the Matterport SDK instance.
- useEffect: Calls the
initializeMatterport
function once when the component mounts, setting up the Matterport Viewer.
4. Initialize SuperViz
Create a function to initialize the SuperViz environment and integrate presence and video conferencing.
1const initializeSuperViz = useCallback(async () => {2const superviz = await SuperVizRoom(apiKey, {3roomId: ROOM_ID,4participant: {5id: PLAYER_ID,6name: 'player-name',7},8group: {9id: 'matterport-sales-tool',10name: 'matterport-sales-tool',11}12});1314const presence = new Presence3D(matterportSDK.current!);15superviz.addComponent(presence);1617const video = new VideoConference({18enableFollow: true,19enableGather: true,20enableGoTo: true,21userType: 'host'22});2324superviz.addComponent(video);25}, []);
Explanation:
- initializeSuperViz: An asynchronous function that initializes the SuperViz room, adds the presence component to track user interactions within the 3D space, and integrates video conferencing.
- Presence3D: Manages real-time presence in the Matterport space, showing where each participant is looking or interacting.
- VideoConference: Adds video conferencing with features like follow, gather, and go-to, enhancing the collaborative experience.
5. Initialize Matterport Viewer
Create a function to initialize the Matterport Viewer with the necessary credentials and configurations.
1const initializeMatterport = useCallback(async () => {2const showcase = document.getElementById('showcase') as MatterportIframe;3const showcaseWindow = showcase.contentWindow as MatterportIframe['window'];4const source = `/vendor/matterport/showcase.html?&play=1&qs=1&applicationKey=${matterportKey}&m=Zh14WDtkjdC`;5showcase.setAttribute('src', source);67await new Promise((resolve) => {8showcase.addEventListener('load', async () => {9matterportSDK.current = await showcaseWindow?.MP_SDK.connect(showcaseWindow, matterportKey);10resolve(matterportSDK.current);11});12});1314initializeSuperViz();15}, [initializeSuperViz]);
Explanation:
- initializeMatterport: Loads the Matterport Viewer in an iframe, connects the Matterport SDK, and then initializes SuperViz for real-time collaboration.
- initializeSuperViz: Called after Matterport is initialized to set up presence and video conferencing.
Step 3: Render the Application
Finally, return the JSX structure for rendering the Matterport Viewer and the SuperViz-powered interface.
1return (2<div className='w-full h-full bg-gray-200 flex items-center justify-center flex-col'>3<header className='w-full p-5 bg-purple-400 flex items-center justify-between'>4<h1 className='text-white text-2xl font-bold'>SuperViz Matterport Sales Tool</h1>5</header>6<main className='w-full h-full flex items-center justify-center relative'>7<iframe id='showcase' className='w-full h-full' />8</main>9</div>10);
Explanation:
- Viewer Container: The
showcase
iframe is where the Matterport Viewer will be rendered, filling the entire screen. This is where users will interact with the 3D space and collaborate in real time.
Step 4: Understanding the Project Structure
Here's a quick overview of how the project structure supports a Matterport sales tool:
App.tsx
:- Initializes the SuperViz environment.
- Sets up the Matterport Viewer with real-time presence and video conferencing features.
- Handles the loading of 3D spaces and integration of collaborative tools.
- Matterport Viewer: Renders the 3D space, allowing users to navigate, inspect, and collaborate in a shared virtual environment.
- SuperViz Components:
- Presence3D: Displays real-time presence information, showing where each participant is looking or interacting in the 3D space.
- VideoConference: Enables video communication within the 3D space, supporting collaborative sales presentations and discussions.
Step 5: Running the Application
1. Start the React Application
To run your application, use the following command in your project directory:
1npm run dev
This command will start the development server and open your application in the default web browser. You can interact with the 3D space and see real-time presence and video conferencing from other participants.
2. Test the Application
- Real-Time Presence: Open the application in multiple browser windows or tabs to simulate multiple participants and verify that presence information is updated in real-time.
- Collaborative Interaction: Test the video conferencing feature by starting a call within the 3D space and interacting with participants.
Summary
In this tutorial, we built a Matterport sales tool using SuperViz for real-time collaboration. We configured a React application to handle 3D space navigation and video conferencing, enabling multiple users to engage in a collaborative sales presentation seamlessly. This setup can be extended and customized to fit various scenarios where real-time collaboration on 3D spaces is required.
Feel free to explore the full code and further examples in the GitHub repository for more details.