Skip to content

This project includes an SDK designed to simplify the implementation of essential communication features such as video call, text chat, and screen sharing.

Notifications You must be signed in to change notification settings

lyh990517/Android-WebRTC-SDK

Repository files navigation

Overview

This project uses a custom SDK that simplifies WebRTC integration to deliver seamless communication capabilities. It includes video call, real-time chat via data channel, and screen sharing using MediaProjection.

Feature Status
Video Call
Chat
Screen Sharing
File Transfer

Sample App Preview

스크린샷 2024-11-23 오전 12 52 16 스크린샷 2024-11-23 오전 12 52 28 스크린샷 2024-11-23 오전 12 53 17 스크린샷 2024-11-23 오전 12 57 31 스크린샷 2024-11-23 오전 12 54 22 스크린샷 2024-11-23 오전 12 58 16 스크린샷 2024-11-23 오전 12 58 16

How To Start Sample

  1. Create a Firebase Project:

    • Go to the Firebase Console.
    • Click on Add project and follow the steps to create your Firebase project.
  2. Create Firestore Database:

    • In the Firebase project overview, navigate to Build > Firestore Database.
    • Click Create database and follow the prompts to set up Firestore in either test or production mode.
  3. Download google-services.json:

    • Go to Project settings (click on the gear icon).
    • Under Your apps, select your Android app and download the google-services.json configuration file.
  4. Place google-services.json in Your Project:

    • Copy the downloaded google-services.json file.
    • Place it in the app directory of your project.
    스크린샷 2024-11-23 오전 12 51 09
  5. Creating a Room

    • Launch the app and select the option to "connect" or "connect with projection"
    • A unique number or word will be assigned to the created room.
  6. Joining a Room

    • To join a room created by another user, enter the assigned number or word for that room and click the "connect" or "connect with projection".
    • When both users connect to the same room by using the same number or word, the video call will begin.

With these simple steps, you can set up and enjoy video calls. Share the room number or word with other users to start a call together.

WebRTC Sdk Interface

interface WebRtcClient {
    fun connect(roomID: String)

    fun getEvent(): Flow<WebRtcEvent>

    suspend fun getRoomList(): Flow<List<String>?>

    fun sendMessage(message: String)

    fun sendInputEvent()

    fun getMessages(): Flow<Message>

    fun disconnect()

    fun toggleVoice()

    fun toggleVideo()

    fun getLocalSurface(): SurfaceViewRenderer

    fun getRemoteSurface(): SurfaceViewRenderer
}

WebRTC Sdk Usage

in Video Call

@Composable
fun VideoCallScreen() {
    val context = LocalContext.current
    val webrtcClient = remember { WebRtcClientFactory.create(context) } // 1. create client

    AndroidView(
        factory = {
            webrtcClient.getRemoteSurface() // 2. Initialize the UI to receive the other person's video
        }
    )
    AndroidView(
        factory = {
            webrtcClient.getLocalSurface() // 3. Initialize the UI to receive my video
        }
    )
    Button(
        onClick = {
            webrtcClient.connect("input roomId") // 4. try to connect
        },
    ) {
        Text("Connect")
    }
}

in Screen Share

@Composable
fun MediaProjectionScreen() {
    val context = LocalContext.current
    var webrtcClient by remember { mutableStateOf<WebRtcClient?>(null) }
    val mediaProjectionLauncher = rememberLauncherForActivityResult(
        contract = ActivityResultContracts.StartActivityForResult(),
        onResult = { result ->
            if (result.resultCode == RESULT_OK) {
                result.data?.let { intent ->
                    WebRtcCaptureService.startService(context, intent) // 2. start capture service
                }
            }
        }
    )

    LaunchedEffect(Unit) {
        val mediaProjectionManager =
            context.getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
        val captureIntent = mediaProjectionManager.createScreenCaptureIntent()

        mediaProjectionLauncher.launch(captureIntent) // 1. get media projection

        WebRtcCaptureService.getClient().collect { client -> webrtcClient = client } // 3. after the process of getting the media projection, initialize your client
    }

    webrtcClient?.getRemoteSurface()?.let { remote ->
        AndroidView(
            factory = { remote }
        )
    }
    webrtcClient?.getLocalSurface()?.let { local ->
        AndroidView(
            factory = { local }
        )
    }
    Button(
        onClick = {
            webrtcClient?.connect("input roomId") // 4. try to connect
        },
    ) {
        Text("Connect")
    }
}

Sdk Architecture

sdk arch

Sample App Modularization

12412t5r3t1

About

This project includes an SDK designed to simplify the implementation of essential communication features such as video call, text chat, and screen sharing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages