Publisher
extension Publisher
extension Publisher where Self.Failure == LittleBluetoothError
extension Publisher where Self.Output == PeripheralDiscovery, Self.Failure == LittleBluetoothError
extension Publisher where Self.Output == PeripheralIdentifier, Self.Failure == LittleBluetoothError
-
Provides a subject that shares a single subscription to the upstream publisher and replays at most
bufferSizeitems emitted by that publisherDeclaration
Swift
public func shareReplay(_ bufferSize: Int) -> AnyPublisher<Output, Failure>Parameters
bufferSizelimits the number of items that can be replayed
-
Returns a publisher with the
LittleBlueToothCharacteristicwhere the notify command has been activated. After starting the listen command you should subscribe to thelistenPublisherto be notified.Important
This publisher only activate the notification on a specific characteristic, it will not send notified values. After starting the listen command you should subscribe to thelistenPublisherto be notified.Declaration
Swift
public func enableListen(for littleBluetooth: LittleBlueTooth, from characteristic: LittleBlueToothCharacteristic) -> AnyPublisher<LittleBlueToothCharacteristic, LittleBluetoothError>Parameters
littleBluetooththe
LittleBlueToothinstancecharacteristicCharacteristc you want to be notified.
Return Value
A publisher with the
LittleBlueToothCharacteristicwhere the notify command has been activated. -
Returns a shared publisher for listening to a specific characteristic.
Important
The type of the value must be conform toReadableDeclaration
Swift
public func startListen<T: Readable>(for littleBluetooth: LittleBlueTooth, from charact: LittleBlueToothCharacteristic) -> AnyPublisher<T, LittleBluetoothError>Parameters
littleBluetooththe
LittleBlueToothinstancecharacteristicCharacteristc you want to be notified.
Return Value
A shared publisher that will send out values of the type defined by the generic type.
-
Disable listen from a specific characteristic
Declaration
Swift
public func disableListen(for littleBluetooth: LittleBlueTooth, from characteristic: LittleBlueToothCharacteristic) -> AnyPublisher<LittleBlueToothCharacteristic, LittleBluetoothError>Parameters
characteristiccharacteristic you want to stop listen
Return Value
A publisher with that informs you about the successful or failed task
-
Returns a publisher with the
Intvalue of the RSSI.Declaration
Swift
public func readRSSI(for littleBluetooth: LittleBlueTooth) -> AnyPublisher<Int, LittleBluetoothError>Parameters
littleBluetooththe
LittleBlueToothinstanceReturn Value
A publisher with the
Intvalue of the RSSI.
-
Read a value from a specific charteristic
Important
The type of the value must be conform toReadableDeclaration
Swift
public func read<T: Readable>(for littleBluetooth: LittleBlueTooth, from characteristic: LittleBlueToothCharacteristic) -> AnyPublisher<T, LittleBluetoothError>Parameters
littleBluetooththe
LittleBlueToothinstancecharacteristiccharacteristic where you want to read
Return Value
A publisher with the value you want to read.
-
Write a value to a specific charteristic
Important
The type of the value must be conform toWritableDeclaration
Swift
public func write<T: Writable>(for littleBluetooth: LittleBlueTooth, to characteristic: LittleBlueToothCharacteristic, value: T, response: Bool = true) -> AnyPublisher<Void, LittleBluetoothError>Parameters
littleBluetooththe
LittleBlueToothinstancecharacteristiccharacteristic where you want to write
valueThe value you want to write
responseAn optional
Boolvalue that will look for error after write operationReturn Value
A publisher with that informs you about eventual error
-
Write a value to a specific charteristic and wait for a response
Declaration
Swift
public func writeAndListen<W: Writable, R: Readable>(for littleBluetooth: LittleBlueTooth, from characteristic: LittleBlueToothCharacteristic, value: W) -> AnyPublisher<R, LittleBluetoothError>Parameters
littleBluetooththe
LittleBlueToothinstancecharacteristiccharacteristic where you want to write and listen
valueThe value you want to write must conform to
WritableReturn Value
A publisher with that post and error or the response of the write requests.
-
Starts scanning for
PeripheralDiscoveryDeclaration
Swift
public func startDiscovery(for littleBluetooth: LittleBlueTooth, withServices services: [CBUUID]?, options: [String : Any]? = nil) -> AnyPublisher<PeripheralDiscovery, LittleBluetoothError>Parameters
littleBluetooththe
LittleBlueToothinstanceservicesServices for peripheral you are looking for
optionsScanning options same as CoreBluetooth central manager option.
Return Value
A publisher with stream of disovered peripherals.
-
Stops peripheral discovery
Declaration
Swift
public func stopDiscovery(for littleBluetooth: LittleBlueTooth) -> AnyPublisher<Void, LittleBluetoothError>Parameters
littleBluetooththe
LittleBlueToothinstanceReturn Value
A publisher when discovery has been stopped
-
Starts connection for
PeripheralDiscoveryDeclaration
Swift
public func connect(for littleBluetooth: LittleBlueTooth, options: [String : Any]? = nil) -> AnyPublisher<Peripheral, LittleBluetoothError>Parameters
littleBluetooththe
LittleBlueToothinstanceoptionsConnecting options same as CoreBluetooth central manager option.
Return Value
A publisher with the just connected
Peripheral.
-
Starts connection for
PeripheralIdentifierDeclaration
Swift
public func connect(for littleBluetooth: LittleBlueTooth, options: [String : Any]? = nil) -> AnyPublisher<Peripheral, LittleBluetoothError>Parameters
littleBluetooththe
LittleBlueToothinstanceoptionsConnecting options same as CoreBluetooth central manager option.
Return Value
A publisher with the just connected
Peripheral.
-
Disconnect the connected
PeripheralDeclaration
Swift
@discardableResult public func disconnect(for littleBluetooth: LittleBlueTooth) -> AnyPublisher<Peripheral, LittleBluetoothError>Return Value
A publisher with the just disconnected
Peripheralor aLittleBluetoothError -
Specialized timeout function to return a
LittleBluetoothErrorerror type. By default it returns.operationTimeout, but you can specify a different error such as.connectionTimeout,.scanTimeoutTerminates publishing if the upstream publisher exceeds the specified time interval without producing an element.Declaration
Swift
public func timeout<S>(_ interval: S.SchedulerTimeType.Stride, scheduler: S, options: S.SchedulerOptions? = nil, error: LittleBluetoothError = .operationTimeout) -> AnyPublisher<Self.Output, LittleBluetoothError> where S : SchedulerParameters
intervalThe maximum time interval the publisher can go without emitting an element, expressed in the time system of the scheduler.
schedulerThe scheduler to deliver events on.
optionsScheduler options that customize the delivery of elements.
errorAn error to be returned if the publisher times out, by default
LittleBluetoothError.connectionTimeoutReturn Value
A publisher that terminates if the specified interval elapses with no events received from the upstream publisher.
View on GitHub
Publisher Extension Reference