From 1666677baf0f7ba810353eae96fe80ed6127a4db Mon Sep 17 00:00:00 2001 From: CranberrySoup <142951702+CranberrySoup@users.noreply.github.com> Date: Fri, 2 Aug 2024 01:29:45 +0000 Subject: [PATCH] Update FcastManager.kt --- .../cloudstream3/utils/fcast/FcastManager.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/fcast/FcastManager.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/fcast/FcastManager.kt index 9ff5cc08..e7c36a87 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/fcast/FcastManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/fcast/FcastManager.kt @@ -79,7 +79,9 @@ class FcastManager { override fun onServiceResolved(serviceInfo: NsdServiceInfo?) { if (serviceInfo == null) return - currentDevices.add(PublicDeviceInfo(serviceInfo)) + synchronized(_currentDevices) { + _currentDevices.add(PublicDeviceInfo(serviceInfo)) + } Log.d( tag, @@ -93,8 +95,10 @@ class FcastManager { if (serviceInfo == null) return // May remove duplicates, but net and port is null here, preventing device specific identification - currentDevices.removeAll { - it.rawName == serviceInfo.serviceName + synchronized(_currentDevices) { + _currentDevices.removeAll { + it.rawName == serviceInfo.serviceName + } } Log.d(tag, "Service lost: ${serviceInfo.serviceName}") @@ -103,7 +107,8 @@ class FcastManager { companion object { const val APP_PREFIX = "CloudStream" - val currentDevices: MutableList = mutableListOf() + private val _currentDevices: MutableList = mutableListOf() + val currentDevices: List = _currentDevices class DefaultRegistrationListener : NsdManager.RegistrationListener { val tag = "DiscoveryService" @@ -132,4 +137,4 @@ class PublicDeviceInfo(serviceInfo: NsdServiceInfo) { val rawName: String = serviceInfo.serviceName val host: String? = serviceInfo.host.hostAddress val name = rawName.replace("-", " ") + host?.let { " $it" } -} \ No newline at end of file +}