diff --git a/gradle.properties b/gradle.properties index d3845c4df..d96b4501f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/room-kit/src/main/java/live/hms/roomkit/ui/HMSRoomKit.kt b/room-kit/src/main/java/live/hms/roomkit/ui/HMSRoomKit.kt index fc0167c2f..274b15e55 100644 --- a/room-kit/src/main/java/live/hms/roomkit/ui/HMSRoomKit.kt +++ b/room-kit/src/main/java/live/hms/roomkit/ui/HMSRoomKit.kt @@ -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 { @@ -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) + } + } + } diff --git a/room-kit/src/main/java/live/hms/roomkit/ui/meeting/HMSRoomFragment.kt b/room-kit/src/main/java/live/hms/roomkit/ui/meeting/HMSRoomFragment.kt index 1ec37f26b..7a940dfe2 100644 --- a/room-kit/src/main/java/live/hms/roomkit/ui/meeting/HMSRoomFragment.kt +++ b/room-kit/src/main/java/live/hms/roomkit/ui/meeting/HMSRoomFragment.kt @@ -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 { diff --git a/room-kit/src/main/java/live/hms/roomkit/ui/meeting/MeetingActivity.kt b/room-kit/src/main/java/live/hms/roomkit/ui/meeting/MeetingActivity.kt index 35bfb3cd7..b69d59171 100644 --- a/room-kit/src/main/java/live/hms/roomkit/ui/meeting/MeetingActivity.kt +++ b/room-kit/src/main/java/live/hms/roomkit/ui/meeting/MeetingActivity.kt @@ -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 @@ -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() diff --git a/room-kit/src/main/java/live/hms/roomkit/ui/meeting/MeetingViewModel.kt b/room-kit/src/main/java/live/hms/roomkit/ui/meeting/MeetingViewModel.kt index 0dce3267d..ddd3fd4aa 100644 --- a/room-kit/src/main/java/live/hms/roomkit/ui/meeting/MeetingViewModel.kt +++ b/room-kit/src/main/java/live/hms/roomkit/ui/meeting/MeetingViewModel.kt @@ -140,6 +140,7 @@ class MeetingViewModel( fun initSdk( roomCode: String, + token: String, hmsPrebuiltOptions: HMSPrebuiltOptions?, onHMSActionResultListener: HMSActionResultListener ) { @@ -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), @@ -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() + } + }) } diff --git a/room-kit/src/main/java/live/hms/roomkit/util/Constants.kt b/room-kit/src/main/java/live/hms/roomkit/util/Constants.kt index fac0aa83d..bbd8e389e 100644 --- a/room-kit/src/main/java/live/hms/roomkit/util/Constants.kt +++ b/room-kit/src/main/java/live/hms/roomkit/util/Constants.kt @@ -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"