Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Interactive Player connect-subscribe flow's changed in 1.8.2 #85

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ class SingleStreamListener(

private suspend fun onConnected() {
Log.d(TAG, "onConnected")
subscriber.subscribe(Option(statsDelayMs = 1_000))
try {
subscriber.subscribe(Option(statsDelayMs = 1_000))
} catch (e: MillicastException) {
e.printStackTrace()
}
}

private fun onActive(p0: String?, p1: Array<out String>, p2: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import com.millicast.clients.stats.RtsReport
import com.millicast.devices.track.AudioTrack
import com.millicast.devices.track.TrackType
import com.millicast.devices.track.VideoTrack
import com.millicast.subscribers.Option
import com.millicast.subscribers.ProjectionData
import com.millicast.subscribers.state.ActivityStream
import com.millicast.subscribers.state.LayerData
import com.millicast.subscribers.state.SubscriberConnectionState
import com.millicast.utils.MillicastException
import io.dolby.rtscomponentkit.domain.MultiStreamStatisticsData
import io.dolby.rtscomponentkit.domain.MultiStreamingData
import kotlinx.coroutines.CoroutineScope
Expand All @@ -27,7 +29,8 @@ import kotlinx.coroutines.launch

class MultiStreamListener(
private val data: MutableStateFlow<MultiStreamingData>,
private var subscriber: Subscriber
private var subscriber: Subscriber,
private val options: Option
) {
private lateinit var coroutineScope: CoroutineScope

Expand All @@ -38,7 +41,8 @@ class MultiStreamListener(
Log.d(TAG, "Listener start")
coroutineScope = CoroutineScope(Dispatchers.IO)

subscriber.state.map { it.connectionState }.collectInLocalScope { state ->
subscriber.state.map { it.connectionState }.distinctUntilChanged().collectInLocalScope { state ->
Log.d(TAG, "New state: $state")
when (state) {
SubscriberConnectionState.Connected -> {
onConnected()
Expand Down Expand Up @@ -137,11 +141,16 @@ class MultiStreamListener(
subscriber.release()
}

private fun onConnected() {
private suspend fun onConnected() {
Log.d(
TAG,
"onConnected, this: $this, thread: ${Thread.currentThread().id}"
)
try {
subscriber.subscribe(options = options)
} catch (e: MillicastException) {
e.printStackTrace()
}
}

private fun onDisconnected() {
Expand All @@ -160,9 +169,6 @@ class MultiStreamListener(

private fun onSignalingError(p0: String?) {
Log.d(TAG, "onSignalingError: $p0")
data.update {
it.populateError(error = p0 ?: "Signaling error")
}
}

private fun onStatsReport(p0: RtsReport?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ class MultiStreamingRepository(
}
val subscriber = Core.createSubscriber()

listener = MultiStreamListener(_data, subscriber).apply {
start()
}
subscriber.enableStats(true)

subscriber.setCredentials(
Expand Down Expand Up @@ -209,11 +206,14 @@ class MultiStreamingRepository(
options = options.copy(rtcEventLogOutputPath = path + "/${timeStamp}_rtclogs.proto")
}

listener = MultiStreamListener(_data, subscriber, options).apply {
start()
}

Log.d(TAG, "Connecting ...")

try {
subscriber.connect(ConnectionOptions(true))
subscriber.subscribe(options = options)
} catch (e: Throwable) {
e.printStackTrace()
}
Expand Down
Loading