DEV Community

Cover image for Build a Video Calling App in React with ZEGOCLOUD SDK – Step-by-Step Guide πŸš€
lifetime Coding
lifetime Coding

Posted on

Build a Video Calling App in React with ZEGOCLOUD SDK – Step-by-Step Guide πŸš€

πŸ“’ Introduction
Have you ever wanted to build a fully functional video calling app in React with minimal effort? 🀯

With ZEGOCLOUD SDK, you can integrate high-quality video calls into your React application within minutes!

In this guide, we will walk through how to use ZEGOCLOUD SDK to build a video calling app step by step.

This tutorial is perfect for beginners and intermediate React developers who want to learn about video call integration.

🎯 By the end of this tutorial, you will have a working video calling app deployed online!

Let’s get started! πŸš€

πŸ“Œ Prerequisites
Before we start, make sure you have:
βœ… Basic React knowledge
βœ… Node.js installed
βœ… A ZEGOCLOUD account (Sign up - https://www.zegocloud.com/)

πŸ”ΉStep 1: Set Up a ZEGOCLOUD Account

Image description

1️⃣ Go to ZEGOCLOUD's website β†’ Sign Up

Image description
2️⃣ Create a new project and get your AppID & AppSign

Image description

πŸ“Έ Make sure to note down the AppID & AppSign – we’ll use them in the code.

Image description

Creating a video call app
The following steps show you how to create a video call app using ZEGOCLOUD and react.

1.Create a new React project.
2.Install the ZEGOCLOUD React SDK.
3.Import the ZEGOCLOUD SDK into your project.
4.Join a room.
5.Create a local audio and video stream.
6.Start a video call.
7.Render the video streams.

  1. Add user controls (Mute, Camera Toggle, Leave Call, etc.)

Step 1: Create a new React Project
To start, create a new React app using Vite

npm create vite@latest video-call-app
npm run dev

After running the above commands, your React project is successfully set up. Now, open the project folder in VS Code and start the development server.

Next, let’s install the ZEGOCLOUD SDK to integrate video calling! πŸš€

step 2 : Install the ZEGOCLOUD React SDK

Now that our React project is set up, let's install the ZEGOCLOUD React SDK, which will help us integrate video calling functionality.

Run the following command in your project directory:

npm install zego-express-engine-react

What Does This Package Do?
πŸ“Ή zego-express-engine-react β†’ Provides real-time audio/video communication features using ZEGOCLOUD SDK.

Once installed, we’re ready to integrate ZEGOCLOUD into our React project! πŸš€

Next, let's set up the SDK and join a video call! πŸŽ₯

step 3: Import the ZEGOCLOUD SDK into your project.

Now that we have installed the ZEGOCLOUD React SDK, let's import it into our React project and initialize it.

1️⃣ Open your project and navigate to App.jsx or create a new component VideoCall.jsx.

2️⃣ Import the required ZEGOCLOUD SDK components:

import {zegoUiKitPrebuilt} from "@zegocloud/zego-uikit-prebuilt";

Step 4: join a room.

import React from 'react'
import { useParams } from 'react-router-dom'
import { ZegoUIKitPrebuilt } from '@zegocloud/zego-uikit-prebuilt';
import { APP_ID, SERVER_SECRET } from './constant';

const VideoPage = () => {
    const {id} = useParams();
    const roomID = id
    let myMeeting = async (element) => {
   // generate Kit Token
    const appID = APP_ID;
    const serverSecret = SERVER_SECRET;
    const kitToken =  ZegoUIKitPrebuilt.generateKitTokenForTest(appID, serverSecret, roomID, Date.now().toString(),"aanchalmittal");  
   // Create instance object from Kit Token.
    const zp = ZegoUIKitPrebuilt.create(kitToken);
    // start the call
    zp.joinRoom({
      container: element,
      sharedLinks: [
        {
          name: 'Copy link',
          url:
           window.location.protocol + '//' + 
           window.location.host + window.location.pathname +
            '?roomID=' +
            roomID,
        },
      ],
      scenario: {
        mode: ZegoUIKitPrebuilt.OneONoneCall, // To implement 1-on-1 calls, modify the parameter here to [ZegoUIKitPrebuilt.OneONoneCall].
      },
    });


};
  return (
    <div ref={myMeeting}>

    </div>
  )
}

export default VideoPage 
Enter fullscreen mode Exit fullscreen mode

What This Code Does?
βœ… Imports ZEGOCLOUD SDK into the project.
βœ… Generates a Kit Token for authentication.
βœ… Creates & joins a video call room.
βœ… Renders the video call UI inside a

.

Now, you can import VideoCall.jsx inside App.jsx and render it! πŸš€

Step 5: Create a Local Audio and Video Stream.

Now that we have joined a room, the next step is to create a local audio and video stream using the ZEGOCLOUD SDK. This will allow the user to capture their video and audio and stream it in real time.

πŸ“Œ Implementing Local Stream in React
1️⃣ Import the required dependencies and initialize the stream.
2️⃣ Use ZegoUIKitPrebuilt to access the user’s camera and microphone.
3️⃣ Render the local video stream inside a

.

Here’s the code snippet to set up the local stream in VideoCall.jsx:

πŸ› οΈ What This Code Does?
βœ… Initializes a unique user and room ID.
βœ… Uses ZegoUIKitPrebuilt.create() to create an instance.
βœ… Calls joinRoom() to start the local audio & video stream.
βœ… Renders the video stream inside a div.

Now, the user’s local video and audio will be streamed in the video call! πŸŽ₯πŸŽ™οΈ

βœ… Next Step: Start a Video Call

step 6 : Start a video call .
Now that we have set up the local audio and video stream, the next step is to start a video call where multiple participants can join and communicate in real time.

πŸ“Œ Implementing a Video Call in React
1️⃣ Use ZegoUIKitPrebuilt.create() to initialize the call.
2️⃣ Join the video call room with camera and microphone enabled.
3️⃣ Display all participants’ video streams dynamically.

Image description

πŸ› οΈ What This Code Does?
βœ… Initializes a video call room where users can join.
βœ… Allows multiple participants to communicate in real time.
βœ… Displays video streams of all users.
βœ… Adds call features like room timer, user list, and leave confirmation.

Now, when users join the room, their video and audio will be streamed live! πŸŽ₯πŸ“ž

βœ… Next Step: Render the Video Streams
Now that we have started the call, let’s proceed to Step 7: Render the Video Streams to display all participants' videos dynamically! πŸš€

step 7:Render the video streams.

Now that we have started a video call, we need to display the video streams of all participants dynamically. The ZEGOCLOUD SDK makes this easy by automatically handling the rendering of video streams for users in a call.

πŸ“Œ Rendering Video Streams in React
1️⃣ Use the ZegoUIKitPrebuilt component to manage video streams.
2️⃣ Dynamically update the UI as participants join or leave.
3️⃣ Handle multiple participants seamlessly in the video grid.

Image description

πŸ› οΈ What This Code Does?
βœ… Joins the video call room and streams live video.
βœ… Displays multiple users’ video feeds dynamically.
βœ… Handles user entries and exits smoothly.
βœ… Uses a grid layout to arrange video streams neatly.

βœ… Next Step: Add User Controls (Mute, Camera Toggle, Leave Call, etc.)
Now that the video streams are being rendered, let's add user controls like mute, camera toggle, and leave call to enhance the user experience! πŸš€

step 8:Add user controls (Mute, Camera Toggle, Leave Call, etc.)
To improve the user experience, we will add controls that allow users to:
βœ… Mute/Unmute their microphone 🎀
βœ… Turn their camera ON/OFF πŸ“·
βœ… Leave the call πŸšͺ

Image description

πŸ› οΈ What This Code Does?
βœ… Provides UI buttons for Mute, Camera Toggle, and Leave Call.
βœ… Allows users to enable/disable screen sharing.
βœ… Displays call duration, participant list, and layouts.
βœ… Auto-turns ON the camera and microphone when joining.

🎯 Conclusion
Congratulations! πŸŽ‰ You have successfully built a fully functional video calling app using React and ZEGOCLOUD SDK. πŸš€

Through this guide, you have learned how to:
βœ… Set up a ZEGOCLOUD account and create a project.
βœ… Install and integrate the ZEGOCLOUD React SDK.
βœ… Join a room and manage audio/video streams.
βœ… Render video streams and add user controls (Mute, Camera Toggle, Leave Call).

You can further improve your app by:
🎨 Customizing the UI to match your branding.
πŸ” Adding authentication for secure calls.
πŸ“‘ Integrating real-time chat for better user interaction.

Now, you’re all set to build and enhance your own video calling experience! πŸš€πŸ”₯

Happy coding .

Top comments (0)