Skip to content

Commit

Permalink
Merge pull request #524 from 100mslive/dev
Browse files Browse the repository at this point in the history
prebuilt release 1.1.3
  • Loading branch information
AniketSK authored Nov 7, 2023
2 parents 864b1ea + c49678e commit ba7d0c3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 27 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ kotlin.code.style=official
100MS_APP_VERSION_CODE=643
100MS_APP_VERSION_NAME=5.8.872
hmsRoomKitGroup=live.100ms
HMS_ROOM_KIT_VERSION=1.1.2
HMS_ROOM_KIT_VERSION=1.1.3
android.suppressUnsupportedCompileSdk=33
10 changes: 10 additions & 0 deletions room-kit/src/main/java/live/hms/roomkit/ui/HMSRoomKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.core.content.ContextCompat.startActivity
import live.hms.roomkit.ui.meeting.MeetingActivity
import live.hms.roomkit.util.ROOM_CODE
import live.hms.roomkit.util.ROOM_PREBUILT
import live.hms.roomkit.util.TOKEN

object HMSRoomKit {

Expand All @@ -19,5 +20,14 @@ object HMSRoomKit {

}


fun launchPrebuiltUsingAuthToken(token: String, activity: Activity, options: HMSPrebuiltOptions? = null) {
Intent(activity, MeetingActivity::class.java).apply {
putExtra(TOKEN, token)
putExtra(ROOM_PREBUILT, options)
startActivity(activity, this, null)
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class HMSRoomFragment : Fragment() {

meetingViewModel.initSdk(
roomCode.orEmpty(),
hmsPrebuiltOptions, object : HMSActionResultListener {
"", hmsPrebuiltOptions, object : HMSActionResultListener {
override fun onError(error: HMSException) {
contextSafe { context, activity ->
activity.runOnUiThread {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import live.hms.roomkit.ui.notification.HMSNotificationType
import live.hms.roomkit.ui.settings.SettingsStore
import live.hms.roomkit.util.ROOM_CODE
import live.hms.roomkit.util.ROOM_PREBUILT
import live.hms.roomkit.util.TOKEN
import live.hms.roomkit.util.init
import live.hms.video.error.HMSException
import live.hms.video.sdk.HMSActionResultListener
Expand Down Expand Up @@ -77,10 +78,19 @@ class MeetingActivity : AppCompatActivity() {

val hmsPrebuiltOption: HMSPrebuiltOptions? =
intent!!.extras!![ROOM_PREBUILT] as? HMSPrebuiltOptions
val roomCode: String = intent!!.getStringExtra(ROOM_CODE)!!

val roomCode: String = intent?.getStringExtra(ROOM_CODE)?:""
val token: String = intent?.getStringExtra(TOKEN)?:""

if (roomCode.isEmpty() && token.isEmpty()) {
Toast.makeText(this, "Room code or token is required", Toast.LENGTH_SHORT).show()
finish()
}


binding.progressBar.visibility = View.VISIBLE
//todo show a loader UI
meetingViewModel.initSdk(roomCode, hmsPrebuiltOption, object : HMSActionResultListener {
meetingViewModel.initSdk(roomCode, token, hmsPrebuiltOption, object : HMSActionResultListener {
override fun onError(error: HMSException) {
runOnUiThread {
Toast.makeText(this@MeetingActivity, error.message, Toast.LENGTH_SHORT).show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class MeetingViewModel(

fun initSdk(
roomCode: String,
token: String,
hmsPrebuiltOptions: HMSPrebuiltOptions?,
onHMSActionResultListener: HMSActionResultListener
) {
Expand All @@ -149,13 +150,15 @@ class MeetingViewModel(
}
//if empty is uses the prod token url else uses the debug token url
val tokenURL: String = hmsPrebuiltOptions?.endPoints?.get("token") ?: ""
val initURL: String = if (hmsPrebuiltOptions?.endPoints?.containsKey("init") == true)
hmsPrebuiltOptions.endPoints["init"].orEmpty()
else
"https://prod-init.100ms.live/init"


isPrebuiltDebug = hmsPrebuiltOptions?.debugInfo ?: false

if (token.isNullOrEmpty().not()) {
joinRoomUsingToken(token, hmsPrebuiltOptions, onHMSActionResultListener)
return
}

hmsSDK.getAuthTokenByRoomCode(
TokenRequest(roomCode, hmsPrebuiltOptions?.userId ?: UUID.randomUUID().toString()),
TokenRequestOptions(tokenURL),
Expand All @@ -166,31 +169,42 @@ class MeetingViewModel(
}

override fun onTokenSuccess(token: String) {
joinRoomUsingToken(token, hmsPrebuiltOptions, onHMSActionResultListener)
}

val layoutEndpointBase = hmsPrebuiltOptions?.endPoints?.get("layout")
hmsSDK.getRoomLayout(
token,
LayoutRequestOptions(layoutEndpointBase),
object :
HMSLayoutListener {
override fun onError(error: HMSException) {
Log.e(TAG, "onError: ", error)
onHMSActionResultListener.onError(error)
}
})

override fun onLayoutSuccess(layoutConfig: HMSRoomLayout) {
hmsRoomLayout = layoutConfig
prebuiltInfoContainer.setParticipantLabelInfo(hmsRoomLayout)
setHmsConfig(hmsPrebuiltOptions, token, initURL)
kotlin.runCatching { setTheme(layoutConfig.data?.getOrNull(0)?.themes?.getOrNull(0)?.palette!!) }
onHMSActionResultListener.onSuccess()
}

})
}


fun joinRoomUsingToken(token: String, hmsPrebuiltOptions: HMSPrebuiltOptions?, onHMSActionResultListener: HMSActionResultListener) {

val initURL: String = if (hmsPrebuiltOptions?.endPoints?.containsKey("init") == true)
hmsPrebuiltOptions.endPoints["init"].orEmpty()
else
"https://prod-init.100ms.live/init"

val layoutEndpointBase = hmsPrebuiltOptions?.endPoints?.get("layout")
hmsSDK.getRoomLayout(
token,
LayoutRequestOptions(layoutEndpointBase),
object :
HMSLayoutListener {
override fun onError(error: HMSException) {
Log.e(TAG, "onError: ", error)
onHMSActionResultListener.onError(error)
}

})
override fun onLayoutSuccess(layoutConfig: HMSRoomLayout) {
hmsRoomLayout = layoutConfig
prebuiltInfoContainer.setParticipantLabelInfo(hmsRoomLayout)
setHmsConfig(hmsPrebuiltOptions, token, initURL)
kotlin.runCatching { setTheme(layoutConfig.data?.getOrNull(0)?.themes?.getOrNull(0)?.palette!!) }
onHMSActionResultListener.onSuccess()
}

})

}

Expand Down
1 change: 1 addition & 0 deletions room-kit/src/main/java/live/hms/roomkit/util/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package live.hms.roomkit.util

const val ROOM_DETAILS = "room-details"
const val ROOM_CODE = "room-code"
const val TOKEN = "token"
const val ROOM_PREBUILT = "room-prebuilt"
const val MEETING_URL = "meeting-url"
const val USERNAME = "username"
Expand Down

0 comments on commit ba7d0c3

Please sign in to comment.