Custom Screen Share Track - React Native
We have introduced the ability to pass a custom Screen Share track while sharing the screen of participants. This feature can be used to add custom video encoder config,background removal & video filter from external SDK(e.g., Banuba) and send it to other participants.
Creating a Custom Screen Share Track
- You can create a Screen Share track using
createScreenShareVideoTrack()
method ofVideoSDK
. - This method can be used to create screen share track using different encoding parameters.
Parameters
-
encoderConfig:
- type:
String
- required:
true
- default:
h720p_15fps
- Allowed values :
h360p_30fps
|h720p_5fps
|h720p_15fps
|h1080p_15fps
|h1080p_30fps
- It will be the encoderConfigs you can want to use for the Screen Share Track.
- type:
note
Above mentioned encoder configurations are valid for both, landscape as well as portrait mode.
-
data
- type:
Intent
- required:
true
- It is Intent received from onActivityResult when user provide permission for ScreenShare.
- type:
-
context
- type:
Context
- required:
true
- Pass the Android Context for this parameter.
- type:
-
listener
- type:
CustomTrackListener
- required:
true
- Callback to this listener will be made when track is ready with CustomTrack as parameter.
- type:
Example
- Kotlin
- Java
// data is received from onActivityResult method.
VideoSDK.createScreenShareVideoTrack("h720p_5fps", data, this) { track ->
meeting!!.enableScreenShare(track)
}
// data is received from onActivityResult method.
VideoSDK.createScreenShareVideoTrack("h720p_5fps", data, this, (track)->{
meeting.enableScreenShare(track);
});
Using Custom Screen Share Track
Custom Track with enableScreenShare()
In order to switch tracks during the meeting, you have to pass the CustomStreamTrack
in the enableScreenShare()
method of Meeting
.
note
Make sure to call disableScreenShare()
before you create a new track as it may lead to unexpected behavior.
- Kotlin
- Java
@TargetApi(21)
private fun askPermissionForScreenShare() {
val mediaProjectionManager = application.getSystemService<Any>(
Context.MEDIA_PROJECTION_SERVICE
) as MediaProjectionManager
startActivityForResult(
mediaProjectionManager.createScreenCaptureIntent(), CAPTURE_PERMISSION_REQUEST_CODE
)
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode != CAPTURE_PERMISSION_REQUEST_CODE) return
if (resultCode == RESULT_OK) {
VideoSDK.createScreenShareVideoTrack("h720p_5fps", data, this) { track ->
meeting!!.enableScreenShare(track)
}
}
}
@TargetApi(21)
private void askPermissionForScreenShare() {
MediaProjectionManager mediaProjectionManager =
(MediaProjectionManager) getApplication().getSystemService(
Context.MEDIA_PROJECTION_SERVICE);
startActivityForResult(
mediaProjectionManager.createScreenCaptureIntent(), CAPTURE_PERMISSION_REQUEST_CODE);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode != CAPTURE_PERMISSION_REQUEST_CODE)
return;
if (resultCode == Activity.RESULT_OK) {
VideoSDK.createScreenShareVideoTrack("h720p_5fps", data, this, (track)->{
meeting.enableScreenShare(track);
});
}
}
Got a Question? Ask us on discord