videosdk-live / videosdk-rtc-android-java-sdk-example

WebRTC based video conferencing SDK for Android (Java)

Home Page:https://docs.videosdk.live/android/guide/video-and-audio-calling-api-sdk/getting-started

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Documentation Firebase Discord Register

At Video SDK, we’re building tools to help companies create world-class collaborative products with capabilities of live audio/videos, compose cloud recordings/rtmp/hls and interaction APIs

Demo App

📱 Download the sample Android app here: https://appdistribution.firebase.dev/i/99ae2c5db3a7e446

Features

  • Real-time video and audio conferencing
  • Enable/disable camera
  • Mute/unmute mic
  • Switch between front and back camera
  • Change audio device
  • Screen share
  • Chat
  • Raise hand
  • Recording
  • External call detection

Setup Guide


Prerequisites


Run the Sample Project

1. Clone the sample project

Clone the repository to your local environment.

git clone https://github.com/videosdk-live/videosdk-rtc-android-java-sdk-example.git

2. Modify local.properties

Generate temporary token from Video SDK Account.

auth_token = "TEMPORARY-TOKEN";

3. Run the sample app

Run the android app with Shift+F10 or the ▶ Run from toolbar.


Key Concepts

  • Meeting - A Meeting represents Real time audio and video communication.

    Note : Don't confuse with Room and Meeting keyword, both are same thing 😃

  • Sessions - A particular duration you spend in a given meeting is a referred as session, you can have multiple session of a particular meetingId.

  • Participant - Participant represents someone who is attending the meeting's session, local partcipant represents self (You), for this self, other participants are remote participants.

  • Stream - Stream means video or audio media content that is either published by local participant or remote participants.


Android Permission

Add all the following permissions to AndroidManifest.xml file.

    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.CAMERA" />

    <!-- Needed to communicate with already-paired Bluetooth devices. (Legacy up to Android 11) -->
    <uses-permission
        android:name="android.permission.BLUETOOTH"
        android:maxSdkVersion="30" />
    <uses-permission
        android:name="android.permission.BLUETOOTH_ADMIN"
        android:maxSdkVersion="30" />

    <!-- Needed to communicate with already-paired Bluetooth devices. (Android 12 upwards)-->
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />


Token Generation

Token is used to create and validate a meeting using API and also initialise a meeting.

🛠️ Development Environment:

  • For development, you can use temporary token. Visit VideoSDK dashboard to generate temporary token.

🌐 Production Environment:

  • For production, you have to set up an authentication server to authorize users. Follow our official example repositories to setup authentication server, videosdk-rtc-api-server-examples

API: Create and Validate meeting

  • create meeting - Please refer this documentation to create meeting.
  • validate meeting- Please refer this documentation to validate the meetingId.

  1. For meeting initialization, you have to first initialize the VideoSDK. You can initialize the VideoSDK using initialize() method.
  VideoSDK.initialize(Context context)
  1. After successfully initialization, you can configure VideoSDK by passing token in config method
  VideoSDK.config(String token)
  1. After VideoSDK initialization and configuration, you can initialize the meeting using initMeeting() method. initMeeting() will generate a new Meeting class and the initiated meeting will be returned.
  Meeting meeting = VideoSDK.initMeeting(
                       Context context,
                       String meetingId,
                       String name,
                       boolean micEnabled,
                       boolean webcamEnabled,
                       String participantId)

// unmute mic
meeting.unmuteMic();

// mute mic
meeting.muteMic();

  • The meeting.getMics() function allows a participant to list all of the attached microphones (e.g., Bluetooth and Earphone).
 // get connected mics
 Set<AppRTCAudioManager.AudioDevice> mics = meeting.getMics();
  • Local participant can change the audio device using changeMic(AppRTCAudioManager.AudioDevice device) method of meeting class.
// change mic
 meeting.changeMic(AppRTCAudioManager.AudioDevice device);

Please consult our documentation Change Audio Device for more infromation.


// enable webcam
meeting.enableWebcam();

// disable webcam
meeting.disableWebcam();

// switch webcam
meeting.changeWebcam();

The chat feature allows participants to send and receive messages about specific topics to which they have subscribed.

// publish
meeting.pubSub.publish(String topic,String message, PubSubPublishOptions pubSubPublishoptions);

// pubSubPublishoptions is an object of PubSubPublishOptions, which provides an option, such as persist, which persists message history for upcoming participants.


//subscribe
List<PubSubMessage> pubSubMessageList = meeting.pubSub.subscribe(String topic, PubSubMessageListener pubSubMessageListener)


//unsubscribe
meeting.pubSub.unsubscribe(topic, PubSubMessageListener pubSubMessageListener);


// receiving messages
// PubSubMessageListener will be invoked with onMessageReceived(PubSubMessage message)
PubSubMessageListener pubSubMessageListener = new PubSubMessageListener() {
    @Override
    public void onMessageReceived(PubSubMessage message) {
        Log.d("#message", "onMessageReceived: " + message.getMessage());
    }
};

// Only one participant will leave/exit the meeting; the rest of the participants will remain.
meeting.leave();

// The meeting will come to an end for each and every participant. So, use this function in accordance with your requirements.
meeting.end();

By implementing MeetingEventListener, VideoSDK sends callbacks to the client app whenever there is a change or update in the meeting after a user joins.

  MeetingEventListener meetingEventListener = new MeetingEventListener() {
        @Override
        public void onMeetingJoined() {
           // This event will be emitted when a localParticipant(you) successfully joined the meeting.
        }

        @Override
        public void onMeetingLeft() {
           // This event will be emitted when a localParticipant(you) left the meeting.
        }

        @Override
        public void onParticipantJoined(Participant participant) {
           // This event will be emitted when a new participant joined the meeting.
           // [participant]: new participant who joined the meeting
        }

        @Override
        public void onParticipantLeft(Participant participant) {
           // This event will be emitted when a joined participant left the meeting.
           // [participant]: participant who left the meeting
        }

        @Override
        public void onPresenterChanged(String participantId) {
           // This event will be emitted when any participant starts or stops screen sharing.
           // [participantId]: Id of participant who shares the screen.
        }

        @Override
        public void onSpeakerChanged(String participantId) {
           // This event will be emitted when a active speaker changed.
           // [participantId] : Id of active speaker
        }

        @Override
        public void onRecordingStarted() {
           // This event will be emitted when recording of the meeting is started.
        }

        @Override
        public void onRecordingStopped() {
           // This event will be emitted when recording of the meeting is stopped.
        }

        @Override
        public void onExternalCallStarted() {
           // This event will be emitted when local particpant receive incoming call.
        }

        @Override
        public void onMeetingStateChanged(String state) {
           // This event will be emitted when state of meeting changes.
        }
    };

By implementing ParticipantEventListener, VideoSDK sends callbacks to the client app whenever a participant's video, audio, or screen share stream is enabled or disabled.

  ParticipantEventListener participantEventListener = new ParticipantEventListener() {
       @Override
       public void onStreamEnabled(Stream stream) {
          // This event will be triggered whenever a participant's video, audio or screen share stream is enabled.
       }

       @Override
       public void onStreamDisabled(Stream stream) {
          // This event will be triggered whenever a participant's video, audio or screen share stream is disabled.
       }
   };

If you want to learn more about, read the complete documentation of Android VideoSDK


Project Description


Note :

  • master branch: Better UI with One-to-One and Group call experience.
  • v1-code-sample branch: Simple UI with Group call experience.

App behaviour with different meeting types

  • One-to-One meeting - The One-to-One meeting allows 2 participants to join a meeting in the app.

  • Group meeting - The Group meeting allows 2 or more participants to join a meeting in the app.


Project Structure

We have 3 packages :

  1. OneToOneCall - OneToOneCall package includes all classes/files related to OneToOne meeting.
  2. GroupCall - GroupCall package includes all classes/files related to Group meeting.
  3. Common - Common package inclues all the classes/files that are used in both meeting type.

1. Create or Join Meeting

  • NetworkUtils.java - This class is used to call the api to generate token,create and validate the meeting.

  • CreateOrJoinActivity.java and activity_create_or_join.xml

    • This activity is used to ask permissions to the partcipant,and to initiate webcam and mic status.
    • CreateOrJoinFragment,CreateMeetingFragment,JoinMeetingFragment will be bound to this activity.
  • CreateOrJoinFragment.java and fragment_createorjoin.xml - This fragment will include

    • Create Meeting Button - This button will navigate to CreateMeetingFragment.
    • Join Meeting Button - This button will navigate to JoinMeetingFragment.

  • CreateMeetingFragment.java and fragment_create_meeting.xml - This fragement will include

    • Dropdown to select meeting type - This dropdown will give choice for meeting type.
    • EditText for ParticipantName - This edit text will contain name of the participant.
    • Create Meeting Button - This button will call api for create a new meeting and navigate to OneToOneCallActivity or GroupCallActivity according to user choice.

  • JoinMeetingFragment.java and fragment_join_meeting.xml - This fragement will include

    • Dropdown to select meeting type - This dropdown will give choice for meeting type.
    • EditText for ParticipantName - This edit text will contain name of the participant.
    • EditText for MeetingId - This edit text will contain the meeting Id that you want to join.
    • Join Meeting Button - This button will call api for join meeting with meetingId that you provided and navigate to OneToOneCallActivity or GroupCallActivity according to user choice.

2. ParticipantList

3. Dialogs




Examples

Examples for Conference

Examples for Live Streaming


Documentation

Read the documentation to start using Video SDK.


Community

  • Discord - To get involved with the Video SDK community, ask questions and share tips.
  • Twitter - To receive updates, announcements, blog posts, and general Video SDK tips.