Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
O

OpenAgoraWeb-React

> 前端框架
Open source

Video Call App built with :heart:Agora SDK:heart: and React

100 stars0 likes2 views
WebsiteGitHub

About

Video Call App built with :heart:Agora SDK:heart: and React

This repository has been deprecated, please use the demo provided by latest agora react rtc sdk

Open Video Call React

This tutorial describes how to add video chat to your ReactJS applications using the AgoraRTC SDK.

With this sample app, you can:

  • Join a meeting room with up to 7 people
  • Leave the meeting room
  • Disable/Enable audio
  • Disable/Enable video
  • Apply two layouts views
  • Hide a remote window

Prerequisites

  • Node.js 6.9.1+

Quick Start

This section shows you how to prepare, build, and run the sample application.

  • Create an Account and Obtain an App ID
  • Update and Run the Sample Application

Create an Account and Obtain an App ID

To build and run the sample application, you must obtain an app ID:

  1. Create a developer account at agora.io. Once you finish the sign-up process, you are redirected to the dashboard.
  2. Navigate in the dashboard tree on the left to Projects > Project List.
  3. Copy the app ID that you obtained from the dashboard into a text file. You will use this when you launch the app.

Update and Run the Sample Application

  1. Edit the src/agora.config.js file. In the AGORA_APP_ID declaration, update Your App ID with your app ID.
javascript
export const AGORA_APP_ID = 'Your App ID'
  1. Download the Agora Web Video SDK. Unzip the downloaded SDK package and copy the AgoraRTC-*.js file into the sample application's /src/library/ folder. Rename the file to AgoraRTC.js.

    Note: CDN can now be used to retrieve the latest SDK. You do not have to re-download SDK updates.

  2. Open the terminal and navigate to your project folder.

bash
cd path/to/project
  1. Use npm to install the dependencies:
bash
# install dependency
npm install
  1. Build and run the project:

Use start for a local build. View the application in your browser with the URL http://localhost:3000

bash
# serve with hot reload at localhost:3000
npm run start

Use build for a production version with minification.

bash
# build for production with minification
npm run build

Steps to Create the Sample

  • Add Assets
  • Create Index Page
  • Create Meeting Page
  • Create AgoraVideoCall Component

Add Assets

The sample application uses assets located in the src/assets/images folder.

Asset Image Description
ag-index-background.png Main application background image.
ag-logo.png Logo image for the application.
avatar.png Avatar image for the application.
ag-login.png
Image of a monitor, for login.
ag-audience.png and ag-audience-active.png

|Image of a person icon in a circle, to represent an audience member. ag-mic-s.png and ag-mic-active-s.png|

|Image of a microphone, to turn on/off audio. ag-video-s.png and ag-video-active-s.png|

|Video camera image, to turn on/off video. ag-oval.png and ag-oval-active.png|

|Circle image (empty and filled-in) to indicate selections.

Create Index Page

The Index page is managed by the src/pages/index/index.jsx file.

The Index page is comprised of four classes:

Class Description
Index Main class for the index page. The other classes are used in the layout for this class.
InputChannel Text input manager for the channel name.
BaseOptions Chooser for the type of call.
AdvancedOptions Chooser for video transcoding.
javascript
import React from 'react'
import * as Cookies from 'js-cookie'

import '../../assets/fonts/css/icons.css'
import Validator from '../../utils/Validator'
import { RESOLUTION_ARR } from '../../utils/Settings'
import './index.css'

class Index extends React.Component {
	...
}
class InputChannel extends React.Component {
	...
}
class BaseOptions extends React.Component {
	...
}
class AdvancedOptions extends React.Component {
	...
}

...

export default Index

Create the Index Class

The Index class is main class for the index page.

javascript
class Index extends React.Component {
  
  ...
  
}
  • Add the Constructor Method for the Index Class
  • Add Event Listeners for the Index Class
  • Add the Render Method for the Index Class
Add the Constructor Method for the Index Class

The constructor() method initializes the state properties for the class:

Property Value Description
joinBtn false Indicates if the Join button is enabled / disabled.
channel Empty string Name of the channel.
baseMode avc Indicates the current base mode for the call.
transcode interop Indicates the current transcoding setting.
attendeeMode video Indicates the current connection mode for the attendee.
videoProfile 480p_4 Indicates the current video profile setting.
javascript
  constructor(props) {
    super(props)
    this.state = {
      joinBtn: false,
      channel: '',
      baseMode: 'avc',
      transcode: 'interop',
      attendeeMode: 'video',
      videoProfile: '480p_4',

    }
  }
Add Event Listeners for the Index Class

The componentDidMount() method initializes event listener for keyboard presses.

When a keyboard button is pressed, ensure e.keyCode is the Enter / Return key before executing this.handleJoin().

javascript
  componentDidMount() {
    window.addEventListener('keypress', (e) => {
      e.keyCode === 13 && this.handleJoin()
    })
  }

The handleChannel() method updates the channel and joinBtn state properties.

javascript
  /**
   * 
   * @param {String} val 0-9 a-z A-Z _ only 
   * @param {Boolean} state 
   */
  handleChannel = (val, state) => {
    this.setState({
      channel: val,
      joinBtn: state
    })
  }

The handleJoin() method initiates joining the channel.

  1. Ensure the joinBtn state is false, otherwise stop the method execution with a return.
  2. Set a log for the state information using console.log.
  3. Set cookies for the state properties channel, baseMode, transcode, attendeeMode, and videoProfile.
  4. Transfer the user to the meeting page.
javascript
  handleJoin = () => {
    if (!this.state.joinBtn) {
      return
    }
    console.log(this.state)
    Cookies.set('channel', this.state.channel)
    Cookies.set('baseMode', this.state.baseMode)
    Cookies.set('transcode', this.state.transcode)
    Cookies.set('attendeeMode', this.state.attendeeMode)
    Cookies.set('videoProfile', this.state.videoProfile)
    window.location.hash = "meeting"
  }
Add the Render Method for the Index Class

The render() method displays the UI for the index page in the return().

The layout is comprised of three sections, specified by the class names ag-header, ag-main, and ag-footer.

The ag-main section contains the key login elements for the layout. The remaining code for this section is contained within the section sub-element.

The ag-footer section contains a Powered By Agora text and Agora contact information.

javascript
  render() {
    return (
      

        

        

        
      
    )
  }

The login-header section contains the Agora logo, application title, and the application motto / subtitle.

javascript
            

The login-body section is divided into three main sections:

  • The text input for the room name
  • The call options
  • The attendee mode options
javascript
            

              
              

                

              
              

              
            

The first section is a text input box for the room name / channel. The InputChannel element is nested within two div elements. The text input has onChange event listener which invokes the this.handleChannel method.

javascript
              

              

The second section is contains a BaseOptions component and a AdvancedOptions component.

The BaseOptions component has an onChange event listener which updates the baseMode state value.

The AdvancedOptions component has two event listeners:

  • An onRadioChange event listener which updates the transcode state value.
  • An OnSelectChange event listener which updates the videoProfile state value.
javascript
              

                

              

The third section is contains a set of radio dials and supporting images and text labels. Each radio input element has an onChange event listener which updates the attendeeMode state value.

javascript
              

                
              

The footer for the ag-main section contains a Join button, designated by an a element. The Join button has an onClick event listener which invokes the this.handleJoin method. This button is set to enabled / disabled by the joinBtn state value.

javascript
            

Add the InputChannel Class

The InputChannel class defines the room channel text input for the index page.

javascript
class InputChannel extends React.Component {
  
  ...
  
}
  • Add the Constructor Method for the InputChannel Class
  • Add Validation and Event Listeners for the InputChannel Class
  • Add the Render Method for the InputChannel Class
Add the Constructor for the InputChannel Class

The constructor() method initializes the state properties errorMsg and state to empty strings.

javascript
  constructor(props) {
    super(props)
    this.state = {
      errorMsg: '',
      state: ''
    }
  }
Add Validation and Event Listeners for the InputChannel Class

The validate() method checks the string for the text input and updates the state and errorMsg properties if necessary.

Set both properties to an empty string.

javascript
  validate = (val) => {
    this.setState({
      state: '',
      errorMsg: ''
    })
    
    ...
    
  }

Ensure the text input value is not empty using Validator.isNonEmpty. If the value is empty, update the errorMsg and state properties to inform the user that the text input should not be empty.

javascript
    if (Validator.isNonEmpty(val.trim())) {
      this.setState({
        errorMsg: 'Cannot be empty!',
        state: 'is-danger'
      })
      return false
    }

Ensure the text input value at least 1 character long. If the value is shorter than 1 character, update the errorMsg and state properties to inform the user that the text input should be longer than 1 character.

javascript
    else if (Validator.minLength(val.trim(), 1)) {
      this.setState({
        errorMsg: 'No shorter than 1!',
        state: 'is-danger'
      })
      return false
    }

Ensure the text input value 16 characters or shorter. If the value is longer than 16 characters, update the errorMsg and state properties to inform the user that the text input should no longer than 16 characters.

javascript
    else if (Validator.maxLength(val.t

Issues· 19 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptagorareactvideocallvideoconferencing-room

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架