Update FcastManager.kt (#1244)

This commit is contained in:
CranberrySoup 2024-08-02 10:30:37 +00:00 committed by GitHub
parent 15b5013e28
commit 7936ccf5d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -79,7 +79,9 @@ class FcastManager {
override fun onServiceResolved(serviceInfo: NsdServiceInfo?) { override fun onServiceResolved(serviceInfo: NsdServiceInfo?) {
if (serviceInfo == null) return if (serviceInfo == null) return
currentDevices.add(PublicDeviceInfo(serviceInfo)) synchronized(_currentDevices) {
_currentDevices.add(PublicDeviceInfo(serviceInfo))
}
Log.d( Log.d(
tag, tag,
@ -93,8 +95,10 @@ class FcastManager {
if (serviceInfo == null) return if (serviceInfo == null) return
// May remove duplicates, but net and port is null here, preventing device specific identification // May remove duplicates, but net and port is null here, preventing device specific identification
currentDevices.removeAll { synchronized(_currentDevices) {
it.rawName == serviceInfo.serviceName _currentDevices.removeAll {
it.rawName == serviceInfo.serviceName
}
} }
Log.d(tag, "Service lost: ${serviceInfo.serviceName}") Log.d(tag, "Service lost: ${serviceInfo.serviceName}")
@ -103,7 +107,8 @@ class FcastManager {
companion object { companion object {
const val APP_PREFIX = "CloudStream" const val APP_PREFIX = "CloudStream"
val currentDevices: MutableList<PublicDeviceInfo> = mutableListOf() private val _currentDevices: MutableList<PublicDeviceInfo> = mutableListOf()
val currentDevices: List<PublicDeviceInfo> = _currentDevices
class DefaultRegistrationListener : NsdManager.RegistrationListener { class DefaultRegistrationListener : NsdManager.RegistrationListener {
val tag = "DiscoveryService" val tag = "DiscoveryService"
@ -132,4 +137,4 @@ class PublicDeviceInfo(serviceInfo: NsdServiceInfo) {
val rawName: String = serviceInfo.serviceName val rawName: String = serviceInfo.serviceName
val host: String? = serviceInfo.host.hostAddress val host: String? = serviceInfo.host.hostAddress
val name = rawName.replace("-", " ") + host?.let { " $it" } val name = rawName.replace("-", " ") + host?.let { " $it" }
} }