Skip to content

Commit

Permalink
Merge pull request #647 from 100mslive/develop
Browse files Browse the repository at this point in the history
Release 0.9.6: Develop to main
  • Loading branch information
ygit authored Jun 9, 2022
2 parents cf19367 + cd77505 commit 58eb70f
Show file tree
Hide file tree
Showing 82 changed files with 5,101 additions and 4,800 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.7'
implementation 'com.github.100mslive.android-sdk:lib:2.3.9'
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import live.hms.video.sdk.models.*
import live.hms.video.sdk.models.role.*
import live.hms.video.sdk.models.trackchangerequest.HMSChangeTrackStateRequest

object HmsDecoder {
object HMSDecoder {

fun getHmsRoom(hmsRoom: HMSRoom?): WritableMap {
val room: WritableMap = Arguments.createMap()
if (hmsRoom != null) {
room.putString("id", hmsRoom.roomId)
room.putString("sessionId", hmsRoom.sessionId)
room.putString("name", hmsRoom.name)
room.putString("metaData", null)
room.putString("startedAt", hmsRoom.startedAt.toString())
Expand All @@ -33,6 +34,7 @@ object HmsDecoder {
this.getHMSServerRecordingState(hmsRoom.serverRecordingState)
)
room.putMap("hlsStreamingState", this.getHMSHlsStreamingState(hmsRoom.hlsStreamingState))
room.putMap("hlsRecordingState", this.getHMSHlsRecordingState(hmsRoom.hlsRecordingState))
room.putMap("localPeer", this.getHmsLocalPeer(hmsRoom.localPeer))
room.putArray("peers", this.getAllPeers(hmsRoom.peerList))
room.putInt("peerCount", hmsRoom.peerCount)
Expand Down Expand Up @@ -354,37 +356,18 @@ object HmsDecoder {
return changeTrackStateRequest
}

fun getError(error: HMSException): WritableMap {
val decodedError: WritableMap = Arguments.createMap()

decodedError.putInt("code", error.code)
decodedError.putString("localizedDescription", error.localizedMessage)
decodedError.putString("description", error.description)
decodedError.putString("message", error.message)
decodedError.putString("name", error.name)
decodedError.putString("action", error.action)

return decodedError
}

private fun getCustomError(message: String?, code: Int?): WritableMap {
val decodedError: WritableMap = Arguments.createMap()
var customCode = 101
var customMessage = "SOMETHING WENT WRONG"
if (code !== null) {
customCode = code.toInt()
fun getError(error: HMSException?): WritableMap? {
if (error !== null) {
val decodedError: WritableMap = Arguments.createMap()
decodedError.putInt("code", error.code)
decodedError.putString("localizedDescription", error.localizedMessage)
decodedError.putString("description", error.description)
decodedError.putString("message", error.message)
decodedError.putString("name", error.name)
decodedError.putString("action", error.action)
return decodedError
}
if (message !== null) {
customMessage = message
}
decodedError.putInt("code", customCode)
decodedError.putString("localizedDescription", customMessage)
decodedError.putString("description", customMessage)
decodedError.putString("message", customMessage)
decodedError.putInt("name", customCode)
decodedError.putInt("action", customCode)

return decodedError
return null
}

private fun getHMSBrowserRecordingState(data: HMSBrowserRecordingState?): ReadableMap {
Expand All @@ -394,7 +377,7 @@ object HmsDecoder {
input.putString("startedAt", data.startedAt.toString())
input.putString("stoppedAt", data.stoppedAt.toString())
input.putBoolean("running", data.running)
input.putMap("error", this.getCustomError(data.error?.message, data.error?.code))
input.putMap("error", this.getError(data.error))
}
return input
}
Expand All @@ -405,7 +388,7 @@ object HmsDecoder {
input.putBoolean("running", data.running)
input.putString("startedAt", data.startedAt.toString())
input.putString("stoppedAt", data.stoppedAt.toString())
input.putMap("error", this.getCustomError(data.error?.message, data.error?.code))
input.putMap("error", this.getError(data.error))
}
return input
}
Expand All @@ -415,7 +398,7 @@ object HmsDecoder {
if (data !== null) {
input.putBoolean("running", data.running)
input.putString("startedAt", data.startedAt.toString())
input.putMap("error", data.error?.let { this.getError(it) })
input.putMap("error", this.getError(data.error))
}
return input
}
Expand All @@ -429,6 +412,27 @@ object HmsDecoder {
return input
}

private fun getHMSHlsRecordingState(data: HmsHlsRecordingState?): ReadableMap {
val input = Arguments.createMap()
if (data !== null) {
data.running?.let { input.putBoolean("running", it) }
input.putString("startedAt", data.startedAt.toString())
// input.putMap("hlsRecordingConfig", this.getHMSHlsRecordingConfig(data.hlsRecordingConfig))
data.hlsRecordingConfig?.let { input.putBoolean("singleFilePerLayer", it.singleFilePerLayer) }
data.hlsRecordingConfig?.let { input.putBoolean("videoOnDemand", it.videoOnDemand) }
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import live.hms.video.sdk.models.role.HMSRole
import live.hms.video.utils.HmsUtilities
import org.webrtc.SurfaceViewRenderer

object HmsHelper {
object HMSHelper {

fun areAllRequiredKeysAvailable(
map: ReadableMap?,
Expand Down Expand Up @@ -64,6 +64,39 @@ object HmsHelper {
return true
}

fun getUnavailableRequiredKey(
map: ReadableMap?,
requiredKeys: Array<Pair<String, String>>
): String? {
if (map == null) {
return "Object_Is_Null"
}
for ((key, value) in requiredKeys) {
if (map.hasKey(key)) {
when (value) {
"String" -> {
if (map.getString(key) == null) {
return key + "_Is_Null"
}
}
"Array" -> {
if (map.getArray(key) == null) {
return key + "_Is_Null"
}
}
"Map" -> {
if (map.getMap(key) == null) {
return key + "_Is_Null"
}
}
}
} else {
return key + "_Is_Required"
}
}
return null
}

fun getPeerFromPeerId(peerId: String?, room: HMSRoom?): HMSPeer? {
if (peerId != null && room != null) {
return HmsUtilities.getPeer(peerId, room)
Expand Down Expand Up @@ -253,7 +286,7 @@ object HmsHelper {
return HMSVideoTrackSettings.CameraFacing.FRONT
}

fun getHms(credentials: ReadableMap, hmsCollection: MutableMap<String, HmsSDK>): HmsSDK? {
fun getHms(credentials: ReadableMap, hmsCollection: MutableMap<String, HMSRNSDK>): HMSRNSDK? {
val id = credentials.getString("id")

return if (id != null) {
Expand Down Expand Up @@ -442,7 +475,7 @@ object HmsHelper {
surfaceView,
bitmap,
{ copyResult ->
if (copyResult === PixelCopy.SUCCESS) {
if (copyResult == PixelCopy.SUCCESS) {
Log.d("captureSurfaceView", "bitmap: $bitmap")
val byteArrayOutputStream = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream)
Expand All @@ -455,7 +488,7 @@ object HmsHelper {
.receiveEvent(id, "captureFrame", output)
} else {
Log.e("captureSurfaceView", "copyResult: $copyResult")
HmsModule.hmsCollection[sdkId]?.emitHMSError(
HMSManager.hmsCollection[sdkId]?.emitHMSError(
HMSException(
103,
copyResult.toString(),
Expand All @@ -474,7 +507,7 @@ object HmsHelper {
)
} catch (e: Exception) {
Log.e("captureSurfaceView", "error: $e")
HmsModule.hmsCollection[sdkId]?.emitHMSError(e as HMSException)
HMSManager.hmsCollection[sdkId]?.emitHMSError(e as HMSException)
output.putString("error", e.message)
reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, "captureFrame", output)
}
Expand Down
Loading

0 comments on commit 58eb70f

Please sign in to comment.