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
bufferSize
items emitted by that publisherDeclaration
Swift
public func shareReplay(_ bufferSize: Int) -> AnyPublisher<Output, Failure>
Parameters
bufferSize
limits the number of items that can be replayed
-
Returns a publisher with the
LittleBlueToothCharacteristic
where the notify command has been activated. After starting the listen command you should subscribe to thelistenPublisher
to 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 thelistenPublisher
to be notified.Declaration
Swift
public func enableListen(for littleBluetooth: LittleBlueTooth, from characteristic: LittleBlueToothCharacteristic) -> AnyPublisher<LittleBlueToothCharacteristic, LittleBluetoothError>
Parameters
littleBluetooth
the
LittleBlueTooth
instancecharacteristic
Characteristc you want to be notified.
Return Value
A publisher with the
LittleBlueToothCharacteristic
where 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 toReadable
Declaration
Swift
public func startListen<T: Readable>(for littleBluetooth: LittleBlueTooth, from charact: LittleBlueToothCharacteristic) -> AnyPublisher<T, LittleBluetoothError>
Parameters
littleBluetooth
the
LittleBlueTooth
instancecharacteristic
Characteristc 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
characteristic
characteristic you want to stop listen
Return Value
A publisher with that informs you about the successful or failed task
-
Returns a publisher with the
Int
value of the RSSI.Declaration
Swift
public func readRSSI(for littleBluetooth: LittleBlueTooth) -> AnyPublisher<Int, LittleBluetoothError>
Parameters
littleBluetooth
the
LittleBlueTooth
instanceReturn Value
A publisher with the
Int
value of the RSSI.
-
Read a value from a specific charteristic
Important
The type of the value must be conform toReadable
Declaration
Swift
public func read<T: Readable>(for littleBluetooth: LittleBlueTooth, from characteristic: LittleBlueToothCharacteristic) -> AnyPublisher<T, LittleBluetoothError>
Parameters
littleBluetooth
the
LittleBlueTooth
instancecharacteristic
characteristic 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 toWritable
Declaration
Swift
public func write<T: Writable>(for littleBluetooth: LittleBlueTooth, to characteristic: LittleBlueToothCharacteristic, value: T, response: Bool = true) -> AnyPublisher<Void, LittleBluetoothError>
Parameters
littleBluetooth
the
LittleBlueTooth
instancecharacteristic
characteristic where you want to write
value
The value you want to write
response
An optional
Bool
value 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
littleBluetooth
the
LittleBlueTooth
instancecharacteristic
characteristic where you want to write and listen
value
The value you want to write must conform to
Writable
Return Value
A publisher with that post and error or the response of the write requests.
-
Starts scanning for
PeripheralDiscovery
Declaration
Swift
public func startDiscovery(for littleBluetooth: LittleBlueTooth, withServices services: [CBUUID]?, options: [String : Any]? = nil) -> AnyPublisher<PeripheralDiscovery, LittleBluetoothError>
Parameters
littleBluetooth
the
LittleBlueTooth
instanceservices
Services for peripheral you are looking for
options
Scanning 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
littleBluetooth
the
LittleBlueTooth
instanceReturn Value
A publisher when discovery has been stopped
-
Starts connection for
PeripheralDiscovery
Declaration
Swift
public func connect(for littleBluetooth: LittleBlueTooth, options: [String : Any]? = nil) -> AnyPublisher<Peripheral, LittleBluetoothError>
Parameters
littleBluetooth
the
LittleBlueTooth
instanceoptions
Connecting options same as CoreBluetooth central manager option.
Return Value
A publisher with the just connected
Peripheral
.
-
Starts connection for
PeripheralIdentifier
Declaration
Swift
public func connect(for littleBluetooth: LittleBlueTooth, options: [String : Any]? = nil) -> AnyPublisher<Peripheral, LittleBluetoothError>
Parameters
littleBluetooth
the
LittleBlueTooth
instanceoptions
Connecting options same as CoreBluetooth central manager option.
Return Value
A publisher with the just connected
Peripheral
.
-
Disconnect the connected
Peripheral
Declaration
Swift
@discardableResult public func disconnect(for littleBluetooth: LittleBlueTooth) -> AnyPublisher<Peripheral, LittleBluetoothError>
Return Value
A publisher with the just disconnected
Peripheral
or aLittleBluetoothError
-
Specialized timeout function to return a
LittleBluetoothError
error type. By default it returns.operationTimeout
, but you can specify a different error such as.connectionTimeout
,.scanTimeout
Terminates 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 : Scheduler
Parameters
interval
The maximum time interval the publisher can go without emitting an element, expressed in the time system of the scheduler.
scheduler
The scheduler to deliver events on.
options
Scheduler options that customize the delivery of elements.
error
An error to be returned if the publisher times out, by default
LittleBluetoothError.connectionTimeout
Return Value
A publisher that terminates if the specified interval elapses with no events received from the upstream publisher.