Skip to content

Commit

Permalink
Merge pull request #763 from 100mslive/develop
Browse files Browse the repository at this point in the history
Release 0.9.94: Develop to main
  • Loading branch information
ygit authored Oct 31, 2022
2 parents 278780a + 0f8827e commit dc1d270
Show file tree
Hide file tree
Showing 62 changed files with 7,608 additions and 3,059 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ const getTrackSettings = () => {

const setupBuild = async () => {
const trackSettings = getTrackSettings();
const build = await HmsManager.build({ trackSettings });
const build = await HMSSDK.build({ trackSettings });
setInstance(build);
updateHms({ hmsInstance: build });
};
Expand Down
22 changes: 12 additions & 10 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
buildscript {
ext.kotlin_version = '1.5.30-RC'
ext.kotlin_version = '1.5.30-RC'
if (project == rootProject) {
repositories {
google()
jcenter()
mavenCentral()
gradlePluginPortal( )
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
}
}
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

apply plugin: 'com.android.library'
Expand Down Expand Up @@ -55,15 +56,16 @@ repositories {
url("$rootDir/../node_modules/react-native/android")
}
google()
jcenter()
mavenCentral()
gradlePluginPortal( )
maven { url 'https://jitpack.io' }
}

dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // From node_modules
implementation 'com.github.100mslive.android-sdk:lib:2.4.8'
implementation 'com.github.100mslive.android-sdk:lib:2.5.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.appcompat:appcompat:1.3.1'
Expand Down
33 changes: 8 additions & 25 deletions android/src/main/java/com/reactnativehmssdk/HMSDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -229,30 +229,22 @@ object HMSDecoder {
private fun getHmsAudioTrackSettings(hmsAudioTrackSettings: HMSAudioTrackSettings?): WritableMap {
val settings: WritableMap = Arguments.createMap()
if (hmsAudioTrackSettings != null) {
settings.putInt("maxBitrate", hmsAudioTrackSettings.maxBitrate)
settings.putDouble("volume", hmsAudioTrackSettings.volume)
settings.putBoolean(
"useHardwareAcousticEchoCanceler",
hmsAudioTrackSettings.useHardwareAcousticEchoCanceler
)
settings.putString("codec", hmsAudioTrackSettings.codec.name)
settings.putString("trackDescription", "")
settings.putString("initialState", hmsAudioTrackSettings.initialState.name)
}
return settings
}

private fun getHmsVideoTrackSettings(hmsVideoTrackSettings: HMSVideoTrackSettings?): WritableMap {
val settings: WritableMap = Arguments.createMap()
if (hmsVideoTrackSettings != null) {
settings.putString("codec", hmsVideoTrackSettings.codec.name)
settings.putInt("maxBitrate", hmsVideoTrackSettings.maxBitRate)
settings.putInt("maxFrameRate", hmsVideoTrackSettings.maxFrameRate)
settings.putString("cameraFacing", hmsVideoTrackSettings.cameraFacing.name)
settings.putString("trackDescription", hmsVideoTrackSettings.codec.name)
settings.putMap(
"resolution",
this.getHmsVideoTrackResolution(hmsVideoTrackSettings.resolution)
)
settings.putBoolean("disableAutoResize", hmsVideoTrackSettings.disableAutoResize)
settings.putBoolean("forceSoftwareDecoder", hmsVideoTrackSettings.forceSoftwareDecoder)
settings.putString("initialState", hmsVideoTrackSettings.initialState.name)
}
return settings
}
Expand Down Expand Up @@ -320,15 +312,15 @@ object HMSDecoder {
return hmsTrack
}

fun getPreviewTracks(tracks: Array<HMSTrack>?): WritableMap {
val hmsTracks: WritableMap = Arguments.createMap()
fun getPreviewTracks(tracks: Array<HMSTrack>?): WritableArray {
val hmsTracks: WritableArray = Arguments.createArray()
if (tracks != null) {
for (track: HMSTrack in tracks) {
if (track is HMSLocalVideoTrack) {
hmsTracks.putMap("videoTrack", this.getHmsLocalVideoTrack(track))
hmsTracks.pushMap(this.getHmsLocalVideoTrack(track))
}
if (track is HMSLocalAudioTrack) {
hmsTracks.putMap("audioTrack", this.getHmsLocalAudioTrack(track))
hmsTracks.pushMap(this.getHmsLocalAudioTrack(track))
}
}
}
Expand Down Expand Up @@ -425,15 +417,6 @@ object HMSDecoder {
return input
}

// private fun getHMSHlsRecordingConfig(data: HMSHlsRecordingConfig?): ReadableMap {
// val input = Arguments.createMap()
// if (data !== null) {
// input.putBoolean("singleFilePerLayer", data.singleFilePerLayer)
// input.putBoolean("videoOnDemand", data.videoOnDemand)
// }
// return input
// }

private fun getHMSHLSVariant(data: ArrayList<HMSHLSVariant>?): ReadableArray {
val variants = Arguments.createArray()
if (data !== null) {
Expand Down
208 changes: 119 additions & 89 deletions android/src/main/java/com/reactnativehmssdk/HMSHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@ import android.view.PixelCopy
import android.webkit.URLUtil
import androidx.annotation.RequiresApi
import com.facebook.react.bridge.*
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.uimanager.events.RCTEventEmitter
import java.io.ByteArrayOutputStream
import java.util.*
import live.hms.video.audio.HMSAudioManager
import live.hms.video.error.HMSException
import live.hms.video.media.codec.HMSAudioCodec
import live.hms.video.media.codec.HMSVideoCodec
import live.hms.video.events.AgentType
import live.hms.video.media.settings.*
import live.hms.video.media.tracks.HMSRemoteAudioTrack
import live.hms.video.media.tracks.HMSRemoteVideoTrack
import live.hms.video.media.tracks.HMSTrack
import live.hms.video.sdk.models.*
import live.hms.video.sdk.models.enums.AudioMixingMode
import live.hms.video.sdk.models.role.HMSRole
import live.hms.video.services.LogAlarmManager
import live.hms.video.utils.HMSLogger
import live.hms.video.utils.HmsUtilities
import org.webrtc.SurfaceViewRenderer

Expand Down Expand Up @@ -161,93 +160,148 @@ object HMSHelper {
return null
}

fun getTrackSettings(data: ReadableMap?): HMSTrackSettings? {
if (data == null) {
return null
fun getFrameworkInfo(data: ReadableMap?): FrameworkInfo? {
if (data != null &&
this.areAllRequiredKeysAvailable(
data,
arrayOf(Pair("version", "String"), Pair("sdkVersion", "String"))
)
) {
val version = data.getString("version") as String
val sdkVersion = data.getString("sdkVersion") as String
return FrameworkInfo(AgentType.REACT_NATIVE, sdkVersion, version)
}
return null
}

var useHardwareEchoCancellation = false
val requiredKeysUseHardwareEchoCancellation =
this.areAllRequiredKeysAvailable(
data,
arrayOf(Pair("useHardwareEchoCancellation", "Boolean"))
)
if (requiredKeysUseHardwareEchoCancellation) {
useHardwareEchoCancellation = data.getBoolean("useHardwareEchoCancellation")
fun getLogSettings(data: ReadableMap?): HMSLogSettings? {
if (data != null &&
this.areAllRequiredKeysAvailable(
data,
arrayOf(
Pair("level", "String"),
Pair("maxDirSizeInBytes", "String"),
Pair("isLogStorageEnabled", "Boolean")
)
)
) {
val level = getLogLevel(data.getString("level"))
val maxDirSizeInBytes = getLogAlarmManager(data.getString("maxDirSizeInBytes"))
val isLogStorageEnabled = data.getBoolean("isLogStorageEnabled")
return HMSLogSettings(maxDirSizeInBytes, isLogStorageEnabled, level)
}
return null
}

var video: ReadableMap? = null
val requiredKeysVideo = this.areAllRequiredKeysAvailable(data, arrayOf(Pair("video", "Map")))
if (requiredKeysVideo) {
video = data.getMap("video")
private fun getLogAlarmManager(logAlarmManager: String?): Long {
when (logAlarmManager) {
"DEFAULT_DIR_SIZE" -> {
return LogAlarmManager.DEFAULT_DIR_SIZE
}
"DEFAULT_LOGS_FILE_NAME" -> {
return LogAlarmManager.DEFAULT_LOGS_FILE_NAME.toLong()
}
"MAX_DIR_SIZE" -> {
return LogAlarmManager.MAX_DIR_SIZE.toLong()
}
}
return LogAlarmManager.DEFAULT_DIR_SIZE
}

var audio: ReadableMap? = null
val requiredKeysAudio = this.areAllRequiredKeysAvailable(data, arrayOf(Pair("audio", "Map")))
if (requiredKeysAudio) {
audio = data.getMap("audio")
private fun getLogLevel(logLevel: String?): HMSLogger.LogLevel {
when (logLevel) {
"VERBOSE" -> {
return HMSLogger.LogLevel.VERBOSE
}
"WARN" -> {
return HMSLogger.LogLevel.WARN
}
"ERROR" -> {
return HMSLogger.LogLevel.ERROR
}
}
return HMSLogger.LogLevel.VERBOSE
}

if (video == null && audio == null && !useHardwareEchoCancellation) {
fun getTrackSettings(data: ReadableMap?): HMSTrackSettings? {
if (data == null) {
return null
}
val builder = HMSTrackSettings.Builder()
if (this.areAllRequiredKeysAvailable(data, arrayOf(Pair("video", "Map")))) {
val video = data.getMap("video")
val videoSettings = this.getVideoTrackSettings(video)
if (videoSettings != null) {
builder.video(videoSettings)
}
}

val videoSettings = this.getVideoTrackSettings(video)
val audioSettings = this.getAudioTrackSettings(audio, useHardwareEchoCancellation)
val trackSettingsBuilder = HMSTrackSettings.Builder()
return trackSettingsBuilder.audio(audioSettings).video(videoSettings).build()
if (this.areAllRequiredKeysAvailable(data, arrayOf(Pair("audio", "Map")))) {
val audio = data.getMap("audio")
val audioSettings = this.getAudioTrackSettings(audio)
if (audioSettings != null) {
builder.audio(audioSettings)
}
}
return builder.build()
}

private fun getAudioTrackSettings(
data: ReadableMap?,
useHardwareEchoCancellation: Boolean
): HMSAudioTrackSettings {
val builder =
HMSAudioTrackSettings.Builder()
.setUseHardwareAcousticEchoCanceler(useHardwareEchoCancellation)

if (data != null) {
val maxBitrate = data.getInt("maxBitrate")
val codec = getAudioCodec(data.getString("codec"))

builder.maxBitrate(maxBitrate)
builder.codec(codec)
private fun getAudioTrackSettings(data: ReadableMap?): HMSAudioTrackSettings? {
if (data == null) {
return null
}
val builder = HMSAudioTrackSettings.Builder()
if (areAllRequiredKeysAvailable(data, arrayOf(Pair("useHardwareEchoCancellation", "Boolean")))
) {
val useHardwareEchoCancellation = data.getBoolean("useHardwareEchoCancellation")
builder.setUseHardwareAcousticEchoCanceler(useHardwareEchoCancellation)
}

if (areAllRequiredKeysAvailable(data, arrayOf(Pair("initialState", "String")))) {
val initialState = getHMSTrackSettingsInitState(data.getString("initialState"))
builder.initialState(initialState)
}
return builder.build()
}

// TODO: find out a way to set settings required to create HMSVideoTrackSettings

private fun getVideoTrackSettings(data: ReadableMap?): HMSVideoTrackSettings {
private fun getVideoTrackSettings(data: ReadableMap?): HMSVideoTrackSettings? {
if (data == null) {
return null
}
val builder = HMSVideoTrackSettings.Builder()
if (data != null) {
val codec = getVideoCodec(data.getString("codec"))
val resolution = getVideoResolution(data.getMap("resolution"))
val maxBitrate = data.getInt("maxBitrate")
val maxFrameRate = data.getInt("maxFrameRate")
val cameraFacing = getCameraFacing(data.getString("cameraFacing"))

builder.codec(codec)
if (areAllRequiredKeysAvailable(data, arrayOf(Pair("cameraFacing", "String")))) {
val cameraFacing = getCameraFacing(data.getString("cameraFacing"))
builder.cameraFacing(cameraFacing)
if (resolution != null) {
builder.resolution(resolution)
}
builder.maxBitrate(maxBitrate)
builder.maxFrameRate(maxFrameRate)
}

if (areAllRequiredKeysAvailable(data, arrayOf(Pair("disableAutoResize", "Boolean")))) {
val disableAutoResize = data.getBoolean("disableAutoResize")
builder.disableAutoResize(disableAutoResize)
}

if (areAllRequiredKeysAvailable(data, arrayOf(Pair("initialState", "String")))) {
val initialState = getHMSTrackSettingsInitState(data.getString("initialState"))
builder.initialState(initialState)
}

if (areAllRequiredKeysAvailable(data, arrayOf(Pair("forceSoftwareDecoder", "Boolean")))) {
val forceSoftwareDecoder = data.getBoolean("forceSoftwareDecoder")
builder.forceSoftwareDecoder(forceSoftwareDecoder)
}
return builder.build()
}

private fun getVideoResolution(map: ReadableMap?): HMSVideoResolution? {
val width = map?.getDouble("width")
val height = map?.getDouble("height")

return if (width != null && height != null) {
HMSVideoResolution(width = width.toInt(), height = height.toInt())
} else {
null
private fun getHMSTrackSettingsInitState(initState: String?): HMSTrackSettings.InitState {
when (initState) {
"UNMUTED" -> {
return HMSTrackSettings.InitState.UNMUTED
}
"MUTED" -> {
return HMSTrackSettings.InitState.MUTED
}
}
return HMSTrackSettings.InitState.UNMUTED
}

fun getAudioMixingMode(audioMixingMode: String?): AudioMixingMode {
Expand All @@ -265,30 +319,6 @@ object HMSHelper {
return AudioMixingMode.TALK_AND_MUSIC
}

private fun getAudioCodec(codecString: String?): HMSAudioCodec {
when (codecString) {
"opus" -> {
return HMSAudioCodec.OPUS
}
}
return HMSAudioCodec.OPUS
}

private fun getVideoCodec(codecString: String?): HMSVideoCodec {
when (codecString) {
"H264" -> {
return HMSVideoCodec.H264
}
"VP8" -> {
return HMSVideoCodec.VP8
}
"VP9" -> {
return HMSVideoCodec.VP9
}
}
return HMSVideoCodec.H264
}

private fun getCameraFacing(cameraFacing: String?): HMSVideoTrackSettings.CameraFacing {
when (cameraFacing) {
"FRONT" -> {
Expand Down
Loading

0 comments on commit dc1d270

Please sign in to comment.