Allow controls magix endpoint to receive broadcast.
This commit is contained in:
parent
fa2414ef47
commit
b1121d61cb
@ -32,12 +32,14 @@ internal fun generateId(request: MagixMessage): String = if (request.id != null)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Communicate with server in [Magix format](https://github.com/waltz-controls/rfc/tree/master/1)
|
* Communicate with server in [Magix format](https://github.com/waltz-controls/rfc/tree/master/1)
|
||||||
|
*
|
||||||
|
* Accepts messages with target that equals [endpointID] or null (broadcast messages)
|
||||||
*/
|
*/
|
||||||
public fun DeviceManager.launchMagixService(
|
public fun DeviceManager.launchMagixService(
|
||||||
endpoint: MagixEndpoint,
|
endpoint: MagixEndpoint,
|
||||||
endpointID: String = controlsMagixFormat.defaultFormat,
|
endpointID: String = controlsMagixFormat.defaultFormat,
|
||||||
): Job = context.launch {
|
): Job = context.launch {
|
||||||
endpoint.subscribe(controlsMagixFormat, targetFilter = listOf(endpointID)).onEach { (request, payload) ->
|
endpoint.subscribe(controlsMagixFormat, targetFilter = listOf(endpointID, null)).onEach { (request, payload) ->
|
||||||
val responsePayload = respondHubMessage(payload)
|
val responsePayload = respondHubMessage(payload)
|
||||||
responsePayload.forEach {
|
responsePayload.forEach {
|
||||||
endpoint.send(
|
endpoint.send(
|
||||||
|
@ -26,7 +26,7 @@ public data class MagixFormat<T>(
|
|||||||
public fun <T> MagixEndpoint.subscribe(
|
public fun <T> MagixEndpoint.subscribe(
|
||||||
format: MagixFormat<T>,
|
format: MagixFormat<T>,
|
||||||
originFilter: Collection<String>? = null,
|
originFilter: Collection<String>? = null,
|
||||||
targetFilter: Collection<String>? = null,
|
targetFilter: Collection<String?>? = null,
|
||||||
): Flow<Pair<MagixMessage, T>> = subscribe(
|
): Flow<Pair<MagixMessage, T>> = subscribe(
|
||||||
MagixMessageFilter(format = format.formats, source = originFilter, target = targetFilter)
|
MagixMessageFilter(format = format.formats, source = originFilter, target = targetFilter)
|
||||||
).map {
|
).map {
|
||||||
|
@ -11,7 +11,7 @@ import kotlinx.serialization.Serializable
|
|||||||
public data class MagixMessageFilter(
|
public data class MagixMessageFilter(
|
||||||
val format: Collection<String>? = null,
|
val format: Collection<String>? = null,
|
||||||
val source: Collection<String>? = null,
|
val source: Collection<String>? = null,
|
||||||
val target: Collection<String>? = null,
|
val target: Collection<String?>? = null,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
public fun accepts(message: MagixMessage): Boolean =
|
public fun accepts(message: MagixMessage): Boolean =
|
||||||
|
@ -39,9 +39,8 @@ public class XodusMagixHistory(private val store: PersistentEntityStore) : Write
|
|||||||
|
|
||||||
setBlobString(MagixMessage::payload.name, magixJson.encodeToString(message.payload))
|
setBlobString(MagixMessage::payload.name, magixJson.encodeToString(message.payload))
|
||||||
|
|
||||||
message.targetEndpoint?.let {
|
setProperty(MagixMessage::targetEndpoint.name, (message.targetEndpoint ?: ""))
|
||||||
setProperty(MagixMessage::targetEndpoint.name, it)
|
|
||||||
}
|
|
||||||
message.id?.let {
|
message.id?.let {
|
||||||
setProperty(MagixMessage::id.name, it)
|
setProperty(MagixMessage::id.name, it)
|
||||||
}
|
}
|
||||||
@ -68,14 +67,14 @@ public class XodusMagixHistory(private val store: PersistentEntityStore) : Write
|
|||||||
): Unit = store.executeInReadonlyTransaction { transaction ->
|
): Unit = store.executeInReadonlyTransaction { transaction ->
|
||||||
val all = transaction.getAll(XodusMagixStorage.MAGIC_MESSAGE_ENTITY_TYPE)
|
val all = transaction.getAll(XodusMagixStorage.MAGIC_MESSAGE_ENTITY_TYPE)
|
||||||
|
|
||||||
fun StoreTransaction.findAllIn(
|
fun findAllIn(
|
||||||
entityType: String,
|
entityType: String,
|
||||||
field: String,
|
field: String,
|
||||||
values: Collection<String>?,
|
values: Collection<String?>?,
|
||||||
): EntityIterable? {
|
): EntityIterable? {
|
||||||
var union: EntityIterable? = null
|
var union: EntityIterable? = null
|
||||||
values?.forEach {
|
values?.forEach {
|
||||||
val filter = transaction.find(entityType, field, it)
|
val filter = transaction.find(entityType, field, it ?: "")
|
||||||
union = union?.union(filter) ?: filter
|
union = union?.union(filter) ?: filter
|
||||||
}
|
}
|
||||||
return union
|
return union
|
||||||
@ -84,21 +83,24 @@ public class XodusMagixHistory(private val store: PersistentEntityStore) : Write
|
|||||||
// filter by magix filter
|
// filter by magix filter
|
||||||
val filteredByMagix: EntityIterable = magixFilter?.let { mf ->
|
val filteredByMagix: EntityIterable = magixFilter?.let { mf ->
|
||||||
var res = all
|
var res = all
|
||||||
transaction.findAllIn(XodusMagixStorage.MAGIC_MESSAGE_ENTITY_TYPE, MagixMessage::format.name, mf.format)
|
findAllIn(
|
||||||
?.let {
|
XodusMagixStorage.MAGIC_MESSAGE_ENTITY_TYPE,
|
||||||
res = res.intersect(it)
|
MagixMessage::format.name,
|
||||||
}
|
mf.format
|
||||||
transaction.findAllIn(
|
)?.let {
|
||||||
|
res = res.intersect(it)
|
||||||
|
}
|
||||||
|
findAllIn(
|
||||||
XodusMagixStorage.MAGIC_MESSAGE_ENTITY_TYPE,
|
XodusMagixStorage.MAGIC_MESSAGE_ENTITY_TYPE,
|
||||||
MagixMessage::sourceEndpoint.name,
|
MagixMessage::sourceEndpoint.name,
|
||||||
mf.source
|
mf.source
|
||||||
)?.let {
|
)?.let {
|
||||||
res = res.intersect(it)
|
res = res.intersect(it)
|
||||||
}
|
}
|
||||||
transaction.findAllIn(
|
findAllIn(
|
||||||
XodusMagixStorage.MAGIC_MESSAGE_ENTITY_TYPE,
|
XodusMagixStorage.MAGIC_MESSAGE_ENTITY_TYPE,
|
||||||
MagixMessage::targetEndpoint.name,
|
MagixMessage::targetEndpoint.name,
|
||||||
mf.target
|
mf.target?.filterNotNull()
|
||||||
)?.let {
|
)?.let {
|
||||||
res = res.intersect(it)
|
res = res.intersect(it)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user