Skip to content

Commit

Permalink
Merge pull request #265 from 100mslive/dev
Browse files Browse the repository at this point in the history
dev to release
  • Loading branch information
AniketSK authored Jul 29, 2022
2 parents 2ef6acd + 64215db commit 8d146b2
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 26 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'

//100ms.live SDK
implementation 'com.github.100mslive.android-sdk:lib:2.4.5'
implementation 'com.github.100mslive.android-sdk:virtualBackground:2.4.5'
implementation 'com.github.100mslive.android-sdk:lib:2.4.7'
implementation 'com.github.100mslive.android-sdk:virtualBackground:2.4.7'

// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:2.4.0"
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/live/hms/app2/ui/meeting/MeetingFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ class MeetingFragment : Fragment() {
override fun onPrepareOptionsMenu(menu: Menu) {
super.onPrepareOptionsMenu(menu)

menu.findItem(R.id.hls_start).isVisible = meetingViewModel.isAllowedToHlsStream()
menu.findItem(R.id.hls_stop).isVisible = meetingViewModel.isAllowedToHlsStream()
menu.findItem(R.id.raise_hand).isVisible = true
menu.findItem(R.id.change_name).isVisible = true
menu.findItem(R.id.pip_mode).isVisible = true
Expand All @@ -278,7 +280,7 @@ class MeetingFragment : Fragment() {
}

menu.findItem(R.id.action_stop_streaming_and_recording).apply {
isVisible = meetingViewModel.isRecording.value == RecordingState.RECORDING ||
isVisible = meetingViewModel.isAllowedToBrowserRecord() && meetingViewModel.isRecording.value == RecordingState.RECORDING ||
meetingViewModel.isRecording.value == RecordingState.STREAMING ||
meetingViewModel.isRecording.value == RecordingState.STREAMING_AND_RECORDING
}
Expand All @@ -292,7 +294,7 @@ class MeetingFragment : Fragment() {
}

menu.findItem(R.id.action_record_meeting).apply {
isVisible = true
isVisible = meetingViewModel.isAllowedToBrowserRecord()

// If we're in a transitioning state, we prevent further clicks.
// Checked or not checked depends on if it's currently recording or not. Checked if recording.
Expand Down Expand Up @@ -602,6 +604,11 @@ class MeetingFragment : Fragment() {
viewLifecycleOwner.lifecycleScope.launch {
meetingViewModel.events.collect { event ->
when (event) {
is MeetingViewModel.Event.CameraSwitchEvent -> {
withContext(Dispatchers.Main) {
Toast.makeText(context, "Camera Switch ${event.message}", Toast.LENGTH_LONG).show()
}
}
is MeetingViewModel.Event.RTMPError -> {
withContext(Dispatchers.Main) {
Toast.makeText(context, "RTMP error ${event.exception}", Toast.LENGTH_LONG).show()
Expand Down Expand Up @@ -901,7 +908,7 @@ class MeetingFragment : Fragment() {

meetingViewModel.setTitle(mode.titleResId)

if (mode == MeetingViewMode.AUDIO_ONLY) {
if (mode == MeetingViewMode.AUDIO_ONLY ||mode is MeetingViewMode.HLS) {
binding.buttonToggleVideo.visibility = View.GONE
} else {
binding.buttonToggleVideo.visibility = View.VISIBLE
Expand Down
39 changes: 32 additions & 7 deletions app/src/main/java/live/hms/app2/ui/meeting/MeetingViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class MeetingViewModel(
val previewErrorLiveData : LiveData<HMSException> = previewErrorData
val previewUpdateLiveData : LiveData<Pair<HMSRoom, Array<HMSTrack>>> = previewUpdateData

private val _peerCount = MutableLiveData<Int>()
val peerCount : LiveData<Int> = _peerCount

fun setMeetingViewMode(mode: MeetingViewMode) {
if (mode != meetingViewMode.value) {
Expand Down Expand Up @@ -245,6 +247,10 @@ class MeetingViewModel(
roomState.postValue(Pair(type,hmsRoom))
// This will keep the isRecording value updated correctly in preview. It will not be called after join.
_isRecording.postValue(getRecordingState(hmsRoom))
if(type == HMSRoomUpdate.ROOM_PEER_COUNT_UPDATED) {
_peerCount.postValue(hmsRoom.peerCount)
Log.d("PeerCountUpdated", "New peer count is : ${hmsRoom.peerCount}")
}
}

})
Expand Down Expand Up @@ -733,12 +739,22 @@ class MeetingViewModel(

// NOTE: During audio-only calls, this switch-camera is ignored
// as no camera in use
try {
HMSCoroutineScope.launch(Dispatchers.Main) {
hmsSDK.getLocalPeer()?.videoTrack?.switchCamera()
}
} catch (ex: HMSException) {
Log.e(TAG, "flipCamera: ${ex.description}", ex)

viewModelScope.launch {
hmsSDK.getLocalPeer()?.videoTrack?.switchCamera(object : HMSActionResultListener {
override fun onError(error: HMSException) {
viewModelScope.launch {
_events.emit(Event.CameraSwitchEvent("Error: $error"))
}
}

override fun onSuccess() {
viewModelScope.launch {
_events.emit(Event.CameraSwitchEvent("Success: Facing is now: ${hmsSDK.getLocalPeer()?.videoTrack?.settings?.cameraFacing}"))
}
}

})
}
}

Expand Down Expand Up @@ -867,6 +883,14 @@ class MeetingViewModel(
return hmsSDK.getLocalPeer()?.hmsRole?.permission?.unmute == true
}

fun isAllowedToRtmpStream() : Boolean =
hmsSDK.getLocalPeer()?.hmsRole?.permission?.rtmpStreaming == true

fun isAllowedToBrowserRecord() : Boolean = hmsSDK.getLocalPeer()?.hmsRole?.permission?.browserRecording == true

fun isAllowedToHlsStream() : Boolean =
hmsSDK.getLocalPeer()?.hmsRole?.permission?.hlsStreaming == true

fun changeRole(remotePeerId: String, toRoleName: String, force: Boolean) {
val hmsPeer = hmsSDK.getPeers().find { it.peerID == remotePeerId }
val toRole = hmsSDK.getRoles().find { it.name == toRoleName }
Expand Down Expand Up @@ -1145,6 +1169,7 @@ class MeetingViewModel(
data class ServerRecordEvent(val message: String) : Event()
data class HlsEvent(override val message : String) : MessageEvent(message)
data class HlsRecordingEvent(override val message : String) : MessageEvent(message)
data class CameraSwitchEvent(override val message: String) : MessageEvent(message)
}

private val _isHandRaised = MutableLiveData<Boolean>(false)
Expand Down Expand Up @@ -1189,7 +1214,7 @@ class MeetingViewModel(

fun getStats(): Flow<Map<String, HMSStats>> = statsFlow

fun startHls(hlsUrl : String, recordingConfig : HMSHlsRecordingConfig) {
fun startHls(hlsUrl : String?, recordingConfig : HMSHlsRecordingConfig) {
val config = HMSHLSConfig(listOf(HMSHLSMeetingURLVariant(hlsUrl)),
recordingConfig)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ class ParticipantsFragment : Fragment() {
meetingViewModel.peerLiveDate.observe(viewLifecycleOwner) {
val peers = meetingViewModel.peers
adapter.setItems(peers)
binding.participantCount.text = "${peers.size}"
}

meetingViewModel.peerCount.observe(viewLifecycleOwner) { peerCount ->
binding.participantCount.text = "$peerCount"
}

meetingViewModel.state.observe(viewLifecycleOwner) { state ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -48,16 +49,16 @@ class RtmpRecordFragment : Fragment() {
// Get a listener on the page for the urls.

binding.addRtmpUrlButton.setOnClickListener { addItem() }
rtmpUrladapter.submitList(settings.rtmpUrlsList.toList())
binding.rtmpUrls.layoutManager = LinearLayoutManager(context)
binding.rtmpUrls.adapter = rtmpUrladapter
binding.startButton.setOnClickListener { startClicked() }

val recordingTimesUseCase = RecordingTimesUseCase()
enableDisable()
with(binding) {
recording.text = recordingTimesUseCase.showRecordInfo(meetingViewModel.hmsSDK.getRoom()!!)
rtmp.text = recordingTimesUseCase.showRtmpInfo(meetingViewModel.hmsSDK.getRoom()!!)
sfu.text = recordingTimesUseCase.showServerInfo(meetingViewModel.hmsSDK.getRoom()!!)
shouldStartHls.isChecked = meetingViewModel.isAllowedToHlsStream()
rtmpStreamingSwitch.isChecked = meetingViewModel.isAllowedToRtmpStream()
hlsSingleFilePerLayer.isEnabled = shouldStartHls.isChecked
hlsVod.isEnabled = shouldStartHls.isChecked
shouldStartHls.setOnCheckedChangeListener { buttonView, isChecked ->
Expand All @@ -79,6 +80,32 @@ class RtmpRecordFragment : Fragment() {
}
}

private fun enableDisable() {
with(binding) {
enableDisableRtmp()
addRtmpUrlButton.isEnabled = meetingViewModel.isAllowedToRtmpStream()
shouldRecord.isEnabled = meetingViewModel.isAllowedToBrowserRecord()
shouldStartHls.isEnabled = meetingViewModel.isAllowedToHlsStream()
rtmpStreamingSwitch.isEnabled = meetingViewModel.isAllowedToRtmpStream()
}
}

private fun enableDisableRtmp() {
// addRtmpUrlButton,rtmpUrlContainer,existingRtmpUrlsText,rtmpUrls
val enabled = meetingViewModel.isAllowedToRtmpStream()
with(binding) {
if(meetingViewModel.isAllowedToRtmpStream()) {
rtmpUrladapter.submitList(settings.rtmpUrlsList.toList())
rtmpUrls.layoutManager = LinearLayoutManager(context)
rtmpUrls.adapter = rtmpUrladapter
}
addRtmpUrlButton.isVisible = enabled
rtmpUrlContainer.isVisible = enabled
existingRtmpUrlsText.isVisible = enabled
rtmpUrls.isVisible = enabled
}
}

private fun addItem() {
val urlToAdd = binding.newRtmpUrl.editableText.toString()
if (urlToAdd.isEmpty()) {
Expand Down Expand Up @@ -115,7 +142,7 @@ class RtmpRecordFragment : Fragment() {
val isRecording = binding.shouldRecord.isChecked
val isHls = binding.shouldStartHls.isChecked
val meetingUrl = binding.meetingUrl.text.toString()
val isRtmp = settings.rtmpUrlsList.toList().isNotEmpty()
val isRtmp = binding.rtmpStreamingSwitch.isChecked && settings.rtmpUrlsList.toList().isNotEmpty() && meetingViewModel.isAllowedToRtmpStream()

val isHlsSingleFilePerLayer = binding.hlsSingleFilePerLayer.isChecked
val isHlsVod = binding.hlsVod.isChecked
Expand All @@ -135,10 +162,10 @@ class RtmpRecordFragment : Fragment() {
return
}

if (meetingUrl.isNullOrBlank()) {
if (meetingUrl.isNullOrBlank() && (isRecording || isRtmp) ) {
Toast.makeText(
requireContext(),
"A valid meeting url is required. $meetingUrl is invalid or not a role name",
"A valid meeting url is required for recording/rtmp. $meetingUrl is invalid or not a role name",
Toast.LENGTH_LONG
).show()
} else if((isRecording || isRtmp) && isHls) {
Expand Down
14 changes: 11 additions & 3 deletions app/src/main/res/layout/layout_rtmp_recording.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Rtmp Width" />
android:hint="@string/stream_width" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
Expand All @@ -47,7 +47,7 @@
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="RTMP Height" />
android:hint="@string/stream_height" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
Expand Down Expand Up @@ -83,6 +83,7 @@
android:src="@drawable/ic_round_add_circle_24" />

<TextView
android:id="@+id/existingRtmpUrlsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
Expand All @@ -98,12 +99,19 @@
tools:itemCount="3"
tools:listitem="@layout/layout_rtmp_url_item" />

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/rtmpStreamingSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/rtmp_streaming_switch"
android:layout_marginTop="32dp"
android:textAlignment="viewStart" />

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/shouldRecord"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/record"
android:layout_marginTop="32dp"
android:textAlignment="viewStart" />

<com.google.android.material.switchmaterial.SwitchMaterial
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@
<string name="record">Record</string>
<string name="stop_recording_stream">Stop Recording/Stream</string>
<string name="add_new_rtmp_streaming_url">Add new RTMP streaming url</string>
<string name="rtmp_settings">RTMP Settings</string>
<string name="use_hardware_AEC">Use Harware AEC</string>
<string name="rtmp_settings">Stream Settings</string>
<string name="use_hardware_AEC">Use Hardware AEC</string>
<string name="enable_background">Enable Background</string>
<string name="disable_background">Disable Background</string>
<string name="show_stats">Show stats</string>
Expand All @@ -166,4 +166,7 @@
<string name="audio_mode_media">Audio mode : media</string>
<string name="unknown">unknown</string>
<string name="file_playing">File Playing</string>
<string name="stream_width">Width</string>
<string name="stream_height">Height</string>
<string name="rtmp_streaming_switch">RTMP streaming</string>
</resources>
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ android.useAndroidX=true
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
100MS_APP_VERSION_CODE=349
100MS_APP_VERSION_NAME=3.8.1
100MS_APP_VERSION_CODE=350
100MS_APP_VERSION_NAME=3.8.2

0 comments on commit 8d146b2

Please sign in to comment.