Sample code
Here we provide you with a sample application to experience ZEGOCLOUD's In-app Chat, and also describe how to run the sample code.
Prepare the environment
- React Native 0.60.0 or later
- A real iOS device that is running on iOS 11.0 or later and supports audio and video.
- An Android device or Simulator that is running on Android 4.1 or later and supports audio and video. We recommend you use a real device (enable the "USB Debugging" option).
- Your device is connected to the internet.
- Configure Visual Studio Code, search for the "React Native Tools" extension and install it.
Prerequisites
- Go to ZEGOCLOUD Admin Console, and do the following:
- Create a project, get the AppID and AppSign.
- Subscribe to the In-app Chat service (contact us if the subscription doesn't go well).
For SDK 2.3.0
or later, the AppSign authentication mode and Token-based authentication mode are both supported.
If you want to change your authentication mode, please refer to the Upgrade the authentication mode from using the AppSign to Token.
Get the sample code
The following structure shows the subdirectory structure of the sample code:
.
├── App.js
├── Gemfile
├── __tests__
├── android
├── app.json
├── babel.config.js
├── index.js
├── ios
├── main.js
├── metro.config.js
├── package-lock.json
├── package.json
├── react-native.config.js
├── src
│ ├── assets
│ │ └── js
│ │ ├── config.js
│ ├── components
│ ├── hooks
│ │ └── zim.js
│ └── pages
│ ├── action
│ ├── chat
│ ├── group
│ ├── home
│ └── login
├───────
Run the sample code
-
In Visual Studio Code, import the sample code package file.
-
Modify the
config.js
file under thesrc/assets/js
folder with the AppID and AppSign that you get in the Prerequisites steps.Untitledexport const appConfig = { appID: , // Fill in the AppID you get. appSign: , // Fill in the AppSign you get. };
1If your project uses the "Token-based authentication mode", please go to the ZEGOCLOUD Admin Console to get a temporary Token for debugging.
-
Enter the root directory of the project, and run the
yarn install
to install dependencies. (for iOS devices, run thepod install
command instead.) -
If running the program on an iOS device, please navigate to the root directory of the project and execute the command
cd ios && pod install
to install dependencies. -
In the root directory, run the
yarn ios
or theyarn android
command to run the sample code.