Skip to content

Commit

Permalink
Merge pull request #238 from morikatron/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ma2bara committed Nov 29, 2021
2 parents dac89e0 + 4ea950a commit fef36c4
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 52 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- [BLE] iOS BLE Plugin now supports XCode 13.
- [WebGL] Update WebGL template `webble` for Unity 2020. The old template is renamed as `webble.unity2019`.
- [General] Unity tags used by toio SDK for unity are changed to `t4u_Cube`, `t4u_Mat`, `t4u_StandardID` and `t4u_Magnet`, to avoid potential conflits with users' codes.
- [Sample] Sample_Sensor updated with new Cube features.
Expand Down
Expand Up @@ -64,9 +64,18 @@ import CoreBluetooth
guard let arrayOfAnyObjects = objects else { return [] }
return arrayOfAnyObjects.compactMap { $0 as? CBService }
.map(RxCBService.init)
.map { Service(peripheral: Peripheral(manager: bluetoothManager,
peripheral: RxCBPeripheral(peripheral: $0.service.peripheral)),
service: $0) }
.compactMap {

// Necessary to accomodate the changes between
// iOS 14 and iOS 15
let optPeripheral: CBPeripheral? = $0.service.peripheral
guard let peripheral = optPeripheral else {
return nil
}

return Service(peripheral: Peripheral(manager: bluetoothManager,
peripheral: RxCBPeripheral(peripheral: peripheral)),
service: $0) }
}
}
#endif
Expand Up @@ -31,6 +31,13 @@ class RxCBCharacteristic: RxCharacteristicType {
self.characteristic = characteristic
}

init?(characteristic: CBCharacteristic?) {
guard let characteristic = characteristic else {
return nil
}
self.characteristic = characteristic
}

var objectId: UInt {
return UInt(bitPattern: ObjectIdentifier(characteristic))
}
Expand All @@ -55,7 +62,7 @@ class RxCBCharacteristic: RxCharacteristicType {
return characteristic.descriptors?.map(RxCBDescriptor.init)
}

var service: RxServiceType {
var service: RxServiceType? {
return RxCBService(service: characteristic.service)
}

Expand Down
Expand Up @@ -39,7 +39,7 @@ class RxCBDescriptor: RxDescriptorType {
return descriptor.uuid
}

var characteristic: RxCharacteristicType {
var characteristic: RxCharacteristicType? {
return RxCBCharacteristic(characteristic: descriptor.characteristic)
}

Expand Down
Expand Up @@ -54,7 +54,7 @@ class RxCBPeripheral: RxPeripheralType {
}

var services: [RxServiceType]? {
return peripheral.services?.map(RxCBService.init)
return peripheral.services?.compactMap(RxCBService.init)
}

var canSendWriteWithoutResponse: Bool {
Expand Down Expand Up @@ -247,7 +247,7 @@ class RxCBPeripheral: RxPeripheralType {
\(peripheral.logDescription) didModifyServices(services:
[\(invalidatedServices.logDescription))]
""")
peripheralDidModifyServicesSubject.onNext(invalidatedServices.map(RxCBService.init))
peripheralDidModifyServicesSubject.onNext(invalidatedServices.compactMap(RxCBService.init))
}

@objc func peripheral(_ peripheral: CBPeripheral, didReadRSSI rssi: NSNumber, error: Error?) {
Expand All @@ -264,7 +264,7 @@ class RxCBPeripheral: RxPeripheralType {
: \(String(describing: peripheral.services?.logDescription)),
error: \(String(describing: error)))
""")
peripheralDidDiscoverServicesSubject.onNext((peripheral.services?.map(RxCBService.init), error))
peripheralDidDiscoverServicesSubject.onNext((peripheral.services?.compactMap(RxCBService.init), error))
}

@objc func peripheral(_ peripheral: CBPeripheral,
Expand Down
Expand Up @@ -30,6 +30,13 @@ class RxCBService: RxServiceType {
self.service = service
}

init?(service: CBService?) {
guard let service = service else {
return nil
}
self.service = service
}

var objectId: UInt {
return UInt(bitPattern: ObjectIdentifier(service))
}
Expand All @@ -39,11 +46,11 @@ class RxCBService: RxServiceType {
}

var characteristics: [RxCharacteristicType]? {
return service.characteristics?.map(RxCBCharacteristic.init)
return service.characteristics?.compactMap(RxCBCharacteristic.init)
}

var includedServices: [RxServiceType]? {
return service.includedServices?.map(RxCBService.init)
return service.includedServices?.compactMap(RxCBService.init)
}

var isPrimary: Bool {
Expand Down
Expand Up @@ -30,7 +30,7 @@ protocol RxCharacteristicType {
var isNotifying: Bool { get }
var properties: CBCharacteristicProperties { get }
var descriptors: [RxDescriptorType]? { get }
var service: RxServiceType { get }
var service: RxServiceType? { get }

func isEqualTo(characteristic: RxCharacteristicType) -> Bool
}
Expand Down
Expand Up @@ -29,7 +29,7 @@ protocol RxDescriptorType {

var uuid: CBUUID { get }

var characteristic: RxCharacteristicType { get }
var characteristic: RxCharacteristicType? { get }

var value: Any? { get }

Expand Down
Expand Up @@ -24,7 +24,7 @@ public enum CompletableEvent {
}

public extension PrimitiveSequenceType where TraitType == CompletableTrait, ElementType == Swift.Never {
public typealias CompletableObserver = (CompletableEvent) -> ()
typealias CompletableObserver = (CompletableEvent) -> ()

/**
Creates an observable sequence from a specified subscribe method implementation.
Expand All @@ -34,7 +34,7 @@ public extension PrimitiveSequenceType where TraitType == CompletableTrait, Elem
- parameter subscribe: Implementation of the resulting observable sequence's `subscribe` method.
- returns: The observable sequence with the specified implementation for the `subscribe` method.
*/
public static func create(subscribe: @escaping (@escaping CompletableObserver) -> Disposable) -> PrimitiveSequence<TraitType, ElementType> {
static func create(subscribe: @escaping (@escaping CompletableObserver) -> Disposable) -> PrimitiveSequence<TraitType, ElementType> {
let source = Observable<ElementType>.create { observer in
return subscribe { event in
switch event {
Expand All @@ -54,7 +54,7 @@ public extension PrimitiveSequenceType where TraitType == CompletableTrait, Elem
- returns: Subscription for `observer` that can be used to cancel production of sequence elements and free resources.
*/
public func subscribe(_ observer: @escaping (CompletableEvent) -> ()) -> Disposable {
func subscribe(_ observer: @escaping (CompletableEvent) -> ()) -> Disposable {
var stopped = false
return self.primitiveSequence.asObservable().subscribe { event in
if stopped { return }
Expand All @@ -78,7 +78,7 @@ public extension PrimitiveSequenceType where TraitType == CompletableTrait, Elem
- parameter onError: Action to invoke upon errored termination of the observable sequence.
- returns: Subscription object used to unsubscribe from the observable sequence.
*/
public func subscribe(onCompleted: (() -> Void)? = nil, onError: ((Swift.Error) -> Void)? = nil) -> Disposable {
func subscribe(onCompleted: (() -> Void)? = nil, onError: ((Swift.Error) -> Void)? = nil) -> Disposable {
#if DEBUG
let callStack = Hooks.recordCallStackOnError ? Thread.callStackSymbols : []
#else
Expand Down Expand Up @@ -108,7 +108,7 @@ public extension PrimitiveSequenceType where TraitType == CompletableTrait, Elem
- returns: The observable sequence that terminates with specified error.
*/
public static func error(_ error: Swift.Error) -> Completable {
static func error(_ error: Swift.Error) -> Completable {
return PrimitiveSequence(raw: Observable.error(error))
}

Expand All @@ -119,7 +119,7 @@ public extension PrimitiveSequenceType where TraitType == CompletableTrait, Elem
- returns: An observable sequence whose observers will never get called.
*/
public static func never() -> Completable {
static func never() -> Completable {
return PrimitiveSequence(raw: Observable.never())
}

Expand All @@ -130,7 +130,7 @@ public extension PrimitiveSequenceType where TraitType == CompletableTrait, Elem
- returns: An observable sequence with no elements.
*/
public static func empty() -> Completable {
static func empty() -> Completable {
return Completable(raw: Observable.empty())
}

Expand All @@ -150,7 +150,7 @@ public extension PrimitiveSequenceType where TraitType == CompletableTrait, Elem
- parameter onDispose: Action to invoke after subscription to source observable has been disposed for any reason. It can be either because sequence terminates for some reason or observer subscription being disposed.
- returns: The source sequence with the side-effecting behavior applied.
*/
public func `do`(onError: ((Swift.Error) throws -> Void)? = nil,
func `do`(onError: ((Swift.Error) throws -> Void)? = nil,
onCompleted: (() throws -> Void)? = nil,
onSubscribe: (() -> ())? = nil,
onSubscribed: (() -> ())? = nil,
Expand All @@ -175,7 +175,7 @@ public extension PrimitiveSequenceType where TraitType == CompletableTrait, Elem
- parameter second: Second observable sequence.
- returns: An observable sequence that contains the elements of `self`, followed by those of the second sequence.
*/
public func concat(_ second: Completable) -> Completable {
func concat(_ second: Completable) -> Completable {
return Completable.concat(primitiveSequence, second)
}

Expand All @@ -186,7 +186,7 @@ public extension PrimitiveSequenceType where TraitType == CompletableTrait, Elem
- returns: An observable sequence that contains the elements of each given sequence, in sequential order.
*/
public static func concat<S: Sequence>(_ sequence: S) -> Completable
static func concat<S: Sequence>(_ sequence: S) -> Completable
where S.Iterator.Element == Completable {
let source = Observable.concat(sequence.lazy.map { $0.asObservable() })
return Completable(raw: source)
Expand All @@ -199,7 +199,7 @@ public extension PrimitiveSequenceType where TraitType == CompletableTrait, Elem
- returns: An observable sequence that contains the elements of each given sequence, in sequential order.
*/
public static func concat<C: Collection>(_ collection: C) -> Completable
static func concat<C: Collection>(_ collection: C) -> Completable
where C.Iterator.Element == Completable {
let source = Observable.concat(collection.map { $0.asObservable() })
return Completable(raw: source)
Expand All @@ -212,7 +212,7 @@ public extension PrimitiveSequenceType where TraitType == CompletableTrait, Elem
- returns: An observable sequence that contains the elements of each given sequence, in sequential order.
*/
public static func concat(_ sources: Completable ...) -> Completable {
static func concat(_ sources: Completable ...) -> Completable {
let source = Observable.concat(sources.map { $0.asObservable() })
return Completable(raw: source)
}
Expand All @@ -225,7 +225,7 @@ public extension PrimitiveSequenceType where TraitType == CompletableTrait, Elem
- parameter sources: Collection of observable sequences to merge.
- returns: The observable sequence that merges the elements of the observable sequences.
*/
public static func merge<C: Collection>(_ sources: C) -> Completable
static func merge<C: Collection>(_ sources: C) -> Completable
where C.Iterator.Element == Completable {
let source = Observable.merge(sources.map { $0.asObservable() })
return Completable(raw: source)
Expand All @@ -239,7 +239,7 @@ public extension PrimitiveSequenceType where TraitType == CompletableTrait, Elem
- parameter sources: Array of observable sequences to merge.
- returns: The observable sequence that merges the elements of the observable sequences.
*/
public static func merge(_ sources: [Completable]) -> Completable {
static func merge(_ sources: [Completable]) -> Completable {
let source = Observable.merge(sources.map { $0.asObservable() })
return Completable(raw: source)
}
Expand All @@ -252,7 +252,7 @@ public extension PrimitiveSequenceType where TraitType == CompletableTrait, Elem
- parameter sources: Collection of observable sequences to merge.
- returns: The observable sequence that merges the elements of the observable sequences.
*/
public static func merge(_ sources: Completable...) -> Completable {
static func merge(_ sources: Completable...) -> Completable {
let source = Observable.merge(sources.map { $0.asObservable() })
return Completable(raw: source)
}
Expand Down

0 comments on commit fef36c4

Please sign in to comment.