Skip to content

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

Repository files navigation


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-kotlin-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(token: String?)
  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.
  val meeting: Meeting? = VideoSDK.initMeeting(
                            context: Context?,
                            meetingId: String?,
                            name: String?,
                            micEnabled: Boolean,
                            webcamEnabled: Boolean,
                            participantId: String?,
                            customTracks: Map<String?, CustomStreamTrack?>?
                        )

// unmute mic
meeting!!.unmuteMic()

// mute mic
meeting!!.muteMic()

  • The meeting.mics function allows a participant to list all of the attached microphones (e.g., Bluetooth and Earphone).
 // get connected mics
 val mics= meeting!!.mics
  • Local participant can change the audio device using changeMic(device: AudioDevice?) method of meeting class.
// change mic
meeting!!.changeMic(device: AudioDevice?) 

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(topic: String?, message: String?, options: PubSubPublishOptions) 

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


//subscribe
val pubSubMessageList = meeting!!.pubSub.subscribe(topic: String, listener: PubSubMessageListener)

//unsubscribe
meeting!!.pubSub.unsubscribe(topic: String, listener: PubSubMessageListener)


// receiving messages
// PubSubMessageListener will be invoked with onMessageReceived(PubSubMessage message)
var pubSubMessageListener: PubSubMessageListener? = PubSubMessageListener { message ->
                                                    Log.d("#message", "onMessageReceived: " + message.message)
                                                    }

// 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.

  val meetingEventListener: MeetingEventListener = object : MeetingEventListener() {
        override fun onMeetingJoined() {
           // This event will be emitted when a localParticipant(you) successfully joined the meeting.
        }

        override fun onMeetingLeft() {
           // This event will be emitted when a localParticipant(you) left the meeting.
        }

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

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

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

        override fun onSpeakerChanged(participantId: String?) {
           // This event will be emitted when a active speaker changed.
           // [participantId] : Id of active speaker
        }

        override fun onRecordingStarted() {
           // This event will be emitted when recording of the meeting is started.
        }

        override fun onRecordingStopped() {
           // This event will be emitted when recording of the meeting is stopped.
        }

        override fun onExternalCallStarted() {
           // This event will be emitted when local particpant receive incoming call.
        }

        override fun onMeetingStateChanged(state: String) {
           // 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.

  val participantEventListener: ParticipantEventListener = object : ParticipantEventListener() {
       override fun onStreamEnabled(stream: Stream) {
          // This event will be triggered whenever a participant's video, audio or screen share stream is enabled.
       }

       override fun 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.kt - This class is used to call the api to generate token,create and validate the meeting.

  • CreateOrJoinActivity.kt 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.kt and fragment_create_or_join.xml - This fragment will include

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

  • CreateMeetingFragment.kt 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.kt 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.