mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-09-16 22:42:23 +00:00
casting: add discovered devices directly to internal list when added
This commit is contained in:
parent
1176cee40b
commit
7169cd1b82
1 changed files with 7 additions and 15 deletions
|
@ -111,21 +111,6 @@ class ExpStateCasting {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
org.fcast.sender_sdk.initLogger(org.fcast.sender_sdk.LogLevelFilter.DEBUG)
|
org.fcast.sender_sdk.initLogger(org.fcast.sender_sdk.LogLevelFilter.DEBUG)
|
||||||
onDeviceAdded.subscribe { device ->
|
|
||||||
invokeInMainScopeIfRequired {
|
|
||||||
val deviceHandle = CastingDeviceHandle(device)
|
|
||||||
devices[deviceHandle.device.name()] = deviceHandle
|
|
||||||
Log.i(TAG, "Device added: ${deviceHandle.device.name()}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onDeviceRemoved.subscribe { deviceName ->
|
|
||||||
invokeInMainScopeIfRequired {
|
|
||||||
if (devices.containsKey(deviceName)) {
|
|
||||||
devices.remove(deviceName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleUrl(context: Context, url: String) {
|
fun handleUrl(context: Context, url: String) {
|
||||||
|
@ -191,17 +176,24 @@ class ExpStateCasting {
|
||||||
context,
|
context,
|
||||||
DiscoveryEventHandler(
|
DiscoveryEventHandler(
|
||||||
{ deviceInfo -> // Added
|
{ deviceInfo -> // Added
|
||||||
|
Logger.i(TAG, "Device added: ${deviceInfo.name}")
|
||||||
val device = _context.createDeviceFromInfo(deviceInfo)
|
val device = _context.createDeviceFromInfo(deviceInfo)
|
||||||
|
val deviceHandle = CastingDeviceHandle(device)
|
||||||
|
devices[deviceHandle.device.name()] = deviceHandle
|
||||||
invokeInMainScopeIfRequired {
|
invokeInMainScopeIfRequired {
|
||||||
onDeviceAdded.emit(device)
|
onDeviceAdded.emit(device)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ deviceName -> // Removed
|
{ deviceName -> // Removed
|
||||||
invokeInMainScopeIfRequired {
|
invokeInMainScopeIfRequired {
|
||||||
|
if (devices.containsKey(deviceName)) {
|
||||||
|
devices.remove(deviceName)
|
||||||
|
}
|
||||||
onDeviceRemoved.emit(deviceName)
|
onDeviceRemoved.emit(deviceName)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ deviceInfo -> // Updated
|
{ deviceInfo -> // Updated
|
||||||
|
Logger.i(TAG, "Device updated: $deviceInfo")
|
||||||
val handle = devices[deviceInfo.name]
|
val handle = devices[deviceInfo.name]
|
||||||
if (handle != null) {
|
if (handle != null) {
|
||||||
handle.device.setPort(deviceInfo.port)
|
handle.device.setPort(deviceInfo.port)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue