Skip to content

Commit

Permalink
Merge pull request #610 from 100mslive/develop
Browse files Browse the repository at this point in the history
Release 0.9.4: Develop to main
  • Loading branch information
ygit authored Apr 20, 2022
2 parents 81bde18 + 0a9ab8c commit 30e6876
Show file tree
Hide file tree
Showing 26 changed files with 1,783 additions and 1,535 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ 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.3.4'
implementation 'com.github.100mslive.android-sdk:lib:2.3.5'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
Expand Down
125 changes: 97 additions & 28 deletions android/src/main/java/com/reactnativehmssdk/HmsHelper.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
package com.reactnativehmssdk

import android.content.Context
import android.graphics.Bitmap
import android.media.MediaScannerConnection
import android.os.Build
import android.os.Environment
import android.os.Handler
import android.util.Log
import android.view.PixelCopy
import androidx.annotation.RequiresApi
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import live.hms.video.error.HMSException
import live.hms.video.media.codec.HMSAudioCodec
import live.hms.video.media.codec.HMSVideoCodec
import live.hms.video.media.settings.HMSAudioTrackSettings
import live.hms.video.media.settings.HMSTrackSettings
import live.hms.video.media.settings.HMSVideoResolution
import live.hms.video.media.settings.HMSVideoTrackSettings
import live.hms.video.media.tracks.*
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.role.*
import live.hms.video.sdk.models.role.HMSRole
import live.hms.video.utils.HmsUtilities
import org.webrtc.SurfaceViewRenderer
import java.io.File
import java.io.FileOutputStream
import java.util.*

object HmsHelper {

Expand Down Expand Up @@ -120,9 +136,7 @@ object HmsHelper {
var useHardwareEchoCancellation = false
val requiredKeysUseHardwareEchoCancellation =
this.areAllRequiredKeysAvailable(
data,
arrayOf(Pair("useHardwareEchoCancellation", "Boolean"))
)
data, arrayOf(Pair("useHardwareEchoCancellation", "Boolean")))
if (requiredKeysUseHardwareEchoCancellation) {
useHardwareEchoCancellation = data.getBoolean("useHardwareEchoCancellation")
}
Expand Down Expand Up @@ -277,17 +291,11 @@ object HmsHelper {
var singleFilePerLayer = false
var videoOnDemand = false
if (areAllRequiredKeysAvailable(
hmsHlsRecordingConfig,
arrayOf(Pair("singleFilePerLayer", "Boolean"))
)
) {
hmsHlsRecordingConfig, arrayOf(Pair("singleFilePerLayer", "Boolean")))) {
singleFilePerLayer = hmsHlsRecordingConfig.getBoolean("singleFilePerLayer")
}
if (areAllRequiredKeysAvailable(
hmsHlsRecordingConfig,
arrayOf(Pair("videoOnDemand", "Boolean"))
)
) {
hmsHlsRecordingConfig, arrayOf(Pair("videoOnDemand", "Boolean")))) {
videoOnDemand = hmsHlsRecordingConfig.getBoolean("videoOnDemand")
}
return HMSHlsRecordingConfig(singleFilePerLayer, videoOnDemand)
Expand Down Expand Up @@ -321,9 +329,7 @@ object HmsHelper {
arrayOf(
Pair("endpoint", "String"),
Pair("metadata", "String"),
Pair("captureNetworkQualityInPreview", "Boolean")
)
) -> {
Pair("captureNetworkQualityInPreview", "Boolean"))) -> {
config =
HMSConfig(
credentials.getString("username") as String,
Expand All @@ -335,9 +341,7 @@ object HmsHelper {
)
}
areAllRequiredKeysAvailable(
credentials,
arrayOf(Pair("endpoint", "String"), Pair("metadata", "String"))
) -> {
credentials, arrayOf(Pair("endpoint", "String"), Pair("metadata", "String"))) -> {
config =
HMSConfig(
credentials.getString("username") as String,
Expand All @@ -348,8 +352,8 @@ object HmsHelper {
}
areAllRequiredKeysAvailable(
credentials,
arrayOf(Pair("endpoint", "String"), Pair("captureNetworkQualityInPreview", "Boolean"))
) -> {
arrayOf(
Pair("endpoint", "String"), Pair("captureNetworkQualityInPreview", "Boolean"))) -> {
config =
HMSConfig(
credentials.getString("username") as String,
Expand All @@ -361,8 +365,8 @@ object HmsHelper {
}
areAllRequiredKeysAvailable(
credentials,
arrayOf(Pair("metadata", "String"), Pair("captureNetworkQualityInPreview", "Boolean"))
) -> {
arrayOf(
Pair("metadata", "String"), Pair("captureNetworkQualityInPreview", "Boolean"))) -> {
config =
HMSConfig(
credentials.getString("username") as String,
Expand All @@ -389,18 +393,83 @@ object HmsHelper {
)
}
areAllRequiredKeysAvailable(
credentials,
arrayOf(Pair("captureNetworkQualityInPreview", "Boolean"))
) -> {
credentials, arrayOf(Pair("captureNetworkQualityInPreview", "Boolean"))) -> {
config =
HMSConfig(
credentials.getString("username") as String,
credentials.getString("authToken") as String,
captureNetworkQualityInPreview =
credentials.getBoolean("captureNetworkQualityInPreview")
)
credentials.getBoolean("captureNetworkQualityInPreview"))
}
}
return config
}

@RequiresApi(Build.VERSION_CODES.N)
fun captureSurfaceView(surfaceView: SurfaceViewRenderer, context: Context, id: String?) {
try {
val bitmap: Bitmap =
Bitmap.createBitmap(surfaceView.width, surfaceView.height, Bitmap.Config.ARGB_8888)
PixelCopy.request(
surfaceView,
bitmap,
{ copyResult ->
if (copyResult === PixelCopy.SUCCESS) {
Log.d("captureSurfaceView", "bitmap: $bitmap")
saveImage(bitmap, context, id)
} else {
HmsModule.hmsCollection[id]?.emitHMSError(
HMSException(
103,
copyResult.toString(),
copyResult.toString(),
copyResult.toString(),
copyResult.toString()
)
)
Log.e("captureSurfaceView", "copyResult: $copyResult")
}
},
Handler()
)
} catch (e: Exception) {
Log.e("captureSurfaceView", "error: $e")
}
}

private fun saveImage(finalBitmap: Bitmap, context: Context, id: String?) {
val folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
if (!folder.exists()) {
folder.mkdir()
}
val generator = Random()
var n = 10000
n = generator.nextInt(n)
val fileName = "Image-$n.jpg"
val file = File(folder.absolutePath, fileName)
if (file.exists()) file.delete()
try {
val out = FileOutputStream(file)
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out)
out.flush()
out.close()
} catch (e: Exception) {
HmsModule.hmsCollection[id]?.emitHMSError(
HMSException(
103,
e.message.toString(),
e.message.toString(),
e.message.toString(),
e.message.toString()
)
)
Log.e("saveImage", "error: $e")
}
// Tell the media scanner about the new file so that it is
// immediately available to the user.
MediaScannerConnection.scanFile(context, arrayOf(file.toString()), null) { path, uri ->
Log.i("ExternalStorage", "Scanned $path:")
Log.i("ExternalStorage", "-> uri=$uri")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ class HmsScreenshareActivity : ComponentActivity() {
)
} else {
val id = intent.getStringExtra("id")
val data: WritableMap = Arguments.createMap()
data.putBoolean("success", true)
data.putString("message", "RESULT_CANCELED")
HmsModule.hmsCollection[id]?.screenshareCallback?.resolve(data)
val error = HMSException(
103,
"RESULT_CANCELED",
"RESULT_CANCELED",
"RESULT_CANCELED",
"RESULT_CANCELED"
)
HmsModule.hmsCollection[id]?.screenshareCallback?.reject(error)
HmsModule.hmsCollection[id]?.emitHMSError(error)
finish()
}
}
Expand Down
29 changes: 22 additions & 7 deletions android/src/main/java/com/reactnativehmssdk/HmsView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.reactnativehmssdk

import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.annotation.RequiresApi
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.WritableMap
Expand All @@ -19,17 +21,24 @@ class HmsView(context: ReactContext) : FrameLayout(context) {
private var surfaceView: SurfaceViewRenderer = SurfaceViewRenderer(context)
private var videoTrack: HMSVideoTrack? = null
private var scaleTypeApplied: Boolean = false
private var sdkId: String = "12345"
private var currentScaleType: RendererCommon.ScalingType =
RendererCommon.ScalingType.SCALE_ASPECT_FILL
RendererCommon.ScalingType.SCALE_ASPECT_FILL

init {
val inflater = getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val inflater =
getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view = inflater.inflate(R.layout.hms_view, this)

surfaceView = view.findViewById(R.id.surfaceView)
surfaceView.setEnableHardwareScaler(true)
}

@RequiresApi(Build.VERSION_CODES.N)
fun captureHmsView() {
HmsHelper.captureSurfaceView(surfaceView, context, sdkId)
}

private fun onReceiveNativeEvent() {
val event: WritableMap = Arguments.createMap()
event.putString("message", "MyMessage")
Expand All @@ -55,6 +64,13 @@ class HmsView(context: ReactContext) : FrameLayout(context) {
}
}

fun updateZOrderMediaOverlay(setZOrderMediaOverlay: Boolean?) {
if (setZOrderMediaOverlay != null && setZOrderMediaOverlay) {
// surfaceView.setZOrderOnTop(true);
surfaceView.setZOrderMediaOverlay(setZOrderMediaOverlay)
}
}

fun updateScaleType(scaleType: String?) {
if (scaleType != null) {
when (scaleType) {
Expand All @@ -81,12 +97,11 @@ class HmsView(context: ReactContext) : FrameLayout(context) {
}

fun setData(
id: String?,
trackId: String?,
hmsCollection: MutableMap<String, HmsSDK>,
mirror: Boolean?
id: String?,
trackId: String?,
hmsCollection: MutableMap<String, HmsSDK>,
mirror: Boolean?
) {
var sdkId = "12345"
if (id != null) {
sdkId = id
}
Expand Down
15 changes: 15 additions & 0 deletions android/src/main/java/com/reactnativehmssdk/HmssdkViewManager.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.reactnativehmssdk

import android.os.Build
import androidx.annotation.RequiresApi
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.common.MapBuilder
import com.facebook.react.uimanager.SimpleViewManager
Expand Down Expand Up @@ -44,6 +46,19 @@ class HmssdkViewManager : SimpleViewManager<HmsView>() {
view.updateScaleType(data)
}

@ReactProp(name = "setZOrderMediaOverlay")
fun setZOrderMediaOverlay(view: HmsView, data: Boolean?) {
view.updateZOrderMediaOverlay(data)
}

@RequiresApi(Build.VERSION_CODES.N)
@ReactProp(name = "screenshot")
fun setCaptureHmsView(view: HmsView, screenshot: Boolean?) {
if(screenshot == true){
view.captureHmsView()
}
}

private fun getHms(): MutableMap<String, HmsSDK>? {
return reactContext?.getNativeModule(HmsModule::class.java)?.getHmsInstance()
}
Expand Down
18 changes: 9 additions & 9 deletions example/android/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ GEM
artifactory (3.0.15)
atomos (0.1.3)
aws-eventstream (1.2.0)
aws-partitions (1.572.0)
aws-sdk-core (3.130.0)
aws-partitions (1.578.0)
aws-sdk-core (3.130.1)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.55.0)
aws-sdk-kms (1.56.0)
aws-sdk-core (~> 3, >= 3.127.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.113.0)
Expand Down Expand Up @@ -105,9 +105,9 @@ GEM
xcodeproj (>= 1.13.0, < 2.0.0)
xcpretty (~> 0.3.0)
xcpretty-travis-formatter (>= 0.0.3)
fastlane-plugin-firebase_app_distribution (0.3.3)
fastlane-plugin-firebase_app_distribution (0.3.4)
gh_inspector (1.1.3)
google-apis-androidpublisher_v3 (0.17.0)
google-apis-androidpublisher_v3 (0.19.0)
google-apis-core (>= 0.4, < 2.a)
google-apis-core (0.4.2)
addressable (~> 2.5, >= 2.5.1)
Expand All @@ -122,15 +122,15 @@ GEM
google-apis-core (>= 0.4, < 2.a)
google-apis-playcustomapp_v1 (0.7.0)
google-apis-core (>= 0.4, < 2.a)
google-apis-storage_v1 (0.11.0)
google-apis-storage_v1 (0.13.0)
google-apis-core (>= 0.4, < 2.a)
google-cloud-core (1.6.0)
google-cloud-env (~> 1.0)
google-cloud-errors (~> 1.0)
google-cloud-env (1.6.0)
faraday (>= 0.17.3, < 3.0)
google-cloud-errors (1.2.0)
google-cloud-storage (1.36.1)
google-cloud-storage (1.36.2)
addressable (~> 2.8)
digest-crc (~> 0.4)
google-apis-iamcredentials_v1 (~> 0.1)
Expand Down Expand Up @@ -162,7 +162,7 @@ GEM
optparse (0.1.1)
os (1.1.4)
plist (3.6.0)
public_suffix (4.0.6)
public_suffix (4.0.7)
rake (13.0.6)
representable (3.1.1)
declarative (< 0.1.0)
Expand Down Expand Up @@ -219,4 +219,4 @@ DEPENDENCIES
fastlane-plugin-firebase_app_distribution

BUNDLED WITH
2.3.10
2.3.11
Loading

0 comments on commit 30e6876

Please sign in to comment.