Skip to content

Commit

Permalink
Merge pull request #547 from 100mslive/dev
Browse files Browse the repository at this point in the history
Dev to release
  • Loading branch information
PratimMallick authored Dec 8, 2023
2 parents 671be7f + 70d1d42 commit f9f6928
Show file tree
Hide file tree
Showing 18 changed files with 194 additions and 84 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

//100ms.live prebuilt lib
implementation "live.100ms:room-kit:1.1.2"
implementation "live.100ms:room-kit:$HMS_ROOM_KIT_VERSION"

// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:2.4.0"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/live/hms/app2/ui/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class HomeFragment : Fragment() {
val consistentUserId = getConsistentUserIdOverSessions()

HMSRoomKit.launchPrebuilt(
code, activity, HMSPrebuiltOptions(userName = getUsername(), userId = consistentUserId, debugInfo = settings.inPreBuiltDebugMode,
code, activity, HMSPrebuiltOptions(userName = if(settings.setInitialNameFromClient) getUsername() else null, userId = consistentUserId, debugInfo = settings.inPreBuiltDebugMode,
endPoints = hashMapOf<String, String>().apply {
if (settings.environment.contains("prod").not()) {
put("token", "https://auth-nonprod.100ms.live")
Expand Down
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.5
HMS_ROOM_KIT_VERSION=1.1.6
android.suppressUnsupportedCompileSdk=33
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ import live.hms.roomkit.R
import live.hms.roomkit.animation.RootViewDeferringInsetsCallback
import live.hms.roomkit.databinding.ActivityMeetingBinding
import live.hms.roomkit.ui.HMSPrebuiltOptions
import live.hms.roomkit.ui.meeting.chat.combined.CHAT_TAB_TITLE
import live.hms.roomkit.ui.meeting.chat.combined.ChatParticipantCombinedFragment
import live.hms.roomkit.ui.meeting.chat.combined.OPEN_TO_PARTICIPANTS
import live.hms.roomkit.ui.notification.CardStackLayoutManager
import live.hms.roomkit.ui.notification.CardStackListener
import live.hms.roomkit.ui.notification.Direction
import live.hms.roomkit.ui.notification.HMSNotification
import live.hms.roomkit.ui.notification.HMSNotificationAdapter
import live.hms.roomkit.ui.notification.HMSNotificationDiffCallBack
import live.hms.roomkit.ui.notification.HMSNotificationType
import live.hms.roomkit.ui.polls.display.POLL_TO_DISPLAY
import live.hms.roomkit.ui.polls.display.PollDisplayFragment
import live.hms.roomkit.ui.settings.SettingsStore
import live.hms.roomkit.util.ROOM_CODE
import live.hms.roomkit.util.ROOM_PREBUILT
Expand Down Expand Up @@ -153,13 +158,6 @@ class MeetingActivity : AppCompatActivity() {
tryRemovingNotification(it)
}

meetingViewModel.openPollOrQuizzTrgger.observe(this) { pollID ->
if (pollID.isEmpty().not()) {
meetingViewModel.openPollOrQuizzTrgger.value = ""
findNavController(R.id.nav_host_fragment)
.navigate(R.id.action_global_pollDisplayFragment, bundleOf("pollId" to pollID))
}
}
}

private fun triggerNotification(hmsNotification: HMSNotification) {
Expand Down Expand Up @@ -270,7 +268,7 @@ class MeetingActivity : AppCompatActivity() {
}

is HMSNotificationType.OpenPollOrQuiz -> {
meetingViewModel.openPollsOrQuizTrigger(type.pollId)
PollDisplayFragment.launch(type.pollId, supportFragmentManager)
handleNotificationDismissClick()
}

Expand All @@ -296,4 +294,4 @@ class MeetingActivity : AppCompatActivity() {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import live.hms.roomkit.ui.polls.QuestionUi
import live.hms.roomkit.ui.settings.SettingsFragment.Companion.REAR_FACING_CAMERA
import live.hms.roomkit.ui.settings.SettingsStore
import live.hms.roomkit.ui.theme.HMSPrebuiltTheme
import live.hms.roomkit.util.POLL_IDENTIFIER_FOR_HLS_CUE
import live.hms.roomkit.util.SingleLiveEvent
import live.hms.video.connection.stats.*
import live.hms.video.error.HMSException
Expand Down Expand Up @@ -123,11 +124,14 @@ class MeetingViewModel(
) {
when(hmsPollUpdateType) {
HMSPollUpdateType.started -> viewModelScope.launch {
_events.emit(Event.PollStarted(hmsPoll))
// Only show latest polls
if (lastPollStartedTime < hmsPoll.startedAt) {
lastPollStartedTime = hmsPoll.startedAt
triggerPollsNotification(hmsPoll)
if(!isHlsPeer(hmsSDK.getLocalPeer()?.hmsRole)) {
_events.emit(Event.PollStarted(hmsPoll))
// Only show latest polls
if (lastPollStartedTime < hmsPoll.startedAt) {
lastPollStartedTime = hmsPoll.startedAt
triggerPollsNotification(hmsPoll)

}
}
}
HMSPollUpdateType.stopped -> viewModelScope.launch {
Expand All @@ -143,12 +147,14 @@ class MeetingViewModel(
}
fun getHmsRoomLayout() = hmsRoomLayout

var prebuiltOptions : HMSPrebuiltOptions? = null
fun initSdk(
roomCode: String,
token: String,
hmsPrebuiltOptions: HMSPrebuiltOptions?,
onHMSActionResultListener: HMSActionResultListener
) {
this.prebuiltOptions = hmsPrebuiltOptions
if (hasValidToken) {
onHMSActionResultListener.onSuccess()
return
Expand Down Expand Up @@ -1055,10 +1061,16 @@ class MeetingViewModel(

}

private var lastStartedPoll : HmsPoll? = null
private fun updatePolls() {
// Just running this is enough since it will trigger the poll started notifications
localHmsInteractivityCenter.fetchPollList(HmsPollState.STARTED, object : HmsTypedActionResultListener<List<HmsPoll>>{
override fun onSuccess(result: List<HmsPoll>) {
// Put the last poll in the list.
lastStartedPoll = result.maxByOrNull { it.startedAt }
// Log.d("PollInfoS","${lastStartedPoll?.pollId} at ${lastStartedPoll?.startedAt}")
// This happens only once.
// _events.emit(Event.PollStarted(hmsPoll))
// viewModelScope.launch {
// result.sortedBy { it.startedAt }.firstOrNull()?.also { firstPoll ->
// _events.emit(Event.PollStarted(firstPoll))
Expand Down Expand Up @@ -2018,14 +2030,21 @@ class MeetingViewModel(
QuestionUi.AddAnotherItemView, -> { /*Nothing to do here*/}
}
}
val pollBuilder = hmsPollBuilder.build()

localHmsInteractivityCenter.quickStartPoll(hmsPollBuilder.build(), object : HMSActionResultListener {
localHmsInteractivityCenter.quickStartPoll(pollBuilder, object : HMSActionResultListener {
override fun onError(error: HMSException) {
Log.d("Polls","Error $error")
}

override fun onSuccess() {
Log.d("Polls","Success")
// Now send a notification into the hls cue,
// it's ok if this fails since that just means there's no hls stream
// to send it into.
// Might need to avoid sending it hls viewers though.
val hlsPollEvent = HMSHLSTimedMetadata("$POLL_IDENTIFIER_FOR_HLS_CUE${pollBuilder.pollId}",1000)
sendHlsMetadata(hlsPollEvent)
}

})
Expand Down Expand Up @@ -2194,11 +2213,6 @@ class MeetingViewModel(
changeRole(handRaisePeer.peerID, onStageRole, false)
}

val openPollOrQuizzTrgger by lazy { MutableLiveData<String>() }
fun openPollsOrQuizTrigger(pollID: String) {
openPollOrQuizzTrgger.value = pollID
}

fun triggerErrorNotification(message: String, isDismissible: Boolean = true, type: HMSNotificationType = HMSNotificationType.Error, actionButtonText:String ="") {
hmsNotificationEvent.postValue(
HMSNotification(
Expand Down Expand Up @@ -2279,5 +2293,29 @@ class MeetingViewModel(
fun defaultRecipientToMessage() = prebuiltInfoContainer.defaultRecipientToMessage()

fun chatTitle() = prebuiltInfoContainer.getChatTitle()

private var playerStarted = false
fun hlsPlayerBeganToPlay() {
val lp = lastStartedPoll
if(lp == null) {
playerStarted = true
return
}

val currentUnixTimestampInSeconds = (System.currentTimeMillis()/1000L)
val isPollLaunchedGreaterThan20SecondsAgo = currentUnixTimestampInSeconds - lp.startedAt > 20
// val t = Date().time
Log.d("PollInfoS","diff: $isPollLaunchedGreaterThan20SecondsAgo lastPollTime : ${lp.startedAt} current time : $currentUnixTimestampInSeconds diff : ${currentUnixTimestampInSeconds - lp.startedAt}")

if(!playerStarted && isPollLaunchedGreaterThan20SecondsAgo) {
// Log.d("PollInfoS","Launching")
viewModelScope.launch {
triggerPollsNotification(lp)
}
}
playerStarted = true
}

fun disableNameEdit() = prebuiltOptions?.userName != null
}

Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ class PreviewFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
initIntroAnimation()
binding.applyTheme()
with(binding.editTextName) {
isEnabled = !meetingViewModel.disableNameEdit()
if(!isEnabled) {
binding.editContainerName.isHintEnabled = false
} else {
hint = "Enter Nameโ€ฆ"
}
}
requireActivity().invalidateOptionsMenu()
setHasOptionsMenu(true)
settings = SettingsStore(requireContext())
Expand Down Expand Up @@ -233,6 +241,8 @@ class PreviewFragment : Fragment() {
}

private fun setupUI(roleName: String) {
// don't allow editing the name if there's supposed to be a fixed one

var introAnimationOffset = 450
if (meetingViewModel.getHmsRoomLayout()
?.getPreviewLayout(roleName)?.default?.elements?.previewHeader?.title.isNullOrEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ class SessionOptionBottomSheet(
add(raiseHandOption)
if (meetingViewModel.isAllowedToBrowserRecord())
add(recordingOption)
add(changeName)
if(!meetingViewModel.disableNameEdit()) {
add(changeName)
}
if (meetingViewModel.showPollOnUi()) {
add(GridOptionItem(
"Polls and Quizzes", R.drawable.poll_vote, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package live.hms.roomkit.ui.meeting.activespeaker
import com.google.gson.annotations.SerializedName
import kotlinx.coroutines.delay
import live.hms.hls_player.HmsHlsCue
import live.hms.roomkit.util.POLL_IDENTIFIER_FOR_HLS_CUE
import live.hms.video.utils.GsonUtils

class DisplayHlsCuesUseCase(val showText: (String) -> Unit) {
class DisplayHlsCuesUseCase(val showText: (String) -> Unit,
val openPoll : (pollId :String) -> Unit) {

private val listToShow = mutableListOf<String>()

Expand All @@ -21,12 +23,18 @@ class DisplayHlsCuesUseCase(val showText: (String) -> Unit) {
((hlsCue.endDate?.time ?: 0) - hlsCue.startDate.time).toInt()
}
if (duration > 0) {
val result = convert(hlsCue.payloadval)
listToShow.add(result)
showList()
delay(duration.toLong())
listToShow.remove(result)
showList()
when(val result = convert(hlsCue.payloadval)) {
CueTypes.Invalid -> {} // do nothing
is CueTypes.DisplayText-> {
listToShow.add(result.text)
showList()
delay(duration.toLong())
listToShow.remove(result.text)
showList()
}
// Might need to be single shot somehow.
is CueTypes.PollId -> openPoll(result.pollId)
}
}
}

Expand All @@ -37,32 +45,49 @@ class DisplayHlsCuesUseCase(val showText: (String) -> Unit) {
showText(text)
}

private fun convert(text: String?): String {
private fun convert(text: String?): CueTypes {
if (text == null)
return "null"
return CueTypes.Invalid

val isEmojiReact = text.contains("type") && text.contains("emojiId")
if (!isEmojiReact)
return text
val isPoll = text.startsWith(POLL_IDENTIFIER_FOR_HLS_CUE)
if(isEmojiReact) {
val emojiReact = GsonUtils.gson.fromJson(text, EmojiReact::class.java)
if (emojiReact.type != "EMOJI_REACTION")
return CueTypes.DisplayText.Text(text)

val emojiReact = GsonUtils.gson.fromJson(text, EmojiReact::class.java)
if (emojiReact.type != "EMOJI_REACTION")
return text

return when (emojiReact.emojiId) {
"+1" -> "๐Ÿ‘"
"-1" -> "๐Ÿ‘Ž"
"wave" -> "๐Ÿ‘‹"
"clap" -> "๐Ÿ‘"
"fire" -> "๐Ÿ”ฅ"
"tada" -> "๐ŸŽ‰"
"heart_eyes" -> "๐Ÿ˜"
"joy" -> "๐Ÿ˜‚"
"open_mouth" -> "๐Ÿ˜ฎ"
"sob" -> "๐Ÿ˜ญ"
else -> text
val emoji = when (emojiReact.emojiId) {
"+1" -> "๐Ÿ‘"
"-1" -> "๐Ÿ‘Ž"
"wave" -> "๐Ÿ‘‹"
"clap" -> "๐Ÿ‘"
"fire" -> "๐Ÿ”ฅ"
"tada" -> "๐ŸŽ‰"
"heart_eyes" -> "๐Ÿ˜"
"joy" -> "๐Ÿ˜‚"
"open_mouth" -> "๐Ÿ˜ฎ"
"sob" -> "๐Ÿ˜ญ"
else -> null
}
if(emoji == null)
CueTypes.DisplayText.Text(text)
else CueTypes.DisplayText.Emoji(emoji)
} else if (isPoll) {
return CueTypes.PollId(text.drop(POLL_IDENTIFIER_FOR_HLS_CUE.length))
}

return CueTypes.DisplayText.Text(text)
}
}

sealed class CueTypes {
object Invalid :CueTypes()
sealed class DisplayText(open val text : String) : CueTypes() {
data class Text(override val text : String) : DisplayText(text)
data class Emoji(override val text : String) : DisplayText(text)
}

data class PollId(val pollId :String) : CueTypes()
}

private data class EmojiReact(
Expand Down
Loading

0 comments on commit f9f6928

Please sign in to comment.