Giter VIP home page Giter VIP logo

easy_example_android's Introduction

ZEGOCLOUD easy example

Platform ZEGOCLOUD

Click the search button below to search documentation or error code

image

ZEGOCLOUD's easy example is a simple wrapper around our RTC product. You can refer to the sample code for quick integration.

Getting started

Prerequisites

Clone the repository

  1. Clone the easy example Github repository.
  2. Checkout to call_invite branch

Setup FCM

  1. Go to Firebase Console and create new project if you don't have one.
  2. Andd new Android app to your Firebase project. Download the google-service.json file and move it into your Android app module root directory.
  3. Add the google-services plugin as a dependency inside of your /android/build.gradle file:
buildscript {
  dependencies {
    // ... other dependencies
    classpath 'com.google.gms:google-services:4.3.10'
    // Add me --- /\
  }
}
  1. Execute the plugin by adding the following to your /android/app/build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services' // <- Add this line

Modify the project configurations

  • You need to modify appID to your own account, which can be obtained in the ZEGO Admin Console.
  • You need to set serverUrl to a valid URL that can be obtained for Zego auth token and post FCM notification request.

Run the sample code

  1. Connect the Android device to your computer.

  2. Open Android Studio, select the Android device you are using,click the Run 'app' in the upper center to run the sample code and experience the Live Audio Room service.

Integrate into your own project

Introduce SDK

In your setting.gradle file, add the jitpack maven .

pluginManagement {
    repositories {
        
        maven { url 'https://www.jitpack.io' } // <- Add this line
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven { url 'https://www.jitpack.io' } // <- Add this line
    }
}

Import the source code module

import the :zegoexpress module to your project

Choose the zegoexpress directory. And add dependency in your app's build.gradle's dependencies:

dependencies{
   implementation project(':zegoexpress') 
}

Setup FCM

Same as getting started section.

Setup backend service

  1. Generate Firebase Admin SDK Private Key

Generate Key 2. Click this deploy button to start deploy your service:

Deploy with Vercel

If you are using Firebase Cloud Functions, check this doc for usage and check this example code to make the FCM work with your project.

Method call

The calling sequence of the SDK interface is as follows: createEngine --> joinRoom --> setLocalVideoView/setRemoteVideoView --> leaveRoom

Create engine

Before using the SDK function, you need to create the instance of the SDK(Engine) first. We recommend creating it when the application starts. The sample code is as follows:

 ExpressManager.getInstance().createEngine(getApplication(), AppCenter.appID);

Join room

When you want to communicate with audio and video, you need to call the join room interface first.

If you need to invite other to join the call, you can send the invitation at the same time while you join the room.

binding.callUser.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        PermissionX.init(LoginActivity.this)
            .permissions(Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO)
            .request((allGranted, grantedList, deniedList) -> {
                if (allGranted) {
                    CloudMessage cloudMessage = new CloudMessage();
                    cloudMessage.targetUserID = binding.targetUserId.getText().toString();
                    cloudMessage.roomID = selfID;
                    cloudMessage.callType = "Video";
                    cloudMessage.callerUserID = selfID;
                    cloudMessage.callerUserName = selfName;
                    cloudMessage.callerIconUrl = selfIcon
                    HttpClient.getInstance().callUserByCloudMessage(cloudMessage, new HttpResult() {
                        @Override
                        public void onResult(int errorCode, String result) {
                            if (errorCode == 0) {
                                joinRoom(cloudMessage.roomID, cloudMessage.callerUserID,
                                    cloudMessage.callerUserName);
                            } else {
                                Toast.makeText(getApplication(), "callUserByCloudMessage failed:" + result,
                                    Toast.LENGTH_LONG).show();
                            }
                        }
                    });
                }
            });
    }
});

set video view

If your project needs to use the video communication function, you need to set the View for displaying the video, call setLocalVideoView for the local video, and call setRemoteVideoView for the remote video.

setLocalVideoView:

ExpressManager.getInstance().setLocalVideoView(binding.localTexture);

setLocalVideoView:

@Override
public void onRoomUserUpdate(String roomID, ZegoUpdateType updateType, ArrayList<ZegoUser> userList) {
    if (updateType == ZegoUpdateType.ADD) {
        for (int i = 0; i < userList.size(); i++) {
            ZegoUser user = userList.get(i);
            TextureView remoteTexture = binding.remoteTexture;
            binding.remoteName.setText(user.userName);
            setRemoteViewVisible(true);
            ExpressManager.getInstance().setRemoteVideoView(user.userID, remoteTexture);
        }
    } else {
        setRemoteViewVisible(false);
    }
}

leave room

When you want to leave the room, you can call the leaveroom interface.

ExpressManager.getInstance().leaveRoom();

How is call invitation works

  1. Device A starts the App to obtain the FCM Token, sends a POST request to https://server/store_fcm_token, and stores the UserID_A and FCM Token on the Server.

  2. Device B starts the App to obtain the FCM Token, sends a POST request to https://server/store_fcm_token, and stores the UserID_B and FCM Token on the Server.

  3. The App on Device B is killed.

  4. Device A sends the call_invitation_data by sending an HTTP request to https://server/send_call_invitation, and calls the loginRoom and startPublishingStream methods of ZegoExpressEngin to start the call.

  5. The Server sends a message to Device B via the Firebase messaging.send interface.

  6. Device B receives the call_invitation_data via the public void onMessageReceived(@NonNull RemoteMessage remoteMessage) interface and pops up the phone call invitation dialog.

  7. After clicking the system notification box, Device B starts the App and uses the call_invitation_data to call the loginRoom and startPublishingStream methods of ZegoExpressEngin to start the call.

easy_example_android's People

Contributors

larryluo1 avatar match-yang avatar nangonghuang avatar yerannnnnn avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easy_example_android's Issues

"Callback on recording completed" is too slow

When the streaming completed, the call back triggering for recorded video URL like "replay_url" is slow which is taken minimum a minute time to trigger. Can you please provide any way to speed up this process?

Importing the SDK leads to increasing the app size

The library file alone consists of 45.7MB size which leads to increasing the actual app size. Can you please let me know the way to reduce the app size or reduce the size of the library file. Here I've attached the analyzed APK screen shot for reference. Can you please check and let me know?

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.