Skip to content
Merged
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
30 changes: 29 additions & 1 deletion Sources/FlutterSwiftOCA/OcaChannelManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ Sendable {
private let meteringEventChannel: FlutterEventChannel
private let connectionStateChannel: FlutterEventChannel

private let identificationSensor: OcaIdentificationSensor?
private let identifyEventChannel: FlutterEventChannel? // report identify events

private final class MeteringEventSubscription: Hashable, Sendable {
static func == (
lhs: OcaChannelManager.MeteringEventSubscription,
Expand Down Expand Up @@ -115,7 +118,8 @@ Sendable {
binaryMessenger: FlutterBinaryMessenger,
logger: Logger,
flags: Flags = [],
propertyEventChannelBufferSize: Int = 10
propertyEventChannelBufferSize: Int = 10,
identificationSensor: OcaIdentificationSensor? = nil
) throws {
self.connection = connection
self.binaryMessenger = binaryMessenger
Expand Down Expand Up @@ -164,6 +168,16 @@ Sendable {
binaryMessenger: binaryMessenger
)

self.identificationSensor = identificationSensor
if identificationSensor != nil {
identifyEventChannel = FlutterEventChannel(
name: "\(OcaChannelPrefix)identify",
binaryMessenger: binaryMessenger
)
} else {
identifyEventChannel = nil
}

try methodChannel.setMethodCallHandler(onMethod)
try getPropertyChannel.setMethodCallHandler(onGetProperty)
try setPropertyChannel.setMethodCallHandler(onSetProperty)
Expand All @@ -183,6 +197,10 @@ Sendable {
onListen: onConnectionStateListen,
onCancel: onConnectionStateCancel
)
try identifyEventChannel?.setStreamHandler(
onListen: onIdentifyEventListen,
onCancel: onIdentifyEventCancel
)

try propertyEventChannel.allowChannelBufferOverflow(true)
try propertyEventChannel.resizeChannelBuffer(propertyEventChannelBufferSize)
Expand Down Expand Up @@ -673,6 +691,16 @@ Sendable {

@Sendable
private func onConnectionStateCancel(_: AnyFlutterStandardCodable?) async throws {}

@Sendable
private func onIdentifyEventListen(_: AnyFlutterStandardCodable?) async throws
-> FlutterEventStream<Bool>
{
await identificationSensor!.identifyEvents.map { true }.eraseToAnyAsyncSequence()
}

@Sendable
private func onIdentifyEventCancel(_: AnyFlutterStandardCodable?) async throws {}
}

extension OcaPropertySubjectRepresentable {
Expand Down